|
6 | 6 | #include <qt/guiutil.h> |
7 | 7 |
|
8 | 8 | #include <qt/bitcoinaddressvalidator.h> |
| 9 | +#include <qt/bitcoingui.h> |
9 | 10 | #include <qt/bitcoinunits.h> |
10 | 11 | #include <qt/qvalidatedlineedit.h> |
11 | 12 | #include <qt/walletmodel.h> |
@@ -1057,7 +1058,39 @@ void loadStyleSheet(QWidget* widget, bool fForceUpdate) |
1057 | 1058 | { |
1058 | 1059 | QFile qFile(QString(stylesheetDirectory + "/" + "%1%2").arg(name).arg(isStyleSheetDirectoryCustom() ? ".css" : "")); |
1059 | 1060 | if (qFile.open(QFile::ReadOnly)) { |
1060 | | - stylesheet->append(QLatin1String(qFile.readAll())); |
| 1061 | + QString strStyle = QLatin1String(qFile.readAll()); |
| 1062 | + |
| 1063 | + // RegEx to match all <os=...></os> groups in the stylesheet |
| 1064 | + QRegularExpressionMatch osStyleMatch; |
| 1065 | + QRegularExpression osStyleExp("^(<os=(?:'|\").+(?:'|\")>)((?:.|\n)+?)(</os>?)$"); |
| 1066 | + osStyleExp.setPatternOptions(QRegularExpression::MultilineOption); |
| 1067 | + QRegularExpressionMatchIterator it = osStyleExp.globalMatch(strStyle); |
| 1068 | + |
| 1069 | + // For all <os=...></os> sections |
| 1070 | + while (it.hasNext() && (osStyleMatch = it.next()).isValid()) { |
| 1071 | + |
| 1072 | + QStringList listMatches = osStyleMatch.capturedTexts(); |
| 1073 | + |
| 1074 | + // Full match + 3 group matches |
| 1075 | + if (listMatches.size() % 4) { |
| 1076 | + qDebug() << "Invalid OS specific stylesheet section."; |
| 1077 | + return; |
| 1078 | + } |
| 1079 | + |
| 1080 | + for (int i = 0; i < listMatches.size(); i+=4) { |
| 1081 | + if (!listMatches[i+1].contains(QString::fromStdString(BitcoinGUI::DEFAULT_UIPLATFORM))) { |
| 1082 | + // If os is not supported for this styles |
| 1083 | + // just remove the full match |
| 1084 | + strStyle.replace(listMatches[i], ""); |
| 1085 | + } else { |
| 1086 | + // If its supported remove the <os=...></os> tags |
| 1087 | + strStyle.replace(listMatches[i+1], ""); |
| 1088 | + strStyle.replace(listMatches[i+3], ""); |
| 1089 | + } |
| 1090 | + } |
| 1091 | + } |
| 1092 | + |
| 1093 | + stylesheet->append(strStyle); |
1061 | 1094 | } |
1062 | 1095 | }; |
1063 | 1096 |
|
|
0 commit comments