3#include "qml_material/scrollable/flickable.hpp"
4#include <QtQuick/private/qquickflickable_p.h>
12 explicit ScrollViewport(QObject*
object)
13 : m_owned(qobject_cast<Flickable*>(object)), m_qt(qobject_cast<QQuickFlickable*>(object)) {}
15 QQuickItem* item()
const {
16 return m_owned ?
static_cast<QQuickItem*
>(m_owned.data()) : m_qt.data();
18 QObject* visibleArea()
const {
19 if (m_owned)
return m_owned->visibleArea();
20 return m_qt ? m_qt->property(
"visibleArea").value<QObject*>() : nullptr;
22 bool moving(
bool horizontal)
const {
24 return horizontal ? m_owned->isMovingHorizontally() : m_owned->isMovingVertically();
25 return m_qt && (horizontal ? m_qt->isMovingHorizontally() : m_qt->isMovingVertically());
27 qreal offset(
bool horizontal)
const {
28 if (m_owned)
return horizontal ? m_owned->contentX() : m_owned->contentY();
29 return m_qt ? (horizontal ? m_qt->contentX() : m_qt->contentY()) : 0;
31 bool pixelAligned()
const {
32 return m_owned ? m_owned->pixelAligned() : m_qt && m_qt->pixelAligned();
34 void setOffset(
bool horizontal, qreal position) {
37 m_owned->setContentX(position);
39 m_owned->setContentY(position);
42 m_qt->setContentX(position);
44 m_qt->setContentY(position);
48 void observeMoving(QObject* receiver, F callback) {
49 auto connectOwner = [receiver, callback](
auto* owner) {
50 using Owner = std::remove_pointer_t<
decltype(owner)>;
51 QObject::connect(owner, &Owner::movingHorizontallyChanged, receiver, [callback] {
54 QObject::connect(owner, &Owner::movingVerticallyChanged, receiver, [callback] {
59 connectOwner(m_owned.data());
61 connectOwner(m_qt.data());
65 QPointer<Flickable> m_owned;
66 QPointer<QQuickFlickable> m_qt;