summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-20 11:21:29 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-20 11:59:51 (GMT)
commit90beb4a5e37b887caad1e767046a42dad0af1ab3 (patch)
tree27ec05401c5eff1038d41fe1e1092338c0fc9e19
parent3187c511c4aea82b954915387567d0d4e88f124e (diff)
Fix slow scrolling in dock panels
Commit f688bcd1f1 fixed slow scrolling with xf86-input-libinput on DolphinView. However the commit also exposed a bug in the Dolphin scrolling algorithm, which was previously hidden. This resulted in slow scrolling in dock panels (Places and Folders), with both xf86-input-evdev and xf86-input-libinput drivers, as well as libinput on Wayland. KItemListContainer::updateScrollOffsetScrollBar() relied on the view's itemSize() method to compute the scrollbar's singleStep, but this QSize was invalid for the dock panels' views. We use a new itemSizeHint() method instead, which is always valid and also adapts to the current icon size set in the view. BUG: 365968 FIXED-IN: 16.12.0 REVIEW: 129409
-rw-r--r--src/kitemviews/kitemlistcontainer.cpp2
-rw-r--r--src/kitemviews/kitemlistview.cpp5
-rw-r--r--src/kitemviews/kitemlistview.h7
-rw-r--r--src/kitemviews/private/kitemlistsizehintresolver.cpp13
-rw-r--r--src/kitemviews/private/kitemlistsizehintresolver.h2
5 files changed, 27 insertions, 2 deletions
diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp
index 6974ebb..6a0c575 100644
--- a/src/kitemviews/kitemlistcontainer.cpp
+++ b/src/kitemviews/kitemlistcontainer.cpp
@@ -265,7 +265,7 @@ void KItemListContainer::updateScrollOffsetScrollBar()
if (view->scrollOrientation() == Qt::Vertical) {
smoothScroller = m_verticalSmoothScroller;
scrollOffsetScrollBar = verticalScrollBar();
- singleStep = view->itemSize().height();
+ singleStep = view->itemSizeHint().height();
// 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();
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index df65399..d840509 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -344,6 +344,11 @@ QSizeF KItemListView::itemSize() const
return m_itemSize;
}
+QSizeF KItemListView::itemSizeHint() const
+{
+ return m_sizeHintResolver->maxSizeHint();
+}
+
const KItemListStyleOption& KItemListView::styleOption() const
{
return m_styleOption;
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index 9adf9f8..c93297c 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -154,10 +154,15 @@ public:
/**
* @return The basic size of all items. The size of an item may be larger than
- * the basic size (see KItemListView::itemSizeHint() and KItemListView::itemRect()).
+ * the basic size (see KItemListView::itemRect()).
*/
QSizeF itemSize() const;
+ /**
+ * @return The size hint of all items. It is provided by the KItemListSizeHintResolver.
+ */
+ QSizeF itemSizeHint() const;
+
const KItemListStyleOption& styleOption() const;
virtual void setGeometry(const QRectF& rect) Q_DECL_OVERRIDE;
diff --git a/src/kitemviews/private/kitemlistsizehintresolver.cpp b/src/kitemviews/private/kitemlistsizehintresolver.cpp
index 1d80670..02f1865 100644
--- a/src/kitemviews/private/kitemlistsizehintresolver.cpp
+++ b/src/kitemviews/private/kitemlistsizehintresolver.cpp
@@ -25,6 +25,7 @@ KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView* itemLi
m_itemListView(itemListView),
m_logicalHeightHintCache(),
m_logicalWidthHint(0.0),
+ m_logicalHeightHint(0.0),
m_needsResolving(false)
{
}
@@ -33,6 +34,12 @@ KItemListSizeHintResolver::~KItemListSizeHintResolver()
{
}
+QSizeF KItemListSizeHintResolver::maxSizeHint()
+{
+ updateCache();
+ return QSizeF(m_logicalWidthHint, m_logicalHeightHint);
+}
+
QSizeF KItemListSizeHintResolver::sizeHint(int index)
{
updateCache();
@@ -149,6 +156,12 @@ 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_needsResolving = false;
}
}
diff --git a/src/kitemviews/private/kitemlistsizehintresolver.h b/src/kitemviews/private/kitemlistsizehintresolver.h
index ff17f2d..841e9ca 100644
--- a/src/kitemviews/private/kitemlistsizehintresolver.h
+++ b/src/kitemviews/private/kitemlistsizehintresolver.h
@@ -36,6 +36,7 @@ class DOLPHIN_EXPORT KItemListSizeHintResolver
public:
KItemListSizeHintResolver(const KItemListView* itemListView);
virtual ~KItemListSizeHintResolver();
+ QSizeF maxSizeHint();
QSizeF sizeHint(int index);
void itemsInserted(const KItemRangeList& itemRanges);
@@ -50,6 +51,7 @@ private:
const KItemListView* m_itemListView;
mutable QVector<qreal> m_logicalHeightHintCache;
mutable qreal m_logicalWidthHint;
+ mutable qreal m_logicalHeightHint;
bool m_needsResolving;
};