From 675ddb2e2e37683fb5dea1a6713b623c9d724fab Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 17 Jun 2019 21:01:50 +0300 Subject: [PATCH] provide more modern Screens ComboBox --- declarativeimports/components/ComboBox.qml | 119 ++++++++++++--------- 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/declarativeimports/components/ComboBox.qml b/declarativeimports/components/ComboBox.qml index afa917a21..a32e8808f 100644 --- a/declarativeimports/components/ComboBox.qml +++ b/declarativeimports/components/ComboBox.qml @@ -21,6 +21,7 @@ import QtQuick 2.7 import QtQuick.Window 2.2 import QtQuick.Templates 2.2 as T import QtQuick.Controls 2.2 as Controls +import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kirigami 2.5 as Kirigami @@ -83,14 +84,14 @@ T.ComboBox { elementId: "down-arrow" } -// contentItem: Label { -// text: control.displayText -// font: control.font -// color: theme.buttonTextColor -// horizontalAlignment: Text.AlignLeft -// verticalAlignment: Text.AlignVCenter -// elide: Text.ElideRight -// } + // contentItem: Label { + // text: control.displayText + // font: control.font + // color: theme.buttonTextColor + // horizontalAlignment: Text.AlignLeft + // verticalAlignment: Text.AlignVCenter + // elide: Text.ElideRight + // } contentItem: MouseArea { id: mouseArea anchors.fill: parent @@ -144,52 +145,70 @@ T.ComboBox { control.pressed = false; } } - T.TextField { - id: textField - padding: 0 - anchors { - fill:parent - leftMargin: control.leftPadding - rightMargin: control.rightPadding - topMargin: control.topPadding - bottomMargin: control.bottomPadding + RowLayout { + anchors.fill: parent + + PlasmaCore.IconItem { + id: selectedIcon + Layout.leftMargin: 2 + + width: textField.height + height: textField.height + + colorGroup: PlasmaCore.Theme.ButtonColorGroup + source: control.iconRole === "icon" ? control.model.get(control.currentIndex).icon : '' + + visible: source !== '' } - text: control.editable ? control.editText : control.displayText - - enabled: control.editable - autoScroll: control.editable - - readOnly: control.down || !control.hasOwnProperty("editable") || !control.editable - inputMethodHints: control.inputMethodHints - validator: control.validator - - // Work around Qt bug where NativeRendering breaks for non-integer scale factors - // https://bugreports.qt.io/browse/QTBUG-67007 - renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering - color: theme.buttonTextColor //control.enabled ? theme.textColor : theme.disabledTextColor - selectionColor: Kirigami.Theme.highlightColor - selectedTextColor: Kirigami.Theme.highlightedTextColor - - selectByMouse: !Kirigami.Settings.tabletMode - cursorDelegate: Kirigami.Settings.tabletMode ? mobileCursor : undefinedCursor - - font: control.font - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - opacity: control.enabled ? 1 : 0.6 - onFocusChanged: { - if (focus) { - Private.MobileTextActionsToolBar.controlRoot = textField; + + T.TextField { + id: textField + padding: 0 + Layout.fillWidth: true + Layout.fillHeight: true + + Layout.leftMargin: selectedIcon.visible ? 0 : control.leftPadding + Layout.rightMargin: control.rightPadding + Layout.topMargin: control.topPadding + Layout.bottomMargin: control.bottomPadding + + text: control.editable ? control.editText : control.displayText + + enabled: control.editable + autoScroll: control.editable + + readOnly: control.down || !control.hasOwnProperty("editable") || !control.editable + inputMethodHints: control.inputMethodHints + validator: control.validator + + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering + color: theme.buttonTextColor //control.enabled ? theme.textColor : theme.disabledTextColor + selectionColor: Kirigami.Theme.highlightColor + selectedTextColor: Kirigami.Theme.highlightedTextColor + + selectByMouse: !Kirigami.Settings.tabletMode + cursorDelegate: Kirigami.Settings.tabletMode ? mobileCursor : undefinedCursor + + font: control.font + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + opacity: control.enabled ? 1 : 0.6 + onFocusChanged: { + if (focus) { + Private.MobileTextActionsToolBar.controlRoot = textField; + } } - } - onPressAndHold: { - if (!Kirigami.Settings.tabletMode) { - return; + onPressAndHold: { + if (!Kirigami.Settings.tabletMode) { + return; + } + forceActiveFocus(); + cursorPosition = positionAt(event.x, event.y); + selectWord(); } - forceActiveFocus(); - cursorPosition = positionAt(event.x, event.y); - selectWord(); } } }