blob: f505d9fc50c434392774d87b1c185bc7d14073fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
import QtQuick 2.1
import HelperWidgets 2.0
import StudioControls 1.0 as StudioControls
import StudioTheme 1.0 as StudioTheme
import QtQuick.Layouts 1.0
RowLayout {
id: urlChooser
property variant backendValue
property color textColor: colorLogic.highlight ? colorLogic.textColor : "white"
property string filter: "*.png *.gif *.jpg *.bmp *.jpeg *.svg *.pbm *.pgm *.ppm *.xbm *.xpm *.hdr"
FileResourcesModel {
id: fileModel
modelNodeBackendProperty: modelNodeBackend
filter: urlChooser.filter
}
ColorLogic {
id: colorLogic
backendValue: urlChooser.backendValue
}
StudioControls.ComboBox {
id: comboBox
actionIndicator.icon.color: extFuncLogic.color
actionIndicator.icon.text: extFuncLogic.glyph
actionIndicator.onClicked: extFuncLogic.show()
actionIndicator.forceVisible: extFuncLogic.menuVisible
ExtendedFunctionLogic {
id: extFuncLogic
backendValue: urlChooser.backendValue
}
property bool isComplete: false
property bool dirty: false
onEditTextChanged: comboBox.dirty = true
function setCurrentText(text) {
var index = comboBox.find(text)
if (index === -1)
currentIndex = -1
comboBox.editText = text
comboBox.dirty = false
}
property string textValue: {
if (urlChooser.backendValue.isBound)
return urlChooser.backendValue.expression
return urlChooser.backendValue.valueToString
}
onTextValueChanged: comboBox.setCurrentText(comboBox.textValue)
Layout.fillWidth: true
editable: true
model: fileModel.fileModel
onModelChanged: {
if (!comboBox.isComplete)
return
comboBox.setCurrentText(comboBox.textValue)
}
onAccepted: {
if (!comboBox.isComplete)
return
if (comboBox.backendValue.value !== comboBox.editText)
comboBox.backendValue.value = comboBox.editText
comboBox.dirty = false
}
onFocusChanged: {
if (comboBox.dirty)
comboBox.handleActivate(comboBox.currentIndex)
}
onCompressedActivated: comboBox.handleActivate(index)
function handleActivate(index)
{
var cText = comboBox.textAt(index)
if (index === -1)
cText = comboBox.editText
if (urlChooser.backendValue === undefined)
return
if (!comboBox.isComplete)
return
if (urlChooser.backendValue.value !== cText)
urlChooser.backendValue.value = cText
comboBox.dirty = false
}
Component.onCompleted: {
// Hack to style the text input
for (var i = 0; i < comboBox.children.length; i++) {
if (comboBox.children[i].text !== undefined) {
comboBox.children[i].color = urlChooser.textColor
comboBox.children[i].anchors.rightMargin = 34
}
}
comboBox.isComplete = true
comboBox.setCurrentText(comboBox.textValue)
}
}
StudioControls.AbstractButton {
buttonIcon: StudioTheme.Constants.addFile
iconColor: urlChooser.textColor
onClicked: {
fileModel.openFileDialog()
if (fileModel.fileName !== "")
urlChooser.backendValue.value = fileModel.fileName
}
}
}
|