Warning, /maui/nomad-style/ComboBox.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2017 Marco Martin <mart@kde.org> 0003 * Copyright 2017 The Qt Company Ltd. 0004 * 0005 * GNU Lesser General Public License Usage 0006 * Alternatively, this file may be used under the terms of the GNU Lesser 0007 * General Public License version 3 as published by the Free Software 0008 * Foundation and appearing in the file LICENSE.LGPLv3 included in the 0009 * packaging of this file. Please review the following information to 0010 * ensure the GNU Lesser General Public License version 3 requirements 0011 * will be met: https://www.gnu.org/licenses/lgpl.html. 0012 * 0013 * GNU General Public License Usage 0014 * Alternatively, this file may be used under the terms of the GNU 0015 * General Public License version 2.0 or later as published by the Free 0016 * Software Foundation and appearing in the file LICENSE.GPL included in 0017 * the packaging of this file. Please review the following information to 0018 * ensure the GNU General Public License version 2.0 requirements will be 0019 * met: http://www.gnu.org/licenses/gpl-2.0.html. 0020 */ 0021 0022 0023 import QtQuick 2.6 0024 import QtQuick.Window 2.2 0025 import QtQuick.Templates 2.3 as T 0026 import QtQuick.Controls 2.3 as Controls 0027 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate 0028 import QtGraphicalEffects 1.0 0029 import org.kde.kirigami 2.2 as Kirigami 0030 0031 T.ComboBox { 0032 id: controlRoot 0033 //NOTE: typeof necessary to not have warnings on Qt 5.7 0034 Kirigami.Theme.colorSet: typeof(editable) != "undefined" && editable ? Kirigami.Theme.View : Kirigami.Theme.Button 0035 Kirigami.Theme.inherit: false 0036 0037 implicitWidth: background.implicitWidth + leftPadding + rightPadding 0038 implicitHeight: background.implicitHeight 0039 baselineOffset: contentItem.y + contentItem.baselineOffset 0040 0041 hoverEnabled: true 0042 padding: 5 0043 leftPadding: padding + 5 0044 rightPadding: padding + 5 0045 0046 delegate: ItemDelegate { 0047 width: controlRoot.popup.width 0048 text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData 0049 highlighted: controlRoot.highlightedIndex == index 0050 property bool separatorVisible: false 0051 Kirigami.Theme.colorSet: controlRoot.Kirigami.Theme.inherit ? controlRoot.Kirigami.Theme.colorSet : Kirigami.Theme.View 0052 Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit 0053 } 0054 0055 indicator: Item {} 0056 0057 contentItem: MouseArea { 0058 onPressed: mouse.accepted = false; 0059 onWheel: { 0060 if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) { 0061 controlRoot.currentIndex = (controlRoot.currentIndex + 1) % delegateModel.count 0062 } else { 0063 controlRoot.currentIndex = (controlRoot.currentIndex - 1 + delegateModel.count) % delegateModel.count 0064 } 0065 } 0066 T.TextField { 0067 anchors { 0068 fill: parent 0069 leftMargin: controlRoot.mirrored ? 12 : 1 0070 rightMargin: !controlRoot.mirrored ? 12 : 1 0071 } 0072 0073 text: controlRoot.editText 0074 0075 visible: typeof(controlRoot.editable) != "undefined" && controlRoot.editable 0076 readOnly: controlRoot.popup.visible 0077 inputMethodHints: controlRoot.inputMethodHints 0078 validator: controlRoot.validator 0079 renderType: Window.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering 0080 color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0081 selectionColor: Kirigami.Theme.highlightColor 0082 selectedTextColor: Kirigami.Theme.highlightedTextColor 0083 selectByMouse: true 0084 0085 font: controlRoot.font 0086 horizontalAlignment: Text.AlignLeft 0087 verticalAlignment: Text.AlignVCenter 0088 opacity: controlRoot.enabled ? 1 : 0.3 0089 } 0090 } 0091 0092 background: StylePrivate.StyleItem { 0093 id: styleitem 0094 control: controlRoot 0095 elementType: "combobox" 0096 anchors.fill: parent 0097 hover: controlRoot.hovered 0098 sunken: controlRoot.pressed 0099 raised: !sunken 0100 hasFocus: controlRoot.activeFocus 0101 enabled: controlRoot.enabled 0102 // contentHeight as in QComboBox magic numbers taken from QQC1 style 0103 contentHeight: Math.max(Math.ceil(textHeight("")), 14) + 2 0104 text: controlRoot.displayText 0105 properties: { 0106 "editable" : control.editable 0107 } 0108 } 0109 0110 popup: T.Popup { 0111 y: controlRoot.height 0112 width: Math.max(controlRoot.width, 150) 0113 implicitHeight: contentItem.implicitHeight 0114 topMargin: 6 0115 bottomMargin: 6 0116 Kirigami.Theme.colorSet: Kirigami.Theme.View 0117 Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit 0118 0119 contentItem: ListView { 0120 id: listview 0121 clip: true 0122 implicitHeight: contentHeight 0123 model: controlRoot.popup.visible ? controlRoot.delegateModel : null 0124 currentIndex: controlRoot.highlightedIndex 0125 highlightRangeMode: ListView.ApplyRange 0126 highlightMoveDuration: 0 0127 T.ScrollBar.vertical: Controls.ScrollBar { } 0128 } 0129 background: Rectangle { 0130 anchors { 0131 fill: parent 0132 margins: -1 0133 } 0134 radius: 2 0135 color: Kirigami.Theme.backgroundColor 0136 property color borderColor: Kirigami.Theme.textColor 0137 border.color: Qt.rgba(borderColor.r, borderColor.g, borderColor.b, 0.3) 0138 layer.enabled: true 0139 0140 layer.effect: DropShadow { 0141 transparentBorder: true 0142 radius: 4 0143 samples: 8 0144 horizontalOffset: 2 0145 verticalOffset: 2 0146 color: Qt.rgba(0, 0, 0, 0.3) 0147 } 0148 } 0149 } 0150 }