Skip to content
Merged
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
1 change: 1 addition & 0 deletions contrib/dash-qt.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FORMS += \
../src/qt/forms/aboutdialog.ui \
../src/qt/forms/addressbookpage.ui \
../src/qt/forms/appearancewidget.ui \
../src/qt/forms/askpassphrasedialog.ui \
../src/qt/forms/coincontroldialog.ui \
../src/qt/forms/debugwindow.ui \
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ QT_TS = \

QT_FORMS_UI = \
qt/forms/addressbookpage.ui \
qt/forms/appearancewidget.ui \
qt/forms/askpassphrasedialog.ui \
qt/forms/coincontroldialog.ui \
qt/forms/editaddressdialog.ui \
Expand All @@ -54,6 +55,7 @@ QT_FORMS_UI = \
QT_MOC_CPP = \
qt/moc_addressbookpage.cpp \
qt/moc_addresstablemodel.cpp \
qt/moc_appearancewidget.cpp \
qt/moc_askpassphrasedialog.cpp \
qt/moc_bantablemodel.cpp \
qt/moc_bitcoinaddressvalidator.cpp \
Expand Down Expand Up @@ -126,6 +128,7 @@ PROTOBUF_PROTO = qt/paymentrequest.proto
BITCOIN_QT_H = \
qt/addressbookpage.h \
qt/addresstablemodel.h \
qt/appearancewidget.h \
qt/askpassphrasedialog.h \
qt/bantablemodel.h \
qt/bitcoinaddressvalidator.h \
Expand Down Expand Up @@ -238,6 +241,7 @@ RES_ICONS = \
qt/res/icons/network_disabled.png

BITCOIN_QT_BASE_CPP = \
qt/appearancewidget.cpp \
qt/bantablemodel.cpp \
qt/bitcoinaddressvalidator.cpp \
qt/bitcoinamountfield.cpp \
Expand Down
159 changes: 159 additions & 0 deletions src/qt/appearancewidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright (c) 2020 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include <config/dash-config.h>
#endif

#include <qt/forms/ui_appearancewidget.h>

#include <qt/appearancewidget.h>
#include <qt/optionsmodel.h>

#include <util.h>

#include <QComboBox>
#include <QDataWidgetMapper>
#include <QSettings>
#include <QSlider>

AppearanceWidget::AppearanceWidget(QWidget* parent) :
QWidget(parent),
ui(new Ui::AppearanceWidget),
fAcceptChanges(false),
prevTheme(GUIUtil::getActiveTheme()),
prevFontFamily(GUIUtil::getFontFamily()),
prevScale(GUIUtil::getFontScale()),
prevWeightNormal(GUIUtil::getFontWeightNormal()),
prevWeightBold(GUIUtil::getFontWeightBold())
{
ui->setupUi(this);

for (const QString& entry : GUIUtil::listThemes()) {
ui->theme->addItem(entry, QVariant(entry));
}

GUIUtil::FontFamily fontSystem = GUIUtil::FontFamily::SystemDefault;
GUIUtil::FontFamily fontMontserrat = GUIUtil::FontFamily::Montserrat;

ui->fontFamily->addItem(GUIUtil::fontFamilyToString(fontSystem), QVariant(static_cast<int>(fontSystem)));
ui->fontFamily->addItem(GUIUtil::fontFamilyToString(fontMontserrat), QVariant(static_cast<int>(fontMontserrat)));

updateWeightSlider();

mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setOrientation(Qt::Vertical);

connect(ui->theme, SIGNAL(currentTextChanged(const QString&)), this, SLOT(updateTheme(const QString&)));
connect(ui->fontFamily, SIGNAL(activated(int)), this, SLOT(updateFontFamily(int)));
connect(ui->fontScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontScale(int)));
connect(ui->fontWeightNormalSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontWeightNormal(int)));
connect(ui->fontWeightBoldSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontWeightBold(int)));
}

AppearanceWidget::~AppearanceWidget()
{
if (fAcceptChanges) {
mapper->submit();
} else {
if (prevTheme != GUIUtil::getActiveTheme()) {
updateTheme(prevTheme);
}
if (prevFontFamily != GUIUtil::getFontFamily()) {
GUIUtil::setFontFamily(prevFontFamily);
}
if (prevScale != GUIUtil::getFontScale()) {
GUIUtil::setFontScale(prevScale);
}
if (prevWeightNormal != GUIUtil::getFontWeightNormal()) {
GUIUtil::setFontWeightNormal(prevWeightNormal);
}
if (prevWeightBold != GUIUtil::getFontWeightBold()) {
GUIUtil::setFontWeightBold(prevWeightBold);
}
}
delete ui;
}

