switch to new preview widget

Change-Id: I5a6c86156defe7117028c07d65d2f292c2663eb4
This commit is contained in:
石博文 2017-05-23 11:15:22 +08:00
parent 604f85da21
commit 82e8e22882
Notes: Deepin Code Review 2017-05-23 11:21:29 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 23 May 2017 11:21:27 +0800
Reviewed-on: https://cr.deepin.io/23339
Project: dde/dde-dock
Branch: refs/heads/master
4 changed files with 34 additions and 16 deletions

View File

@ -23,11 +23,7 @@ QPoint AppItem::MousePressPos;
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
: DockItem(parent),
m_appNameTips(new QLabel(this)),
#ifdef QT_DEBUG
m_appPreviewTips(new _PreviewContainer(this)),
#else
m_appPreviewTips(new PreviewContainer(this)),
#endif
m_itemEntry(new DBusDockEntry(entry.path(), this)),
m_itemView(new QGraphicsView(this)),
@ -81,17 +77,10 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries, Qt::QueuedConnection);
#ifdef QT_DEBUG
connect(m_appPreviewTips, &_PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
connect(m_appPreviewTips, &_PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, Qt::QueuedConnection);
connect(m_appPreviewTips, &_PreviewContainer::requestCancelPreview, this, &AppItem::requestCancelPreview, Qt::QueuedConnection);
connect(m_appPreviewTips, &_PreviewContainer::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection);
#else
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
connect(m_appPreviewTips, &PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, Qt::QueuedConnection);
connect(m_appPreviewTips, &PreviewContainer::requestCancelPreview, this, &AppItem::requestCancelPreview, Qt::QueuedConnection);
connect(m_appPreviewTips, &PreviewContainer::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection);
#endif
updateTitle();
refershIcon();

View File

@ -2,7 +2,6 @@
#define APPITEM_H
#include "dockitem.h"
#include "components/previewcontainer.h"
#include "components/_previewcontainer.h"
#include "dbus/dbusdockentry.h"
#include "dbus/dbusclientmanager.h"
@ -58,11 +57,7 @@ private slots:
private:
QLabel *m_appNameTips;
#ifdef QT_DEBUG
_PreviewContainer *m_appPreviewTips;
#else
PreviewContainer *m_appPreviewTips;
#endif
DBusDockEntry *m_itemEntry;
QGraphicsView *m_itemView;

View File

@ -10,14 +10,20 @@
_PreviewContainer::_PreviewContainer(QWidget *parent)
: QWidget(parent),
m_mouseLeaveTimer(new QTimer(this)),
m_wmHelper(DWindowManagerHelper::instance())
{
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
m_windowListLayout->setSpacing(SPACING);
m_windowListLayout->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
m_mouseLeaveTimer->setSingleShot(true);
m_mouseLeaveTimer->setInterval(10);
setLayout(m_windowListLayout);
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
connect(m_mouseLeaveTimer, &QTimer::timeout, this, &_PreviewContainer::checkMouseLeave, Qt::QueuedConnection);
}
void _PreviewContainer::setWindowInfos(const WindowDict &infos)
@ -54,6 +60,15 @@ void _PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
adjustSize();
}
void _PreviewContainer::checkMouseLeave()
{
if (!underMouse())
{
emit requestCancelPreview();
emit requestHidePreview();
}
}
void _PreviewContainer::adjustSize()
{
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
@ -94,3 +109,17 @@ void _PreviewContainer::appendSnapWidget(const WId wid)
m_snapshots.insert(wid, snap);
}
void _PreviewContainer::enterEvent(QEvent *e)
{
QWidget::enterEvent(e);
m_mouseLeaveTimer->start();
}
void _PreviewContainer::leaveEvent(QEvent *e)
{
QWidget::leaveEvent(e);
m_mouseLeaveTimer->start();
}

View File

@ -34,16 +34,21 @@ public:
public slots:
void updateLayoutDirection(const Dock::Position dockPos);
void checkMouseLeave();
private:
void adjustSize();
void appendSnapWidget(const WId wid);
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
private:
QMap<WId, AppSnapshot *> m_snapshots;
QBoxLayout *m_windowListLayout;
QTimer *m_mouseLeaveTimer;
DWindowManagerHelper *m_wmHelper;
};