-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.qml
285 lines (252 loc) · 8.93 KB
/
Main.qml
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
import QtQuick
import QtQuick.Window
import Qt.labs.platform 1.1
import "./qml/js/parseParameters.js" as ParseFunc
import "./qml/controls"
Window {
id: frontEnd
visible: true
// visibility: Window.FullScreen
minimumWidth: 1024
minimumHeight: 768
color: colorSpace.backgroundColor
title: qsTr("Hello World")
property var topArea
property var frontEndJson
property var guiJson
property string fontFamily
property var colorSpace
property var dyValues: undefined
property var lastColorSpace
property bool showTip: false
property var shortcutObjList:[]
property color undefinedColor
property Component shortcutComp: Qt.createComponent("./qml/controls/DYShortcut.qml")
signal sigShowGUIChoosePage()
signal sigTriggerGUI(var dSignal)
signal sigTriggerConfirm(var dSignal)
signal sigTriggerBackEnd(var dSignal)
signal sigTriggerFrontEnd(var dSignal)//会被sigTriggerGUI与sigTriggerConfirm触发
DYColorSpace{
id: dyColor
}
///////////////////////////////////////////////////////////////////////////
// Design Area: you can change the code of this area.
///////////////////////////////////////////////////////////////////////////
Text {
id: centerText
anchors.centerIn: parent
anchors.verticalCenterOffset: -60
text: qsTr("Ctrl+O: Open GUI Config File\nCtrl+F: Switch FullScreen\nCtrl+Q: Quit the Application")
color: colorSpace.placeholderFontColor//"#9e9e9e"
font.pixelSize: 40
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
Text{
id: bomTipText
color: colorSpace.secondaryFontColor
font.pixelSize: 30
text: "You can design this page as you wish"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 210
}
Text{
id: secondTipText
color: colorSpace.secondaryFontColor
font.pixelSize: 20
text: "(Default loading GUI json file in 'Default' folder)"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 180
}
///////////////////////////////////////////////////////////////////////////////
// Functional Area: Do not try to change the code below unless you well
// study the structure of DYQML and know how to improve the code, otherwise
// you may destroy of breakdown the function of the DYQML system. you can
// design default page and change the code above.
///////////////////////////////////////////////////////////////////////////////
Shortcut{
id: keyOfShowSelectPage
context: Qt.ApplicationShortcut
sequence: "Ctrl+O"
onActivated: sigShowGUIChoosePage()
}
Shortcut{
id: keyOfQuitApp
context: Qt.ApplicationShortcut
sequence: "Ctrl+Q"
onActivated: frontEnd.close()
}
Shortcut{
id: keySwitchFullScreen
context: Qt.ApplicationShortcut
sequence: "Ctrl+F"
onActivated: {
if(frontEnd.visibility == Window.FullScreen)
frontEnd.visibility = Window.Windowed;
else
frontEnd.visibility = Window.FullScreen;
}
}
Shortcut{
id: keyReloadGUI
context: Qt.ApplicationShortcut
sequence: "Ctrl+R"
onActivated: fileLoader.reloadGUI()
}
FileDialog{
id: chooseJsonDialog
title: qsTr("Choose a GUI Config Json File")
nameFilters: ["JSON Files (*.json)", "*.*"]
fileMode: FileDialog.OpenFile
onAccepted: {
let jsonFilePath = chooseJsonDialog.file;
let currentFile = chooseJsonDialog.currentFile;
fileLoader.jsonHasChosen(jsonFilePath);
}
}
Timer {
id: freshTimer
running: true
repeat: true
interval: 200
}
Component{
id: areaComp
DYArea{
anchors.fill: parent
clip: true
}
}
onSigShowGUIChoosePage: {
console.log("Open Gui Choose Page.");
chooseJsonDialog.open();
}
Connections{
target: fileLoader
function onJsonHasRead(jsonStr){
console.log(`json has read`);
frontEndJson = JSON.parse(jsonStr);
destroyGUI();
generateGUI();
}
}
Connections {
target: frontEnd
function onSigTriggerGUI(dSignal){sigTriggerFrontEnd(dSignal);}
function onSigTriggerConfirm(dSignal){sigTriggerFrontEnd(dSignal);}
function onSigTriggerFrontEnd(dSignal){
console.log(`signal trigger frontend, and dSignal = ${
JSON.stringify(dSignal)
}`);
if(dSignal.sigId === "SWITCH-TO-SPECIFIED-FONT-FAMILY"){
if(dSignal.subInfo.fontFamily)
frontEnd.fontFamily = dSignal.subInfo.fontFamily;
if(dSignal.subInfo.item){
try{
frontEnd.fontFamily = dSignal.subInfo.item;
}catch(err){}
}
}
if(dSignal.sigId === "SET-COLORSPACE")
setCrtColorSpace(dSignal["subInfo"]);
}
function onSigTriggerBackEnd(dSignal){
console.log(`signal trigger backend, and dSignal = ${
JSON.stringify(dSignal)
}`);
backend.receiveFromQml(dSignal);
}
}
function setCrtColorSpace(colorSpaceObj){
lastColorSpace = JSON.parse(JSON.stringify(colorSpace));
let preLastBorderColor = lastColorSpace.baseBorderColor;
colorSpace = Object.assign(colorSpace, colorSpaceObj);
let postLastBorderColor = lastColorSpace.baseBorderColor;
let crtBorderColor = colorSpace.baseBorderColor;
}
function destroyGUI(){
if(topArea)
topArea.destroy();
if(shortcutObjList.length!==0){
destroyShortcut();
}
if(centerText)
centerText.destroy();
if(bomTipText)
bomTipText.destroy();
if(secondTipText)
secondTipText.destroy();
if(dyValues)
dyValues = undefined;
}
function generateGUI(){
resizeWindow();
generateGlobalValues();
modifyColorSpace();
guiJson = frontEndJson["topArea"];
guiJson["ctrlType"] = "topArea";
let paras = ParseFunc.parseParas(frontEnd, guiJson);
frontEnd.showTip = paras.showTip;
frontEnd.fontFamily = paras.fontFamily;
delete paras.showTip;
delete paras.fontFamily;
topArea = areaComp.createObject(frontEnd, paras);
addShortcut();
}
function destroyShortcut(){
let shortcutNum = shortcutObjList.length;
for(let i=0; i<shortcutNum; i++){
let shortcut = shortcutObjList.shift();
shortcut.enabled = false;
shortcut.destroy();
}
}
function addShortcut(){
if(frontEndJson["appSetting"] && frontEndJson["appSetting"]["shortcutList"]){
let shortcutList = frontEndJson["appSetting"]["shortcutList"];
let paras;
for(let i=0; i<shortcutList.length; i++){
paras = {
"signalList": shortcutList[i].dSignalList,
"sequence": shortcutList[i].keys,
};
shortcutObjList.push(shortcutComp.createObject(frontEnd, paras));
}
}
}
function resizeWindow(){
if(frontEndJson["appSetting"] && frontEndJson["appSetting"]["width"]){
frontEnd.minimumWidth = frontEndJson["appSetting"]["width"];
frontEnd.width = frontEndJson["appSetting"]["width"];
}else{
frontEnd.minimumWidth = 1024;
frontEnd.width = 1024;
}
if(frontEndJson["appSetting"] && frontEndJson["appSetting"]["height"]){
frontEnd.minimumHeight = frontEndJson["appSetting"]["height"];
frontEnd.height = frontEndJson["appSetting"]["height"];
}else{
frontEnd.minimumHeight = 768;
frontEnd.height = 768;
}
}
function generateGlobalValues(){
if(frontEndJson["appSetting"] && frontEndJson["appSetting"]["dyValues"])
frontEnd.dyValues = frontEndJson["appSetting"]["dyValues"];
}
function modifyColorSpace(){
colorSpace = JSON.parse(JSON.stringify(dyColor)); // restore the default colorSpace firstly.
if(frontEndJson["appSetting"] && frontEndJson["appSetting"]["colorSpace"]){
let colorSpaceSetting = frontEndJson["appSetting"]["colorSpace"];
let keys = Object.keys(colorSpaceSetting);
setCrtColorSpace(colorSpaceSetting);
}
}
Component.onDestruction: console.log(`Application start quits.`)
Component.onCompleted: {
colorSpace = JSON.parse(JSON.stringify(dyColor));
}
}