mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
support preview content
Change-Id: I61a65844a17c6cda152939cb327027ca8e3d9870
This commit is contained in:
parent
165a64f858
commit
1f5052cf53
Notes:
Deepin Code Review
2017-03-28 15:57:06 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 28 Mar 2017 15:57:06 +0800 Reviewed-on: https://cr.deepin.io/21882 Project: dde/dde-dock Branch: refs/heads/master
@ -8,7 +8,7 @@ DESTDIR = $$_PRO_FILE_PWD_/../
|
||||
TEMPLATE = app
|
||||
CONFIG += c++11 link_pkgconfig
|
||||
|
||||
PKGCONFIG += xcb-ewmh dtkwidget dtkbase dtkutil
|
||||
PKGCONFIG += xcb-ewmh dtkwidget dtkbase dtkutil x11
|
||||
|
||||
SOURCES += main.cpp \
|
||||
window/mainwindow.cpp \
|
||||
@ -36,7 +36,8 @@ SOURCES += main.cpp \
|
||||
controller/dockpluginloader.cpp \
|
||||
item/containeritem.cpp \
|
||||
item/components/containerwidget.cpp \
|
||||
dbus/dbusdockadaptors.cpp
|
||||
dbus/dbusdockadaptors.cpp \
|
||||
item/components/previewcontainer.cpp
|
||||
|
||||
HEADERS += \
|
||||
window/mainwindow.h \
|
||||
@ -64,7 +65,8 @@ HEADERS += \
|
||||
controller/dockpluginloader.h \
|
||||
item/containeritem.h \
|
||||
item/components/containerwidget.h \
|
||||
dbus/dbusdockadaptors.h
|
||||
dbus/dbusdockadaptors.h \
|
||||
item/components/previewcontainer.h
|
||||
|
||||
dbus_service.files += com.deepin.dde.Dock.service
|
||||
dbus_service.path = /usr/share/dbus-1/services
|
||||
|
@ -18,6 +18,7 @@ QPoint AppItem::MousePressPos;
|
||||
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
: DockItem(parent),
|
||||
m_appNameTips(new QLabel(this)),
|
||||
m_appPreviewTips(new PreviewContainer(this)),
|
||||
m_itemEntry(new DBusDockEntry(entry.path(), this)),
|
||||
m_draging(false),
|
||||
m_launchingEffects(0.0),
|
||||
@ -247,10 +248,18 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
if (distance.manhattanLength() > APP_DRAG_THRESHOLD)
|
||||
return;
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
const int windowCount = m_titles.size();
|
||||
if (windowCount < 2)
|
||||
m_itemEntry->Activate();
|
||||
else
|
||||
showPreview();
|
||||
#else
|
||||
m_itemEntry->Activate();
|
||||
#endif
|
||||
|
||||
if (!m_titles.isEmpty())
|
||||
return;
|
||||
// if (!m_titles.isEmpty())
|
||||
// return;
|
||||
|
||||
// start launching effects
|
||||
//m_launchingEffects = 0.0;
|
||||
@ -413,3 +422,10 @@ void AppItem::activeChanged()
|
||||
{
|
||||
m_active = !m_active;
|
||||
}
|
||||
|
||||
void AppItem::showPreview()
|
||||
{
|
||||
m_appPreviewTips->setWindowInfos(m_titles);
|
||||
|
||||
QTimer::singleShot(100, this, [=] { showPopupApplet(m_appPreviewTips); });
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define APPITEM_H
|
||||
|
||||
#include "dockitem.h"
|
||||
#include "components/previewcontainer.h"
|
||||
#include "dbus/dbusdockentry.h"
|
||||
#include "dbus/dbusclientmanager.h"
|
||||
|
||||
@ -41,9 +42,11 @@ private slots:
|
||||
void updateTitle();
|
||||
void refershIcon();
|
||||
void activeChanged();
|
||||
void showPreview();
|
||||
|
||||
private:
|
||||
QLabel *m_appNameTips;
|
||||
PreviewContainer *m_appPreviewTips;
|
||||
DBusDockEntry *m_itemEntry;
|
||||
|
||||
bool m_draging;
|
||||
|
59
frame/item/components/previewcontainer.cpp
Normal file
59
frame/item/components/previewcontainer.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "previewcontainer.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWindow>
|
||||
#include <QX11Info>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
PreviewContainer::PreviewContainer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
m_windowListLayout->setMargin(0);
|
||||
m_windowListLayout->setSpacing(5);
|
||||
|
||||
setLayout(m_windowListLayout);
|
||||
}
|
||||
|
||||
void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
{
|
||||
// TODO: optimize
|
||||
while (QLayoutItem *item = m_windowListLayout->takeAt(0))
|
||||
{
|
||||
item->widget()->deleteLater();
|
||||
delete item;
|
||||
}
|
||||
|
||||
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
|
||||
{
|
||||
XWindowAttributes attrs;
|
||||
XGetWindowAttributes(QX11Info::display(), it.key(), &attrs);
|
||||
XImage *ximage = XGetImage(QX11Info::display(), it.key(), 0, 0, attrs.width, attrs.height, AllPlanes, ZPixmap);
|
||||
const QImage qimage((uchar*)(ximage->data), attrs.width, attrs.height, QImage::Format_ARGB32);
|
||||
XDestroyImage(ximage);
|
||||
|
||||
QLabel *l = new QLabel;
|
||||
l->setFixedSize(250, 200);
|
||||
l->setPixmap(QPixmap::fromImage(qimage).scaled(250, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
m_windowListLayout->addWidget(l);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
||||
{
|
||||
switch (dockPos)
|
||||
{
|
||||
case Dock::Top:
|
||||
case Dock::Bottom:
|
||||
m_windowListLayout->setDirection(QBoxLayout::LeftToRight);
|
||||
break;
|
||||
|
||||
case Dock::Left:
|
||||
case Dock::Right:
|
||||
m_windowListLayout->setDirection(QBoxLayout::TopToBottom);
|
||||
break;
|
||||
}
|
||||
}
|
27
frame/item/components/previewcontainer.h
Normal file
27
frame/item/components/previewcontainer.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef PREVIEWCONTAINER_H
|
||||
#define PREVIEWCONTAINER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "dbus/dbusdockentry.h"
|
||||
#include "constants.h"
|
||||
|
||||
class PreviewContainer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PreviewContainer(QWidget *parent = 0);
|
||||
|
||||
public:
|
||||
void setWindowInfos(const WindowDict &infos);
|
||||
|
||||
public slots:
|
||||
void updateLayoutDirection(const Dock::Position dockPos);
|
||||
|
||||
private:
|
||||
QBoxLayout *m_windowListLayout;
|
||||
};
|
||||
|
||||
#endif // PREVIEWCONTAINER_H
|
Loading…
x
Reference in New Issue
Block a user