Improve drawing selected items in Compact/Details View and Places Panel

This commit removes the icon tinting for the selected item in Compact
and Details View, and extends the selection rectangle such that it
includes the icon area as well. The icon tinting can be disturbing, and
having a selection rectangle that only includes the text can look a bit
strange, especially in the Places Panel.

BUG: 304643
REVIEW: 119018
FIXED-IN: 4.14.0
This commit is contained in:
Frank Reininghaus 2014-07-04 00:49:31 +02:00
parent d329e0ed72
commit 1f69714a23
4 changed files with 31 additions and 2 deletions

View file

@ -522,7 +522,7 @@ void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QS
viewItemOption.state = styleState; viewItemOption.state = styleState;
viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
viewItemOption.showDecorationSelected = true; viewItemOption.showDecorationSelected = true;
viewItemOption.rect = textRect().toRect(); viewItemOption.rect = selectionRect().toRect();
widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
} }

View file

@ -163,6 +163,11 @@ public:
*/ */
virtual QRectF textFocusRect() const; 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. * @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 * Per default an empty rectangle is returned which means that no selection-toggle

View file

@ -494,6 +494,29 @@ QRectF KStandardItemListWidget::textFocusRect() const
return m_textRect; 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 QRectF KStandardItemListWidget::expansionToggleRect() const
{ {
const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
@ -945,7 +968,7 @@ void KStandardItemListWidget::updatePixmapCache()
KIconEffect::semiTransparent(m_pixmap); KIconEffect::semiTransparent(m_pixmap);
} }
if (isSelected()) { if (m_layout == IconsLayout && isSelected()) {
const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
QImage image = m_pixmap.toImage(); QImage image = m_pixmap.toImage();
KIconEffect::colorize(image, color, 0.8f); KIconEffect::colorize(image, color, 0.8f);

View file

@ -109,6 +109,7 @@ public:
virtual QRectF iconRect() const; virtual QRectF iconRect() const;
virtual QRectF textRect() const; virtual QRectF textRect() const;
virtual QRectF textFocusRect() const; virtual QRectF textFocusRect() const;
virtual QRectF selectionRect() const;
virtual QRectF expansionToggleRect() const; virtual QRectF expansionToggleRect() const;
virtual QRectF selectionToggleRect() const; virtual QRectF selectionToggleRect() const;
virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = 0); virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = 0);