Browse Source

- Added drag'n Drop from torrent list to labels (for torrent labeling)

- Fix label counters update in some cases
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
18bd3b855c
  1. 20
      src/GUI.cpp
  2. 1
      src/GUI.h
  3. 55
      src/transferlistfilterswidget.h
  4. 2
      src/transferlistwidget.cpp
  5. 2
      src/transferlistwidget.h

20
src/GUI.cpp

@ -598,9 +598,29 @@ void GUI::dragEnterEvent(QDragEnterEvent *event) {
foreach(const QString &mime, event->mimeData()->formats()){ foreach(const QString &mime, event->mimeData()->formats()){
qDebug("mimeData: %s", mime.toLocal8Bit().data()); qDebug("mimeData: %s", mime.toLocal8Bit().data());
} }
if (event->mimeData()->hasFormat("application/x-qstandarditemmodeldatalist")) {
if(childAt(event->pos()) == transferListFilters) {
qDebug("DragEnterEvent: torrent to filter list, accepting...");
event->acceptProposedAction();
}
} else {
if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) { if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) {
event->acceptProposedAction(); event->acceptProposedAction();
} }
}
}
void GUI::dragMoveEvent(QDragMoveEvent *event) {
if (event->mimeData()->hasFormat("application/x-qstandarditemmodeldatalist")) {
if(childAt(event->pos()) == transferListFilters) {
qDebug("DragMoveEvent: torrent to filter list, accepting...");
event->acceptProposedAction();
}
} else {
if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) {
event->acceptProposedAction();
}
}
} }
/***************************************************** /*****************************************************

1
src/GUI.h

@ -97,6 +97,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
// GUI related slots // GUI related slots
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void toggleVisibility(QSystemTrayIcon::ActivationReason e); void toggleVisibility(QSystemTrayIcon::ActivationReason e);
void on_actionAbout_triggered(); void on_actionAbout_triggered();
void on_actionCreate_torrent_triggered(); void on_actionCreate_torrent_triggered();

55
src/transferlistfilterswidget.h

@ -39,10 +39,43 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QMenu> #include <QMenu>
#include <QInputDialog> #include <QInputDialog>
#include <QDragMoveEvent>
#include "transferlistdelegate.h" #include "transferlistdelegate.h"
#include "transferlistwidget.h" #include "transferlistwidget.h"
class LabelFiltersList: public QListWidget {
Q_OBJECT
public:
LabelFiltersList(QWidget *parent): QListWidget(parent){
// Accept drop
setAcceptDrops(true);
}
signals:
void torrentDropped(int label_row);
protected:
void dragMoveEvent(QDragMoveEvent* event) {
//qDebug("filters, dragmoveevent");
if(itemAt(event->pos()) && row(itemAt(event->pos())) > 0) {
//qDebug("Name: %s", itemAt(event->pos())->text().toLocal8Bit().data());
event->acceptProposedAction();
} else {
event->ignore();
}
}
void dropEvent(QDropEvent *event) {
qDebug("Drop Event in labels list");
if(itemAt(event->pos())) {
emit torrentDropped(row(itemAt(event->pos())));
}
event->ignore();
}
};
class TransferListFiltersWidget: public QFrame { class TransferListFiltersWidget: public QFrame {
Q_OBJECT Q_OBJECT
@ -50,7 +83,7 @@ private:
QStringList customLabels; QStringList customLabels;
QList<int> labelCounters; QList<int> labelCounters;
QListWidget* statusFilters; QListWidget* statusFilters;
QListWidget* labelFilters; LabelFiltersList* labelFilters;
QVBoxLayout* vLayout; QVBoxLayout* vLayout;
TransferListWidget *transferList; TransferListWidget *transferList;
int nb_labeled; int nb_labeled;
@ -60,9 +93,9 @@ public:
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) { TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) {
// Construct lists // Construct lists
vLayout = new QVBoxLayout(); vLayout = new QVBoxLayout();
statusFilters = new QListWidget(); statusFilters = new QListWidget(this);
vLayout->addWidget(statusFilters); vLayout->addWidget(statusFilters);
labelFilters = new QListWidget(); labelFilters = new LabelFiltersList(this);
vLayout->addWidget(labelFilters); vLayout->addWidget(labelFilters);
setLayout(vLayout); setLayout(vLayout);
// Limit status filters list height // Limit status filters list height
@ -90,8 +123,10 @@ public:
connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int))); connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int)));
connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint, uint))); connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint, uint)));
connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int))); connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int)));
connect(labelFilters, SIGNAL(torrentDropped(int)), this, SLOT(torrentDropped(int)));
connect(transferList, SIGNAL(torrentAdded(QModelIndex)), this, SLOT(torrentAdded(QModelIndex))); connect(transferList, SIGNAL(torrentAdded(QModelIndex)), this, SLOT(torrentAdded(QModelIndex)));
connect(transferList, SIGNAL(torrentAboutToBeRemoved(QModelIndex)), this, SLOT(torrentAboutToBeDeleted(QModelIndex))); connect(transferList, SIGNAL(torrentAboutToBeRemoved(QModelIndex)), this, SLOT(torrentAboutToBeDeleted(QModelIndex)));
connect(transferList, SIGNAL(torrentChangedLabel(QString,QString)), this, SLOT(torrentChangedLabel(QString, QString)));
// Load settings // Load settings
loadSettings(); loadSettings();
@ -153,6 +188,16 @@ protected slots:
statusFilters->item(FILTER_INACTIVE)->setData(Qt::DisplayRole, tr("Inactive")+" ("+QString::number(nb_inactive)+")"); statusFilters->item(FILTER_INACTIVE)->setData(Qt::DisplayRole, tr("Inactive")+" ("+QString::number(nb_inactive)+")");
} }
void torrentDropped(int row) {
Q_ASSERT(row > 0);
if(row == 1) {
transferList->setSelectionLabel("");
} else {
QString label = customLabels.at(row-2);
transferList->setSelectionLabel(label);
}
}
void addLabel(QString label) { void addLabel(QString label) {
if(label.trimmed().isEmpty()) return; if(label.trimmed().isEmpty()) return;
if(customLabels.contains(label)) return; if(customLabels.contains(label)) return;
@ -214,12 +259,14 @@ protected slots:
} }
void torrentChangedLabel(QString old_label, QString new_label) { void torrentChangedLabel(QString old_label, QString new_label) {
qDebug("Torrent label changed from %s to %s", old_label.toLocal8Bit().data(), new_label.toLocal8Bit().data());
if(!old_label.isEmpty()) { if(!old_label.isEmpty()) {
int i = customLabels.indexOf(old_label); int i = customLabels.indexOf(old_label);
int new_count = labelCounters[i]-1; int new_count = labelCounters[i]-1;
Q_ASSERT(new_count >= 0); Q_ASSERT(new_count >= 0);
labelCounters.replace(i, new_count); labelCounters.replace(i, new_count);
labelFilters->item(i+2)->setText(old_label + " ("+ QString::number(new_count) +")"); labelFilters->item(i+2)->setText(old_label + " ("+ QString::number(new_count) +")");
--nb_labeled;
} }
if(!new_label.isEmpty()) { if(!new_label.isEmpty()) {
if(!customLabels.contains(new_label)) if(!customLabels.contains(new_label))
@ -228,7 +275,9 @@ protected slots:
int new_count = labelCounters[i]+1; int new_count = labelCounters[i]+1;
labelCounters.replace(i, new_count); labelCounters.replace(i, new_count);
labelFilters->item(i+2)->setText(new_label + " ("+ QString::number(new_count) +")"); labelFilters->item(i+2)->setText(new_label + " ("+ QString::number(new_count) +")");
++nb_labeled;
} }
updateStickyLabelCounters();
} }
void torrentAdded(QModelIndex index) { void torrentAdded(QModelIndex index) {

2
src/transferlistwidget.cpp

@ -52,7 +52,6 @@
TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent *_BTSession): TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent *_BTSession):
QTreeView(parent), BTSession(_BTSession), main_window(main_window) { QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
// Create and apply delegate // Create and apply delegate
listDelegate = new TransferListDelegate(this); listDelegate = new TransferListDelegate(this);
@ -103,6 +102,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, Bittor
setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionMode(QAbstractItemView::ExtendedSelection);
setItemsExpandable(false); setItemsExpandable(false);
setAutoScroll(true); setAutoScroll(true);
setDragDropMode(QAbstractItemView::DragOnly);
hideColumn(TR_PRIORITY); hideColumn(TR_PRIORITY);
//hideColumn(TR_LABEL); //hideColumn(TR_LABEL);

2
src/transferlistwidget.h

@ -88,7 +88,6 @@ protected slots:
#endif #endif
void toggleSelectedTorrentsSequentialDownload(); void toggleSelectedTorrentsSequentialDownload();
void toggleSelectedFirstLastPiecePrio(); void toggleSelectedFirstLastPiecePrio();
void setSelectionLabel(QString label);
void askNewLabelForSelection(); void askNewLabelForSelection();
void setRowColor(int row, QColor color); void setRowColor(int row, QColor color);
@ -96,6 +95,7 @@ public slots:
void refreshList(); void refreshList();
void addTorrent(QTorrentHandle& h); void addTorrent(QTorrentHandle& h);
void setFinished(QTorrentHandle &h); void setFinished(QTorrentHandle &h);
void setSelectionLabel(QString label);
void setRefreshInterval(int t); void setRefreshInterval(int t);
void startSelectedTorrents(); void startSelectedTorrents();
void startAllTorrents(); void startAllTorrents();

Loading…
Cancel
Save