+ connect(current, &KItemListView::scrollOrientationChanged, this, &KItemListContainer::slotScrollOrientationChanged);
+ connect(current, &KItemListView::scrollOffsetChanged, this, &KItemListContainer::updateScrollOffsetScrollBar);
+ connect(current, &KItemListView::maximumScrollOffsetChanged, this, &KItemListContainer::updateScrollOffsetScrollBar);
+ connect(current, &KItemListView::itemOffsetChanged, this, &KItemListContainer::updateItemOffsetScrollBar);
+ connect(current, &KItemListView::maximumItemOffsetChanged, this, &KItemListContainer::updateItemOffsetScrollBar);
+ connect(current, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo);
+ connect(m_horizontalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, current, &KItemListView::scrollingStopped);
+ connect(m_verticalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, current, &KItemListView::scrollingStopped);
+
+ m_horizontalSmoothScroller->setTargetObject(current);
+ m_verticalSmoothScroller->setTargetObject(current);
+ updateSmoothScrollers(current->scrollOrientation());
+ }
+}
+
+void KItemListContainer::scrollTo(qreal offset)
+{
+ const KItemListView *view = m_controller->view();
+ if (view) {
+ if (view->scrollOrientation() == Qt::Vertical) {
+ m_verticalSmoothScroller->scrollTo(offset);
+ } else {
+ m_horizontalSmoothScroller->scrollTo(offset);
+ }
+ }
+}
+
+void KItemListContainer::updateScrollOffsetScrollBar()
+{
+ const KItemListView *view = m_controller->view();
+ if (!view) {
+ return;
+ }
+
+ KItemListSmoothScroller *smoothScroller = nullptr;
+ QScrollBar *scrollOffsetScrollBar = nullptr;
+ int pageStep = 0;
+ int maximum = 0;
+ if (view->scrollOrientation() == Qt::Vertical) {
+ smoothScroller = m_verticalSmoothScroller;
+ if (smoothScroller->isAnimating()) {
+ return;
+ }
+ scrollOffsetScrollBar = verticalScrollBar();
+
+ // 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();
+
+ // However, the total height of the view must be considered for the
+ // maximum value of the scroll bar. Note that the view's scrollOffset()
+ // refers to the offset of the top part of the view, which might be
+ // hidden behind the header.
+ maximum = qMax(0, int(view->maximumScrollOffset() - view->size().height()));
+ } else {
+ smoothScroller = m_horizontalSmoothScroller;
+ if (smoothScroller->isAnimating()) {
+ return;
+ }
+ scrollOffsetScrollBar = horizontalScrollBar();
+ pageStep = view->size().width();
+ maximum = qMax(0, int(view->maximumScrollOffset() - view->size().width()));
+ }
+
+ const int singleStep = view->scrollSingleStep();
+ const int value = view->scrollOffset();
+ if (smoothScroller->requestScrollBarUpdate(maximum)) {
+ const bool updatePolicy = (scrollOffsetScrollBar->maximum() > 0 && maximum == 0) || horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOn;
+
+ scrollOffsetScrollBar->setSingleStep(singleStep);
+ scrollOffsetScrollBar->setPageStep(pageStep);
+ scrollOffsetScrollBar->setMinimum(0);
+ scrollOffsetScrollBar->setMaximum(maximum);
+ scrollOffsetScrollBar->setValue(value);
+
+ if (updatePolicy) {
+ // Prevent a potential endless layout loop (see bug #293318).
+ updateScrollOffsetScrollBarPolicy();
+ }