summarylogtreecommitdiffstats
path: root/qt5ct-shenanigans.patch
blob: a4975c62bcb1a76e60c3e4b5185b9c473a546223 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
Index: qt5ct/CMakeLists.txt
===================================================================
--- qt5ct/CMakeLists.txt	(revision 690)
+++ qt5ct/CMakeLists.txt	(working copy)
@@ -27,8 +27,11 @@
 
 ADD_DEFINITIONS(-DQT_DISABLE_DEPRECATED_BEFORE=0x050C00 -DUSE_WIDGETS)
 
-find_package(Qt5 ${QT_MINIMUM_VERSION} COMPONENTS Widgets Concurrent LinguistTools REQUIRED)
+find_package(Qt5 ${QT_MINIMUM_VERSION} COMPONENTS Widgets Concurrent LinguistTools QuickControls2 REQUIRED)
 find_package(Qt5Gui ${QT_MINIMUM_VERSION} CONFIG REQUIRED Private)
+find_package(KF5Config REQUIRED)
+find_package(KF5ConfigWidgets REQUIRED)
+find_package(KF5IconThemes REQUIRED)
 
 if(NOT DISABLE_DBUS)
     find_package(Qt5 ${QT_MINIMUM_VERSION} COMPONENTS DBus ThemeSupport REQUIRED)
@@ -54,7 +57,9 @@
     message(FATAL_ERROR "Could NOT find qtpaths executable")
 endif()
 
-execute_process(COMMAND ${QT_QTPATHS_EXECUTABLE} --plugin-dir OUTPUT_VARIABLE PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT PLUGINDIR)
+    execute_process(COMMAND ${QT_QTPATHS_EXECUTABLE} --plugin-dir OUTPUT_VARIABLE PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif()
 message(STATUS "Plugin path: " ${PLUGINDIR})
 
 message(STATUS "Generating translations ...")
Index: qt5ct/src/qt5ct/CMakeLists.txt
===================================================================
--- qt5ct/src/qt5ct/CMakeLists.txt	(revision 690)
+++ qt5ct/src/qt5ct/CMakeLists.txt	(working copy)
@@ -28,6 +28,6 @@
 )
 
 add_executable(qt5ct ${app_SRCS})
