-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLiveCodingPanel.qml
More file actions
230 lines (194 loc) · 5.25 KB
/
Copy pathLiveCodingPanel.qml
File metadata and controls
230 lines (194 loc) · 5.25 KB
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
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Window 2.0
import Qt.labs.settings 1.0
import com.machinekoder.live 1.0
Item {
id: root
property alias hideToolBar: hideToolBarCheck.checked
property int flags: Qt.Window
property int visibility: Window.AutomaticVisibility
readonly property var defaultNameFilters: ["*.qmlc", "*.jsc", "*.pyc", ".#*", ".*", "*~", "__pycache__", "*___jb_tmp___", // PyCharm safe write
"*___jb_old___"]
property var additionalNameFilters: []
QtObject {
id: d
function reload() {
loader.source = ""
LiveCoding.clearQmlComponentCache()
loader.source = fileDialog.file
}
function openWithSystemEditor() {
LiveCoding.openUrlWithDefaultApplication(fileDialog.file)
}
function unload() {
loader.source = ""
fileDialog.selected = false
browser.update()
}
function restart() {
LiveCoding.restartApplication()
}
}
Settings {
id: windowSettings
category: "window"
property alias width: root.width
property alias height: root.height
property alias x: root.x
property alias y: root.y
property alias visibility: root.visibility
property alias hideToolBar: hideToolBarCheck.checked
}
MouseArea {
id: smallArea
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 10
width: height
z: 10
visible: contentItem.loaded && !fullArea.delayedVisible
hoverEnabled: true
propagateComposedEvents: true
onClicked: mouse.accepted = false
onEntered: fullArea.visible = true
}
MouseArea {
property bool delayedVisible: false
id: fullArea
anchors.top: parent.top
anchors.right: parent.right
anchors.left: parent.left
height: 40
z: 9
hoverEnabled: true
propagateComposedEvents: true
visible: false
onClicked: mouse.accepted = false
onPressed: mouse.accepted = false
onReleased: mouse.accepted = false
onExited: visible = false
onVisibleChanged: delayTimer.start()
Timer {
id: delayTimer
interval: 10
onTriggered: fullArea.delayedVisible = fullArea.visible // break binding loop
}
}
ColumnLayout {
anchors.fill: parent
anchors.topMargin: menuBar.visible ? 5 : 0
RowLayout {
id: menuBar
visible: !hideToolBarCheck.checked || (smallArea.containsMouse
|| fullArea.containsMouse
|| !contentItem.loaded)
Button {
Layout.preferredHeight: 30
enabled: fileDialog.selected
text: qsTr("Edit")
onClicked: d.openWithSystemEditor()
}
Button {
Layout.preferredHeight: 30
enabled: fileDialog.selected
text: qsTr("Reload")
onClicked: d.reload()
}
Button {
Layout.preferredHeight: 30
text: qsTr("Unload")
onClicked: d.unload()
}
Button {
Layout.preferredHeight: 30
text: qsTr("Restart")
onClicked: d.restart()
}
Item {
Layout.fillWidth: true
}
CheckBox {
id: hideToolBarCheck
text: qsTr("Hide Tool Bar")
checked: false
}
CheckBox {
text: qsTr("Fullscreen")
checked: root.visibility === Window.FullScreen
onClicked: {
if (checked) {
root.visibility = Window.FullScreen
} else {
root.visibility = Window.AutomaticVisibility
}
}
}
CheckBox {
text: qsTr("On Top")
checked: root.flags & Qt.WindowStaysOnTopHint
onClicked: {
if (checked) {
root.flags = root.flags | Qt.WindowStaysOnTopHint
} else {
root.flags = root.flags & ~Qt.WindowStaysOnTopHint
}
}
}
}
Item {
id: contentItem
Layout.fillWidth: true
Layout.fillHeight: true
property bool loaded: loader.status !== Loader.Null
Loader {
id: loader
anchors.fill: parent
onStatusChanged: {
if (status !== Loader.Error) {
return
}
var msg = loader.sourceComponent.errorString()
errorLabel.text = qsTr("QML Error: Loading QML file failed:\n") + msg
}
}
Label {
id: errorLabel
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
visible: loader.status === Loader.Error
}
FileSelectionDialog {
id: fileDialog
anchors.fill: parent
model: browser.qmlFiles
visible: !contentItem.loaded
onSelectedChanged: {
if (selected) {
d.reload()
}
}
}
}
}
ProjectBrowser {
id: browser
extensions: ["qml", "ui.qml"]
}
FileWatcher {
id: fileWatcher
fileUrl: browser.projectPath
recursive: true
enabled: fileDialog.selected
onFileChanged: {
d.reload()
}
nameFilters: root.defaultNameFilters.concat(root.additionalNameFilters)
}
// add additional components that should only be loaded once here.
}