Merge pull request 'Calc: update exchange icon on skin change' (#323) from tobtoht/feather:calc_update_icon into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/323
This commit is contained in:
tobtoht 2021-02-03 19:41:40 +00:00
commit 038eee5f42
7 changed files with 54 additions and 4 deletions

View file

@ -6,6 +6,8 @@
#include "calcwidget.h"
#include "ui_calcwidget.h"
#include "mainwindow.h"
#include "components.h"
#include "utils/ColorScheme.h"
CalcWidget::CalcWidget(QWidget *parent) :
QWidget(parent),
@ -15,8 +17,7 @@ CalcWidget::CalcWidget(QWidget *parent) :
m_ctx = MainWindow::getContext();
ui->imageExchange->setBackgroundRole(QPalette::Base);
QPixmap pm(":/assets/images/exchange.png");
ui->imageExchange->setPixmap(pm);
ui->imageExchange->setAssets(":/assets/images/exchange.png", ":/assets/images/exchange_white.png");
ui->imageExchange->setScaledContents(true);
ui->imageExchange->setFixedSize(26, 26);
@ -134,6 +135,10 @@ void CalcWidget::initComboBox() {
this->m_comboBoxInit = true;
}
void CalcWidget::skinChanged() {
ui->imageExchange->setMode(ColorScheme::hasDarkBackground(this));
}
CalcWidget::~CalcWidget() {
delete ui;
}

View file

@ -28,6 +28,7 @@ public slots:
void toComboChanged(const QString& data);
void initFiat();
void initCrypto();
void skinChanged();
private:
Ui::CalcWidget *ui;

View file

@ -84,7 +84,7 @@
</layout>
</item>
<item row="0" column="1">
<widget class="QLabel" name="imageExchange">
<widget class="DoublePixmapLabel" name="imageExchange">
<property name="text">
<string>exchange image</string>
</property>
@ -159,6 +159,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>DoublePixmapLabel</class>
<extends>QLabel</extends>
<header>components.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>

View file

@ -5,6 +5,24 @@
#include <QtWidgets>
DoublePixmapLabel::DoublePixmapLabel(QWidget *parent)
: QLabel(parent)
{}
void DoublePixmapLabel::setAssets(const QString &firstAsset, const QString &secondAsset)
{
m_first.load(firstAsset);
m_second.load(secondAsset);
this->setPixmap(m_first);
}
void DoublePixmapLabel::setMode(bool mode) {
if (mode != m_mode) {
this->setPixmap(mode ? m_second : m_first);
}
m_mode = mode;
}
StatusBarButton::StatusBarButton(const QIcon &icon, const QString &tooltip, QWidget *parent) : QPushButton(parent) {
setIcon(icon);
setToolTip(tooltip);

View file

@ -11,6 +11,23 @@
#include <QPlainTextEdit>
#include <QLineEdit>
class DoublePixmapLabel : public QLabel
{
Q_OBJECT
public:
explicit DoublePixmapLabel(QWidget *parent = nullptr);
public slots:
void setAssets(const QString &firstAsset, const QString &secondAsset);
void setMode(bool mode);
private:
bool m_mode = false;
QPixmap m_first;
QPixmap m_second;
};
class StatusBarButton : public QPushButton
{
Q_OBJECT

View file

@ -1019,6 +1019,8 @@ void MainWindow::skinChanged(const QString &skinName) {
qApp->setStyleSheet(m_skins[skinName]);
qDebug() << QString("Skin changed to %1").arg(skinName);
ColorScheme::updateFromWidget(this);
ui->conversionWidget->skinChanged();
}
void MainWindow::closeEvent(QCloseEvent *event) {

View file

@ -20,7 +20,7 @@ bool ColorScheme::hasDarkBackground(QWidget *widget) {
}
void ColorScheme::updateFromWidget(QWidget *widget, bool forceDark) {
darkScheme = forceDark or ColorScheme::hasDarkBackground(widget);
darkScheme = forceDark || ColorScheme::hasDarkBackground(widget);
}
QString ColorSchemeItem::asStylesheet(bool background) {