add container widget

Change-Id: I3ed54a4fe6b947205a78a70d3abc7eb902317981
This commit is contained in:
石博文 2016-08-08 13:55:00 +08:00
parent 66f9aff697
commit ab5a88f22c
Notes: Deepin Code Review 2016-08-08 06:36:12 +00:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Mon, 08 Aug 2016 06:36:11 +0000
Reviewed-on: https://cr.deepin.io/14966
Project: dde/dde-dock
Branch: refs/heads/master
13 changed files with 112 additions and 10 deletions

View File

@ -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<void (DockItemController::*)(const QString &)>(&DockItemController::appItemRemoved));

View File

@ -8,6 +8,7 @@
#include "item/stretchitem.h"
#include "item/appitem.h"
#include "item/placeholderitem.h"
#include "item/containeritem.h"
#include <QObject>
@ -48,6 +49,7 @@ private:
DBusDock *m_appInter;
DockPluginsController *m_pluginsInter;
StretchItem *m_placeholderItem;
ContainerItem *m_containerItem;
static DockItemController *INSTANCE;
};

View File

@ -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

View File

@ -0,0 +1,13 @@
#include "containerwidget.h"
#include <QDebug>
ContainerWidget::ContainerWidget(QWidget *parent)
: QWidget(parent)
{
}
QSize ContainerWidget::sizeHint() const
{
return QSize(80, 40);
}

View File

@ -0,0 +1,16 @@
#ifndef CONTAINERWIDGET_H
#define CONTAINERWIDGET_H
#include <QWidget>
class ContainerWidget : public QWidget
{
Q_OBJECT
public:
explicit ContainerWidget(QWidget *parent = 0);
QSize sizeHint() const;
};
#endif // CONTAINERWIDGET_H

View File

@ -1,7 +1,50 @@
#include "constants.h"
#include "containeritem.h"
ContainerItem::ContainerItem(QWidget *parent)
: DockItem(parent)
{
#include <QPainter>
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);
}

View File

@ -2,6 +2,9 @@
#define CONTAINERITEM_H
#include "dockitem.h"
#include "components/containerwidget.h"
#include <QPixmap>
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

View File

@ -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);

View File

@ -4,5 +4,7 @@
<file>resources/indicator.png</file>
<file>resources/indicator_ver.png</file>
<file>resources/indicator_active_ver.png</file>
<file>resources/arrow_up_normal.png</file>
<file>resources/arrow_down_normal.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

View File

@ -105,7 +105,7 @@ void MainPanel::updateDockDisplayMode(const DisplayMode displayMode)
// const QList<DockItem *> 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;

View File

@ -5,6 +5,8 @@
namespace Dock {
#define DOCK_PLUGIN_MIME "dock/plugin"
#define PROP_DISPLAY_MODE "DisplayMode"
enum DisplayMode
{