]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Improve scroll wheel speed by basing it on label height, not icon height
authorNate Graham <nate@kde.org>
Wed, 20 Feb 2019 17:05:06 +0000 (10:05 -0700)
committerNate Graham <nate@kde.org>
Sat, 21 Dec 2019 18:54:46 +0000 (11:54 -0700)
Summary:
Dolphin currently scrolls by the height of three items at a time per "step" when
using a scroll wheel. Because item height is highly variable, this leads to scroll
speed being inconsistent between views, and generally far too fast when using
icon view with icons larger than 22px size.

This patch makes the size of the scroll step based on the text label rather than the
icon size just like D25683, ensuring that the scroll speed does not vary and become
super fast when using large icons in particular.

It also reverts 90beb4a5e37b887caad1e767046a42dad0af1ab3, which is no longer needed.

BUG: 386379
FIXED-IN: 19.12.1

Test Plan:
Use a mouse with a scroll wheel and scroll in Dolphin item views with list view,
details view, icon view, etc, using different item sizes. Speed should be
consistent in all views now, and also feel consistent with other KDE apps.

Also try with multiple scale factors to make sure the behavior does not change.

No change with high-resolution two-finger touchpad scrolling.

Reviewers: #dolphin, elvisangelaccio

Reviewed By: #dolphin, elvisangelaccio

Subscribers: ahiemstra, lots0logs, anthonyfieroni, kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D19190

src/kitemviews/kitemlistcontainer.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h
src/kitemviews/private/kitemlistsizehintresolver.cpp

index 2deba5466d1ed3948a8ce3371041c8bdcabaec3c..b274e75e2f0c18617f193a7a07cacb3f00046e80 100644 (file)
@@ -27,6 +27,7 @@
 #include "private/kitemlistsmoothscroller.h"
 
 #include <QApplication>
+#include <QFontMetrics>
 #include <QGraphicsScene>
 #include <QGraphicsView>
 #include <QScrollBar>
@@ -261,7 +262,14 @@ void KItemListContainer::updateScrollOffsetScrollBar()
     if (view->scrollOrientation() == Qt::Vertical) {
         smoothScroller = m_verticalSmoothScroller;
         scrollOffsetScrollBar = verticalScrollBar();
-        singleStep = view->itemSizeHint().height();
+
+        // Don't scroll super fast when using a wheel mouse:
+        // We want to consider one "line" to be the text label which has a
+        // roughly fixed height rather than using the height of the icon which
+        // may be very tall
+        const QFontMetrics metrics(font());
+        singleStep = metrics.height() * QApplication::wheelScrollLines();
+
         // We cannot use view->size().height() because this height might
         // include the header widget, which is not part of the scrolled area.
         pageStep = view->verticalPageStep();
index 53682461a400bc6de352fb78e6f0011ef72a1418..e64e226ab70c2328e8363fe4cb056b047c32acdd 100644 (file)
@@ -335,11 +335,6 @@ QSizeF KItemListView::itemSize() const
     return m_itemSize;
 }
 
-QSizeF KItemListView::itemSizeHint() const
-{
-    return m_sizeHintResolver->minSizeHint();
-}
-
 const KItemListStyleOption& KItemListView::styleOption() const
 {
     return m_styleOption;
index 9349e5003cf55ecc268946eace92ee499c96f025..3dff35a63276f4a0c493838708d4453ef2849a8f 100644 (file)
@@ -158,11 +158,6 @@ public:
      */
     QSizeF itemSize() const;
 
-    /**
-     * @return The size hint of all items. It is provided by the KItemListSizeHintResolver.
-     */
-    QSizeF itemSizeHint() const;
-
     const KItemListStyleOption& styleOption() const;
 
     void setGeometry(const QRectF& rect) override;
index c53bb2a4a6874e9964a30c4d3eadb9d0abe36df6..66784f191ac25e2d20c978c53edbc99e20d012d9 100644 (file)
@@ -24,7 +24,6 @@ KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView* itemLi
     m_itemListView(itemListView),
     m_logicalHeightHintCache(),
     m_logicalWidthHint(0.0),
-    m_logicalHeightHint(0.0),
     m_minHeightHint(0.0),
     m_needsResolving(false)
 {
@@ -34,12 +33,6 @@ KItemListSizeHintResolver::~KItemListSizeHintResolver()
 {
 }
 
-QSizeF KItemListSizeHintResolver::maxSizeHint()
-{
-    updateCache();
-    return QSizeF(m_logicalWidthHint, m_logicalHeightHint);
-}
-
 QSizeF KItemListSizeHintResolver::minSizeHint()
 {
     updateCache();
@@ -162,13 +155,6 @@ void KItemListSizeHintResolver::updateCache()
 {
     if (m_needsResolving) {
         m_itemListView->calculateItemSizeHints(m_logicalHeightHintCache, m_logicalWidthHint);
-        // Set logical height as the max cached height (if the cache is not empty).
-        if (m_logicalHeightHintCache.isEmpty()) {
-            m_logicalHeightHint = 0.0;
-        } else {
-            m_logicalHeightHint = *std::max_element(m_logicalHeightHintCache.begin(), m_logicalHeightHintCache.end());
-            m_minHeightHint = *std::min_element(m_logicalHeightHintCache.begin(), m_logicalHeightHintCache.end());
-        }
         m_needsResolving = false;
     }
 }