diff --git a/examples/sizeview/glacier-sizeview.qml b/examples/sizeview/glacier-sizeview.qml index 8ca803b..60ca73b 100644 --- a/examples/sizeview/glacier-sizeview.qml +++ b/examples/sizeview/glacier-sizeview.qml @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2024 Chupligin Sergey + * Copyright (C) 2017-2025 Chupligin Sergey * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ import QtQuick import QtQuick.Window +import Nemo import Nemo.Controls ApplicationWindow { @@ -88,18 +89,18 @@ ApplicationWindow { } Label{ - text: "DP Scale factor: " + size.dpScaleFactor; + text: "DP Scale factor: " + Theme.dpScaleFactor; } Label{ - text: "MM Scale factor: " + size.mmScaleFactor; + text: "MM Scale factor: " + Theme.mmScaleFactor; } Rectangle{ color: Theme.accentColor - width: size.mm(10) - height: size.mm(10) + width: Theme.mm(10) + height: Theme.mm(10) Label{ anchors.centerIn: parent diff --git a/src/controls/qml/DatePicker.qml b/src/controls/qml/DatePicker.qml index ff5a0bd..dbb2874 100644 --- a/src/controls/qml/DatePicker.qml +++ b/src/controls/qml/DatePicker.qml @@ -1,6 +1,6 @@ /**************************************************************************************** ** -** Copyright (C) 2017-2021 Chupligin Sergey +** Copyright (C) 2017-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -31,6 +31,7 @@ import QtQuick +import Nemo import Nemo.Controls import Nemo.Models diff --git a/src/controls/qml/GlacierRoller.qml b/src/controls/qml/GlacierRoller.qml index 9832b9f..cff70e7 100644 --- a/src/controls/qml/GlacierRoller.qml +++ b/src/controls/qml/GlacierRoller.qml @@ -1,4 +1,24 @@ +/* + * Copyright (C) 2018-2025 Chupligin Sergey + * + * This library 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 of the License, or (at your option) any later version. + * + * This library 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 library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + import QtQuick 2.6 +import Nemo Item { id: glacierRoller @@ -33,7 +53,7 @@ Item { Rectangle{ id: topLine width: parent.width - height: size.dp(1) + height: Theme.dp(1) color: Theme.backgroundAccentColor anchors.top: view.top z: 2 @@ -42,7 +62,7 @@ Item { Rectangle{ id: bottomLine width: parent.width - height: size.dp(3) + height: Theme.dp(3) color: Theme.backgroundAccentColor anchors.bottom: view.bottom z: 2 diff --git a/src/controls/qml/GlacierRollerItem.qml b/src/controls/qml/GlacierRollerItem.qml index 4448c65..297d779 100644 --- a/src/controls/qml/GlacierRollerItem.qml +++ b/src/controls/qml/GlacierRollerItem.qml @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2018-2023 Chupligin Sergey + * + * This library 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 of the License, or (at your option) any later version. + * + * This library 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 library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + import QtQuick 2.6 Rectangle{ diff --git a/src/controls/qml/ListView.qml b/src/controls/qml/ListView.qml index 1e6b3e8..418c2c1 100644 --- a/src/controls/qml/ListView.qml +++ b/src/controls/qml/ListView.qml @@ -1,6 +1,6 @@ /**************************************************************************************** ** -** Copyright (C) 2023 Chupligin Sergey +** Copyright (C) 2023-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -32,6 +32,8 @@ import QtQuick 2.6 import QtQuick.Controls +import Nemo + ListView { id: listView @@ -68,7 +70,7 @@ ListView { Rectangle{ id: line - height: size.dp(1) + height: Theme.dp(1) color: Theme.textColor width: listView.width-sectionText.width-Theme.itemHeightExtraSmall anchors{ diff --git a/src/controls/qml/ListViewItemWithActions.qml b/src/controls/qml/ListViewItemWithActions.qml index 3c02bfe..f1d3903 100644 --- a/src/controls/qml/ListViewItemWithActions.qml +++ b/src/controls/qml/ListViewItemWithActions.qml @@ -1,6 +1,6 @@ /**************************************************************************************** ** -** Copyright (C) 2017-2023 Chupligin Sergey +** Copyright (C) 2017-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -32,6 +32,7 @@ import QtQuick import QtQuick.Shapes +import Nemo import Nemo.Controls Item { diff --git a/src/controls/qml/ScrollDecorator.qml b/src/controls/qml/ScrollDecorator.qml index c0e459e..631271b 100644 --- a/src/controls/qml/ScrollDecorator.qml +++ b/src/controls/qml/ScrollDecorator.qml @@ -1,6 +1,6 @@ /**************************************************************************************** ** -** Copyright (C) 2017 Chupligin Sergey +** Copyright (C) 2017-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -32,6 +32,7 @@ import QtQuick 2.6 import QtQuick.Controls +import Nemo import Nemo.Controls Rectangle{ diff --git a/src/controls/qml/TabButton.qml b/src/controls/qml/TabButton.qml index f68a0e1..b3a310c 100644 --- a/src/controls/qml/TabButton.qml +++ b/src/controls/qml/TabButton.qml @@ -48,7 +48,7 @@ TabButton { bottom: parent.bottom } width: parent.width - height: size.dp(1) + height: Theme.dp(1) color: Theme.accentColor } } diff --git a/src/controls/qml/TextField.qml b/src/controls/qml/TextField.qml index 1ab0273..4fd8d7a 100644 --- a/src/controls/qml/TextField.qml +++ b/src/controls/qml/TextField.qml @@ -1,7 +1,7 @@ /**************************************************************************************** ** ** Copyright (c) 2017, Eetu Kahelin -** Copyright (C) 2021-2023 Chupligin Sergey +** Copyright (C) 2021-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -77,7 +77,7 @@ TextField { anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right - height: size.dp(2) + height: Theme.dp(2) width: parent.width color: control.readOnly ? Theme.fillDarkColor : Theme.accentColor } diff --git a/src/controls/qml/TimePicker.qml b/src/controls/qml/TimePicker.qml index df5d773..d08ca1d 100644 --- a/src/controls/qml/TimePicker.qml +++ b/src/controls/qml/TimePicker.qml @@ -1,6 +1,6 @@ /**************************************************************************************** ** -** Copyright (C) 2018-2021 Chupligin Sergey +** Copyright (C) 2018-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -30,6 +30,8 @@ ****************************************************************************************/ import QtQuick 2.6 + +import Nemo import Nemo.Controls Item{ diff --git a/src/controls/qml/ToolButton.qml b/src/controls/qml/ToolButton.qml index 8dddae6..8b0f77b 100644 --- a/src/controls/qml/ToolButton.qml +++ b/src/controls/qml/ToolButton.qml @@ -1,6 +1,6 @@ /**************************************************************************************** ** -** Copyright (C) 2019-2023 Chupligin Sergey +** Copyright (C) 2019-2025 Chupligin Sergey ** All rights reserved. ** ** You may use this file under the terms of BSD license as follows: @@ -32,6 +32,7 @@ import QtQuick 2.6 import QtQuick.Controls +import Nemo import Nemo.Controls Item { diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 34b1767..0507fad 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,7 +1,6 @@ set(PACKAGE nemocoreplugin) set(SRC - sizing.cpp nemoimageprovider.cpp plugin.cpp themedaemon/mlocalthemedaemonclient.cpp @@ -17,8 +16,7 @@ set(HEADERS themedaemon/mabstractthemedaemonclient.h) set(PUBLIC_HEADERS - theme.h - sizing.h) + theme.h) add_library(${PACKAGE} SHARED ${SRC} ${MLITE}) add_definitions( -DQT_INSTALL_QML="${QT_INSTALL_QML}") diff --git a/src/core/plugin.cpp b/src/core/plugin.cpp index 4ef78f9..5f20e0f 100644 --- a/src/core/plugin.cpp +++ b/src/core/plugin.cpp @@ -20,7 +20,6 @@ #include "plugin.h" #include "nemoimageprovider.h" -#include "sizing.h" #include "theme.h" #include diff --git a/src/core/sizing.cpp b/src/core/sizing.cpp deleted file mode 100644 index dcc1ed0..0000000 --- a/src/core/sizing.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2018-2024 Chupligin Sergey - * - * This library 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 of the License, or (at your option) any later version. - * - * This library 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 library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "sizing.h" -#include "logging.h" - -#include -#include -#include -#include - -Sizing::Sizing(QObject* parent) - : QObject(parent) - , m_mmScaleFactor(10) - , m_dpScaleFactor(1) - , m_screenDPI(0) -{ - // All sizes we get from LipstickSettings::exportScreenProperties() - MDConfItem* physicalDotsPerInchConf = new MDConfItem("/lipstick/screen/primary/physicalDotsPerInch"); - connect(physicalDotsPerInchConf, &MDConfItem::valueChanged, this, &Sizing::recalcConstants); - if (physicalDotsPerInchConf->value().isNull()) { - QScreen* primaryScreen = QGuiApplication::primaryScreen(); - physicalDotsPerInchConf->set(primaryScreen->physicalDotsPerInch()); - physicalDotsPerInchConf->sync(); - } - - recalcConstants(); -} - -void Sizing::setDpScaleFactor() -{ - MDConfItem* dpScaleFactorValue = new MDConfItem(QStringLiteral("/nemo/apps/libglacier/dpScaleFactor")); - float value = dpScaleFactorValue->value("0").toFloat(); - - if (value != m_dpScaleFactor && value != 0) { - m_dpScaleFactor = value; - emit dpScaleFactorChanged(); - } -} - -void Sizing::setMmScaleFactor(float value) -{ - if (value != m_mmScaleFactor && value != 0) { - m_mmScaleFactor = value; - emit mmScaleFactorChanged(); - } -} - -float Sizing::dp(float value) -{ - return value * m_dpScaleFactor; -} - -float Sizing::mm(float value) -{ - return value * m_mmScaleFactor; -} - -void Sizing::recalcConstants() -{ - qreal dpi = MDConfItem("/lipstick/screen/primary/physicalDotsPerInch").value().toReal(); - - if (dpi == m_screenDPI) { - return; - } - - qCDebug(lcNemoControlsCoreLog) << "Screen DPI is: " << dpi; - - float dpScaleFactor; - - if (dpi < 200) { - dpScaleFactor = 1; - } else if (dpi >= 200 && dpi < 300) { - dpScaleFactor = 1.5; - } else if (dpi >= 300 && dpi < 450) { - dpScaleFactor = 2; - } else { - dpScaleFactor = 2.5; - } - - m_screenDPI = dpi; - emit screenDPIChanged(); - - if (dpScaleFactor != m_dpScaleFactor) { - m_dpScaleFactor = dpScaleFactor; - emit dpScaleFactorChanged(); - } - - float pixelsInMM = dpi / 2.45 / 10; - if (pixelsInMM != m_mmScaleFactor) { - m_mmScaleFactor = pixelsInMM; - emit mmScaleFactorChanged(); - } -} diff --git a/src/core/sizing.h b/src/core/sizing.h deleted file mode 100644 index 9f750cc..0000000 --- a/src/core/sizing.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2018-2024 Chupligin Sergey - * - * This library 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 of the License, or (at your option) any later version. - * - * This library 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 library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef SIZING_H -#define SIZING_H - -#include -#include -#include - -class Sizing : public QObject { - Q_OBJECT - - Q_PROPERTY(float mmScaleFactor READ mmScaleFactor WRITE setMmScaleFactor NOTIFY mmScaleFactorChanged) - Q_PROPERTY(float dpScaleFactor READ dpScaleFactor NOTIFY dpScaleFactorChanged) - -public: - explicit Sizing(QObject* parent = 0); - - float mmScaleFactor() { return m_mmScaleFactor; } - float dpScaleFactor() { return m_dpScaleFactor; } - - void setMmScaleFactor(float value); - void setDpScaleFactor(); - - Q_INVOKABLE float dp(float value); - Q_INVOKABLE float mm(float value); - -signals: - void mmScaleFactorChanged(); - void dpScaleFactorChanged(); - void screenDPIChanged(); - -private slots: - void recalcConstants(); - -private: - float m_mmScaleFactor; - float m_dpScaleFactor; - - qreal m_screenDPI; -}; - -#endif // SIZING_H diff --git a/src/core/theme.cpp b/src/core/theme.cpp index 7c7b244..aea550b 100644 --- a/src/core/theme.cpp +++ b/src/core/theme.cpp @@ -19,20 +19,33 @@ #include "theme.h" #include "logging.h" -#include "sizing.h" #include +#include #include #include #include +#include +#include static Theme* themeInstance = 0; Theme::Theme(QObject* parent) : QObject(parent) - , m_size(new Sizing) { - m_size = new Sizing; + // All sizes we get from LipstickSettings::exportScreenProperties() + MDConfItem* physicalDotsPerInchConf = new MDConfItem("/lipstick/screen/primary/physicalDotsPerInch"); + if (physicalDotsPerInchConf->value().isNull()) { + QScreen* primaryScreen = QGuiApplication::primaryScreen(); + physicalDotsPerInchConf->set(primaryScreen->physicalDotsPerInch()); + physicalDotsPerInchConf->sync(); + } + + MDConfItem* dpScaleFactorValue = new MDConfItem(QStringLiteral("/nemo/apps/libglacier/dpScaleFactor")); + m_dpScaleFactor = dpScaleFactorValue->value("1").toFloat(); + + MDConfItem* dpi = new MDConfItem("/lipstick/screen/primary/physicalDotsPerInch"); + m_mmScaleFactor = dpi->value("1").toReal() / 2.45 / 10; loadDefaultValue(); @@ -40,7 +53,9 @@ Theme::Theme(QObject* parent) m_theme = m_themeValue->value().toString(); connect(m_themeValue, &MDConfItem::valueChanged, this, &Theme::themeValueChanged); - connect(m_size, &Sizing::dpScaleFactorChanged, this, &Theme::setThemeValues); + connect(dpScaleFactorValue, &MDConfItem::valueChanged, this, &Theme::setThemeValues); + connect(dpi, &MDConfItem::valueChanged, this, &Theme::setThemeValues); + connect(physicalDotsPerInchConf, &MDConfItem::valueChanged, this, &Theme::setThemeValues); if (!m_theme.isEmpty()) { loadTheme(m_theme); @@ -79,8 +94,24 @@ bool Theme::loadTheme(QString fileName) return true; } +float Theme::dp(float value) +{ + return value * m_dpScaleFactor; +} + +float Theme::mm(float value) +{ + return value * m_mmScaleFactor; +} + void Theme::setThemeValues() { + MDConfItem* dpScaleFactorValue = new MDConfItem(QStringLiteral("/nemo/apps/libglacier/dpScaleFactor")); + m_dpScaleFactor = dpScaleFactorValue->value("0").toFloat(); + + qreal dpi = MDConfItem("/lipstick/screen/primary/physicalDotsPerInch").value().toReal(); + m_mmScaleFactor = dpi / 2.45 / 10; + QString themeJsonString; bool updated = false; @@ -100,99 +131,99 @@ void Theme::setThemeValues() } if (theme.value("itemWidthExtraLarge").toString().toFloat() != 0 && floor(theme.value("itemWidthExtraLarge").toString().toFloat()) != m_itemWidthExtraLarge) { - m_itemWidthExtraLarge = floor(theme.value("itemWidthExtraLarge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemWidthExtraLarge = floor(theme.value("itemWidthExtraLarge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemWidthLarge").toString().toFloat() != 0 && floor(theme.value("itemWidthLarge").toString().toFloat()) != m_itemWidthLarge) { - m_itemWidthLarge = floor(theme.value("itemWidthLarge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemWidthLarge = floor(theme.value("itemWidthLarge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemWidthMedium").toString().toFloat() != 0 && floor(theme.value("itemWidthMedium").toString().toFloat()) != m_itemWidthMedium) { - m_itemWidthMedium = floor(theme.value("itemWidthMedium").toString().toFloat() * m_size->dpScaleFactor()); + m_itemWidthMedium = floor(theme.value("itemWidthMedium").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemWidthSmall").toString().toFloat() != 0 && floor(theme.value("itemWidthSmall").toString().toFloat()) != m_itemWidthSmall) { - m_itemWidthSmall = floor(theme.value("itemWidthSmall").toString().toFloat() * m_size->dpScaleFactor()); + m_itemWidthSmall = floor(theme.value("itemWidthSmall").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemWidthExtraSmall").toString().toFloat() != 0 && floor(theme.value("itemWidthExtraSmall").toString().toFloat()) != m_itemWidthExtraSmall) { - m_itemWidthExtraSmall = floor(theme.value("itemWidthExtraSmall").toString().toFloat() * m_size->dpScaleFactor()); + m_itemWidthExtraSmall = floor(theme.value("itemWidthExtraSmall").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemHeightHuge").toString().toFloat() != 0 && floor(theme.value("itemHeightHuge").toString().toFloat()) != m_itemHeightHuge) { - m_itemHeightHuge = floor(theme.value("itemHeightHuge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemHeightHuge = floor(theme.value("itemHeightHuge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemHeightExtraLarge").toString().toFloat() != 0 && floor(theme.value("itemHeightExtraLarge").toString().toFloat()) != m_itemHeightExtraLarge) { - m_itemHeightExtraLarge = floor(theme.value("itemHeightExtraLarge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemHeightExtraLarge = floor(theme.value("itemHeightExtraLarge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemHeightLarge").toString().toFloat() != 0 && floor(theme.value("itemHeightLarge").toString().toFloat()) != m_itemHeightLarge) { - m_itemHeightLarge = floor(theme.value("itemHeightLarge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemHeightLarge = floor(theme.value("itemHeightLarge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemHeightMedium").toString().toFloat() != 0 && floor(theme.value("itemHeightMedium").toString().toFloat()) != m_itemHeightMedium) { - m_itemHeightMedium = floor(theme.value("itemHeightMedium").toString().toFloat() * m_size->dpScaleFactor()); + m_itemHeightMedium = floor(theme.value("itemHeightMedium").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemHeightSmall").toString().toFloat() != 0 && floor(theme.value("itemHeightSmall").toString().toFloat()) != m_itemHeightSmall) { - m_itemHeightSmall = floor(theme.value("itemHeightSmall").toString().toFloat() * m_size->dpScaleFactor()); + m_itemHeightSmall = floor(theme.value("itemHeightSmall").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemHeightExtraSmall").toString().toFloat() != 0 && floor(theme.value("itemHeightExtraSmall").toString().toFloat()) != m_itemHeightExtraSmall) { - m_itemHeightExtraSmall = floor(theme.value("itemHeightExtraSmall").toString().toFloat() * m_size->dpScaleFactor()); + m_itemHeightExtraSmall = floor(theme.value("itemHeightExtraSmall").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemSpacingHuge").toString().toFloat() != 0 && floor(theme.value("itemSpacingHuge").toString().toFloat()) != m_itemSpacingHuge) { - m_itemSpacingHuge = floor(theme.value("itemSpacingHuge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemSpacingHuge = floor(theme.value("itemSpacingHuge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemSpacingLarge").toString().toFloat() != 0 && floor(theme.value("itemSpacingLarge").toString().toFloat()) != m_itemSpacingLarge) { - m_itemSpacingLarge = floor(theme.value("itemSpacingLarge").toString().toFloat() * m_size->dpScaleFactor()); + m_itemSpacingLarge = floor(theme.value("itemSpacingLarge").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemSpacingMedium").toString().toFloat() != 0 && floor(theme.value("itemSpacingMedium").toString().toFloat()) != m_itemSpacingMedium) { - m_itemSpacingMedium = floor(theme.value("itemSpacingMedium").toString().toFloat() * m_size->dpScaleFactor()); + m_itemSpacingMedium = floor(theme.value("itemSpacingMedium").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemSpacingSmall").toString().toFloat() != 0 && floor(theme.value("itemSpacingSmall").toString().toFloat()) != m_itemSpacingSmall) { - m_itemSpacingSmall = floor(theme.value("itemSpacingSmall").toString().toFloat() * m_size->dpScaleFactor()); + m_itemSpacingSmall = floor(theme.value("itemSpacingSmall").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("itemSpacingExtraSmall").toString().toFloat() != 0 && floor(theme.value("itemSpacingExtraSmall").toString().toFloat()) != m_itemSpacingExtraSmall) { - m_itemSpacingExtraSmall = floor(theme.value("itemSpacingExtraSmall").toString().toFloat() * m_size->dpScaleFactor()); + m_itemSpacingExtraSmall = floor(theme.value("itemSpacingExtraSmall").toString().toFloat() * m_dpScaleFactor); updated = true; } if (theme.value("fontSizeExtraLarge").toInt() != 0 && floor(theme.value("fontSizeExtraLarge").toInt()) != m_fontSizeExtraLarge) { - m_fontSizeExtraLarge = floor(theme.value("fontSizeExtraLarge").toInt() * m_size->dpScaleFactor()); + m_fontSizeExtraLarge = floor(theme.value("fontSizeExtraLarge").toInt() * m_dpScaleFactor); updated = true; } if (theme.value("fontSizeLarge").toInt() != 0 && floor(theme.value("fontSizeLarge").toInt()) != m_fontSizeLarge) { - m_fontSizeLarge = floor(theme.value("fontSizeLarge").toInt() * m_size->dpScaleFactor()); + m_fontSizeLarge = floor(theme.value("fontSizeLarge").toInt() * m_dpScaleFactor); updated = true; } if (theme.value("fontSizeMedium").toInt() != 0 && floor(theme.value("fontSizeMedium").toInt()) != m_fontSizeMedium) { - m_fontSizeMedium = floor(theme.value("fontSizeMedium").toInt() * m_size->dpScaleFactor()); + m_fontSizeMedium = floor(theme.value("fontSizeMedium").toInt() * m_dpScaleFactor); updated = true; } if (theme.value("fontSizeSmall").toInt() != 0 && floor(theme.value("fontSizeSmall").toInt()) != m_fontSizeSmall) { - m_fontSizeSmall = floor(theme.value("fontSizeSmall").toInt() * m_size->dpScaleFactor()); + m_fontSizeSmall = floor(theme.value("fontSizeSmall").toInt() * m_dpScaleFactor); updated = true; } if (theme.value("fontSizeTiny").toInt() != 0 && floor(theme.value("fontSizeTiny").toInt()) != m_fontSizeTiny) { - m_fontSizeTiny = floor(theme.value("fontSizeTiny").toInt() * m_size->dpScaleFactor()); + m_fontSizeTiny = floor(theme.value("fontSizeTiny").toInt() * m_dpScaleFactor); updated = true; } if (theme.value("fontWeightLarge").toInt() != 0 && theme.value("fontWeightLarge").toInt() != m_fontWeightLarge) { - m_fontWeightLarge = theme.value("fontWeightLarge").toInt() * m_size->dpScaleFactor(); + m_fontWeightLarge = theme.value("fontWeightLarge").toInt() * m_dpScaleFactor; updated = true; } if (theme.value("fontWeightMedium").toInt() != 0 && theme.value("fontWeightMedium").toInt() != m_fontWeightMedium) { - m_fontWeightMedium = theme.value("fontWeightMedium").toInt() * m_size->dpScaleFactor(); + m_fontWeightMedium = theme.value("fontWeightMedium").toInt() * m_dpScaleFactor; updated = true; } @@ -246,32 +277,32 @@ void Theme::themeValueChanged() void Theme::loadDefaultValue() { // Load defaults - m_itemWidthExtraLarge = floor(450 * m_size->dpScaleFactor()); - m_itemWidthLarge = floor(320 * m_size->dpScaleFactor()); - m_itemWidthMedium = floor(240 * m_size->dpScaleFactor()); - m_itemWidthSmall = floor(120 * m_size->dpScaleFactor()); - m_itemWidthExtraSmall = floor(72 * m_size->dpScaleFactor()); - - m_itemHeightHuge = floor(80 * m_size->dpScaleFactor()); - m_itemHeightExtraLarge = floor(75 * m_size->dpScaleFactor()); - m_itemHeightLarge = floor(63 * m_size->dpScaleFactor()); - m_itemHeightMedium = floor(50 * m_size->dpScaleFactor()); - m_itemHeightSmall = floor(40 * m_size->dpScaleFactor()); - m_itemHeightExtraSmall = floor(32 * m_size->dpScaleFactor()); - - m_itemSpacingHuge = floor(48 * m_size->dpScaleFactor()); - m_itemSpacingLarge = floor(24 * m_size->dpScaleFactor()); - m_itemSpacingMedium = floor(18 * m_size->dpScaleFactor()); - m_itemSpacingSmall = floor(14 * m_size->dpScaleFactor()); - m_itemSpacingExtraSmall = floor(12 * m_size->dpScaleFactor()); - - m_fontSizeExtraLarge = floor(44 * m_size->dpScaleFactor()); - m_fontSizeLarge = floor(24 * m_size->dpScaleFactor()); - m_fontSizeMedium = floor(20 * m_size->dpScaleFactor()); - m_fontSizeSmall = floor(18 * m_size->dpScaleFactor()); - m_fontSizeTiny = floor(14 * m_size->dpScaleFactor()); - m_fontWeightLarge = 63 * m_size->dpScaleFactor(); - m_fontWeightMedium = 25 * m_size->dpScaleFactor(); + m_itemWidthExtraLarge = floor(450 * m_dpScaleFactor); + m_itemWidthLarge = floor(320 * m_dpScaleFactor); + m_itemWidthMedium = floor(240 * m_dpScaleFactor); + m_itemWidthSmall = floor(120 * m_dpScaleFactor); + m_itemWidthExtraSmall = floor(72 * m_dpScaleFactor); + + m_itemHeightHuge = floor(80 * m_dpScaleFactor); + m_itemHeightExtraLarge = floor(75 * m_dpScaleFactor); + m_itemHeightLarge = floor(63 * m_dpScaleFactor); + m_itemHeightMedium = floor(50 * m_dpScaleFactor); + m_itemHeightSmall = floor(40 * m_dpScaleFactor); + m_itemHeightExtraSmall = floor(32 * m_dpScaleFactor); + + m_itemSpacingHuge = floor(48 * m_dpScaleFactor); + m_itemSpacingLarge = floor(24 * m_dpScaleFactor); + m_itemSpacingMedium = floor(18 * m_dpScaleFactor); + m_itemSpacingSmall = floor(14 * m_dpScaleFactor); + m_itemSpacingExtraSmall = floor(12 * m_dpScaleFactor); + + m_fontSizeExtraLarge = floor(44 * m_dpScaleFactor); + m_fontSizeLarge = floor(24 * m_dpScaleFactor); + m_fontSizeMedium = floor(20 * m_dpScaleFactor); + m_fontSizeSmall = floor(18 * m_dpScaleFactor); + m_fontSizeTiny = floor(14 * m_dpScaleFactor); + m_fontWeightLarge = 63 * m_dpScaleFactor; + m_fontWeightMedium = 25 * m_dpScaleFactor; m_fontPath = "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf"; m_accentColor = "#0091e5"; @@ -281,3 +312,13 @@ void Theme::loadDefaultValue() m_backgroundColor = "#000000"; m_backgroundAccentColor = "#ffffff"; } + +float Theme::mmScaleFactor() const +{ + return m_mmScaleFactor; +} + +float Theme::dpScaleFactor() const +{ + return m_dpScaleFactor; +} diff --git a/src/core/theme.h b/src/core/theme.h index 6996b9f..d92f1fe 100644 --- a/src/core/theme.h +++ b/src/core/theme.h @@ -24,12 +24,13 @@ #include #include -class Sizing; - class Theme : public QObject { Q_OBJECT Q_DISABLE_COPY(Theme) + Q_PROPERTY(float mmScaleFactor READ mmScaleFactor NOTIFY mmScaleFactorChanged) + Q_PROPERTY(float dpScaleFactor READ dpScaleFactor NOTIFY dpScaleFactorChanged) + Q_PROPERTY(qreal iconSizeLauncher READ iconSizeLauncher NOTIFY themeUpdated) Q_PROPERTY(qreal itemWidthExtraLarge READ itemWidthExtraLarge NOTIFY themeUpdated) @@ -73,9 +74,10 @@ class Theme : public QObject { explicit Theme(QObject* parent = nullptr); static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine); - Sizing* size() const { return m_size; } - Q_INVOKABLE bool loadTheme(const QString fileName); + Q_INVOKABLE float dp(float value); + Q_INVOKABLE float mm(float value); + qreal itemWidthLarge() const { return m_itemWidthLarge; } qreal itemWidthMedium() const { return m_itemWidthMedium; } qreal itemWidthSmall() const { return m_itemWidthSmall; } @@ -110,15 +112,18 @@ class Theme : public QObject { QString textColor() const { return m_textColor; } QString backgroundColor() const { return m_backgroundColor; } QString backgroundAccentColor() const { return m_backgroundAccentColor; } - qreal iconSizeLauncher() const { return m_iconSizeLauncher; } QString themePath() const { return m_theme; } - qreal itemWidthExtraLarge() const { return m_itemHeightExtraLarge; } + float mmScaleFactor() const; + float dpScaleFactor() const; + signals: void themeUpdated(); void desktopModeChanged(); + void mmScaleFactorChanged(); + void dpScaleFactorChanged(); private slots: void themeValueChanged(); @@ -167,7 +172,8 @@ private slots: void setThemeValues(); MDConfItem* m_themeValue; - Sizing* m_size; + float m_mmScaleFactor; + float m_dpScaleFactor; }; #endif // THEME_H