-target_link_libraries(qt5ct PRIVATE Qt5::Widgets Qt5::Concurrent Qt5::WidgetsPrivate qt5ct-common)
+target_link_libraries(qt5ct PRIVATE Qt5::Widgets Qt5::Concurrent Qt5::WidgetsPrivate KF5::ConfigCore qt5ct-common)
 install(TARGETS qt5ct DESTINATION ${CMAKE_INSTALL_BINDIR})
 install(FILES qt5ct.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
Index: qt5ct/src/qt5ct/appearancepage.cpp
===================================================================
--- qt5ct/src/qt5ct/appearancepage.cpp	(revision 690)
+++ qt5ct/src/qt5ct/appearancepage.cpp	(working copy)
@@ -35,6 +35,8 @@
 #include <QMenu>
 #include <QIcon>
 #include <QStringList>
+#include <KSharedConfig>
+#include <KConfigGroup>
 #include <qpa/qplatformthemefactory_p.h>
 #include "qt5ct.h"
 #include "appearancepage.h"
@@ -68,7 +70,7 @@
     QMenu *menu = new QMenu(this);
     menu->addAction(QIcon::fromTheme("document-new"), tr("Create"), this, SLOT(createColorScheme()));
     m_changeColorSchemeAction = menu->addAction(QIcon::fromTheme("accessories-text-editor"), tr("Edit"), this, SLOT(changeColorScheme()));
-    menu->addAction(QIcon::fromTheme("edit-copy"), tr("Create a Copy"), this, SLOT(copyColorScheme()));
+    m_copyColorSchemeAction = menu->addAction(QIcon::fromTheme("edit-copy"), tr("Create a Copy"), this, SLOT(copyColorScheme()));
     m_renameColorSchemeAction = menu->addAction(tr("Rename"), this, SLOT(renameColorScheme()));
     menu->addSeparator();
     m_removeColorSchemeAction = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Remove"), this, SLOT(removeColorScheme()));
@@ -301,6 +303,7 @@
 
 void AppearancePage::updateActions()
 {
+    m_copyColorSchemeAction->setVisible(!Qt5CT::isKColorScheme(m_ui->colorSchemeComboBox->currentData().toString()));
     if(m_ui->colorSchemeComboBox->count() == 0 ||
             !QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable())
     {
@@ -324,8 +327,7 @@
     m_ui->styleComboBox->setCurrentText(style);
 
     m_ui->customPaletteButton->setChecked(settings.value("custom_palette", false).toBool());
-    QString colorSchemePath = settings.value("color_scheme_path").toString();
-    colorSchemePath = Qt5CT::resolvePath(colorSchemePath); //replace environment variables
+    QString colorSchemePath = Qt5CT::resolvePath(settings.value("color_scheme_path").toString()); //replace environment variables
 
     QDir("/").mkpath(Qt5CT::userColorSchemePath());
     findColorSchemes(Qt5CT::userColorSchemePath());
@@ -378,11 +380,23 @@
 {
     QDir dir(path);
     dir.setFilter(QDir::Files);
-    dir.setNameFilters(QStringList() << "*.conf");
+    dir.setNameFilters(QStringList() << "*.conf" << "*.colors");
 
     for(const QFileInfo &info : dir.entryInfoList())
     {
-        m_ui->colorSchemeComboBox->addItem(info.baseName(), info.filePath());
+        QString name;
+        QString path = info.filePath();
+        if(Qt5CT::isKColorScheme(path))
+        {
+            KSharedConfigPtr config = KSharedConfig::openConfig(path, KConfig::SimpleConfig);
+            KConfigGroup group(config, "General");
+            name = group.readEntry("Name", info.baseName()) + " (KColorScheme)";
+        }
+        else
+        {
+            name = info.baseName();
+        }
+        m_ui->colorSchemeComboBox->addItem(name, path);
     }
 }
 
Index: qt5ct/src/qt5ct/appearancepage.h
===================================================================
--- qt5ct/src/qt5ct/appearancepage.h	(revision 690)
+++ qt5ct/src/qt5ct/appearancepage.h	(working copy)
@@ -72,7 +72,7 @@
     QStyle *m_selectedStyle = nullptr;
     QPalette m_customPalette;
     QWidget *m_previewWidget;
-    QAction *m_changeColorSchemeAction, *m_renameColorSchemeAction, *m_removeColorSchemeAction;
+    QAction *m_changeColorSchemeAction, *m_copyColorSchemeAction, *m_renameColorSchemeAction, *m_removeColorSchemeAction;
     Ui::PreviewForm *m_previewUi;
 };
 
Index: qt5ct/src/qt5ct-common/CMakeLists.txt
===================================================================
--- qt5ct/src/qt5ct-common/CMakeLists.txt	(revision 690)
+++ qt5ct/src/qt5ct-common/CMakeLists.txt	(working copy)
@@ -26,5 +26,5 @@
 
 add_library(qt5ct-common SHARED ${app_SRCS})
 set_target_properties(qt5ct-common PROPERTIES VERSION ${QT5CT_VERSION})
-target_link_libraries(qt5ct-common PRIVATE Qt5::Core Qt5::Gui)
+target_link_libraries(qt5ct-common PRIVATE Qt5::Core Qt5::Gui KF5::ConfigCore KF5::ConfigWidgets)
 install(TARGETS qt5ct-common DESTINATION ${CMAKE_INSTALL_LIBDIR})
Index: qt5ct/src/qt5ct-common/qt5ct.cpp
===================================================================
--- qt5ct/src/qt5ct-common/qt5ct.cpp	(revision 690)
+++ qt5ct/src/qt5ct-common/qt5ct.cpp	(working copy)
@@ -34,6 +34,8 @@
 #include <QFile>
 #include <QSettings>
 #include <QtDebug>
+#include <KSharedConfig>
+#include <KColorScheme>
 #include "qt5ct.h"
 
 #ifndef QT5CT_DATADIR
@@ -113,6 +115,7 @@
     for(const QString &p : QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation))
     {
         paths << (p + QLatin1String("/qt5ct/colors"));
+        paths << (p + QLatin1String("/color-schemes"));
     }
     paths << QLatin1String(QT5CT_DATADIR"/qt5ct/colors");
     paths.removeDuplicates();
@@ -121,6 +124,9 @@
 
 QString Qt5CT::resolvePath(const QString &path)
 {
+    if(path.isEmpty())
+        return path;
+
     QString tmp = path;
     tmp.replace("~", QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
     if(!tmp.contains("$"))
@@ -140,8 +146,15 @@
     return tmp;
 }
 
+bool Qt5CT::isKColorScheme(const QString &filePath)
+{
+    return filePath.toLower().endsWith(".colors");
+}
+
 QPalette Qt5CT::loadColorScheme(const QString &filePath, const QPalette &fallback)
 {
+    if(isKColorScheme(filePath))
+        return KColorScheme::createApplicationPalette(KSharedConfig::openConfig(filePath));
     QPalette customPalette;
     QSettings settings(filePath, QSettings::IniFormat);
     settings.beginGroup("ColorScheme");
Index: qt5ct/src/qt5ct-common/qt5ct.h
===================================================================
--- qt5ct/src/qt5ct-common/qt5ct.h	(revision 690)
+++ qt5ct/src/qt5ct-common/qt5ct.h	(working copy)
@@ -68,6 +68,7 @@
     static QString userColorSchemePath();
     static QStringList sharedColorSchemePaths();
     static QString resolvePath(const QString &path);
+    static bool isKColorScheme(const QString &filePath);
     static QPalette loadColorScheme(const QString &filePath, const QPalette &fallback);
 
     static void registerStyleInstance(StyleInstance *instance);
Index: qt5ct/src/qt5ct-qtplugin/CMakeLists.txt
===================================================================
--- qt5ct/src/qt5ct-qtplugin/CMakeLists.txt	(revision 690)
+++ qt5ct/src/qt5ct-qtplugin/CMakeLists.txt	(working copy)
@@ -9,7 +9,7 @@
 
 add_library(qt5ct-qtplugin MODULE ${app_SRCS})
 set_target_properties(qt5ct-qtplugin PROPERTIES OUTPUT_NAME qt5ct)
-target_link_libraries(qt5ct-qtplugin PRIVATE Qt5::Widgets Qt5::GuiPrivate qt5ct-common)
+target_link_libraries(qt5ct-qtplugin PRIVATE Qt5::Widgets Qt5::GuiPrivate Qt5::QuickControls2 KF5::IconThemes qt5ct-common)
 if(NOT DISABLE_DBUS)
     target_link_libraries(qt5ct-qtplugin PRIVATE Qt5::DBus Qt5::ThemeSupportPrivate)
 endif()
Index: qt5ct/src/qt5ct-qtplugin/qt5ctplatformtheme.cpp
===================================================================
--- qt5ct/src/qt5ct-qtplugin/qt5ctplatformtheme.cpp	(revision 690)
+++ qt5ct/src/qt5ct-qtplugin/qt5ctplatformtheme.cpp	(working copy)
@@ -45,6 +45,7 @@
 #endif
 #include <QFile>
 #include <QFileSystemWatcher>
+#include <QQuickStyle>
 
 #include "qt5ct.h"
 #include "qt5ctplatformtheme.h"
@@ -58,6 +59,9 @@
 #include <QStringList>
 #include <qpa/qplatformthemefactory_p.h>
 
+#include <KIconEngine>
+#include <KIconLoader>
+
 Q_LOGGING_CATEGORY(lqt5ct, "qt5ct", QtWarningMsg)
 
 //QT_QPA_PLATFORMTHEME=qt5ct
@@ -73,6 +77,9 @@
         QMetaObject::invokeMethod(this, "createFSWatcher", Qt::QueuedConnection);
 #endif
         QGuiApplication::setFont(m_generalFont);
+        //don't override the value explicitly set by the user
+        if(QQuickStyle::name().isEmpty() || QQuickStyle::name() == QLatin1String("Fusion"))
+            QQuickStyle::setStyle(QLatin1String("org.kde.desktop"));
     }
     qCDebug(lqt5ct) << "using qt5ct plugin";
 #ifdef QT_WIDGETS_LIB
@@ -79,6 +86,7 @@
     if(!QStyleFactory::keys().contains("qt5ct-style"))
         qCCritical(lqt5ct) << "unable to find qt5ct proxy style";
 #endif
+	QCoreApplication::instance()->installEventFilter(this);
 }
 
 Qt5CTPlatformTheme::~Qt5CTPlatformTheme()
@@ -185,6 +193,11 @@
 }
 #endif
 
