8 #include <QApplication> 13 QStringList lines = style.split(
"\n");
15 std::map<QString, QString> palette;
19 while( i < lines.size() )
21 if( lines[i++].contains(
"PALETTE START") )
27 while( i < lines.size() )
29 auto parts = lines[i].split(
":");
30 if( parts.size() == 2 )
32 palette.insert( {parts[0].remove(
" "), parts[1].remove(
" ")} );
35 if( lines[i++].contains(
"PALETTE END") )
42 while( i < lines.size() )
44 QString line = lines[i];
46 int pos_start = line.indexOf(
"${", 0 );
49 int pos_end = line.indexOf(
"}",pos_start );
52 throw std::runtime_error(
"problem loading stylesheet. Unclosed ${}");
54 int mid_length = pos_end -( pos_start+2 );
55 QString
id = line.mid(pos_start+2, mid_length);
57 if (palette.count(
id) == 0)
59 std::string msg =
"Problem loading stylesheet: can't find palette id: ";
60 msg +=
id.toStdString();
61 throw std::runtime_error(msg);
63 QString color = palette[id];
64 line = line.left(pos_start) + color + line.right(line.size() - pos_end -1);
72 settings.setValue(
"StyleSheet::theme", palette[
"theme"]);
74 dynamic_cast<QApplication*
>(QCoreApplication::instance())->setStyleSheet(out);
76 return palette[
"theme"];
79 #endif // STYLESHEET_H QString SetApplicationStyleSheet(QString style)