| 165 | } |
| 166 | |
| 167 | void PluginItemDelegate::paintItemColumn(QPainter *painter, |
| 168 | const QStyleOptionViewItem &option, |
| 169 | const QModelIndex &index, |
| 170 | const QRectF &iconRect) const |
| 171 | { |
| 172 | painter->save(); |
| 173 | |
| 174 | bool isSelected = (option.state & QStyle::State_Selected) && option.showDecorationSelected; |
| 175 | if (isSelected) |
| 176 | painter->setPen(option.palette.color(DPalette::ColorGroup::Active, QPalette::HighlightedText)); |
| 177 | |
| 178 | QFont boldFont = option.font; |
| 179 | boldFont.setPointSize(10); |
| 180 | boldFont.setBold(true); |
| 181 | QFontMetrics fmBold(boldFont); |
| 182 | |
| 183 | // display plugin name. |
| 184 | QString pluginName = index.data(Qt::DisplayRole).toString(); |
| 185 | pluginName = fmBold.elidedText(pluginName, Qt::ElideRight, |
| 186 | qRound(option.rect.width() - iconRect.width() - kIconLeftMargin * 2)); |
| 187 | painter->setFont(boldFont); |
| 188 | painter->drawText(option.rect.adjusted(kIconLeftMargin + kIconWidth + kTextLeftMargin, 5, 0, -5), |
| 189 | Qt::AlignLeft | Qt::AlignTop, pluginName); |
| 190 | painter->restore(); |
| 191 | |
| 192 | painter->save(); |
| 193 | // display description. |
| 194 | if (isSelected) |
| 195 | painter->setPen(Qt::white); |
| 196 | else |
| 197 | painter->setOpacity(0.7); |
| 198 | QString description = index.data(PluginListView::Description).toString(); |
| 199 | QFontMetrics fm(option.font); |
| 200 | description = fm.elidedText(description, Qt::ElideRight, |
| 201 | qRound(option.rect.width() - iconRect.width() - kIconLeftMargin * 2)); |
| 202 | painter->drawText(option.rect.adjusted(kIconLeftMargin + kIconWidth + kTextLeftMargin, 5, 0, -5), |
| 203 | Qt::AlignLeft | Qt::AlignVCenter, description); |
| 204 | |
| 205 | // display vender. |
| 206 | boldFont.setPointSize(9); |
| 207 | QFontMetrics fmSmallBold(boldFont); |
| 208 | QString vender = index.data(PluginListView::Vender).toString(); |
| 209 | vender = fmSmallBold.elidedText(vender, Qt::ElideRight, |
| 210 | qRound(option.rect.width() - iconRect.width() - kIconLeftMargin * 2)); |
| 211 | painter->setFont(boldFont); |
| 212 | painter->drawText(option.rect.adjusted(kIconLeftMargin + kIconWidth + kTextLeftMargin, 5, 0, -5), |
| 213 | Qt::AlignLeft | Qt::AlignBottom, vender); |
| 214 | |
| 215 | painter->restore(); |
| 216 | } |