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 000000000..934c6f323 Binary files /dev/null and b/frame/item/resources/arrow_down_normal.png differ diff --git a/frame/item/resources/arrow_up_normal.png b/frame/item/resources/arrow_up_normal.png new file mode 100644 index 000000000..41618ff5a Binary files /dev/null and b/frame/item/resources/arrow_up_normal.png differ diff --git a/frame/panel/mainpanel.cpp b/frame/panel/mainpanel.cpp index c80a38f35..a2a917128 100644 --- a/frame/panel/mainpanel.cpp +++ b/frame/panel/mainpanel.cpp @@ -105,7 +105,7 @@ void MainPanel::updateDockDisplayMode(const DisplayMode displayMode) // const QList 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 {