diff --git a/frame/window/tray/tray_gridview.cpp b/frame/window/tray/tray_gridview.cpp index 8bdfc3ff4..3f51f99cf 100644 --- a/frame/window/tray/tray_gridview.cpp +++ b/frame/window/tray/tray_gridview.cpp @@ -365,7 +365,7 @@ const QModelIndex TrayGridView::getIndexFromPos(QPoint currentPoint) const return QModelIndex(); } -void TrayGridView::dropEvent(QDropEvent *e) +void TrayGridView::handleDropEvent(QDropEvent *e) { setState(DListView::NoState); clearDragModelIndex(); @@ -437,6 +437,10 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions) drag->setPixmap(pixmap); drag->setHotSpot(pixmap.rect().center() / ratio); QMimeData *data = model()->mimeData(QModelIndexList() << modelIndex); + if (!data) { + return false; + } + data->setImageData(pixmap); drag->setMimeData(data); @@ -513,3 +517,8 @@ void TrayGridView::initUi() connect(m_aniStartTime, &QTimer::timeout, this, &TrayGridView::moveAnimation); } + +void TrayGridView::dropEvent(QDropEvent *e) +{ + handleDropEvent(e); +} diff --git a/frame/window/tray/tray_gridview.h b/frame/window/tray/tray_gridview.h index 7ae02602b..e06cb0f30 100644 --- a/frame/window/tray/tray_gridview.h +++ b/frame/window/tray/tray_gridview.h @@ -46,6 +46,8 @@ public: const QRect indexRect(const QModelIndex &index) const; void dropSwap(); + void handleDropEvent(QDropEvent *e); + Q_SIGNALS: void requestRemove(const QString &); void dragLeaved(); diff --git a/frame/window/traymanagerwindow.cpp b/frame/window/traymanagerwindow.cpp index 74753e397..50b03cc68 100644 --- a/frame/window/traymanagerwindow.cpp +++ b/frame/window/traymanagerwindow.cpp @@ -445,16 +445,22 @@ void TrayManagerWindow::dragMoveEvent(QDragMoveEvent *e) void TrayManagerWindow::dropEvent(QDropEvent *e) { - const QuickPluginMimeData *mimeData = qobject_cast(e->mimeData()); - if (!mimeData) + if (!e || !e->mimeData() || e->source() == this) return; - if (e->source() == this) - return; + if (qobject_cast(e->source())) { + const QuickPluginMimeData *mimeData = qobject_cast(e->mimeData()); + if (!mimeData) + return; - PluginsItemInterface *pluginItem = static_cast(mimeData->pluginItemInterface()); - if (pluginItem) - m_quickIconWidget->dragPlugin(pluginItem); + PluginsItemInterface *pluginItem = static_cast(mimeData->pluginItemInterface()); + if (pluginItem) + m_quickIconWidget->dragPlugin(pluginItem); + } else if (qobject_cast(e->source())) { + // 将trayView中的dropEvent扩大到整个区域(this),这样便于随意拖动到这个区域都可以捕获。 + // m_trayView中有e->accept不会导致事件重复处理。 + m_trayView->handleDropEvent(e); + } } void TrayManagerWindow::dragLeaveEvent(QDragLeaveEvent *event)