From 79e2d253d48ce6b7f4a291cea9a1342968c935f4 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 31 Jul 2007 10:48:17 +0000 Subject: [PATCH] - Improved finishedList delegate --- src/FinishedListDelegate.h | 52 ++++++-------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/src/FinishedListDelegate.h b/src/FinishedListDelegate.h index b4a7e03f8..3c63fe490 100644 --- a/src/FinishedListDelegate.h +++ b/src/FinishedListDelegate.h @@ -48,57 +48,30 @@ class FinishedListDelegate: public QItemDelegate { ~FinishedListDelegate(){} void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{ - QStyleOptionViewItem opt = option; char tmp[MAX_CHAR_TMP]; - // set text color - QVariant value = index.data(Qt::ForegroundRole); - if (value.isValid() && qvariant_cast(value).isValid()){ - opt.palette.setColor(QPalette::Text, qvariant_cast(value)); - } - QPalette::ColorGroup cg = option.state & QStyle::State_Enabled - ? QPalette::Normal : QPalette::Disabled; - if (option.state & QStyle::State_Selected){ - painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); - }else{ - painter->setPen(opt.palette.color(cg, QPalette::Text)); - } - // draw the background color - if(index.column() != F_PROGRESS){ - if (option.showDecorationSelected && (option.state & QStyle::State_Selected)){ - if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)){ - cg = QPalette::Inactive; - } - painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight)); - }else{ -// 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); - } - } - } + QStyleOptionViewItemV3 opt = QItemDelegate::setOptions(index, option); switch(index.column()){ case F_SIZE: - painter->drawText(option.rect, Qt::AlignCenter, misc::friendlyUnit(index.data().toLongLong())); + QItemDelegate::drawBackground(painter, opt, index); + QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); break; case F_UPSPEED:{ + QItemDelegate::drawBackground(painter, opt, index); float speed = index.data().toDouble(); snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.); - painter->drawText(option.rect, Qt::AlignCenter, QString(tmp)+" "+tr("KiB/s")); + QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(tmp)+" "+tr("KiB/s")); break; } case F_RATIO:{ + QItemDelegate::drawBackground(painter, opt, index); float ratio = index.data().toDouble(); snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio); - painter->drawText(option.rect, Qt::AlignCenter, QString(tmp)); + QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(tmp)); break; } case F_PROGRESS:{ QStyleOptionProgressBarV2 newopt; + QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; float progress; progress = index.data().toDouble()*100.; snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress); @@ -124,15 +97,6 @@ class FinishedListDelegate: public QItemDelegate { } } - QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{ - QVariant value = index.data(Qt::FontRole); - QFont fnt = value.isValid() ? qvariant_cast(value) : option.font; - QFontMetrics fontMetrics(fnt); - const QString text = index.data(Qt::DisplayRole).toString(); - QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1)); - return textRect.size(); - } - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { // No editor here return 0;