mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 21:14:33 +00:00
- Improved finishedList delegate
This commit is contained in:
parent
9b08b0ff8c
commit
79e2d253d4
@ -48,57 +48,30 @@ class FinishedListDelegate: public QItemDelegate {
|
|||||||
~FinishedListDelegate(){}
|
~FinishedListDelegate(){}
|
||||||
|
|
||||||
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::ForegroundRole);
|
|
||||||
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() != 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<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 F_SIZE:
|
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;
|
break;
|
||||||
case F_UPSPEED:{
|
case F_UPSPEED:{
|
||||||
|
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 F_RATIO:{
|
case F_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 F_PROGRESS:{
|
case F_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);
|
||||||
@ -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<QFont>(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 {
|
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const {
|
||||||
// No editor here
|
// No editor here
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user