Browse Source

- Added Comboboxes in torrent properties. No usable yet but it will be very useful when we will support pieces prioritization

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
d3eda2e8be
  1. 6
      TODO
  2. 74
      src/PropListDelegate.h
  3. 5
      src/properties.ui
  4. 45
      src/properties_imp.cpp
  5. 2
      src/properties_imp.h

6
TODO

@ -29,6 +29,9 @@
- Add a torrent scheduler - Add a torrent scheduler
- Improve Ipfilter.dat parser (move to a thread ? - too slow to load qBT and more importantly options) - 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 // in v0.10 (partial) - WIP
- Download from RSS feeds (WIP by gtsoul, clean & finish rss.h, add a tab in mainWindow, debug) - 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) - 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) - Display more info in log (UPnP)
- Update to libtorrent SVN (0.13) - Update to libtorrent SVN (0.13)
- Use its UPnP/NAT-PMP built-in support instead of ours - Use its UPnP/NAT-PMP built-in support instead of ours
- Use its piece prioritization support - Use its piece prioritization support (Add comboboxes in properties)
- Tab support in search (maybe a bit later)

74
src/PropListDelegate.h

@ -22,8 +22,10 @@
#ifndef PROPLISTDELEGATE_H #ifndef PROPLISTDELEGATE_H
#define PROPLISTDELEGATE_H #define PROPLISTDELEGATE_H
#include <QAbstractItemDelegate> #include <QItemDelegate>
#include <QStyleOptionProgressBarV2> #include <QStyleOptionProgressBarV2>
#include <QStyleOptionComboBox>
#include <QComboBox>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>
#include <QProgressBar> #include <QProgressBar>
@ -36,11 +38,11 @@
#define PROGRESS 2 #define PROGRESS 2
#define SELECTED 3 #define SELECTED 3
class PropListDelegate: public QAbstractItemDelegate { class PropListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT
public: public:
PropListDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){} PropListDelegate(QObject *parent=0) : QItemDelegate(parent){}
~PropListDelegate(){} ~PropListDelegate(){}
@ -101,18 +103,55 @@ class PropListDelegate: public QAbstractItemDelegate {
painter->drawText(option.rect, Qt::AlignCenter, newopt.text); painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
break; break;
} }
case SELECTED: case SELECTED:{
QStyleOptionComboBox newopt;
newopt.rect = opt.rect;
if(index.data().toBool()){ 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{ }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; break;
}
default: default:
painter->drawText(option.rect, Qt::AlignCenter, index.data().toString()); 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<QComboBox*>(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{ QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{
QVariant value = index.data(Qt::FontRole); QVariant value = index.data(Qt::FontRole);
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font; QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
@ -121,6 +160,29 @@ class PropListDelegate: public QAbstractItemDelegate {
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1)); QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
return textRect.size(); return textRect.size();
} }
public slots:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
QComboBox *combobox = static_cast<QComboBox*>(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; i<model->columnCount(); ++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 #endif

5
src/properties.ui

@ -22,7 +22,7 @@
<item> <item>
<widget class="QTabWidget" name="torrentContent" > <widget class="QTabWidget" name="torrentContent" >
<property name="currentIndex" > <property name="currentIndex" >
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="tab" > <widget class="QWidget" name="tab" >
<attribute name="title" > <attribute name="title" >
@ -859,6 +859,9 @@
<height>301</height> <height>301</height>
</size> </size>
</property> </property>
<property name="editTriggers" >
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<property name="selectionMode" > <property name="selectionMode" >
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>

45
src/properties_imp.cpp

@ -44,7 +44,8 @@ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerEr
filesList->setModel(PropListModel); filesList->setModel(PropListModel);
PropDelegate = new PropListDelegate(); PropDelegate = new PropListDelegate();
filesList->setItemDelegate(PropDelegate); 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(addTracker_button, SIGNAL(clicked()), this, SLOT(askForTracker()));
connect(removeTracker_button, SIGNAL(clicked()), this, SLOT(deleteSelectedTrackers())); connect(removeTracker_button, SIGNAL(clicked()), this, SLOT(deleteSelectedTrackers()));
connect(riseTracker_button, SIGNAL(clicked()), this, SLOT(riseSelectedTracker())); 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 // Toggle the selected state of a file within the torrent when we
// double click on it. // double click on it.
void properties::toggleSelectedState(const QModelIndex& index){ // void properties::toggleSelectedState(const QModelIndex& index){
int row = index.row(); // int row = index.row();
if(selectionBitmask.at(row)){ // if(selectionBitmask.at(row)){
// File is selected // // File is selected
selectionBitmask.erase(selectionBitmask.begin()+row); // selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 0); // selectionBitmask.insert(selectionBitmask.begin()+row, 0);
// Update list infos // // Update list infos
setRowColor(row, "green"); // setRowColor(row, "green");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true)); // PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
}else{ // }else{
// File is not selected // // File is not selected
selectionBitmask.erase(selectionBitmask.begin()+row); // selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 1); // selectionBitmask.insert(selectionBitmask.begin()+row, 1);
// Update list infos // // Update list infos
setRowColor(row, "red"); // setRowColor(row, "red");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false)); // PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
} // }
h.filter_files(selectionBitmask); // h.filter_files(selectionBitmask);
// Save filtered pieces to a file to remember them // // Save filtered pieces to a file to remember them
saveFilteredFiles(); // saveFilteredFiles();
} // }
void properties::on_incrementalDownload_stateChanged(int){ void properties::on_incrementalDownload_stateChanged(int){
qDebug("Incremental download toggled"); qDebug("Incremental download toggled");

2
src/properties_imp.h

@ -48,7 +48,7 @@ class properties : public QDialog, private Ui::properties{
void on_okButton_clicked(); void on_okButton_clicked();
void on_incrementalDownload_stateChanged(int); void on_incrementalDownload_stateChanged(int);
void setRowColor(int row, QString color); void setRowColor(int row, QString color);
void toggleSelectedState(const QModelIndex& index); // void toggleSelectedState(const QModelIndex& index);
void saveFilteredFiles(); void saveFilteredFiles();
void updateProgress(); void updateProgress();
void loadFilteredFiles(); void loadFilteredFiles();

Loading…
Cancel
Save