From e3fba2575466ece88d7fc3b5c65660d198abda0f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 14 Dec 2017 12:56:06 +0100 Subject: [PATCH] move kirigami plasma styles here solves a nasty dependency loop (and kirigami is supposed to be tier1) --- src/declarativeimports/CMakeLists.txt | 3 + .../kirigamiplasmadesktopstyle/Units.qml | 127 ++++++++++++++++++ .../kirigamiplasmastyle/Icon.qml | 38 ++++++ .../kirigamiplasmastyle/Theme.qml | 91 +++++++++++++ .../kirigamiplasmastyle/Units.qml | 108 +++++++++++++++ 5 files changed, 367 insertions(+) create mode 100644 src/declarativeimports/kirigamiplasmadesktopstyle/Units.qml create mode 100644 src/declarativeimports/kirigamiplasmastyle/Icon.qml create mode 100644 src/declarativeimports/kirigamiplasmastyle/Theme.qml create mode 100644 src/declarativeimports/kirigamiplasmastyle/Units.qml diff --git a/src/declarativeimports/CMakeLists.txt b/src/declarativeimports/CMakeLists.txt index 2b45b4719..8ac236239 100644 --- a/src/declarativeimports/CMakeLists.txt +++ b/src/declarativeimports/CMakeLists.txt @@ -7,6 +7,9 @@ add_subdirectory(calendar) install(DIRECTORY plasmastyle/ DESTINATION ${KDE_INSTALL_QMLDIR}/QtQuick/Controls/Styles/Plasma) +install(DIRECTORY kirigamiplasmastyle/ DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles/Plasma) + +install(DIRECTORY kirigamiplasmadesktopstyle/ DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles/org.kde.desktop.plasma) #install the components as a QQC2 Style, as style for applications (mainly for Plasma Mobile) install(DIRECTORY plasmacomponents3/ DESTINATION ${KDE_INSTALL_QMLDIR}/QtQuick/Controls.2/Plasma PATTERN qmldir EXCLUDE) diff --git a/src/declarativeimports/kirigamiplasmadesktopstyle/Units.qml b/src/declarativeimports/kirigamiplasmadesktopstyle/Units.qml new file mode 100644 index 000000000..dd820e62d --- /dev/null +++ b/src/declarativeimports/kirigamiplasmadesktopstyle/Units.qml @@ -0,0 +1,127 @@ +/* + * 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 1.4 as QtQuickControls +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: fontMetrics.roundedIconSize(16 * devicePixelRatio) + property int smallMedium: fontMetrics.roundedIconSize(22 * devicePixelRatio) + property int medium: fontMetrics.roundedIconSize(32 * devicePixelRatio) + property int large: fontMetrics.roundedIconSize(48 * devicePixelRatio) + property int huge: fontMetrics.roundedIconSize(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: Math.floor(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.max(1, (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 QtObject __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" + function roundedIconSize(size) { + if (size < 16) { + return size; + } else if (size < 22) { + return 16; + } else if (size < 32) { + return 22; + } else if (size < 48) { + return 32; + } else if (size < 64) { + return 48; + } else { + return size; + } + } + } +} diff --git a/src/declarativeimports/kirigamiplasmastyle/Icon.qml b/src/declarativeimports/kirigamiplasmastyle/Icon.qml new file mode 100644 index 000000000..04878d39b --- /dev/null +++ b/src/declarativeimports/kirigamiplasmastyle/Icon.qml @@ -0,0 +1,38 @@ +/* + * 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.0 +import org.kde.plasma.core 2.0 as PlasmaCore + + +PlasmaCore.IconItem { + property bool selected: false + property bool isMask: false + //TODO: implement in libplasma + property color color: "transparent" + usesPlasmaTheme: false + colorGroup: PlasmaCore.ColorScope.colorGroup + onSelectedChanged: { + if (selected) { + status = PlasmaCore.Svg.Selected; + } else { + status = PlasmaCore.Svg.Normal; + } + } +} diff --git a/src/declarativeimports/kirigamiplasmastyle/Theme.qml b/src/declarativeimports/kirigamiplasmastyle/Theme.qml new file mode 100644 index 000000000..b00500b69 --- /dev/null +++ b/src/declarativeimports/kirigamiplasmastyle/Theme.qml @@ -0,0 +1,91 @@ +/* + * 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 +import org.kde.kirigami 2.2 as Kirigami + +QtObject { + property color textColor: theme.textColor + property color disabledTextColor: Qt.rgba(theme.textColor.r, theme.textColor.g, theme.textColor.b, 0.6) + + property color highlightColor: theme.highlightColor + property color highlightedTextColor: theme.highlightedTextColor + property color backgroundColor: theme.backgroundColor + //TODO: don't make this invisible + property color activeTextColor: theme.highlightColor + property color linkColor: theme.linkColor + property color visitedLinkColor: theme.visitedLinkColor + property color negativeTextColor: theme.negativeTextColor + property color neutralTextColor: theme.neutralTextColor + property color positiveTextColor: theme.positiveTextColor + + property color buttonTextColor: theme.buttonTextColor + property color buttonBackgroundColor: theme.buttonBackgroundColor + property color buttonHoverColor: theme.buttonHoverColor + property color buttonFocusColor: theme.buttonFocusColor + + property color viewTextColor: theme.viewTextColor + property color viewBackgroundColor: theme.viewBackgroundColor + property color viewHoverColor: theme.viewHoverColor + property color viewFocusColor: theme.viewFocusColor + + property color selectionTextColor: theme.highlightedTextColor + property color selectionBackgroundColor: theme.highlightColor + property color selectionHoverColor: theme.buttonHoverColor + property color selectionFocusColor: theme.buttonFocusColor + + property color tooltipTextColor: theme.complementaryTextColor + property color tooltipBackgroundColor: theme.complementaryBackgroundColor + property color tooltipHoverColor: theme.complementaryHoverColor + property color tooltipFocusColor: theme.complementaryFocusColor + + property color complementaryTextColor: theme.complementaryTextColor + property color complementaryBackgroundColor: theme.complementaryBackgroundColor + property color complementaryHoverColor: theme.complementaryHoverColor + property color complementaryFocusColor: theme.complementaryFocusColor + + property variant defaultFont: theme.defaultFont + + function __propagateColorSet(object, context) { + object.PlasmaCore.ColorScope.inherit = false; + switch(context) { + case Kirigami.Theme.Window: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.NormalColorGroup; + break; + case Kirigami.Theme.Button: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.ButtonColorGroup; + break; + case Kirigami.Theme.View: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.ViewColorGroup; + break; + case Kirigami.Theme.Selection: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.NormalColorGroup; + break; + case Kirigami.Theme.Tooltip: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.ComplementaryColorGroup; + break; + case Kirigami.Theme.Complementary: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.ComplementaryColorGroup; + break; + } + } +} diff --git a/src/declarativeimports/kirigamiplasmastyle/Units.qml b/src/declarativeimports/kirigamiplasmastyle/Units.qml new file mode 100644 index 000000000..cfa10b4cf --- /dev/null +++ b/src/declarativeimports/kirigamiplasmastyle/Units.qml @@ -0,0 +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" + } +}