Commit 5634d3a8 authored by David Redondo's avatar David Redondo 🏎

Use default scheme option of KColorSchemeManager if available

Since KF 5.67 Kcolorschememanager has a system theme option that reacts to system
theme changes so we don't need to read the system color scheme if the user didn't
set a custom scheme.
parent 03bed527
...@@ -63,7 +63,14 @@ QString ColorSchemeChooser::loadCurrentScheme() const ...@@ -63,7 +63,14 @@ QString ColorSchemeChooser::loadCurrentScheme() const
{ {
KSharedConfigPtr config = KSharedConfig::openConfig(); KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup cg(config, "UiSettings"); KConfigGroup cg(config, "UiSettings");
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 67, 0)
// Since 5.67 KColorSchemeManager includes a system color scheme option that reacts to system
// scheme changes. This scheme will be activated if we pass an empty string to KColorSchemeManager
// So no need anymore to read the the current global scheme ourselves if no custom one is configured.
return cg.readEntry("ColorScheme");
#else
return cg.readEntry("ColorScheme", currentDesktopDefaultScheme()); return cg.readEntry("ColorScheme", currentDesktopDefaultScheme());
#endif
} }
void ColorSchemeChooser::saveCurrentScheme(const QString &name) void ColorSchemeChooser::saveCurrentScheme(const QString &name)
...@@ -74,6 +81,7 @@ void ColorSchemeChooser::saveCurrentScheme(const QString &name) ...@@ -74,6 +81,7 @@ void ColorSchemeChooser::saveCurrentScheme(const QString &name)
cg.sync(); cg.sync();
} }
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 67, 0)
QString ColorSchemeChooser::currentDesktopDefaultScheme() const QString ColorSchemeChooser::currentDesktopDefaultScheme() const
{ {
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdeglobals"));
...@@ -85,6 +93,7 @@ QString ColorSchemeChooser::currentDesktopDefaultScheme() const ...@@ -85,6 +93,7 @@ QString ColorSchemeChooser::currentDesktopDefaultScheme() const
const QString name = KConfigGroup(schemeFile, "General").readEntry("Name", scheme); const QString name = KConfigGroup(schemeFile, "General").readEntry("Name", scheme);
return name; return name;
} }
#endif
QString ColorSchemeChooser::currentSchemeName() const QString ColorSchemeChooser::currentSchemeName() const
{ {
...@@ -93,7 +102,12 @@ QString ColorSchemeChooser::currentSchemeName() const ...@@ -93,7 +102,12 @@ QString ColorSchemeChooser::currentSchemeName() const
QAction* const action = menu()->activeAction(); QAction* const action = menu()->activeAction();
if(action) return KLocalizedString::removeAcceleratorMarker(action->text()); if(action) return KLocalizedString::removeAcceleratorMarker(action->text());
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 67, 0)
// See above
return QString();
#else
return currentDesktopDefaultScheme(); return currentDesktopDefaultScheme();
#endif
} }
void ColorSchemeChooser::slotSchemeChanged(QAction* triggeredAction) void ColorSchemeChooser::slotSchemeChanged(QAction* triggeredAction)
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
#define COLORSCHEMECHOOSER_H #define COLORSCHEMECHOOSER_H
#include <QAction> #include <QAction>
#include <QtGlobal>
#include <kconfigwidgets_version.h>
#include "mainwindow.h" #include "mainwindow.h"
...@@ -47,7 +50,9 @@ private Q_SLOTS: ...@@ -47,7 +50,9 @@ private Q_SLOTS:
private: private:
QString loadCurrentScheme() const; QString loadCurrentScheme() const;
void saveCurrentScheme(const QString &name); void saveCurrentScheme(const QString &name);
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 67, 0)
QString currentDesktopDefaultScheme() const; QString currentDesktopDefaultScheme() const;
#endif
}; };
} // namespace KDevelop } // namespace KDevelop
......
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