mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-29 13:32:33 +02:00
qt: Add GUIUtil::ThemedLabel class
The ThemedLabel class correctly handles appearance changes on macOS.
This commit is contained in:
parent
c054720e08
commit
d99ef327a8
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <qt/bitcoinaddressvalidator.h>
|
#include <qt/bitcoinaddressvalidator.h>
|
||||||
#include <qt/bitcoinunits.h>
|
#include <qt/bitcoinunits.h>
|
||||||
|
#include <qt/platformstyle.h>
|
||||||
#include <qt/qvalidatedlineedit.h>
|
#include <qt/qvalidatedlineedit.h>
|
||||||
#include <qt/sendcoinsrecipient.h>
|
#include <qt/sendcoinsrecipient.h>
|
||||||
|
|
||||||
@ -61,6 +62,7 @@
|
|||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
@ -786,6 +788,35 @@ qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal m
|
|||||||
return font_size;
|
return font_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThemedLabel::ThemedLabel(const PlatformStyle* platform_style, QWidget* parent)
|
||||||
|
: QLabel{parent}, m_platform_style{platform_style}
|
||||||
|
{
|
||||||
|
assert(m_platform_style);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemedLabel::setThemedPixmap(const QString& image_filename, int width, int height)
|
||||||
|
{
|
||||||
|
m_image_filename = image_filename;
|
||||||
|
m_pixmap_width = width;
|
||||||
|
m_pixmap_height = height;
|
||||||
|
updateThemedPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemedLabel::changeEvent(QEvent* e)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
if (e->type() == QEvent::PaletteChange) {
|
||||||
|
updateThemedPixmap();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
QLabel::changeEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemedLabel::updateThemedPixmap()
|
||||||
|
{
|
||||||
|
setPixmap(m_platform_style->SingleColorIcon(m_image_filename).pixmap(m_pixmap_width, m_pixmap_height));
|
||||||
|
}
|
||||||
|
|
||||||
void ClickableLabel::mouseReleaseEvent(QMouseEvent *event)
|
void ClickableLabel::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_EMIT clicked(event->pos());
|
Q_EMIT clicked(event->pos());
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
class PlatformStyle;
|
||||||
class QValidatedLineEdit;
|
class QValidatedLineEdit;
|
||||||
class SendCoinsRecipient;
|
class SendCoinsRecipient;
|
||||||
|
|
||||||
@ -221,6 +222,25 @@ namespace GUIUtil
|
|||||||
|
|
||||||
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
|
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
|
||||||
|
|
||||||
|
class ThemedLabel : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ThemedLabel(const PlatformStyle* platform_style, QWidget* parent = nullptr);
|
||||||
|
void setThemedPixmap(const QString& image_filename, int width, int height);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent(QEvent* e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const PlatformStyle* m_platform_style;
|
||||||
|
QString m_image_filename;
|
||||||
|
int m_pixmap_width;
|
||||||
|
int m_pixmap_height;
|
||||||
|
void updateThemedPixmap();
|
||||||
|
};
|
||||||
|
|
||||||
class ClickableLabel : public QLabel
|
class ClickableLabel : public QLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Loading…
Reference in New Issue
Block a user