MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / readThemeJson

Function readThemeJson

launcher/ui/themes/CustomTheme.cpp:9–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7const char * styleFile = "themeStyle.css";
8
9static bool readThemeJson(const QString &path, QPalette &palette, double &fadeAmount, QColor &fadeColor, QString &name, QString &widgets)
10{
11 QFileInfo pathInfo(path);
12 if(pathInfo.exists() && pathInfo.isFile())
13 {
14 try
15 {
16 auto doc = Json::requireDocument(path, "Theme JSON file");
17 const QJsonObject root = doc.object();
18 name = Json::requireString(root, "name", "Theme name");
19 widgets = Json::requireString(root, "widgets", "Qt widget theme");
20 auto colorsRoot = Json::requireObject(root, "colors", "colors object");
21 auto readColor = [&](QString colorName) -> QColor
22 {
23 auto colorValue = Json::ensureString(colorsRoot, colorName, QString());
24 if(!colorValue.isEmpty())
25 {
26 QColor color(colorValue);
27 if(!color.isValid())
28 {
29 qWarning() << "Color value" << colorValue << "for" << colorName << "was not recognized.";
30 return QColor();
31 }
32 return color;
33 }
34 return QColor();
35 };
36 auto readAndSetColor = [&](QPalette::ColorRole role, QString colorName)
37 {
38 auto color = readColor(colorName);
39 if(color.isValid())
40 {
41 palette.setColor(role, color);
42 }
43 else
44 {
45 qDebug() << "Color value for" << colorName << "was not present.";
46 }
47 };
48
49 // palette
50 readAndSetColor(QPalette::Window, "Window");
51 readAndSetColor(QPalette::WindowText, "WindowText");
52 readAndSetColor(QPalette::Base, "Base");
53 readAndSetColor(QPalette::AlternateBase, "AlternateBase");
54 readAndSetColor(QPalette::ToolTipBase, "ToolTipBase");
55 readAndSetColor(QPalette::ToolTipText, "ToolTipText");
56 readAndSetColor(QPalette::Text, "Text");
57 readAndSetColor(QPalette::Button, "Button");
58 readAndSetColor(QPalette::ButtonText, "ButtonText");
59 readAndSetColor(QPalette::BrightText, "BrightText");
60 readAndSetColor(QPalette::Link, "Link");
61 readAndSetColor(QPalette::Highlight, "Highlight");
62 readAndSetColor(QPalette::HighlightedText, "HighlightedText");
63
64 //fade
65 fadeColor = readColor("fadeColor");
66 fadeAmount = Json::ensureDouble(colorsRoot, "fadeAmount", 0.5, "fade amount");

Callers 1

CustomThemeMethod · 0.85

Calls 9

requireDocumentFunction · 0.85
requireObjectFunction · 0.85
QStringClass · 0.85
QColorClass · 0.85
existsMethod · 0.80
objectMethod · 0.80
isEmptyMethod · 0.80
causeMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected