diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive Completion Config ConfigWidgets CoreAddons DBusAddons Declarative I18n IconThemes - KIO Plasma PlasmaQuick Service TextEditor WidgetsAddons DocTools) + KIO Plasma PlasmaQuick Service TextEditor WidgetsAddons DocTools ConfigWidgets) ######################################################################### if (EXISTS "${CMAKE_SOURCE_DIR}/.git") diff --git a/cuttlefish/autotests/CMakeLists.txt b/cuttlefish/autotests/CMakeLists.txt --- a/cuttlefish/autotests/CMakeLists.txt +++ b/cuttlefish/autotests/CMakeLists.txt @@ -15,4 +15,5 @@ KF5::Package KF5::Service KF5::Plasma + KF5::ConfigWidgets ) diff --git a/cuttlefish/package/contents/ui/Comparison.qml b/cuttlefish/package/contents/ui/Comparison.qml --- a/cuttlefish/package/contents/ui/Comparison.qml +++ b/cuttlefish/package/contents/ui/Comparison.qml @@ -8,7 +8,8 @@ property int comparisonSize background: Rectangle { id:background - color: cuttlefish.viewbgcolor + Kirigami.Theme.colorSet: Kirigami.Theme.View + color: Kirigami.Theme.backgroundColor anchors.fill: parent } @@ -20,12 +21,6 @@ } ColumnLayout { - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor RowLayout { Layout.alignment: Qt.AlignHCenter QQC2.Slider { diff --git a/cuttlefish/package/contents/ui/IconGridDelegate.qml b/cuttlefish/package/contents/ui/IconGridDelegate.qml --- a/cuttlefish/package/contents/ui/IconGridDelegate.qml +++ b/cuttlefish/package/contents/ui/IconGridDelegate.qml @@ -50,23 +50,9 @@ anchors { fill: parent } - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor } Kirigami.Icon { - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor id: delegateIcon width: iconSize height: width @@ -78,13 +64,6 @@ } QQC2.Label { - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor font.pointSize: iconSize > 96 ? theme.defaultFont.pointSize : theme.smallestFont.pointSize text: iconName wrapMode: Text.Wrap diff --git a/cuttlefish/package/contents/ui/Preview.qml b/cuttlefish/package/contents/ui/Preview.qml --- a/cuttlefish/package/contents/ui/Preview.qml +++ b/cuttlefish/package/contents/ui/Preview.qml @@ -31,14 +31,6 @@ property alias iconPreview: iconPreview property alias dualMont: dualMont - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - color: Kirigami.Theme.backgroundColor FileDialog { @@ -103,13 +95,6 @@ } Rectangle { id: iconPreview - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor property bool screenshotting: false diff --git a/cuttlefish/package/contents/ui/ResponsivePreview.qml b/cuttlefish/package/contents/ui/ResponsivePreview.qml --- a/cuttlefish/package/contents/ui/ResponsivePreview.qml +++ b/cuttlefish/package/contents/ui/ResponsivePreview.qml @@ -32,14 +32,6 @@ handleOpenIcon.source: "dialog-close" handleClosedIcon.source: "view-preview" - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - focus: false actions: cuttlefish.actions diff --git a/cuttlefish/package/contents/ui/SvgGrid.qml b/cuttlefish/package/contents/ui/SvgGrid.qml --- a/cuttlefish/package/contents/ui/SvgGrid.qml +++ b/cuttlefish/package/contents/ui/SvgGrid.qml @@ -57,13 +57,6 @@ } Rectangle { - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor color: theme.highlightColor opacity: iconGrid.currentIndex == index ? 1.0 : 0 Behavior on opacity { NumberAnimation { duration: units.shortDuration } } @@ -76,13 +69,6 @@ } Kirigami.Icon { - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor id: delegateIcon width: iconSize height: width @@ -94,13 +80,6 @@ } QQC2.Label { - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor font.pointSize: iconSize > 96 ? theme.defaultFont.pointSize : theme.smallestFont.pointSize text: modelData.fileName + " " + modelData.iconName wrapMode: QQC2.Text.Wrap diff --git a/cuttlefish/package/contents/ui/Tools.qml b/cuttlefish/package/contents/ui/Tools.qml --- a/cuttlefish/package/contents/ui/Tools.qml +++ b/cuttlefish/package/contents/ui/Tools.qml @@ -25,6 +25,7 @@ import QtQuick.Layouts 1.0 import org.kde.kirigami 2.8 as Kirigami +import org.kde.kquickcontrolsaddons 2.0 as KQCAddons Rectangle { id: root @@ -37,14 +38,6 @@ property alias currentIndex: colorcombo.currentIndex property alias value: sizeslider.value - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - RowLayout { anchors.fill: parent anchors.leftMargin: Kirigami.Units.smallSpacing @@ -128,13 +121,28 @@ QQC2.ComboBox { id: colorcombo visible: cuttlefish.widescreen - model: ["System Color Scheme", "Breeze (Normal)", "Breeze Dark"] + model: colorSchemes.colorSchemes delegate: QQC2.ItemDelegate { - text: i18n(modelData) + Kirigami.Theme.colorSet: Kirigami.Theme.View width: parent.width + highlighted: colorcombo.highlightedIndex == index + contentItem: RowLayout { + Kirigami.Icon { + source: model.decoration + Layout.preferredHeight: Kirigami.Units.iconSizes.small + Layout.preferredWidth: Kirigami.Units.iconSizes.small + } + QQC2.Label { + text: model.display + color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor + Layout.fillWidth: true + } + } } + textRole: "display" onActivated: (index) => { root.colorschemeChanged(index) + colorSchemes.activateColorScheme(currentText) } popup.modal: false } diff --git a/cuttlefish/package/contents/ui/ToolsResponsive.qml b/cuttlefish/package/contents/ui/ToolsResponsive.qml --- a/cuttlefish/package/contents/ui/ToolsResponsive.qml +++ b/cuttlefish/package/contents/ui/ToolsResponsive.qml @@ -30,14 +30,6 @@ width: parent.width color: Kirigami.Theme.backgroundColor - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - property alias currentIndex: colorcombo.currentIndex property alias value: sizeslider.value @@ -96,18 +88,33 @@ QQC2.ComboBox { id: colorcombo visible: !cuttlefish.widescreen - model: ["System Color Scheme", "Breeze (Normal)", "Breeze Dark"] + model: colorSchemes.colorSchemes delegate: QQC2.ItemDelegate { - text: i18n(modelData) + Kirigami.Theme.colorSet: Kirigami.Theme.View width: parent.width + highlighted: colorcombo.highlightedIndex == index + contentItem: RowLayout { + Kirigami.Icon { + source: model.decoration + Layout.preferredHeight: Kirigami.Units.iconSizes.small + Layout.preferredWidth: Kirigami.Units.iconSizes.small + } + QQC2.Label { + text: model.display + color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor + Layout.fillWidth: true + } + } } + textRole: "display" onActivated: (index) => { root.colorschemeChanged(index) + colorSchemes.activateColorScheme(currentText) } popup.modal: false } Item { width: Kirigami.Units.largeSpacing * 3 } } -} \ No newline at end of file +} diff --git a/cuttlefish/package/contents/ui/cuttlefish.qml b/cuttlefish/package/contents/ui/cuttlefish.qml --- a/cuttlefish/package/contents/ui/cuttlefish.qml +++ b/cuttlefish/package/contents/ui/cuttlefish.qml @@ -39,29 +39,9 @@ property bool widescreen: cuttlefish.width >= 800 property int iconSize: Kirigami.Units.iconSizes.large - property bool darkScheme: false - property bool usesPlasmaTheme: true - property var schemeStash property alias actions: actions.actions - property color textcolor: Kirigami.Theme.textColor - property color bgcolor: Kirigami.Theme.backgroundColor - property color highlightcolor: Kirigami.Theme.highlightColor - property color highlightedtextcolor: Kirigami.Theme.highlightedTextColor - property color positivetextcolor: Kirigami.Theme.positiveTextColor - property color neutraltextcolor: Kirigami.Theme.neutralTextColor - property color negativetextcolor: Kirigami.Theme.negativeTextColor - property color viewbgcolor: Kirigami.Theme.viewBackgroundColor - - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - Loader { // Use a Loader instead of creating a GMB directly, // so if the GMB errors, it doesn't affect Cuttlefish's operation @@ -103,43 +83,6 @@ } } } - function changeColors(index) { - switch(index) { - case 0: - cuttlefish.Kirigami.Theme.inherit = true - cuttlefish.textcolor = cuttlefish.schemeStash[0] - cuttlefish.bgcolor = cuttlefish.schemeStash[1] - cuttlefish.highlightcolor = cuttlefish.schemeStash[2] - cuttlefish.highlightedtextcolor = cuttlefish.schemeStash[3] - cuttlefish.positivetextcolor = cuttlefish.schemeStash[4] - cuttlefish.neutraltextcolor = cuttlefish.schemeStash[5] - cuttlefish.negativetextcolor = cuttlefish.schemeStash[6] - cuttlefish.viewbgcolor = cuttlefish.schemeStash[7] - break - case 1: - cuttlefish.Kirigami.Theme.inherit = false - cuttlefish.textcolor = "#232629" - cuttlefish.bgcolor = "#eff0f1" - cuttlefish.highlightcolor = "#3daee9" - cuttlefish.highlightedtextcolor = "#eff0f1" - cuttlefish.positivetextcolor = "#27ae60" - cuttlefish.neutraltextcolor = "#f67400" - cuttlefish.negativetextcolor = "#da4453" - cuttlefish.viewbgcolor = "#fcfcfc" - break - case 2: - cuttlefish.Kirigami.Theme.inherit = false - cuttlefish.textcolor = "#eff0f1" - cuttlefish.bgcolor = "#31363b" - cuttlefish.highlightcolor = "#3daee9" - cuttlefish.highlightedtextcolor = "#eff0f1" - cuttlefish.positivetextcolor = "#27ae60" - cuttlefish.neutraltextcolor = "#f67400" - cuttlefish.negativetextcolor = "#da4453" - cuttlefish.viewbgcolor = "#232629" - break - } - } function indexToSize(ix) { @@ -156,7 +99,7 @@ } Rectangle { Kirigami.Theme.colorSet: Kirigami.Theme.View - color: tools.currentIndex != 0 ? cuttlefish.viewbgcolor : Kirigami.Theme.viewBackgroundColor + color: Kirigami.Theme.backgroundColor anchors.fill: parent } ColumnLayout { @@ -218,7 +161,6 @@ Connections { target: tools onColorschemeChanged: (index) => { - cuttlefish.changeColors(index) toolsResponsive.currentIndex = index } onSliderValueChanged: (val) => { @@ -228,7 +170,6 @@ Connections { target: toolsResponsive onColorschemeChanged: (index) => { - cuttlefish.changeColors(index) tools.currentIndex = index } onSliderValueChanged: (val) => { @@ -246,16 +187,4 @@ property variant sizes: [] property bool scalable: true } - - Component.onCompleted: { - cuttlefish.schemeStash += Kirigami.Theme.textColor - cuttlefish.schemeStash += Kirigami.Theme.backgroundColor - cuttlefish.schemeStash += Kirigami.Theme.highlightColor - cuttlefish.schemeStash += Kirigami.Theme.highlightedTextColor - cuttlefish.schemeStash += Kirigami.Theme.positiveTextColor - cuttlefish.schemeStash += Kirigami.Theme.neutralTextColor - cuttlefish.schemeStash += Kirigami.Theme.negativeTextColor - cuttlefish.schemeStash += Kirigami.Theme.viewBackgroundColor - console.log(cuttlefish.schemeStash) - } } diff --git a/cuttlefish/src/CMakeLists.txt b/cuttlefish/src/CMakeLists.txt --- a/cuttlefish/src/CMakeLists.txt +++ b/cuttlefish/src/CMakeLists.txt @@ -2,6 +2,7 @@ set(cuttlefish_SRCS main.cpp iconmodel.cpp + colorschemes.cpp ) add_executable(cuttlefish ${cuttlefish_SRCS}) @@ -14,6 +15,7 @@ KF5::Plasma KF5::KIOWidgets KF5::Declarative + KF5::ConfigWidgets KF5::I18n KF5::IconThemes KF5::Package diff --git a/cuttlefish/src/colorschemes.h b/cuttlefish/src/colorschemes.h new file mode 100644 --- /dev/null +++ b/cuttlefish/src/colorschemes.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * * + * Copyright 2019 David Redondo * + * * + * 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 . * + * * + ***************************************************************************/ + +#ifndef CUTTLEFISHCOLORSCHEMES_H +#define CUTTLEFISHCOLORSCHEMES_H + +#include +#include + +class QAbstractItemModel; + +class KColorSchemeManager; + +namespace CuttleFish { +class ColorSchemes : public QObject { + + Q_OBJECT + + Q_PROPERTY(QAbstractItemModel *colorSchemes READ colorSchemes CONSTANT) + +public: + Q_INVOKABLE void activateColorScheme(const QString &name); + + ColorSchemes(QObject *parent); + + QAbstractItemModel* colorSchemes(); + +private: + KColorSchemeManager* m_colorManager; +}; +} +#endif diff --git a/cuttlefish/src/colorschemes.cpp b/cuttlefish/src/colorschemes.cpp new file mode 100644 --- /dev/null +++ b/cuttlefish/src/colorschemes.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * * + * Copyright 2019 David Redondo * + * * + * 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 "colorschemes.h" + +#include + +#include +#include +#include +#include + +using namespace CuttleFish; + +ColorSchemes::ColorSchemes(QObject *parent) + : QObject(parent) + , m_colorManager(new KColorSchemeManager(this)) +{ + QAbstractItemModel *model = m_colorManager->model(); +} + +QAbstractItemModel* CuttleFish::ColorSchemes::colorSchemes() +{ + return m_colorManager->model(); +} + +void ColorSchemes::activateColorScheme(const QString& name) +{ + m_colorManager->activateScheme(m_colorManager->indexForScheme(name)); +} + diff --git a/cuttlefish/src/iconmodel.h b/cuttlefish/src/iconmodel.h --- a/cuttlefish/src/iconmodel.h +++ b/cuttlefish/src/iconmodel.h @@ -29,6 +29,8 @@ #include #include +class KColorSchemeManager; + namespace CuttleFish { @@ -87,6 +89,7 @@ QString plasmaTheme() const; QStringList plasmathemes() const; QStringList categories() const; + QAbstractItemModel* colorschemes() const; bool loading(); diff --git a/cuttlefish/src/iconmodel.cpp b/cuttlefish/src/iconmodel.cpp --- a/cuttlefish/src/iconmodel.cpp +++ b/cuttlefish/src/iconmodel.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include diff --git a/cuttlefish/src/main.cpp b/cuttlefish/src/main.cpp --- a/cuttlefish/src/main.cpp +++ b/cuttlefish/src/main.cpp @@ -35,6 +35,7 @@ #include // Own +#include "colorschemes.h" #include "iconmodel.h" void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) @@ -120,18 +121,22 @@ } auto iconModel = new CuttleFish::IconModel(engine.rootContext()); + auto colorSchemes = new CuttleFish::ColorSchemes(engine.rootContext()); engine.rootContext()->setContextProperty("iconModel", iconModel); engine.rootContext()->setContextProperty("pickerMode", parser.isSet("picker")); + engine.rootContext()->setContextProperty("colorSchemes", colorSchemes); engine.load(QUrl::fromLocalFile(package.filePath("mainscript"))); if (engine.rootObjects().isEmpty()) { return -1; } #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) qmlRegisterType(); + qmlRegisterType(); #else qmlRegisterAnonymousType("org.kde.plasma.sdk", 1); + qmlRegisterAnonymousType("org.kde.plasma.sdk", 1); #endif return app.exec();