fix: 插件适配不同主题图标

实现根据主题返回不同图标的接口

Log:
Influence: 切换主题,观察任务栏的图标和控制中心个性化中的图标是否发生了变化
Task: https://pms.uniontech.com/task-view-222025.html
Change-Id: Ib5420a963da4d5f6b4ed7c3e4927890bd80118e4
This commit is contained in:
donghualin 2022-12-01 12:38:38 +08:00
parent 40d13df340
commit 7b11668d04
9 changed files with 75 additions and 16 deletions

View File

@ -25,11 +25,16 @@
#include "org_deepin_dde_daemon_dock.h"
#include "org_deepin_dde_daemon_dock_entry.h"
#include <DGuiApplicationHelper>
#include <QIcon>
#include <QSettings>
#include <QPainter>
#define PLUGIN_STATE_KEY "enable"
DGUI_USE_NAMESPACE
using DBusDock = org::deepin::dde::daemon::Dock1;
using DockEntryInter = org::deepin::dde::daemon::dock1::Entry;
@ -165,10 +170,18 @@ void OnboardPlugin::pluginSettingsChanged()
refreshPluginItemsVisible();
}
QIcon OnboardPlugin::icon(const DockPart &dockPart)
QIcon OnboardPlugin::icon(const DockPart &dockPart, int themeType)
{
if (dockPart == DockPart::DCCSetting)
return QIcon(":/icons/icon/dcc_keyboard.svg");
if (dockPart == DockPart::DCCSetting) {
if (themeType == DGuiApplicationHelper::ColorType::LightType)
return QIcon(":/icons/icon/dcc_keyboard.svg");
QPixmap pixmap(":/icons/icon/dcc_keyboard.svg");
QPainter pa(&pixmap);
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
pa.fillRect(pixmap.rect(), Qt::white);
return pixmap;
}
if (dockPart == DockPart::QuickPanel)
return m_onboardItem->iconPixmap(24);

View File

@ -58,7 +58,7 @@ public:
void setSortKey(const QString &itemKey, const int order) override;
void pluginSettingsChanged() override;
QIcon icon(const DockPart &dockPart) override;
QIcon icon(const DockPart &dockPart, int themeType) override;
PluginStatus status() const override;
QString description() const override;

View File

@ -174,14 +174,11 @@ void PowerPlugin::pluginSettingsChanged()
refreshPluginItemsVisible();
}
QIcon PowerPlugin::icon(const DockPart &dockPart)
QIcon PowerPlugin::icon(const DockPart &dockPart, int themeType)
{
// 电池插件不显示在快捷面板上,因此此处返回空图标
if (dockPart == DockPart::QuickPanel)
return QIcon();
static QIcon batteryIcon;
const QPixmap pixmap = m_powerStatusWidget->getBatteryIcon();
const QPixmap pixmap = m_powerStatusWidget->getBatteryIcon(themeType);
batteryIcon.detach();
batteryIcon.addPixmap(pixmap);
return batteryIcon;

View File

@ -57,7 +57,7 @@ public:
int itemSortKey(const QString &itemKey) override;
void setSortKey(const QString &itemKey, const int order) override;
void pluginSettingsChanged() override;
QIcon icon(const DockPart &dockPart) override;
QIcon icon(const DockPart &dockPart, int themeType) override;
PluginFlags flags() const override;
private:

View File

@ -54,7 +54,10 @@ void PowerStatusWidget::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);
const QPixmap icon = getBatteryIcon();
int themeType = DGuiApplicationHelper::instance()->themeType();
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && themeType == DGuiApplicationHelper::LightType)
themeType = DGuiApplicationHelper::DarkType;
const QPixmap icon = getBatteryIcon(themeType);
const auto ratio = devicePixelRatioF();
QPainter painter(this);
@ -63,7 +66,7 @@ void PowerStatusWidget::paintEvent(QPaintEvent *e)
painter.drawPixmap(rf.center() - rfp.center() / ratio, icon);
}
QPixmap PowerStatusWidget::getBatteryIcon()
QPixmap PowerStatusWidget::getBatteryIcon(int themeType)
{
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
const uint value = uint(qMin(100.0, qMax(0.0, data.value("Display"))));
@ -108,7 +111,7 @@ QPixmap PowerStatusWidget::getBatteryIcon()
.arg(plugged ? "plugged-symbolic" : "symbolic");
}
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
if (themeType == DGuiApplicationHelper::ColorType::LightType)
iconStr.append(PLUGIN_MIN_ICON_NAME);
const auto ratio = devicePixelRatioF();