+QIconEngine *Qt5CTPlatformTheme::createIconEngine(const QString &iconName) const
+{
+    return new KIconEngine(iconName, KIconLoader::global());
+}
+
 void Qt5CTPlatformTheme::applySettings()
 {
     if(!QGuiApplication::desktopSettingsAware() || m_isIgnored)
@@ -204,6 +217,9 @@
         }
     }
 
+    if(Qt5CT::isKColorScheme(m_schemePath))
+        qApp->setProperty("KDE_COLOR_SCHEME_PATH", m_schemePath);
+
 #ifdef QT_WIDGETS_LIB
     if(hasWidgets())
     {
@@ -295,12 +311,11 @@
 
     settings.beginGroup("Appearance");
     m_style = settings.value("style", "Fusion").toString();
-    QString schemePath = settings.value("color_scheme_path").toString();
-    if(!schemePath.isEmpty() && settings.value("custom_palette", false).toBool())
-    {
-        schemePath = Qt5CT::resolvePath(schemePath); //replace environment variables
-        m_palette = new QPalette(Qt5CT::loadColorScheme(schemePath, *QPlatformTheme::palette(SystemPalette)));
-    }
+    m_schemePath = settings.value("custom_palette", false).toBool()
+        ? Qt5CT::resolvePath(settings.value("color_scheme_path").toString()) //replace environment variables
+        : QString();
+    if(!m_schemePath.isEmpty())
+        m_palette = new QPalette(Qt5CT::loadColorScheme(m_schemePath, *QPlatformTheme::palette(SystemPalette)));
     m_iconTheme = settings.value("icon_theme").toString();
     //load dialogs
     if(!m_update)
@@ -414,3 +429,17 @@
     content.replace(regExp, "\n");
     return content;
 }
