Changeset View
Changeset View
Standalone View
Standalone View
org.kde.desktop/ComboBox.qml
Show All 16 Lines | |||||
17 | * the packaging of this file. Please review the following information to | 17 | * the packaging of this file. Please review the following information to | ||
18 | * ensure the GNU General Public License version 2.0 requirements will be | 18 | * ensure the GNU General Public License version 2.0 requirements will be | ||
19 | * met: http://www.gnu.org/licenses/gpl-2.0.html. | 19 | * met: http://www.gnu.org/licenses/gpl-2.0.html. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | 22 | | |||
23 | import QtQuick 2.6 | 23 | import QtQuick 2.6 | ||
24 | import QtQuick.Window 2.2 | 24 | import QtQuick.Window 2.2 | ||
25 | import QtQuick.Templates 2.0 as T | 25 | import QtQuick.Templates @QQC2_VERSION@ as T | ||
26 | import QtQuick.Controls 2.0 as Controls | 26 | import QtQuick.Controls @QQC2_VERSION@ as Controls | ||
27 | import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate | 27 | import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate | ||
28 | import QtGraphicalEffects 1.0 | 28 | import QtGraphicalEffects 1.0 | ||
29 | import org.kde.kirigami 2.2 as Kirigami | 29 | import org.kde.kirigami 2.2 as Kirigami | ||
30 | 30 | | |||
31 | T.ComboBox { | 31 | T.ComboBox { | ||
32 | id: controlRoot | 32 | id: controlRoot | ||
33 | Kirigami.Theme.colorSet: Kirigami.Theme.Button | 33 | //NOTE: typeof necessary to not have warnings on Qt 5.7 | ||
34 | Kirigami.Theme.colorSet: typeof(editable) != "undefined" && editable ? Kirigami.Theme.View : Kirigami.Theme.Button | ||||
34 | Kirigami.Theme.inherit: false | 35 | Kirigami.Theme.inherit: false | ||
35 | 36 | | |||
36 | implicitWidth: background.implicitWidth + leftPadding + rightPadding | 37 | implicitWidth: background.implicitWidth + leftPadding + rightPadding | ||
37 | implicitHeight: background.implicitHeight | 38 | implicitHeight: background.implicitHeight | ||
38 | baselineOffset: contentItem.y + contentItem.baselineOffset | 39 | baselineOffset: contentItem.y + contentItem.baselineOffset | ||
39 | 40 | | |||
40 | hoverEnabled: true | 41 | hoverEnabled: true | ||
41 | padding: 5 | 42 | padding: 5 | ||
Show All 15 Lines | 57 | contentItem: MouseArea { | |||
57 | onPressed: mouse.accepted = false; | 58 | onPressed: mouse.accepted = false; | ||
58 | onWheel: { | 59 | onWheel: { | ||
59 | if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) { | 60 | if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) { | ||
60 | controlRoot.currentIndex = (controlRoot.currentIndex + 1) % delegateModel.count | 61 | controlRoot.currentIndex = (controlRoot.currentIndex + 1) % delegateModel.count | ||
61 | } else { | 62 | } else { | ||
62 | controlRoot.currentIndex = (controlRoot.currentIndex - 1 + delegateModel.count) % delegateModel.count | 63 | controlRoot.currentIndex = (controlRoot.currentIndex - 1 + delegateModel.count) % delegateModel.count | ||
63 | } | 64 | } | ||
64 | } | 65 | } | ||
66 | T.TextField { | ||||
67 | anchors { | ||||
68 | fill: parent | ||||
69 | leftMargin: controlRoot.mirrored ? 12 : 1 | ||||
70 | rightMargin: !controlRoot.mirrored ? 12 : 1 | ||||
71 | } | ||||
72 | | ||||
73 | text: controlRoot.editText | ||||
74 | | ||||
75 | visible: typeof(controlRoot.editable) != "undefined" && controlRoot.editable | ||||
76 | readOnly: controlRoot.popup.visible | ||||
77 | inputMethodHints: controlRoot.inputMethodHints | ||||
78 | validator: controlRoot.validator | ||||
79 | renderType: Window.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering | ||||
80 | color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor | ||||
81 | selectionColor: Kirigami.Theme.highlightColor | ||||
82 | selectedTextColor: Kirigami.Theme.highlightedTextColor | ||||
83 | selectByMouse: true | ||||
84 | | ||||
85 | font: controlRoot.font | ||||
86 | horizontalAlignment: Text.AlignLeft | ||||
87 | verticalAlignment: Text.AlignVCenter | ||||
88 | opacity: controlRoot.enabled ? 1 : 0.3 | ||||
89 | } | ||||
65 | } | 90 | } | ||
66 | 91 | | |||
67 | background: StylePrivate.StyleItem { | 92 | background: StylePrivate.StyleItem { | ||
68 | id: styleitem | 93 | id: styleitem | ||
69 | control: controlRoot | 94 | control: controlRoot | ||
70 | elementType: "combobox" | 95 | elementType: "combobox" | ||
71 | anchors.fill: parent | 96 | anchors.fill: parent | ||
72 | hover: controlRoot.hovered | 97 | hover: controlRoot.hovered | ||
73 | sunken: controlRoot.pressed | 98 | sunken: controlRoot.pressed | ||
74 | raised: !sunken | 99 | raised: !sunken | ||
75 | hasFocus: controlRoot.activeFocus | 100 | hasFocus: controlRoot.activeFocus | ||
76 | enabled: controlRoot.enabled | 101 | enabled: controlRoot.enabled | ||
77 | // contentHeight as in QComboBox magic numbers taken from QQC1 style | 102 | // contentHeight as in QComboBox magic numbers taken from QQC1 style | ||
78 | contentHeight: Math.max(Math.ceil(textHeight("")), 14) + 2 | 103 | contentHeight: Math.max(Math.ceil(textHeight("")), 14) + 2 | ||
79 | text: controlRoot.displayText | 104 | text: controlRoot.displayText | ||
105 | properties: { | ||||
106 | "editable" : control.editable | ||||
107 | } | ||||
80 | } | 108 | } | ||
81 | 109 | | |||
82 | popup: T.Popup { | 110 | popup: T.Popup { | ||
83 | y: controlRoot.height | 111 | y: controlRoot.height | ||
84 | width: Math.max(controlRoot.width, 150) | 112 | width: Math.max(controlRoot.width, 150) | ||
85 | implicitHeight: contentItem.implicitHeight | 113 | implicitHeight: contentItem.implicitHeight | ||
86 | topMargin: 6 | 114 | topMargin: 6 | ||
87 | bottomMargin: 6 | 115 | bottomMargin: 6 | ||
Show All 35 Lines |