View File

@ -24,8 +24,12 @@
#include <QWidget>
#include <DGuiApplicationHelper>
#define POWER_KEY "power"
DGUI_USE_NAMESPACE
class DBusPower;
// from https://upower.freedesktop.org/docs/Device.html#Device:State
@ -43,7 +47,7 @@ class PowerStatusWidget : public QWidget
public:
explicit PowerStatusWidget(QWidget *parent = 0);
QPixmap getBatteryIcon();
QPixmap getBatteryIcon(int themeType);
public Q_SLOTS:
void refreshIcon();

View File

@ -27,9 +27,11 @@
#include <DSysInfo>
#include <DDBusSender>
#include <DGuiApplicationHelper>
#include <QIcon>
#include <QSettings>
#include <QPainter>
#define PLUGIN_STATE_KEY "enable"
#define GSETTING_SHOW_SUSPEND "showSuspend"
@ -38,6 +40,7 @@
#define GSETTING_SHOW_LOCK "showLock"
DCORE_USE_NAMESPACE
DGUI_USE_NAMESPACE
using namespace Dock;
ShutdownPlugin::ShutdownPlugin(QObject *parent)
@ -312,6 +315,32 @@ QIcon ShutdownPlugin::icon(const DockPart &dockPart)
return shutdownIcon;
}
QIcon ShutdownPlugin::icon(const DockPart &dockPart, int themeType)
{
if (dockPart == DockPart::DCCSetting) {
if (themeType == DGuiApplicationHelper::ColorType::LightType)
return QIcon(":/icons/resources/icons/dcc_shutdown.svg");
QPixmap pixmap(":/icons/resources/icons/dcc_shutdown.svg");
QPainter pa(&pixmap);
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
pa.fillRect(pixmap.rect(), Qt::white);
return pixmap;
}
QString iconName = "system-shutdown";
if (themeType == DGuiApplicationHelper::LightType)
iconName.append(PLUGIN_MIN_ICON_NAME);
const auto ratio = qApp->devicePixelRatio();
QPixmap pixmap;
pixmap = QIcon::fromTheme(iconName, QIcon::fromTheme(":/icons/resources/icons/system-shutdown.svg")).pixmap(QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE) * ratio);
pixmap.setDevicePixelRatio(ratio);
return pixmap;
}
PluginFlags ShutdownPlugin::flags() const
{
return PluginFlag::Type_System | PluginFlag::Attribute_CanSetting;

View File

@ -62,6 +62,7 @@ public:
void pluginSettingsChanged() override;
QIcon icon(const DockPart &dockPart) override;
QIcon icon(const DockPart &dockPart, int themeType) override;
PluginFlags flags() const override;
// 休眠待机配置保持和sessionshell一致

View File

@ -29,10 +29,14 @@
#include <DApplication>
#include <DDesktopServices>
#include <DGuiApplicationHelper>
#include <QPainter>
#define PLUGIN_STATE_KEY "enable"
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
using namespace Dock;
@ -190,8 +194,16 @@ void TrashPlugin::pluginSettingsChanged()
QIcon TrashPlugin::icon(const DockPart &dockPart, int themeType)
{
if (dockPart == DockPart::DCCSetting)
return QIcon(":/icons/dcc_trash.svg");
if (dockPart == DockPart::DCCSetting) {
if (themeType == DGuiApplicationHelper::ColorType::LightType)
return QIcon(":/icons/dcc_trash.svg");
QPixmap pixmap(":/icons/dcc_trash.svg");
QPainter pa(&pixmap);
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
pa.fillRect(pixmap.rect(), Qt::white);
return pixmap;
}
return QIcon();
}