|
|
@ -50,61 +50,35 @@ class DLListDelegate: public QItemDelegate { |
|
|
|
~DLListDelegate(){} |
|
|
|
~DLListDelegate(){} |
|
|
|
|
|
|
|
|
|
|
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{ |
|
|
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{ |
|
|
|
QStyleOptionViewItem opt = option; |
|
|
|
|
|
|
|
char tmp[MAX_CHAR_TMP]; |
|
|
|
char tmp[MAX_CHAR_TMP]; |
|
|
|
// set text color
|
|
|
|
QStyleOptionViewItemV3 opt = QItemDelegate::setOptions(index, option); |
|
|
|
QVariant value = index.data(Qt::TextColorRole); |
|
|
|
|
|
|
|
if (value.isValid() && qvariant_cast<QColor>(value).isValid()){ |
|
|
|
|
|
|
|
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(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() != 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<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()){ |
|
|
|
switch(index.column()){ |
|
|
|
case SIZE: |
|
|
|
case 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; |
|
|
|
break; |
|
|
|
case ETA: |
|
|
|
case ETA: |
|
|
|
painter->drawText(option.rect, Qt::AlignCenter, misc::userFriendlyDuration(index.data().toLongLong())); |
|
|
|
QItemDelegate::drawBackground(painter, opt, index); |
|
|
|
|
|
|
|
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::userFriendlyDuration(index.data().toLongLong())); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case UPSPEED: |
|
|
|
case UPSPEED: |
|
|
|
case DLSPEED:{ |
|
|
|
case DLSPEED:{ |
|
|
|
|
|
|
|
QItemDelegate::drawBackground(painter, opt, index); |
|
|
|
float speed = index.data().toDouble(); |
|
|
|
float speed = index.data().toDouble(); |
|
|
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.); |
|
|
|
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; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case RATIO:{ |
|
|
|
case RATIO:{ |
|
|
|
|
|
|
|
QItemDelegate::drawBackground(painter, opt, index); |
|
|
|
float ratio = index.data().toDouble(); |
|
|
|
float ratio = index.data().toDouble(); |
|
|
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio); |
|
|
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio); |
|
|
|
painter->drawText(option.rect, Qt::AlignCenter, QString(tmp)); |
|
|
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(tmp)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case PROGRESS:{ |
|
|
|
case PROGRESS:{ |
|
|
|
QStyleOptionProgressBarV2 newopt; |
|
|
|
QStyleOptionProgressBarV2 newopt; |
|
|
|
|
|
|
|
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; |
|
|
|
float progress; |
|
|
|
float progress; |
|
|
|
progress = index.data().toDouble()*100.; |
|
|
|
progress = index.data().toDouble()*100.; |
|
|
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress); |
|
|
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress); |
|
|
@ -122,7 +96,7 @@ class DLListDelegate: public QItemDelegate { |
|
|
|
opt.palette.setColor(QPalette::Text, QColor("grey")); |
|
|
|
opt.palette.setColor(QPalette::Text, QColor("grey")); |
|
|
|
painter->setPen(opt.palette.color(cg, QPalette::Text)); |
|
|
|
painter->setPen(opt.palette.color(cg, QPalette::Text)); |
|
|
|
} |
|
|
|
} |
|
|
|
painter->drawText(option.rect, Qt::AlignCenter, newopt.text); |
|
|
|
painter->drawText(opt.rect, Qt::AlignCenter, newopt.text); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
@ -139,6 +113,11 @@ class DLListDelegate: public QItemDelegate { |
|
|
|
return textRect.size(); |
|
|
|
return textRect.size(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { |
|
|
|
|
|
|
|
// No editor here
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|