]> git.sur5r.net Git - bacula/bacula/commitdiff
bat: Try to implement drag&drop for file selection
authorEric Bollengier <eric@eb.homelinux.org>
Fri, 1 Oct 2010 21:26:17 +0000 (23:26 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Wed, 6 Oct 2010 09:10:56 +0000 (11:10 +0200)
bacula/src/qt-console/restore/brestore.cpp
bacula/src/qt-console/restore/brestore.ui
bacula/src/qt-console/restore/restore.h

index abd1b7ec265a9151ad0dea843abbe177b4698808..9079218ab86ae4c2e7da45df09d22a877b189838 100644 (file)
@@ -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();
+   }
+}
+
index 706e532ae0a629626084aed05e81773cf61244f2..d2ff1e0bdc0617bca561ff421e9a5d30902e19e6 100644 (file)
@@ -47,7 +47,7 @@
          <number>9</number>
         </property>
         <item>
-         <widget class="QTableWidget" name="FileList">
+         <widget class="bRestoreTable" name="FileList">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
             <horstretch>5</horstretch>
          <number>9</number>
         </property>
         <item>
-         <widget class="QTableWidget" name="FileRevisions">
+         <widget class="bRestoreTable" name="FileRevisions">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
             <horstretch>0</horstretch>
@@ -244,10 +244,16 @@ p, li { white-space: pre-wrap; }
         </layout>
        </item>
        <item>
-        <widget class="QTableWidget" name="RestoreList">
+        <widget class="bRestoreTable" name="RestoreList">
          <property name="acceptDrops">
           <bool>true</bool>
          </property>
+         <property name="dragDropMode">
+          <enum>QAbstractItemView::DropOnly</enum>
+         </property>
+         <attribute name="verticalHeaderVisible">
+          <bool>false</bool>
+         </attribute>
          <column>
           <property name="text">
            <string>Data</string>
@@ -378,6 +384,13 @@ p, li { white-space: pre-wrap; }
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>bRestoreTable</class>
+   <extends>QTableWidget</extends>
+   <header>restore.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>
index b57b998f0031b41202d82c535a451cedfb71691f..a65d637ee67d8994069049d4ebd611e88428dc79 100644 (file)
 
 #include <QtGui>
 #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