123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #include "astyle.h"
- #include "src/opl.h"
- #include <QStyle>
- #include <QStyleFactory>
- #include <QApplication>
- #include <QFont>
- #include "src/classes/asettings.h"
- #include "src/functions/alog.h"
- const QString AStyle::defaultStyle = QLatin1String("Fusion");
- const QStringList AStyle::styles = QStyleFactory::keys();
- const QList<StyleSheet> AStyle::styleSheets = {
- {QLatin1String("Breeze"), QLatin1String(":breeze_light.qss")},
- {QLatin1String("Breeze-Dark"), QLatin1String(":breeze_dark.qss")},
- {QLatin1String("QDarkStyle"), QLatin1String(":qdarkstyle/qdarkstyle.qss")},
- };
- QString AStyle::currentStyle = defaultStyle;
- QLatin1String AStyle::DARK_PALETTE = QLatin1String("Dark-Palette");
- void AStyle::setup()
- {
- if (!ASettings::read(ASettings::Main::SetupComplete).toBool())
- return;
-
- if (!ASettings::read(ASettings::Main::UseSystemFont).toBool()) {
- QFont font(ASettings::read(ASettings::Main::Font).toString());
- font.setPointSize(ASettings::read(ASettings::Main::FontSize).toUInt());
- qApp->setFont(font);
- LOG << "Application Font set: " << font.toString().split(',').first();
- }
-
- QString style_setting = ASettings::read(ASettings::Main::Style).toString();
- if (style_setting == DARK_PALETTE) {
- AStyle::setStyle(AStyle::darkPalette());
- ASettings::write(ASettings::Main::Style, style_setting);
- return;
- }
- for (const auto &style_name : styles) {
- if (style_setting == style_name) {
- setStyle(style_name);
- currentStyle = style_name;
- return;
- }
- }
- for (const auto &style_sheet : styleSheets) {
- if (style_setting == style_sheet.styleSheetName) {
- setStyle(style_sheet);
- currentStyle = style_sheet.styleSheetName;
- return;
- }
- }
- }
- void AStyle::resetStyle()
- {
- qApp->setStyle(QStyleFactory::create(defaultStyle));
- qApp->setStyleSheet(QString());
- qApp->setPalette(qApp->style()->standardPalette());
- }
- void AStyle::setStyle(const QString &style_key)
- {
- resetStyle();
- LOG << "Setting style: " << style_key;
- QApplication::setStyle(QStyleFactory::create(style_key));
- currentStyle = style_key;
- }
- void AStyle::setStyle(const StyleSheet &style_sheet)
- {
- resetStyle();
- LOG << "Setting stylesheet: " << style_sheet.styleSheetName;
- qApp->setStyleSheet(read_stylesheet(style_sheet.fileName));
- currentStyle = style_sheet.styleSheetName;
- }
- void AStyle::setStyle(const QPalette &palette)
- {
- resetStyle();
- LOG << "Setting Colour Palette...";
- currentStyle = DARK_PALETTE;
- qApp->setPalette(palette);
- }
- StyleType AStyle::getStyleType()
- {
- const QStringList darkStyles = {
- QStringLiteral("Breeze-Dark"),
- QStringLiteral("QDarkStyle"),
- DARK_PALETTE,
- };
- if (darkStyles.contains(currentStyle))
- return StyleType::Dark;
- else
- return StyleType::Light;
- }
- QPalette AStyle::darkPalette()
- {
- auto palette = QPalette();
-
-
-
-
-
-
-
-
-
-
-
-
-
- palette.setColor(QPalette::Window, QColor(53, 53, 53));
- palette.setColor(QPalette::WindowText, Qt::white);
- palette.setColor(QPalette::Disabled, QPalette::WindowText,
- QColor(127, 127, 127));
- palette.setColor(QPalette::Base, QColor(42, 42, 42));
- palette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
- palette.setColor(QPalette::ToolTipBase, Qt::white);
- palette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
- palette.setColor(QPalette::Text, Qt::white);
- palette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
- palette.setColor(QPalette::Dark, QColor(35, 35, 35));
- palette.setColor(QPalette::Shadow, QColor(20, 20, 20));
- palette.setColor(QPalette::Button, QColor(53, 53, 53));
- palette.setColor(QPalette::ButtonText, Qt::white);
- palette.setColor(QPalette::Disabled, QPalette::ButtonText,
- QColor(127, 127, 127));
- palette.setColor(QPalette::BrightText, Qt::red);
- palette.setColor(QPalette::Link, QColor(42, 130, 218));
- palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
- palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
- palette.setColor(QPalette::HighlightedText, Qt::white);
- palette.setColor(QPalette::Disabled, QPalette::HighlightedText,
- QColor(127, 127, 127));
- return palette;
- }
- const QString& AStyle::style()
- {
- return currentStyle;
- }
|