Changeset 14315


Ignore:
Timestamp:
Jul 3, 2014, 11:12:50 PM (8 years ago)
Author:
jordan
Message:

(trunk, qt) #5723: 'Simplify file tree icons drawing' -- patch by mike.dld

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/file-tree.cc

    r14225 r14315  
    155155           break;
    156156        }
     157    }
     158  else if (role == Qt::DecorationRole && column == COL_NAME)
     159    {
     160      if (childCount () > 0)
     161        value = QApplication::style ()->standardIcon (QStyle::SP_DirOpenIcon);
     162      else
     163        value = Utils::guessMimeIcon (name ());
    157164    }
    158165
     
    778785  switch(index.column())
    779786    {
    780       case COL_NAME:
    781         {
    782           const QFontMetrics fm(item.font);
    783           const int iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    784           size.rwidth() = HIG::PAD_SMALL + iconSize;
    785           size.rheight() = std::max(iconSize, fm.height());
    786           break;
    787         }
    788 
    789787      case COL_PROGRESS:
    790788      case COL_WANTED:
     
    793791
    794792      default:
    795         {
    796           const QFontMetrics fm(item.font);
    797           const QString text = index.data().toString();
    798           size = fm.size(0, text);
    799           break;
    800         }
     793        size = QItemDelegate::sizeHint (item, index);
    801794    }
    802795
     
    812805  const int column(index.column());
    813806
    814   if ((column != COL_PROGRESS) && (column != COL_WANTED) && (column != COL_NAME))
     807  if ((column != COL_PROGRESS) && (column != COL_WANTED))
    815808    {
    816809      QItemDelegate::paint(painter, option, index);
     
    819812
    820813  QStyle * style (QApplication :: style());
    821   if (option.state & QStyle::State_Selected)
    822     painter->fillRect (option.rect, option.palette.highlight());
     814
    823815  painter->save();
    824   if (option.state & QStyle::State_Selected)
    825     painter->setBrush (option.palette.highlightedText());
    826 
    827   if (column == COL_NAME)
    828     {
    829       // draw the file icon
    830       static const int iconSize (style->pixelMetric(QStyle :: PM_SmallIconSize));
    831       const QRect iconArea (option.rect.x(),
    832                             option.rect.y() + (option.rect.height()-iconSize)/2,
    833                             iconSize, iconSize);
    834       QIcon icon;
    835       if (index.model()->hasChildren(index))
    836         {
    837           icon = style->standardIcon(QStyle::StandardPixmap(QStyle::SP_DirOpenIcon));
    838         }
    839       else
    840         {
    841           QString name = index.data().toString();
    842           icon = Utils :: guessMimeIcon (name);
    843         }
    844       icon.paint (painter, iconArea, Qt::AlignCenter, QIcon::Normal, QIcon::On);
    845 
    846       // draw the name
    847       QStyleOptionViewItem tmp (option);
    848       tmp.rect.setWidth (option.rect.width() - iconArea.width() - HIG::PAD_SMALL);
    849       tmp.rect.moveRight (option.rect.right());
    850       QItemDelegate::paint (painter, tmp, index);
    851     }
    852   else if(column == COL_PROGRESS)
     816  QItemDelegate::drawBackground (painter, option, index);
     817
     818  if(column == COL_PROGRESS)
    853819    {
    854820      QStyleOptionProgressBar p;
     
    884850    }
    885851
     852  QItemDelegate::drawFocus (painter, option, option.rect);
    886853  painter->restore();
    887854}
Note: See TracChangeset for help on using the changeset viewer.