From ab5a88f22c0da911cb1f95b0ce1b00e5c9f4cbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Mon, 8 Aug 2016 13:55:00 +0800 Subject: [PATCH] add container widget Change-Id: I3ed54a4fe6b947205a78a70d3abc7eb902317981 --- frame/controller/dockitemcontroller.cpp | 4 +- frame/controller/dockitemcontroller.h | 2 + frame/frame.pro | 6 ++- frame/item/components/containerwidget.cpp | 13 ++++++ frame/item/components/containerwidget.h | 16 +++++++ frame/item/containeritem.cpp | 49 +++++++++++++++++++-- frame/item/containeritem.h | 15 +++++++ frame/item/pluginsitem.cpp | 6 ++- frame/item/resources.qrc | 2 + frame/item/resources/arrow_down_normal.png | Bin 0 -> 301 bytes frame/item/resources/arrow_up_normal.png | Bin 0 -> 283 bytes frame/panel/mainpanel.cpp | 7 +-- interfaces/constants.h | 2 + 13 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 frame/item/components/containerwidget.cpp create mode 100644 frame/item/components/containerwidget.h create mode 100644 frame/item/resources/arrow_down_normal.png create mode 100644 frame/item/resources/arrow_up_normal.png diff --git a/frame/controller/dockitemcontroller.cpp b/frame/controller/dockitemcontroller.cpp index c58b5966b..5c94c9d07 100644 --- a/frame/controller/dockitemcontroller.cpp +++ b/frame/controller/dockitemcontroller.cpp @@ -89,7 +89,8 @@ DockItemController::DockItemController(QObject *parent) : QObject(parent), m_appInter(new DBusDock(this)), m_pluginsInter(new DockPluginsController(this)), - m_placeholderItem(new StretchItem) + m_placeholderItem(new StretchItem), + m_containerItem(new ContainerItem) { // m_placeholderItem->hide(); @@ -97,6 +98,7 @@ DockItemController::DockItemController(QObject *parent) for (auto entry : m_appInter->entries()) m_itemList.append(new AppItem(entry)); m_itemList.append(m_placeholderItem); + m_itemList.append(m_containerItem); connect(m_appInter, &DBusDock::EntryAdded, this, &DockItemController::appItemAdded); connect(m_appInter, &DBusDock::EntryRemoved, this, static_cast(&DockItemController::appItemRemoved)); diff --git a/frame/controller/dockitemcontroller.h b/frame/controller/dockitemcontroller.h index bb00c04c8..6fb18a7a5 100644 --- a/frame/controller/dockitemcontroller.h +++ b/frame/controller/dockitemcontroller.h @@ -8,6 +8,7 @@ #include "item/stretchitem.h" #include "item/appitem.h" #include "item/placeholderitem.h" +#include "item/containeritem.h" #include @@ -48,6 +49,7 @@ private: DBusDock *m_appInter; DockPluginsController *m_pluginsInter; StretchItem *m_placeholderItem; + ContainerItem *m_containerItem; static DockItemController *INSTANCE; }; diff --git a/frame/frame.pro b/frame/frame.pro index 4c0230c6e..bdc5f2da1 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -34,7 +34,8 @@ SOURCES += main.cpp \ item/stretchitem.cpp \ item/placeholderitem.cpp \ controller/dockpluginloader.cpp \ - item/containeritem.cpp + item/containeritem.cpp \ + item/components/containerwidget.cpp HEADERS += \ window/mainwindow.h \ @@ -60,7 +61,8 @@ HEADERS += \ item/stretchitem.h \ item/placeholderitem.h \ controller/dockpluginloader.h \ - item/containeritem.h + item/containeritem.h \ + item/components/containerwidget.h dbus_service.files += com.deepin.dde.dock.service dbus_service.path = /usr/share/dbus-1/services diff --git a/frame/item/components/containerwidget.cpp b/frame/item/components/containerwidget.cpp new file mode 100644 index 000000000..f441053f4 --- /dev/null +++ b/frame/item/components/containerwidget.cpp @@ -0,0 +1,13 @@ +#include "containerwidget.h" + +#include + +ContainerWidget::ContainerWidget(QWidget *parent) + : QWidget(parent) +{ +} + +QSize ContainerWidget::sizeHint() const +{ + return QSize(80, 40); +} diff --git a/frame/item/components/containerwidget.h b/frame/item/components/containerwidget.h new file mode 100644 index 000000000..ea9ca8663 --- /dev/null +++ b/frame/item/components/containerwidget.h @@ -0,0 +1,16 @@ +#ifndef CONTAINERWIDGET_H +#define CONTAINERWIDGET_H + +#include + +class ContainerWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ContainerWidget(QWidget *parent = 0); + + QSize sizeHint() const; +}; + +#endif // CONTAINERWIDGET_H diff --git a/frame/item/containeritem.cpp b/frame/item/containeritem.cpp index 3a95bc111..8bfe8ec79 100644 --- a/frame/item/containeritem.cpp +++ b/frame/item/containeritem.cpp @@ -1,7 +1,50 @@ +#include "constants.h" #include "containeritem.h" -ContainerItem::ContainerItem(QWidget *parent) - : DockItem(parent) -{ +#include +ContainerItem::ContainerItem(QWidget *parent) + : DockItem(parent), + m_icon(":/indicator/resources/arrow_up_normal.png"), + m_containerWidget(new ContainerWidget(this)) +{ + m_containerWidget->setVisible(false); + + setAcceptDrops(true); +} + +void ContainerItem::dragEnterEvent(QDragEnterEvent *e) +{ + if (!e->mimeData()->hasFormat(DOCK_PLUGIN_MIME)) + return; + + e->accept(); +} + +void ContainerItem::dragMoveEvent(QDragMoveEvent *e) +{ + Q_UNUSED(e); + + return; +} + +void ContainerItem::paintEvent(QPaintEvent *e) +{ + DockItem::paintEvent(e); + + QPainter painter(this); + painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon); +} + +void ContainerItem::mouseReleaseEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton) + return showPopupApplet(m_containerWidget); + + return DockItem::mouseReleaseEvent(e); +} + +QSize ContainerItem::sizeHint() const +{ + return QSize(24, 24); } diff --git a/frame/item/containeritem.h b/frame/item/containeritem.h index 3c138f36f..a7e4cfd64 100644 --- a/frame/item/containeritem.h +++ b/frame/item/containeritem.h @@ -2,6 +2,9 @@ #define CONTAINERITEM_H #include "dockitem.h" +#include "components/containerwidget.h" + +#include class ContainerItem : public DockItem { @@ -11,6 +14,18 @@ public: explicit ContainerItem(QWidget *parent = 0); inline ItemType itemType() const {return Container;} + +protected: + void dragEnterEvent(QDragEnterEvent *e); + void dragMoveEvent(QDragMoveEvent *e); + void paintEvent(QPaintEvent *e); + void mouseReleaseEvent(QMouseEvent *e); + QSize sizeHint() const; + +private: + QPixmap m_icon; + + ContainerWidget *m_containerWidget; }; #endif // CONTAINERITEM_H diff --git a/frame/item/pluginsitem.cpp b/frame/item/pluginsitem.cpp index e90838097..34edbb6da 100644 --- a/frame/item/pluginsitem.cpp +++ b/frame/item/pluginsitem.cpp @@ -1,3 +1,4 @@ +#include "constants.h" #include "pluginsitem.h" #include "pluginsiteminterface.h" @@ -116,10 +117,13 @@ void PluginsItem::startDrag() m_draging = true; update(); + QMimeData *mime = new QMimeData; + mime->setData(DOCK_PLUGIN_MIME, m_itemKey.toStdString().c_str()); + QDrag *drag = new QDrag(this); drag->setPixmap(pixmap); drag->setHotSpot(pixmap.rect().center()); - drag->setMimeData(new QMimeData); + drag->setMimeData(mime); emit dragStarted(); const Qt::DropAction result = drag->exec(Qt::MoveAction); diff --git a/frame/item/resources.qrc b/frame/item/resources.qrc index f9318f8cd..dc87fc058 100644 --- a/frame/item/resources.qrc +++ b/frame/item/resources.qrc @@ -4,5 +4,7 @@ resources/indicator.png resources/indicator_ver.png resources/indicator_active_ver.png + resources/arrow_up_normal.png + resources/arrow_down_normal.png diff --git a/frame/item/resources/arrow_down_normal.png b/frame/item/resources/arrow_down_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..934c6f323179ecce0c452ea5a36aaaad0c32241d GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP*AeO zHKHUqKdq!Zu_%?nF(p4KRlzeiF+DXXH8G{K@MNkDP|+?=7srr_TSsWZ74jz zo6sP2fcZ#q!w#k+$J-sV7GzaA)QC;!Sg|6bAR{B=$87WbeFjEGO(JCprFzQAt`QLt z`#L%}&cC|4nxDBFVdQ&MBb@0KV90H~;_u literal 0 HcmV?d00001 diff --git a/frame/item/resources/arrow_up_normal.png b/frame/item/resources/arrow_up_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..41618ff5ab73f4e476aaa0b22f0ab824bca89cf8 GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP*AeO zHKHUqKdq!Zu_%?nF(p4KRlzeiF+DXXH8G{K@MNkDP|*rc7srr_TSsWZ73{| zK5*hh1mmK{EUSW*i3gWk>gedmpE{Pw!EJXoD=SM#!LFnCv;dF(g6y`&= itemList = m_itemController->itemList(); // for (auto item : itemList) // { -// if (item->itemType() == DockItem::Stretch) +// if (item->itemType() == DockItem::Container) // item->setVisible(displayMode == Dock::Efficient); // } @@ -353,9 +353,10 @@ void MainPanel::adjustItemSize() for (auto item : itemList) { - if (item->itemType() == DockItem::Stretch) + const DockItem::ItemType itemType = item->itemType(); + if (itemType == DockItem::Stretch || itemType == DockItem::Container) continue; - if (item->itemType() == DockItem::Plugins) + if (itemType == DockItem::Plugins) if (m_displayMode != Dock::Fashion) continue; diff --git a/interfaces/constants.h b/interfaces/constants.h index 9eb748cca..affbf127a 100644 --- a/interfaces/constants.h +++ b/interfaces/constants.h @@ -5,6 +5,8 @@ namespace Dock { +#define DOCK_PLUGIN_MIME "dock/plugin" + #define PROP_DISPLAY_MODE "DisplayMode" enum DisplayMode {