From b7afa427568e585adf4a1c5c0ebb742be0ad398e Mon Sep 17 00:00:00 2001 From: fengli Date: Thu, 4 Jan 2024 21:28:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=92=E4=BB=B6=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E4=B8=BA=E7=B3=BB=E7=BB=9F=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 插件图标更换为系统图标 Log: 插件图标更换为系统图标 --- .../gui/monitor_plugin.cpp | 10 +++++++--- .../gui/monitorpluginbuttonwidget.cpp | 15 +++++++++------ .../gui/monitorpluginbuttonwidget.h | 3 ++- .../gui/quickpanelwidget.cpp | 5 +++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/deepin-system-monitor-plugin/gui/monitor_plugin.cpp b/deepin-system-monitor-plugin/gui/monitor_plugin.cpp index 3c9e4134..cfd85226 100644 --- a/deepin-system-monitor-plugin/gui/monitor_plugin.cpp +++ b/deepin-system-monitor-plugin/gui/monitor_plugin.cpp @@ -65,8 +65,9 @@ void MonitorPlugin::init(PluginProxyInterface *proxyInter) #ifdef USE_API_QUICKPANEL20 m_proxyInter->itemAdded(this, pluginName()); m_quickPanelWidget->setDescription(pluginDisplayName()); - QString plugIcon = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType? "dsm_pluginicon_dark" : "dsm_pluginicon_light"; - m_quickPanelWidget->setIcon(QIcon::fromTheme(plugIcon)); + QString plugIcon = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? "status-system-monitor-dark" : "status-system-monitor"; + QIcon fallbackIcon = QIcon::fromTheme(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType? "dsm_pluginicon_dark" : "dsm_pluginicon_light"); + m_quickPanelWidget->setIcon(QIcon::fromTheme(plugIcon, fallbackIcon)); connect(m_quickPanelWidget,&QuickPanelWidget::clicked,this,&MonitorPlugin::onClickQuickPanel); qInfo() << __FUNCTION__ << __LINE__ << "[-MonitorPlugin-] QUICKPANEL20"; #endif @@ -446,7 +447,10 @@ MonitorPlugin::~MonitorPlugin() QIcon MonitorPlugin::icon(Dock::IconType iconType, Dock::ThemeType) const { - return( (iconType == Dock::IconType_DCC_Settings) ? QIcon(":/deepin-system-monitor.svg") : QIcon()); + QIcon fallbackIcon = QIcon(":/deepin-system-monitor.svg"); + QString iconName = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? "status-system-monitor-dark" : "status-system-monitor"; + + return( (iconType == Dock::IconType_DCC_Settings) ? QIcon::fromTheme(iconName, fallbackIcon) : QIcon()); } void MonitorPlugin::onClickQuickPanel() diff --git a/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.cpp b/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.cpp index 7be61112..4399e3f4 100644 --- a/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.cpp +++ b/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.cpp @@ -38,7 +38,8 @@ void MonitorPluginButtonWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e) - QString iconName = "dsm_pluginicon_light"; + QString iconName = "status-system-monitor"; + QString fallbackIconName = "dsm_pluginicon_light"; QPixmap pixmap; int iconSize = PLUGIN_ICON_MAX_SIZE; @@ -84,13 +85,14 @@ void MonitorPluginButtonWidget::paintEvent(QPaintEvent *e) painter.fillPath(path, color); } else if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { // 最小尺寸时,不画背景,采用深色图标 - iconName = "dsm_pluginicon_dark"; + iconName = "status-system-monitor-dark"; + fallbackIconName = "dsm_pluginicon_dark"; } const auto ratio = devicePixelRatioF(); painter.setOpacity(1); - pixmap = loadSvg(iconName, ":/icons/deepin/builtin/actions/", iconSize, ratio); + pixmap = loadSvg(iconName, fallbackIconName, ":/icons/deepin/builtin/actions/", iconSize, ratio); const QRectF &rf = QRectF(rect()); const QRectF &rfp = QRectF(pixmap.rect()); @@ -155,9 +157,10 @@ void MonitorPluginButtonWidget::leaveEvent(QEvent *event) QWidget::leaveEvent(event); } -const QPixmap MonitorPluginButtonWidget::loadSvg(const QString &iconName, const QString &localPath, const int size, const qreal ratio) +const QPixmap MonitorPluginButtonWidget::loadSvg(const QString &iconName, const QString &fallbackIconName, const QString &localPath, const int size, const qreal ratio) { - QIcon icon = QIcon::fromTheme(iconName); + QIcon fallbackIcon = QIcon::fromTheme(fallbackIconName); + QIcon icon = QIcon::fromTheme(iconName, fallbackIcon); int pixmapSize = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? size : int(size * ratio); if (!icon.isNull()) { QPixmap pixmap = icon.pixmap(pixmapSize); @@ -166,7 +169,7 @@ const QPixmap MonitorPluginButtonWidget::loadSvg(const QString &iconName, const } QPixmap pixmap(pixmapSize, pixmapSize); - QString localIcon = QString("%1%2%3").arg(localPath).arg(iconName + "_20px").arg(iconName.contains(".svg") ? "" : ".svg"); + QString localIcon = QString("%1%2%3").arg(localPath).arg(fallbackIconName + "_20px").arg(fallbackIconName.contains(".svg") ? "" : ".svg"); QSvgRenderer renderer(localIcon); pixmap.fill(Qt::transparent); diff --git a/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.h b/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.h index 7ea82c32..5dc77fb7 100644 --- a/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.h +++ b/deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.h @@ -58,12 +58,13 @@ class MonitorPluginButtonWidget :public QWidget //! \brief loadSvg 加载SVG图标 //! \param iconName 图标名称 + //! \param fallbackIconName 备用图标名称,没有系统图标,就使用资源文件的图标 //! \param localPath 图标路径 //! \param size 图标大小 //! \param ratio 缩放比例 //! \return //! - const QPixmap loadSvg(const QString &iconName, const QString &localPath, const int size, const qreal ratio); + const QPixmap loadSvg(const QString &iconName, const QString &fallbackIconName, const QString &localPath, const int size, const qreal ratio); //! //! \brief containCursorPos 是否鼠标在界面上 //! \return diff --git a/deepin-system-monitor-plugin/gui/quickpanelwidget.cpp b/deepin-system-monitor-plugin/gui/quickpanelwidget.cpp index cd4048c6..3bd7810d 100644 --- a/deepin-system-monitor-plugin/gui/quickpanelwidget.cpp +++ b/deepin-system-monitor-plugin/gui/quickpanelwidget.cpp @@ -87,8 +87,9 @@ void QuickPanelWidget::paintEvent(QPaintEvent *event) void QuickPanelWidget::refreshBg() { - QString plugIcon = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType? "dsm_pluginicon_dark" : "dsm_pluginicon_light"; - setIcon(QIcon::fromTheme(plugIcon)); + QString plugIcon = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? "status-system-monitor-dark" : "status-system-monitor"; + QIcon fallbackIcon = QIcon::fromTheme(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? "dsm_pluginicon_dark" : "dsm_pluginicon_light"); + setIcon(QIcon::fromTheme(plugIcon, fallbackIcon)); m_description->setForegroundRole(m_icon->activeState() && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType ? QPalette::Highlight : QPalette::NoRole); update();