tableWidget->setColumnWidth(TYPE, 60);
tableWidget->setColumnWidth(SIZE, 125);
tableWidget->setColumnWidth(MODIFIED, 175);
+ tableWidget->setDragDropMode(QAbstractItemView::DragDrop);
+ tableWidget->setDragEnabled(true);
+ tableWidget->setDragDropOverwriteMode(true);
+ tableWidget->setAcceptDrops(true);
connect(pushButtonUp, SIGNAL(clicked()), SLOT(pushButtonUpClicked()));
connect(pushButtonRoot, SIGNAL(clicked()), SLOT(pushButtonRootClicked()));
connect(tableWidget, SIGNAL(cellDoubleClicked(int, int)), this,
return rc;
}
+/**
+ * Processes the dragging operation of the selected files in the table widget.
+ */
+void ReFileTable::fileDragging(){
+ QDrag *drag = new QDrag(this);
+ QMimeData *mimeData = new QMimeData;
+ QList < QUrl > urls;
+ QList < QTableWidgetSelectionRange > ranges =
+ tableWidget->selectedRanges();
+ QList <QTableWidgetSelectionRange>::iterator it;
+ int files = 0;
+ int dirs = 0;
+ bool isDir = false;
+ for (it = ranges.begin(); it != ranges.end(); ++it){
+ for (int row = (*it).topRow(); row <= (*it).bottomRow(); row++){
+ isDir = cellAsText(row, SIZE).isEmpty();
+ QUrl url(buildAbsPath(row, true, true));
+ urls.append(url);
+ if (isDir)
+ dirs++;
+ else
+ files++;
+ }
+ }
+ if (urls.size() > 0){
+ mimeData->setUrls(urls);
+ drag->setMimeData(mimeData);
+ QPixmap image(200, 30);
+ QPainter painter(&image);
+ QString msg;
+ if (urls.size() == 1)
+ msg = tr("copy ") + ReFileUtils::nodeOf(urls.at(0).toString());
+ else if (files > 0 && dirs > 0)
+ msg = tr("copy %1 file(s) and %2 dir(s)").arg(files).arg(dirs);
+ else if (files > 0)
+ msg = tr("copy %1 file(s)").arg(files);
+ else
+ msg = tr("copy %1 dirs(s)").arg(dirs);
+
+ painter.fillRect(image.rect(), Qt::white);
+ painter.drawText(10, 20, msg);
+ drag->setPixmap(image);
+
+ Qt::DropAction dropAction = drag->exec(Qt::CopyAction);
+ }
+}
+
/**
* Copies the selected files into the clipboard.
*
say(LOG_INFO,
tr("%1 entry/entries copied to clipboard").arg(urls.length()));
}
+/**
+ * Handles the event "drag enter".
+ *
+ * @param event the event data
+ */
+void ReFileTable::dragEnterEvent(QDragEnterEvent *event)
+{
+ if (event->mimeData()->hasFormat("text/uri-list"))
+ event->acceptProposedAction();
+}
+
+void ReFileTable::dropEvent(QDropEvent *event)
+{
+ QList<QUrl> urls = event->mimeData()->urls();
+ if (! urls.isEmpty()){
+ QString fileName = urls.first().toLocalFile();
+ say(LOG_INFO, "copy " + fileName);
+ }
+}
/**
* Fills the table with the file data of the filesystem.