From 1331a43336ad20bdd44508fdf00c7682c07a032b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Tue, 7 Jun 2016 16:01:37 +0800 Subject: [PATCH] add drag & drop Change-Id: I2921e9d443e470556e24115afed0146218de8c96 --- item/appitem.cpp | 12 +++++++++++- item/appitem.h | 2 ++ panel/mainpanel.cpp | 18 ++++++++++++++++++ panel/mainpanel.h | 4 ++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/item/appitem.cpp b/item/appitem.cpp index 73fae119b..92de2b643 100644 --- a/item/appitem.cpp +++ b/item/appitem.cpp @@ -19,7 +19,8 @@ uint AppItem::ActiveWindowId = 0; AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) : DockItem(App, parent), - m_itemEntry(new DBusDockEntry(entry.path(), this)) + m_itemEntry(new DBusDockEntry(entry.path(), this)), + m_draging(false) { initClientManager(); @@ -32,6 +33,9 @@ void AppItem::paintEvent(QPaintEvent *e) { DockItem::paintEvent(e); + if (m_draging) + return; + const QRect itemRect = rect(); const int iconSize = std::min(itemRect.width(), itemRect.height()); @@ -90,6 +94,9 @@ void AppItem::mouseMoveEvent(QMouseEvent *e) void AppItem::startDrag() { + m_draging = true; + update(); + QPixmap pixmap(25, 25); pixmap.fill(Qt::red); @@ -101,6 +108,9 @@ void AppItem::startDrag() const Qt::DropAction result = drag->exec(Qt::MoveAction); qDebug() << result; + + m_draging = false; + update(); } void AppItem::initClientManager() diff --git a/item/appitem.h b/item/appitem.h index 8cf81ee2b..ee45459b0 100644 --- a/item/appitem.h +++ b/item/appitem.h @@ -25,6 +25,8 @@ private: private: DBusDockEntry *m_itemEntry; + bool m_draging; + QMap m_data; QMap m_windows; diff --git a/panel/mainpanel.cpp b/panel/mainpanel.cpp index ec4c6b858..8c8be7fb2 100644 --- a/panel/mainpanel.cpp +++ b/panel/mainpanel.cpp @@ -1,6 +1,7 @@ #include "mainpanel.h" #include +#include MainPanel::MainPanel(QWidget *parent) : QFrame(parent), @@ -8,6 +9,7 @@ MainPanel::MainPanel(QWidget *parent) m_itemController(DockItemController::instance(this)) { + setAcceptDrops(true); setObjectName("MainPanel"); setStyleSheet("QWidget #MainPanel {" "border:none;" @@ -40,6 +42,22 @@ void MainPanel::resizeEvent(QResizeEvent *e) adjustItemSize(); } +void MainPanel::dragEnterEvent(QDragEnterEvent *e) +{ + // TODO: check + e->accept(); +} + +void MainPanel::dragMoveEvent(QDragMoveEvent *e) +{ + qDebug() << e; +} + +void MainPanel::dropEvent(QDropEvent *e) +{ + qDebug() << e; +} + void MainPanel::adjustItemSize() { const QList itemList = m_itemController->itemList(); diff --git a/panel/mainpanel.h b/panel/mainpanel.h index 29412adb7..f62ef2bc8 100644 --- a/panel/mainpanel.h +++ b/panel/mainpanel.h @@ -18,6 +18,10 @@ public: private: void resizeEvent(QResizeEvent *e); + void dragEnterEvent(QDragEnterEvent *e); + void dragMoveEvent(QDragMoveEvent *e); + void dropEvent(QDropEvent *e); + void adjustItemSize(); private: