Add the ability to select custom themes in the settings dialog (#4570)
Themes are loaded from the Themes directory (under the Chatterino directory, so %APPDATA%/Chatterino2/Themes). Themes are json files (see the built in themes as an example). After importing a theme, you must restart Chatterino for it to show up in the settings
This commit is contained in:
@@ -6,16 +6,40 @@
|
||||
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
#include <QColor>
|
||||
#include <QJsonObject>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class WindowManager;
|
||||
|
||||
struct ThemeDescriptor {
|
||||
QString key;
|
||||
|
||||
// Path to the theme on disk
|
||||
// Can be a Qt resource path
|
||||
QString path;
|
||||
|
||||
// Name of the theme
|
||||
QString name;
|
||||
|
||||
bool custom{};
|
||||
};
|
||||
|
||||
class Theme final : public Singleton
|
||||
{
|
||||
public:
|
||||
Theme();
|
||||
static const std::vector<ThemeDescriptor> builtInThemes;
|
||||
|
||||
// The built in theme that will be used if some theme parsing fails
|
||||
static const ThemeDescriptor fallbackTheme;
|
||||
|
||||
void initialize(Settings &settings, Paths &paths) final;
|
||||
|
||||
bool isLightTheme() const;
|
||||
|
||||
@@ -114,6 +138,11 @@ public:
|
||||
void normalizeColor(QColor &color) const;
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Return a list of available themes
|
||||
**/
|
||||
std::vector<std::pair<QString, QVariant>> availableThemes() const;
|
||||
|
||||
pajlada::Signals::NoArgSignal updated;
|
||||
|
||||
QStringSetting themeName{"/appearance/theme/name", "Dark"};
|
||||
@@ -121,7 +150,17 @@ public:
|
||||
private:
|
||||
bool isLight_ = false;
|
||||
|
||||
void parse();
|
||||
std::vector<ThemeDescriptor> availableThemes_;
|
||||
|
||||
/**
|
||||
* Figure out which themes are available in the Themes directory
|
||||
*
|
||||
* NOTE: This is currently not built to be reloadable
|
||||
**/
|
||||
void loadAvailableThemes();
|
||||
|
||||
std::optional<ThemeDescriptor> findThemeByKey(const QString &key);
|
||||
|
||||
void parseFrom(const QJsonObject &root);
|
||||
|
||||
pajlada::Signals::NoArgSignal repaintVisibleChatWidgets_;
|
||||
|
||||
Reference in New Issue
Block a user