From 181b39ddd0b3c027341b228ab51482ce4413d3bb Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Thu, 10 Mar 2016 13:54:07 +0100 Subject: add scaling unit to the theme plugin and use it instaed of the main.qml unit item --- components/mail/contents/ui/main.qml | 19 +++++------- components/package/contents/ui/FocusComposer.qml | 2 +- components/package/contents/ui/FolderListView.qml | 9 +++--- components/package/contents/ui/ListItem.qml | 5 +-- components/package/contents/ui/MailListView.qml | 17 +++++----- components/package/contents/ui/Settings.qml | 2 +- framework/theme/CMakeLists.txt | 1 + framework/theme/themeplugin.cpp | 14 +++++++-- framework/theme/unit.cpp | 29 +++++++++++++++++ framework/theme/unit.h | 38 +++++++++++++++++++++++ 10 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 framework/theme/unit.cpp create mode 100644 framework/theme/unit.h diff --git a/components/mail/contents/ui/main.qml b/components/mail/contents/ui/main.qml index 181174d2..d864f2fc 100644 --- a/components/mail/contents/ui/main.qml +++ b/components/mail/contents/ui/main.qml @@ -22,6 +22,7 @@ import org.kde.plasma.components 2.0 as PlasmaComponents import org.kube.framework.actions 1.0 as KubeAction import org.kube.framework.settings 1.0 as KubeSettings +import org.kube.framework.theme 1.0 import org.kube.components 1.0 as KubeComponents ApplicationWindow { @@ -154,17 +155,17 @@ ApplicationWindow { KubeComponents.FolderListView { id: folderListView - width: unit.size * 55 - Layout.maximumWidth: unit.size * 150 - Layout.minimumWidth: unit.size * 30 + width: Unit.size * 55 + Layout.maximumWidth: Unit.size * 150 + Layout.minimumWidth: Unit.size * 30 } KubeComponents.MailListView { id: mailListView parentFolder: folderListView.currentFolder - width: unit.size * 80 - Layout.maximumWidth: unit.size * 250 - Layout.minimumWidth: unit.size * 50 + width: Unit.size * 80 + Layout.maximumWidth: Unit.size * 250 + Layout.minimumWidth: Unit.size * 50 focus: true } @@ -187,11 +188,5 @@ ApplicationWindow { anchors.fill: parent } - - //TODO find a better way to scale UI - Item { - id: unit - property int size: 5 - } } diff --git a/components/package/contents/ui/FocusComposer.qml b/components/package/contents/ui/FocusComposer.qml index bc8b3f2d..ab04dbed 100644 --- a/components/package/contents/ui/FocusComposer.qml +++ b/components/package/contents/ui/FocusComposer.qml @@ -55,7 +55,7 @@ Rectangle { anchors { fill: parent - margins: unit.size * 3 + margins: Unit.size * 3 } Composer { diff --git a/components/package/contents/ui/FolderListView.qml b/components/package/contents/ui/FolderListView.qml index d78531a2..fafc1623 100644 --- a/components/package/contents/ui/FolderListView.qml +++ b/components/package/contents/ui/FolderListView.qml @@ -24,6 +24,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kube.framework.domain 1.0 as KubeFramework +import org.kube.framework.theme 1.0 Item { id: root @@ -34,7 +35,7 @@ Item { id: searchBox width: root.width - height: unit.size * 10 + height: Unit.size * 10 TextField { anchors. centerIn: parent @@ -68,7 +69,7 @@ Item { style: TreeViewStyle { activateItemOnSingleClick: true rowDelegate: Rectangle { - height: unit.size * 10 + height: Unit.size * 10 color: "transparent" } itemDelegate: Rectangle { @@ -81,7 +82,7 @@ Item { anchors { verticalCenter: parent.verticalCenter left: parent.left - leftMargin: unit.size * 3 + leftMargin: Unit.size * 3 } source: model.icon } @@ -89,7 +90,7 @@ Item { anchors { verticalCenter: parent.verticalCenter left: iconItem.right - leftMargin: unit.size * 3 + leftMargin: Unit.size * 3 } renderType: Text.NativeRendering text: styleData.value diff --git a/components/package/contents/ui/ListItem.qml b/components/package/contents/ui/ListItem.qml index 5396645d..bea3c11b 100644 --- a/components/package/contents/ui/ListItem.qml +++ b/components/package/contents/ui/ListItem.qml @@ -16,13 +16,14 @@ */ import QtQuick 2.4 +import org.kube.framework.theme 1.0 Item { id: delegateRoot readonly property bool isCurrentItem: ListView.isCurrentItem - height: unit.width * 25 + height: Unit.width * 25 width: parent.width MouseArea { @@ -60,4 +61,4 @@ Item { opacity: 0.2 } } -} \ No newline at end of file +} diff --git a/components/package/contents/ui/MailListView.qml b/components/package/contents/ui/MailListView.qml index bf5185dc..e7fc634f 100644 --- a/components/package/contents/ui/MailListView.qml +++ b/components/package/contents/ui/MailListView.qml @@ -24,6 +24,7 @@ import QtQml 2.2 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kube.framework.domain 1.0 as KubeFramework +import org.kube.framework.theme 1.0 ScrollView { id: root @@ -47,7 +48,7 @@ ScrollView { delegate: PlasmaComponents.ListItem { width: listView.width - height: unit.size * 12 + height: Unit.size * 12 enabled: true checked: listView.currentIndex == index @@ -84,10 +85,10 @@ ScrollView { anchors { verticalCenter: parent.verticalCenter left: parent.left - leftMargin: unit.size * 2 + leftMargin: Unit.size * 2 } - height: unit.size * 9 + height: Unit.size * 9 width: height name: model.senderName @@ -99,7 +100,7 @@ ScrollView { anchors { top: avatar.top left: avatar.right - leftMargin: unit.size * 3 + leftMargin: Unit.size * 3 } text: model.senderName @@ -114,9 +115,9 @@ ScrollView { // anchors { // top: avatar.top // left: senderName.right - // leftMargin: unit.size + // leftMargin: Unit.size // right: date.left - // rightMargin: unit.size + // rightMargin: Unit.size // } // // text: "(" + model.sender +")" @@ -130,7 +131,7 @@ ScrollView { anchors { top: avatar.top right: parent.right - rightMargin: unit.size * 2 + rightMargin: Unit.size * 2 } text: Qt.formatDateTime(model.date) @@ -144,7 +145,7 @@ ScrollView { anchors { bottom: avatar.bottom left: avatar.right - leftMargin: unit.size * 3 + leftMargin: Unit.size * 3 } text: model.subject diff --git a/components/package/contents/ui/Settings.qml b/components/package/contents/ui/Settings.qml index fa886f2b..bada1140 100644 --- a/components/package/contents/ui/Settings.qml +++ b/components/package/contents/ui/Settings.qml @@ -75,7 +75,7 @@ Rectangle { anchors { verticalCenter: parent.verticalCenter left: parent.left - // leftMargin: unit.size * 3 + // leftMargin: Unit.size * 3 } source: accountFactory.icon } diff --git a/framework/theme/CMakeLists.txt b/framework/theme/CMakeLists.txt index 4314f662..319e3d39 100644 --- a/framework/theme/CMakeLists.txt +++ b/framework/theme/CMakeLists.txt @@ -1,6 +1,7 @@ set(themeplugin_SRCS themeplugin.cpp colorpalette.cpp + unit.cpp ) add_library(themeplugin SHARED ${themeplugin_SRCS}) diff --git a/framework/theme/themeplugin.cpp b/framework/theme/themeplugin.cpp index 919205cf..ad9d0e1b 100644 --- a/framework/theme/themeplugin.cpp +++ b/framework/theme/themeplugin.cpp @@ -18,11 +18,12 @@ #include "themeplugin.h" -#include "colorpalette.h" - #include #include +#include "colorpalette.h" +#include "unit.h" + static QObject *colorpaletteInstace(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine); @@ -31,10 +32,19 @@ static QObject *colorpaletteInstace(QQmlEngine *engine, QJSEngine *scriptEngine) return new ColorPalette; } +static QObject *unitInstace(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + + return new Unit; +} + void ThemePlugin::registerTypes (const char *uri) { Q_ASSERT(uri == QLatin1String("org.kube.framework.theme")); qmlRegisterSingletonType(uri, 1, 0, "ColorPalette", colorpaletteInstace); + qmlRegisterSingletonType(uri, 1, 0, "Unit", unitInstace); } diff --git a/framework/theme/unit.cpp b/framework/theme/unit.cpp new file mode 100644 index 00000000..1f3803cb --- /dev/null +++ b/framework/theme/unit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2016 Michael Bohlender + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, 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 General Public License for more details. + + You should have received a copy of the GNU 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. +*/ + +#include "unit.h" + +Unit::Unit(QObject *parent) : QObject(parent), m_size(5) +{ + +} + +int Unit::size() const +{ + return m_size; +} \ No newline at end of file diff --git a/framework/theme/unit.h b/framework/theme/unit.h new file mode 100644 index 00000000..bd9b58f0 --- /dev/null +++ b/framework/theme/unit.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2016 Michael Bohlender + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, 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 General Public License for more details. + + You should have received a copy of the GNU 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. +*/ + +#include + + +class Unit : public QObject +{ + Q_OBJECT + Q_PROPERTY (int size READ size NOTIFY unitChanged) + + +public: + explicit Unit(QObject *parent = Q_NULLPTR); + + int size() const; + +signals: + void unitChanged(); + +private: + int m_size; +}; -- cgit v1.2.3