1
1
import QtQuick
2
- import QtQuick.Controls as QTC
2
+ import QtQuick.Controls
3
3
import QtQuick.Layouts
4
4
import JASP
5
5
@@ -19,59 +19,18 @@ ComboBoxBase
19
19
property alias currentLabel: comboBox .currentText
20
20
property alias value: comboBox .currentValue
21
21
property alias indexDefaultValue: comboBox .currentIndex
22
- property alias fieldWidth: control .width
22
+ property alias fieldWidth: control .implicitWidth
23
23
property int textFormat: Text .AutoText
24
24
property bool showVariableTypeIcon: containsVariables
25
25
property var enabledOptions: []
26
26
property bool setLabelAbove: false
27
- property int controlMinWidth: 0
28
27
property bool useExternalBorder: true
29
28
property bool showBorder: true
30
29
property bool showEmptyValueAsNormal: false
31
30
property bool addLineAfterEmptyValue: false
32
31
property double controlXOffset: 0
33
32
property bool alignInGroup: ! setLabelAbove
34
33
35
- onControlMinWidthChanged: _resetWidth (textMetrics .width )
36
-
37
-
38
-
39
- function resetWidth (values )
40
- {
41
- var maxWidth = 0
42
- var maxValue = " "
43
- textMetrics .initialized = false ;
44
-
45
- if (addEmptyValue)
46
- values .push (placeholderText)
47
-
48
- for (var i = 0 ; i < values .length ; i++ )
49
- {
50
- textMetrics .text = values[i]
51
- if (textMetrics .width > maxWidth)
52
- {
53
- maxWidth = textMetrics .width
54
- maxValue = values[i]
55
- }
56
- }
57
-
58
- textMetrics .text = maxValue;
59
- textMetrics .initialized = true ;
60
- _resetWidth (maxWidth)
61
- }
62
-
63
- function _resetWidth (maxTextWidth )
64
- {
65
- control .maxTextWidth = maxTextWidth
66
- // The real field width is composed by the type icon (if displayed) + 2-padding + max width + 5-padding + dropdownIcon width + 2-padding
67
- var newFieldWidth = (comboBox .showVariableTypeIcon ? contentIcon .x + contentIcon .width : 0 ) + (allowedTypeIcons .count > 0 ? allowedTypeIcons .width + jaspTheme .itemPadding : 0 ) + maxTextWidth + dropdownIcon .width + 9 * preferencesModel .uiScale
68
- if (newFieldWidth < controlMinWidth)
69
- newFieldWidth = controlMinWidth
70
-
71
- control .realFieldWidth = newFieldWidth
72
- if (! fixedWidth) control .width = newFieldWidth;
73
- }
74
-
75
34
Component .onCompleted : control .activated .connect (activated);
76
35
77
36
Rectangle
@@ -92,9 +51,10 @@ ComboBoxBase
92
51
}
93
52
}
94
53
95
- QTC . ComboBox
54
+ ComboBox
96
55
{
97
56
id: control
57
+ implicitWidth: longestFieldWidth + (allowedTypeIcons .count > 0 ? allowedTypeIcons .width + jaspTheme .contentMargin : 0 )
98
58
model: comboBox .model
99
59
anchors
100
60
{
@@ -105,31 +65,25 @@ ComboBoxBase
105
65
106
66
focus: true
107
67
padding: 2 * preferencesModel .uiScale
108
- width: 0
109
68
height: jaspTheme .comboBoxHeight
110
69
font: jaspTheme .font
111
70
property bool isEmptyValue: comboBox .addEmptyValue && comboBox .currentIndex === 0
112
71
property bool showEmptyValueStyle: ! comboBox .showEmptyValueAsNormal && isEmptyValue
113
- property double realFieldWidth : width
114
- property double maxTextWidth : 0
72
+ property double longestFieldWidth : ( comboBox . showVariableTypeIcon ? contentIcon . x + contentIcon . width + jaspTheme . contentMargin : 0 ) +
73
+ textMetrics . width + indicator . width + 3 * jaspTheme . contentMargin
115
74
116
75
TextMetrics
117
76
{
118
77
id: textMetrics
119
78
font: control .font
120
-
121
- property bool initialized: false
122
-
123
- onWidthChanged:
124
- {
125
- if (initialized)
126
- _resetWidth (width)
127
- }
79
+ text: longestValue
128
80
}
129
81
130
82
contentItem: Rectangle
131
83
{
84
+ id: contentRectangle
132
85
color: jaspTheme .controlBackgroundColor
86
+
133
87
Image
134
88
{
135
89
id: contentIcon
@@ -143,18 +97,19 @@ ComboBoxBase
143
97
144
98
Text
145
99
{
146
- anchors .left : contentIcon .visible ? contentIcon .right : parent .left
147
- anchors .leftMargin : 2 * preferencesModel .uiScale
148
- anchors .verticalCenter : parent .verticalCenter
149
- anchors .horizontalCenter : control .showEmptyValueStyle ? parent .horizontalCenter : undefined
100
+ id: controlText
101
+ anchors
102
+ {
103
+ left: contentIcon .visible ? contentIcon .right : parent .left
104
+ leftMargin: 2 * preferencesModel .uiScale
105
+ right: allowedColumnsIcons .length > 0 ? allowedTypeIcons .left : parent .right
106
+ verticalCenter: parent .verticalCenter
107
+ // horizontalCenter: control.showEmptyValueStyle ? parent.horizontalCenter : undefined
108
+ }
150
109
text: comboBox .currentText
151
110
font: control .font
152
111
color: (! enabled || control .showEmptyValueStyle ) ? jaspTheme .grayDarker : jaspTheme .black
153
- width: (fixedWidth ? widthWhenContralHasFixedWidth : control .maxTextWidth ) + 5 * preferencesModel .uiScale
154
112
elide: Text .ElideRight
155
-
156
- property double widthWhenContralHasFixedWidth: control .width - (x + dropdownIcon .width + 4 * preferencesModel .uiScale ) // 4 = leftMargin + 2 padding right of dropdownIcon)
157
-
158
113
}
159
114
160
115
AllowedTypeIcons
@@ -205,18 +160,12 @@ ComboBoxBase
205
160
radius: jaspTheme .jaspControlHighlightWidth
206
161
}
207
162
208
- popup: QTC . Popup
163
+ popup: Popup
209
164
{
210
165
id: popupRoot
211
- y: control .height
212
- width: Math .max (control .realFieldWidth , fieldWidth) + scrollBar .width
213
-
214
- property real maxHeight: typeof mainWindowRoot !== ' undefined' ? mainWindowRoot .height // Case Dropdowns used in Desktop
215
- : (typeof rcmdRoot !== ' undefined' ? rcmdRoot .height // Case Dropdown used in R Command
216
- : (typeof backgroundForms !== ' undefined' ? backgroundForms .height // Case Dropdowns used in Analysis forms
217
- : Infinity ))
218
- height: Math .min (popupView .contentHeight + (padding* 2 ), maxHeight)
219
166
padding: 1
167
+ implicitWidth: popupView .implicitWidth + scrollBar .width + 2 * padding
168
+ implicitHeight: popupView .implicitHeight + 2 * padding
220
169
221
170
enter: Transition { NumberAnimation { property: " opacity" ; from: 0.0 ; to: 1.0 } enabled: preferencesModel .animationsOn }
222
171
@@ -236,16 +185,22 @@ ComboBoxBase
236
185
}
237
186
}
238
187
239
-
240
188
contentItem: ListView
241
189
{
242
190
id: popupView
243
- width : popupRoot . width - scrollBar .width
244
- height : popupRoot . height
245
- model: control .popup . visible ? control . delegateModel : null
191
+ implicitWidth : Math . max ( control . longestFieldWidth , control .width )
192
+ implicitHeight : Math . min (contentHeight, maxHeight)
193
+ model: control .delegateModel
246
194
currentIndex: control .highlightedIndex
247
195
clip: true
248
196
197
+ property real maxHeight: typeof mainWindowRoot !== ' undefined' ? mainWindowRoot .height // Case Dropdowns used in Desktop
198
+ : (typeof rcmdRoot !== ' undefined' ? rcmdRoot .height // Case Dropdown used in R Command
199
+ : (typeof backgroundForms !== ' undefined' ? backgroundForms .height // Case Dropdowns used in Analysis forms
200
+ : Infinity ))
201
+
202
+
203
+
249
204
Rectangle
250
205
{
251
206
anchors .centerIn : parent
@@ -265,10 +220,10 @@ ComboBoxBase
265
220
}
266
221
}
267
222
268
- delegate: QTC . ItemDelegate
223
+ delegate: ItemDelegate
269
224
{
270
- height : jaspTheme .comboBoxHeight
271
- width : popupView .width
225
+ implicitHeight : jaspTheme .comboBoxHeight
226
+ implicitWidth : popupView .width
272
227
enabled: comboBox .enabledOptions .length == 0 || comboBox .enabledOptions .length <= index || comboBox .enabledOptions [index]
273
228
274
229
contentItem: Rectangle
0 commit comments