yhkylin-backup-tools/kybackup/component/pixmaplabel.cpp

55 lines
1.5 KiB
C++

#include "pixmaplabel.h"
#include <QIcon>
#include "../globalsignals.h"
#include "../globalbackupinfo.h"
#include "../gsettingswrapper.h"
#include "../../common/mydefine.h"
PixmapLabel::PixmapLabel(QWidget *parent) :
QLabel(parent)
{}
PixmapLabel::~PixmapLabel()
{}
void PixmapLabel::setLightAndDarkPixmap(const QString &light, const QString &dark)
{
m_light = light;
m_dark = dark;
on_styleNameChanged(g_GSettingWrapper.isDarkTheme());
disconnect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::styleNameChanged, this, &PixmapLabel::on_styleNameChanged);
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::styleNameChanged, this, &PixmapLabel::on_styleNameChanged);
}
void PixmapLabel::on_styleNameChanged(bool isDark)
{
if (isDark) {
QPixmap pixmap(m_dark);
setPixmap(pixmap);
} else {
QPixmap pixmap(m_light);
setPixmap(pixmap);
}
}
// 设置跟随主题图标
void PixmapLabel::setUkuiIconSchema(const QString &schema, QSize size)
{
m_iconTheme = schema;
m_iconSize = size;
on_themeIconChanged();
disconnect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &PixmapLabel::on_themeIconChanged);
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &PixmapLabel::on_themeIconChanged);
}
void PixmapLabel::on_themeIconChanged()
{
QIcon titleIcon = QIcon::fromTheme(m_iconTheme);
setPixmap(titleIcon.pixmap(titleIcon.actualSize(m_iconSize)));
}