From 1f5052cf530b0975f5b5faf622866f461c9af4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Tue, 28 Mar 2017 15:44:13 +0800 Subject: [PATCH] support preview content Change-Id: I61a65844a17c6cda152939cb327027ca8e3d9870 --- frame/frame.pro | 8 +-- frame/item/appitem.cpp | 20 +++++++- frame/item/appitem.h | 3 ++ frame/item/components/previewcontainer.cpp | 59 ++++++++++++++++++++++ frame/item/components/previewcontainer.h | 27 ++++++++++ 5 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 frame/item/components/previewcontainer.cpp create mode 100644 frame/item/components/previewcontainer.h diff --git a/frame/frame.pro b/frame/frame.pro index 034b63460..3094c5b26 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -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 diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index e2c0dc756..6cee67945 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -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); }); +} diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 1dd44f7da..bc7686803 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -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; diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp new file mode 100644 index 000000000..ba8d32906 --- /dev/null +++ b/frame/item/components/previewcontainer.cpp @@ -0,0 +1,59 @@ +#include "previewcontainer.h" + +#include +#include +#include + +#include +#include +#include + +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; + } +} diff --git a/frame/item/components/previewcontainer.h b/frame/item/components/previewcontainer.h new file mode 100644 index 000000000..cca100ebf --- /dev/null +++ b/frame/item/components/previewcontainer.h @@ -0,0 +1,27 @@ +#ifndef PREVIEWCONTAINER_H +#define PREVIEWCONTAINER_H + +#include +#include + +#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