aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickscrollview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickscrollview.cpp')
-rw-r--r--src/quicktemplates2/qquickscrollview.cpp155
1 files changed, 62 insertions, 93 deletions
diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp
index 451f54d4..abd75d31 100644
--- a/src/quicktemplates2/qquickscrollview.cpp
+++ b/src/quicktemplates2/qquickscrollview.cpp
@@ -35,7 +35,7 @@
****************************************************************************/
#include "qquickscrollview_p.h"
-#include "qquickcontrol_p_p.h"
+#include "qquickpane_p_p.h"
#include "qquickscrollbar_p_p.h"
#include <QtQuick/private/qquickflickable_p.h>
@@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE
/*!
\qmltype ScrollView
- \inherits Control
+ \inherits Pane
\instantiates QQuickScrollView
\inqmlmodule QtQuick.Controls
\since 5.9
@@ -115,11 +115,15 @@ QT_BEGIN_NAMESPACE
{Focus Management in Qt Quick Controls 2}
*/
-class QQuickScrollViewPrivate : public QQuickControlPrivate
+class QQuickScrollViewPrivate : public QQuickPanePrivate
{
Q_DECLARE_PUBLIC(QQuickScrollView)
public:
+ QQmlListProperty<QObject> contentData() override;
+ QQmlListProperty<QQuickItem> contentChildren() override;
+ QList<QQuickItem *> contentChildItems() const override;
+
QQuickItem *getContentItem() override;
QQuickFlickable *ensureFlickable(bool content);
@@ -143,12 +147,20 @@ public:
static QQuickItem *contentChildren_at(QQmlListProperty<QQuickItem> *prop, int index);
static void contentChildren_clear(QQmlListProperty<QQuickItem> *prop);
+ void itemImplicitWidthChanged(QQuickItem *item) override;
+
bool wasTouched = false;
- qreal contentWidth = -1;
- qreal contentHeight = -1;
QQuickFlickable *flickable = nullptr;
};
+QList<QQuickItem *> QQuickScrollViewPrivate::contentChildItems() const
+{
+ if (!flickable)
+ return QList<QQuickItem *>();
+
+ return flickable->contentItem()->childItems();
+}
+
QQuickItem *QQuickScrollViewPrivate::getContentItem()
{
if (!contentItem)
@@ -178,7 +190,7 @@ bool QQuickScrollViewPrivate::setFlickable(QQuickFlickable *item, bool content)
if (attached)
QQuickScrollBarAttachedPrivate::get(attached)->setFlickable(nullptr);
- QObject::disconnect(flickable->contentItem(), &QQuickItem::childrenChanged, q, &QQuickScrollView::contentChildrenChanged);
+ QObjectPrivate::disconnect(flickable->contentItem(), &QQuickItem::childrenChanged, this, &QQuickPanePrivate::contentChildrenChange);
QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentWidthChanged, this, &QQuickScrollViewPrivate::updateContentWidth);
QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentHeightChanged, this, &QQuickScrollViewPrivate::updateContentHeight);
}
@@ -189,19 +201,19 @@ bool QQuickScrollViewPrivate::setFlickable(QQuickFlickable *item, bool content)
if (flickable) {
flickable->installEventFilter(q);
- if (contentWidth > 0)
- item->setContentWidth(contentWidth);
+ if (hasContentWidth)
+ flickable->setContentWidth(contentWidth);
else
updateContentWidth();
- if (contentHeight > 0)
- item->setContentHeight(contentHeight);
+ if (hasContentHeight)
+ flickable->setContentHeight(contentHeight);
else
updateContentHeight();
if (attached)
QQuickScrollBarAttachedPrivate::get(attached)->setFlickable(flickable);
- QObject::connect(flickable->contentItem(), &QQuickItem::childrenChanged, q, &QQuickScrollView::contentChildrenChanged);
+ QObjectPrivate::connect(flickable->contentItem(), &QQuickItem::childrenChanged, this, &QQuickPanePrivate::contentChildrenChange);
QObjectPrivate::connect(flickable, &QQuickFlickable::contentWidthChanged, this, &QQuickScrollViewPrivate::updateContentWidth);
QObjectPrivate::connect(flickable, &QQuickFlickable::contentHeightChanged, this, &QQuickScrollViewPrivate::updateContentHeight);
}
@@ -216,11 +228,11 @@ void QQuickScrollViewPrivate::updateContentWidth()
return;
const qreal cw = flickable->contentWidth();
- if (qFuzzyCompare(cw, contentWidth))
+ if (qFuzzyCompare(cw, implicitContentWidth))
return;
- contentWidth = cw;
- emit q->contentWidthChanged();
+ implicitContentWidth = cw;
+ emit q->implicitContentWidthChanged();
}
void QQuickScrollViewPrivate::updateContentHeight()
@@ -230,11 +242,11 @@ void QQuickScrollViewPrivate::updateContentHeight()
return;
const qreal ch = flickable->contentHeight();
- if (qFuzzyCompare(ch, contentHeight))
+ if (qFuzzyCompare(ch, implicitContentHeight))
return;
- contentHeight = ch;
- emit q->contentHeightChanged();
+ implicitContentHeight = ch;
+ emit q->implicitContentHeightChanged();
}
QQuickScrollBar *QQuickScrollViewPrivate::verticalScrollBar() const
@@ -356,73 +368,24 @@ void QQuickScrollViewPrivate::contentChildren_clear(QQmlListProperty<QQuickItem>
children.clear(&children);
}
-QQuickScrollView::QQuickScrollView(QQuickItem *parent)
- : QQuickControl(*(new QQuickScrollViewPrivate), parent)
+void QQuickScrollViewPrivate::itemImplicitWidthChanged(QQuickItem *item)
{
- setFlag(ItemIsFocusScope);
- setActiveFocusOnTab(true);
- setFiltersChildMouseEvents(true);
- setWheelEnabled(true);
-}
-
-/*!
- \qmlproperty real QtQuick.Controls::ScrollView::contentWidth
-
- This property holds the width of the scrollable content.
-
- If only a single item is used within a ScrollView, the content size is
- automatically calculated based on the implicit size of its contained item.
-
- \sa contentHeight, Sizing
-*/
-qreal QQuickScrollView::contentWidth() const
-{
- Q_D(const QQuickScrollView);
- return d->contentWidth;
-}
-
-void QQuickScrollView::setContentWidth(qreal width)
-{
- Q_D(QQuickScrollView);
- if (qFuzzyCompare(d->contentWidth, width))
+ // a special case for width<->height dependent content (wrapping text) in ScrollView
+ if (contentWidth < 0 && !componentComplete)
return;
- if (d->flickable) {
- d->flickable->setContentWidth(width);
- } else {
- d->contentWidth = width;
- emit contentWidthChanged();
- }
-}
-
-/*!
- \qmlproperty real QtQuick.Controls::ScrollView::contentHeight
-
- This property holds the height of the scrollable content.
-
- If only a single item is used within a ScrollView, the content size is
- automatically calculated based on the implicit size of its contained item.
-
- \sa contentWidth, Sizing
-*/
-qreal QQuickScrollView::contentHeight() const
-{
- Q_D(const QQuickScrollView);
- return d->contentHeight;
+ QQuickPanePrivate::itemImplicitWidthChanged(item);
}
-void QQuickScrollView::setContentHeight(qreal height)
+QQuickScrollView::QQuickScrollView(QQuickItem *parent)
+ : QQuickPane(*(new QQuickScrollViewPrivate), parent)
{
Q_D(QQuickScrollView);
- if (qFuzzyCompare(d->contentHeight, height))
- return;
+ d->contentWidth = -1;
+ d->contentHeight = -1;
- if (d->flickable) {
- d->flickable->setContentHeight(height);
- } else {
- d->contentHeight = height;
- emit contentHeightChanged();
- }
+ setFiltersChildMouseEvents(true);
+ setWheelEnabled(true);
}
/*!
@@ -437,10 +400,10 @@ void QQuickScrollView::setContentHeight(qreal height)
\sa Item::data, contentChildren
*/
-QQmlListProperty<QObject> QQuickScrollView::contentData()
+QQmlListProperty<QObject> QQuickScrollViewPrivate::contentData()
{
- Q_D(QQuickScrollView);
- return QQmlListProperty<QObject>(this, d,
+ Q_Q(QQuickScrollView);
+ return QQmlListProperty<QObject>(q, this,
QQuickScrollViewPrivate::contentData_append,
QQuickScrollViewPrivate::contentData_count,
QQuickScrollViewPrivate::contentData_at,
@@ -458,10 +421,10 @@ QQmlListProperty<QObject> QQuickScrollView::contentData()
\sa Item::children, contentData
*/
-QQmlListProperty<QQuickItem> QQuickScrollView::contentChildren()
+QQmlListProperty<QQuickItem> QQuickScrollViewPrivate::contentChildren()
{
- Q_D(QQuickScrollView);
- return QQmlListProperty<QQuickItem>(this, d,
+ Q_Q(QQuickScrollView);
+ return QQmlListProperty<QQuickItem>(q, this,
QQuickScrollViewPrivate::contentChildren_append,
QQuickScrollViewPrivate::contentChildren_count,
QQuickScrollViewPrivate::contentChildren_at,
@@ -517,13 +480,13 @@ bool QQuickScrollView::eventFilter(QObject *object, QEvent *event)
if (!d->wheelEnabled)
return true;
}
- return QQuickControl::eventFilter(object, event);
+ return QQuickPane::eventFilter(object, event);
}
void QQuickScrollView::keyPressEvent(QKeyEvent *event)
{
Q_D(QQuickScrollView);
- QQuickControl::keyPressEvent(event);
+ QQuickPane::keyPressEvent(event);
switch (event->key()) {
case Qt::Key_Up:
if (QQuickScrollBar *vbar = d->verticalScrollBar()) {
@@ -558,22 +521,26 @@ void QQuickScrollView::keyPressEvent(QKeyEvent *event)
void QQuickScrollView::componentComplete()
{
Q_D(QQuickScrollView);
- QQuickControl::componentComplete();
- if (!d->contentItem) {
+ QQuickPane::componentComplete();
+ if (!d->contentItem)
d->ensureFlickable(true);
- } else {
- if (d->contentWidth <= 0)
- d->updateContentWidth();
- if (d->contentHeight <= 0)
- d->updateContentHeight();
- }
}
void QQuickScrollView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
{
Q_D(QQuickScrollView);
- QQuickControl::contentItemChange(newItem, oldItem);
d->setFlickable(qobject_cast<QQuickFlickable *>(newItem), false);
+ QQuickPane::contentItemChange(newItem, oldItem);
+}
+
+void QQuickScrollView::contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize)
+{
+ Q_D(QQuickScrollView);
+ QQuickPane::contentSizeChange(newSize, oldSize);
+ if (d->flickable) {
+ d->flickable->setContentWidth(newSize.width());
+ d->flickable->setContentHeight(newSize.height());
+ }
}
#if QT_CONFIG(accessibility)
@@ -584,3 +551,5 @@ QAccessible::Role QQuickScrollView::accessibleRole() const
#endif
QT_END_NAMESPACE
+
+#include "moc_qquickscrollview_p.cpp"