/
Main.qml
495 lines (431 loc) · 16.3 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
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
489
490
491
492
493
494
495
/*
Copyright 2011-2012 Heikki Holstila <heikki.holstila@gmail.com>
This file is part of FingerTerm.
FingerTerm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
FingerTerm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FingerTerm. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import TextRender 1.0
import QtQuick.Window 2.0
Item {
id: root
property string windowTitle: util.currentWindowTitle();
Item {
id: page
property bool forceOrientation
property int forcedOrientation
property bool portrait: rotation % 180 == 0
width: portrait ? root.width : root.height
height: portrait ? root.height : root.width
anchors.centerIn: parent
rotation: Screen.angleBetween((forceOrientation ? forcedOrientation : Screen.orientation),
Screen.primaryOrientation)
focus: true
Keys.onPressed: {
term.keyPress(event.key,event.modifiers,event.text);
}
Component.onCompleted: {
var stringMode = util.settingsValue("ui/orientationLockMode");
applyOrientationLock(stringMode)
}
function applyOrientationLock(stringMode) {
switch (stringMode) {
case "auto":
page.forceOrientation = false
break
case "landscape":
page.forceOrientation = true
page.forcedOrientation = Qt.LandscapeOrientation
break
case "portrait":
page.forceOrientation = true
page.forcedOrientation = Qt.PortraitOrientation
}
}
Rectangle {
property string fgcolor: "black"
property string bgcolor: "#000000"
property int fontSize: 14*pixelRatio
property int fadeOutTime: 80
property int fadeInTime: 350
property real pixelRatio: root.width / 540
// layout constants
property int buttonWidthSmall: 60*pixelRatio
property int buttonWidthLarge: 180*pixelRatio
property int buttonWidthHalf: 90*pixelRatio
property int buttonHeightSmall: 48*pixelRatio
property int buttonHeightLarge: 68*pixelRatio
property int headerHeight: 20*pixelRatio
property int radiusSmall: 5*pixelRatio
property int radiusMedium: 10*pixelRatio
property int radiusLarge: 15*pixelRatio
property int paddingSmall: 5*pixelRatio
property int paddingMedium: 10*pixelRatio
property int fontSizeSmall: 14*pixelRatio
property int fontSizeLarge: 24*pixelRatio
property int uiFontSize: util.uiFontSize()*pixelRatio
property int scrollBarWidth: 6*window.pixelRatio
anchors.fill: parent
id: window
objectName: "window"
color: bgcolor
NotifyWin {
id: aboutDialog
property int termW: 0
property int termH: 0
text: {
var str = "<font size=\"+3\">FingerTerm " + util.versionString() + "</font><br>\n" +
"<font size=\"+1\">" +
"by Heikki Holstila <<a href=\"mailto:heikki.holstila@gmail.com?subject=FingerTerm\">heikki.holstila@gmail.com</a>><br><br>\n\n" +
"Config files for adjusting settings are at:<br>\n" +
util.configPath() + "/<br><br>\n" +
"Documentation:<br>\n<a href=\"http://hqh.unlink.org/harmattan\">http://hqh.unlink.org/harmattan</a>"
if (termH != 0 && termW != 0) {
str += "<br><br>Current window title: <font color=\"gray\">" + windowTitle.substring(0,40) + "</font>"; //cut long window title
if(windowTitle.length>40)
str += "...";
str += "<br>Current terminal size: <font color=\"gray\">" + termW + "x" + termH + "</font>";
str += "<br>Charset: <font color=\"gray\">" + util.settingsValue("terminal/charset") + "</font>";
}
str += "</font>";
return str;
}
onDismissed: {
util.setSettingsValue("state/showWelcomeScreen", false);
}
z: 1001
}
NotifyWin {
id: errorDialog
text: ""
z: 1002
}
UrlWindow {
id: urlWindow
z: 1000
}
LayoutWindow {
id: layoutWindow
z: 1000
}
Lineview {
id: lineView
x: 0
y: -(height+1)
z: 20
property int duration: 0;
onFontPointSizeChanged: {
lineView.setPosition(vkb.active)
}
}
Keyboard {
id: vkb
property bool visibleSetting: true
x: 0
y: parent.height-vkb.height
visible: page.activeFocus && visibleSetting
}
// area that handles gestures/select/scroll modes and vkb-keypresses
MultiPointTouchArea {
id: multiTouchArea
anchors.fill: parent
property int firstTouchId: -1
property var pressedKeys: ({})
onPressed: {
touchPoints.forEach(function (touchPoint) {
if (multiTouchArea.firstTouchId == -1) {
multiTouchArea.firstTouchId = touchPoint.pointId;
//gestures c++ handler
util.mousePress(touchPoint.x, touchPoint.y);
}
var key = vkb.keyAt(touchPoint.x, touchPoint.y);
if (key != null) {
key.handlePress(multiTouchArea, touchPoint.x, touchPoint.y);
}
multiTouchArea.pressedKeys[touchPoint.pointId] = key;
});
}
onUpdated: {
touchPoints.forEach(function (touchPoint) {
if (multiTouchArea.firstTouchId == touchPoint.pointId) {
//gestures c++ handler
util.mouseMove(touchPoint.x, touchPoint.y);
}
var key = multiTouchArea.pressedKeys[touchPoint.pointId];
if (key != null) {
if (!key.handleMove(multiTouchArea, touchPoint.x, touchPoint.y)) {
delete multiTouchArea.pressedKeys[touchPoint.pointId];
}
}
});
}
onReleased: {
touchPoints.forEach(function (touchPoint) {
if (multiTouchArea.firstTouchId == touchPoint.pointId) {
// Toggle keyboard wake-up when tapping outside the keyboard, but:
// - only when not scrolling (y-diff < 20 pixels)
// - not in select mode, as it would be hard to select text
if (touchPoint.y < vkb.y && touchPoint.startY < vkb.y &&
Math.abs(touchPoint.y - touchPoint.startY) < 20 &&
util.settingsValue("ui/dragMode") !== "select") {
if (vkb.active) {
window.sleepVKB();
} else {
window.wakeVKB();
}
}
//gestures c++ handler
util.mouseRelease(touchPoint.x, touchPoint.y);
multiTouchArea.firstTouchId = -1;
}
var key = multiTouchArea.pressedKeys[touchPoint.pointId];
if (key != null) {
key.handleRelease(multiTouchArea, touchPoint.x, touchPoint.y);
}
delete multiTouchArea.pressedKeys[touchPoint.pointId];
});
}
}
Rectangle {
//top right corner menu button
x: window.width - width
y: 0
z: 1
width: menuImg.width + 60*window.pixelRatio
height: menuImg.height + 30*window.pixelRatio
color: "transparent"
opacity: 0.5
Image {
anchors.centerIn: parent
id: menuImg
source: "qrc:/icons/menu.png"
height: sourceSize.height
width: sourceSize.width
scale: window.pixelRatio
}
MouseArea {
anchors.fill: parent
onClicked: {
menu.showMenu();
}
}
}
Image {
// terminal buffer scroll indicator
source: "qrc:/icons/scroll-indicator.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
visible: textrender.showBufferScrollIndicator
z: 5
scale: window.pixelRatio
}
MenuFingerterm {
id: menu
x: window.width-width
y: 0
}
TextRender {
id: textrender
objectName: "textrender"
x: 0
y: 0
height: parent.height
width: parent.width
myWidth: width
myHeight: height
opacity: 1.0
property int duration: 0;
property int cutAfter: height
Behavior on opacity {
NumberAnimation { duration: textrender.duration; easing.type: Easing.InOutQuad }
}
Behavior on y {
NumberAnimation { duration: textrender.duration; easing.type: Easing.InOutQuad }
}
onFontSizeChanged: {
lineView.fontPointSize = textrender.fontPointSize;
}
onCutAfterChanged: {
// this property is used in the paint function, so make sure that the element gets
// painted with the updated value (might not otherwise happen because of caching)
textrender.redraw();
}
z: 10
}
Timer {
id: fadeTimer
running: false
repeat: false
interval: menu.keyboardFadeOutDelay
onTriggered: {
window.sleepVKB();
}
}
Timer {
id: bellTimer
running: false
repeat: false
interval: 80
onTriggered: {
window.color = window.bgcolor;
}
}
Connections {
target: util
onVisualBell: {
window.visualBell();
}
onGestureNotify: {
textNotify.text = msg;
textNotifyAnim.enabled = false;
textNotify.opacity = 1.0;
textNotifyAnim.enabled = true;
textNotify.opacity = 0;
}
onWindowTitleChanged: {
windowTitle = util.currentWindowTitle();
}
}
Text {
// shows large text notification in the middle of the screen (for gestures)
id: textNotify
anchors.centerIn: parent
color: "#ffffff"
z: 100
opacity: 0
text: ""
font.pointSize: 40*window.pixelRatio
Behavior on opacity {
id: textNotifyAnim
NumberAnimation { duration: 500; }
}
}
Rectangle {
// visual key press feedback...
// easier to work with the coordinates if it's here and not under keyboard element
id: visualKeyFeedbackRect
visible: false
x: 0
y: 0
z: 200
width: 0
height: 0
radius: window.radiusSmall
color: "#ffffff"
property string label: ""
Text {
color: "#000000"
font.pointSize: 34*window.pixelRatio
anchors.centerIn: parent
text: visualKeyFeedbackRect.label
}
}
function vkbKeypress(key,modifiers) {
wakeVKB();
term.keyPress(key,modifiers);
}
function wakeVKB()
{
if(!vkb.visibleSetting)
return;
lineView.duration = window.fadeOutTime;
textrender.duration = window.fadeOutTime;
fadeTimer.restart();
vkb.active = true;
lineView.setPosition(vkb.active);
setTextRenderAttributes();
updateGesturesAllowed();
}
function sleepVKB()
{
textrender.duration = window.fadeInTime;
lineView.duration = window.fadeInTime;
vkb.active = false;
lineView.setPosition(vkb.active);
setTextRenderAttributes();
updateGesturesAllowed();
}
function setTextRenderAttributes()
{
if(util.settingsValue("ui/vkbShowMethod")==="move")
{
vkb.visibleSetting = true;
textrender.opacity = 1.0;
if(vkb.active) {
var move = textrender.cursorPixelPos().y + textrender.fontHeight/2 + textrender.fontHeight*util.settingsValue("ui/showExtraLinesFromCursor");
if(move < vkb.y) {
textrender.y = 0;
textrender.cutAfter = vkb.y;
} else {
textrender.y = 0 - move + vkb.y
textrender.cutAfter = move;
}
} else {
textrender.cutAfter = textrender.height;
textrender.y = 0;
}
}
else if(util.settingsValue("ui/vkbShowMethod")==="fade")
{
vkb.visibleSetting = true;
textrender.cutAfter = textrender.height;
textrender.y = 0;
if(vkb.active)
textrender.opacity = 0.3;
else
textrender.opacity = 1.0;
}
else // "off" (vkb disabled)
{
vkb.visibleSetting = false;
textrender.cutAfter = textrender.height;
textrender.y = 0;
textrender.opacity = 1.0;
}
}
function displayBufferChanged()
{
lineView.lines = term.printableLinesFromCursor(util.settingsValue("ui/showExtraLinesFromCursor"));
lineView.cursorX = textrender.cursorPixelPos().x;
lineView.cursorWidth = textrender.cursorPixelSize().width;
lineView.cursorHeight = textrender.cursorPixelSize().height;
setTextRenderAttributes();
}
Component.onCompleted: {
if( util.settingsValue("state/showWelcomeScreen") === true )
aboutDialog.state = "visible";
}
function showErrorMessage(string)
{
errorDialog.text = "<font size=\"+2\">" + string + "</font>";
errorDialog.state = "visible"
}
function visualBell()
{
bellTimer.start();
window.color = "#ffffff"
}
function updateGesturesAllowed()
{
if(vkb.active || menu.showing || urlWindow.state=="visible" ||
aboutDialog.state=="visible" || layoutWindow.state=="visible")
util.allowGestures = false;
else
util.allowGestures = true;
}
function setOrientationLockMode(stringMode)
{
util.setSettingsValue("ui/orientationLockMode", stringMode);
page.applyOrientationLock(stringMode)
}
}
}
}