diff options
author | Petr Mrázek <peterix@gmail.com> | 2018-07-15 14:51:05 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2018-07-15 14:51:05 +0200 |
commit | bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9 (patch) | |
tree | e6497e304b7b9368367565fbc7c06efab1124b1c /application/themes | |
parent | 03280cc62e75f8073f8d3d9e9e3952acf21fa77d (diff) | |
download | PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.gz PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.bz2 PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.zip |
NOISSUE tabs -> spaces
Diffstat (limited to 'application/themes')
-rw-r--r-- | application/themes/BrightTheme.cpp | 44 | ||||
-rw-r--r-- | application/themes/BrightTheme.h | 18 | ||||
-rw-r--r-- | application/themes/CustomTheme.cpp | 368 | ||||
-rw-r--r-- | application/themes/CustomTheme.h | 38 | ||||
-rw-r--r-- | application/themes/DarkTheme.cpp | 44 | ||||
-rw-r--r-- | application/themes/DarkTheme.h | 18 | ||||
-rw-r--r-- | application/themes/FusionTheme.cpp | 2 | ||||
-rw-r--r-- | application/themes/FusionTheme.h | 4 | ||||
-rw-r--r-- | application/themes/ITheme.cpp | 68 | ||||
-rw-r--r-- | application/themes/ITheme.h | 32 | ||||
-rw-r--r-- | application/themes/SystemTheme.cpp | 62 | ||||
-rw-r--r-- | application/themes/SystemTheme.h | 28 |
12 files changed, 363 insertions, 363 deletions
diff --git a/application/themes/BrightTheme.cpp b/application/themes/BrightTheme.cpp index 2763c982..b9188bdd 100644 --- a/application/themes/BrightTheme.cpp +++ b/application/themes/BrightTheme.cpp @@ -2,55 +2,55 @@ QString BrightTheme::id() { - return "bright"; + return "bright"; } QString BrightTheme::name() { - return QObject::tr("Bright"); + return QObject::tr("Bright"); } bool BrightTheme::hasColorScheme() { - return true; + return true; } QPalette BrightTheme::colorScheme() { - QPalette brightPalette; - brightPalette.setColor(QPalette::Window, QColor(239,240,241)); - brightPalette.setColor(QPalette::WindowText, QColor(49,54,59)); - brightPalette.setColor(QPalette::Base, QColor(252,252,252)); - brightPalette.setColor(QPalette::AlternateBase, QColor(239,240,241)); - brightPalette.setColor(QPalette::ToolTipBase, QColor(49,54,59)); - brightPalette.setColor(QPalette::ToolTipText, QColor(239,240,241)); - brightPalette.setColor(QPalette::Text, QColor(49,54,59)); - brightPalette.setColor(QPalette::Button, QColor(239,240,241)); - brightPalette.setColor(QPalette::ButtonText, QColor(49,54,59)); - brightPalette.setColor(QPalette::BrightText, Qt::red); - brightPalette.setColor(QPalette::Link, QColor(41, 128, 185)); - brightPalette.setColor(QPalette::Highlight, QColor(61, 174, 233)); - brightPalette.setColor(QPalette::HighlightedText, QColor(239,240,241)); - return fadeInactive(brightPalette, fadeAmount(), fadeColor()); + QPalette brightPalette; + brightPalette.setColor(QPalette::Window, QColor(239,240,241)); + brightPalette.setColor(QPalette::WindowText, QColor(49,54,59)); + brightPalette.setColor(QPalette::Base, QColor(252,252,252)); + brightPalette.setColor(QPalette::AlternateBase, QColor(239,240,241)); + brightPalette.setColor(QPalette::ToolTipBase, QColor(49,54,59)); + brightPalette.setColor(QPalette::ToolTipText, QColor(239,240,241)); + brightPalette.setColor(QPalette::Text, QColor(49,54,59)); + brightPalette.setColor(QPalette::Button, QColor(239,240,241)); + brightPalette.setColor(QPalette::ButtonText, QColor(49,54,59)); + brightPalette.setColor(QPalette::BrightText, Qt::red); + brightPalette.setColor(QPalette::Link, QColor(41, 128, 185)); + brightPalette.setColor(QPalette::Highlight, QColor(61, 174, 233)); + brightPalette.setColor(QPalette::HighlightedText, QColor(239,240,241)); + return fadeInactive(brightPalette, fadeAmount(), fadeColor()); } double BrightTheme::fadeAmount() { - return 0.5; + return 0.5; } QColor BrightTheme::fadeColor() { - return QColor(239,240,241); + return QColor(239,240,241); } bool BrightTheme::hasStyleSheet() { - return false; + return false; } QString BrightTheme::appStyleSheet() { - return QString(); + return QString(); } diff --git a/application/themes/BrightTheme.h b/application/themes/BrightTheme.h index 31b31b2d..c61f52d5 100644 --- a/application/themes/BrightTheme.h +++ b/application/themes/BrightTheme.h @@ -5,15 +5,15 @@ class BrightTheme: public FusionTheme { public: - virtual ~BrightTheme() {} + virtual ~BrightTheme() {} - QString id() override; - QString name() override; - bool hasStyleSheet() override; - QString appStyleSheet() override; - bool hasColorScheme() override; - QPalette colorScheme() override; - double fadeAmount() override; - QColor fadeColor() override; + QString id() override; + QString name() override; + bool hasStyleSheet() override; + QString appStyleSheet() override; + bool hasColorScheme() override; + QPalette colorScheme() override; + double fadeAmount() override; + QColor fadeColor() override; }; diff --git a/application/themes/CustomTheme.cpp b/application/themes/CustomTheme.cpp index 28e8c5c0..3e3e27de 100644 --- a/application/themes/CustomTheme.cpp +++ b/application/themes/CustomTheme.cpp @@ -8,237 +8,237 @@ const char * styleFile = "themeStyle.css"; static bool readThemeJson(const QString &path, QPalette &palette, double &fadeAmount, QColor &fadeColor, QString &name, QString &widgets) { - QFileInfo pathInfo(path); - if(pathInfo.exists() && pathInfo.isFile()) - { - try - { - auto doc = Json::requireDocument(path, "Theme JSON file"); - const QJsonObject root = doc.object(); - name = Json::requireString(root, "name", "Theme name"); - widgets = Json::requireString(root, "widgets", "Qt widget theme"); - auto colorsRoot = Json::requireObject(root, "colors", "colors object"); - auto readColor = [&](QString colorName) -> QColor - { - auto colorValue = Json::ensureString(colorsRoot, colorName, QString()); - if(!colorValue.isEmpty()) - { - QColor color(colorValue); - if(!color.isValid()) - { - qWarning() << "Color value" << colorValue << "for" << colorName << "was not recognized."; - return QColor(); - } - return color; - } - return QColor(); - }; - auto readAndSetColor = [&](QPalette::ColorRole role, QString colorName) - { - auto color = readColor(colorName); - if(color.isValid()) - { - palette.setColor(role, color); - } - else - { - qDebug() << "Color value for" << colorName << "was not present."; - } - }; - - // palette - readAndSetColor(QPalette::Window, "Window"); - readAndSetColor(QPalette::WindowText, "WindowText"); - readAndSetColor(QPalette::Base, "Base"); - readAndSetColor(QPalette::AlternateBase, "AlternateBase"); - readAndSetColor(QPalette::ToolTipBase, "ToolTipBase"); - readAndSetColor(QPalette::ToolTipText, "ToolTipText"); - readAndSetColor(QPalette::Text, "Text"); - readAndSetColor(QPalette::Button, "Button"); - readAndSetColor(QPalette::ButtonText, "ButtonText"); - readAndSetColor(QPalette::BrightText, "BrightText"); - readAndSetColor(QPalette::Link, "Link"); - readAndSetColor(QPalette::Highlight, "Highlight"); - readAndSetColor(QPalette::HighlightedText, "HighlightedText"); - - //fade - fadeColor = readColor("fadeColor"); - fadeAmount = Json::ensureDouble(colorsRoot, "fadeAmount", 0.5, "fade amount"); - - } - catch (const Exception &e) - { - qWarning() << "Couldn't load theme json: " << e.cause(); - return false; - } - } - else - { - qDebug() << "No theme json present."; - return false; - } - return true; + QFileInfo pathInfo(path); + if(pathInfo.exists() && pathInfo.isFile()) + { + try + { + auto doc = Json::requireDocument(path, "Theme JSON file"); + const QJsonObject root = doc.object(); + name = Json::requireString(root, "name", "Theme name"); + widgets = Json::requireString(root, "widgets", "Qt widget theme"); + auto colorsRoot = Json::requireObject(root, "colors", "colors object"); + auto readColor = [&](QString colorName) -> QColor + { + auto colorValue = Json::ensureString(colorsRoot, colorName, QString()); + if(!colorValue.isEmpty()) + { + QColor color(colorValue); + if(!color.isValid()) + { + qWarning() << "Color value" << colorValue << "for" << colorName << "was not recognized."; + return QColor(); + } + return color; + } + return QColor(); + }; + auto readAndSetColor = [&](QPalette::ColorRole role, QString colorName) + { + auto color = readColor(colorName); + if(color.isValid()) + { + palette.setColor(role, color); + } + else + { + qDebug() << "Color value for" << colorName << "was not present."; + } + }; + + // palette + readAndSetColor(QPalette::Window, "Window"); + readAndSetColor(QPalette::WindowText, "WindowText"); + readAndSetColor(QPalette::Base, "Base"); + readAndSetColor(QPalette::AlternateBase, "AlternateBase"); + readAndSetColor(QPalette::ToolTipBase, "ToolTipBase"); + readAndSetColor(QPalette::ToolTipText, "ToolTipText"); + readAndSetColor(QPalette::Text, "Text"); + readAndSetColor(QPalette::Button, "Button"); + readAndSetColor(QPalette::ButtonText, "ButtonText"); + readAndSetColor(QPalette::BrightText, "BrightText"); + readAndSetColor(QPalette::Link, "Link"); + readAndSetColor(QPalette::Highlight, "Highlight"); + readAndSetColor(QPalette::HighlightedText, "HighlightedText"); + + //fade + fadeColor = readColor("fadeColor"); + fadeAmount = Json::ensureDouble(colorsRoot, "fadeAmount", 0.5, "fade amount"); + + } + catch (const Exception &e) + { + qWarning() << "Couldn't load theme json: " << e.cause(); + return false; + } + } + else + { + qDebug() << "No theme json present."; + return false; + } + return true; } static bool writeThemeJson(const QString &path, const QPalette &palette, double fadeAmount, QColor fadeColor, QString name, QString widgets) { - QJsonObject rootObj; - rootObj.insert("name", name); - rootObj.insert("widgets", widgets); - - QJsonObject colorsObj; - auto insertColor = [&](QPalette::ColorRole role, QString colorName) - { - colorsObj.insert(colorName, palette.color(role).name()); - }; - - // palette - insertColor(QPalette::Window, "Window"); - insertColor(QPalette::WindowText, "WindowText"); - insertColor(QPalette::Base, "Base"); - insertColor(QPalette::AlternateBase, "AlternateBase"); - insertColor(QPalette::ToolTipBase, "ToolTipBase"); - insertColor(QPalette::ToolTipText, "ToolTipText"); - insertColor(QPalette::Text, "Text"); - insertColor(QPalette::Button, "Button"); - insertColor(QPalette::ButtonText, "ButtonText"); - insertColor(QPalette::BrightText, "BrightText"); - insertColor(QPalette::Link, "Link"); - insertColor(QPalette::Highlight, "Highlight"); - insertColor(QPalette::HighlightedText, "HighlightedText"); - - // fade - colorsObj.insert("fadeColor", fadeColor.name()); - colorsObj.insert("fadeAmount", fadeAmount); - - rootObj.insert("colors", colorsObj); - try - { - Json::write(rootObj, path); - return true; - } - catch (const Exception &e) - { - qWarning() << "Failed to write theme json to" << path; - return false; - } + QJsonObject rootObj; + rootObj.insert("name", name); + rootObj.insert("widgets", widgets); + + QJsonObject colorsObj; + auto insertColor = [&](QPalette::ColorRole role, QString colorName) + { + colorsObj.insert(colorName, palette.color(role).name()); + }; + + // palette + insertColor(QPalette::Window, "Window"); + insertColor(QPalette::WindowText, "WindowText"); + insertColor(QPalette::Base, "Base"); + insertColor(QPalette::AlternateBase, "AlternateBase"); + insertColor(QPalette::ToolTipBase, "ToolTipBase"); + insertColor(QPalette::ToolTipText, "ToolTipText"); + insertColor(QPalette::Text, "Text"); + insertColor(QPalette::Button, "Button"); + insertColor(QPalette::ButtonText, "ButtonText"); + insertColor(QPalette::BrightText, "BrightText"); + insertColor(QPalette::Link, "Link"); + insertColor(QPalette::Highlight, "Highlight"); + insertColor(QPalette::HighlightedText, "HighlightedText"); + + // fade + colorsObj.insert("fadeColor", fadeColor.name()); + colorsObj.insert("fadeAmount", fadeAmount); + + rootObj.insert("colors", colorsObj); + try + { + Json::write(rootObj, path); + return true; + } + catch (const Exception &e) + { + qWarning() << "Failed to write theme json to" << path; + return false; + } } CustomTheme::CustomTheme(ITheme* baseTheme, QString folder) { - m_id = folder; - QString path = FS::PathCombine("themes", m_id); - QString pathResources = FS::PathCombine("themes", m_id, "resources"); - - qDebug() << "Loading theme" << m_id; - - if(!FS::ensureFolderPathExists(path) || !FS::ensureFolderPathExists(pathResources)) - { - qWarning() << "couldn't create folder for theme!"; - m_palette = baseTheme->colorScheme(); - m_styleSheet = baseTheme->appStyleSheet(); - return; - } - - auto themeFilePath = FS::PathCombine(path, themeFile); - - m_palette = baseTheme->colorScheme(); - if (!readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets)) - { - m_name = "Custom"; - m_palette = baseTheme->colorScheme(); - m_fadeColor = baseTheme->fadeColor(); - m_fadeAmount = baseTheme->fadeAmount(); - m_widgets = baseTheme->qtTheme(); - - QFileInfo info(themeFilePath); - if(!info.exists()) - { - writeThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, "Custom", m_widgets); - } - } - else - { - m_palette = fadeInactive(m_palette, m_fadeAmount, m_fadeColor); - } - - auto cssFilePath = FS::PathCombine(path, styleFile); - QFileInfo info (cssFilePath); - if(info.isFile()) - { - try - { - // TODO: validate css? - m_styleSheet = QString::fromUtf8(FS::read(cssFilePath)); - } - catch (const Exception &e) - { - qWarning() << "Couldn't load css:" << e.cause() << "from" << cssFilePath; - m_styleSheet = baseTheme->appStyleSheet(); - } - } - else - { - qDebug() << "No theme css present."; - m_styleSheet = baseTheme->appStyleSheet(); - try - { - FS::write(cssFilePath, m_styleSheet.toUtf8()); - } - catch (const Exception &e) - { - qWarning() << "Couldn't write css:" << e.cause() << "to" << cssFilePath; - } - } + m_id = folder; + QString path = FS::PathCombine("themes", m_id); + QString pathResources = FS::PathCombine("themes", m_id, "resources"); + + qDebug() << "Loading theme" << m_id; + + if(!FS::ensureFolderPathExists(path) || !FS::ensureFolderPathExists(pathResources)) + { + qWarning() << "couldn't create folder for theme!"; + m_palette = baseTheme->colorScheme(); + m_styleSheet = baseTheme->appStyleSheet(); + return; + } + + auto themeFilePath = FS::PathCombine(path, themeFile); + + m_palette = baseTheme->colorScheme(); + if (!readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets)) + { + m_name = "Custom"; + m_palette = baseTheme->colorScheme(); + m_fadeColor = baseTheme->fadeColor(); + m_fadeAmount = baseTheme->fadeAmount(); + m_widgets = baseTheme->qtTheme(); + + QFileInfo info(themeFilePath); + if(!info.exists()) + { + writeThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, "Custom", m_widgets); + } + } + else + { + m_palette = fadeInactive(m_palette, m_fadeAmount, m_fadeColor); + } + + auto cssFilePath = FS::PathCombine(path, styleFile); + QFileInfo info (cssFilePath); + if(info.isFile()) + { + try + { + // TODO: validate css? + m_styleSheet = QString::fromUtf8(FS::read(cssFilePath)); + } + catch (const Exception &e) + { + qWarning() << "Couldn't load css:" << e.cause() << "from" << cssFilePath; + m_styleSheet = baseTheme->appStyleSheet(); + } + } + else + { + qDebug() << "No theme css present."; + m_styleSheet = baseTheme->appStyleSheet(); + try + { + FS::write(cssFilePath, m_styleSheet.toUtf8()); + } + catch (const Exception &e) + { + qWarning() << "Couldn't write css:" << e.cause() << "to" << cssFilePath; + } + } } QStringList CustomTheme::searchPaths() { - return { FS::PathCombine("themes", m_id, "resources") }; + return { FS::PathCombine("themes", m_id, "resources") }; } QString CustomTheme::id() { - return m_id; + return m_id; } QString CustomTheme::name() { - return m_name; + return m_name; } bool CustomTheme::hasColorScheme() { - return true; + return true; } QPalette CustomTheme::colorScheme() { - return m_palette; + return m_palette; } bool CustomTheme::hasStyleSheet() { - return true; + return true; } QString CustomTheme::appStyleSheet() { - return m_styleSheet; + return m_styleSheet; } double CustomTheme::fadeAmount() { - return m_fadeAmount; + return m_fadeAmount; } QColor CustomTheme::fadeColor() { - return m_fadeColor; + return m_fadeColor; } QString CustomTheme::qtTheme() { - return m_widgets; + return m_widgets; } diff --git a/application/themes/CustomTheme.h b/application/themes/CustomTheme.h index 9023b13e..d216895d 100644 --- a/application/themes/CustomTheme.h +++ b/application/themes/CustomTheme.h @@ -5,27 +5,27 @@ class CustomTheme: public ITheme { public: - CustomTheme(ITheme * baseTheme, QString folder); - virtual ~CustomTheme() {} + CustomTheme(ITheme * baseTheme, QString folder); + virtual ~CustomTheme() {} - QString id() override; - QString name() override; - bool hasStyleSheet() override; - QString appStyleSheet() override; - bool hasColorScheme() override; - QPalette colorScheme() override; - double fadeAmount() override; - QColor fadeColor() override; - QString qtTheme() override; - QStringList searchPaths() override; + QString id() override; + QString name() override; + bool hasStyleSheet() override; + QString appStyleSheet() override; + bool hasColorScheme() override; + QPalette colorScheme() override; + double fadeAmount() override; + QColor fadeColor() override; + QString qtTheme() override; + QStringList searchPaths() override; private: /* data */ - QPalette m_palette; - QColor m_fadeColor; - double m_fadeAmount; - QString m_styleSheet; - QString m_name; - QString m_id; - QString m_widgets; + QPalette m_palette; + QColor m_fadeColor; + double m_fadeAmount; + QString m_styleSheet; + QString m_name; + QString m_id; + QString m_widgets; }; diff --git a/application/themes/DarkTheme.cpp b/application/themes/DarkTheme.cpp index cf4a81e1..31ecd559 100644 --- a/application/themes/DarkTheme.cpp +++ b/application/themes/DarkTheme.cpp @@ -2,54 +2,54 @@ QString DarkTheme::id() { - return "dark"; + return "dark"; } QString DarkTheme::name() { - return QObject::tr("Dark"); + return QObject::tr("Dark"); } bool DarkTheme::hasColorScheme() { - return true; + return true; } QPalette DarkTheme::colorScheme() { - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, QColor(49,54,59)); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, QColor(35,38,41)); - darkPalette.setColor(QPalette::AlternateBase, QColor(49,54,59)); - darkPalette.setColor(QPalette::ToolTipBase, Qt::white); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, QColor(49,54,59)); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::BrightText, Qt::red); - darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::HighlightedText, Qt::black); - return fadeInactive(darkPalette, fadeAmount(), fadeColor()); + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, QColor(49,54,59)); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, QColor(35,38,41)); + darkPalette.setColor(QPalette::AlternateBase, QColor(49,54,59)); + darkPalette.setColor(QPalette::ToolTipBase, Qt::white); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, QColor(49,54,59)); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::BrightText, Qt::red); + darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::HighlightedText, Qt::black); + return fadeInactive(darkPalette, fadeAmount(), fadeColor()); } double DarkTheme::fadeAmount() { - return 0.5; + return 0.5; } QColor DarkTheme::fadeColor() { - return QColor(49,54,59); + return QColor(49,54,59); } bool DarkTheme::hasStyleSheet() { - return true; + return true; } QString DarkTheme::appStyleSheet() { - return "QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"; + return "QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"; } diff --git a/application/themes/DarkTheme.h b/application/themes/DarkTheme.h index f3c18e22..9bd2f343 100644 --- a/application/themes/DarkTheme.h +++ b/application/themes/DarkTheme.h @@ -5,14 +5,14 @@ class DarkTheme: public FusionTheme { public: - virtual ~DarkTheme() {} + virtual ~DarkTheme() {} - QString id() override; - QString name() override; - bool hasStyleSheet() override; - QString appStyleSheet() override; - bool hasColorScheme() override; - QPalette colorScheme() override; - double fadeAmount() override; - QColor fadeColor() override; + QString id() override; + QString name() override; + bool hasStyleSheet() override; + QString appStyleSheet() override; + bool hasColorScheme() override; + QPalette colorScheme() override; + double fadeAmount() override; + QColor fadeColor() override; }; diff --git a/application/themes/FusionTheme.cpp b/application/themes/FusionTheme.cpp index aaf7b3d5..cf3286ba 100644 --- a/application/themes/FusionTheme.cpp +++ b/application/themes/FusionTheme.cpp @@ -2,5 +2,5 @@ QString FusionTheme::qtTheme() { - return "Fusion"; + return "Fusion"; } diff --git a/application/themes/FusionTheme.h b/application/themes/FusionTheme.h index e2d9014c..ee34245a 100644 --- a/application/themes/FusionTheme.h +++ b/application/themes/FusionTheme.h @@ -5,7 +5,7 @@ class FusionTheme: public ITheme { public: - virtual ~FusionTheme() {} + virtual ~FusionTheme() {} - QString qtTheme() override; + QString qtTheme() override; }; diff --git a/application/themes/ITheme.cpp b/application/themes/ITheme.cpp index b1cecf57..bfec87e7 100644 --- a/application/themes/ITheme.cpp +++ b/application/themes/ITheme.cpp @@ -6,42 +6,42 @@ void ITheme::apply(bool) { - QApplication::setStyle(QStyleFactory::create(qtTheme())); - if(hasColorScheme()) - { - QApplication::setPalette(colorScheme()); - } - if(hasStyleSheet()) - { - MMC->setStyleSheet(appStyleSheet()); - } - else - { - MMC->setStyleSheet(QString()); - } - QDir::setSearchPaths("theme", searchPaths()); + QApplication::setStyle(QStyleFactory::create(qtTheme())); + if(hasColorScheme()) + { + QApplication::setPalette(colorScheme()); + } + if(hasStyleSheet()) + { + MMC->setStyleSheet(appStyleSheet()); + } + else + { + MMC->setStyleSheet(QString()); + } + QDir::setSearchPaths("theme", searchPaths()); } QPalette ITheme::fadeInactive(QPalette in, qreal bias, QColor color) { - auto blend = [&in, bias, color](QPalette::ColorRole role) - { - QColor from = in.color(QPalette::Active, role); - QColor blended = Rainbow::mix(from, color, bias); - in.setColor(QPalette::Disabled, role, blended); - }; - blend(QPalette::Window); - blend(QPalette::WindowText); - blend(QPalette::Base); - blend(QPalette::AlternateBase); - blend(QPalette::ToolTipBase); - blend(QPalette::ToolTipText); - blend(QPalette::Text); - blend(QPalette::Button); - blend(QPalette::ButtonText); - blend(QPalette::BrightText); - blend(QPalette::Link); - blend(QPalette::Highlight); - blend(QPalette::HighlightedText); - return in; + auto blend = [&in, bias, color](QPalette::ColorRole role) + { + QColor from = in.color(QPalette::Active, role); + QColor blended = Rainbow::mix(from, color, bias); + in.setColor(QPalette::Disabled, role, blended); + }; + blend(QPalette::Window); + blend(QPalette::WindowText); + blend(QPalette::Base); + blend(QPalette::AlternateBase); + blend(QPalette::ToolTipBase); + blend(QPalette::ToolTipText); + blend(QPalette::Text); + blend(QPalette::Button); + blend(QPalette::ButtonText); + blend(QPalette::BrightText); + blend(QPalette::Link); + blend(QPalette::Highlight); + blend(QPalette::HighlightedText); + return in; } diff --git a/application/themes/ITheme.h b/application/themes/ITheme.h index b75001c2..c2347cf6 100644 --- a/application/themes/ITheme.h +++ b/application/themes/ITheme.h @@ -7,21 +7,21 @@ class QStyle; class ITheme { public: - virtual ~ITheme() {} - virtual void apply(bool initial); - virtual QString id() = 0; - virtual QString name() = 0; - virtual bool hasStyleSheet() = 0; - virtual QString appStyleSheet() = 0; - virtual QString qtTheme() = 0; - virtual bool hasColorScheme() = 0; - virtual QPalette colorScheme() = 0; - virtual QColor fadeColor() = 0; - virtual double fadeAmount() = 0; - virtual QStringList searchPaths() - { - return {}; - } + virtual ~ITheme() {} + virtual void apply(bool initial); + virtual QString id() = 0; + virtual QString name() = 0; + virtual bool hasStyleSheet() = 0; + virtual QString appStyleSheet() = 0; + virtual QString qtTheme() = 0; + virtual bool hasColorScheme() = 0; + virtual QPalette colorScheme() = 0; + virtual QColor fadeColor() = 0; + virtual double fadeAmount() = 0; + virtual QStringList searchPaths() + { + return {}; + } - static QPalette fadeInactive(QPalette in, qreal bias, QColor color); + static QPalette fadeInactive(QPalette in, qreal bias, QColor color); }; diff --git a/application/themes/SystemTheme.cpp b/application/themes/SystemTheme.cpp index a9ee853a..00b2300d 100644 --- a/application/themes/SystemTheme.cpp +++ b/application/themes/SystemTheme.cpp @@ -6,75 +6,75 @@ SystemTheme::SystemTheme() { - const auto & style = QApplication::style(); - systemPalette = style->standardPalette(); - QString lowerThemeName = style->objectName(); - qDebug() << systemTheme; - QStringList styles = QStyleFactory::keys(); - for(auto &st: styles) - { - if(st.toLower() == lowerThemeName) - { - systemTheme = st; - return; - } - } - // fall back to fusion if we can't find the current theme. - systemTheme = "Fusion"; - qDebug() << "System theme not found, defaulted to Fusion"; + const auto & style = QApplication::style(); + systemPalette = style->standardPalette(); + QString lowerThemeName = style->objectName(); + qDebug() << systemTheme; + QStringList styles = QStyleFactory::keys(); + for(auto &st: styles) + { + if(st.toLower() == lowerThemeName) + { + systemTheme = st; + return; + } + } + // fall back to fusion if we can't find the current theme. + systemTheme = "Fusion"; + qDebug() << "System theme not found, defaulted to Fusion"; } void SystemTheme::apply(bool initial) { - // if we are applying the system theme as the first theme, just don't touch anything. it's for the better... - if(initial) - { - return; - } - ITheme::apply(initial); + // if we are applying the system theme as the first theme, just don't touch anything. it's for the better... + if(initial) + { + return; + } + ITheme::apply(initial); } QString SystemTheme::id() { - return "system"; + return "system"; } QString SystemTheme::name() { - return QObject::tr("System"); + return QObject::tr("System"); } QString SystemTheme::qtTheme() { - return systemTheme; + return systemTheme; } QPalette SystemTheme::colorScheme() { - return systemPalette; + return systemPalette; } QString SystemTheme::appStyleSheet() { - return QString(); + return QString(); } double SystemTheme::fadeAmount() { - return 0.5; + return 0.5; } QColor SystemTheme::fadeColor() { - return QColor(128,128,128); + return QColor(128,128,128); } bool SystemTheme::hasStyleSheet() { - return false; + return false; } bool SystemTheme::hasColorScheme() { - return true; + return true; } diff --git a/application/themes/SystemTheme.h b/application/themes/SystemTheme.h index 18291b68..fe450600 100644 --- a/application/themes/SystemTheme.h +++ b/application/themes/SystemTheme.h @@ -5,20 +5,20 @@ class SystemTheme: public ITheme { public: - SystemTheme(); - virtual ~SystemTheme() {} - void apply(bool initial) override; + SystemTheme(); + virtual ~SystemTheme() {} + void apply(bool initial) override; - QString id() override; - QString name() override; - QString qtTheme() override; - bool hasStyleSheet() override; - QString appStyleSheet() override; - bool hasColorScheme() override; - QPalette colorScheme() override; - double fadeAmount() override; - QColor fadeColor() override; + QString id() override; + QString name() override; + QString qtTheme() override; + bool hasStyleSheet() override; + QString appStyleSheet() override; + bool hasColorScheme() override; + QPalette colorScheme() override; + double fadeAmount() override; + QColor fadeColor() override; private: - QPalette systemPalette; - QString systemTheme; + QPalette systemPalette; + QString systemTheme; }; |