diff --git a/org.kde.desktop/ComboBox.qml b/org.kde.desktop/ComboBox.qml index d6a2c3c..e7589f6 100644 --- a/org.kde.desktop/ComboBox.qml +++ b/org.kde.desktop/ComboBox.qml @@ -1,234 +1,234 @@ /* * Copyright 2017 Marco Martin * 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 @QQC2_VERSION@ as T import QtQuick.Controls @QQC2_VERSION@ as Controls import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate import QtGraphicalEffects 1.0 import org.kde.kirigami 2.4 as Kirigami import "private" as Private T.ComboBox { id: controlRoot @DISABLE_UNDER_QQC2_2_4@ palette: Kirigami.Theme.palette //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 + implicitWidth: Math.max(200, background.implicitWidth + leftPadding + rightPadding) implicitHeight: background.implicitHeight baselineOffset: contentItem.y + contentItem.baselineOffset hoverEnabled: true padding: 5 leftPadding: controlRoot.editable && controlRoot.mirrored ? 24 : padding rightPadding: controlRoot.editable && !controlRoot.mirrored ? 24 : padding delegate: ItemDelegate { width: controlRoot.popup.width text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData highlighted: mouseArea.pressed ? listView.currentIndex == index : 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 { id: mouseArea anchors.fill: parent acceptedButtons: Qt.LeftButton preventStealing: true property int indexUnderMouse: -1 onWheel: { if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) { controlRoot.currentIndex = Math.min(controlRoot.currentIndex + 1, delegateModel.count -1); } else { controlRoot.currentIndex = Math.max(controlRoot.currentIndex - 1, 0); } controlRoot.activated(controlRoot.currentIndex); } onPressed: { indexUnderMouse = -1; listView.currentIndex = controlRoot.highlightedIndex controlRoot.down = true; controlRoot.pressed = true; controlRoot.popup.visible = !controlRoot.popup.visible; } onReleased: { if (!containsMouse) { controlRoot.down = false; controlRoot.pressed = false; controlRoot.popup.visible = false; } if (indexUnderMouse > -1) { controlRoot.currentIndex = indexUnderMouse; controlRoot.activated(indexUnderMouse); } } onCanceled: { controlRoot.down = false; controlRoot.pressed = false; } onPositionChanged: { var pos = listView.mapFromItem(this, mouse.x, mouse.y); indexUnderMouse = listView.indexAt(pos.x, pos.y); listView.currentIndex = indexUnderMouse; } Connections { target: popup onClosed: { controlRoot.down = false; controlRoot.pressed = false; } } T.TextField { id: textField padding: 0 anchors { fill:parent leftMargin: controlRoot.leftPadding rightMargin: controlRoot.rightPadding topMargin: controlRoot.topPadding bottomMargin: controlRoot.bottomPadding } text: controlRoot.editable ? controlRoot.editText : controlRoot.displayText enabled: controlRoot.editable autoScroll: controlRoot.editable readOnly: controlRoot.down visible: typeof(controlRoot.editable) != "undefined" && controlRoot.editable inputMethodHints: controlRoot.inputMethodHints validator: controlRoot.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: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor selectionColor: Kirigami.Theme.highlightColor selectedTextColor: Kirigami.Theme.highlightedTextColor selectByMouse: !Kirigami.Settings.tabletMode cursorDelegate: Kirigami.Settings.tabletMode ? mobileCursor : undefined font: controlRoot.font horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter opacity: controlRoot.enabled ? 1 : 0.3 onFocusChanged: { if (focus) { Private.MobileTextActionsToolBar.controlRoot = textField; } } onPressAndHold: { if (!Kirigami.Settings.tabletMode) { return; } forceActiveFocus(); cursorPosition = positionAt(event.x, event.y); selectWord(); } } } Component { id: mobileCursor Private.MobileCursor { target: textField } } Private.MobileCursor { target: textField selectionStartHandle: true property var rect: target.positionToRectangle(target.selectionStart) x: rect.x + 5 y: rect.y + 6 } 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: 8 samples: 8 horizontalOffset: 0 verticalOffset: 2 color: Qt.rgba(0, 0, 0, 0.3) } } } } diff --git a/org.kde.desktop/ScrollView.qml b/org.kde.desktop/ScrollView.qml index 8c5a04f..8eff770 100644 --- a/org.kde.desktop/ScrollView.qml +++ b/org.kde.desktop/ScrollView.qml @@ -1,152 +1,158 @@ /* * Copyright 2017 Marco Martin * 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.9 import QtQuick.Controls @QQC2_VERSION@ import QtQuick.Templates @QQC2_VERSION@ as T import org.kde.kirigami 2.4 as Kirigami import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate T.ScrollView { id: controlRoot clip: true @DISABLE_UNDER_QQC2_2_4@ palette: Kirigami.Theme.palette implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) contentWidth: scrollHelper.flickableItem ? scrollHelper.flickableItem.contentWidth : 0 contentHeight: scrollHelper.flickableItem ? scrollHelper.flickableItem.contentHeight : 0 Kirigami.Theme.colorSet: Kirigami.Theme.View Kirigami.Theme.inherit: !background || !background.visible //size in pixel to accomodate the border drawn by qstyle leftPadding: background && background.visible ? 2 : 0 topPadding: background && background.visible ? 2 : 0 rightPadding: background && background.visible ? 2 : 0 bottomPadding: background && background.visible ? 2 : 0 - + //create a background only after Component.onCompleted, see on the component creation below for explanation Component.onCompleted: { if (!controlRoot.background) { controlRoot.background = backgroundComponent.createObject(controlRoot); } } children: [ MouseArea { id: scrollHelper anchors.fill: parent drag.filterChildren: !Kirigami.Settings.isMobile property bool isMobile: !verticalScrollBar.interactive onIsMobileChanged: { flickableItem.boundsBehavior = scrollHelper.isMobile ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds; } readonly property Flickable flickableItem: controlRoot.contentItem onFlickableItemChanged: { flickableItem.boundsBehavior = scrollHelper.isMobile ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds; - + //don't make the scrolling items overlap the background borders. flickableItem.anchors.margins = Qt.binding(function() { return controlRoot.background && controlRoot.background.visible ? 2 : 0; }); flickableItem.clip = true; - flickableItem.pixelAligned = true; flickableItem.interactive = Kirigami.Settings.isMobile + flickableItem.parent = scrollHelper; } onPressed: { mouse.accepted = false; flickableItem.interactive = true; } onPositionChanged: { mouse.accepted = false; } onReleased: { mouse.accepted = false; - flickableItem.interactive = false; + //flickableItem.interactive = false; } onWheel: { if (isMobile || flickableItem.contentHeight < flickableItem.height) { return; } flickableItem.interactive = false; var y = wheel.pixelDelta.y != 0 ? wheel.pixelDelta.y : wheel.angleDelta.y / 8 //if we don't have a pixeldelta, apply the configured mouse wheel lines if (!wheel.pixelDelta.y) { y *= Kirigami.Settings.mouseWheelScrollLines; } var minYExtent = flickableItem.topMargin - flickableItem.originY; var maxYExtent = flickableItem.height - (flickableItem.contentHeight + flickableItem.bottomMargin + flickableItem.originY); flickableItem.contentY = Math.min(-maxYExtent, Math.max(-minYExtent, flickableItem.contentY - y)); //this is just for making the scrollbar appear flickableItem.flick(0, 0); flickableItem.cancelFlick(); } Connections { target: scrollHelper.flickableItem - onFlickEnded: scrollHelper.flickableItem.interactive = false; - onMovementEnded: scrollHelper.flickableItem.interactive = false; + onFlickEnded: { + scrollHelper.flickableItem.interactive = false; + scrollHelper.flickableItem.contentY = Math.round(scrollHelper.flickableItem.contentY); + } + onMovementEnded: { + scrollHelper.flickableItem.interactive = false; + scrollHelper.flickableItem.contentY = Math.round(scrollHelper.flickableItem.contentY); + } } /*create a background only after Component.onCompleted because: * implementations can set their own background in a declarative way * ScrollView {background.visible: true} must *not* work, becasue all upstream styles don't have a background so applications using this would break with other styles * This is child of scrollHelper as it would break native scrollview finding of the flickable if it was a direct child */ Component { id: backgroundComponent StylePrivate.StyleItem { control: controlRoot elementType: "edit" visible: false sunken: true hasFocus: controlRoot.activeFocus || scrollHelper.flickableItem.activeFocus hover: controlRoot.hovered } } } ] ScrollBar.vertical: ScrollBar { id: verticalScrollBar parent: controlRoot x: controlRoot.mirrored ? 0 : controlRoot.width - width y: controlRoot.topPadding height: controlRoot.availableHeight active: controlRoot.ScrollBar.horizontal || controlRoot.ScrollBar.horizontal.active } ScrollBar.horizontal: ScrollBar { parent: controlRoot x: controlRoot.leftPadding y: controlRoot.height - height width: controlRoot.availableWidth active: controlRoot.ScrollBar.vertical || controlRoot.ScrollBar.vertical.active } }