148 lines
5.4 KiB
C++
148 lines
5.4 KiB
C++
#ifndef OLLIE_THEME_MANAGER_H
|
|
#define OLLIE_THEME_MANAGER_H
|
|
|
|
#include <QObject>
|
|
#include <QPalette>
|
|
#include <QSettings>
|
|
#include <QFileSystemWatcher>
|
|
#include <KConfigWatcher>
|
|
#include <KSharedConfig>
|
|
#include <QColor>
|
|
#include <QStringList>
|
|
#include <QFont>
|
|
#include <QVariant>
|
|
|
|
class ThemeManager : public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(QString mode READ mode WRITE setMode NOTIFY modeChanged)
|
|
Q_PROPERTY(QStringList availableSchemes READ availableSchemes CONSTANT)
|
|
Q_PROPERTY(bool isDark READ isDark NOTIFY paletteChanged)
|
|
Q_PROPERTY(bool overriding READ overriding NOTIFY paletteChanged)
|
|
|
|
// Palette color properties for QML binding
|
|
Q_PROPERTY(QColor windowColor READ windowColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor windowTextColor READ windowTextColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor baseColor READ baseColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor alternateBaseColor READ alternateBaseColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor textColor READ textColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor buttonColor READ buttonColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor buttonTextColor READ buttonTextColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor highlightColor READ highlightColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor tooltipBaseColor READ tooltipBaseColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor tooltipTextColor READ tooltipTextColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor linkColor READ linkColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor midColor READ midColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor darkColor READ darkColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor lightColor READ lightColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor dialogOutlineColor READ dialogOutlineColor NOTIFY paletteChanged)
|
|
Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor NOTIFY paletteChanged)
|
|
|
|
// Font properties
|
|
Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontChanged)
|
|
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontChanged)
|
|
Q_PROPERTY(QString fontStyle READ fontStyle WRITE setFontStyle NOTIFY fontChanged)
|
|
Q_PROPERTY(QStringList availableFamilies READ availableFamilies CONSTANT)
|
|
Q_PROPERTY(QStringList availableStyles READ availableStyles NOTIFY fontChanged)
|
|
|
|
// Close-to-tray
|
|
Q_PROPERTY(bool closeToTray READ closeToTray WRITE setCloseToTray NOTIFY closeToTrayChanged)
|
|
|
|
// Shortcut keys
|
|
Q_PROPERTY(QString approveBypassKey READ approveBypassKey WRITE setApproveBypassKey NOTIFY shortcutsChanged)
|
|
Q_PROPERTY(QString denyBypassKey READ denyBypassKey WRITE setDenyBypassKey NOTIFY shortcutsChanged)
|
|
|
|
public:
|
|
enum Mode {
|
|
System, // Follow KDE system color scheme
|
|
Light, // Force BreezeLight
|
|
Dark // Force BreezeDark
|
|
};
|
|
Q_ENUM(Mode)
|
|
|
|
explicit ThemeManager(QObject *parent = nullptr);
|
|
|
|
QString mode() const;
|
|
void setMode(const QString &mode);
|
|
QStringList availableSchemes() const;
|
|
bool isDark() const;
|
|
bool overriding() const;
|
|
|
|
// Color accessors (from stored palette)
|
|
QColor windowColor() const;
|
|
QColor windowTextColor() const;
|
|
QColor baseColor() const;
|
|
QColor alternateBaseColor() const;
|
|
QColor textColor() const;
|
|
QColor buttonColor() const;
|
|
QColor buttonTextColor() const;
|
|
QColor highlightColor() const;
|
|
QColor highlightedTextColor() const;
|
|
QColor tooltipBaseColor() const;
|
|
QColor tooltipTextColor() const;
|
|
QColor linkColor() const;
|
|
QColor midColor() const;
|
|
QColor darkColor() const;
|
|
QColor lightColor() const;
|
|
QColor dialogOutlineColor() const;
|
|
QColor shadowColor() const;
|
|
QColor placeholderTextColor() const;
|
|
|
|
// Font accessors
|
|
QString fontFamily() const;
|
|
void setFontFamily(const QString &family);
|
|
int fontSize() const;
|
|
void setFontSize(int size);
|
|
QString fontStyle() const;
|
|
void setFontStyle(const QString &style);
|
|
QStringList availableFamilies() const;
|
|
QStringList availableStyles() const;
|
|
|
|
// Close-to-tray
|
|
bool closeToTray() const;
|
|
void setCloseToTray(bool enabled);
|
|
|
|
// Shortcut keys
|
|
QString approveBypassKey() const;
|
|
void setApproveBypassKey(const QString &key);
|
|
QString denyBypassKey() const;
|
|
void setDenyBypassKey(const QString &key);
|
|
|
|
Q_INVOKABLE void resetFont();
|
|
Q_INVOKABLE QString chooseFolder(const QString &title, const QString &startDir = QString());
|
|
|
|
void applyPalette();
|
|
void applyFont();
|
|
|
|
signals:
|
|
void modeChanged();
|
|
void paletteChanged();
|
|
void fontChanged();
|
|
void closeToTrayChanged();
|
|
void shortcutsChanged();
|
|
|
|
private:
|
|
QPalette paletteFromScheme(const QString &path) const;
|
|
QColor parseColor(const QVariant &value) const;
|
|
QString systemSchemePath() const;
|
|
QString schemePath(const QString &name) const;
|
|
QStringList schemeDirs() const;
|
|
void loadSettings();
|
|
void saveSettings();
|
|
|
|
QString m_mode; // "system", "light", "dark"
|
|
QPalette m_palette;
|
|
QString m_fontFamily;
|
|
int m_fontSize;
|
|
QString m_fontStyle;
|
|
bool m_closeToTray;
|
|
QString m_approveBypassKey;
|
|
QString m_denyBypassKey;
|
|
QFileSystemWatcher *m_watcher;
|
|
KConfigWatcher::Ptr m_configWatcher;
|
|
static constexpr const char *SCHEMES_DIR = "/usr/share/color-schemes";
|
|
};
|
|
|
|
#endif // OLLIE_THEME_MANAGER_H
|