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 | |
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')
-rw-r--r-- | src/imports/controls/SwipeView.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/material/SwipeView.qml | 2 | ||||
-rw-r--r-- | src/imports/templates/qtquicktemplates2plugin.cpp | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipeview.cpp | 34 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipeview_p.h | 5 |
5 files changed, 41 insertions, 3 deletions
diff --git a/src/imports/controls/SwipeView.qml b/src/imports/controls/SwipeView.qml index df569721..4ccef22b 100644 --- a/src/imports/controls/SwipeView.qml +++ b/src/imports/controls/SwipeView.qml @@ -52,7 +52,7 @@ T.SwipeView { currentIndex: control.currentIndex spacing: control.spacing - orientation: Qt.Horizontal + orientation: control.orientation snapMode: ListView.SnapOneItem boundsBehavior: Flickable.StopAtBounds diff --git a/src/imports/controls/material/SwipeView.qml b/src/imports/controls/material/SwipeView.qml index 77a7b9f6..293cce46 100644 --- a/src/imports/controls/material/SwipeView.qml +++ b/src/imports/controls/material/SwipeView.qml @@ -51,7 +51,7 @@ T.SwipeView { currentIndex: control.currentIndex spacing: control.spacing - orientation: Qt.Horizontal + orientation: control.orientation snapMode: ListView.SnapOneItem boundsBehavior: Flickable.StopAtBounds diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 3166afd9..c50ca2f6 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -234,6 +234,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) qmlRegisterType<QQuickSlider, 2>(uri, 2, 2, "Slider"); qmlRegisterType<QQuickSpinBox, 2>(uri, 2, 2, "SpinBox"); qmlRegisterType<QQuickSwipeDelegate, 2>(uri, 2, 2, "SwipeDelegate"); + qmlRegisterType<QQuickSwipeView, 2>(uri, 2, 2, "SwipeView"); qmlRegisterType<QQuickTabBar, 2>(uri, 2, 2, "TabBar"); qmlRegisterType<QQuickTumbler, 2>(uri, 2, 2, "Tumbler"); } 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; |