Skip to content

Commit

Permalink
feat: 插件图标更换为系统图标
Browse files Browse the repository at this point in the history
插件图标更换为系统图标

Log: 插件图标更换为系统图标
  • Loading branch information
feeengli committed Jan 4, 2024
1 parent 31a4c43 commit c64031e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
10 changes: 7 additions & 3 deletions deepin-system-monitor-plugin/gui/monitor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion deepin-system-monitor-plugin/gui/monitorpluginbuttonwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions deepin-system-monitor-plugin/gui/quickpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c64031e

Please sign in to comment.