From 4d8f89f55a030758bf818a668bf6edad451df356 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Fri, 27 Jun 2014 13:02:12 +0200 Subject: Remove current item highlighting in the Places Panel In the Places Panel, there is always exactly one selected item, which is equal to the current item. Since the selected item is highlighted by drawing its background in a different color, it is not really necessary to highlight additionally that it is the current item. This is achieved by removing the calls to KItemListWidget::setCurrent(true) from KItemListView. The "current" information in the widget is only used for deciding if the "current item highlighting", like an underline in Oxygen, should be drawn. The motivation for this change is that I have seem some complaints about the "current item" highlighting, which can be even more distracting with non-Oxygen styles. REVIEW: 119019 --- src/kitemviews/kitemlistview.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/kitemviews') diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 281258898..756f9e39a 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -1332,14 +1332,18 @@ void KItemListView::slotCurrentChanged(int current, int previous) { Q_UNUSED(previous); - KItemListWidget* previousWidget = m_visibleItems.value(previous, 0); - if (previousWidget) { - previousWidget->setCurrent(false); - } + // In SingleSelection mode (e.g., in the Places Panel), the current item is + // always the selected item. It is not necessary to highlight the current item then. + if (m_controller->selectionBehavior() != KItemListController::SingleSelection) { + KItemListWidget* previousWidget = m_visibleItems.value(previous, 0); + if (previousWidget) { + previousWidget->setCurrent(false); + } - KItemListWidget* currentWidget = m_visibleItems.value(current, 0); - if (currentWidget) { - currentWidget->setCurrent(true); + KItemListWidget* currentWidget = m_visibleItems.value(current, 0); + if (currentWidget) { + currentWidget->setCurrent(true); + } } QAccessible::updateAccessibility(this, current+1, QAccessible::Focus); } @@ -1978,7 +1982,12 @@ void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index) widget->setStyleOption(m_styleOption); const KItemListSelectionManager* selectionManager = m_controller->selectionManager(); - widget->setCurrent(index == selectionManager->currentItem()); + + // In SingleSelection mode (e.g., in the Places Panel), the current item is + // always the selected item. It is not necessary to highlight the current item then. + if (m_controller->selectionBehavior() != KItemListController::SingleSelection) { + widget->setCurrent(index == selectionManager->currentItem()); + } widget->setSelected(selectionManager->isSelected(index)); widget->setHovered(false); widget->setEnabledSelectionToggle(enabledSelectionToggles()); -- cgit v1.3.1 From 20e13c31df64f5fe3dfd410a1b0a0bd78c07ba32 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Fri, 4 Jul 2014 00:49:31 +0200 Subject: 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 --- src/kitemviews/kitemlistwidget.cpp | 2 +- src/kitemviews/kitemlistwidget.h | 5 +++++ src/kitemviews/kstandarditemlistwidget.cpp | 25 ++++++++++++++++++++++++- src/kitemviews/kstandarditemlistwidget.h | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src/kitemviews') diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index c261bf1d2..e7d2951b9 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -522,7 +522,7 @@ void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QS 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); } diff --git a/src/kitemviews/kitemlistwidget.h b/src/kitemviews/kitemlistwidget.h index a06bb5c9c..c086ee6d3 100644 --- a/src/kitemviews/kitemlistwidget.h +++ b/src/kitemviews/kitemlistwidget.h @@ -163,6 +163,11 @@ public: */ 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 diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index e0375480e..998acc066 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -494,6 +494,29 @@ QRectF KStandardItemListWidget::textFocusRect() const return m_textRect; } +QRectF KStandardItemListWidget::selectionRect() const +{ + const_cast(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(this)->triggerCacheRefreshing(); @@ -945,7 +968,7 @@ void KStandardItemListWidget::updatePixmapCache() 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); diff --git a/src/kitemviews/kstandarditemlistwidget.h b/src/kitemviews/kstandarditemlistwidget.h index 4f7a9136e..403794fc3 100644 --- a/src/kitemviews/kstandarditemlistwidget.h +++ b/src/kitemviews/kstandarditemlistwidget.h @@ -109,6 +109,7 @@ public: 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); -- cgit v1.3.1