Browse Source

- Started to improve download & finished list rendering (filename column)

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
0561206d91
  1. 4
      TODO
  2. 55
      src/DLListDelegate.h
  3. 36
      src/FinishedListDelegate.h

4
TODO

@ -44,9 +44,9 @@ @@ -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

55
src/DLListDelegate.h

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
#ifndef DLLISTDELEGATE_H
#define DLLISTDELEGATE_H
#include <QAbstractItemDelegate>
#include <QItemDelegate>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionProgressBarV2>
@ -41,11 +41,11 @@ @@ -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 { @@ -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<QBrush>(value)) {
// QPointF oldBO = painter->brushOrigin();
// painter->setBrushOrigin(option.rect.topLeft());
// painter->fillRect(option.rect, qvariant_cast<QBrush>(value));
// painter->setBrushOrigin(oldBO);
// }
QVariant value = index.data(Qt::BackgroundRole);
if (qVariantCanConvert<QBrush>(value)) {
QPointF oldBO = painter->brushOrigin();
painter->setBrushOrigin(option.rect.topLeft());
painter->fillRect(option.rect, qvariant_cast<QBrush>(value));
painter->setBrushOrigin(oldBO);
}
}
}
switch(index.column()){
@ -125,20 +125,8 @@ class DLListDelegate: public QAbstractItemDelegate { @@ -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<QIcon>(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 { @@ -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<DLListDelegate*>(this));
// return progressBar;
// }
// return 0;
// }
// void setEditorData(QWidget *editor, const QModelIndex &index) const{
// QProgressBar *progressBar = static_cast<QProgressBar*>(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

36
src/FinishedListDelegate.h

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
#ifndef FINISHEDLISTDELEGATE_H
#define FINISHEDLISTDELEGATE_H
#include <QAbstractItemDelegate>
#include <QItemDelegate>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionProgressBarV2>
@ -39,11 +39,11 @@ @@ -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 { @@ -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<QBrush>(value)) {
// QPointF oldBO = painter->brushOrigin();
// painter->setBrushOrigin(option.rect.topLeft());
// painter->fillRect(option.rect, qvariant_cast<QBrush>(value));
// painter->setBrushOrigin(oldBO);
// }
QVariant value = index.data(Qt::BackgroundRole);
if (qVariantCanConvert<QBrush>(value)) {
QPointF oldBO = painter->brushOrigin();
painter->setBrushOrigin(option.rect.topLeft());
painter->fillRect(option.rect, qvariant_cast<QBrush>(value));
painter->setBrushOrigin(oldBO);
}
}
}
switch(index.column()){
@ -119,20 +119,8 @@ class FinishedListDelegate: public QAbstractItemDelegate { @@ -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<QIcon>(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);
}
}

Loading…
Cancel
Save