fix: 修复拖拽托盘窗口图标至任务栏托盘区域经常失败的问题。

修复拖拽托盘窗口图标至任务栏托盘区域经常失败的问题。原因:现有实现只在任务栏托盘一小块区域实现,导致拖拽经常不能被捕获,已修改为托盘父窗口区域捕获传递给任务栏托盘区域处理,实现每次拖拽都能捕获。

Log: 修复拖拽托盘窗口图标至任务栏托盘区域经常失败的问题。
Bug: https://pms.uniontech.com/bug-view-147789.html
Influence: 拖拽托盘窗口图标至任务栏托盘区域。
Change-Id: I310916160fe1dc0e05b134a45a018c81766fe8cf
This commit is contained in:
zyz 2022-07-15 18:14:29 +08:00 committed by zhaoyingzhen
parent 16cb904058
commit 7502b87e06
3 changed files with 25 additions and 8 deletions

View File

@ -365,7 +365,7 @@ const QModelIndex TrayGridView::getIndexFromPos(QPoint currentPoint) const
return QModelIndex(); return QModelIndex();
} }
void TrayGridView::dropEvent(QDropEvent *e) void TrayGridView::handleDropEvent(QDropEvent *e)
{ {
setState(DListView::NoState); setState(DListView::NoState);
clearDragModelIndex(); clearDragModelIndex();
@ -437,6 +437,10 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions)
drag->setPixmap(pixmap); drag->setPixmap(pixmap);
drag->setHotSpot(pixmap.rect().center() / ratio); drag->setHotSpot(pixmap.rect().center() / ratio);
QMimeData *data = model()->mimeData(QModelIndexList() << modelIndex); QMimeData *data = model()->mimeData(QModelIndexList() << modelIndex);
if (!data) {
return false;
}
data->setImageData(pixmap); data->setImageData(pixmap);
drag->setMimeData(data); drag->setMimeData(data);
@ -513,3 +517,8 @@ void TrayGridView::initUi()
connect(m_aniStartTime, &QTimer::timeout, this, &TrayGridView::moveAnimation); connect(m_aniStartTime, &QTimer::timeout, this, &TrayGridView::moveAnimation);
} }
void TrayGridView::dropEvent(QDropEvent *e)
{
handleDropEvent(e);
}

View File

@ -46,6 +46,8 @@ public:
const QRect indexRect(const QModelIndex &index) const; const QRect indexRect(const QModelIndex &index) const;
void dropSwap(); void dropSwap();
void handleDropEvent(QDropEvent *e);
Q_SIGNALS: Q_SIGNALS:
void requestRemove(const QString &); void requestRemove(const QString &);
void dragLeaved(); void dragLeaved();

View File

@ -445,16 +445,22 @@ void TrayManagerWindow::dragMoveEvent(QDragMoveEvent *e)
void TrayManagerWindow::dropEvent(QDropEvent *e) void TrayManagerWindow::dropEvent(QDropEvent *e)
{ {
const QuickPluginMimeData *mimeData = qobject_cast<const QuickPluginMimeData *>(e->mimeData()); if (!e || !e->mimeData() || e->source() == this)
if (!mimeData)
return; return;
if (e->source() == this) if (qobject_cast<QuickPluginWindow *>(e->source())) {
return; const QuickPluginMimeData *mimeData = qobject_cast<const QuickPluginMimeData *>(e->mimeData());
if (!mimeData)
return;
PluginsItemInterface *pluginItem = static_cast<PluginsItemInterface *>(mimeData->pluginItemInterface()); PluginsItemInterface *pluginItem = static_cast<PluginsItemInterface *>(mimeData->pluginItemInterface());
if (pluginItem) if (pluginItem)
m_quickIconWidget->dragPlugin(pluginItem); m_quickIconWidget->dragPlugin(pluginItem);
} else if (qobject_cast<TrayGridView *>(e->source())) {
// 将trayView中的dropEvent扩大到整个区域this这样便于随意拖动到这个区域都可以捕获。
// m_trayView中有e->accept不会导致事件重复处理。
m_trayView->handleDropEvent(e);
}
} }
void TrayManagerWindow::dragLeaveEvent(QDragLeaveEvent *event) void TrayManagerWindow::dragLeaveEvent(QDragLeaveEvent *event)