diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-01-11 11:10:52 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-01-11 13:45:51 +0000 |
commit | 4a97498f4c20936ac61f364b74d7476097a7e8bf (patch) | |
tree | ce90fc52852af31369f657712719752f32e8787c /src/quicktemplates2 | |
parent | 0b6bf36e246dab0912b3f1de04581979a435b3df (diff) |
Add SwipeView::orientation
[ChangeLog][Controls][SwipeView] Added orientation property.
Task-number: QTBUG-56031
Change-Id: I4ed47d659ef83cb48f63b703b681bdf1b8662fe8
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickswipeview.cpp | 34 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipeview_p.h | 5 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp index 79fc221a..b2075e80 100644 --- a/src/quicktemplates2/qquickswipeview.cpp +++ b/src/quicktemplates2/qquickswipeview.cpp @@ -106,7 +106,7 @@ class QQuickSwipeViewPrivate : public QQuickContainerPrivate Q_DECLARE_PUBLIC(QQuickSwipeView) public: - QQuickSwipeViewPrivate() : interactive(true) { } + QQuickSwipeViewPrivate() : interactive(true), orientation(Qt::Horizontal) { } void resizeItem(QQuickItem *item); void resizeItems(); @@ -114,6 +114,7 @@ public: static QQuickSwipeViewPrivate *get(QQuickSwipeView *view); bool interactive; + Qt::Orientation orientation; }; void QQuickSwipeViewPrivate::resizeItems() @@ -130,6 +131,10 @@ void QQuickSwipeViewPrivate::resizeItems() item->setProperty("_q_QQuickSwipeView_warned", true); } + if (orientation == Qt::Horizontal) + item->setY(0); + else + item->setX(0); item->setSize(QSizeF(contentItem->width(), contentItem->height())); } } @@ -172,6 +177,33 @@ void QQuickSwipeView::setInteractive(bool interactive) emit interactiveChanged(); } +/*! + \qmlproperty enumeration QtQuick.Controls::SwipeView::orientation + + This property holds the orientation. + + Possible values: + \value Qt.Horizontal Horizontal (default) + \value Qt.Vertical Vertical +*/ +Qt::Orientation QQuickSwipeView::orientation() const +{ + Q_D(const QQuickSwipeView); + return d->orientation; +} + +void QQuickSwipeView::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickSwipeView); + if (d->orientation == orientation) + return; + + d->orientation = orientation; + if (isComponentComplete()) + d->resizeItems(); + emit orientationChanged(); +} + QQuickSwipeViewAttached *QQuickSwipeView::qmlAttachedProperties(QObject *object) { return new QQuickSwipeViewAttached(object); diff --git a/src/quicktemplates2/qquickswipeview_p.h b/src/quicktemplates2/qquickswipeview_p.h index 832cde37..8a46f0d2 100644 --- a/src/quicktemplates2/qquickswipeview_p.h +++ b/src/quicktemplates2/qquickswipeview_p.h @@ -59,6 +59,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipeView : public QQuickContainer { Q_OBJECT Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION 1) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL REVISION 2) public: explicit QQuickSwipeView(QQuickItem *parent = nullptr); @@ -66,10 +67,14 @@ public: bool isInteractive() const; void setInteractive(bool interactive); + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + static QQuickSwipeViewAttached *qmlAttachedProperties(QObject *object); Q_SIGNALS: Q_REVISION(1) void interactiveChanged(); + Q_REVISION(2) void orientationChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; |