From e9e2af5afb6ce7f8756906cf6edbc397ef381caa Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Thu, 31 Mar 2022 11:22:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=8E=A7=E4=BB=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kybackup/component/imageutil.cpp | 42 +++++++---------------------- kybackup/component/myiconbutton.cpp | 1 + kybackup/component/pixmaplabel.cpp | 8 +++++- kybackup/component/pixmaplabel.h | 6 ++--- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/kybackup/component/imageutil.cpp b/kybackup/component/imageutil.cpp index b1fdf51..c898f84 100755 --- a/kybackup/component/imageutil.cpp +++ b/kybackup/component/imageutil.cpp @@ -30,23 +30,12 @@ const QPixmap ImageUtil::loadTheme(const QString &theme, const QString &defaultT { int origSize = size; const auto ratio = qApp->devicePixelRatio(); - if ( 2 == ratio) { - size += origSize; - } else if (3 == ratio) { - size += origSize; - } + size = origSize * ratio; - QIcon icon = QIcon::fromTheme(theme); - // 在主题中未找到,则使用默认路径的图标 - if (icon.isNull()) { - QIcon iconDefault(defaultTheme); - QPixmap pixmap = iconDefault.pixmap(iconDefault.actualSize(QSize(size, size))); - - pixmap.setDevicePixelRatio(ratio); - return drawSymbolicColoredPixmap(pixmap, color); - } - - return icon.pixmap(icon.actualSize(QSize(size, size))); + QIcon icon = QIcon::fromTheme(theme, QIcon(defaultTheme)); + QPixmap pixmap = icon.pixmap(icon.actualSize(QSize(size, size))); + pixmap.setDevicePixelRatio(ratio); + return drawSymbolicColoredPixmap(pixmap, color); } const QPixmap ImageUtil::loadTheme(const QString &theme, const QString &defaultTheme, const QString& color, QSize size) @@ -57,28 +46,17 @@ const QPixmap ImageUtil::loadTheme(const QString &theme, const QString &defaultT size.setWidth(origWidth * ratio); size.setHeight(origHeight * ratio); - QIcon icon = QIcon::fromTheme(theme); - // 在主题中未找到,则使用默认路径的图标 - if (icon.isNull()) { - QIcon iconDefault(defaultTheme); - QPixmap pixmap = iconDefault.pixmap(iconDefault.actualSize(size)); - - pixmap.setDevicePixelRatio(ratio); - return drawSymbolicColoredPixmap(pixmap, color); - } - - return icon.pixmap(icon.actualSize(size)); + QIcon icon = QIcon::fromTheme(theme, QIcon(defaultTheme)); + QPixmap pixmap = icon.pixmap(icon.actualSize(size)); + pixmap.setDevicePixelRatio(ratio); + return drawSymbolicColoredPixmap(pixmap, color); } const QPixmap ImageUtil::loadPixmap(QIcon &icon, const QString &color, int size) { int origSize = size; const auto ratio = qApp->devicePixelRatio(); - if ( 2 == ratio) { - size += origSize; - } else if (3 == ratio) { - size += origSize; - } + size = origSize * ratio; QPixmap pixmap = icon.pixmap(QSize(size, size)); diff --git a/kybackup/component/myiconbutton.cpp b/kybackup/component/myiconbutton.cpp index 13058ad..7988401 100755 --- a/kybackup/component/myiconbutton.cpp +++ b/kybackup/component/myiconbutton.cpp @@ -25,6 +25,7 @@ MyIconButton::MyIconButton(QWidget *parent) : m_iconButton->setFixedSize(QSize(24, 24)); m_iconButton->setFocusPolicy(Qt::NoFocus); m_iconButton->setFlat(true); + // m_iconButton->setProperty("useIconHighlightEffect", 0x8); QString iconBtnQss = QString("QPushButton:checked{border: none;}" "QPushButton:!checked{border: none;}"); m_iconButton->setStyleSheet(iconBtnQss); diff --git a/kybackup/component/pixmaplabel.cpp b/kybackup/component/pixmaplabel.cpp index 6d9576f..4c07fcc 100644 --- a/kybackup/component/pixmaplabel.cpp +++ b/kybackup/component/pixmaplabel.cpp @@ -15,6 +15,7 @@ PixmapLabel::PixmapLabel(QWidget *parent) : PixmapLabel::~PixmapLabel() {} +// 应用场景一:设置深浅主题分别展示的图片 void PixmapLabel::setLightAndDarkPixmap(const QString &light, const QString &dark) { m_light = light; @@ -37,7 +38,7 @@ void PixmapLabel::on_styleNameChanged(bool isDark) } } -// 设置跟随主题图标 +// 应用场景二:设置跟随主题风格图标,不随深浅背景色变化 void PixmapLabel::setUkuiIconSchema(const QString &schema, QSize size) { m_iconTheme = schema; @@ -49,16 +50,21 @@ void PixmapLabel::setUkuiIconSchema(const QString &schema, QSize size) connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &PixmapLabel::on_themeIconChanged); } +// 应用场景三:设置跟随主题风格图标(主题中也可能不存在该图标),随深浅色背景色变化 void PixmapLabel::setUkuiIconSchema(const QString &schema, const QString &schemaDefault, QSize size) { m_iconTheme = schema; m_iconThemeDefault = schemaDefault; m_iconSize = size; + // setProperty("useIconHighlightEffect", 0x8); on_themeIconChanged(); disconnect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &PixmapLabel::on_themeIconChanged); connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &PixmapLabel::on_themeIconChanged); + + disconnect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::styleNameChanged, this, &PixmapLabel::on_themeIconChanged); + connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::styleNameChanged, this, &PixmapLabel::on_themeIconChanged); } void PixmapLabel::on_themeIconChanged() diff --git a/kybackup/component/pixmaplabel.h b/kybackup/component/pixmaplabel.h index 6912971..f280bd3 100644 --- a/kybackup/component/pixmaplabel.h +++ b/kybackup/component/pixmaplabel.h @@ -12,12 +12,12 @@ public: explicit PixmapLabel(QWidget *parent = nullptr); ~PixmapLabel(); - // 设置深浅主题分别展示的图片 + // 应用场景一:设置深浅主题分别展示的图片 void setLightAndDarkPixmap(const QString &light, const QString &dark); - // 设置跟随主题图标 + // 应用场景二:设置跟随主题风格图标,不随深浅背景色变化 void setUkuiIconSchema(const QString &schema, QSize size = QSize(24, 24)); - // 设置跟随主题图标 + // 应用场景三:设置跟随主题风格图标(主题中也可能不存在该图标),随深浅色背景色变化 void setUkuiIconSchema(const QString &schema, const QString &schemaDefault, QSize size = QSize(16, 16)); private slots: