14 #include <QApplication>
17 #include "QSyntaxStyle"
22 QStringList lines = style.split(
"\n");
24 std::map<QString, QString> palette;
28 while (i < lines.size())
30 if (lines[i++].contains(
"PALETTE START"))
36 while (i < lines.size())
38 auto parts = lines[i].split(
":");
39 if (parts.size() == 2)
41 QString value = parts[1].remove(
" ");
43 palette.insert({ parts[0].remove(
" "), value });
46 if (lines[i++].contains(
"PALETTE END"))
52 while (i < lines.size())
54 QString line = lines[i];
56 int pos_start = line.indexOf(
"${", 0);
59 int pos_end = line.indexOf(
"}", pos_start);
62 throw std::runtime_error(
"problem loading stylesheet. Unclosed ${}");
64 int mid_length = pos_end - (pos_start + 2);
65 QString
id = line.mid(pos_start + 2, mid_length);
67 if (palette.count(
id) == 0)
69 std::string
msg =
"Problem loading stylesheet: can't find palette id: ";
70 msg +=
id.toStdString();
71 throw std::runtime_error(
msg);
73 QString
color = palette[id];
74 line = line.left(pos_start) +
color + line.right(line.size() - pos_end - 1);
82 settings.setValue(
"StyleSheet::theme", palette[
"theme"]);
84 dynamic_cast<QApplication*
>(QCoreApplication::instance())->setStyleSheet(out);
86 return palette[
"theme"];
94 if (fl.open(QIODevice::ReadOnly))
97 if (!style->
load(fl.readAll()))
105 static QSyntaxStyle* style[2] = { loadStyle(
":/resources/lua_style_light.xml"),
106 loadStyle(
":/resources/lua_style_dark.xml") };
108 return theme ==
"light" ? style[0] : style[1];
111 #endif // STYLESHEET_H