diff --git a/plugins/projectmanagerview/projectmodelitemdelegate.cpp b/plugins/projectmanagerview/projectmodelitemdelegate.cpp --- a/plugins/projectmanagerview/projectmodelitemdelegate.cpp +++ b/plugins/projectmanagerview/projectmodelitemdelegate.cpp @@ -27,10 +27,53 @@ : QItemDelegate(parent) {} +static QIcon::Mode IconMode( QStyle::State state ) +{ + if (!(state & QStyle::State_Enabled)) { + return QIcon::Disabled; + } + else if (state & QStyle::State_Selected) { + return QIcon::Selected; + } + else return QIcon::Normal; +} + +static QIcon::State IconState(QStyle::State state) +{ + return (state & QStyle::State_Open) + ? QIcon::On + : QIcon::Off + ; +} + + void ProjectModelItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opt, const QModelIndex& index) const { - QPixmap decoData = decoration(opt, index.data(Qt::DecorationRole)); - QRect decorationRect = rect(opt, index, Qt::DecorationRole); + QVariant value; + QPixmap decoData; + QRect decorationRect; + QIcon icon; + QIcon::Mode mode; + QIcon::State state; + value = index.data(Qt::DecorationRole); + if (value.isValid()) { + decoData = decoration(opt, value); + + if (value.type() == QVariant::Icon) { + icon = qvariant_cast(value); + mode = IconMode(opt.state); + state = IconState(opt.state); + QSize size = icon.actualSize( opt.decorationSize, mode, state ); + decorationRect = QRect(QPoint(0, 0), size); + } + else { + decorationRect = QRect(QPoint(0, 0), decoData.size()); + } + } + else { + decorationRect = QRect(); + } + QRect checkRect; //unused in practice QRect spaceLeft = opt.rect; @@ -48,10 +91,18 @@ drawStyledBackground(painter, opt); // drawCheck(painter, opt, checkRect, checkState); - drawDecoration(painter, opt, decorationRect, decoData); + + if (!icon.isNull()) { + icon.paint(painter, decorationRect, opt.decorationAlignment, mode, state ); + } + else { + drawDecoration(painter, opt, decorationRect, decoData); + } + drawDisplay(painter, opt, displayRect, displayData); drawBranchName(painter, opt, branchNameRect, branchNameData); drawFocus(painter, opt, displayRect); + } void ProjectModelItemDelegate::drawBranchName(QPainter* painter, const QStyleOptionViewItem& option,