mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 05:49:11 +01:00
ef4dfa8524
(script modified to account for Dash backports, doesn't account for rebasing) ------------- BEGIN SCRIPT --------------- mkdir -p src/util git mv src/util.h src/util/system.h git mv src/util.cpp src/util/system.cpp git mv src/utilmemory.h src/util/memory.h git mv src/utilmoneystr.h src/util/moneystr.h git mv src/utilmoneystr.cpp src/util/moneystr.cpp git mv src/utilstrencodings.h src/util/strencodings.h git mv src/utilstrencodings.cpp src/util/strencodings.cpp git mv src/utiltime.h src/util/time.h git mv src/utiltime.cpp src/util/time.cpp git mv src/utilasmap.h src/util/asmap.h git mv src/utilasmap.cpp src/util/asmap.cpp git mv src/utilstring.h src/util/string.h git mv src/utilstring.cpp src/util/string.cpp gsed -i 's/<util\.h>/<util\/system\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilmemory\.h>/<util\/memory\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilmoneystr\.h>/<util\/moneystr\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utiltime\.h>/<util\/time\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilasmap\.h>/<util\/asmap\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilstring\.h>/<util\/string\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h gsed -i 's/BITCOIN_UTILMEMORY_H/BITCOIN_UTIL_MEMORY_H/g' src/util/memory.h gsed -i 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h gsed -i 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h gsed -i 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h gsed -i 's/BITCOIN_UTILASMAP_H/BITCOIN_UTIL_ASMAP_H/g' src/util/asmap.h gsed -i 's/BITCOIN_UTILSTRING_H/BITCOIN_UTIL_STRING_H/g' src/util/string.h gsed -i 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am gsed -i 's/utilmemory\.\(h\|cpp\)/util\/memory\.\1/g' src/Makefile.am gsed -i 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am gsed -i 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am gsed -i 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am gsed -i 's/utilasmap\.\(h\|cpp\)/util\/asmap\.\1/g' src/Makefile.am gsed -i 's/utilstring\.\(h\|cpp\)/util\/string\.\1/g' src/Makefile.am gsed -i 's/-> util ->/-> util\/system ->/' test/lint/lint-circular-dependencies.sh gsed -i 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-format-strings.py test/lint/lint-locale-dependence.sh gsed -i 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh gsed -i 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh ------------- END SCRIPT ---------------
169 lines
6.1 KiB
C++
169 lines
6.1 KiB
C++
// Copyright (c) 2020-2021 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/system.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(currentIndexChanged(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)));
|
|
|
|
connect(ui->theme, &QComboBox::currentTextChanged, [=]() { Q_EMIT appearanceChanged(); });
|
|
connect(ui->fontFamily, &QComboBox::currentTextChanged, [=]() { Q_EMIT appearanceChanged(); });
|
|
connect(ui->fontScaleSlider, &QSlider::sliderReleased, [=]() { Q_EMIT appearanceChanged(); });
|
|
connect(ui->fontWeightNormalSlider, &QSlider::sliderReleased, [=]() { Q_EMIT appearanceChanged(); });
|
|
connect(ui->fontWeightBoldSlider, &QSlider::sliderReleased, [=]() { Q_EMIT appearanceChanged(); });
|
|
}
|
|
|
|
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);
|
|
// Force loading the theme
|
|
if (model) {
|
|
GUIUtil::loadTheme(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AppearanceWidget::updateFontFamily(int index)
|
|
{
|
|
GUIUtil::setFontFamily(static_cast<GUIUtil::FontFamily>(ui->fontFamily->itemData(index).toInt()));
|
|
updateWeightSlider(true);
|
|
}
|
|
|
|
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(const bool fForce)
|
|
{
|
|
int nMaximum = GUIUtil::getSupportedWeights().size() - 1;
|
|
|
|
ui->fontWeightNormalSlider->setMinimum(0);
|
|
ui->fontWeightNormalSlider->setMaximum(nMaximum);
|
|
|
|
ui->fontWeightBoldSlider->setMinimum(0);
|
|
ui->fontWeightBoldSlider->setMaximum(nMaximum);
|
|
|
|
if (fForce || !GUIUtil::isSupportedWeight(prevWeightNormal) || !GUIUtil::isSupportedWeight(prevWeightBold)) {
|
|
int nIndexNormal = GUIUtil::supportedWeightToIndex(GUIUtil::getSupportedFontWeightNormalDefault());
|
|
int nIndexBold = GUIUtil::supportedWeightToIndex(GUIUtil::getSupportedFontWeightBoldDefault());
|
|
assert(nIndexNormal != -1 && nIndexBold != -1);
|
|
updateFontWeightNormal(nIndexNormal, true);
|
|
updateFontWeightBold(nIndexBold, true);
|
|
}
|
|
}
|