fix: 修复从托盘拖动应用到任务栏上面图标显示异常的问题

将图标从托盘拖动到任务栏上面的时候,会将信息保存到DConfig配置,触发任务栏上多次添加图标的功能,引起图标重复

Log: 修复从托盘拖动应用到任务栏上图标显示异常
Influence: 将安全中心等图标从托盘拖动到任务栏,观察图标是否重复
Bug: https://pms.uniontech.com/bug-view-171493.html
Change-Id: I15b85b8192e7e7cca0f563f9ecc6381cd616f0ee
This commit is contained in:
donghualin 2022-11-16 18:21:48 +08:00
parent 9abab8ed1b
commit e98f1df2f5
5 changed files with 59 additions and 13 deletions

View File

@ -30,7 +30,6 @@
#define ICON_SIZE 16
#define ITEM_SPACING 5
struct WinInfo;
class ExpandIconWidget;
class QListView;
class PluginsItemInterface;

View File

@ -20,6 +20,9 @@
*/
#include "tray_gridview.h"
#include "settingconfig.h"
#include "expandiconwidget.h"
#include "tray_model.h"
#include "basetraywidget.h"
#include <QMouseEvent>
#include <QDragEnterEvent>
@ -33,9 +36,6 @@
#include <QDebug>
#include <QTimer>
#include "tray_model.h"
#include "basetraywidget.h"
TrayGridView::TrayGridView(QWidget *parent)
: DListView(parent)
, m_aniCurveType(QEasingCurve::Linear)
@ -516,6 +516,14 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions)
} else {
listModel->setDragKey(QString());
clearDragModelIndex();
if (listModel->isIconTray()) {
// 如果当前是从托盘移动到任务栏,则根据托盘内部是否有应用来决定是否显示展开图标
bool hasIcon = (listModel->rowCount() > 0);
TrayModel::getDockModel()->setExpandVisible(hasIcon, hasIcon);
// 如果没有图标,则隐藏托盘图标
if (!hasIcon)
ExpandIconWidget::popupTrayView()->hide();
}
m_dropPos = QPoint();
m_dragPos = QPoint();

View File

@ -148,9 +148,11 @@ void TrayModel::setExpandVisible(bool visible, bool openExpand)
if (visible) {
// 如果展开图标已经存在,则不添加,
for (const WinInfo &winInfo : m_winInfos) {
if (winInfo.type == TrayIconType::ExpandIcon)
for (WinInfo &winInfo : m_winInfos) {
if (winInfo.type == TrayIconType::ExpandIcon) {
winInfo.expand = openExpand;
return;
}
}
// 如果是任务栏图标,则添加托盘展开图标
beginInsertRows(QModelIndex(), rowCount(), rowCount());
@ -431,14 +433,24 @@ bool TrayModel::isTypeWriting(const QString &servicePath) const
void TrayModel::saveConfig(int index, const WinInfo &winInfo)
{
if (m_fixedTrayNames.contains(winInfo.itemKey))
return;
if (m_isTrayIcon) {
// 如果是从任务栏将图标移动到托盘,就从配置中移除
if (!m_fixedTrayNames.contains(winInfo.itemKey))
return;
if (index >= 0 && index < m_fixedTrayNames.size()) {
m_fixedTrayNames.insert(index, winInfo.itemKey);
m_fixedTrayNames.removeOne(winInfo.itemKey);
} else {
m_fixedTrayNames << winInfo.itemKey;
// 如果是将图标从托盘移到任务栏上面,就增加到配置中
if (m_fixedTrayNames.contains(winInfo.itemKey))
return;
if (index >= 0 && index < m_fixedTrayNames.size()) {
m_fixedTrayNames.insert(index, winInfo.itemKey);
} else {
m_fixedTrayNames << winInfo.itemKey;
}
}
SETTINGCONFIG->setValue(DOCKQUICKTRAYNAME, m_fixedTrayNames);
}
@ -538,6 +550,11 @@ void TrayModel::onSniTrayAdded(const QString &servicePath)
if (!sniCanExport(servicePath))
return;
for (const WinInfo &winInfo : m_winInfos) {
if (winInfo.servicePath == servicePath)
return;
}
bool typeWriting = isTypeWriting(servicePath);
beginInsertRows(QModelIndex(), rowCount(), rowCount());
@ -704,6 +721,13 @@ void TrayModel::onSettingChanged(const QString &key, const QVariant &value)
QStringList indicators = m_monitor->indicatorNames();
for (const QString &indicatorName : indicators) {
if (!m_indicatorMap.contains(indicatorName))
continue;
IndicatorPlugin *plugin = m_indicatorMap[indicatorName];
if (!plugin->isLoaded())
continue;
if (indicatorCanExport(indicatorName))
onIndicatorAdded(indicatorName);
else

View File

@ -169,9 +169,11 @@ void IndicatorPluginPrivate::initDBus(const QString &indicatorName)
if (data.contains("text")) {
featData("text", data, SLOT(textPropertyChanged(QDBusMessage)), [ = ](QVariant v) {
if (v.toString().isEmpty()) {
q->m_isLoaded = false;
Q_EMIT q->removed();
return;
}
q->m_isLoaded = true;
Q_EMIT q->delayLoaded();
indicatorTrayWidget->setText(v.toString());
updateContent();
@ -181,9 +183,11 @@ void IndicatorPluginPrivate::initDBus(const QString &indicatorName)
if (data.contains("icon")) {
featData("icon", data, SLOT(iconPropertyChanged(QDBusMessage)), [ = ](QVariant v) {
if (v.toByteArray().isEmpty()) {
q->m_isLoaded = false;
Q_EMIT q->removed();
return;
}
q->m_isLoaded = true;
Q_EMIT q->delayLoaded();
indicatorTrayWidget->setPixmapData(v.toByteArray());
updateContent();
@ -214,6 +218,7 @@ void IndicatorPluginPrivate::initDBus(const QString &indicatorName)
IndicatorPlugin::IndicatorPlugin(const QString &indicatorName, QObject *parent)
: QObject(parent)
, d_ptr(new IndicatorPluginPrivate(this))
, m_isLoaded(false)
{
Q_D(IndicatorPlugin);
@ -244,12 +249,18 @@ void IndicatorPlugin::removeWidget()
d->indicatorTrayWidget = nullptr;
}
bool IndicatorPlugin::isLoaded()
{
return m_isLoaded;
}
void IndicatorPlugin::textPropertyChanged(const QDBusMessage &message)
{
Q_D(IndicatorPlugin);
d->propertyChanged("text", message, [=] (const QVariant &value) {
d->propertyChanged("text", message, [ = ] (const QVariant &value) {
if (value.toString().isEmpty()) {
m_isLoaded = false;
Q_EMIT removed();
return;
}
@ -266,8 +277,9 @@ void IndicatorPlugin::iconPropertyChanged(const QDBusMessage &message)
{
Q_D(IndicatorPlugin);
d->propertyChanged("icon", message, [=] (const QVariant &value) {
d->propertyChanged("icon", message, [ = ] (const QVariant &value) {
if (value.toByteArray().isEmpty()) {
m_isLoaded = false;
Q_EMIT removed();
return;
}

View File

@ -37,6 +37,8 @@ public:
void removeWidget();
bool isLoaded();
signals:
void delayLoaded();
void removed();
@ -47,5 +49,6 @@ private slots:
private:
QScopedPointer<IndicatorPluginPrivate> d_ptr;
bool m_isLoaded;
Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), IndicatorPlugin)
};