summaryrefslogtreecommitdiffstats
path: root/components/package
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-17 12:04:41 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-17 17:57:36 +0100
commit56d0411b0a8bce305220adbf12f6b859abf9f431 (patch)
treeec1e6aeb0bd1b73b6c59d48eb3fa9d623a69a0b4 /components/package
parentc633f7c5fce50db60035792526b6c7e84b51149f (diff)
downloadkube-56d0411b0a8bce305220adbf12f6b859abf9f431.tar.gz
kube-56d0411b0a8bce305220adbf12f6b859abf9f431.zip
AutocompleteLineEdit
Diffstat (limited to 'components/package')
-rw-r--r--components/package/contents/ui/AutocompleteLineEdit.qml144
-rw-r--r--components/package/contents/ui/FocusComposer.qml35
2 files changed, 167 insertions, 12 deletions
diff --git a/components/package/contents/ui/AutocompleteLineEdit.qml b/components/package/contents/ui/AutocompleteLineEdit.qml
new file mode 100644
index 00000000..173a006c
--- /dev/null
+++ b/components/package/contents/ui/AutocompleteLineEdit.qml
@@ -0,0 +1,144 @@
1/*
2 Copyright (C) 2016 Christian Mollekopf, <mollekopf@kolabsys.com>
3
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
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19import QtQuick 2.7
20import QtQuick.Controls 1.4
21import QtQuick.Controls 2.0 as Controls2
22import QtQuick.Layouts 1.1
23import QtQuick.Dialogs 1.0
24
25import org.kde.kirigami 1.0 as Kirigami
26
27TextField {
28 id: textField
29
30 property string searchTerm
31 property variant model
32 onTextChanged: {
33 if (text.length >= 2) {
34 searchTerm = text
35 startCompleting()
36 } else {
37 searchTerm = ""
38 abort()
39 }
40 }
41 Keys.onDownPressed: {
42 listView.incrementCurrentIndex()
43 }
44 Keys.onUpPressed: {
45 listView.decrementCurrentIndex()
46 }
47 Keys.onRightPressed: {
48 startCompleting()
49 }
50 Keys.onTabPressed: {
51 if (popup.visible) {
52 listView.incrementCurrentIndex()
53 } else {
54 event.accepted = false
55 }
56 }
57 Keys.onReturnPressed: {
58 accept()
59 }
60 Keys.onEscapePressed: {
61 abort()
62 }
63
64 function startCompleting() {
65 if (!popup.visible) {
66 popup.open()
67 listView.currentIndex = -1
68 }
69 }
70
71 function accept() {
72 textField.text = listView.currentItem.text;
73 popup.close()
74 }
75
76 function abort() {
77 popup.close()
78 }
79
80 Controls2.Popup {
81 id: popup
82 x: 0
83 y: textField.y + textField.height
84 padding: 0
85 contentWidth: rect.width
86 contentHeight: rect.height
87
88 Rectangle {
89 color: Kirigami.Theme.backgroundColor
90 id: rect
91 anchors.top: popup.top
92 anchors.left: popup.left
93 height: listView.contentHeight
94 width: textField.width
95 border.color: "Black"
96 radius: 5
97 ScrollView {
98 id: scrollView
99 anchors.fill: parent
100 ListView {
101 id: listView
102 height: childrenRect.height
103 width: scrollView.width
104 interactive: true
105 model: textField.model
106 delegate: Kirigami.AbstractListItem {
107 id: listDelegate
108 property string text: model.text
109
110 width: listView.width
111 height: textField.height
112
113 enabled: true
114 supportsMouseEvents: true
115
116 checked: listView.currentIndex == index
117 onClicked: {
118 listView.currentIndex = model.index
119 accept()
120 }
121
122 //Content
123 Item {
124 width: parent.width
125 height: parent.height
126
127 Column {
128 anchors {
129 verticalCenter: parent.verticalCenter
130 left: parent.left
131 }
132
133 Text{
134 text: model.text
135 color: listDelegate.checked ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
136 }
137 }
138 }
139 }
140 }
141 }
142 }
143 }
144}
diff --git a/components/package/contents/ui/FocusComposer.qml b/components/package/contents/ui/FocusComposer.qml
index 741faeba..f2ec2826 100644
--- a/components/package/contents/ui/FocusComposer.qml
+++ b/components/package/contents/ui/FocusComposer.qml
@@ -93,29 +93,30 @@ Controls2.Popup {
93 text: "To" 93 text: "To"
94 } 94 }
95 95
96 RowLayout { 96 AutocompleteLineEdit {
97 Layout.fillWidth: true 97 id: to
98
99 Controls.TextField {
100 id: to
101 98
102 Layout.fillWidth: true 99 Layout.fillWidth: true
103 100
104 text: composer.to 101 text: composer.to
102 onTextChanged: {
103 composer.to = text;
104 }
105 105
106 onTextChanged: { 106 model: composer.recepientAutocompletionModel
107 composer.to = text; 107 onSearchTermChanged: {
108 } 108 composer.recepientSearchString = searchTerm
109 } 109 }
110 } 110 }
111 111
112
112 Kirigami.Label { 113 Kirigami.Label {
113 text: "Cc" 114 text: "Cc"
114 115
115 visible: cc.visible 116 visible: cc.visible
116 } 117 }
117 118
118 Controls.TextField { 119 AutocompleteLineEdit {
119 id: cc 120 id: cc
120 121
121 Layout.fillWidth: true 122 Layout.fillWidth: true
@@ -127,6 +128,11 @@ Controls2.Popup {
127 onTextChanged: { 128 onTextChanged: {
128 composer.cc = text; 129 composer.cc = text;
129 } 130 }
131
132 model: composer.recepientAutocompletionModel
133 onSearchTermChanged: {
134 composer.recepientSearchString = searchTerm
135 }
130 } 136 }
131 137
132 Kirigami.Label { 138 Kirigami.Label {
@@ -135,7 +141,7 @@ Controls2.Popup {
135 visible: bcc.visible 141 visible: bcc.visible
136 } 142 }
137 143
138 Controls.TextField { 144 AutocompleteLineEdit {
139 id: bcc 145 id: bcc
140 146
141 Layout.fillWidth: true 147 Layout.fillWidth: true
@@ -147,6 +153,11 @@ Controls2.Popup {
147 onTextChanged: { 153 onTextChanged: {
148 composer.bcc = text; 154 composer.bcc = text;
149 } 155 }
156
157 model: composer.recepientAutocompletionModel
158 onSearchTermChanged: {
159 composer.recepientSearchString = searchTerm
160 }
150 } 161 }
151 } 162 }
152 163