This repository has been archived by the owner on Oct 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ComboBox.qml
executable file
·150 lines (135 loc) · 5.64 KB
/
ComboBox.qml
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright 2017 Marco Martin <mart@kde.org>
* Copyright 2017 The Qt Company Ltd.
*
* GNU Lesser General Public License Usage
* Alternatively, this file may be used under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.LGPLv3 included in the
* packaging of this file. Please review the following information to
* ensure the GNU Lesser General Public License version 3 requirements
* will be met: https://www.gnu.org/licenses/lgpl.html.
*
* GNU General Public License Usage
* Alternatively, this file may be used under the terms of the GNU
* General Public License version 2.0 or later as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information to
* ensure the GNU General Public License version 2.0 requirements will be
* met: http://www.gnu.org/licenses/gpl-2.0.html.
*/
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Templates 2.3 as T
import QtQuick.Controls 2.3 as Controls
import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
import QtGraphicalEffects 1.0
import org.kde.kirigami 2.2 as Kirigami
T.ComboBox {
id: controlRoot
//NOTE: typeof necessary to not have warnings on Qt 5.7
Kirigami.Theme.colorSet: typeof(editable) != "undefined" && editable ? Kirigami.Theme.View : Kirigami.Theme.Button
Kirigami.Theme.inherit: false
implicitWidth: background.implicitWidth + leftPadding + rightPadding
implicitHeight: background.implicitHeight
baselineOffset: contentItem.y + contentItem.baselineOffset
hoverEnabled: true
padding: 5
leftPadding: padding + 5
rightPadding: padding + 5
delegate: ItemDelegate {
width: controlRoot.popup.width
text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData
highlighted: controlRoot.highlightedIndex == index
property bool separatorVisible: false
Kirigami.Theme.colorSet: controlRoot.Kirigami.Theme.inherit ? controlRoot.Kirigami.Theme.colorSet : Kirigami.Theme.View
Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit
}
indicator: Item {}
contentItem: MouseArea {
onPressed: mouse.accepted = false;
onWheel: {
if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) {
controlRoot.currentIndex = (controlRoot.currentIndex + 1) % delegateModel.count
} else {
controlRoot.currentIndex = (controlRoot.currentIndex - 1 + delegateModel.count) % delegateModel.count
}
}
T.TextField {
anchors {
fill: parent
leftMargin: controlRoot.mirrored ? 12 : 1
rightMargin: !controlRoot.mirrored ? 12 : 1
}
text: controlRoot.editText
visible: typeof(controlRoot.editable) != "undefined" && controlRoot.editable
readOnly: controlRoot.popup.visible
inputMethodHints: controlRoot.inputMethodHints
validator: controlRoot.validator
renderType: Window.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
selectionColor: Kirigami.Theme.highlightColor
selectedTextColor: Kirigami.Theme.highlightedTextColor
selectByMouse: true
font: controlRoot.font
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
opacity: controlRoot.enabled ? 1 : 0.3
}
}
background: StylePrivate.StyleItem {
id: styleitem
control: controlRoot
elementType: "combobox"
anchors.fill: parent
hover: controlRoot.hovered
sunken: controlRoot.pressed
raised: !sunken
hasFocus: controlRoot.activeFocus
enabled: controlRoot.enabled
// contentHeight as in QComboBox magic numbers taken from QQC1 style
contentHeight: Math.max(Math.ceil(textHeight("")), 14) + 2
text: controlRoot.displayText
properties: {
"editable" : control.editable
}
}
popup: T.Popup {
y: controlRoot.height
width: Math.max(controlRoot.width, 150)
implicitHeight: contentItem.implicitHeight
topMargin: 6
bottomMargin: 6
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit
contentItem: ListView {
id: listview
clip: true
implicitHeight: contentHeight
model: controlRoot.popup.visible ? controlRoot.delegateModel : null
currentIndex: controlRoot.highlightedIndex
highlightRangeMode: ListView.ApplyRange
highlightMoveDuration: 0
T.ScrollBar.vertical: Controls.ScrollBar { }
}
background: Rectangle {
anchors {
fill: parent
margins: -1
}
radius: 2
color: Kirigami.Theme.backgroundColor
property color borderColor: Kirigami.Theme.textColor
border.color: Qt.rgba(borderColor.r, borderColor.g, borderColor.b, 0.3)
layer.enabled: true
layer.effect: DropShadow {
transparentBorder: true
radius: 4
samples: 8
horizontalOffset: 2
verticalOffset: 2
color: Qt.rgba(0, 0, 0, 0.3)
}
}
}
}