mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add floating preview widget
Change-Id: Ia13af9810b1aa8769b1920a4175e3dd315869627
This commit is contained in:
parent
82e8e22882
commit
d7c4656dee
Notes:
Deepin Code Review
2017-05-23 14:53:36 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 23 May 2017 14:53:33 +0800 Reviewed-on: https://cr.deepin.io/23348 Project: dde/dde-dock Branch: refs/heads/master
@ -41,7 +41,8 @@ SOURCES += main.cpp \
|
||||
item/components/previewcontainer.cpp \
|
||||
item/components/previewwidget.cpp \
|
||||
item/components/_previewcontainer.cpp \
|
||||
item/components/appsnapshot.cpp
|
||||
item/components/appsnapshot.cpp \
|
||||
item/components/floatingpreview.cpp
|
||||
|
||||
HEADERS += \
|
||||
window/mainwindow.h \
|
||||
@ -73,7 +74,8 @@ HEADERS += \
|
||||
item/components/previewcontainer.h \
|
||||
item/components/previewwidget.h \
|
||||
item/components/_previewcontainer.h \
|
||||
item/components/appsnapshot.h
|
||||
item/components/appsnapshot.h \
|
||||
item/components/floatingpreview.h
|
||||
|
||||
dbus_service.files += com.deepin.dde.Dock.service
|
||||
dbus_service.path = /usr/share/dbus-1/services
|
||||
|
@ -10,6 +10,7 @@
|
||||
_PreviewContainer::_PreviewContainer(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_floatingPreview(new FloatingPreview(this)),
|
||||
m_mouseLeaveTimer(new QTimer(this)),
|
||||
m_wmHelper(DWindowManagerHelper::instance())
|
||||
{
|
||||
@ -20,10 +21,13 @@ _PreviewContainer::_PreviewContainer(QWidget *parent)
|
||||
m_mouseLeaveTimer->setSingleShot(true);
|
||||
m_mouseLeaveTimer->setInterval(10);
|
||||
|
||||
m_floatingPreview->setVisible(false);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void _PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
@ -62,8 +66,12 @@ void _PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
||||
|
||||
void _PreviewContainer::checkMouseLeave()
|
||||
{
|
||||
if (!underMouse())
|
||||
const bool hover = underMouse();
|
||||
|
||||
if (!hover)
|
||||
{
|
||||
m_floatingPreview->setVisible(false);
|
||||
|
||||
emit requestCancelPreview();
|
||||
emit requestHidePreview();
|
||||
}
|
||||
@ -103,7 +111,7 @@ void _PreviewContainer::appendSnapWidget(const WId wid)
|
||||
connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestActivateWindow, Qt::QueuedConnection);
|
||||
connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestCancelPreview);
|
||||
connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestHidePreview);
|
||||
connect(snap, &AppSnapshot::entered, this, &_PreviewContainer::requestPreviewWindow);
|
||||
connect(snap, &AppSnapshot::entered, this, &_PreviewContainer::previewEntered);
|
||||
|
||||
m_windowListLayout->addWidget(snap);
|
||||
|
||||
@ -123,3 +131,26 @@ void _PreviewContainer::leaveEvent(QEvent *e)
|
||||
|
||||
m_mouseLeaveTimer->start();
|
||||
}
|
||||
|
||||
void _PreviewContainer::previewEntered(const WId wid)
|
||||
{
|
||||
AppSnapshot *snap = static_cast<AppSnapshot *>(sender());
|
||||
|
||||
m_floatingPreview->trackWindow(snap);
|
||||
m_floatingPreview->setVisible(true);
|
||||
m_floatingPreview->raise();
|
||||
|
||||
emit requestPreviewWindow(wid);
|
||||
}
|
||||
|
||||
void _PreviewContainer::moveFloatingPreview(const QPoint &p)
|
||||
{
|
||||
const QRect r = rect();
|
||||
|
||||
if (p.x() < r.left())
|
||||
m_floatingPreview->move(MARGIN, p.y());
|
||||
else if (p.x() + m_floatingPreview->width() > r.right())
|
||||
m_floatingPreview->move(r.right() - m_floatingPreview->width() - MARGIN + 1, p.y());
|
||||
else
|
||||
m_floatingPreview->move(p);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "dbus/dbusdockentry.h"
|
||||
#include "constants.h"
|
||||
#include "appsnapshot.h"
|
||||
#include "floatingpreview.h"
|
||||
|
||||
#include <DWindowManagerHelper>
|
||||
|
||||
@ -43,9 +44,14 @@ private:
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
|
||||
private slots:
|
||||
void previewEntered(const WId wid);
|
||||
void moveFloatingPreview(const QPoint &p);
|
||||
|
||||
private:
|
||||
QMap<WId, AppSnapshot *> m_snapshots;
|
||||
|
||||
FloatingPreview *m_floatingPreview;
|
||||
QBoxLayout *m_windowListLayout;
|
||||
|
||||
QTimer *m_mouseLeaveTimer;
|
||||
|
46
frame/item/components/floatingpreview.cpp
Normal file
46
frame/item/components/floatingpreview.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "floatingpreview.h"
|
||||
#include "appsnapshot.h"
|
||||
#include "_previewcontainer.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
FloatingPreview::FloatingPreview(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_closeBtn(new DImageButton)
|
||||
{
|
||||
m_closeBtn->setFixedSize(24, 24);
|
||||
m_closeBtn->setNormalPic(":/icons/resources/close_round_normal.png");
|
||||
m_closeBtn->setHoverPic(":/icons/resources/close_round_hover.png");
|
||||
m_closeBtn->setPressPic(":/icons/resources/close_round_press.png");
|
||||
|
||||
QVBoxLayout *centralLayout = new QVBoxLayout;
|
||||
centralLayout->addWidget(m_closeBtn);
|
||||
centralLayout->setAlignment(m_closeBtn, Qt::AlignRight | Qt::AlignTop);
|
||||
centralLayout->setMargin(0);
|
||||
centralLayout->setSpacing(0);
|
||||
|
||||
setLayout(centralLayout);
|
||||
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
|
||||
}
|
||||
|
||||
void FloatingPreview::trackWindow(AppSnapshot * const snap)
|
||||
{
|
||||
m_tracked = snap;
|
||||
|
||||
const QRect r = rect();
|
||||
const QRect sr = snap->geometry();
|
||||
const QPoint offset = sr.center() - r.center();
|
||||
|
||||
emit requestMove(offset);
|
||||
}
|
||||
|
||||
void FloatingPreview::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(rect(), Qt::red);
|
||||
}
|
34
frame/item/components/floatingpreview.h
Normal file
34
frame/item/components/floatingpreview.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef FLOATINGPREVIEW_H
|
||||
#define FLOATINGPREVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
#include <dimagebutton.h>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class AppSnapshot;
|
||||
class FloatingPreview : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FloatingPreview(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void requestMove(const QPoint &p) const;
|
||||
|
||||
public slots:
|
||||
void trackWindow(AppSnapshot * const snap);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private:
|
||||
QPointer<AppSnapshot> m_tracked;
|
||||
|
||||
DImageButton *m_closeBtn;
|
||||
};
|
||||
|
||||
#endif // FLOATINGPREVIEW_H
|
Loading…
x
Reference in New Issue
Block a user