diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 5252e66ac..1009dd3c9 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -359,13 +359,14 @@ void AppItem::resizeEvent(QResizeEvent *e) void AppItem::dragEnterEvent(QDragEnterEvent *e) { // ignore drag from panel - if (e->source()) - return; + if (e->source()) { + return e->ignore(); + } // ignore request dock event QString draggingMimeKey = e->mimeData()->formats().contains("RequestDock") ? "RequestDock" : "text/plain"; if (QMimeDatabase().mimeTypeForFile(e->mimeData()->data(draggingMimeKey)).name() == "application/x-desktop") { - return; + return e->ignore(); } e->accept(); diff --git a/frame/panel/mainpanel.cpp b/frame/panel/mainpanel.cpp index 4c223f56e..295da3257 100644 --- a/frame/panel/mainpanel.cpp +++ b/frame/panel/mainpanel.cpp @@ -29,6 +29,8 @@ #include #include +#include + static DockItem *DraggingItem = nullptr; static PlaceholderItem *RequestDockItem = nullptr; @@ -44,6 +46,7 @@ MainPanel::MainPanel(QWidget *parent) m_itemLayout(new QBoxLayout(QBoxLayout::LeftToRight)), m_showDesktopItem(new ShowDesktopItem(this)), m_itemAdjustTimer(new QTimer(this)), + m_checkMouseLeaveTimer(new QTimer(this)), m_itemController(DockItemController::instance(this)), m_appDragWidget(nullptr) { @@ -57,6 +60,7 @@ MainPanel::MainPanel(QWidget *parent) setAcceptDrops(true); setAccessibleName("dock-mainpanel"); setObjectName("MainPanel"); + setMouseTracking(true); QFile qssFile(":/qss/frame.qss"); @@ -72,11 +76,15 @@ MainPanel::MainPanel(QWidget *parent) connect(m_itemController, &DockItemController::itemManaged, this, &MainPanel::manageItem); connect(m_itemController, &DockItemController::itemUpdated, m_itemAdjustTimer, static_cast(&QTimer::start)); connect(m_itemAdjustTimer, &QTimer::timeout, this, &MainPanel::adjustItemSize, Qt::QueuedConnection); + connect(m_checkMouseLeaveTimer, &QTimer::timeout, this, &MainPanel::checkMouseReallyLeave, Qt::QueuedConnection); connect(&DockSettings::Instance(), &DockSettings::opacityChanged, this, &MainPanel::setMaskAlpha); m_itemAdjustTimer->setSingleShot(true); m_itemAdjustTimer->setInterval(100); + m_checkMouseLeaveTimer->setSingleShot(true); + m_checkMouseLeaveTimer->setInterval(300); + const auto &itemList = m_itemController->itemList(); for (auto item : itemList) { @@ -210,6 +218,12 @@ void MainPanel::resizeEvent(QResizeEvent *e) void MainPanel::dragEnterEvent(QDragEnterEvent *e) { + // 不知道为什么有可能会收不到dragLeaveEvent,因此使用timer来检测鼠标是否已经离开dock + m_checkMouseLeaveTimer->start(); + + // call dragEnterEvent of MainWindow to show dock when dock is hidden + static_cast(window())->dragEnterEvent(e); + DockItem *item = itemAt(e->pos()); if (item && item->itemType() == DockItem::Container) return; @@ -273,8 +287,6 @@ void MainPanel::dragLeaveEvent(QDragLeaveEvent *e) void MainPanel::dropEvent(QDropEvent *e) { - Q_UNUSED(e) - DraggingItem = nullptr; if (RequestDockItem) @@ -666,3 +678,14 @@ void MainPanel::handleDragMove(QDragMoveEvent *e, bool isFilter) } } } + +void MainPanel::checkMouseReallyLeave() +{ + if (window()->geometry().contains(QCursor::pos())) { + return m_checkMouseLeaveTimer->start(); + } + + m_checkMouseLeaveTimer->stop(); + + dragLeaveEvent(new QDragLeaveEvent); +} diff --git a/frame/panel/mainpanel.h b/frame/panel/mainpanel.h index d5cdf0662..2d00c9afb 100644 --- a/frame/panel/mainpanel.h +++ b/frame/panel/mainpanel.h @@ -86,6 +86,7 @@ private slots: void itemDragStarted(); void itemDropped(QObject *destnation); void handleDragMove(QDragMoveEvent *e, bool isFilter); + void checkMouseReallyLeave(); private: Position m_position; @@ -94,6 +95,7 @@ private: ShowDesktopItem *m_showDesktopItem; QTimer *m_itemAdjustTimer; + QTimer *m_checkMouseLeaveTimer; DockItemController *m_itemController; QWidget *m_appDragWidget; diff --git a/frame/window/mainwindow.cpp b/frame/window/mainwindow.cpp index b8760345b..7579d0b60 100644 --- a/frame/window/mainwindow.cpp +++ b/frame/window/mainwindow.cpp @@ -211,8 +211,9 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *e) { QWidget::dragEnterEvent(e); - if (m_settings->hideState() != Show) + if (m_settings->hideState() != Show) { m_expandDelayTimer->start(); + } } void MainWindow::setFixedSize(const QSize &size) diff --git a/frame/window/mainwindow.h b/frame/window/mainwindow.h index 35fce7aaa..f8622a64e 100644 --- a/frame/window/mainwindow.h +++ b/frame/window/mainwindow.h @@ -44,6 +44,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + friend class MainPanel; + public slots: void launch();