Commit 2d8d17a7 authored by David Redondo's avatar David Redondo 🏎

Enable selecting all installed color schemes in Cuttlefish

Summary:
By using KColorSchemeManager we can enable viewing icons with all installed
color schemes. Also all the color setting everywhere can be dropped.

Test Plan: {F7936066}

Reviewers: #plasma, ngraham

Reviewed By: ngraham

Subscribers: ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25273
parent 56274d8f
......@@ -48,7 +48,7 @@ set_package_properties(KF5Kirigami2 PROPERTIES
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")
......
......@@ -15,4 +15,5 @@ ecm_add_test(iconmodeltest.cpp ../src/iconmodel.cpp
KF5::Package
KF5::Service
KF5::Plasma
KF5::ConfigWidgets
)
......@@ -8,7 +8,8 @@ Kirigami.OverlaySheet {
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 @@ Kirigami.OverlaySheet {
}
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 {
......
......@@ -50,23 +50,9 @@ MouseArea {
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 @@ MouseArea {
}
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
......
......@@ -31,14 +31,6 @@ Rectangle {
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 {
}
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
......
......@@ -32,14 +32,6 @@ Kirigami.GlobalDrawer {
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
......
......@@ -57,13 +57,6 @@ GridView {
}
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 @@ GridView {
}
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 @@ GridView {
}
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
......
......@@ -25,6 +25,7 @@ import QtQuick.Controls 2.5 as QQC2
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 @@ Rectangle {
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 @@ Rectangle {
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
}
......
......@@ -30,14 +30,6 @@ Rectangle {
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,13 +88,28 @@ Rectangle {
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
}
......@@ -110,4 +117,4 @@ Rectangle {
width: Kirigami.Units.largeSpacing * 3
}
}
}
\ No newline at end of file
}
......@@ -39,29 +39,9 @@ Kirigami.ApplicationWindow {
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 @@ Kirigami.ApplicationWindow {
}
}
}
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 @@ Kirigami.ApplicationWindow {
}
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 @@ Kirigami.ApplicationWindow {
Connections {
target: tools
onColorschemeChanged: (index) => {
cuttlefish.changeColors(index)
toolsResponsive.currentIndex = index
}
onSliderValueChanged: (val) => {
......@@ -228,7 +170,6 @@ Kirigami.ApplicationWindow {
Connections {
target: toolsResponsive
onColorschemeChanged: (index) => {
cuttlefish.changeColors(index)
tools.currentIndex = index
}
onSliderValueChanged: (val) => {
......@@ -246,16 +187,4 @@ Kirigami.ApplicationWindow {
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)
}
}
......@@ -2,6 +2,7 @@
set(cuttlefish_SRCS
main.cpp
iconmodel.cpp
colorschemes.cpp
)
add_executable(cuttlefish ${cuttlefish_SRCS})
......@@ -14,6 +15,7 @@ target_link_libraries(cuttlefish
KF5::Plasma
KF5::KIOWidgets
KF5::Declarative
KF5::ConfigWidgets
KF5::I18n
KF5::IconThemes
KF5::Package
......
/***************************************************************************
* *
* Copyright 2019 David Redondo <kde@david-redondo.de> *
* *
* 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 <QAbstractItemModel>
#include <KColorSchemeManager>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
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));
}
/***************************************************************************
* *
* Copyright 2019 David Redondo <kde@david-redondo.de> *
* *
* 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 <QObject>
#include <QString>
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
......@@ -33,6 +33,7 @@
#include <QJsonDocument>
#include <KConfigGroup>
#include <KColorSchemeManager>
#include <KIconLoader>
#include <KIconTheme>
#include <KSharedConfig>
......
......@@ -29,6 +29,8 @@
#include <QVariantMap>
#include <QVariantList>
class KColorSchemeManager;
namespace CuttleFish {
......@@ -87,6 +89,7 @@ public:
QString plasmaTheme() const;
QStringList plasmathemes() const;
QStringList categories() const;
QAbstractItemModel* colorschemes() const;
bool loading();
......
......@@ -35,6 +35,7 @@
#include <Plasma/Theme>
// Own
#include "colorschemes.h"
#include "iconmodel.h"
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
......@@ -120,8 +121,10 @@ int main(int argc, char **argv)
}
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()) {
......@@ -130,8 +133,10 @@ int main(int argc, char **argv)
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
qmlRegisterType<CuttleFish::IconModel>();
qmlRegisterType<CuttleFish::ColorSchemes>();
#else
qmlRegisterAnonymousType<CuttleFish::IconModel>("org.kde.plasma.sdk", 1);
qmlRegisterAnonymousType<CuttleFish::ColorSchemes>("org.kde.plasma.sdk", 1);
#endif
return app.exec();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment