Skip to content

Commit 88f4d0b

Browse files
committed
qt: Add platform specific css loading to GUIUtil::loadStyleSheet
This commit leads to GUIUtil::loadStyleSheet treating css code between <os="<os_list>"> and </os> different. It will only become added for operating systems provided in the list of the sections start tag. There may be multiple entries per section. Possible entries: - macosx - windows - other <os_list> must be a combination of the three options above separated by comma like in "windows,macosx". Its ok to have multiple <os="...">...</os> sections in a file with arbitrary OS combinations. They will all become added to the end of the file though. Means even putting an <os> section in the top of the file would become appended to the end of the file during loading which should be kept in mind when adding sections to avoid unexpected overwriting. Example ------------------------------------------------------------------------ <os="macosx, windows, other"> /* Example section to add styles for all operating systems Remove any to exclude it. */ </os>
1 parent 1d94d91 commit 88f4d0b

File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed

src/qt/guiutil.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <qt/guiutil.h>
77

88
#include <qt/bitcoinaddressvalidator.h>
9+
#include <qt/bitcoingui.h>
910
#include <qt/bitcoinunits.h>
1011
#include <qt/qvalidatedlineedit.h>
1112
#include <qt/walletmodel.h>
@@ -1064,7 +1065,36 @@ void loadStyleSheet(QWidget* widget, bool fDebugWidget)
10641065
if (!qFile.open(QFile::ReadOnly)) {
10651066
throw std::runtime_error(strprintf("%s: Failed to open file: %s", __func__, file.toStdString()));
10661067
}
1067-
stylesheet->append(QLatin1String(qFile.readAll()));
1068+
1069+
QString strStyle = QLatin1String(qFile.readAll());
1070+
// Process all <os=...></os> groups in the stylesheet first
1071+
QRegularExpressionMatch osStyleMatch;
1072+
QRegularExpression osStyleExp("^(<os=(?:'|\").+(?:'|\")>)((?:.|\n)+?)(</os>?)$");
1073+
osStyleExp.setPatternOptions(QRegularExpression::MultilineOption);
1074+
QRegularExpressionMatchIterator it = osStyleExp.globalMatch(strStyle);
1075+
1076+
// For all <os=...></os> sections
1077+
while (it.hasNext() && (osStyleMatch = it.next()).isValid()) {
1078+
QStringList listMatches = osStyleMatch.capturedTexts();
1079+
1080+
// Full match + 3 group matches
1081+
if (listMatches.size() % 4) {
1082+
throw std::runtime_error(strprintf("%s: Invalid <os=...></os> section in file %s", __func__, file.toStdString()));
1083+
}
1084+
1085+
for (int i = 0; i < listMatches.size(); i += 4) {
1086+
if (!listMatches[i + 1].contains(QString::fromStdString(BitcoinGUI::DEFAULT_UIPLATFORM))) {
1087+
// If os is not supported for this styles
1088+
// just remove the full match
1089+
strStyle.replace(listMatches[i], "");
1090+
} else {
1091+
// If its supported remove the <os=...></os> tags
1092+
strStyle.replace(listMatches[i + 1], "");
1093+
strStyle.replace(listMatches[i + 3], "");
1094+
}
1095+
}
1096+
}
1097+
stylesheet->append(strStyle);
10681098
}
10691099
return true;
10701100
};

src/qt/res/css/dark.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,38 @@ TransactionView
784784
******************************************************/
785785

786786
/***** No dark.css specific coloring here yet *****/
787+
788+
789+
/******************************************************
790+
*******************************************************
791+
STYLING OF OS SPECIFIC UI PARTS
792+
793+
NOTE: GUIUtil::loadStyleSheet treats css code between <os="<os_list>"> and </os>
794+
different. It will only become added for operating systems provided in the list
795+
of the sections start tag.
796+
797+
There may be multiple entries per section. Possible entries:
798+
799+
- macosx
800+
- windows
801+
- other
802+
803+
<os_list> must be a combination of the three options above separated by
804+
comma like in "windows,macosx".
805+
806+
Its ok to have multiple <os="...">...</os> sections in a file with
807+
arbitrary OS combinations. They will all become added to the end of the
808+
file though. Means even putting an <os> section in the top of the file
809+
would become appended to the end of the file during loading which should
810+
be kept in mind when adding sections to avoid unexpected overwriting.
811+
*******************************************************
812+
******************************************************/
813+
814+
<os="macosx, windows, other">
815+
816+
/* Example section to add styles for all operating systems
817+
Remove any to exclude it.
818+
*/
819+
820+
</os>
821+

src/qt/res/css/general.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,3 +1849,39 @@ TransactionView QComboBox {
18491849
min-height: 30px;
18501850
margin-top: 15px;
18511851
}
1852+
1853+
1854+
/******************************************************
1855+
*******************************************************
1856+
STYLING OF OS SPECIFIC UI PARTS
1857+
1858+
NOTE: GUIUtil::loadStyleSheet treats css code between <os="<os_list>"> and </os>
1859+
different. It will only become added for operating systems provided in the list
1860+
of the sections start tag.
1861+
1862+
There may be multiple entries per section. Possible entries:
1863+
1864+
- macosx
1865+
- windows
1866+
- other
1867+
1868+
<os_list> must be a combination of the three options above separated by
1869+
comma like in "windows,macosx".
1870+
1871+
Its ok to have multiple <os="...">...</os> sections in a file with
1872+
arbitrary OS combinations. They will all become added to the end of the
1873+
file though. Means even putting an <os> section in the top of the file
1874+
would become appended to the end of the file during loading which should
1875+
be kept in mind when adding sections to avoid unexpected overwriting.
1876+
*******************************************************
1877+
******************************************************/
1878+
1879+
1880+
<os="macosx, windows, other">
1881+
1882+
/* Example section to add styles for all operating systems
1883+
Remove any to exclude it.
1884+
*/
1885+
1886+
</os>
1887+

src/qt/res/css/light.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,3 +766,39 @@ TransactionView
766766
******************************************************/
767767

768768
/***** No light.css specific coloring here yet *****/
769+
770+
771+
/******************************************************
772+
*******************************************************
773+
STYLING OF OS SPECIFIC UI PARTS
774+
775+
NOTE: GUIUtil::loadStyleSheet treats css code between <os="<os_list>"> and </os>
776+
different. It will only become added for operating systems provided in the list
777+
of the sections start tag.
778+
779+
There may be multiple entries per section. Possible entries:
780+
781+
- macosx
782+
- windows
783+
- other
784+
785+
<os_list> must be a combination of the three options above separated by
786+
comma like in "windows,macosx".
787+
788+
Its ok to have multiple <os="...">...</os> sections in a file with
789+
arbitrary OS combinations. They will all become added to the end of the
790+
file though. Means even putting an <os> section in the top of the file
791+
would become appended to the end of the file during loading which should
792+
be kept in mind when adding sections to avoid unexpected overwriting.
793+
*******************************************************
794+
******************************************************/
795+
796+
797+
<os="macosx, windows, other">
798+
799+
/* Example section to add styles for all operating systems
800+
Remove any to exclude it.
801+
*/
802+
803+
</os>
804+

0 commit comments

Comments
 (0)