void AppearanceWidget::setModel(OptionsModel* _model)
{
this->model = _model;

if (_model) {
mapper->setModel(_model);
mapper->addMapping(ui->theme, OptionsModel::Theme);
mapper->addMapping(ui->fontFamily, OptionsModel::FontFamily);
mapper->addMapping(ui->fontScaleSlider, OptionsModel::FontScale);
mapper->addMapping(ui->fontWeightNormalSlider, OptionsModel::FontWeightNormal);
mapper->addMapping(ui->fontWeightBoldSlider, OptionsModel::FontWeightBold);
mapper->toFirst();
}
}

void AppearanceWidget::accept()
{
fAcceptChanges = true;
}

void AppearanceWidget::updateTheme(const QString& theme)
{
QString newValue = theme.isEmpty() ? ui->theme->currentData().toString() : theme;
if (GUIUtil::getActiveTheme() != newValue) {
QSettings().setValue("theme", newValue);
GUIUtil::loadTheme();
}
}

void AppearanceWidget::updateFontFamily(int index)
{
GUIUtil::setFontFamily(static_cast<GUIUtil::FontFamily>(ui->fontFamily->itemData(index).toInt()));
updateWeightSlider();
}

void AppearanceWidget::updateFontScale(int nScale)
{
GUIUtil::setFontScale(nScale);
}

void AppearanceWidget::updateFontWeightNormal(int nValue, bool fForce)
{
int nSliderValue = nValue;
if (nValue > ui->fontWeightBoldSlider->value() && !fForce) {
nSliderValue = ui->fontWeightBoldSlider->value();
}
const QSignalBlocker blocker(ui->fontWeightNormalSlider);
ui->fontWeightNormalSlider->setValue(nSliderValue);
GUIUtil::setFontWeightNormal(GUIUtil::supportedWeightFromIndex(ui->fontWeightNormalSlider->value()));
}

void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce)
{
int nSliderValue = nValue;
if (nValue < ui->fontWeightNormalSlider->value() && !fForce) {
nSliderValue = ui->fontWeightNormalSlider->value();
}
const QSignalBlocker blocker(ui->fontWeightBoldSlider);
ui->fontWeightBoldSlider->setValue(nSliderValue);
GUIUtil::setFontWeightBold(GUIUtil::supportedWeightFromIndex(ui->fontWeightBoldSlider->value()));
}

void AppearanceWidget::updateWeightSlider()
{
int nMaximum = GUIUtil::getSupportedWeights().size() - 1;

ui->fontWeightNormalSlider->setMinimum(0);
ui->fontWeightNormalSlider->setMaximum(nMaximum);

ui->fontWeightBoldSlider->setMinimum(0);
ui->fontWeightBoldSlider->setMaximum(nMaximum);

if (nMaximum < 4) {
updateFontWeightNormal(0, true);
updateFontWeightBold(nMaximum, true);
} else {
updateFontWeightNormal(1, true);
updateFontWeightBold(4, true);
}
}
56 changes: 56 additions & 0 deletions src/qt/appearancewidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2020 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_QT_APPEARANCE_WIDGET_H
#define DASH_QT_APPEARANCE_WIDGET_H

#include <QWidget>

#include <qt/guiutil.h>

namespace Ui {
class AppearanceWidget;
}

class OptionsModel;

class QDataWidgetMapper;
class QSlider;
class QComboBox;

class AppearanceWidget : public QWidget
{
Q_OBJECT

public:
explicit AppearanceWidget(QWidget* parent = 0);
~AppearanceWidget();

void setModel(OptionsModel* model);

public Q_SLOTS:
void accept();

private Q_SLOTS:
void updateTheme(const QString& toTheme = QString());
void updateFontFamily(int index);
void updateFontScale(int nScale);
void updateFontWeightNormal(int nValue, bool fForce = false);
void updateFontWeightBold(int nValue, bool fForce = false);

private:
Ui::AppearanceWidget* ui;
QDataWidgetMapper* mapper;
OptionsModel* model;
bool fAcceptChanges;
QString prevTheme;
int prevScale;
GUIUtil::FontFamily prevFontFamily;
QFont::Weight prevWeightNormal;
QFont::Weight prevWeightBold;

void updateWeightSlider();
};

#endif // DASH_QT_APPEARANCE_WIDGET_H
1 change: 0 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ void BitcoinGUI::optionsClicked()

OptionsDialog dlg(this, enableWallet);
dlg.setModel(clientModel->getOptionsModel());
connect(&dlg, &OptionsDialog::themeChanged, [=]() { GUIUtil::loadTheme(); });
dlg.exec();
}

Expand Down
3 changes: 3 additions & 0 deletions src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ void BitcoinApplication::initializeResult(bool success)
}
Q_EMIT splashFinished(window);

// Let the users setup their prefered appearance if there are no settings for it defined yet.
GUIUtil::setupAppearance(window, clientModel->getOptionsModel());

#ifdef ENABLE_WALLET
// Now that initialization/startup is done, process any command-line
// dash: URIs or payment requests:
Expand Down
Loading