| 13 | } |
| 14 | |
| 15 | void StyleHelper::SetStyle() |
| 16 | { |
| 17 | MainWindow *m_host = qobject_cast<MainWindow*>(m_objhost); |
| 18 | |
| 19 | QApplication::setStyle(AppConfig::instance().get<QString>(AppConfig::Theme)); |
| 20 | |
| 21 | QString color_palette = AppConfig::instance().get<QString>(AppConfig::ThemeColors); |
| 22 | auto palettes = ColorStyleProvider::TABLE(); |
| 23 | |
| 24 | if (color_palette == "custom") |
| 25 | { |
| 26 | QColor base = QColor(loadColor(0, 0), loadColor(0, 1), loadColor(0, 2)); |
| 27 | QColor background = QColor(loadColor(1, 0), loadColor(1, 1), loadColor(1, 2)); |
| 28 | QColor foreground = QColor(loadColor(2, 0), loadColor(2, 1), loadColor(2, 2)); |
| 29 | QColor selection = QColor(loadColor(3, 0), loadColor(3, 1), loadColor(3, 2)); |
| 30 | QColor disabled = QColor(loadColor(4, 0), loadColor(4, 1), loadColor(4, 2)); |
| 31 | QColor selectiontext = QColor(255 - loadColor(3, 0), 255 - loadColor(3, 1), 255 - loadColor(3, 2)); |
| 32 | ColorStyle cs = ColorStyle(AppConfig::instance().get<bool>(AppConfig::ThemeColorsCustomWhiteIcons), |
| 33 | base, background, foreground, selection, selectiontext, disabled); |
| 34 | |
| 35 | setPalette(cs); |
| 36 | loadIcons(AppConfig::instance().get<bool>(AppConfig::ThemeColorsCustomWhiteIcons)); |
| 37 | } |
| 38 | else if (palettes.contains(color_palette)) |
| 39 | { |
| 40 | ColorStyle currentColorStyle = palettes[color_palette]; |
| 41 | setPalette(currentColorStyle); |
| 42 | loadIcons(currentColorStyle.useWhiteIcons); |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | loadIcons(false); |
| 47 | #ifndef IS_FLATPAK |
| 48 | QApplication::setPalette(m_host->style()->standardPalette()); |
| 49 | #else |
| 50 | QApplication::setPalette(getDefaultLightPalette()); |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | QFile f(":/styles/default.qss"); |
| 55 | |
| 56 | if (!f.exists()) |
| 57 | { |
| 58 | printf("Unable to set stylesheet, file not found\n"); |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | f.open(QFile::ReadOnly | QFile::Text); |
| 63 | QTextStream ts(&f); |
| 64 | qApp->setStyleSheet(ts.readAll()); |
| 65 | } |
| 66 | |
| 67 | emit styleChanged(); |
| 68 | } |
| 69 | |
| 70 | void StyleHelper::setPalette(const ColorStyle &s) |
| 71 | { |
no test coverage detected