mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
remove old preview container widget
Change-Id: Ibf7828e1135f660b123ee605ad3b279f9035bd3e
This commit is contained in:
parent
e7664fc2d3
commit
07c44bb617
Notes:
Deepin Code Review
2017-07-31 17:20:52 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Mon, 31 Jul 2017 17:20:50 +0800 Reviewed-on: https://cr.deepin.io/25145 Project: dde/dde-dock Branch: refs/heads/master
@ -38,11 +38,10 @@ SOURCES += main.cpp \
|
|||||||
item/containeritem.cpp \
|
item/containeritem.cpp \
|
||||||
item/components/containerwidget.cpp \
|
item/components/containerwidget.cpp \
|
||||||
dbus/dbusdockadaptors.cpp \
|
dbus/dbusdockadaptors.cpp \
|
||||||
item/components/previewcontainer.cpp \
|
|
||||||
item/components/previewwidget.cpp \
|
item/components/previewwidget.cpp \
|
||||||
item/components/_previewcontainer.cpp \
|
|
||||||
item/components/appsnapshot.cpp \
|
item/components/appsnapshot.cpp \
|
||||||
item/components/floatingpreview.cpp
|
item/components/floatingpreview.cpp \
|
||||||
|
item/components/previewcontainer.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
window/mainwindow.h \
|
window/mainwindow.h \
|
||||||
@ -71,11 +70,10 @@ HEADERS += \
|
|||||||
item/containeritem.h \
|
item/containeritem.h \
|
||||||
item/components/containerwidget.h \
|
item/components/containerwidget.h \
|
||||||
dbus/dbusdockadaptors.h \
|
dbus/dbusdockadaptors.h \
|
||||||
item/components/previewcontainer.h \
|
|
||||||
item/components/previewwidget.h \
|
item/components/previewwidget.h \
|
||||||
item/components/_previewcontainer.h \
|
|
||||||
item/components/appsnapshot.h \
|
item/components/appsnapshot.h \
|
||||||
item/components/floatingpreview.h
|
item/components/floatingpreview.h \
|
||||||
|
item/components/previewcontainer.h
|
||||||
|
|
||||||
dbus_service.files += com.deepin.dde.Dock.service
|
dbus_service.files += com.deepin.dde.Dock.service
|
||||||
dbus_service.path = /usr/share/dbus-1/services
|
dbus_service.path = /usr/share/dbus-1/services
|
||||||
|
@ -26,7 +26,7 @@ QPoint AppItem::MousePressPos;
|
|||||||
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||||
: DockItem(parent),
|
: DockItem(parent),
|
||||||
m_appNameTips(new QLabel(this)),
|
m_appNameTips(new QLabel(this)),
|
||||||
m_appPreviewTips(new _PreviewContainer(this)),
|
m_appPreviewTips(new PreviewContainer(this)),
|
||||||
m_itemEntry(new DBusDockEntry(entry.path(), this)),
|
m_itemEntry(new DBusDockEntry(entry.path(), this)),
|
||||||
|
|
||||||
m_itemView(new QGraphicsView(this)),
|
m_itemView(new QGraphicsView(this)),
|
||||||
@ -87,11 +87,11 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
|||||||
|
|
||||||
connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries, Qt::QueuedConnection);
|
connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries, Qt::QueuedConnection);
|
||||||
|
|
||||||
connect(m_appPreviewTips, &_PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
|
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
|
||||||
connect(m_appPreviewTips, &_PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, 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::requestCancelPreview, this, &AppItem::requestCancelPreview, Qt::QueuedConnection);
|
||||||
connect(m_appPreviewTips, &_PreviewContainer::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection);
|
connect(m_appPreviewTips, &PreviewContainer::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection);
|
||||||
connect(m_appPreviewTips, &_PreviewContainer::requestCheckWindows, m_itemEntry, &DBusDockEntry::Check);
|
connect(m_appPreviewTips, &PreviewContainer::requestCheckWindows, m_itemEntry, &DBusDockEntry::Check);
|
||||||
|
|
||||||
updateTitle();
|
updateTitle();
|
||||||
refershIcon();
|
refershIcon();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define APPITEM_H
|
#define APPITEM_H
|
||||||
|
|
||||||
#include "dockitem.h"
|
#include "dockitem.h"
|
||||||
#include "components/_previewcontainer.h"
|
#include "components/previewcontainer.h"
|
||||||
#include "dbus/dbusdockentry.h"
|
#include "dbus/dbusdockentry.h"
|
||||||
#include "dbus/dbusclientmanager.h"
|
#include "dbus/dbusclientmanager.h"
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *m_appNameTips;
|
QLabel *m_appNameTips;
|
||||||
_PreviewContainer *m_appPreviewTips;
|
PreviewContainer *m_appPreviewTips;
|
||||||
DBusDockEntry *m_itemEntry;
|
DBusDockEntry *m_itemEntry;
|
||||||
|
|
||||||
QGraphicsView *m_itemView;
|
QGraphicsView *m_itemView;
|
||||||
|
@ -1,218 +0,0 @@
|
|||||||
#include "_previewcontainer.h"
|
|
||||||
|
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QScreen>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDragEnterEvent>
|
|
||||||
|
|
||||||
#define SPACING 0
|
|
||||||
#define MARGIN 0
|
|
||||||
#define SNAP_HEIGHT_WITHOUT_COMPOSITE 30
|
|
||||||
|
|
||||||
_PreviewContainer::_PreviewContainer(QWidget *parent)
|
|
||||||
: QWidget(parent),
|
|
||||||
m_needActivate(false),
|
|
||||||
|
|
||||||
m_floatingPreview(new FloatingPreview(this)),
|
|
||||||
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(300);
|
|
||||||
|
|
||||||
m_floatingPreview->setVisible(false);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::setWindowInfos(const WindowDict &infos)
|
|
||||||
{
|
|
||||||
// check removed window
|
|
||||||
for (auto it(m_snapshots.begin()); it != m_snapshots.end();)
|
|
||||||
{
|
|
||||||
if (!infos.contains(it.key()))
|
|
||||||
{
|
|
||||||
m_windowListLayout->removeWidget(it.value());
|
|
||||||
it.value()->deleteLater();
|
|
||||||
it = m_snapshots.erase(it);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
|
|
||||||
{
|
|
||||||
if (!m_snapshots.contains(it.key()))
|
|
||||||
appendSnapWidget(it.key());
|
|
||||||
m_snapshots[it.key()]->setWindowTitle(it.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_snapshots.isEmpty())
|
|
||||||
{
|
|
||||||
emit requestCancelPreview();
|
|
||||||
emit requestHidePreview();
|
|
||||||
} else {
|
|
||||||
adjustSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::updateSnapshots()
|
|
||||||
{
|
|
||||||
for (AppSnapshot *snap : m_snapshots)
|
|
||||||
snap->fetchSnapshot();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
|
||||||
{
|
|
||||||
if (m_wmHelper->hasComposite() && (dockPos == Dock::Top || dockPos == Dock::Bottom))
|
|
||||||
m_windowListLayout->setDirection(QBoxLayout::LeftToRight);
|
|
||||||
else
|
|
||||||
m_windowListLayout->setDirection(QBoxLayout::TopToBottom);
|
|
||||||
|
|
||||||
adjustSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::checkMouseLeave()
|
|
||||||
{
|
|
||||||
const bool hover = underMouse();
|
|
||||||
|
|
||||||
if (!hover)
|
|
||||||
{
|
|
||||||
m_floatingPreview->setVisible(false);
|
|
||||||
|
|
||||||
if (!isVisible())
|
|
||||||
return;
|
|
||||||
|
|
||||||
emit requestCancelPreview();
|
|
||||||
emit requestHidePreview();
|
|
||||||
|
|
||||||
if (m_needActivate)
|
|
||||||
{
|
|
||||||
m_needActivate = false;
|
|
||||||
emit requestActivateWindow(m_floatingPreview->trackedWid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::adjustSize()
|
|
||||||
{
|
|
||||||
const int count = m_snapshots.size();
|
|
||||||
const bool composite = m_wmHelper->hasComposite();
|
|
||||||
if (!composite)
|
|
||||||
{
|
|
||||||
const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1);
|
|
||||||
setFixedSize(SNAP_WIDTH, h);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QRect r = qApp->primaryScreen()->geometry();
|
|
||||||
const int padding = 20;
|
|
||||||
|
|
||||||
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
|
||||||
if (horizontal)
|
|
||||||
{
|
|
||||||
const int h = SNAP_HEIGHT + MARGIN * 2;
|
|
||||||
const int w = SNAP_WIDTH * count + MARGIN * 2 + SPACING * (count - 1);
|
|
||||||
|
|
||||||
setFixedHeight(h);
|
|
||||||
setFixedWidth(std::min(w, r.width() - padding));
|
|
||||||
} else {
|
|
||||||
const int w = SNAP_WIDTH + MARGIN * 2;
|
|
||||||
const int h = SNAP_HEIGHT * count + MARGIN * 2 + SPACING * (count - 1);
|
|
||||||
|
|
||||||
setFixedWidth(w);
|
|
||||||
setFixedHeight(std::min(h, r.height() - padding));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::appendSnapWidget(const WId wid)
|
|
||||||
{
|
|
||||||
AppSnapshot *snap = new AppSnapshot(wid);
|
|
||||||
|
|
||||||
connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestActivateWindow, Qt::QueuedConnection);
|
|
||||||
connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestCancelPreview, Qt::QueuedConnection);
|
|
||||||
connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestHidePreview, Qt::QueuedConnection);
|
|
||||||
connect(snap, &AppSnapshot::entered, this, &_PreviewContainer::previewEntered, Qt::QueuedConnection);
|
|
||||||
connect(snap, &AppSnapshot::requestCheckWindow, this, &_PreviewContainer::requestCheckWindows);
|
|
||||||
|
|
||||||
m_windowListLayout->addWidget(snap);
|
|
||||||
|
|
||||||
m_snapshots.insert(wid, snap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::enterEvent(QEvent *e)
|
|
||||||
{
|
|
||||||
QWidget::enterEvent(e);
|
|
||||||
|
|
||||||
m_needActivate = false;
|
|
||||||
m_mouseLeaveTimer->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::leaveEvent(QEvent *e)
|
|
||||||
{
|
|
||||||
QWidget::leaveEvent(e);
|
|
||||||
|
|
||||||
m_mouseLeaveTimer->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::dragEnterEvent(QDragEnterEvent *e)
|
|
||||||
{
|
|
||||||
e->accept();
|
|
||||||
|
|
||||||
m_needActivate = false;
|
|
||||||
m_mouseLeaveTimer->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::dragLeaveEvent(QDragLeaveEvent *e)
|
|
||||||
{
|
|
||||||
e->ignore();
|
|
||||||
|
|
||||||
m_needActivate = true;
|
|
||||||
m_mouseLeaveTimer->start(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PreviewContainer::previewEntered(const WId wid)
|
|
||||||
{
|
|
||||||
if (!m_wmHelper->hasComposite())
|
|
||||||
return;
|
|
||||||
|
|
||||||
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 bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
|
||||||
const QRect r = rect();
|
|
||||||
|
|
||||||
if (horizontal)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
if (p.y() < r.top())
|
|
||||||
m_floatingPreview->move(p.x(), MARGIN);
|
|
||||||
else if (p.y() + m_floatingPreview->height() > r.bottom())
|
|
||||||
m_floatingPreview->move(p.x(), r.bottom() - m_floatingPreview->height() - MARGIN + 1);
|
|
||||||
else
|
|
||||||
m_floatingPreview->move(p);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
#ifndef _PREVIEWCONTAINER_H
|
|
||||||
#define _PREVIEWCONTAINER_H
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QBoxLayout>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "dbus/dbusdockentry.h"
|
|
||||||
#include "constants.h"
|
|
||||||
#include "appsnapshot.h"
|
|
||||||
#include "floatingpreview.h"
|
|
||||||
|
|
||||||
#include <DWindowManagerHelper>
|
|
||||||
|
|
||||||
#define SNAP_WIDTH 200
|
|
||||||
#define SNAP_HEIGHT 130
|
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
|
||||||
|
|
||||||
class _PreviewContainer : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit _PreviewContainer(QWidget *parent = 0);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void requestActivateWindow(const WId wid) const;
|
|
||||||
void requestPreviewWindow(const WId wid) const;
|
|
||||||
void requestCancelPreview() const;
|
|
||||||
void requestHidePreview() const;
|
|
||||||
void requestCheckWindows() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void setWindowInfos(const WindowDict &infos);
|
|
||||||
void updateSnapshots();
|
|
||||||
|
|
||||||
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);
|
|
||||||
void dragEnterEvent(QDragEnterEvent *e);
|
|
||||||
void dragLeaveEvent(QDragLeaveEvent *e);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void previewEntered(const WId wid);
|
|
||||||
void moveFloatingPreview(const QPoint &p);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_needActivate;
|
|
||||||
QMap<WId, AppSnapshot *> m_snapshots;
|
|
||||||
|
|
||||||
FloatingPreview *m_floatingPreview;
|
|
||||||
QBoxLayout *m_windowListLayout;
|
|
||||||
|
|
||||||
QTimer *m_mouseLeaveTimer;
|
|
||||||
DWindowManagerHelper *m_wmHelper;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _PREVIEWCONTAINER_H
|
|
@ -1,5 +1,5 @@
|
|||||||
#include "appsnapshot.h"
|
#include "appsnapshot.h"
|
||||||
#include "_previewcontainer.h"
|
#include "previewcontainer.h"
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "floatingpreview.h"
|
#include "floatingpreview.h"
|
||||||
#include "appsnapshot.h"
|
#include "appsnapshot.h"
|
||||||
#include "_previewcontainer.h"
|
#include "previewcontainer.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
@ -1,73 +1,74 @@
|
|||||||
#include "previewcontainer.h"
|
#include "previewcontainer.h"
|
||||||
#include "previewwidget.h"
|
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QDesktopWidget>
|
||||||
#include <QWindow>
|
#include <QScreen>
|
||||||
#include <QDebug>
|
#include <QApplication>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
|
||||||
|
#define SPACING 0
|
||||||
|
#define MARGIN 0
|
||||||
|
#define SNAP_HEIGHT_WITHOUT_COMPOSITE 30
|
||||||
|
|
||||||
PreviewContainer::PreviewContainer(QWidget *parent)
|
PreviewContainer::PreviewContainer(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
|
m_needActivate(false),
|
||||||
|
|
||||||
m_wmHelper(DWindowManagerHelper::instance()),
|
m_floatingPreview(new FloatingPreview(this)),
|
||||||
|
m_mouseLeaveTimer(new QTimer(this)),
|
||||||
m_mouseLeaveTimer(new QTimer(this))
|
m_wmHelper(DWindowManagerHelper::instance())
|
||||||
{
|
{
|
||||||
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||||
m_windowListLayout->setMargin(5);
|
m_windowListLayout->setSpacing(SPACING);
|
||||||
m_windowListLayout->setSpacing(3);
|
m_windowListLayout->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
|
||||||
|
|
||||||
m_mouseLeaveTimer->setSingleShot(true);
|
m_mouseLeaveTimer->setSingleShot(true);
|
||||||
m_mouseLeaveTimer->setInterval(100);
|
m_mouseLeaveTimer->setInterval(300);
|
||||||
|
|
||||||
|
m_floatingPreview->setVisible(false);
|
||||||
|
|
||||||
|
setAcceptDrops(true);
|
||||||
setLayout(m_windowListLayout);
|
setLayout(m_windowListLayout);
|
||||||
|
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
|
||||||
|
|
||||||
connect(m_mouseLeaveTimer, &QTimer::timeout, this, &PreviewContainer::checkMouseLeave, Qt::QueuedConnection);
|
connect(m_mouseLeaveTimer, &QTimer::timeout, this, &PreviewContainer::checkMouseLeave, Qt::QueuedConnection);
|
||||||
|
connect(m_floatingPreview, &FloatingPreview::requestMove, this, &PreviewContainer::moveFloatingPreview);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||||
{
|
{
|
||||||
if (infos.isEmpty())
|
// check removed window
|
||||||
|
for (auto it(m_snapshots.begin()); it != m_snapshots.end();)
|
||||||
{
|
{
|
||||||
emit requestCancelPreview();
|
if (!infos.contains(it.key()))
|
||||||
emit requestHidePreview();
|
{
|
||||||
|
m_windowListLayout->removeWidget(it.value());
|
||||||
return;
|
it.value()->deleteLater();
|
||||||
|
it = m_snapshots.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WId> removedWindows;
|
|
||||||
|
|
||||||
// remove desroyed window
|
|
||||||
for (auto it(m_windows.cbegin()); it != m_windows.cend(); ++it)
|
|
||||||
{
|
|
||||||
if (infos.contains(it.key()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
removedWindows << it.key();
|
|
||||||
m_windowListLayout->removeWidget(it.value());
|
|
||||||
it.value()->deleteLater();
|
|
||||||
}
|
|
||||||
for (auto id : removedWindows)
|
|
||||||
m_windows.remove(id);
|
|
||||||
|
|
||||||
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
|
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
|
||||||
{
|
{
|
||||||
if (m_windows.contains(it.key()))
|
if (!m_snapshots.contains(it.key()))
|
||||||
continue;
|
appendSnapWidget(it.key());
|
||||||
|
m_snapshots[it.key()]->setWindowTitle(it.value());
|
||||||
PreviewWidget *w = new PreviewWidget(it.key());
|
|
||||||
w->setTitle(it.value());
|
|
||||||
|
|
||||||
connect(w, &PreviewWidget::requestActivateWindow, this, &PreviewContainer::requestActivateWindow);
|
|
||||||
connect(w, &PreviewWidget::requestPreviewWindow, this, &PreviewContainer::requestPreviewWindow);
|
|
||||||
connect(w, &PreviewWidget::requestCancelPreview, this, &PreviewContainer::requestCancelPreview);
|
|
||||||
connect(w, &PreviewWidget::requestHidePreview, this, &PreviewContainer::requestHidePreview);
|
|
||||||
|
|
||||||
m_windowListLayout->addWidget(w);
|
|
||||||
m_windows.insert(it.key(), w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update geometry
|
if (m_snapshots.isEmpty())
|
||||||
QMetaObject::invokeMethod(this, "updateContainerSize", Qt::QueuedConnection);
|
{
|
||||||
|
emit requestCancelPreview();
|
||||||
|
emit requestHidePreview();
|
||||||
|
} else {
|
||||||
|
adjustSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewContainer::updateSnapshots()
|
||||||
|
{
|
||||||
|
for (AppSnapshot *snap : m_snapshots)
|
||||||
|
snap->fetchSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
void PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
||||||
@ -77,18 +78,83 @@ void PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
|||||||
else
|
else
|
||||||
m_windowListLayout->setDirection(QBoxLayout::TopToBottom);
|
m_windowListLayout->setDirection(QBoxLayout::TopToBottom);
|
||||||
|
|
||||||
// switch (dockPos)
|
adjustSize();
|
||||||
// {
|
}
|
||||||
// case Dock::Top:
|
|
||||||
// case Dock::Bottom:
|
|
||||||
// m_windowListLayout->setDirection(QBoxLayout::LeftToRight);
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case Dock::Left:
|
void PreviewContainer::checkMouseLeave()
|
||||||
// case Dock::Right:
|
{
|
||||||
// m_windowListLayout->setDirection(QBoxLayout::TopToBottom);
|
const bool hover = underMouse();
|
||||||
// break;
|
|
||||||
// }
|
if (!hover)
|
||||||
|
{
|
||||||
|
m_floatingPreview->setVisible(false);
|
||||||
|
|
||||||
|
if (!isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit requestCancelPreview();
|
||||||
|
emit requestHidePreview();
|
||||||
|
|
||||||
|
if (m_needActivate)
|
||||||
|
{
|
||||||
|
m_needActivate = false;
|
||||||
|
emit requestActivateWindow(m_floatingPreview->trackedWid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewContainer::adjustSize()
|
||||||
|
{
|
||||||
|
const int count = m_snapshots.size();
|
||||||
|
const bool composite = m_wmHelper->hasComposite();
|
||||||
|
if (!composite)
|
||||||
|
{
|
||||||
|
const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1);
|
||||||
|
setFixedSize(SNAP_WIDTH, h);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QRect r = qApp->primaryScreen()->geometry();
|
||||||
|
const int padding = 20;
|
||||||
|
|
||||||
|
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
||||||
|
if (horizontal)
|
||||||
|
{
|
||||||
|
const int h = SNAP_HEIGHT + MARGIN * 2;
|
||||||
|
const int w = SNAP_WIDTH * count + MARGIN * 2 + SPACING * (count - 1);
|
||||||
|
|
||||||
|
setFixedHeight(h);
|
||||||
|
setFixedWidth(std::min(w, r.width() - padding));
|
||||||
|
} else {
|
||||||
|
const int w = SNAP_WIDTH + MARGIN * 2;
|
||||||
|
const int h = SNAP_HEIGHT * count + MARGIN * 2 + SPACING * (count - 1);
|
||||||
|
|
||||||
|
setFixedWidth(w);
|
||||||
|
setFixedHeight(std::min(h, r.height() - padding));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewContainer::appendSnapWidget(const WId wid)
|
||||||
|
{
|
||||||
|
AppSnapshot *snap = new AppSnapshot(wid);
|
||||||
|
|
||||||
|
connect(snap, &AppSnapshot::clicked, this, &PreviewContainer::requestActivateWindow, Qt::QueuedConnection);
|
||||||
|
connect(snap, &AppSnapshot::clicked, this, &PreviewContainer::requestCancelPreview, Qt::QueuedConnection);
|
||||||
|
connect(snap, &AppSnapshot::clicked, this, &PreviewContainer::requestHidePreview, Qt::QueuedConnection);
|
||||||
|
connect(snap, &AppSnapshot::entered, this, &PreviewContainer::previewEntered, Qt::QueuedConnection);
|
||||||
|
connect(snap, &AppSnapshot::requestCheckWindow, this, &PreviewContainer::requestCheckWindows);
|
||||||
|
|
||||||
|
m_windowListLayout->addWidget(snap);
|
||||||
|
|
||||||
|
m_snapshots.insert(wid, snap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewContainer::enterEvent(QEvent *e)
|
||||||
|
{
|
||||||
|
QWidget::enterEvent(e);
|
||||||
|
|
||||||
|
m_needActivate = false;
|
||||||
|
m_mouseLeaveTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewContainer::leaveEvent(QEvent *e)
|
void PreviewContainer::leaveEvent(QEvent *e)
|
||||||
@ -98,25 +164,55 @@ void PreviewContainer::leaveEvent(QEvent *e)
|
|||||||
m_mouseLeaveTimer->start();
|
m_mouseLeaveTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewContainer::enterEvent(QEvent *e)
|
void PreviewContainer::dragEnterEvent(QDragEnterEvent *e)
|
||||||
{
|
{
|
||||||
QWidget::enterEvent(e);
|
e->accept();
|
||||||
|
|
||||||
|
m_needActivate = false;
|
||||||
m_mouseLeaveTimer->stop();
|
m_mouseLeaveTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewContainer::updateContainerSize()
|
void PreviewContainer::dragLeaveEvent(QDragLeaveEvent *e)
|
||||||
{
|
{
|
||||||
resize(sizeHint());
|
e->ignore();
|
||||||
|
|
||||||
|
m_needActivate = true;
|
||||||
|
m_mouseLeaveTimer->start(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewContainer::checkMouseLeave()
|
void PreviewContainer::previewEntered(const WId wid)
|
||||||
{
|
{
|
||||||
const QPoint p = mapFromGlobal(QCursor::pos());
|
if (!m_wmHelper->hasComposite())
|
||||||
|
return;
|
||||||
|
|
||||||
if (!rect().contains(p))
|
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 bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
||||||
|
const QRect r = rect();
|
||||||
|
|
||||||
|
if (horizontal)
|
||||||
{
|
{
|
||||||
emit requestCancelPreview();
|
if (p.x() < r.left())
|
||||||
emit requestHidePreview();
|
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);
|
||||||
|
} else {
|
||||||
|
if (p.y() < r.top())
|
||||||
|
m_floatingPreview->move(p.x(), MARGIN);
|
||||||
|
else if (p.y() + m_floatingPreview->height() > r.bottom())
|
||||||
|
m_floatingPreview->move(p.x(), r.bottom() - m_floatingPreview->height() - MARGIN + 1);
|
||||||
|
else
|
||||||
|
m_floatingPreview->move(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,19 @@
|
|||||||
#define PREVIEWCONTAINER_H
|
#define PREVIEWCONTAINER_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QHBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "dbus/dbusdockentry.h"
|
#include "dbus/dbusdockentry.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "appsnapshot.h"
|
||||||
|
#include "floatingpreview.h"
|
||||||
|
|
||||||
#include <DWindowManagerHelper>
|
#include <DWindowManagerHelper>
|
||||||
|
|
||||||
|
#define SNAP_WIDTH 200
|
||||||
|
#define SNAP_HEIGHT 130
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
class PreviewContainer : public QWidget
|
class PreviewContainer : public QWidget
|
||||||
@ -23,29 +29,38 @@ signals:
|
|||||||
void requestPreviewWindow(const WId wid) const;
|
void requestPreviewWindow(const WId wid) const;
|
||||||
void requestCancelPreview() const;
|
void requestCancelPreview() const;
|
||||||
void requestHidePreview() const;
|
void requestHidePreview() const;
|
||||||
|
void requestCheckWindows() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setWindowInfos(const WindowDict &infos);
|
void setWindowInfos(const WindowDict &infos);
|
||||||
|
void updateSnapshots();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLayoutDirection(const Dock::Position dockPos);
|
void updateLayoutDirection(const Dock::Position dockPos);
|
||||||
|
|
||||||
protected:
|
|
||||||
void leaveEvent(QEvent *e);
|
|
||||||
void enterEvent(QEvent *e);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void updateContainerSize();
|
|
||||||
void checkMouseLeave();
|
void checkMouseLeave();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void adjustSize();
|
||||||
|
void appendSnapWidget(const WId wid);
|
||||||
|
|
||||||
|
void enterEvent(QEvent *e);
|
||||||
|
void leaveEvent(QEvent *e);
|
||||||
|
void dragEnterEvent(QDragEnterEvent *e);
|
||||||
|
void dragLeaveEvent(QDragLeaveEvent *e);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void previewEntered(const WId wid);
|
||||||
|
void moveFloatingPreview(const QPoint &p);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_needActivate;
|
||||||
|
QMap<WId, AppSnapshot *> m_snapshots;
|
||||||
|
|
||||||
|
FloatingPreview *m_floatingPreview;
|
||||||
QBoxLayout *m_windowListLayout;
|
QBoxLayout *m_windowListLayout;
|
||||||
|
|
||||||
DWindowManagerHelper *m_wmHelper;
|
|
||||||
|
|
||||||
QTimer *m_mouseLeaveTimer;
|
QTimer *m_mouseLeaveTimer;
|
||||||
|
DWindowManagerHelper *m_wmHelper;
|
||||||
QMap<WId, QWidget *> m_windows;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PREVIEWCONTAINER_H
|
#endif // PREVIEWCONTAINER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user