diff --git a/TODO b/TODO index 0e95a1fc3..d51855e36 100644 --- a/TODO +++ b/TODO @@ -29,6 +29,9 @@ - Add a torrent scheduler - Improve Ipfilter.dat parser (move to a thread ? - too slow to load qBT and more importantly options) +// in v0.11 +- Tabs support in search + // in v0.10 (partial) - WIP - Download from RSS feeds (WIP by gtsoul, clean & finish rss.h, add a tab in mainWindow, debug) - Move finished torrent to another tab and keep on seeding them even after restart (debug) @@ -39,5 +42,4 @@ - Display more info in log (UPnP) - Update to libtorrent SVN (0.13) - Use its UPnP/NAT-PMP built-in support instead of ours - - Use its piece prioritization support -- Tab support in search (maybe a bit later) \ No newline at end of file + - Use its piece prioritization support (Add comboboxes in properties) \ No newline at end of file diff --git a/src/PropListDelegate.h b/src/PropListDelegate.h index 5355ee6ea..caea70650 100644 --- a/src/PropListDelegate.h +++ b/src/PropListDelegate.h @@ -22,8 +22,10 @@ #ifndef PROPLISTDELEGATE_H #define PROPLISTDELEGATE_H -#include +#include #include +#include +#include #include #include #include @@ -36,11 +38,11 @@ #define PROGRESS 2 #define SELECTED 3 -class PropListDelegate: public QAbstractItemDelegate { +class PropListDelegate: public QItemDelegate { Q_OBJECT public: - PropListDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){} + PropListDelegate(QObject *parent=0) : QItemDelegate(parent){} ~PropListDelegate(){} @@ -101,18 +103,55 @@ class PropListDelegate: public QAbstractItemDelegate { painter->drawText(option.rect, Qt::AlignCenter, newopt.text); break; } - case SELECTED: + case SELECTED:{ + QStyleOptionComboBox newopt; + newopt.rect = opt.rect; if(index.data().toBool()){ - painter->drawText(option.rect, Qt::AlignCenter, tr("True")); +// painter->drawText(option.rect, Qt::AlignCenter, tr("True")); + newopt.currentText = tr("True"); }else{ - painter->drawText(option.rect, Qt::AlignCenter, tr("False")); +// painter->drawText(option.rect, Qt::AlignCenter, tr("False")); + newopt.currentText = tr("False"); } + newopt.state |= QStyle::State_Enabled; +// newopt.frame = true; +// newopt.editable = true; + QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &newopt, + painter); + opt.palette.setColor(QPalette::Text, QColor("black")); + painter->setPen(opt.palette.color(cg, QPalette::Text)); + painter->drawText(option.rect, Qt::AlignLeft, " "+newopt.currentText); break; + } default: painter->drawText(option.rect, Qt::AlignCenter, index.data().toString()); } } + QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index) const { + if(index.column() != SELECTED) return 0; + QComboBox* editor = new QComboBox(parent); + editor->setFocusPolicy(Qt::StrongFocus); + editor->addItem(tr("True")); + editor->addItem(tr("False")); + return editor; + } + + void setEditorData(QWidget *editor, const QModelIndex &index) const { + bool value = index.model()->data(index, Qt::DisplayRole).toBool(); + QComboBox *combobox = static_cast(editor); + if(value) { + combobox->setCurrentIndex(0); + } else { + combobox->setCurrentIndex(1); + } + } + +// bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ){ +// qDebug("Event!!!!"); +// return false; +// } + QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{ QVariant value = index.data(Qt::FontRole); QFont fnt = value.isValid() ? qvariant_cast(value) : option.font; @@ -121,6 +160,29 @@ class PropListDelegate: public QAbstractItemDelegate { QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1)); return textRect.size(); } + + public slots: + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { + QComboBox *combobox = static_cast(editor); +// combobox->interpretText(); + int value = combobox->currentIndex(); + qDebug("Setting combobox value in index: %d", value); + QString color; + if(value == 0) { + model->setData(index, true); + color = "green"; + } else { + model->setData(index, false); + color = "red"; + } + for(int i=0; icolumnCount(); ++i){ + model->setData(model->index(index.row(), i), QVariant(QColor(color)), Qt::TextColorRole); + } + } + + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const { + editor->setGeometry(option.rect); + } }; #endif diff --git a/src/properties.ui b/src/properties.ui index 875faef77..eb1fc0817 100644 --- a/src/properties.ui +++ b/src/properties.ui @@ -22,7 +22,7 @@ - 0 + 2 @@ -859,6 +859,9 @@ 301 + + QAbstractItemView::AllEditTriggers + QAbstractItemView::ExtendedSelection diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 21e3aa801..1103d19cd 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -44,7 +44,8 @@ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerEr filesList->setModel(PropListModel); PropDelegate = new PropListDelegate(); filesList->setItemDelegate(PropDelegate); - connect(filesList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(toggleSelectedState(const QModelIndex&))); +// connect(filesList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(toggleSelectedState(const QModelIndex&))); + connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&))); connect(addTracker_button, SIGNAL(clicked()), this, SLOT(askForTracker())); connect(removeTracker_button, SIGNAL(clicked()), this, SLOT(deleteSelectedTrackers())); connect(riseTracker_button, SIGNAL(clicked()), this, SLOT(riseSelectedTracker())); @@ -304,27 +305,27 @@ void properties::setAllPiecesState(bool selected){ // Toggle the selected state of a file within the torrent when we // double click on it. -void properties::toggleSelectedState(const QModelIndex& index){ - int row = index.row(); - if(selectionBitmask.at(row)){ - // File is selected - selectionBitmask.erase(selectionBitmask.begin()+row); - selectionBitmask.insert(selectionBitmask.begin()+row, 0); - // Update list infos - setRowColor(row, "green"); - PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true)); - }else{ - // File is not selected - selectionBitmask.erase(selectionBitmask.begin()+row); - selectionBitmask.insert(selectionBitmask.begin()+row, 1); - // Update list infos - setRowColor(row, "red"); - PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false)); - } - h.filter_files(selectionBitmask); - // Save filtered pieces to a file to remember them - saveFilteredFiles(); -} +// void properties::toggleSelectedState(const QModelIndex& index){ +// int row = index.row(); +// if(selectionBitmask.at(row)){ +// // File is selected +// selectionBitmask.erase(selectionBitmask.begin()+row); +// selectionBitmask.insert(selectionBitmask.begin()+row, 0); +// // Update list infos +// setRowColor(row, "green"); +// PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true)); +// }else{ +// // File is not selected +// selectionBitmask.erase(selectionBitmask.begin()+row); +// selectionBitmask.insert(selectionBitmask.begin()+row, 1); +// // Update list infos +// setRowColor(row, "red"); +// PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false)); +// } +// h.filter_files(selectionBitmask); +// // Save filtered pieces to a file to remember them +// saveFilteredFiles(); +// } void properties::on_incrementalDownload_stateChanged(int){ qDebug("Incremental download toggled"); diff --git a/src/properties_imp.h b/src/properties_imp.h index fce325e32..a41c3e50e 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -48,7 +48,7 @@ class properties : public QDialog, private Ui::properties{ void on_okButton_clicked(); void on_incrementalDownload_stateChanged(int); void setRowColor(int row, QString color); - void toggleSelectedState(const QModelIndex& index); +// void toggleSelectedState(const QModelIndex& index); void saveFilteredFiles(); void updateProgress(); void loadFilteredFiles();