mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix: 插件适配不同主题图标
实现根据主题返回不同图标的接口 Log: Influence: 切换主题,观察任务栏的图标和控制中心个性化中的图标是否发生了变化 Task: https://pms.uniontech.com/task-view-222025.html Change-Id: Ib5420a963da4d5f6b4ed7c3e4927890bd80118e4
This commit is contained in:
parent
40d13df340
commit
7b11668d04
@ -25,11 +25,16 @@
|
|||||||
#include "org_deepin_dde_daemon_dock.h"
|
#include "org_deepin_dde_daemon_dock.h"
|
||||||
#include "org_deepin_dde_daemon_dock_entry.h"
|
#include "org_deepin_dde_daemon_dock_entry.h"
|
||||||
|
|
||||||
|
#include <DGuiApplicationHelper>
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#define PLUGIN_STATE_KEY "enable"
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
|
|
||||||
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
using DBusDock = org::deepin::dde::daemon::Dock1;
|
using DBusDock = org::deepin::dde::daemon::Dock1;
|
||||||
using DockEntryInter = org::deepin::dde::daemon::dock1::Entry;
|
using DockEntryInter = org::deepin::dde::daemon::dock1::Entry;
|
||||||
|
|
||||||
@ -165,10 +170,18 @@ void OnboardPlugin::pluginSettingsChanged()
|
|||||||
refreshPluginItemsVisible();
|
refreshPluginItemsVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon OnboardPlugin::icon(const DockPart &dockPart)
|
QIcon OnboardPlugin::icon(const DockPart &dockPart, int themeType)
|
||||||
{
|
{
|
||||||
if (dockPart == DockPart::DCCSetting)
|
if (dockPart == DockPart::DCCSetting) {
|
||||||
return QIcon(":/icons/icon/dcc_keyboard.svg");
|
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)
|
if (dockPart == DockPart::QuickPanel)
|
||||||
return m_onboardItem->iconPixmap(24);
|
return m_onboardItem->iconPixmap(24);
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
void setSortKey(const QString &itemKey, const int order) override;
|
void setSortKey(const QString &itemKey, const int order) override;
|
||||||
|
|
||||||
void pluginSettingsChanged() override;
|
void pluginSettingsChanged() override;
|
||||||
QIcon icon(const DockPart &dockPart) override;
|
QIcon icon(const DockPart &dockPart, int themeType) override;
|
||||||
PluginStatus status() const override;
|
PluginStatus status() const override;
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
|
|
||||||
|
@ -174,14 +174,11 @@ void PowerPlugin::pluginSettingsChanged()
|
|||||||
refreshPluginItemsVisible();
|
refreshPluginItemsVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon PowerPlugin::icon(const DockPart &dockPart)
|
QIcon PowerPlugin::icon(const DockPart &dockPart, int themeType)
|
||||||
{
|
{
|
||||||
// 电池插件不显示在快捷面板上,因此此处返回空图标
|
// 电池插件不显示在快捷面板上,因此此处返回空图标
|
||||||
if (dockPart == DockPart::QuickPanel)
|
|
||||||
return QIcon();
|
|
||||||
|
|
||||||
static QIcon batteryIcon;
|
static QIcon batteryIcon;
|
||||||
const QPixmap pixmap = m_powerStatusWidget->getBatteryIcon();
|
const QPixmap pixmap = m_powerStatusWidget->getBatteryIcon(themeType);
|
||||||
batteryIcon.detach();
|
batteryIcon.detach();
|
||||||
batteryIcon.addPixmap(pixmap);
|
batteryIcon.addPixmap(pixmap);
|
||||||
return batteryIcon;
|
return batteryIcon;
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
int itemSortKey(const QString &itemKey) override;
|
int itemSortKey(const QString &itemKey) override;
|
||||||
void setSortKey(const QString &itemKey, const int order) override;
|
void setSortKey(const QString &itemKey, const int order) override;
|
||||||
void pluginSettingsChanged() override;
|
void pluginSettingsChanged() override;
|
||||||
QIcon icon(const DockPart &dockPart) override;
|
QIcon icon(const DockPart &dockPart, int themeType) override;
|
||||||
PluginFlags flags() const override;
|
PluginFlags flags() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -54,7 +54,10 @@ void PowerStatusWidget::paintEvent(QPaintEvent *e)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(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();
|
const auto ratio = devicePixelRatioF();
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
@ -63,7 +66,7 @@ void PowerStatusWidget::paintEvent(QPaintEvent *e)
|
|||||||
painter.drawPixmap(rf.center() - rfp.center() / ratio, icon);
|
painter.drawPixmap(rf.center() - rfp.center() / ratio, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap PowerStatusWidget::getBatteryIcon()
|
QPixmap PowerStatusWidget::getBatteryIcon(int themeType)
|
||||||
{
|
{
|
||||||
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
|
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
|
||||||
const uint value = uint(qMin(100.0, qMax(0.0, data.value("Display"))));
|
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");
|
.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);
|
iconStr.append(PLUGIN_MIN_ICON_NAME);
|
||||||
|
|
||||||
const auto ratio = devicePixelRatioF();
|
const auto ratio = devicePixelRatioF();
|
||||||
|
@ -24,8 +24,12 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <DGuiApplicationHelper>
|
||||||
|
|
||||||
#define POWER_KEY "power"
|
#define POWER_KEY "power"
|
||||||
|
|
||||||
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
class DBusPower;
|
class DBusPower;
|
||||||
|
|
||||||
// from https://upower.freedesktop.org/docs/Device.html#Device:State
|
// from https://upower.freedesktop.org/docs/Device.html#Device:State
|
||||||
@ -43,7 +47,7 @@ class PowerStatusWidget : public QWidget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PowerStatusWidget(QWidget *parent = 0);
|
explicit PowerStatusWidget(QWidget *parent = 0);
|
||||||
QPixmap getBatteryIcon();
|
QPixmap getBatteryIcon(int themeType);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void refreshIcon();
|
void refreshIcon();
|
||||||
|
@ -27,9 +27,11 @@
|
|||||||
|
|
||||||
#include <DSysInfo>
|
#include <DSysInfo>
|
||||||
#include <DDBusSender>
|
#include <DDBusSender>
|
||||||
|
#include <DGuiApplicationHelper>
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#define PLUGIN_STATE_KEY "enable"
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
#define GSETTING_SHOW_SUSPEND "showSuspend"
|
#define GSETTING_SHOW_SUSPEND "showSuspend"
|
||||||
@ -38,6 +40,7 @@
|
|||||||
#define GSETTING_SHOW_LOCK "showLock"
|
#define GSETTING_SHOW_LOCK "showLock"
|
||||||
|
|
||||||
DCORE_USE_NAMESPACE
|
DCORE_USE_NAMESPACE
|
||||||
|
DGUI_USE_NAMESPACE
|
||||||
using namespace Dock;
|
using namespace Dock;
|
||||||
|
|
||||||
ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
||||||
@ -312,6 +315,32 @@ QIcon ShutdownPlugin::icon(const DockPart &dockPart)
|
|||||||
return shutdownIcon;
|
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
|
PluginFlags ShutdownPlugin::flags() const
|
||||||
{
|
{
|
||||||
return PluginFlag::Type_System | PluginFlag::Attribute_CanSetting;
|
return PluginFlag::Type_System | PluginFlag::Attribute_CanSetting;
|
||||||
|
@ -62,6 +62,7 @@ public:
|
|||||||
|
|
||||||
void pluginSettingsChanged() override;
|
void pluginSettingsChanged() override;
|
||||||
QIcon icon(const DockPart &dockPart) override;
|
QIcon icon(const DockPart &dockPart) override;
|
||||||
|
QIcon icon(const DockPart &dockPart, int themeType) override;
|
||||||
PluginFlags flags() const override;
|
PluginFlags flags() const override;
|
||||||
|
|
||||||
// 休眠待机配置,保持和sessionshell一致
|
// 休眠待机配置,保持和sessionshell一致
|
||||||
|
@ -29,10 +29,14 @@
|
|||||||
|
|
||||||
#include <DApplication>
|
#include <DApplication>
|
||||||
#include <DDesktopServices>
|
#include <DDesktopServices>
|
||||||
|
#include <DGuiApplicationHelper>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#define PLUGIN_STATE_KEY "enable"
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
using namespace Dock;
|
using namespace Dock;
|
||||||
|
|
||||||
@ -190,8 +194,16 @@ void TrashPlugin::pluginSettingsChanged()
|
|||||||
|
|
||||||
QIcon TrashPlugin::icon(const DockPart &dockPart, int themeType)
|
QIcon TrashPlugin::icon(const DockPart &dockPart, int themeType)
|
||||||
{
|
{
|
||||||
if (dockPart == DockPart::DCCSetting)
|
if (dockPart == DockPart::DCCSetting) {
|
||||||
return QIcon(":/icons/dcc_trash.svg");
|
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();
|
return QIcon();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user