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) { @@ -598,9 +598,29 @@ void GUI::dragEnterEvent(QDragEnterEvent *event) {
foreach(const QString &mime, event->mimeData()->formats()){
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"))) {
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{ @@ -97,6 +97,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
// GUI related slots
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void toggleVisibility(QSystemTrayIcon::ActivationReason e);
void on_actionAbout_triggered();
void on_actionCreate_torrent_triggered();

55
src/transferlistfilterswidget.h

@ -39,10 +39,43 @@ @@ -39,10 +39,43 @@
#include <QVBoxLayout>
#include <QMenu>
#include <QInputDialog>
#include <QDragMoveEvent>
#include "transferlistdelegate.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 {
Q_OBJECT
@ -50,7 +83,7 @@ private: @@ -50,7 +83,7 @@ private:
QStringList customLabels;
QList<int> labelCounters;
QListWidget* statusFilters;
QListWidget* labelFilters;
LabelFiltersList* labelFilters;
QVBoxLayout* vLayout;
TransferListWidget *transferList;
int nb_labeled;
@ -60,9 +93,9 @@ public: @@ -60,9 +93,9 @@ public:
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) {
// Construct lists
vLayout = new QVBoxLayout();
statusFilters = new QListWidget();
statusFilters = new QListWidget(this);
vLayout->addWidget(statusFilters);
labelFilters = new QListWidget();
labelFilters = new LabelFiltersList(this);
vLayout->addWidget(labelFilters);
setLayout(vLayout);
// Limit status filters list height
@ -90,8 +123,10 @@ public: @@ -90,8 +123,10 @@ public:
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(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(torrentAboutToBeRemoved(QModelIndex)), this, SLOT(torrentAboutToBeDeleted(QModelIndex)));
connect(transferList, SIGNAL(torrentChangedLabel(QString,QString)), this, SLOT(torrentChangedLabel(QString, QString)));
// Load settings
loadSettings();
@ -153,6 +188,16 @@ protected slots: @@ -153,6 +188,16 @@ protected slots:
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) {
if(label.trimmed().isEmpty()) return;
if(customLabels.contains(label)) return;
@ -214,12 +259,14 @@ protected slots: @@ -214,12 +259,14 @@ protected slots:
}
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()) {
int i = customLabels.indexOf(old_label);
int new_count = labelCounters[i]-1;
Q_ASSERT(new_count >= 0);
labelCounters.replace(i, new_count);
labelFilters->item(i+2)->setText(old_label + " ("+ QString::number(new_count) +")");
--nb_labeled;
}
if(!new_label.isEmpty()) {
if(!customLabels.contains(new_label))
@ -228,7 +275,9 @@ protected slots: @@ -228,7 +275,9 @@ protected slots:
int new_count = labelCounters[i]+1;
labelCounters.replace(i, new_count);
labelFilters->item(i+2)->setText(new_label + " ("+ QString::number(new_count) +")");
++nb_labeled;
}
updateStickyLabelCounters();
}
void torrentAdded(QModelIndex index) {

2
src/transferlistwidget.cpp

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

2
src/transferlistwidget.h

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

Loading…
Cancel
Save