From 73f430837152d6e4e1c9148a7dd865f88caa26d2 Mon Sep 17 00:00:00 2001 From: yanghongwei Date: Tue, 18 May 2021 20:49:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E6=8F=92=E4=BB=B6=E5=9B=BE=E6=A0=87=E6=8B=96=E5=8A=A8?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E5=9E=83=E5=9C=BE=E7=AE=B1=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=97=81=E8=BE=B9=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在拖动插件往垃圾箱左右放置时,无法放置 Log: 修复任务栏插件图标拖动插入垃圾箱插件旁边异常 Task: https://pms.uniontech.com/zentao/task-view-76877.html Change-Id: I3af3bf5a8999e6886b56c275392b5952109db15a --- frame/window/mainpanelcontrol.cpp | 24 ++++++++++++++++++++++++ frame/window/mainpanelcontrol.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/frame/window/mainpanelcontrol.cpp b/frame/window/mainpanelcontrol.cpp index a36fcad0d..dbb1e720d 100755 --- a/frame/window/mainpanelcontrol.cpp +++ b/frame/window/mainpanelcontrol.cpp @@ -70,6 +70,7 @@ MainPanelControl::MainPanelControl(QWidget *parent) , m_dislayMode(Efficient) , m_isHover(false) , m_needRecoveryWin(false) + , m_trashItem(nullptr) { initUi(); updateMainPanelLayout(); @@ -226,6 +227,11 @@ void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg) QBoxLayout * boxLayout = new QBoxLayout(QBoxLayout::LeftToRight); boxLayout->addWidget(wdg, 0, Qt::AlignCenter); m_pluginLayout->insertLayout(index, boxLayout, 0); + + // 保存垃圾箱插件指针 + PluginsItem *pluginsItem = qobject_cast(wdg); + if (pluginsItem && pluginsItem->pluginName() == "trash") + m_trashItem = pluginsItem; } void MainPanelControl::removeFixedAreaItem(QWidget *wdg) @@ -247,6 +253,11 @@ void MainPanelControl::removePluginAreaItem(QWidget *wdg) { //因为日期时间插件大小和其他插件有异,为了方便设置边距,各插件中增加一层布局 //因此remove插件图标时,需要从多的一层布局中取widget进行判断是否需要移除的插件 + // 清空保存的垃圾箱插件指针 + PluginsItem *pluginsItem = qobject_cast(wdg); + if (pluginsItem && pluginsItem->pluginName() == "trash") + m_trashItem = nullptr; + for (int i = 0; i < m_pluginLayout->count(); ++i) { QLayoutItem *layoutItem = m_pluginLayout->itemAt(i); QLayout *boxLayout = layoutItem->layout(); @@ -709,6 +720,15 @@ void MainPanelControl::startDrag(DockItem *dockItem) drag->setPixmap(pixmap); drag->setHotSpot(pixmap.rect().center() / pixmap.devicePixelRatioF()); } + + // isNeedBack 保存是否需要重置垃圾箱的AcceptDrops + // 设置垃圾箱插件AcceptDrops false + bool isNeedBack = false; + if (item->itemType() == DockItem::Plugins && m_trashItem && dockItem != m_trashItem) { + m_trashItem->centralWidget()->setAcceptDrops(false); + isNeedBack = true; + } + drag->setMimeData(new QMimeData); drag->exec(Qt::MoveAction); @@ -716,6 +736,10 @@ void MainPanelControl::startDrag(DockItem *dockItem) m_appDragWidget = nullptr; item->setDraging(false); item->update(); + + // isNeedBack是否需要设置垃圾箱插件AcceptDrops true + if (isNeedBack) + m_trashItem->centralWidget()->setAcceptDrops(true); } } diff --git a/frame/window/mainpanelcontrol.h b/frame/window/mainpanelcontrol.h index dff1ca2da..83baa975f 100755 --- a/frame/window/mainpanelcontrol.h +++ b/frame/window/mainpanelcontrol.h @@ -134,6 +134,8 @@ private: bool m_isHover; // 判断鼠标是否移到desktop区域 bool m_needRecoveryWin; // 判断鼠标移出desktop区域是否恢复之前窗口 int m_dragIndex = -1; // 记录应用区域被拖拽图标的位置 + + PluginsItem *m_trashItem; // 垃圾箱插件(需要特殊处理一下) }; #endif // MAINPANELCONTROL_H