Skip to content

Commit bb7a32d

Browse files
authored
Add Dark theme (#3216)
* Copy light(-hires).css -> dark(-hires).css (with no changes yet) * Add dark(-hires).css to makefile/qrc and show them in theme selector * Dark theme (css part) * Do not style unit selector in status bar via platform styles, use css instead * No coloring via forms (*.ui) * Implement and use helpers to style parts of rich text differently for light and dark themes * Remove dark-hires due to #3217 * Revert changes to light-hires.css to avoid merge conflicts with #3217
1 parent 05ac4db commit bb7a32d

21 files changed

+1759
-79
lines changed

src/Makefile.qt.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ RES_IMAGES = \
316316
qt/res/images/unchecked.png
317317

318318
RES_CSS = \
319+
qt/res/css/dark.css \
319320
qt/res/css/light.css \
320321
qt/res/css/light-hires.css \
321322
qt/res/css/scrollbars.css \

src/qt/bitcoinamountfield.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "bitcoinamountfield.h"
66

77
#include "bitcoinunits.h"
8-
#include "guiconstants.h"
8+
#include "guiutil.h"
99
#include "qvaluecombobox.h"
1010

1111
#include <QApplication>
@@ -245,7 +245,7 @@ void BitcoinAmountField::setValid(bool valid)
245245
if (valid)
246246
amount->setStyleSheet("");
247247
else
248-
amount->setStyleSheet(STYLE_INVALID);
248+
amount->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_INVALID));
249249
}
250250

251251
bool BitcoinAmountField::eventFilter(QObject *object, QEvent *event)

src/qt/bitcoingui.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,6 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *pl
15921592
}
15931593
setMinimumSize(max_width, 0);
15941594
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1595-
setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
15961595
}
15971596

15981597
/** So that it responds to button clicks */

src/qt/coincontroldialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
621621
}
622622

623623
// turn label red when dust
624-
l7->setStyleSheet((fDust) ? "color:red;" : "");
624+
l7->setStyleSheet((fDust) ? GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) : "");
625625

626626
// tool tips
627627
QString toolTipDust = tr("This label turns red if any recipient receives an amount smaller than the current dust threshold.");

src/qt/dash.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<file alias="network_disabled">res/icons/network_disabled.png</file>
5555
</qresource>
5656
<qresource prefix="/css">
57+
<file alias="dark">res/css/dark.css</file>
5758
<file alias="light">res/css/light.css</file>
5859
<file alias="light-hires">res/css/light-hires.css</file>
5960
<file alias="scrollbars">res/css/scrollbars.css</file>

src/qt/forms/overviewpage.ui

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
<property name="toolTip">
7373
<string>The displayed information may be out of date. Your wallet automatically synchronizes with the Dash network after a connection is established, but this process has not completed yet.</string>
7474
</property>
75-
<property name="styleSheet">
76-
<string notr="true">QLabel { color: red; }</string>
77-
</property>
7875
<property name="text">
7976
<string notr="true">(out of sync)</string>
8077
</property>
@@ -427,9 +424,6 @@
427424
<property name="toolTip">
428425
<string>The displayed information may be out of date. Your wallet automatically synchronizes with the Dash network after a connection is established, but this process has not completed yet.</string>
429426
</property>
430-
<property name="styleSheet">
431-
<string notr="true">QLabel { color: red; }</string>
432-
</property>
433427
<property name="text">
434428
<string notr="true">(out of sync)</string>
435429
</property>
@@ -630,9 +624,6 @@
630624
<property name="toolTip">
631625
<string>The displayed information may be out of date. Your wallet automatically synchronizes with the Dash network after a connection is established, but this process has not completed yet.</string>
632626
</property>
633-
<property name="styleSheet">
634-
<string notr="true">QLabel { color: red; }</string>
635-
</property>
636627
<property name="text">
637628
<string notr="true">(out of sync)</string>
638629
</property>

src/qt/forms/sendcoinsdialog.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
</font>
134134
</property>
135135
<property name="styleSheet">
136-
<string notr="true">color:red;font-weight:bold;</string>
136+
<string notr="true">font-weight:bold;</string>
137137
</property>
138138
<property name="text">
139139
<string>Insufficient funds!</string>

src/qt/guiconstants.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,6 @@ static const int STATUSBAR_ICONSIZE = 16;
1717

1818
static const bool DEFAULT_SPLASHSCREEN = true;
1919

20-
/* Invalid field background style */
21-
#define STYLE_INVALID "background:#FF8080"
22-
23-
/* Transaction list -- unconfirmed transaction */
24-
#define COLOR_UNCONFIRMED QColor(128, 128, 128)
25-
/* Transaction list -- negative amount */
26-
#define COLOR_NEGATIVE QColor(255, 0, 0)
27-
/* Transaction list -- bare address (without label) */
28-
#define COLOR_BAREADDRESS QColor(140, 140, 140)
29-
/* Transaction list -- TX status decoration - open until date */
30-
#define COLOR_TX_STATUS_OPENUNTILDATE QColor(64, 64, 255)
31-
/* Transaction list -- TX status decoration - offline */
32-
#define COLOR_TX_STATUS_OFFLINE QColor(192, 192, 192)
33-
/* Transaction list -- TX status decoration - danger, tx needs attention */
34-
#define COLOR_TX_STATUS_DANGER QColor(200, 100, 100)
35-
/* Transaction list -- TX status decoration - default color */
36-
#define COLOR_BLACK QColor(0, 0, 0)
37-
/* Transaction list -- TX status decoration - LockedByInstantSend color */
38-
#define COLOR_TX_STATUS_LOCKED QColor(0, 128, 255)
39-
4020
/* Tooltips longer than this (in characters) are converted into rich text,
4121
so that they can be word-wrapped.
4222
*/

src/qt/guiutil.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,58 @@ extern double NSAppKitVersionNumber;
7878

7979
namespace GUIUtil {
8080

81+
static const std::map<ThemedColor, QColor> themedColors = {
82+
{ ThemedColor::DEFAULT, QColor(0, 0, 0) },
83+
{ ThemedColor::UNCONFIRMED, QColor(128, 128, 128) },
84+
{ ThemedColor::NEGATIVE, QColor(255, 0, 0) },
85+
{ ThemedColor::BAREADDRESS, QColor(140, 140, 140) },
86+
{ ThemedColor::TX_STATUS_OPENUNTILDATE, QColor(64, 64, 255) },
87+
{ ThemedColor::TX_STATUS_OFFLINE, QColor(192, 192, 192) },
88+
{ ThemedColor::TX_STATUS_DANGER, QColor(200, 100, 100) },
89+
{ ThemedColor::TX_STATUS_LOCKED, QColor(0, 128, 255) },
90+
};
91+
92+
static const std::map<ThemedColor, QColor> themedDarkColors = {
93+
{ ThemedColor::DEFAULT, QColor(170, 170, 170) },
94+
{ ThemedColor::UNCONFIRMED, QColor(204, 204, 204) },
95+
{ ThemedColor::NEGATIVE, QColor(255, 69, 0) },
96+
{ ThemedColor::BAREADDRESS, QColor(140, 140, 140) },
97+
{ ThemedColor::TX_STATUS_OPENUNTILDATE, QColor(64, 64, 255) },
98+
{ ThemedColor::TX_STATUS_OFFLINE, QColor(192, 192, 192) },
99+
{ ThemedColor::TX_STATUS_DANGER, QColor(200, 100, 100) },
100+
{ ThemedColor::TX_STATUS_LOCKED, QColor(0, 128, 255) },
101+
};
102+
103+
static const std::map<ThemedStyle, QString> themedStyles = {
104+
{ ThemedStyle::TS_INVALID, "background:#FF8080;" },
105+
{ ThemedStyle::TS_ERROR, "color:red;" },
106+
{ ThemedStyle::TS_SUCCESS, "color:green;" },
107+
{ ThemedStyle::TS_COMMAND, "color:#006060;" },
108+
{ ThemedStyle::TS_PRIMARY, "color:black;" },
109+
{ ThemedStyle::TS_SECONDARY, "color:#808080;" },
110+
};
111+
112+
static const std::map<ThemedStyle, QString> themedDarkStyles = {
113+
{ ThemedStyle::TS_INVALID, "background:#ff4500;" },
114+
{ ThemedStyle::TS_ERROR, "color:#ff4500;" },
115+
{ ThemedStyle::TS_SUCCESS, "color:green;" },
116+
{ ThemedStyle::TS_COMMAND, "color:#0cc;" },
117+
{ ThemedStyle::TS_PRIMARY, "color:#ccc;" },
118+
{ ThemedStyle::TS_SECONDARY, "color:#aaa;" },
119+
};
120+
121+
QColor getThemedQColor(ThemedColor color)
122+
{
123+
QString theme = QSettings().value("theme", "").toString();
124+
return theme.startsWith("dark") ? themedDarkColors.at(color) : themedColors.at(color);
125+
}
126+
127+
QString getThemedStyleQString(ThemedStyle style)
128+
{
129+
QString theme = QSettings().value("theme", "").toString();
130+
return theme.startsWith("dark") ? themedDarkStyles.at(style) : themedStyles.at(style);
131+
}
132+
81133
QString dateTimeStr(const QDateTime &date)
82134
{
83135
return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm");

src/qt/guiutil.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,47 @@ QT_END_NAMESPACE
3333
*/
3434
namespace GUIUtil
3535
{
36+
/* Enumeration of possible "colors" */
37+
enum class ThemedColor {
38+
/* Transaction list -- TX status decoration - default color */
39+
DEFAULT,
40+
/* Transaction list -- unconfirmed transaction */
41+
UNCONFIRMED,
42+
/* Transaction list -- negative amount */
43+
NEGATIVE,
44+
/* Transaction list -- bare address (without label) */
45+
BAREADDRESS,
46+
/* Transaction list -- TX status decoration - open until date */
47+
TX_STATUS_OPENUNTILDATE,
48+
/* Transaction list -- TX status decoration - offline */
49+
TX_STATUS_OFFLINE,
50+
/* Transaction list -- TX status decoration - danger, tx needs attention */
51+
TX_STATUS_DANGER,
52+
/* Transaction list -- TX status decoration - LockedByInstantSend color */
53+
TX_STATUS_LOCKED,
54+
};
55+
56+
/* Enumeration of possible "styles" */
57+
enum class ThemedStyle {
58+
/* Invalid field background style */
59+
TS_INVALID,
60+
/* Failed operation text style */
61+
TS_ERROR,
62+
/* Failed operation text style */
63+
TS_SUCCESS,
64+
/* Comand text style */
65+
TS_COMMAND,
66+
/* General text styles */
67+
TS_PRIMARY,
68+
TS_SECONDARY,
69+
};
70+
71+
/** Helper to get colors for various themes which can't be applied via css for some reason */
72+
QColor getThemedQColor(ThemedColor color);
73+
74+
/** Helper to get css style strings which are injected into rich text through qt */
75+
QString getThemedStyleQString(ThemedStyle style);
76+
3677
// Create human-readable string from date
3778
QString dateTimeStr(const QDateTime &datetime);
3879
QString dateTimeStr(qint64 nTime);

0 commit comments

Comments
 (0)