Kylin/Fluent/Theme.h

101 lines
3.5 KiB
C
Raw Normal View History

2024-08-21 23:26:43 +08:00
#ifndef THEME_H
#define THEME_H
2024-08-31 04:13:21 +08:00
#include "AccentColor.h"
#include "Utilities.h"
2024-08-21 23:26:43 +08:00
#include <QColor>
2024-08-31 04:13:21 +08:00
#include <QFileSystemWatcher>
#include <QMutex>
2024-08-21 23:26:43 +08:00
#include <QObject>
#include <QQmlEngine>
class Theme : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
2024-08-31 04:13:21 +08:00
Q_PROPERTY(bool dark READ dark NOTIFY darkChanged)
Q_PROPERTY_AUTO_P(AccentColor *, accentColor)
Q_PROPERTY_AUTO(int, darkMode)
Q_PROPERTY_AUTO(QColor, primaryColor)
Q_PROPERTY_AUTO(QColor, backgroundColor)
Q_PROPERTY_AUTO(QColor, dividerColor)
Q_PROPERTY_AUTO(QColor, itemPressColor)
Q_PROPERTY_AUTO(bool, nativeText)
Q_PROPERTY_AUTO(bool, animationEnabled)
2024-08-21 23:26:43 +08:00
Q_PROPERTY(QColor fontPrimaryColor READ fontPrimaryColor WRITE setFontPrimaryColor NOTIFY fontPrimaryColorChanged)
2024-08-31 04:13:21 +08:00
Q_PROPERTY_AUTO(QColor, fontSecondaryColor)
Q_PROPERTY_AUTO(QColor, fontTertiaryColor)
Q_PROPERTY_AUTO(QColor, frameColor)
Q_PROPERTY_AUTO(QColor, frameActiveColor)
Q_PROPERTY_AUTO(QColor, itemCheckColor)
2024-08-21 23:26:43 +08:00
Q_PROPERTY(QColor itemNormalColor READ itemNormalColor WRITE setItemNormalColor NOTIFY itemNormalColorChanged)
2024-08-23 00:04:16 +08:00
Q_PROPERTY(QColor itemHoverColor READ itemHoverColor WRITE setItemHoverColor NOTIFY itemHoverColorChanged)
Q_PROPERTY(QColor windowBackgroundColor READ windowBackgroundColor WRITE setWindowBackgroundColor NOTIFY
windowBackgroundColorChanged)
Q_PROPERTY(QColor windowActiveBackgroundColor READ windowActiveBackgroundColor WRITE setWindowActiveBackgroundColor
NOTIFY windowActiveBackgroundColorChanged)
Q_PROPERTY(QString desktopImagePath READ desktopImagePath WRITE setDesktopImagePath NOTIFY desktopImagePathChanged)
Q_PROPERTY(bool blurBehindWindowEnabled READ blurBehindWindowEnabled WRITE setBlurBehindWindowEnabled NOTIFY
blurBehindWindowEnabledChanged)
2024-08-21 23:26:43 +08:00
public:
2024-08-31 04:13:21 +08:00
static Theme *instance();
static Theme *create(QQmlEngine *, QJSEngine *);
bool dark() const;
2024-08-21 23:26:43 +08:00
QColor fontPrimaryColor() const;
void setFontPrimaryColor(const QColor &color);
QColor itemNormalColor() const;
void setItemNormalColor(const QColor &color);
2024-08-23 00:04:16 +08:00
QColor itemHoverColor() const;
void setItemHoverColor(const QColor &color);
QColor windowBackgroundColor() const;
void setWindowBackgroundColor(const QColor &color);
QColor windowActiveBackgroundColor() const;
void setWindowActiveBackgroundColor(const QColor &color);
QString desktopImagePath() const;
void setDesktopImagePath(const QString &path);
bool blurBehindWindowEnabled() const;
void setBlurBehindWindowEnabled(bool enabled);
2024-08-21 23:26:43 +08:00
signals:
2024-08-31 04:13:21 +08:00
void darkChanged();
2024-08-21 23:26:43 +08:00
void fontPrimaryColorChanged();
void itemNormalColorChanged();
2024-08-23 00:04:16 +08:00
void windowBackgroundColorChanged();
void windowActiveBackgroundColorChanged();
void desktopImagePathChanged();
void blurBehindWindowEnabledChanged();
void itemHoverColorChanged();
2024-08-21 23:26:43 +08:00
2024-08-31 04:13:21 +08:00
protected:
Theme(QObject *parent = nullptr);
void refreshColors();
void checkUpdateDesktopImage();
void timerEvent(QTimerEvent *event) final;
bool eventFilter(QObject *obj, QEvent *event) final;
2024-08-21 23:26:43 +08:00
private:
2024-08-31 04:13:21 +08:00
bool m_systemDark = false;
QMutex m_mutex;
QFileSystemWatcher m_watcher;
2024-08-21 23:26:43 +08:00
QColor m_fontPrimaryColor;
QColor m_itemNormalColor;
2024-08-23 00:04:16 +08:00
QColor m_itemHoverColor;
QColor m_windowBackgroundColor;
QColor m_windowActiveBackgroundColor;
QString m_desktopImagePath;
bool m_blurBehindWindowEnabled;
2024-08-21 23:26:43 +08:00
};
#endif // THEME_H