┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kitemlistwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kitemviews/kitemlistwidget.cpp')
-rw-r--r--src/kitemviews/kitemlistwidget.cpp94
1 files changed, 59 insertions, 35 deletions
diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp
index 089211716..2d94c4303 100644
--- a/src/kitemviews/kitemlistwidget.cpp
+++ b/src/kitemviews/kitemlistwidget.cpp
@@ -121,9 +121,13 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
painter->fillRect(backgroundRect, backgroundColor);
}
+ const QStyle::State selectedState(m_selected ? QStyle::State_Selected : QStyle::State(0));
if ((m_selected || m_current) && m_editedRole.isEmpty()) {
const QStyle::State activeState(isActiveWindow() && widget->hasFocus() ? QStyle::State_Active : 0);
- drawItemStyleOption(painter, widget, activeState | QStyle::State_Enabled | QStyle::State_Selected | QStyle::State_Item);
+ // Only pass State_Selected when the item is actually selected, not just when
+ // it has keyboard focus (m_current), to avoid styles drawing a persistent
+ // selection highlight on focused but unselected items.
+ drawItemStyleOption(painter, widget, activeState | selectedState | QStyle::State_Enabled | QStyle::State_Item);
}
if (m_hoverOpacity > 0.0) {
@@ -135,7 +139,7 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
QPainter pixmapPainter(m_hoverCache);
const QStyle::State activeState(isActiveWindow() && widget->hasFocus() ? QStyle::State_Active | QStyle::State_Enabled : 0);
- drawItemStyleOption(&pixmapPainter, widget, activeState | QStyle::State_MouseOver | QStyle::State_Item);
+ drawItemStyleOption(&pixmapPainter, widget, activeState | selectedState | QStyle::State_MouseOver | QStyle::State_Item);
}
const qreal opacity = painter->opacity();
@@ -231,6 +235,7 @@ void KItemListWidget::setSelected(bool selected)
m_selectionToggle->setChecked(selected);
}
selectedChanged(selected);
+ clearHoverCache();
update();
}
}
@@ -617,50 +622,69 @@ void KItemListWidget::setPressed(bool enabled)
void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QStyle::State styleState)
{
+ painter->save();
QStyleOptionViewItem viewItemOption;
- constexpr int roundness = 5; // From Breeze style.
- constexpr qreal penWidth = 1.25;
initStyleOption(&viewItemOption);
viewItemOption.state = styleState;
viewItemOption.viewItemPosition = QStyleOptionViewItem::OnlyOne;
viewItemOption.showDecorationSelected = true;
viewItemOption.rect = selectionRectFull().toRect();
- QPainterPath path;
- const qreal adjustment = 0.5 * penWidth; // Use same adjustments as Breeze strokedRect uses, to snap to pixelGrid.
- path.addRoundedRect(selectionRectFull().adjusted(adjustment, adjustment, -adjustment, -adjustment), roundness, roundness);
- QColor backgroundColor{widget->palette().color(QPalette::Accent)};
- painter->setRenderHint(QPainter::Antialiasing);
- bool current = m_current && styleState & QStyle::State_Active;
-
- // Background item, alpha values are from
- // https://invent.kde.org/plasma/libplasma/-/blob/master/src/desktoptheme/breeze/widgets/viewitem.svg
- backgroundColor.setAlphaF(0.0);
+ const bool current = m_current && styleState & QStyle::State_Active;
- if (m_clickHighlighted) {
- backgroundColor.setAlphaF(1.0);
- } else {
- if (m_selected && m_hovered) {
- backgroundColor.setAlphaF(0.40);
- } else if (m_selected) {
- backgroundColor.setAlphaF(0.32);
- } else if (m_hovered) {
- backgroundColor = widget->palette().color(QPalette::Text);
- backgroundColor.setAlphaF(0.06);
+ // TODO: Remove this check after Plasma 6.8 release
+ // See: https://invent.kde.org/plasma/breeze/-/merge_requests/595
+ if (style()->name() == QStringLiteral("breeze")) {
+ QColor backgroundColor{widget->palette().color(QPalette::Active, QPalette::Highlight)};
+ backgroundColor.setAlphaF(0.0);
+ if (m_clickHighlighted) {
+ backgroundColor.setAlphaF(1.0);
+ } else {
+ if (m_selected && m_hovered) {
+ backgroundColor.setAlphaF(0.85);
+ } else if (m_selected) {
+ backgroundColor.setAlphaF(0.70);
+ } else if (m_hovered) {
+ backgroundColor = widget->palette().color(QPalette::Text);
+ backgroundColor.setAlphaF(0.12);
+ }
}
- }
+ painter->setRenderHint(QPainter::Antialiasing);
+ constexpr int roundness = 5; // From Breeze style.
+ constexpr qreal penWidth = 1.25;
+ QPainterPath path;
+ const qreal adjustment = 0.5 * penWidth; // Use same adjustments as Breeze strokedRect uses, to snap to pixelGrid.
+ path.addRoundedRect(selectionRectFull().adjusted(adjustment, adjustment, -adjustment, -adjustment), roundness, roundness);
+ painter->fillPath(path, backgroundColor);
- painter->fillPath(path, backgroundColor);
+ // Focus decoration
+ if (current) {
+ QColor focusColor{widget->palette().color(QPalette::Active, QPalette::Highlight)};
+ // Set the pen color lighter or darker depending on background color
+ focusColor = m_styleOption.palette.color(QPalette::Base).lightnessF() > 0.5 ? focusColor.darker(110) : focusColor.lighter(110);
+ focusColor.setAlphaF(m_selected || m_hovered ? 1.0 : 0.8);
+ QPen pen{focusColor, penWidth};
+ pen.setCosmetic(true);
+ painter->strokePath(path, pen);
+ }
+ } else {
+ style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
- // Focus decoration
- if (current) {
- QColor focusColor{widget->palette().color(QPalette::Accent)};
- focusColor = m_styleOption.palette.color(QPalette::Base).lightnessF() > 0.5 ? focusColor.darker(110) : focusColor.lighter(110);
- focusColor.setAlphaF(m_selected || m_hovered ? 1.0 : 0.8);
- // Set the pen color lighter or darker depending on background color
- QPen pen{focusColor, penWidth};
- pen.setCosmetic(true);
- painter->strokePath(path, pen);
+ // Focus decoration
+ if (current) {
+ QStyleOptionFocusRect focusRectOption;
+ initStyleOption(&focusRectOption);
+ focusRectOption.state = QStyle::State_HasFocus;
+ if (m_selected && widget->hasFocus()) {
+ focusRectOption.state = QStyle::State_HasFocus | QStyle::State_Selected;
+ }
+ if (m_hovered) {
+ focusRectOption.state |= QStyle::State_MouseOver;
+ }
+ focusRectOption.rect = viewItemOption.rect;
+ style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget);
+ }
}
+ painter->restore();
}
#include "moc_kitemlistwidget.cpp"