summaryrefslogtreecommitdiff
path: root/tests/manual/testbench/main.qml
blob: 8e5d575772dddfaa426cf1027e668d013ecce8e9 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
import "content"

ApplicationWindow {
    width: 950
    height: 600

    signal propertyChanged
    property bool ignoreUpdate: false
    onPropertyChanged: container.resetSize()

    property var propertyMap: ({})

    property SpinBox widthControl
    property SpinBox heightControl

    color: "lightgray"

    Components{ id: components }
    SystemPalette { id: syspal }

    toolBar: ToolBar {
        width: parent.width
        RowLayout {
            id: alwaysVisible
            anchors.left: parent.left
            anchors.leftMargin: 8
            height: parent.height
            ComboBox {
                id: selector
                Layout.preferredWidth: 140
                model: components.componentModel
                textRole: "name"
            }
            CheckBox {
                id: patternCheckBox
                checked: false
                text: "Background"
            }
            CheckBox {
                id: customStyle
                visible: components.customStyles.get(selector.currentIndex).component !== undefined
                checked: false
                text: !checked ? "Load Custom Style" : "Custom Style loaded"
                onCheckedChanged: {
                    if (checked) {
                        loader.item.style = components.customStyles.get(selector.currentIndex).component
                        enabled = false
                    }
                }
            }
        }

        CheckBox {
            id: startStopAnim
            anchors.left: alwaysVisible.right
            anchors.verticalCenter: parent.verticalCenter
            text: "Stop Animation"
            checked: true
            visible: false
            onCheckedChanged: if (visible) loader.item.___isRunning = checked
        }
    }
    statusBar: StatusBar {
        Row {
            anchors.left: parent.left
            anchors.leftMargin: 8
            anchors.verticalCenter: parent.verticalCenter
            spacing: 5
            Label { text: "X: " + topLeftHandle.x; width: 70 }
            Label { text: "Y: " + topLeftHandle.y; width: 70 }
            Label { text: "Width: " + container.width; width: 80 }
            Label { text: "Height: "+container.height; width: 80 }
        }
    }

    SplitView {
        anchors.fill: parent
        Flickable {
            id: testBenchRect
            clip: true
            Layout.fillWidth: true

            Image {
                anchors.fill: parent
                source: "../images/checkered.png"
                fillMode: Image.Tile
                opacity: patternCheckBox.checked ? 0.12 : 0
                Behavior on opacity { NumberAnimation { duration: 100 } }
            }

            Rectangle {
                id: container

                property bool pressed: topLeftHandle.pressed || bottomRightHandle.pressed

                function resetSize() {
                    topLeftHandle.x = (testBenchRect.width - loader.item.implicitWidth) / 2 - topLeftHandle.width;
                    topLeftHandle.y = (testBenchRect.height - loader.item.implicitHeight) / 2 - topLeftHandle.height;
                    bottomRightHandle.x = topLeftHandle.x + loader.item.implicitWidth;
                    bottomRightHandle.y = topLeftHandle.y + loader.item.implicitHeight;
                }

                function updateSize() {
                    ignoreUpdate = true
                    if (widthControl)
                        widthControl.value = loader.item.width
                    if (heightControl)
                        heightControl.value = loader.item.height
                    ignoreUpdate = false
                }

                onHeightChanged: updateSize()
                onWidthChanged: updateSize()

                y: Math.floor(topLeftHandle.y + topLeftHandle.height - topLeftHandle.width/2)
                x: Math.floor(topLeftHandle.x + topLeftHandle.width - topLeftHandle.height/2)
                width: Math.floor(bottomRightHandle.x - topLeftHandle.x )
                height: Math.floor(bottomRightHandle.y - topLeftHandle.y)
                color: "transparent"
                border.color: pressed ? "darkgray" : "transparent"

                Loader {
                    id: loader
                    focus: true
                    sourceComponent: selector.model.get(selector.currentIndex).component
                    anchors.fill: parent
                    PropertyLayouts{ id: layouts }
                    onStatusChanged: {

                        startStopAnim.visible = false
                        customStyle.enabled = true
                        customStyle.checked = false

                        if (status == Loader.Ready) {
                            propertyMap = {}
                            var arr = {}

                            for (var prop in item) {

                                if (prop.toString() === "___isRunning") {
                                    startStopAnim.visible = true
                                    continue;
                                }

                                if (!(item[prop] instanceof Function)) { // We only want properties
                                    var typeName = "None";
                                    var layout
                                    var enumModelData
                                    var isColor = false
                                    switch (prop) {

                                    case "activeFocusOnPress":
                                    case "activeFocusOnTab":
                                    case "enabled":
                                    case "visible":
                                    case "checkable":
                                    case "checked":
                                    case "running":
                                    case "editable":
                                    case "frameVisible":
                                    case "adjustToContentSize":
                                    case "flat":
                                    case "selectByMouse":
                                    case "selectByKeyboard":
                                    case "readOnly":
                                    case "indeterminate":
                                    case "updateValueWhileDragging":
                                    case "tickmarksEnabled":
                                    case "sortIndicatorVisible":
                                    case "isDefault":
                                    case "partiallyCheckedEnabled":
                                    case "alternatingRowColors":
                                    case "movableColumns":
                                    case "gridVisible":
                                    case "weekNumbersVisible":
                                        layout = layouts.boolLayout
                                        typeName = "Boolean";
                                        break

                                    case "maximumValue":
                                    case "minimumValue":
                                    case "decimals":
                                    case "currentIndex":
                                    case "sortIndicatorColumn":
                                    case "visibleMonth":
                                    case "visibleYear":
                                        layout = layouts.intLayout
                                        typeName = "Int"
                                        break;

                                    case "scale":
                                    case "height":
                                    case "width":
                                    case "stepSize":
                                    case "value":
                                    case "opacity":
                                        layout = layouts.realLayout
                                        typeName = "Real";
                                        break;

                                    case "implicitHeight":
                                    case "activeFocus":
                                    case "implicitWidth":
                                    case "acceptableInput":
                                    case "pressed":
                                    case "currentText":
                                        layout = layouts.readonlyLayout
                                        typeName = "ReadOnly"
                                        break;

                                    case "prefix":
                                    case "suffix":
                                    case "text":
                                    case "title":
                                    case "tooltip":
                                    case "iconSource":
                                        layout = layouts.stringLayout
                                        typeName = "String";
                                        break;

                                    case "horizontalAlignment":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "TextEdit.AlignLeft",    value: TextEdit.AlignLeft});
                                        enumModelData.append({ text: "TextEdit.AlignRight",   value: TextEdit.AlignRight});
                                        enumModelData.append({ text: "TextEdit.AlignHCenter", value: TextEdit.AlignHCenter});
                                        break;

                                    case "textFormat":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "TextEdit.RichText",      value: TextEdit.RichText});
                                        enumModelData.append({ text: "TextEdit.PlainText",   value: TextEdit.PlainText});
                                        enumModelData.append({ text: "TextEdit.AutoText",  value: TextEdit.AutoText});
                                        break;

                                    case "verticalAlignment":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "TextEdit.AlignTop",      value: TextEdit.AlignTop});
                                        enumModelData.append({ text: "TextEdit.AlignBottom",   value: TextEdit.AlignBottom});
                                        enumModelData.append({ text: "TextEdit.AlignVCenter",  value: TextEdit.AlignVCenter});
                                        break;

                                    case "textFormat":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "TextEdit.RichText",      value: TextEdit.RichText});
                                        enumModelData.append({ text: "TextEdit.PlainText",   value: TextEdit.PlainText});
                                        enumModelData.append({ text: "TextEdit.AutoText",  value: TextEdit.AutoText});
                                        break;

                                    case "inputMethodHints":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "Qt.ImhNone",                  value: Qt.ImhNone});
                                        enumModelData.append({ text: "Qt.ImhHiddenText",            value: Qt.ImhHiddenText});
                                        enumModelData.append({ text: "Qt.ImhSensitiveData",         value: Qt.ImhSensitiveData});
                                        enumModelData.append({ text: "Qt.ImhNoAutoUppercase",       value: Qt.ImhNoAutoUppercase});
                                        enumModelData.append({ text: "Qt.ImhPreferNumbers",         value: Qt.ImhPreferNumbers});
                                        enumModelData.append({ text: "Qt.ImhPreferUppercase",       value: Qt.ImhPreferUppercase});
                                        enumModelData.append({ text: "Qt.ImhPreferLowercase",       value: Qt.ImhPreferLowercase});
                                        enumModelData.append({ text: "Qt.ImhNoPredictiveText",      value: Qt.ImhNoPredictiveText});
                                        enumModelData.append({ text: "Qt.ImhDate",                  value: Qt.ImhDate});
                                        enumModelData.append({ text: "Qt.ImhTime",                  value: Qt.ImhTime});
                                        enumModelData.append({ text: "Qt.ImhDigitsOnly",            value: Qt.ImhDigitsOnly});
                                        enumModelData.append({ text: "Qt.ImhFormattedNumbersOnly",  value: Qt.ImhFormattedNumbersOnly});
                                        enumModelData.append({ text: "Qt.ImhUppercaseOnly",         value: Qt.ImhUppercaseOnly});
                                        enumModelData.append({ text: "Qt.ImhLowercaseOnly",         value: Qt.ImhLowercaseOnly});
                                        enumModelData.append({ text: "Qt.ImhDialableCharactersOnly",value: Qt.ImhDialableCharactersOnly});
                                        enumModelData.append({ text: "Qt.ImhEmailCharactersOnly",   value: Qt.ImhEmailCharactersOnly});
                                        enumModelData.append({ text: "Qt.ImhUrlCharactersOnly",     value: Qt.ImhUrlCharactersOnly});
                                        break;

                                    case "orientation":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "Qt.Horizontal",    value: Qt.Horizontal});
                                        enumModelData.append({ text: "Qt.Vertical",      value: Qt.Vertical});
                                        break;

                                    case "echoMode":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "TextInput.Normal",            value: TextInput.Normal});
                                        enumModelData.append({ text: "TextInput.Password",          value: TextInput.Password});
                                        enumModelData.append({ text: "TextInput.NoEcho",            value: TextInput.NoEcho});
                                        enumModelData.append({ text: "TextInput.PasswordEchoOnEdit",value: TextInput.PasswordEchoOnEdit});
                                        break;

                                    case "backgroundColor":
                                    case "textColor":
                                        isColor = true
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "Amber",       value: "#FF7E00"});
                                        enumModelData.append({ text: "Azure",       value: "#007FFF"});
                                        enumModelData.append({ text: "Carmine red", value: "#FF0038"});
                                        break;

                                    case "sortIndicatorOrder":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "Qt.AscendingOrder",    value: Qt.AscendingOrder});
                                        enumModelData.append({ text: "Qt.DescendingOrder",   value: Qt.DescendingOrder});
                                        break;

                                    case "checkedState":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "Qt.Checked",          value: Qt.Checked});
                                        enumModelData.append({ text: "Qt.Unchecked",        value: Qt.Unchecked});
                                        enumModelData.append({ text: "Qt.PartiallyChecked", value: Qt.PartiallyChecked});
                                        break;

                                    case "dayOfWeekFormat":
                                        layout = layouts.enumLayout
                                        enumModelData = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; ListModel {}', layout, '');
                                        typeName = "Enum";
                                        enumModelData.append({ text: "ShortFormat", value: Locale.ShortFormat});
                                        enumModelData.append({ text: "LongFormat", value: Locale.LongFormat});
                                        enumModelData.append({ text: "NarrowFormat", value: Locale.NarrowFormat});
                                        break;


                                    default:
                                        break;
                                    }

                                    var val = item[prop] + "" // All model properties must be the same type

                                    if (typeName != "None" && val !== undefined) {
                                        if (isColor)
                                            enumModelData.append({ text: "Default",    value: val})

                                        if (arr[typeName] === undefined)
                                            arr[typeName] = []
                                        arr[typeName].push({name: prop , result: val, typeString: typeName, layoutComponent: layout, enumModel: enumModelData})
                                    }
                                }
                            }
                            propertyMap = arr;
                            container.resetSize();
                        }
                    }

                    Rectangle {
                        id: marginsRect
                        color: "transparent"
                        // opacity: container.pressed && loader.item.styling && loader.item.styling.topMargin != undefined ? 1 : 0
                        border.color: Qt.rgba(0, 0, 0, 0.2)
                        anchors.fill: parent
                        z: 2
                        Connections {
                            target: loader
                            onItemChanged: {
                                if (!loader.item || !loader.item.styling) return;
                                marginsRect.anchors.leftMargin = Math.max(loader.item.styling.leftMargin, 0);
                                marginsRect.anchors.rightMargin = Math.max(loader.item.styling.rightMargin, 0);
                                marginsRect.anchors.topMargin = Math.max(loader.item.styling.topMargin, 0);
                                marginsRect.anchors.bottomMargin = Math.max(loader.item.styling.bottomMargin, 0);
                            }
                        }
                    }
                }
            }

            MouseArea {
                id: topLeftHandle
                width: 10
                height: 10

                drag.target: topLeftHandle
                drag.minimumX: 0; drag.minimumY: 0
                drag.maximumX: bottomRightHandle.x - width
                drag.maximumY: bottomRightHandle.y - height
                Rectangle {
                    anchors.fill: parent
                    color: "lightsteelblue"
                    border.color: "steelblue"
                }
            }

            MouseArea {
                id: bottomRightHandle
                width: 10
                height: 10

                drag.target: bottomRightHandle
                drag.minimumX: topLeftHandle.x + width
                drag.minimumY: topLeftHandle.y + height
                drag.maximumX: testBenchRect.width - width;
                drag.maximumY: testBenchRect.height - height

                Rectangle {
                    anchors.fill: parent
                    color: "lightsteelblue"
                    border.color: "steelblue"
                }
            }
        }
        Rectangle {
            id: sidebar
            color : syspal.window
            width: 200
            ScrollView {
                id: scrollView
                anchors.fill: parent
                flickableItem.flickableDirection: Flickable.VerticalFlick
                Column {
                    id: properties
                    anchors.left: parent ? parent.left : undefined
                    anchors.top: parent ? parent.top : undefined
                    anchors.margins: 10
                    width: scrollView.viewport.width - 20
                    spacing: 8
                    Repeater {
                        model: ["Boolean", "String","Int", "Real", "ReadOnly", "Enum"]
                        Repeater {
                            model: propertyMap[modelData]
                            Loader {
                                width: properties.width
                                sourceComponent: modelData.layoutComponent
                                property string name: modelData.name
                                property var value: modelData.value
                                property var result: modelData.result
                                property var enumModel: modelData.enumModel
                            }
                        }
                    }
                }
            }
        }
    }
}