mirror of
https://github.com/transmission/transmission
synced 2025-02-22 14:10:34 +00:00
(trunk, qt) #5723: 'Simplify file tree icons drawing' -- patch by mike.dld
This commit is contained in:
parent
60a5c793d9
commit
d0695b7006
1 changed files with 13 additions and 46 deletions
|
@ -155,6 +155,13 @@ FileTreeItem :: data (int column, int role) const
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if (role == Qt::DecorationRole && column == COL_NAME)
|
||||
{
|
||||
if (childCount () > 0)
|
||||
value = QApplication::style ()->standardIcon (QStyle::SP_DirOpenIcon);
|
||||
else
|
||||
value = Utils::guessMimeIcon (name ());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -777,27 +784,13 @@ FileTreeDelegate :: sizeHint(const QStyleOptionViewItem& item, const QModelIndex
|
|||
|
||||
switch(index.column())
|
||||
{
|
||||
case COL_NAME:
|
||||
{
|
||||
const QFontMetrics fm(item.font);
|
||||
const int iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||
size.rwidth() = HIG::PAD_SMALL + iconSize;
|
||||
size.rheight() = std::max(iconSize, fm.height());
|
||||
break;
|
||||
}
|
||||
|
||||
case COL_PROGRESS:
|
||||
case COL_WANTED:
|
||||
size = QSize(20, 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
const QFontMetrics fm(item.font);
|
||||
const QString text = index.data().toString();
|
||||
size = fm.size(0, text);
|
||||
break;
|
||||
}
|
||||
size = QItemDelegate::sizeHint (item, index);
|
||||
}
|
||||
|
||||
size.rheight() += 8; // make the spacing a little nicer
|
||||
|
@ -811,45 +804,18 @@ FileTreeDelegate :: paint (QPainter * painter,
|
|||
{
|
||||
const int column(index.column());
|
||||
|
||||
if ((column != COL_PROGRESS) && (column != COL_WANTED) && (column != COL_NAME))
|
||||
if ((column != COL_PROGRESS) && (column != COL_WANTED))
|
||||
{
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
QStyle * style (QApplication :: style());
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->fillRect (option.rect, option.palette.highlight());
|
||||
|
||||
painter->save();
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->setBrush (option.palette.highlightedText());
|
||||
QItemDelegate::drawBackground (painter, option, index);
|
||||
|
||||
if (column == COL_NAME)
|
||||
{
|
||||
// draw the file icon
|
||||
static const int iconSize (style->pixelMetric(QStyle :: PM_SmallIconSize));
|
||||
const QRect iconArea (option.rect.x(),
|
||||
option.rect.y() + (option.rect.height()-iconSize)/2,
|
||||
iconSize, iconSize);
|
||||
QIcon icon;
|
||||
if (index.model()->hasChildren(index))
|
||||
{
|
||||
icon = style->standardIcon(QStyle::StandardPixmap(QStyle::SP_DirOpenIcon));
|
||||
}
|
||||
else
|
||||
{
|
||||
QString name = index.data().toString();
|
||||
icon = Utils :: guessMimeIcon (name);
|
||||
}
|
||||
icon.paint (painter, iconArea, Qt::AlignCenter, QIcon::Normal, QIcon::On);
|
||||
|
||||
// draw the name
|
||||
QStyleOptionViewItem tmp (option);
|
||||
tmp.rect.setWidth (option.rect.width() - iconArea.width() - HIG::PAD_SMALL);
|
||||
tmp.rect.moveRight (option.rect.right());
|
||||
QItemDelegate::paint (painter, tmp, index);
|
||||
}
|
||||
else if(column == COL_PROGRESS)
|
||||
if(column == COL_PROGRESS)
|
||||
{
|
||||
QStyleOptionProgressBar p;
|
||||
p.state = option.state | QStyle::State_Small;
|
||||
|
@ -883,6 +849,7 @@ FileTreeDelegate :: paint (QPainter * painter,
|
|||
style->drawControl (QStyle::CE_CheckBox, &o, painter);
|
||||
}
|
||||
|
||||
QItemDelegate::drawFocus (painter, option, option.rect);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue