Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when slotFinish happens.
splash->show();
PlatformStyle::applyTheme(PlatformStyle::isDarkModeEnabled());
connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
connect(this, SIGNAL(requestedShutdown()), splash, SLOT(close()));
}
Expand Down Expand Up @@ -549,6 +550,7 @@ MAIN_FUNCTION
QApplication::setOrganizationName(QAPP_ORG_NAME);
QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
PlatformStyle::applyTheme(PlatformStyle::isDarkModeEnabled());
GUIUtil::SubstituteFonts(GetLangTerritory());

/// 4. Initialization of translations, so that intro dialog is in user's language
Expand Down
65 changes: 65 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <iostream>

#include <QAction>
#include <QActionGroup>
#include <QApplication>
#include <QDateTime>
#include <QDesktopWidget>
Expand All @@ -57,6 +58,7 @@
#include <QStyle>
#include <QTimer>
#include <QToolBar>
#include <QToolButton>
#include <QVBoxLayout>

#include <QUrlQuery>
Expand All @@ -83,6 +85,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
clientModel(0),
walletFrame(0),
unitDisplayControl(0),
themeToggleButton(0),
themeTintMenu(0),
labelWalletEncryptionIcon(0),
labelWalletHDStatusIcon(0),
connectionsControl(0),
Expand Down Expand Up @@ -212,6 +216,24 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
themeToggleButton = new QToolButton(frameBlocks);
themeToggleButton->setAutoRaise(true);
themeToggleButton->setCursor(Qt::PointingHandCursor);
themeToggleButton->setContextMenuPolicy(Qt::CustomContextMenu);
themeTintMenu = new QMenu(themeToggleButton);
QActionGroup* tintGroup = new QActionGroup(themeTintMenu);
tintGroup->setExclusive(true);
for (int tint = 0; tint < PlatformStyle::darkModeTintCount(); ++tint) {
QAction* tintAction = new QAction(PlatformStyle::darkModeTintName(tint), themeTintMenu);
tintAction->setData(tint);
tintAction->setCheckable(true);
tintGroup->addAction(tintAction);
themeTintMenu->addAction(tintAction);
}
updateDarkModeToggleText();
connect(themeToggleButton, SIGNAL(clicked()), this, SLOT(toggleDarkMode()));
connect(themeToggleButton, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDarkTintMenu(QPoint)));
connect(themeTintMenu, SIGNAL(triggered(QAction*)), this, SLOT(onDarkTintSelected(QAction*)));
labelWalletEncryptionIcon = new QLabel();
labelWalletHDStatusIcon = new QLabel();
connectionsControl = new GUIUtil::ClickableLabel();
Expand All @@ -220,6 +242,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
{
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(unitDisplayControl);
frameBlocksLayout->addWidget(themeToggleButton);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
Expand Down Expand Up @@ -269,6 +292,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
}
#endif
PlatformStyle::applyTheme(PlatformStyle::isDarkModeEnabled());
}

BitcoinGUI::~BitcoinGUI()
Expand Down Expand Up @@ -1230,6 +1254,47 @@ void BitcoinGUI::toggleNetworkActive()
}
}

void BitcoinGUI::toggleDarkMode()
{
PlatformStyle::setDarkModeEnabled(!PlatformStyle::isDarkModeEnabled());
updateDarkModeToggleText();
}

void BitcoinGUI::updateDarkModeToggleText()
{
if (!themeToggleButton) {
return;
}
const bool darkModeEnabled = PlatformStyle::isDarkModeEnabled();
const QChar sunGlyph(0x2600);
const QChar moonGlyph(0x263E);
themeToggleButton->setStyleSheet(QString("QToolButton { color : %1; }").arg(platformStyle->SingleColor().name()));
themeToggleButton->setText(darkModeEnabled ? QString(sunGlyph) : QString(moonGlyph));
themeToggleButton->setToolTip(darkModeEnabled ? tr("Switch to light mode (right-click for green tint options)") : tr("Switch to dark mode (right-click for green tint options)"));
}

void BitcoinGUI::showDarkTintMenu(const QPoint& point)
{
if (!themeTintMenu || !themeToggleButton) {
return;
}
const int currentTint = PlatformStyle::darkModeTint();
Q_FOREACH (QAction* action, themeTintMenu->actions())
{
action->setChecked(action->data().toInt() == currentTint);
}
themeTintMenu->exec(themeToggleButton->mapToGlobal(point));
}

void BitcoinGUI::onDarkTintSelected(QAction* action)
{
if (!action) {
return;
}
PlatformStyle::setDarkModeTint(action->data().toInt());
updateDarkModeToggleText();
}

UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
optionsModel(0),
menu(0)
Expand Down
7 changes: 7 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ QT_BEGIN_NAMESPACE
class QAction;
class QProgressBar;
class QProgressDialog;
class QToolButton;
QT_END_NAMESPACE

/**
Expand Down Expand Up @@ -84,6 +85,8 @@ class BitcoinGUI : public QMainWindow
WalletFrame *walletFrame;

UnitDisplayStatusBarControl *unitDisplayControl;
QToolButton *themeToggleButton;
QMenu *themeTintMenu;
QLabel *labelWalletEncryptionIcon;
QLabel *labelWalletHDStatusIcon;
QLabel *connectionsControl;
Expand Down Expand Up @@ -244,6 +247,10 @@ private Q_SLOTS:

/** Toggle networking */
void toggleNetworkActive();
void toggleDarkMode();
void updateDarkModeToggleText();
void showDarkTintMenu(const QPoint& point);
void onDarkTintSelected(QAction* action);

void showModalOverlay();
};
Expand Down
2 changes: 2 additions & 0 deletions src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "fs.h"
#include "guiutil.h"
#include "platformstyle.h"

#include "util.h"

Expand Down Expand Up @@ -121,6 +122,7 @@ Intro::Intro(QWidget *parent) :
signalled(false)
{
ui->setupUi(this);
PlatformStyle::applyTheme(PlatformStyle::isDarkModeEnabled());
ui->welcomeLabel->setText(ui->welcomeLabel->text().arg(tr(PACKAGE_NAME)));
ui->storageLabel->setText(ui->storageLabel->text().arg(tr(PACKAGE_NAME)));
uint64_t pruneTarget = std::max<int64_t>(0, GetArg("-prune", 0));
Expand Down
19 changes: 19 additions & 0 deletions src/qt/modaloverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ui_modaloverlay.h"

#include "guiutil.h"
#include "platformstyle.h"

#include "chainparams.h"

Expand All @@ -22,6 +23,7 @@ layerIsVisible(false),
userClosed(false)
{
ui->setupUi(this);
updateStyles();
connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(closeClicked()));
if (parent) {
parent->installEventFilter(this);
Expand All @@ -32,6 +34,21 @@ userClosed(false)
setVisible(false);
}

void ModalOverlay::updateStyles()
{
const bool darkModeEnabled = PlatformStyle::isDarkModeEnabled();
ui->bgWidget->setStyleSheet("#bgWidget { background: rgba(0,0,0,220); }");
if (darkModeEnabled) {
ui->contentWidget->setStyleSheet(
"#contentWidget { background: rgba(35,44,38,240); border-radius: 6px; }\n"
"QLabel { color: rgb(214,232,220); }");
} else {
ui->contentWidget->setStyleSheet(
"#contentWidget { background: rgba(255,255,255,240); border-radius: 6px; }\n"
"QLabel { color: rgb(40,40,40); }");
}
}

ModalOverlay::~ModalOverlay()
{
delete ui;
Expand Down Expand Up @@ -150,6 +167,8 @@ void ModalOverlay::toggleVisibility()

void ModalOverlay::showHide(bool hide, bool userRequested)
{
updateStyles();

if ( (layerIsVisible && !hide) || (!layerIsVisible && hide) || (!hide && userClosed && !userRequested))
return;

Expand Down
2 changes: 2 additions & 0 deletions src/qt/modaloverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public Q_SLOTS:
bool event(QEvent* ev);

private:
void updateStyles();

Ui::ModalOverlay *ui;
int bestHeaderHeight; //best known height (based on the headers)
QDateTime bestHeaderDate;
Expand Down
Loading
Loading