From 010825fe07c238fca872071a8691c297245e892a Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 1 Oct 2010 23:26:17 +0200 Subject: [PATCH] bat: Try to implement drag&drop for file selection --- bacula/src/qt-console/restore/brestore.cpp | 67 ++++++++++++++++++++++ bacula/src/qt-console/restore/brestore.ui | 19 +++++- bacula/src/qt-console/restore/restore.h | 21 ++++++- 3 files changed, 103 insertions(+), 4 deletions(-) diff --git a/bacula/src/qt-console/restore/brestore.cpp b/bacula/src/qt-console/restore/brestore.cpp index abd1b7ec26..9079218ab8 100644 --- a/bacula/src/qt-console/restore/brestore.cpp +++ b/bacula/src/qt-console/restore/brestore.cpp @@ -316,3 +316,70 @@ void bRestore::setupPage() bRestore::~bRestore() { } + +void bRestoreTable::mousePressEvent(QMouseEvent *event) +{ + QTableWidget::mousePressEvent(event); + + if (event->button() == Qt::LeftButton) { + dragStartPosition = event->pos(); + } +} + +void bRestoreTable::mouseMoveEvent(QMouseEvent *event) +{ + if (!(event->buttons() & Qt::LeftButton)) { + QTableWidget::mouseMoveEvent(event); + return; + } + if ((event->pos() - dragStartPosition).manhattanLength() + < QApplication::startDragDistance()) + { + QTableWidget::mouseMoveEvent(event); + return; + } + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setText(QString("test")); + qDebug() << "1 ========" << mimeData->formats() << "========"; + drag->setMimeData(mimeData); + drag->exec(Qt::CopyAction | Qt::MoveAction); +} + +void bRestoreTable::dragEnterEvent(QDragEnterEvent *event) +{ + Pmsg0(0, "dragEnterEvent\n"); + qDebug() << "2 ========" << event->mimeData()->formats() << "========"; + + if (event->mimeData()->hasText()) { + qDebug() << event->mimeData()->text(); + event->acceptProposedAction(); + } else { + event->ignore(); + } +} + +// void bRestoreTable::dragMoveEvent(QDragMoveEvent *event) +// { +// Pmsg0(0, "dragMoveEvent\n"); +// if (event->mimeData()->hasText()) { +// event->acceptProposedAction(); +// } else { +// event->ignore(); +// } +// } +// +void bRestoreTable::dropEvent(QDropEvent *event) +{ + Pmsg0(0, "dropEvent\n"); + qDebug() << "3 ========" << event->mimeData()->formats() << "========"; + if (event->mimeData()->hasText()) { + qDebug() << event->mimeData()->text(); + event->acceptProposedAction(); + } else { + event->ignore(); + } +} + diff --git a/bacula/src/qt-console/restore/brestore.ui b/bacula/src/qt-console/restore/brestore.ui index 706e532ae0..d2ff1e0bdc 100644 --- a/bacula/src/qt-console/restore/brestore.ui +++ b/bacula/src/qt-console/restore/brestore.ui @@ -47,7 +47,7 @@ 9 - + 5 @@ -119,7 +119,7 @@ 9 - + 0 @@ -244,10 +244,16 @@ p, li { white-space: pre-wrap; } - + true + + QAbstractItemView::DropOnly + + + false + Data @@ -378,6 +384,13 @@ p, li { white-space: pre-wrap; } + + + bRestoreTable + QTableWidget +
restore.h
+
+
diff --git a/bacula/src/qt-console/restore/restore.h b/bacula/src/qt-console/restore/restore.h index b57b998f00..a65d637ee6 100644 --- a/bacula/src/qt-console/restore/restore.h +++ b/bacula/src/qt-console/restore/restore.h @@ -36,6 +36,26 @@ #include #include "pages.h" + + +class bRestoreTable : public QTableWidget +{ + Q_OBJECT +private: + QPoint dragStartPosition; +public: + bRestoreTable(QWidget *parent) + : QTableWidget(parent) + { + } + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + + void dragEnterEvent(QDragEnterEvent *event); +// void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); +}; + #include "ui_brestore.h" #include "ui_restore.h" #include "ui_prerestore.h" @@ -113,7 +133,6 @@ private: QString m_splitText; }; - class bRestore : public Pages, public Ui::bRestoreForm { Q_OBJECT -- 2.39.5