Skip to content

Commit 936d38d

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 7f18421 commit 936d38d

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

src/qt/guiutil.cpp

Lines changed: 34 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>
@@ -1057,7 +1058,39 @@ void loadStyleSheet(QWidget* widget, bool fForceUpdate)
10571058
{
10581059
QFile qFile(QString(stylesheetDirectory + "/" + "%1%2").arg(name).arg(isStyleSheetDirectoryCustom() ? ".css" : ""));
10591060
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);
10611094
}
10621095
};
10631096

src/qt/res/css/dark.css

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

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

src/qt/res/css/general.css

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

src/qt/res/css/light.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,3 +770,39 @@ TransactionView
770770
******************************************************/
771771

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

0 commit comments

Comments
 (0)