From 0561206d91b02d8cb0c647b9e5df11fa5cc1785e Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 31 Jul 2007 09:41:47 +0000 Subject: [PATCH] - Started to improve download & finished list rendering (filename column) --- TODO | 4 +-- src/DLListDelegate.h | 55 +++++++++----------------------------- src/FinishedListDelegate.h | 36 +++++++++---------------- 3 files changed, 26 insertions(+), 69 deletions(-) diff --git a/TODO b/TODO index 92a369416..92f7c2957 100644 --- a/TODO +++ b/TODO @@ -44,9 +44,9 @@ - Windows port (Chris - Peerkoel) - Add checking icon to documentation * beta3 - - Translations update (IN PROGESS) + - Translations update (IN PROGRESS) - Optimize and cleanup code - - add asserts to squash remaining bugs + - Improve delegates - Check that there is no problem with right click menu in torrent content (all files filtered for example) - Wait for some bug fixes in libtorrent : - upload/download limit per torrent diff --git a/src/DLListDelegate.h b/src/DLListDelegate.h index 8700db9ab..7df355989 100644 --- a/src/DLListDelegate.h +++ b/src/DLListDelegate.h @@ -22,7 +22,7 @@ #ifndef DLLISTDELEGATE_H #define DLLISTDELEGATE_H -#include +#include #include #include #include @@ -41,11 +41,11 @@ #define ETA 7 #define HASH 8 -class DLListDelegate: public QAbstractItemDelegate { +class DLListDelegate: public QItemDelegate { Q_OBJECT public: - DLListDelegate(QObject *parent) : QAbstractItemDelegate(parent){} + DLListDelegate(QObject *parent) : QItemDelegate(parent){} ~DLListDelegate(){} @@ -72,15 +72,15 @@ class DLListDelegate: public QAbstractItemDelegate { } painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight)); }else{ - painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Base)); +// painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Base)); // The following should work but is broken (retry with future versions of Qt) -// QVariant value = index.data(Qt::BackgroundRole); -// if (qVariantCanConvert(value)) { -// QPointF oldBO = painter->brushOrigin(); -// painter->setBrushOrigin(option.rect.topLeft()); -// painter->fillRect(option.rect, qvariant_cast(value)); -// painter->setBrushOrigin(oldBO); -// } + QVariant value = index.data(Qt::BackgroundRole); + if (qVariantCanConvert(value)) { + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin(option.rect.topLeft()); + painter->fillRect(option.rect, qvariant_cast(value)); + painter->setBrushOrigin(oldBO); + } } } switch(index.column()){ @@ -125,20 +125,8 @@ class DLListDelegate: public QAbstractItemDelegate { painter->drawText(option.rect, Qt::AlignCenter, newopt.text); break; } - case NAME:{ - // decoration - value = index.data(Qt::DecorationRole); - QPixmap pixmap = qvariant_cast(value).pixmap(option.decorationSize, option.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled, option.state & QStyle::State_Open ? QIcon::On : QIcon::Off); - QRect pixmapRect = (pixmap.isNull() ? QRect(0, 0, 0, 0): QRect(QPoint(0, 0), option.decorationSize)); - if (pixmapRect.isValid()){ - QPoint p = QStyle::alignedRect(option.direction, Qt::AlignLeft, pixmap.size(), option.rect).topLeft(); - painter->drawPixmap(p, pixmap); - } - painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, index.data().toString()); - break; - } default: - painter->drawText(option.rect, Qt::AlignCenter, index.data().toString()); + QItemDelegate::paint(painter, option, index); } } @@ -151,25 +139,6 @@ class DLListDelegate: public QAbstractItemDelegate { return textRect.size(); } -// QWidget* createEditor(QWidget * parent, const QStyleOptionViewItem& /*option*/, const QModelIndex & index) const{ -// if(index.column() == PROGRESS){ -// QProgressBar *progressBar = new QProgressBar(parent); -// progressBar->setRange(0,100); -// progressBar->installEventFilter(const_cast(this)); -// return progressBar; -// } -// return 0; -// } -// void setEditorData(QWidget *editor, const QModelIndex &index) const{ -// QProgressBar *progressBar = static_cast(editor); -// float progress = index.data().toDouble(); -// progressBar->setValue((int)(progress*100.)); -// } -// void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & index) const{ -// if(index.column() == PROGRESS){ -// editor->setGeometry(option.rect); -// } -// } }; #endif diff --git a/src/FinishedListDelegate.h b/src/FinishedListDelegate.h index 7cb1dde22..57cd1cee3 100644 --- a/src/FinishedListDelegate.h +++ b/src/FinishedListDelegate.h @@ -22,7 +22,7 @@ #ifndef FINISHEDLISTDELEGATE_H #define FINISHEDLISTDELEGATE_H -#include +#include #include #include #include @@ -39,11 +39,11 @@ #define F_RATIO 5 #define F_HASH 6 -class FinishedListDelegate: public QAbstractItemDelegate { +class FinishedListDelegate: public QItemDelegate { Q_OBJECT public: - FinishedListDelegate(QObject *parent) : QAbstractItemDelegate(parent){} + FinishedListDelegate(QObject *parent) : QItemDelegate(parent){} ~FinishedListDelegate(){} @@ -70,15 +70,15 @@ class FinishedListDelegate: public QAbstractItemDelegate { } painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight)); }else{ - painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Base)); +// painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Base)); // The following should work but is broken (retry with future versions of Qt) -// QVariant value = index.data(Qt::BackgroundRole); -// if (qVariantCanConvert(value)) { -// QPointF oldBO = painter->brushOrigin(); -// painter->setBrushOrigin(option.rect.topLeft()); -// painter->fillRect(option.rect, qvariant_cast(value)); -// painter->setBrushOrigin(oldBO); -// } + QVariant value = index.data(Qt::BackgroundRole); + if (qVariantCanConvert(value)) { + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin(option.rect.topLeft()); + painter->fillRect(option.rect, qvariant_cast(value)); + painter->setBrushOrigin(oldBO); + } } } switch(index.column()){ @@ -119,20 +119,8 @@ class FinishedListDelegate: public QAbstractItemDelegate { painter->drawText(option.rect, Qt::AlignCenter, newopt.text); break; } - case F_NAME:{ - // decoration - value = index.data(Qt::DecorationRole); - QPixmap pixmap = qvariant_cast(value).pixmap(option.decorationSize, option.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled, option.state & QStyle::State_Open ? QIcon::On : QIcon::Off); - QRect pixmapRect = (pixmap.isNull() ? QRect(0, 0, 0, 0): QRect(QPoint(0, 0), option.decorationSize)); - if (pixmapRect.isValid()){ - QPoint p = QStyle::alignedRect(option.direction, Qt::AlignLeft, pixmap.size(), option.rect).topLeft(); - painter->drawPixmap(p, pixmap); - } - painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, index.data().toString()); - break; - } default: - painter->drawText(option.rect, Qt::AlignCenter, index.data().toString()); + QItemDelegate::paint(painter, option, index); } }