dde-dock/plugins/pluginmanager/quicksettingitem.cpp
donghualin 1be68d06b2 fix: 修复移除蓝牙设备后任务栏插件不消失的问题
1、任务栏插件显示区域移除对配置变化的响应,该功能已经在DockPluginController中实现
2、在配置变化的时候,判断插件是否可以加载的条件增加了判断该插件是否被加载
3、修复拖动快捷面板的问题

Log: 修复移除蓝牙设备后任务栏插件不消失的问题
Influence: 插上蓝牙,从控制中心勾选该插件,在任务栏显示,然后移除蓝牙设备,观察任务栏的蓝牙图标是否消失
Bug: https://pms.uniontech.com/bug-view-181945.html
Change-Id: Ib207f4f0e2ceeb4b100c57b1f3e3899a802b8ed7
2023-01-16 17:08:59 +08:00

129 lines
3.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
*
* Author: donghualin <donghualin@uniontech.com>
*
* Maintainer: donghualin <donghualin@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quicksettingitem.h"
#include "pluginsiteminterface.h"
#include "imageutil.h"
#include "largerquickitem.h"
#include "standardquickitem.h"
#include "linequickitem.h"
#include <DGuiApplicationHelper>
#include <DFontSizeManager>
#include <DPaletteHelper>
#include <QIcon>
#include <QPainterPath>
#include <QPushButton>
#include <QFontMetrics>
#include <QPainter>
#define ICONWIDTH 24
#define ICONHEIGHT 24
#define ICONSPACE 10
#define RADIUS 8
#define FONTSIZE 10
#define BGWIDTH 128
#define BGSIZE 36
#define MARGINLEFTSPACE 10
#define OPENICONSIZE 12
#define MARGINRIGHTSPACE 9
DWIDGET_USE_NAMESPACE
QuickSettingItem::QuickSettingItem(PluginsItemInterface *const pluginInter, const QString &itemKey, QWidget *parent)
: QWidget(parent)
, m_pluginInter(pluginInter)
, m_itemKey(itemKey)
{
setAcceptDrops(true);
this->installEventFilter(this);
}
QuickSettingItem::~QuickSettingItem()
{
}
PluginsItemInterface *QuickSettingItem::pluginItem() const
{
return m_pluginInter;
}
const QPixmap QuickSettingItem::dragPixmap()
{
return grab();
}
const QString QuickSettingItem::itemKey() const
{
return m_itemKey;
}
void QuickSettingItem::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter painter(this);
painter.setRenderHint(QPainter::RenderHint::Antialiasing);
painter.setPen(foregroundColor());
QPainterPath path;
path.addRoundedRect(rect(), RADIUS, RADIUS);
painter.setClipPath(path);
// 绘制背景色
QColor backColor(Qt::white);
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::ColorType::DarkType) {
backColor = Qt::black;
backColor.setAlphaF(0.5);
}
DPalette dpa = DPaletteHelper::instance()->palette(this);
painter.fillRect(rect(), backColor);
}
QColor QuickSettingItem::foregroundColor() const
{
DPalette dpa = DPaletteHelper::instance()->palette(this);
// TODO: 此处的颜色是临时获取的,后期需要和设计师确认,改成正规的颜色
if (m_pluginInter->status() == PluginsItemInterface::PluginMode::Active)
return dpa.color(DPalette::ColorGroup::Active, DPalette::ColorRole::Text);
if (m_pluginInter->status() == PluginsItemInterface::PluginMode::Deactive)
return dpa.color(DPalette::ColorGroup::Disabled, DPalette::ColorRole::Text);
return dpa.color(DPalette::ColorGroup::Normal, DPalette::ColorRole::Text);
}
QuickSettingItem *QuickSettingFactory::createQuickWidget(PluginsItemInterface * const pluginInter, const QString &itemKey)
{
// 如果显示在面板的图标或者Widget为空则不让显示(例如电池插件)
if (!(pluginInter->flags() & PluginFlag::Type_Common))
return nullptr;
if (pluginInter->flags() & PluginFlag::Quick_Multi)
return new LargerQuickItem(pluginInter, itemKey);
if (pluginInter->flags() & PluginFlag::Quick_Full)
return new LineQuickItem(pluginInter, itemKey);
if (pluginInter->flags() & PluginFlag::Quick_Single)
return new StandardQuickItem(pluginInter, itemKey);
return nullptr;
}