Skip to content

Commit

Permalink
fix: place holder item still display in dock after drag leave
Browse files Browse the repository at this point in the history
Change-Id: Ibc21b1f984a4ecc1bff466012c2afe05c5df1285
  • Loading branch information
listenerri committed Nov 5, 2018
1 parent f0927a1 commit 725891a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
7 changes: 4 additions & 3 deletions frame/item/appitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 25 additions & 2 deletions frame/panel/mainpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <QScreen>
#include <QGraphicsView>

#include <window/mainwindow.h>

static DockItem *DraggingItem = nullptr;
static PlaceholderItem *RequestDockItem = nullptr;

Expand All @@ -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)
{
Expand All @@ -57,6 +60,7 @@ MainPanel::MainPanel(QWidget *parent)
setAcceptDrops(true);
setAccessibleName("dock-mainpanel");
setObjectName("MainPanel");
setMouseTracking(true);

QFile qssFile(":/qss/frame.qss");

Expand All @@ -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<void (QTimer::*)()>(&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)
{
Expand Down Expand Up @@ -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<MainWindow *>(window())->dragEnterEvent(e);

DockItem *item = itemAt(e->pos());
if (item && item->itemType() == DockItem::Container)
return;
Expand Down Expand Up @@ -273,8 +287,6 @@ void MainPanel::dragLeaveEvent(QDragLeaveEvent *e)

void MainPanel::dropEvent(QDropEvent *e)
{
Q_UNUSED(e)

DraggingItem = nullptr;

if (RequestDockItem)
Expand Down Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions frame/panel/mainpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private slots:
void itemDragStarted();
void itemDropped(QObject *destnation);
void handleDragMove(QDragMoveEvent *e, bool isFilter);
void checkMouseReallyLeave();

private:
Position m_position;
Expand All @@ -94,6 +95,7 @@ private slots:
ShowDesktopItem *m_showDesktopItem;

QTimer *m_itemAdjustTimer;
QTimer *m_checkMouseLeaveTimer;
DockItemController *m_itemController;

QWidget *m_appDragWidget;
Expand Down
3 changes: 2 additions & 1 deletion frame/window/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions frame/window/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class MainWindow : public QWidget
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

friend class MainPanel;

public slots:
void launch();

Expand Down

0 comments on commit 725891a

Please sign in to comment.