From d5e586fc9884de5771fca4255498da3ebfc90847 Mon Sep 17 00:00:00 2001 From: justforlxz Date: Tue, 23 Apr 2019 18:17:07 +0800 Subject: [PATCH] fix: quick click on the preview window will crash --- frame/item/components/appsnapshot.cpp | 11 +++------- frame/item/components/appsnapshot.h | 1 + frame/item/components/previewcontainer.cpp | 24 ++++++++++++++++------ frame/item/components/previewcontainer.h | 3 +++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 18f6e215d..b64181e4b 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -66,9 +66,6 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) m_closeBtn2D->setVisible(false); m_title->setObjectName("AppSnapshotTitle"); - m_waitLeaveTimer->setInterval(200); - m_waitLeaveTimer->setSingleShot(true); - QHBoxLayout *centralLayout = new QHBoxLayout; centralLayout->addWidget(m_title); centralLayout->addWidget(m_closeBtn2D); @@ -83,9 +80,6 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) connect(m_closeBtn2D, &DImageButton::clicked, this, &AppSnapshot::closeWindow, Qt::QueuedConnection); connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &AppSnapshot::compositeChanged, Qt::QueuedConnection); - connect(m_waitLeaveTimer, &QTimer::timeout, this, [=] { - emit entered(wid); - }); QTimer::singleShot(1, this, &AppSnapshot::compositeChanged); } @@ -208,7 +202,7 @@ void AppSnapshot::enterEvent(QEvent *e) m_closeBtn2D->setVisible(true); } else { - m_waitLeaveTimer->start(); + emit entered(wid()); } update(); @@ -219,7 +213,8 @@ void AppSnapshot::leaveEvent(QEvent *e) QWidget::leaveEvent(e); m_closeBtn2D->setVisible(false); - m_waitLeaveTimer->stop(); + + emit leaved(wid()); update(); } diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index 52bfcea7d..77cb870c8 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -58,6 +58,7 @@ public: signals: void entered(const WId wid) const; + void leaved(const WId wid) const; void clicked(const WId wid) const; void requestCheckWindow() const; diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 4e38f60b2..db87ea896 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -47,12 +47,17 @@ PreviewContainer::PreviewContainer(QWidget *parent) m_floatingPreview->setVisible(false); + m_waitForShowPreviewTimer = new QTimer(this); + m_waitForShowPreviewTimer->setSingleShot(true); + m_waitForShowPreviewTimer->setInterval(200); + setAcceptDrops(true); setLayout(m_windowListLayout); setFixedSize(SNAP_WIDTH, SNAP_HEIGHT); connect(m_mouseLeaveTimer, &QTimer::timeout, this, &PreviewContainer::checkMouseLeave, Qt::QueuedConnection); connect(m_floatingPreview, &FloatingPreview::requestMove, this, &PreviewContainer::moveFloatingPreview); + connect(m_waitForShowPreviewTimer, &QTimer::timeout, this, &PreviewContainer::previewFloating); } void PreviewContainer::setWindowInfos(const WindowInfoMap &infos, const WindowList &allowClose) @@ -164,6 +169,7 @@ void PreviewContainer::appendSnapWidget(const WId wid) connect(snap, &AppSnapshot::clicked, this, &PreviewContainer::onSnapshotClicked, Qt::QueuedConnection); connect(snap, &AppSnapshot::entered, this, &PreviewContainer::previewEntered, Qt::QueuedConnection); connect(snap, &AppSnapshot::requestCheckWindow, this, &PreviewContainer::requestCheckWindows); + connect(snap, &AppSnapshot::leaved, m_waitForShowPreviewTimer, &QTimer::stop); m_windowListLayout->addWidget(snap); @@ -187,6 +193,7 @@ void PreviewContainer::leaveEvent(QEvent *e) QWidget::leaveEvent(e); m_mouseLeaveTimer->start(); + m_waitForShowPreviewTimer->stop(); } void PreviewContainer::dragEnterEvent(QDragEnterEvent *e) @@ -233,13 +240,10 @@ void PreviewContainer::previewEntered(const WId wid) preSnap->setContentsMargins(0, 0, 0, 0); } - QTimer::singleShot(0, [=] { - m_floatingPreview->trackWindow(snap); - m_floatingPreview->setVisible(true); - m_floatingPreview->raise(); - }); + m_currentWId = wid; - emit requestPreviewWindow(wid); + m_floatingPreview->trackWindow(snap); + m_waitForShowPreviewTimer->start(); } void PreviewContainer::moveFloatingPreview(const QPoint &p) @@ -264,3 +268,11 @@ void PreviewContainer::moveFloatingPreview(const QPoint &p) m_floatingPreview->move(p); } } + +void PreviewContainer::previewFloating() +{ + m_floatingPreview->setVisible(true); + m_floatingPreview->raise(); + + emit requestPreviewWindow(m_currentWId); +} diff --git a/frame/item/components/previewcontainer.h b/frame/item/components/previewcontainer.h index b30726753..2369c488f 100644 --- a/frame/item/components/previewcontainer.h +++ b/frame/item/components/previewcontainer.h @@ -72,6 +72,7 @@ private slots: void onSnapshotClicked(const WId wid); void previewEntered(const WId wid); void moveFloatingPreview(const QPoint &p); + void previewFloating(); private: bool m_needActivate; @@ -82,6 +83,8 @@ private: QTimer *m_mouseLeaveTimer; DWindowManagerHelper *m_wmHelper; + QTimer *m_waitForShowPreviewTimer; + WId m_currentWId; }; #endif // PREVIEWCONTAINER_H