diff --git a/src/controls/Units.qml b/src/controls/Units.qml index 6cf41215..817cbfde 100644 --- a/src/controls/Units.qml +++ b/src/controls/Units.qml @@ -1,105 +1,111 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Window 2.2 import org.kde.kirigami 2.0 pragma Singleton QtObject { id: units /** * The fundamental unit of space that should be used for sizes, expressed in pixels. * Given the screen has an accurate DPI settings, it corresponds to a width of * the capital letter M */ property int gridUnit: fontMetrics.height /** * units.iconSizes provides access to platform-dependent icon sizing * * The icon sizes provided are normalized for different DPI, so icons * will scale depending on the DPI. * * Icon sizes from KIconLoader, adjusted to devicePixelRatio: * * small * * smallMedium * * medium * * large * * huge * * enormous * * Not devicePixelRation-adjusted:: * * desktop */ property QtObject iconSizes: QtObject { property int small: 16 * devicePixelRatio * (Settings.isMobile ? 1.5 : 1) property int smallMedium: 22 * devicePixelRatio * (Settings.isMobile ? 1.5 : 1) property int medium: 32 * devicePixelRatio * (Settings.isMobile ? 1.5 : 1) property int large: 48 * devicePixelRatio * (Settings.isMobile ? 1.5 : 1) property int huge: 64 * devicePixelRatio * (Settings.isMobile ? 1.5 : 1) property int enormous: 128 * devicePixelRatio * (Settings.isMobile ? 1.5 : 1) } /** * units.smallSpacing is the amount of spacing that should be used around smaller UI elements, * for example as spacing in Columns. Internally, this size depends on the size of * the default font as rendered on the screen, so it takes user-configured font size and DPI * into account. */ property int smallSpacing: gridUnit/4 /** * units.largeSpacing is the amount of spacing that should be used inside bigger UI elements, * for example between an icon and the corresponding text. Internally, this size depends on * the size of the default font as rendered on the screen, so it takes user-configured font * size and DPI into account. */ property int largeSpacing: gridUnit /** * The ratio between physical and device-independent pixels. This value does not depend on the \ * size of the configured font. If you want to take font sizes into account when scaling elements, * use theme.mSize(theme.defaultFont), units.smallSpacing and units.largeSpacing. * The devicePixelRatio follows the definition of "device independent pixel" by Microsoft. */ property real devicePixelRatio: fontMetrics.font.pixelSize / (fontMetrics.font.pointSize * 1.33) /** * units.longDuration should be used for longer, screen-covering animations, for opening and * closing of dialogs and other "not too small" animations */ property int longDuration: 250 /** * units.shortDuration should be used for short animations, such as accentuating a UI event, * hover events, etc.. */ property int shortDuration: 150 + /** + * How much the mouse scroll wheel scrolls, expressed in lines of text. + * Note: this is strictly for classical mouse wheels, touchpads 2 figer scrolling won't be affected + */ + readonly property int wheelScrollLines: 3 + /** * metrics used by the default font */ property variant fontMetrics: TextMetrics { text: "M" } } diff --git a/src/controls/templates/private/ScrollView.qml b/src/controls/templates/private/ScrollView.qml index 76143858..6d368f5a 100644 --- a/src/controls/templates/private/ScrollView.qml +++ b/src/controls/templates/private/ScrollView.qml @@ -1,106 +1,109 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.5 import QtQuick.Controls 2.0 import org.kde.kirigami 2.0 MouseArea { id: root default property Item contentItem property Flickable flickableItem //TODO: horizontalScrollBarPolicy is completely noop just for compatibility right now property int horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff property int verticalScrollBarPolicy: Qt.ScrollBarAsNeeded readonly property Item verticalScrollBar: flickableItem.ScrollBar.vertical ? flickableItem.ScrollBar.vertical : null onVerticalScrollBarPolicyChanged: { flickableItem.ScrollBar.vertical.visible = verticalScrollBarPolicy == Qt.ScrollBarAlwaysOff } drag.filterChildren: !Settings.isMobile onWheel: { if (Settings.isMobile || flickableItem.contentHeight 0 ? Units.gridUnit : -Units.gridUnit) + var y = wheel.pixelDelta.y != 0 ? wheel.pixelDelta.y : (wheel.angleDelta.y > 0 ? step : -step) var minYExtent = flickableItem.topMargin; - var maxYExtent = flickableItem.height - (flickableItem.contentHeight - flickableItem.bottomMargin); + var maxYExtent = flickableItem.height - (flickableItem.contentHeight + flickableItem.bottomMargin); if (typeof(flickableItem.headerItem) !== "undefined" && flickableItem.headerItem) { minYExtent += flickableItem.headerItem.height } + flickableItem.contentY = Math.min(-maxYExtent, Math.max(-minYExtent, flickableItem.contentY - y)); //this is just for making the scrollbar appear flickableItem.flick(0, 0); cancelFlickStateTimer.restart(); } Timer { id: cancelFlickStateTimer interval: 150 onTriggered: flickableItem.cancelFlick() } onContentItemChanged: { if (contentItem.hasOwnProperty("contentY")) { flickableItem = contentItem; contentItem.parent = flickableParent; } else { flickableItem = flickableComponent.createObject(flickableParent); contentItem.parent = flickableItem.contentItem; } //TODO: find a way to make flicking work on laptops with touch screen flickableItem.interactive = Settings.isMobile; flickableItem.anchors.fill = flickableParent; flickableItem.ScrollBar.vertical = scrollComponent.createObject(root); flickableItem.ScrollBar.vertical.anchors.right = root.right flickableItem.ScrollBar.vertical.anchors.top = root.top //flickableItem.ScrollBar.vertical.anchors.bottom = root.bottom } //NOTE: use this instead of anchors as crashes on some Qt 5.8 checkouts onHeightChanged: flickableItem.ScrollBar.vertical.height = root.height Item { id: flickableParent anchors { fill: parent } clip: true } Component { id: flickableComponent Flickable { anchors { fill: parent } contentWidth: root.contentItem ? root.contentItem.width : 0 contentHeight: root.contentItem ? root.contentItem.height : 0 } } Component { id: scrollComponent ScrollBar { visible: root.contentItem.visible } } } diff --git a/src/styles/Plasma/Units.qml b/src/styles/Plasma/Units.qml index 34ec6bcd..cfa10b4c 100644 --- a/src/styles/Plasma/Units.qml +++ b/src/styles/Plasma/Units.qml @@ -1,102 +1,108 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ pragma Singleton import QtQuick 2.4 import org.kde.plasma.core 2.0 as PlasmaCore QtObject { /** * The fundamental unit of space that should be used for sizes, expressed in pixels. * Given the screen has an accurate DPI settings, it corresponds to a width of * the capital letter M */ property int gridUnit: units.gridUnit /** * units.iconSizes provides access to platform-dependent icon sizing * * The icon sizes provided are normalized for different DPI, so icons * will scale depending on the DPI. * * Icon sizes from KIconLoader, adjusted to devicePixelRatio: * * small * * smallMedium * * medium * * large * * huge * * enormous * * Not devicePixelRation-adjusted:: * * desktop */ property QtObject iconSizes: QtObject { property int small: units.iconSizes.small property int smallMedium: units.iconSizes.smallMedium property int medium: units.iconSizes.medium property int large: units.iconSizes.large property int huge: units.iconSizes.huge property int enormous: units.iconSizes.enormous } /** * units.smallSpacing is the amount of spacing that should be used around smaller UI elements, * for example as spacing in Columns. Internally, this size depends on the size of * the default font as rendered on the screen, so it takes user-configured font size and DPI * into account. */ property int smallSpacing: units.smallSpacing /** * units.largeSpacing is the amount of spacing that should be used inside bigger UI elements, * for example between an icon and the corresponding text. Internally, this size depends on * the size of the default font as rendered on the screen, so it takes user-configured font * size and DPI into account. */ property int largeSpacing: units.largeSpacing /** * The ratio between physical and device-independent pixels. This value does not depend on the \ * size of the configured font. If you want to take font sizes into account when scaling elements, * use theme.mSize(theme.defaultFont), units.smallSpacing and units.largeSpacing. * The devicePixelRatio follows the definition of "device independent pixel" by Microsoft. */ property real devicePixelRatio: units.devicePixelRatio /** * units.longDuration should be used for longer, screen-covering animations, for opening and * closing of dialogs and other "not too small" animations */ property int longDuration: units.longDuration /** * units.shortDuration should be used for short animations, such as accentuating a UI event, * hover events, etc.. */ property int shortDuration: units.shortDuration + /** + * How much the mouse scroll wheel scrolls, expressed in lines of text. + * Note: this is strictly for classical mouse wheels, touchpads 2 figer scrolling won't be affected + */ + property int wheelScrollLines: 3 + /** * metrics used by the default font */ property variant fontMetrics: TextMetrics { text: "M" } } diff --git a/src/styles/org.kde.desktop.plasma/Units.qml b/src/styles/org.kde.desktop.plasma/Units.qml index b87d8ba8..9fdaa7cb 100644 --- a/src/styles/org.kde.desktop.plasma/Units.qml +++ b/src/styles/org.kde.desktop.plasma/Units.qml @@ -1,102 +1,111 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Window 2.2 import org.kde.plasma.core 2.0 as PlasmaCore +import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate pragma Singleton QtObject { id: unitsRoot /** * The fundamental unit of space that should be used for sizes, expressed in pixels. * Given the screen has an accurate DPI settings, it corresponds to a width of * the capital letter M */ property int gridUnit: fontMetrics.height /** * units.iconSizes provides access to platform-dependent icon sizing * * The icon sizes provided are normalized for different DPI, so icons * will scale depending on the DPI. * * Icon sizes from KIconLoader, adjusted to devicePixelRatio: * * small * * smallMedium * * medium * * large * * huge * * enormous * * Not devicePixelRation-adjusted:: * * desktop */ property QtObject iconSizes: QtObject { property int small: 16 * devicePixelRatio property int smallMedium: 22 * devicePixelRatio property int medium: 32 * devicePixelRatio property int large: 48 * devicePixelRatio property int huge: 64 * devicePixelRatio property int enormous: 128 * devicePixelRatio } /** * units.smallSpacing is the amount of spacing that should be used around smaller UI elements, * for example as spacing in Columns. Internally, this size depends on the size of * the default font as rendered on the screen, so it takes user-configured font size and DPI * into account. */ property int smallSpacing: gridUnit/4 /** * units.largeSpacing is the amount of spacing that should be used inside bigger UI elements, * for example between an icon and the corresponding text. Internally, this size depends on * the size of the default font as rendered on the screen, so it takes user-configured font * size and DPI into account. */ property int largeSpacing: gridUnit /** * The ratio between physical and device-independent pixels. This value does not depend on the \ * size of the configured font. If you want to take font sizes into account when scaling elements, * use theme.mSize(theme.defaultFont), units.smallSpacing and units.largeSpacing. * The devicePixelRatio follows the definition of "device independent pixel" by Microsoft. */ property real devicePixelRatio: Math.floor(fontMetrics.font.pixelSize / fontMetrics.font.pointSize) /** * units.longDuration should be used for longer, screen-covering animations, for opening and * closing of dialogs and other "not too small" animations */ property int longDuration: units.longDuration /** * units.shortDuration should be used for short animations, such as accentuating a UI event, * hover events, etc.. */ property int shortDuration: units.shortDuration + readonly property QtQuickControlsPrivate.StyleItem __styleItem: QtQuickControlsPrivate.StyleItem {elementType: "frame" } + + /** + * How much the mouse scroll wheel scrolls, expressed in lines of text. + * Note: this is strictly for classical mouse wheels, touchpads 2 figer scrolling won't be affected + */ + readonly property int wheelScrollLines: __styleItem.styleHint("wheelScrollLines") + property variant fontMetrics: TextMetrics { text: "M" } } diff --git a/src/styles/org.kde.desktop/Units.qml b/src/styles/org.kde.desktop/Units.qml index f42b0401..349ca3e9 100644 --- a/src/styles/org.kde.desktop/Units.qml +++ b/src/styles/org.kde.desktop/Units.qml @@ -1,101 +1,109 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Window 2.2 pragma Singleton QtObject { id: units /** * The fundamental unit of space that should be used for sizes, expressed in pixels. * Given the screen has an accurate DPI settings, it corresponds to a width of * the capital letter M */ property int gridUnit: fontMetrics.height /** * units.iconSizes provides access to platform-dependent icon sizing * * The icon sizes provided are normalized for different DPI, so icons * will scale depending on the DPI. * * Icon sizes from KIconLoader, adjusted to devicePixelRatio: * * small * * smallMedium * * medium * * large * * huge * * enormous * * Not devicePixelRation-adjusted:: * * desktop */ property QtObject iconSizes: QtObject { property int small: 16 * devicePixelRatio property int smallMedium: 22 * devicePixelRatio property int medium: 32 * devicePixelRatio property int large: 48 * devicePixelRatio property int huge: 64 * devicePixelRatio property int enormous: 128 * devicePixelRatio } /** * units.smallSpacing is the amount of spacing that should be used around smaller UI elements, * for example as spacing in Columns. Internally, this size depends on the size of * the default font as rendered on the screen, so it takes user-configured font size and DPI * into account. */ property int smallSpacing: gridUnit/4 /** * units.largeSpacing is the amount of spacing that should be used inside bigger UI elements, * for example between an icon and the corresponding text. Internally, this size depends on * the size of the default font as rendered on the screen, so it takes user-configured font * size and DPI into account. */ property int largeSpacing: gridUnit /** * The ratio between physical and device-independent pixels. This value does not depend on the \ * size of the configured font. If you want to take font sizes into account when scaling elements, * use theme.mSize(theme.defaultFont), units.smallSpacing and units.largeSpacing. * The devicePixelRatio follows the definition of "device independent pixel" by Microsoft. */ property real devicePixelRatio: Math.floor(fontMetrics.font.pixelSize / fontMetrics.font.pointSize) /** * units.longDuration should be used for longer, screen-covering animations, for opening and * closing of dialogs and other "not too small" animations */ property int longDuration: 250 /** * units.shortDuration should be used for short animations, such as accentuating a UI event, * hover events, etc.. */ property int shortDuration: 150 + readonly property QtQuickControlsPrivate.StyleItem __styleItem: QtQuickControlsPrivate.StyleItem {elementType: "frame" } + + /** + * How much the mouse scroll wheel scrolls, expressed in lines of text. + * Note: this is strictly for classical mouse wheels, touchpads 2 figer scrolling won't be affected + */ + readonly property int wheelScrollLines: 3//__styleItem.styleHint("wheelScrollLines") + property variant fontMetrics: TextMetrics { text: "M" } }