|
8 | 8 |
|
9 | 9 | #include <qt/appearancewidget.h> |
10 | 10 | #include <qt/bitcoinaddressvalidator.h> |
| 11 | +#include <qt/bitcoingui.h> |
11 | 12 | #include <qt/bitcoinunits.h> |
12 | 13 | #include <qt/optionsdialog.h> |
13 | 14 | #include <qt/qvalidatedlineedit.h> |
@@ -1104,14 +1105,49 @@ void loadStyleSheet(QWidget* widget, bool fForceUpdate) |
1104 | 1105 | return false; |
1105 | 1106 | } |
1106 | 1107 |
|
| 1108 | + std::string platformName = gArgs.GetArg("-uiplatform", BitcoinGUI::DEFAULT_UIPLATFORM); |
1107 | 1109 | stylesheet = std::make_unique<QString>(); |
1108 | 1110 |
|
1109 | 1111 | for (const auto& file : vecFiles) { |
1110 | 1112 | QFile qFile(file); |
1111 | 1113 | if (!qFile.open(QFile::ReadOnly)) { |
1112 | 1114 | throw std::runtime_error(strprintf("%s: Failed to open file: %s", __func__, file.toStdString())); |
1113 | 1115 | } |
1114 | | - stylesheet->append(QLatin1String(qFile.readAll())); |
| 1116 | + |
| 1117 | + QString strStyle = QLatin1String(qFile.readAll()); |
| 1118 | + // Process all <os=...></os> groups in the stylesheet first |
| 1119 | + QRegularExpressionMatch osStyleMatch; |
| 1120 | + QRegularExpression osStyleExp( |
| 1121 | + "^" |
| 1122 | + "(<os=(?:'|\").+(?:'|\")>)" // group 1 |
| 1123 | + "((?:.|\n)+?)" // group 2 |
| 1124 | + "(</os>?)" // group 3 |
| 1125 | + "$"); |
| 1126 | + osStyleExp.setPatternOptions(QRegularExpression::MultilineOption); |
| 1127 | + QRegularExpressionMatchIterator it = osStyleExp.globalMatch(strStyle); |
| 1128 | + |
| 1129 | + // For all <os=...></os> sections |
| 1130 | + while (it.hasNext() && (osStyleMatch = it.next()).isValid()) { |
| 1131 | + QStringList listMatches = osStyleMatch.capturedTexts(); |
| 1132 | + |
| 1133 | + // Full match + 3 group matches |
| 1134 | + if (listMatches.size() % 4) { |
| 1135 | + throw std::runtime_error(strprintf("%s: Invalid <os=...></os> section in file %s", __func__, file.toStdString())); |
| 1136 | + } |
| 1137 | + |
| 1138 | + for (int i = 0; i < listMatches.size(); i += 4) { |
| 1139 | + if (!listMatches[i + 1].contains(QString::fromStdString(platformName))) { |
| 1140 | + // If os is not supported for this styles |
| 1141 | + // just remove the full match |
| 1142 | + strStyle.replace(listMatches[i], ""); |
| 1143 | + } else { |
| 1144 | + // If its supported remove the <os=...></os> tags |
| 1145 | + strStyle.replace(listMatches[i + 1], ""); |
| 1146 | + strStyle.replace(listMatches[i + 3], ""); |
| 1147 | + } |
| 1148 | + } |
| 1149 | + } |
| 1150 | + stylesheet->append(strStyle); |
1115 | 1151 | } |
1116 | 1152 | return true; |
1117 | 1153 | }; |
|
0 commit comments