| 81 | } |
| 82 | |
| 83 | static bool writeThemeJson(const QString &path, const QPalette &palette, double fadeAmount, QColor fadeColor, QString name, QString widgets) |
| 84 | { |
| 85 | QJsonObject rootObj; |
| 86 | rootObj.insert("name", name); |
| 87 | rootObj.insert("widgets", widgets); |
| 88 | |
| 89 | QJsonObject colorsObj; |
| 90 | auto insertColor = [&](QPalette::ColorRole role, QString colorName) |
| 91 | { |
| 92 | colorsObj.insert(colorName, palette.color(role).name()); |
| 93 | }; |
| 94 | |
| 95 | // palette |
| 96 | insertColor(QPalette::Window, "Window"); |
| 97 | insertColor(QPalette::WindowText, "WindowText"); |
| 98 | insertColor(QPalette::Base, "Base"); |
| 99 | insertColor(QPalette::AlternateBase, "AlternateBase"); |
| 100 | insertColor(QPalette::ToolTipBase, "ToolTipBase"); |
| 101 | insertColor(QPalette::ToolTipText, "ToolTipText"); |
| 102 | insertColor(QPalette::Text, "Text"); |
| 103 | insertColor(QPalette::Button, "Button"); |
| 104 | insertColor(QPalette::ButtonText, "ButtonText"); |
| 105 | insertColor(QPalette::BrightText, "BrightText"); |
| 106 | insertColor(QPalette::Link, "Link"); |
| 107 | insertColor(QPalette::Highlight, "Highlight"); |
| 108 | insertColor(QPalette::HighlightedText, "HighlightedText"); |
| 109 | |
| 110 | // fade |
| 111 | colorsObj.insert("fadeColor", fadeColor.name()); |
| 112 | colorsObj.insert("fadeAmount", fadeAmount); |
| 113 | |
| 114 | rootObj.insert("colors", colorsObj); |
| 115 | try |
| 116 | { |
| 117 | Json::write(rootObj, path); |
| 118 | return true; |
| 119 | } |
| 120 | catch (const Exception &e) |
| 121 | { |
| 122 | qWarning() << "Failed to write theme json to" << path; |
| 123 | return false; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | CustomTheme::CustomTheme(ITheme* baseTheme, QString folder) |
| 128 | { |
no test coverage detected