add drag & drop

Change-Id: I2921e9d443e470556e24115afed0146218de8c96
This commit is contained in:
石博文 2016-06-07 16:01:37 +08:00 committed by Hualet Wang
parent 775271b6fd
commit 1331a43336
4 changed files with 35 additions and 1 deletions

View File

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

View File

@ -25,6 +25,8 @@ private:
private:
DBusDockEntry *m_itemEntry;
bool m_draging;
QMap<QString, QString> m_data;
QMap<uint, QString> m_windows;

View File

@ -1,6 +1,7 @@
#include "mainpanel.h"
#include <QBoxLayout>
#include <QDragEnterEvent>
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<DockItem *> itemList = m_itemController->itemList();

View File

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