MenuFingerterm.qml 19.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
    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/>.
*/

John Brooks's avatar
John Brooks committed
20 21
import QtQuick 2.0
import QtQuick.XmlListModel 2.0
22
import FingerTerm 1.0
23

Pekka Vuorela's avatar
Pekka Vuorela committed
24
Item {
25
    id: menuWin
Pekka Vuorela's avatar
Pekka Vuorela committed
26 27 28

    property bool showing

29
    visible: rect.x < menuWin.width
30 31 32

    Rectangle {
        id: fader
Pekka Vuorela's avatar
Pekka Vuorela committed
33

34
        color: "#000000"
35
        opacity: menuWin.showing ? 0.5 : 0.0
Pekka Vuorela's avatar
Pekka Vuorela committed
36
        anchors.fill: parent
Pekka Vuorela's avatar
Pekka Vuorela committed
37

38 39
        Behavior on opacity { NumberAnimation { duration: 100; } }

40 41
        MouseArea {
            anchors.fill: parent
42
            onClicked: menuWin.showing = false
43 44 45 46
        }
    }
    Rectangle {
        id: rect
Pekka Vuorela's avatar
Pekka Vuorela committed
47

48
        color: "#e0e0e0"
49 50
        anchors.left: parent.right
        anchors.leftMargin: menuWin.showing ? -width : 1
51
        width: flickableContent.width + 22*window.pixelRatio;
52 53 54 55 56 57 58
        height: menuWin.height

        MouseArea {
            // event eater
            anchors.fill: parent
        }

59
        Behavior on anchors.leftMargin {
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            NumberAnimation { duration: 100; easing.type: Easing.InOutQuad; }
        }

        XmlListModel {
            id: xmlModel
            xml: term.getUserMenuXml()
            query: "/userMenu/item"

            XmlRole { name: "title"; query: "title/string()" }
            XmlRole { name: "command"; query: "command/string()" }
            XmlRole { name: "disableOn"; query: "disableOn/string()" }
        }

        Component {
            id: xmlDelegate
            Button {
                text: title
                isShellCommand: true
Pekka Vuorela's avatar
Pekka Vuorela committed
78
                enabled: disableOn.length === 0 || util.windowTitle.search(disableOn) === -1
79
                onClicked: {
80
                    menuWin.showing = false;
81 82 83 84 85 86
                    term.putString(command, true);
                }
            }
        }

        Rectangle {
87 88 89
            y: menuFlickArea.visibleArea.yPosition*menuFlickArea.height + window.scrollBarWidth
            x: parent.width-window.paddingMedium
            width: window.scrollBarWidth
90
            height: menuFlickArea.visibleArea.heightRatio*menuFlickArea.height
91
            radius: 3*window.pixelRatio
92 93 94 95 96
            color: "#202020"
        }

        Flickable {
            id: menuFlickArea
97

98
            anchors.fill: parent
99 100 101 102
            anchors.topMargin: window.scrollBarWidth
            anchors.bottomMargin: window.scrollBarWidth
            anchors.leftMargin: window.scrollBarWidth
            anchors.rightMargin: 16*window.pixelRatio
103 104 105 106
            contentHeight: flickableContent.height

            Column {
                id: flickableContent
107

108
                spacing: 12*window.pixelRatio
109 110 111

                Row {
                    id: menuBlocksRow
112
                    spacing: 8*window.pixelRatio
113 114

                    Column {
115
                        spacing: 12*window.pixelRatio
116 117 118 119 120 121 122
                        Repeater {
                            model: xmlModel
                            delegate: xmlDelegate
                        }
                    }

                    Column {
123
                        spacing: 12*window.pixelRatio
124 125 126 127 128

                        Row {
                            Button {
                                text: "Copy"
                                onClicked: {
129
                                    menuWin.showing = false;
130 131
                                    term.copySelectionToClipboard();
                                }
132 133
                                width: window.buttonWidthHalf
                                height: window.buttonHeightLarge
134
                                enabled: util.terminalHasSelection
135 136 137 138
                            }
                            Button {
                                text: "Paste"
                                onClicked: {
139
                                    menuWin.showing = false;
140 141
                                    term.pasteFromClipboard();
                                }
142 143
                                width: window.buttonWidthHalf
                                height: window.buttonHeightLarge
144
                                enabled: util.canPaste
145 146 147 148
                            }
                        }
                        Button {
                            text: "URL grabber"
149 150
                            width: window.buttonWidthLarge
                            height: window.buttonHeightLarge
151
                            onClicked: {
152
                                menuWin.showing = false;
153
                                urlWindow.urls = term.grabURLsFromBuffer();
Pekka Vuorela's avatar
Pekka Vuorela committed
154
                                urlWindow.show = true
155 156 157
                            }
                        }
                        Rectangle {
158 159 160
                            width: window.buttonWidthLarge
                            height: window.buttonHeightLarge
                            radius: window.radiusSmall
161 162 163
                            color: "#606060"
                            border.color: "#000000"
                            border.width: 1
Pekka Vuorela's avatar
Pekka Vuorela committed
164

165 166
                            Column {
                                Text {
167 168
                                    width: window.buttonWidthLarge
                                    height: window.headerHeight
169
                                    color: "#ffffff"
170
                                    font.pointSize: window.uiFontSize-1
171 172 173 174 175 176 177
                                    text: "Font size"
                                    horizontalAlignment: Text.AlignHCenter
                                }
                                Row {
                                    Button {
                                        text: "<font size=\"+3\">+</font>"
                                        onClicked: {
178
                                            util.fontSize = util.fontSize + window.pixelRatio
179
                                            util.notifyText(term.columns + "×" + term.rows);
180
                                        }
181 182
                                        width: window.buttonWidthHalf
                                        height: window.buttonHeightSmall
183 184 185 186
                                    }
                                    Button {
                                        text: "<font size=\"+3\">-</font>"
                                        onClicked: {
187
                                            util.fontSize = util.fontSize - window.pixelRatio
188
                                            util.notifyText(term.columns + "×" + term.rows);
189
                                        }
190 191
                                        width: window.buttonWidthHalf
                                        height: window.buttonHeightSmall
192 193 194 195
                                    }
                                }
                            }
                        }
196
                        Rectangle {
197 198 199
                            width: window.buttonWidthLarge
                            height: window.buttonHeightLarge
                            radius: window.radiusSmall
200 201 202
                            color: "#606060"
                            border.color: "#000000"
                            border.width: 1
Pekka Vuorela's avatar
Pekka Vuorela committed
203

204 205
                            Column {
                                Text {
206 207
                                    width: window.buttonWidthLarge
                                    height: window.headerHeight
208
                                    color: "#ffffff"
209
                                    font.pointSize: window.uiFontSize-1
210 211 212 213 214 215
                                    text: "UI Orientation"
                                    horizontalAlignment: Text.AlignHCenter
                                }
                                Row {
                                    Button {
                                        text: "<font size=\"-1\">Auto</font>"
216 217
                                        highlighted: util.orientationMode == Util.OrientationAuto
                                        onClicked: util.orientationMode = Util.OrientationAuto
218 219
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
220 221 222
                                    }
                                    Button {
                                        text: "<font size=\"-1\">L<font>"
223 224
                                        highlighted: util.orientationMode == Util.OrientationLandscape
                                        onClicked: util.orientationMode = Util.OrientationLandscape
225 226
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
227 228 229
                                    }
                                    Button {
                                        text: "<font size=\"-1\">P</font>"
230 231
                                        highlighted: util.orientationMode == Util.OrientationPortrait
                                        onClicked: util.orientationMode = Util.OrientationPortrait
232 233
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
234 235 236 237
                                    }
                                }
                            }
                        }
238
                        Rectangle {
239 240 241
                            width: window.buttonWidthLarge
                            height: window.buttonHeightLarge
                            radius: window.radiusSmall
242 243 244
                            color: "#606060"
                            border.color: "#000000"
                            border.width: 1
Pekka Vuorela's avatar
Pekka Vuorela committed
245

246 247
                            Column {
                                Text {
248 249
                                    width: window.buttonWidthLarge
                                    height: window.headerHeight
250
                                    color: "#ffffff"
251
                                    font.pointSize: window.uiFontSize-1
252 253 254 255 256 257
                                    text: "Drag mode"
                                    horizontalAlignment: Text.AlignHCenter
                                }
                                Row {
                                    Button {
                                        text: "<font size=\"-1\">Gesture</font>"
258
                                        highlighted: util.dragMode == Util.DragGestures
259
                                        onClicked: {
260
                                            util.dragMode = Util.DragGestures
261
                                            term.clearSelection();
262
                                            menuWin.showing = false;
263
                                        }
264 265
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
266 267 268
                                    }
                                    Button {
                                        text: "<font size=\"-1\">Scroll</font>"
269
                                        highlighted: util.dragMode == Util.DragScroll
270
                                        onClicked: {
271
                                            util.dragMode = Util.DragScroll
272
                                            term.clearSelection();
273
                                            menuWin.showing = false;
274
                                        }
275 276
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
277 278 279
                                    }
                                    Button {
                                        text: "<font size=\"-1\">Select</font>"
280
                                        highlighted: util.dragMode == Util.DragSelect
281
                                        onClicked: {
282
                                            util.dragMode = Util.DragSelect
283
                                            menuWin.showing = false;
284
                                        }
285 286
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
287 288 289 290 291
                                    }
                                }
                            }
                        }
                        Rectangle {
292 293 294
                            width: window.buttonWidthLarge
                            height: window.buttonHeightLarge
                            radius: window.radiusSmall
295 296 297
                            color: "#606060"
                            border.color: "#000000"
                            border.width: 1
Pekka Vuorela's avatar
Pekka Vuorela committed
298

299 300
                            Column {
                                Text {
301 302
                                    width: window.buttonWidthLarge
                                    height: window.headerHeight
303
                                    color: "#ffffff"
304
                                    font.pointSize: window.uiFontSize-1
305 306 307 308 309 310
                                    text: "VKB behavior"
                                    horizontalAlignment: Text.AlignHCenter
                                }
                                Row {
                                    Button {
                                        text: "Off"
311
                                        highlighted: util.keyboardMode == Util.KeyboardOff
312
                                        onClicked: {
313
                                            util.keyboardMode = Util.KeyboardOff
314
                                            window.setTextRenderAttributes();
315
                                            menuWin.showing = false;
316
                                        }
317 318
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
319 320 321
                                    }
                                    Button {
                                        text: "Fade"
322
                                        highlighted: util.keyboardMode == Util.KeyboardFade
323
                                        onClicked: {
324
                                            util.keyboardMode = Util.KeyboardFade
325
                                            window.setTextRenderAttributes();
326
                                            menuWin.showing = false;
327
                                        }
328 329
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
330 331 332
                                    }
                                    Button {
                                        text: "Move"
333
                                        highlighted: util.keyboardMode == Util.KeyboardMove
334
                                        onClicked: {
335
                                            util.keyboardMode = Util.KeyboardMove
336
                                            window.setTextRenderAttributes();
337
                                            menuWin.showing = false;
338
                                        }
339 340
                                        width: window.buttonWidthSmall
                                        height: window.buttonHeightSmall
341 342 343 344 345 346 347
                                    }
                                }
                            }
                        }
                        Button {
                            text: "New window"
                            onClicked: {
348
                                menuWin.showing = false;
349 350 351 352 353 354
                                util.openNewWindow();
                            }
                        }
                        Button {
                            text: "VKB layout..."
                            onClicked: {
355
                                menuWin.showing = false;
356
                                layoutWindow.layouts = keyLoader.availableLayouts();
Pekka Vuorela's avatar
Pekka Vuorela committed
357
                                layoutWindow.show = true
358 359 360 361 362
                            }
                        }
                        Button {
                            text: "About"
                            onClicked: {
363
                                menuWin.showing = false;
Pekka Vuorela's avatar
Pekka Vuorela committed
364
                                aboutDialog.show = true
365 366 367 368 369
                            }
                        }
                        Button {
                            text: "Quit"
                            onClicked: {
370
                                menuWin.showing = false;
371 372 373 374 375 376 377 378
                                Qt.quit();
                            }
                        }
                    }
                }
                // VKB delay slider
                Rectangle {
                    id: vkbDelaySliderArea
Pekka Vuorela's avatar
Pekka Vuorela committed
379

380
                    width: menuBlocksRow.width
381 382
                    height: window.buttonHeightLarge
                    radius: window.radiusSmall
383 384 385
                    color: "#606060"
                    border.color: "#000000"
                    border.width: 1
Pekka Vuorela's avatar
Pekka Vuorela committed
386

387 388
                    Text {
                        width: parent.width
389
                        height: window.headerHeight
390
                        color: "#ffffff"
391
                        font.pointSize: window.uiFontSize-1
392
                        text: "VKB delay: " + vkbDelaySlider.keyboardFadeOutDelay + " ms"
393 394 395
                        horizontalAlignment: Text.AlignHCenter
                    }
                    Rectangle {
396
                        x: window.paddingSmall
397
                        y: vkbDelaySlider.y + vkbDelaySlider.height/2 - height/2
398 399 400
                        width: menuBlocksRow.width - window.paddingMedium
                        height: window.paddingMedium
                        radius: window.radiusSmall
401 402 403 404
                        color: "#909090"
                    }
                    Rectangle {
                        id: vkbDelaySlider
Pekka Vuorela's avatar
Pekka Vuorela committed
405

406
                        property int keyboardFadeOutDelay: util.keyboardFadeOutDelay
Pekka Vuorela's avatar
Pekka Vuorela committed
407

408 409 410 411
                        y: window.headerHeight
                        width: window.buttonWidthSmall
                        radius: window.radiusLarge
                        height: parent.height-window.headerHeight
412 413 414
                        color: "#202020"
                        onXChanged: {
                            if (vkbDelaySliderMA.drag.active)
415
                                vkbDelaySlider.keyboardFadeOutDelay =
416 417
                                        Math.floor((1000+vkbDelaySlider.x/vkbDelaySliderMA.drag.maximumX*9000)/250)*250;
                        }
418 419 420 421
                        Component.onCompleted: {
                            x = (keyboardFadeOutDelay-1000)/9000 * (vkbDelaySliderArea.width - vkbDelaySlider.width)
                        }

422 423 424 425 426 427 428 429 430
                        MouseArea {
                            id: vkbDelaySliderMA
                            anchors.fill: parent
                            drag.target: vkbDelaySlider
                            drag.axis: Drag.XAxis
                            drag.minimumX: 0
                            drag.maximumX: vkbDelaySliderArea.width - vkbDelaySlider.width
                            drag.onActiveChanged: {
                                if (!drag.active) {
431
                                    util.keyboardFadeOutDelay = vkbDelaySlider.keyboardFadeOutDelay
432 433 434 435 436 437 438 439 440
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}