@ -22,7 +22,7 @@
@@ -22,7 +22,7 @@
# ifndef DLLISTDELEGATE_H
# define DLLISTDELEGATE_H
# include <QAbstract ItemDelegate>
# 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 QAbstract ItemDelegate {
class DLListDelegate : public QItemDelegate {
Q_OBJECT
public :
DLListDelegate ( QObject * parent ) : QAbstract ItemDelegate ( 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