Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kitemlistcontainer.cpp
Show All 24 Lines | |||||
25 | #include "kitemlistcontroller.h" | 25 | #include "kitemlistcontroller.h" | ||
26 | #include "kitemlistview.h" | 26 | #include "kitemlistview.h" | ||
27 | #include "private/kitemlistsmoothscroller.h" | 27 | #include "private/kitemlistsmoothscroller.h" | ||
28 | 28 | | |||
29 | #include <QApplication> | 29 | #include <QApplication> | ||
30 | #include <QGraphicsScene> | 30 | #include <QGraphicsScene> | ||
31 | #include <QGraphicsView> | 31 | #include <QGraphicsView> | ||
32 | #include <QScrollBar> | 32 | #include <QScrollBar> | ||
33 | #include <QScroller> | ||||
33 | #include <QStyleOption> | 34 | #include <QStyleOption> | ||
34 | 35 | | |||
35 | /** | 36 | /** | ||
36 | * Replaces the default viewport of KItemListContainer by a | 37 | * Replaces the default viewport of KItemListContainer by a | ||
37 | * non-scrollable viewport. The scrolling is done in an optimized | 38 | * non-scrollable viewport. The scrolling is done in an optimized | ||
38 | * way by KItemListView internally. | 39 | * way by KItemListView internally. | ||
39 | */ | 40 | */ | ||
40 | class KItemListContainerViewport : public QGraphicsView | 41 | class KItemListContainerViewport : public QGraphicsView | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 72 | { | |||
84 | if (controller->view()) { | 85 | if (controller->view()) { | ||
85 | slotViewChanged(controller->view(), nullptr); | 86 | slotViewChanged(controller->view(), nullptr); | ||
86 | } | 87 | } | ||
87 | 88 | | |||
88 | connect(controller, &KItemListController::modelChanged, | 89 | connect(controller, &KItemListController::modelChanged, | ||
89 | this, &KItemListContainer::slotModelChanged); | 90 | this, &KItemListContainer::slotModelChanged); | ||
90 | connect(controller, &KItemListController::viewChanged, | 91 | connect(controller, &KItemListController::viewChanged, | ||
91 | this, &KItemListContainer::slotViewChanged); | 92 | this, &KItemListContainer::slotViewChanged); | ||
93 | connect(controller, &KItemListController::setTouchScroll, | ||||
94 | this, &KItemListContainer::slotSetTouchScroll); | ||||
95 | | ||||
96 | slotSetTouchScroll(true); | ||||
92 | } | 97 | } | ||
93 | 98 | | |||
94 | KItemListContainer::~KItemListContainer() | 99 | KItemListContainer::~KItemListContainer() | ||
95 | { | 100 | { | ||
96 | // Don't rely on the QObject-order to delete the controller, otherwise | 101 | // Don't rely on the QObject-order to delete the controller, otherwise | ||
97 | // the QGraphicsScene might get deleted before the view. | 102 | // the QGraphicsScene might get deleted before the view. | ||
98 | delete m_controller; | 103 | delete m_controller; | ||
99 | m_controller = nullptr; | 104 | m_controller = nullptr; | ||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 233 | connect(current, &KItemListView::maximumItemOffsetChanged, | |||
229 | this, &KItemListContainer::updateItemOffsetScrollBar); | 234 | this, &KItemListContainer::updateItemOffsetScrollBar); | ||
230 | connect(current, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo); | 235 | connect(current, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo); | ||
231 | m_horizontalSmoothScroller->setTargetObject(current); | 236 | m_horizontalSmoothScroller->setTargetObject(current); | ||
232 | m_verticalSmoothScroller->setTargetObject(current); | 237 | m_verticalSmoothScroller->setTargetObject(current); | ||
233 | updateSmoothScrollers(current->scrollOrientation()); | 238 | updateSmoothScrollers(current->scrollOrientation()); | ||
234 | } | 239 | } | ||
235 | } | 240 | } | ||
236 | 241 | | |||
242 | void KItemListContainer::slotSetTouchScroll(bool enabled) { | ||||
243 | if (enabled) { | ||||
244 | QScroller::grabGesture(this, QScroller::TouchGesture); | ||||
245 | } else { | ||||
246 | QScroller::ungrabGesture(this); | ||||
247 | } | ||||
248 | } | ||||
249 | | ||||
237 | void KItemListContainer::scrollTo(qreal offset) | 250 | void KItemListContainer::scrollTo(qreal offset) | ||
238 | { | 251 | { | ||
239 | const KItemListView* view = m_controller->view(); | 252 | const KItemListView* view = m_controller->view(); | ||
240 | if (view) { | 253 | if (view) { | ||
241 | if (view->scrollOrientation() == Qt::Vertical) { | 254 | if (view->scrollOrientation() == Qt::Vertical) { | ||
242 | m_verticalSmoothScroller->scrollTo(offset); | 255 | m_verticalSmoothScroller->scrollTo(offset); | ||
243 | } else { | 256 | } else { | ||
244 | m_horizontalSmoothScroller->scrollTo(offset); | 257 | m_horizontalSmoothScroller->scrollTo(offset); | ||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |