From 0f1e3db89f604a85d0a16c0c9ae416bf62ae99c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Mon, 22 May 2017 15:11:07 +0800 Subject: [PATCH] add snapshot widget Change-Id: I170cca94efd60b1d18f33773626f6af92d51f1f5 --- frame/frame.pro | 6 ++- frame/item/components/_previewcontainer.cpp | 49 ++++++++++++++++++++- frame/item/components/_previewcontainer.h | 9 +++- frame/item/components/appsnapshot.cpp | 7 +++ frame/item/components/appsnapshot.h | 14 ++++++ 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 frame/item/components/appsnapshot.cpp create mode 100644 frame/item/components/appsnapshot.h diff --git a/frame/frame.pro b/frame/frame.pro index aa0e80b98..0f449ae27 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -40,7 +40,8 @@ SOURCES += main.cpp \ dbus/dbusdockadaptors.cpp \ item/components/previewcontainer.cpp \ item/components/previewwidget.cpp \ - item/components/_previewcontainer.cpp + item/components/_previewcontainer.cpp \ + item/components/appsnapshot.cpp HEADERS += \ window/mainwindow.h \ @@ -71,7 +72,8 @@ HEADERS += \ dbus/dbusdockadaptors.h \ item/components/previewcontainer.h \ item/components/previewwidget.h \ - item/components/_previewcontainer.h + item/components/_previewcontainer.h \ + item/components/appsnapshot.h dbus_service.files += com.deepin.dde.Dock.service dbus_service.path = /usr/share/dbus-1/services diff --git a/frame/item/components/_previewcontainer.cpp b/frame/item/components/_previewcontainer.cpp index b73b5820c..932a2bec2 100644 --- a/frame/item/components/_previewcontainer.cpp +++ b/frame/item/components/_previewcontainer.cpp @@ -1,5 +1,8 @@ #include "_previewcontainer.h" +#define FIXED_WIDTH 200 +#define FIXED_HEIGHT 130 + _PreviewContainer::_PreviewContainer(QWidget *parent) : QWidget(parent), @@ -14,7 +17,25 @@ _PreviewContainer::_PreviewContainer(QWidget *parent) void _PreviewContainer::setWindowInfos(const WindowDict &infos) { - qDebug() << infos; + // check removed window + for (auto it(m_snapshots.begin()); it != m_snapshots.end();) + { + if (!infos.contains(it.key())) + { + 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()); + } + + adjustSize(); } void _PreviewContainer::updateLayoutDirection(const Dock::Position dockPos) @@ -23,4 +44,30 @@ void _PreviewContainer::updateLayoutDirection(const Dock::Position dockPos) m_windowListLayout->setDirection(QBoxLayout::LeftToRight); else m_windowListLayout->setDirection(QBoxLayout::TopToBottom); + + adjustSize(); +} + +void _PreviewContainer::adjustSize() +{ + const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight; + const int count = m_snapshots.size(); + + if (horizontal) + { + setFixedHeight(FIXED_HEIGHT); + setFixedWidth(FIXED_WIDTH * count); + } else { + setFixedWidth(FIXED_WIDTH); + setFixedHeight(FIXED_HEIGHT * count); + } +} + +void _PreviewContainer::appendSnapWidget(const WId wid) +{ + AppSnapshot *snap = new AppSnapshot; + + m_windowListLayout->addWidget(snap); + + m_snapshots.insert(wid, snap); } diff --git a/frame/item/components/_previewcontainer.h b/frame/item/components/_previewcontainer.h index cf44831e0..97e269287 100644 --- a/frame/item/components/_previewcontainer.h +++ b/frame/item/components/_previewcontainer.h @@ -3,9 +3,11 @@ #include #include +#include #include "dbus/dbusdockentry.h" #include "constants.h" +#include "appsnapshot.h" #include @@ -31,12 +33,15 @@ public slots: void updateLayoutDirection(const Dock::Position dockPos); private: - QMap m_windows; + void adjustSize(); + void appendSnapWidget(const WId wid); - DWindowManagerHelper *m_wmHelper; +private: + QMap m_snapshots; QBoxLayout *m_windowListLayout; + DWindowManagerHelper *m_wmHelper; }; #endif // _PREVIEWCONTAINER_H diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp new file mode 100644 index 000000000..aa59cab22 --- /dev/null +++ b/frame/item/components/appsnapshot.cpp @@ -0,0 +1,7 @@ +#include "appsnapshot.h" + +AppSnapshot::AppSnapshot(QWidget *parent) + : QWidget(parent) +{ + +} diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h new file mode 100644 index 000000000..6039f7e56 --- /dev/null +++ b/frame/item/components/appsnapshot.h @@ -0,0 +1,14 @@ +#ifndef APPSNAPSHOT_H +#define APPSNAPSHOT_H + +#include + +class AppSnapshot : public QWidget +{ + Q_OBJECT + +public: + explicit AppSnapshot(QWidget *parent = 0); +}; + +#endif // APPSNAPSHOT_H