viewItemOption.state = styleState;
viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
viewItemOption.showDecorationSelected = true;
- viewItemOption.rect = textRect().toRect();
+ viewItemOption.rect = selectionRect().toRect();
widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
}
*/
virtual QRectF textFocusRect() const;
+ /**
+ * @return Rectangle around which a selection box should be drawn if the item is selected.
+ */
+ virtual QRectF selectionRect() const = 0;
+
/**
* @return Rectangle for the selection-toggle that is used to select or deselect an item.
* Per default an empty rectangle is returned which means that no selection-toggle
return m_textRect;
}
+QRectF KStandardItemListWidget::selectionRect() const
+{
+ const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
+
+ switch (m_layout) {
+ case IconsLayout:
+ return m_textRect;
+
+ case CompactLayout:
+ case DetailsLayout: {
+ const int padding = styleOption().padding;
+ QRectF adjustedIconRect = iconRect().adjusted(-padding, -padding, padding, padding);
+ return adjustedIconRect | m_textRect;
+ }
+
+ default:
+ Q_ASSERT(false);
+ break;
+ }
+
+ return m_textRect;
+}
+
QRectF KStandardItemListWidget::expansionToggleRect() const
{
const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
KIconEffect::semiTransparent(m_pixmap);
}
- if (isSelected()) {
+ if (m_layout == IconsLayout && isSelected()) {
const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
QImage image = m_pixmap.toImage();
KIconEffect::colorize(image, color, 0.8f);
virtual QRectF iconRect() const;
virtual QRectF textRect() const;
virtual QRectF textFocusRect() const;
+ virtual QRectF selectionRect() const;
virtual QRectF expansionToggleRect() const;
virtual QRectF selectionToggleRect() const;
virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = 0);