History

introduce test 'controls gallery' application for controls testing

Alexander Ivash committed 8 years ago

Commit 8d213ef1 parent 81d873a8 files · +331 −4Browse files

Showing the changes to scripts/developer (3 of 8 files). Show all

Unified · Split

3 files
  1. scripts/developer/tests/ControlsGallery.qml +103 −0
  2. scripts/developer/tests/Introspector.qml +166 −0
  3. scripts/developer/tests/controlsGallery.js +23 −0
scripts/developer/tests/ControlsGallery.qml+103−0
@@ -0,0 +1,103 @@
1import QtQuick 2.10
2import QtQuick.Window 2.10
3import QtQuick.Controls 2.2
4import QtQuick.Layouts 1.3
5import "qrc:////qml//styles-uit" as HifiStylesUit
6import "qrc:////qml//controls-uit" as HifiControlsUit
7
8//uncomment to use from qmlscratch tool
9//import '../../../interface/resources/qml/controls-uit' as HifiControlsUit
10//import '../../../interface/resources/qml/styles-uit'
11
12//uncomment to use with HIFI_USE_SOURCE_TREE_RESOURCES=1
13//import '../../../resources/qml/controls-uit' as HifiControlsUit
14//import '../../../resources/qml/styles-uit'
15
16Item {
17 visible: true
18 width: 640
19 height: 480
20
21 Introspector {
22 id: introspector
23 properties: ['realFrom', 'realTo', 'realValue', 'realStepSize', 'decimals']
24 visible: true
25 y: 50
26 x: 130
27 }
28
29 HifiStylesUit.HifiConstants {
30 id: hifi
31 }
32
33 TabBar {
34 id: bar
35 width: parent.width
36 TabButton {
37 text: "Spinbox"
38 }
39 TabButton {
40 text: "... Other Controls"
41 }
42 }
43
44 StackLayout {
45 id: controlsLayout
46 currentIndex: bar.currentIndex
47 anchors.top: bar.bottom
48 anchors.bottom: parent.bottom
49 anchors.left: parent.left
50 anchors.right: parent.right
51 anchors.margins: 20
52
53 Item {
54 id: spinboxTab
55 anchors.fill: parent
56
57 Column {
58 spacing: 20
59
60 HifiControlsUit.SpinBox {
61 realValue: 5.0
62 realFrom: 16.0
63 realTo: 20.0
64 decimals: 2
65 realStepSize: 0.01
66
67 width: 100
68 height: 30
69
70 colorScheme: hifi.colorSchemes.dark
71
72 onFocusChanged: {
73 if(focus) {
74 introspector.object = this
75 }
76 }
77 }
78
79 HifiControlsUit.SpinBox {
80 realValue: 5.0
81 realFrom: 1.0
82 realTo: 20.0
83 decimals: 2
84 realStepSize: 0.01
85
86 width: 100
87 height: 30
88
89 colorScheme: hifi.colorSchemes.light
90
91 onFocusChanged: {
92 if(focus) {
93 introspector.object = this
94 }
95 }
96 }
97 }
98 }
99 Item {
100 id: otherTab
101 }
102 }
103}
scripts/developer/tests/Introspector.qml+166−0
@@ -0,0 +1,166 @@
1import QtQuick 2.1;
2import QtQuick.Window 2.1;
3
4MouseArea {
5 id: base;
6 opacity: 0.65;
7 // anchors.fill: parent;
8 width: 400;
9 height: 300;
10
11 drag.target: list;
12 onWheel: { }
13
14 onClicked: { object = null }
15 property var object: null
16 onObjectChanged: {
17 visible = (object != null)
18 }
19
20 property var properties: []
21 onPropertiesChanged: {
22 console.debug('properties: ', JSON.stringify(properties, 4, 0))
23 }
24
25 function getPropertiesList(obj) {
26 var props = [];
27 var propertiesObject = obj;
28 if(properties.length !== 0) {
29 propertiesObject = {};
30 for(var i = 0; i < properties.length; ++i) {
31 propertiesObject[properties[i]] = properties[i];
32 }
33 }
34
35 for(var prop in propertiesObject) {
36
37 var info = {'name' : prop};
38 var value = obj[prop];
39 var typeOfValue = typeof(value);
40
41 if(typeof(value) === 'string') {
42 info['type'] = 'string'
43 } else if(typeof(value) === 'number') {
44 if(Number.isInteger(value))
45 info['type'] = 'int'
46 else
47 info['type'] = 'float'
48 } else if(typeof(value) === 'boolean') {
49 info['type'] = 'boolean'
50 } else if(typeof(value) === 'function') {
51 continue;
52 }
53
54 /*
55 if(prop !== 'parent' && prop !== 'data' && prop !== 'children')
56 console.debug('typeof(value): ', typeof(value), JSON.stringify(value, null, 4));
57 */
58
59 info['subName'] = ''
60 props.push(info);
61 }
62
63 return props;
64 }
65
66 Rectangle {
67 color: "lightgray";
68 anchors.fill: list;
69 anchors.margins: -50;
70 }
71 ListView {
72 id: list;
73 x: 50;
74 y: 50;
75 width: 400;
76 height: 300;
77 spacing: 5;
78 model: object !== null ? getPropertiesList(object) : [];
79 header: Text {
80 text: object !== null ? object.toString () : '';
81 font.bold: true;
82 font.pixelSize: 20;
83 }
84 delegate: Row {
85 spacing: 20;
86
87 Column {
88 width: 180;
89
90 Text {
91 text: (modelData ["subName"] !== "" ? (modelData ["name"] + "." + modelData ["subName"]) : modelData ["name"]);
92 font.pixelSize: 16;
93 }
94 }
95 Column {
96 width: 200;
97
98 Text {
99 text: {
100 return modelData ["type"]
101 }
102 font.pixelSize: 10;
103 }
104 TextInput {
105 id: input;
106 text: display;
107 width: parent.width;
108 font.pixelSize: 16;
109 font.underline: (text !== display);
110 Keys.onReturnPressed: { save (); }
111 Keys.onEnterPressed: { save (); }
112 Keys.onEscapePressed: { cancel (); }
113
114 property string display : "";
115
116 function save () {
117 var tmp;
118 switch (modelData ["type"]) {
119 case 'boolean':
120 tmp = (text === "true" || text === "1");
121 break;
122 case 'float':
123 tmp = parseFloat (text);
124 break;
125 case 'int':
126 tmp = parseInt (text);
127 break;
128 case 'string':
129 tmp = text;
130 break;
131
132 default:
133 break;
134 }
135 if (modelData ["subName"] !== "") {
136 object [modelData ["name"]][modelData ["subName"]] = tmp;
137 }
138 else {
139 object [modelData ["name"]] = tmp;
140 }
141 text = display;
142 }
143
144 function cancel () {
145 text = display;
146 }
147
148 Binding on text { value: input.display; }
149 Binding on display {
150 value: {
151 var ret = (modelData ["subName"] !== ""
152 ? object [modelData ["name"]][modelData ["subName"]]
153 : object [modelData ["name"]]);
154 return ret.toString ();
155 }
156 }
157 Rectangle {
158 z: -1;
159 color: "white";
160 anchors.fill: parent;
161 }
162 }
163 }
164 }
165 }
166}
scripts/developer/tests/controlsGallery.js+23−0
@@ -0,0 +1,23 @@
1(function() { // BEGIN LOCAL_SCOPE
2
3 console.debug('controlsGallery: creating window')
4
5 var qml = Script.resolvePath('ControlsGallery.qml');
6 var qmlWindow = new OverlayWindow({
7 title: 'Hifi Controls Gallery',
8 source: qml,
9 height: 480,
10 width: 640,
11 visible: true
12 });
13
14 console.debug('controlsGallery: creating window... done')
15
16 qmlWindow.closed.connect(function() { Script.stop(); });
17
18 Script.scriptEnding.connect(function() {
19 console.debug('controlsGallery: end of scripting')
20 delete qmlWindow;
21 });
22
23}()); // END LOCAL_SCOPE

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t