Changeset View
Changeset View
Standalone View
Standalone View
applets/kimpanel/package/contents/ui/InputPanel.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2014 Weng Xuetian <wengxt@gmail.com> | 2 | * Copyright 2014-2017 Weng Xuetian <wengxt@gmail.com> | ||
3 | * | 3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | 6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | 7 | * (at your option) any later version. | ||
8 | * | 8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | import QtQuick 2.0 | 19 | import QtQuick 2.6 | ||
20 | import QtQuick.Layouts 1.1 | 20 | import QtQuick.Layouts 1.1 | ||
21 | import org.kde.plasma.plasmoid 2.0 | 21 | import org.kde.plasma.plasmoid 2.0 | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | 23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
24 | import org.kde.plasma.private.kimpanel 0.1 as Kimpanel | 24 | import org.kde.plasma.private.kimpanel 0.1 as Kimpanel | ||
25 | 25 | | |||
26 | 26 | | |||
27 | PlasmaCore.Dialog { | 27 | PlasmaCore.Dialog { | ||
28 | id: inputpanel | 28 | id: inputpanel | ||
29 | type: PlasmaCore.Dialog.PopupMenu | 29 | type: PlasmaCore.Dialog.PopupMenu | ||
30 | flags: Qt.Popup | Qt.WindowStaysOnTopHint | Qt.WindowDoesNotAcceptFocus | 30 | flags: Qt.Popup | Qt.WindowStaysOnTopHint | Qt.WindowDoesNotAcceptFocus | ||
31 | location: PlasmaCore.Types.Floating | 31 | location: PlasmaCore.Types.Floating | ||
32 | property bool verticalLayout: false | 32 | property bool verticalLayout: false | ||
33 | property int highlightCandidate: -1 | 33 | property int highlightCandidate: -1 | ||
34 | property int hoveredCandidate: -1 | ||||
34 | property font preferredFont: plasmoid.configuration.use_default_font ? theme.defaultFont : plasmoid.configuration.font | 35 | property font preferredFont: plasmoid.configuration.use_default_font ? theme.defaultFont : plasmoid.configuration.font | ||
35 | property int baseSize: theme.mSize(preferredFont).height | 36 | property int baseSize: theme.mSize(preferredFont).height | ||
36 | property rect position | 37 | property rect position | ||
37 | 38 | | |||
38 | onPositionChanged : updatePosition(); | 39 | onPositionChanged : updatePosition(); | ||
39 | onWidthChanged : updatePosition(); | 40 | onWidthChanged : updatePosition(); | ||
40 | onHeightChanged : updatePosition(); | 41 | onHeightChanged : updatePosition(); | ||
41 | 42 | | |||
42 | mainItem: Column { | 43 | mainItem: Column { | ||
43 | Layout.minimumWidth: childrenRect.width | 44 | Layout.minimumWidth: childrenRect.width | ||
44 | Layout.minimumHeight: childrenRect.height | 45 | Layout.minimumHeight: childrenRect.height | ||
45 | Layout.maximumWidth: childrenRect.width | 46 | Layout.maximumWidth: childrenRect.width | ||
46 | Layout.maximumHeight: childrenRect.height | 47 | Layout.maximumHeight: childrenRect.height | ||
48 | | ||||
47 | Row { | 49 | Row { | ||
48 | id: textLabel | 50 | id: textLabel | ||
49 | width: auxLabel.width + preedit.width | 51 | width: auxLabel.width + preedit.width | ||
50 | height: Math.max(preedit.height, auxLabel.height) | 52 | height: Math.max(preedit.height, auxLabel.height) | ||
51 | PlasmaComponents.Label { | 53 | PlasmaComponents.Label { | ||
52 | id: auxLabel | 54 | id: auxLabel | ||
53 | font: preferredFont | 55 | font: preferredFont | ||
54 | } | 56 | } | ||
Show All 25 Lines | 57 | Item { | |||
80 | } | 82 | } | ||
81 | } | 83 | } | ||
82 | } | 84 | } | ||
83 | 85 | | |||
84 | GridLayout { | 86 | GridLayout { | ||
85 | flow: inputpanel.verticalLayout ? GridLayout.TopToBottom : GridLayout.LeftToRight | 87 | flow: inputpanel.verticalLayout ? GridLayout.TopToBottom : GridLayout.LeftToRight | ||
86 | columns: inputpanel.verticalLayout ? 1 : tableList.count + 1 | 88 | columns: inputpanel.verticalLayout ? 1 : tableList.count + 1 | ||
87 | rows: inputpanel.verticalLayout ? tableList.count + 1 : 1 | 89 | rows: inputpanel.verticalLayout ? tableList.count + 1 : 1 | ||
90 | columnSpacing: units.smallSpacing / 2 | ||||
91 | rowSpacing: units.smallSpacing / 2 | ||||
88 | Repeater { | 92 | Repeater { | ||
89 | model: ListModel { | 93 | model: ListModel { | ||
90 | id: tableList | 94 | id: tableList | ||
91 | dynamicRoles: true | 95 | dynamicRoles: true | ||
92 | } | 96 | } | ||
93 | delegate: Item { | 97 | delegate: Item { | ||
94 | width: candidate.width | 98 | width: candidate.width + highlight.marginHints.left + highlight.marginHints.right | ||
95 | height: candidate.height | 99 | height: candidate.height + highlight.marginHints.top + highlight.marginHints.bottom | ||
96 | Layout.minimumWidth: candidate.width | 100 | Layout.minimumWidth: width | ||
97 | Layout.minimumHeight: candidate.height | 101 | Layout.minimumHeight: height | ||
98 | Layout.maximumWidth: candidate.width | 102 | Layout.maximumWidth: width | ||
99 | Layout.maximumHeight: candidate.height | 103 | Layout.maximumHeight: height | ||
104 | | ||||
100 | Row { | 105 | Row { | ||
101 | id: candidate | 106 | id: candidate | ||
102 | width: childrenRect.width | 107 | width: childrenRect.width | ||
103 | height: childrenRect.height | 108 | height: childrenRect.height | ||
104 | property bool highlight: (inputpanel.highlightCandidate == model.index) != candidateMouseArea.containsMouse | 109 | x: highlight.marginHints.left | ||
110 | y: highlight.marginHints.top | ||||
105 | PlasmaComponents.Label { | 111 | PlasmaComponents.Label { | ||
106 | id: tableLabel | 112 | id: tableLabel | ||
107 | text: model.label | 113 | text: model.label | ||
108 | color: candidate.highlight ? theme.textColor : theme.highlightColor | | |||
109 | font: preferredFont | 114 | font: preferredFont | ||
115 | color: active ? theme.highlightedTextColor : theme.textColor | ||||
116 | opacity: highlight.visible ? 0.8 : 0.6 | ||||
110 | } | 117 | } | ||
111 | PlasmaComponents.Label { | 118 | PlasmaComponents.Label { | ||
112 | id: textLabel | 119 | id: textLabel | ||
113 | text: model.text | 120 | text: model.text | ||
114 | color: candidate.highlight ? theme.highlightColor : theme.textColor | | |||
115 | font: preferredFont | 121 | font: preferredFont | ||
122 | color: active ? theme.highlightedTextColor : theme.textColor | ||||
116 | } | 123 | } | ||
117 | } | 124 | } | ||
118 | MouseArea { | 125 | MouseArea { | ||
119 | id: candidateMouseArea | 126 | id: candidateMouseArea | ||
120 | anchors.fill: parent | 127 | anchors.fill: parent | ||
121 | hoverEnabled: true | 128 | hoverEnabled: true | ||
122 | onReleased: selectCandidate(model.index) | 129 | onReleased: selectCandidate(model.index) | ||
130 | onContainsMouseChanged: { | ||||
131 | inputpanel.hoveredCandidate = containsMouse ? model.index : -1; | ||||
132 | } | ||||
133 | } | ||||
134 | CandidateHighlight { | ||||
135 | id: highlight | ||||
136 | z: -1 | ||||
137 | visible: inputpanel.highlightCandidate == model.index || inputpanel.hoveredCandidate == model.index | ||||
138 | hover: candidateMouseArea.containsMouse | ||||
139 | selected: inputpanel.highlightCandidate == model.index || candidateMouseArea.pressed | ||||
140 | anchors { | ||||
141 | fill: parent | ||||
142 | } | ||||
123 | } | 143 | } | ||
124 | } | 144 | } | ||
125 | } | 145 | } | ||
126 | Row { | 146 | Row { | ||
127 | id: button | 147 | id: button | ||
128 | width: inputpanel.baseSize * 2 | 148 | width: inputpanel.baseSize * 2 | ||
129 | height: inputpanel.baseSize | 149 | height: inputpanel.baseSize | ||
130 | Layout.minimumWidth: width | 150 | Layout.minimumWidth: width | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 204 | function updateUI() { | |||
205 | auxLabel.text = (auxVisible && data["AuxText"]) ? data["AuxText"] : "" | 225 | auxLabel.text = (auxVisible && data["AuxText"]) ? data["AuxText"] : "" | ||
206 | var preeditText = (preeditVisible && data["PreeditText"]) ? data["PreeditText"] : "" | 226 | var preeditText = (preeditVisible && data["PreeditText"]) ? data["PreeditText"] : "" | ||
207 | var caret = data["CaretPos"] ? data["CaretPos"] : 0; | 227 | var caret = data["CaretPos"] ? data["CaretPos"] : 0; | ||
208 | preeditLabel1.text = preeditText.substring(0, caret); | 228 | preeditLabel1.text = preeditText.substring(0, caret); | ||
209 | preeditLabel2.text = preeditText.substring(caret); | 229 | preeditLabel2.text = preeditText.substring(caret); | ||
210 | preedit.visible = preeditVisible; | 230 | preedit.visible = preeditVisible; | ||
211 | var layout = data["LookupTableLayout"] !== undefined ? data["LookupTableLayout"] : 0; | 231 | var layout = data["LookupTableLayout"] !== undefined ? data["LookupTableLayout"] : 0; | ||
212 | inputpanel.highlightCandidate = data["LookupTableCursor"] !== undefined ? data["LookupTableCursor"] : -1; | 232 | inputpanel.highlightCandidate = data["LookupTableCursor"] !== undefined ? data["LookupTableCursor"] : -1; | ||
233 | inputpanel.hoveredCandidate = -1; | ||||
213 | inputpanel.verticalLayout = (layout === 1) || (layout == 0 && plasmoid.configuration.vertical_lookup_table); | 234 | inputpanel.verticalLayout = (layout === 1) || (layout == 0 && plasmoid.configuration.vertical_lookup_table); | ||
214 | button.visible = lookupTableVisible | 235 | button.visible = lookupTableVisible | ||
215 | 236 | | |||
216 | if (data["LookupTable"]) { | 237 | if (data["LookupTable"]) { | ||
217 | var table = data["LookupTable"]; | 238 | var table = data["LookupTable"]; | ||
218 | if (lookupTableVisible) { | 239 | if (lookupTableVisible) { | ||
219 | if (table.length < tableList.count) { | 240 | if (table.length < tableList.count) { | ||
220 | tableList.remove(table.length, tableList.count - table.length); | 241 | tableList.remove(table.length, tableList.count - table.length); | ||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |