summaryrefslogtreecommitdiffstats
path: root/framework/qml/ComboBox.qml
diff options
context:
space:
mode:
Diffstat (limited to 'framework/qml/ComboBox.qml')
-rw-r--r--framework/qml/ComboBox.qml95
1 files changed, 95 insertions, 0 deletions
diff --git a/framework/qml/ComboBox.qml b/framework/qml/ComboBox.qml
new file mode 100644
index 00000000..9fea0ca3
--- /dev/null
+++ b/framework/qml/ComboBox.qml
@@ -0,0 +1,95 @@
1/*
2 * Copyright (C) 2017 Michael Bohlender, <bohlender@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 2.0
21import QtQuick.Templates 2.0 as T
22import org.kube.framework 1.0
23
24T.ComboBox {
25 id: root
26
27 implicitWidth: Units.gridUnit * 10
28 implicitHeight: Units.gridUnit + Units.smallSpacing * 2
29
30 baselineOffset: contentItem.y + contentItem.baselineOffset
31
32 spacing: Units.largeSpacing
33 padding: Units.smallSpacing
34
35 contentItem: Text {
36 leftPadding: Units.smallSpacing
37 rightPadding: Units.largeSpacing
38
39 color: Colors.textColor
40 text: root.displayText
41 //TODO font:
42 horizontalAlignment: Text.AlignLeft
43 verticalAlignment: Text.AlignVCenter
44 elide: Text.ElideRight
45 }
46
47 indicator: Icon {
48 x: root.mirrored ? root.leftPadding : root.width - width - root.rightPadding
49 y: root.topPadding + (root.availableHeight - height) / 2
50 iconName: Icons.goDown
51 }
52
53 background: Rectangle {
54 border.width: 1
55 border.color: Colors.buttonColor
56 color: Colors.viewBackgroundColor
57 }
58
59 popup: T.Popup {
60 width: root.width
61 implicitHeight: Math.min(Units.gridUnit * 5, contentItem.implicitHeight)
62
63 contentItem: ListView {
64 clip: true
65 implicitHeight: contentHeight
66 model: root.popup.visible ? root.delegateModel : null
67 currentIndex: root.highlightedIndex
68 //FIXME use Kube.Scrollbar once available
69 T.ScrollIndicator.vertical: ScrollIndicator { }
70 }
71
72 background: Rectangle {
73 color: Colors.backgroundColor
74 border.color: Colors.buttonColor
75 border.width: 1
76 }
77 }
78
79 delegate: T.ItemDelegate {
80 width: root.popup.width
81 height: Units.gridUnit * 1.5
82
83 contentItem: Text {
84 padding: Units.smallSpacing
85 text: root.textRole ? (Array.isArray(root.model) ? modelData[root.textRole] : model[root.textRole]) : modelData
86 color: root.highlightedIndex === index ? Colors.highlightedTextColor : Colors.textColor
87 }
88
89 background: Rectangle {
90 color: root.highlightedIndex === index ? Colors.highlightColor : Colors.viewBackgroundColor
91 border.width: 1
92 border.color: Colors.buttonColor
93 }
94 }
95}