File: WordRibbon.qml

package info (click to toggle)
maliit-keyboard 2.3.1-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 40,348 kB
  • sloc: cpp: 9,618; python: 1,548; javascript: 291; xml: 112; makefile: 16; sh: 6
file content (115 lines) | stat: -rw-r--r-- 3,650 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright 2013 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4

import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12

import MaliitKeyboard 2.0

Page {

    id: wordRibbonCanvas
    objectName: "wordRibbenCanvas"
    anchors.margins: 0

    ListView {
        id: listView
        objectName: "wordListView"
        anchors.fill: parent

        model: WordModel

        orientation: ListView.Horizontal
        delegate: wordCandidateDelegate

        leftMargin: Device.gu(1)
        rightMargin: Device.gu(1)
        topMargin: 0
        bottomMargin: Device.top_margin * 2
        spacing: Device.gu(2)
    }

    // Invisible components to get normal and selection colors from the current
    // qqc2 style for showing visual feedback of selected word completion
    TextField {
        id: textArea
        width: 0
        height: 0
        visible: false
    }
    Label {
        id: label
        width: 0
        height: 0
        visible: false
    }

    Component {
        id: wordCandidateDelegate
        RowLayout {
            id: wordCandidateItem
            // Use 1/3 of pixel height of parent converted to grid units
            // as a minimum width threshhold, so that short suggestions
            // are wide enough to tap with a thumb
            width: Math.max(Device.gu(height / 3), wordItem.width)
            height: wordRibbonCanvas.height
            spacing: listView.spacing

            Label {
                id: wordItem

                Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                Layout.fillHeight: true

                font.bold: isPrimaryCandidate || listView.count == 1
                font.pixelSize: parent.height - Device.top_margin * 4
                text: word
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

                MouseArea {
                    anchors.fill: parent
                    onPressed: {
                        wordItem.color = textArea.selectionColor;
                        Feedback.keyPressed();
                        event_handler.onWordCandidatePressed(wordItem.text, isUserInput)
                    }
                    onReleased: {
                        wordItem.color = label.color;
                        event_handler.onWordCandidateReleased(wordItem.text, isUserInput)
                    }
                    onPositionChanged: {
                        wordItem.color = label.color;
                    }
                }
            }

            // FIXME: ListView doesn't support separators directly so we need
            // to be a little hacky to add a muted separator between word
            // candidates, so that multi-word suggestions are distinct
            Rectangle {
                Layout.alignment: Qt.AlignVCenter
                width: 1
                height: parent.height * 0.5
                color: wordItem.color
                opacity: 0.3
                visible: index != listView.count - 1
            }
        }
    }
}