+
+//There's such a thing as KColorSchemeManager that lets the user to change the color scheme
+//application-wide and we should re-apply the color scheme if KCSM resets it to the default
+//which leads KColorScheme to get the color scheme from kdeglobals which won't help us.
+bool Qt5CTPlatformTheme::eventFilter(QObject *obj, QEvent *e)
+{
+    if(obj == qApp &&
+            e->type() == QEvent::DynamicPropertyChange &&
+            static_cast<QDynamicPropertyChangeEvent*>(e)->propertyName() == "KDE_COLOR_SCHEME_PATH" &&
+            qApp->property("KDE_COLOR_SCHEME_PATH").toString().isEmpty() &&
+            Qt5CT::isKColorScheme(m_schemePath))
+        applySettings();
+    return QObject::eventFilter(obj, e);
+}
Index: qt5ct/src/qt5ct-qtplugin/qt5ctplatformtheme.h
===================================================================
--- qt5ct/src/qt5ct-qtplugin/qt5ctplatformtheme.h	(revision 690)
+++ qt5ct/src/qt5ct-qtplugin/qt5ctplatformtheme.h	(working copy)
@@ -87,10 +87,13 @@
     //virtual QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size,
     //                               QPlatformTheme::IconOptions iconOptions = 0) const;
 
-    //virtual QIconEngine *createIconEngine(const QString &iconName) const;
+    virtual QIconEngine *createIconEngine(const QString &iconName) const;
     //virtual QList<QKeySequence> keyBindings(QKeySequence::StandardKey key) const;
     //virtual QString standardButtonText(int button) const;
 
+protected:
+	bool eventFilter(QObject *obj, QEvent *e) override;
+
 private slots:
     void applySettings();
 #ifdef QT_WIDGETS_LIB
@@ -104,7 +107,7 @@
     bool hasWidgets();
 #endif
     QString loadStyleSheets(const QStringList &paths);
-    QString m_style, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
+    QString m_style, m_schemePath, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
     QPalette *m_palette = nullptr;
     QFont m_generalFont, m_fixedFont;
     int m_doubleClickInterval;