diff --git a/examples/touch/content/ButtonPage.qml b/examples/touch/content/ButtonPage.qml index ff86c81406e7abe5d1ae7f7471175367a398bd37..cc5925ce0d960ad2b507723b9cd2c1aaa4b836e0 100644 --- a/examples/touch/content/ButtonPage.qml +++ b/examples/touch/content/ButtonPage.qml @@ -46,7 +46,9 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 -Page { +Item { + width: parent.width + height: parent.height property real progress: 0 SequentialAnimation on progress { diff --git a/examples/touch/content/ProgressBarPage.qml b/examples/touch/content/ProgressBarPage.qml index abbf78fc786441b7bee94cd65d621dd7b937a85f..86a46b69bf2a92f24f6eb09489b9101aaaba92df 100644 --- a/examples/touch/content/ProgressBarPage.qml +++ b/examples/touch/content/ProgressBarPage.qml @@ -46,7 +46,9 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 -Page { +Item { + width: parent.width + height: parent.height property real progress: 0 SequentialAnimation on progress { diff --git a/examples/touch/content/SliderPage.qml b/examples/touch/content/SliderPage.qml index d90a3c2cd69108c25292f2af30baf9e98b83bc39..8d9ff0b1fdbc2a411fa8ad1af89de3bcab8bc953 100644 --- a/examples/touch/content/SliderPage.qml +++ b/examples/touch/content/SliderPage.qml @@ -46,7 +46,10 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 -Page { +Item { + width: parent.width + height: parent.height + Column { spacing: 12 anchors.centerIn: parent diff --git a/examples/touch/content/TabBarPage.qml b/examples/touch/content/TabBarPage.qml index 0a47308b6e0ecd8170cb07915a70d4b2883d747e..41de782209311a5c34dc4c6904cd1f91770129b5 100644 --- a/examples/touch/content/TabBarPage.qml +++ b/examples/touch/content/TabBarPage.qml @@ -46,7 +46,9 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 -Page { +Item { + width: parent.width + height: parent.height TabView { anchors.fill: parent diff --git a/examples/touch/content/TextInputPage.qml b/examples/touch/content/TextInputPage.qml index e363648b845590113c019e1a3a928eee4ef04a81..3f408d472f37fe210bb0be56500866d687d2d926 100644 --- a/examples/touch/content/TextInputPage.qml +++ b/examples/touch/content/TextInputPage.qml @@ -46,7 +46,9 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 -Page { +Item { + width: parent.width + height: parent.height property real progress: 0 SequentialAnimation on progress { diff --git a/examples/touch/main.qml b/examples/touch/main.qml index 3ce116f366c55b319c8eccc08c641510ee7c194a..2546b7da10012eef64a5c75ef4e5b2fcd5cf298b 100644 --- a/examples/touch/main.qml +++ b/examples/touch/main.qml @@ -133,7 +133,9 @@ ApplicationWindow { id: pageStack anchors.fill: parent - initialPage: Page { + initialPage: Item { + width: parent.width + height: parent.height ListView { model: pageModel anchors.fill: parent diff --git a/src/controls/Page.qml b/src/controls/Page.qml deleted file mode 100644 index 4295f65c00850669d7d186486c8a31ecf718a5e6..0000000000000000000000000000000000000000 --- a/src/controls/Page.qml +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Quick Controls module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.1 -import QtQuick.Controls 1.0 - -/*! - \qmltype Page - \inqmlmodule QtQuick.Controls 1.0 - \ingroup viewitems - \brief A Page is an Item you can push on a PageStack. - - A \a Page is the main Item pushed onto a \l PageStack. It normally contains a discrete - set of information and interaction elements meant for the user to solve a specific task, and - contains properties to use when working with a PageStack. - See \l PageStack for more information. - - \qml - \endqml -*/ - -Item { - id: root - - /*! \readonly - The status of the page. It can have one of the following values: - \list - \li \c PageStatus.Inactive: the page is not visible - \li \c PageStatus.Activating: the page is transitioning into becoming an active page on the stack - \li \c PageStatus.Active: the page is on top of the stack - \li \c PageStatus.Deactivating: the page is transitioning into becoming inactive - \endlist */ - readonly property alias status: root.__status - /*! \readonly - This property contains the PageStack the page is in. If the page is not inside - a PageStack, \a pageStack will be \c null. */ - readonly property alias pageStack: root.__pageStack - /*! \readonly - This property contains the index of the page inside \l{pageStack}{PageStack}, so - that \l{PageStack::get()}{pageStack.get(index)} will - return the page itself. If \l{Page::pageStack}{pageStack} is \c null, \a index - will be \c -1. */ - readonly property alias index: root.__index - /*! This property can be set to override the default animations used - during a page transition. To better understand how to use this - property, refer to the \l{PageStack#Transitions}{transition documentation} in PageStack. - \sa {PageStack::animations}{PageStack.animations} */ - property PageTransition pageTransition - - visible: false // PageStack will show/hide the page as needed - width: parent.width - height: parent.height - - // ********** PRIVATE API ********** - - /*! \internal */ - property int __status: PageStatus.Inactive - /*! \internal */ - property PageStack __pageStack: null - /*! \internal */ - property int __index: -1 -} diff --git a/src/controls/PageStack.qml b/src/controls/PageStack.qml index 89cf0170c03d0b6bebd5ac0bdef0bbe866d4bae8..388a766ed9b0dee9a49bed60fe8861edc3945fbb 100644 --- a/src/controls/PageStack.qml +++ b/src/controls/PageStack.qml @@ -57,16 +57,7 @@ import "Private/PageStack.js" as JSArray deeper into the application page hierarchy. Similarily, the user can return back to previous pages at a later point, which from a stack point of view means popping pages from the top of the stack and re-activating them (make them visible on screen). - - Pages can - but do not have to - use \l{Page} as the root item. - \l{Page} defines a contract for how the page and the page stack works together. - Namely the page can be notified when it becomes active or inactive - through the \l{Page::status} {Page.status} property. Status will be - \c PageStatus.Activating when a - page is transitioning into being the current page on screen, and \c PageStatus.Active - once the transition stops. When it leaves the screen, it will be - \c PageStatus.Deactivating, and then \c PageStatus.Inactive. When the page is - inactive, it will be hidden. + The \l Stack attached property provides information about items pushed onto a stack. \section1 Using PageStack in an Application Using the PageStack in the application is typically a simple matter of adding @@ -234,17 +225,17 @@ import "Private/PageStack.js" as JSArray Popping the page off the top of the stack at this point would not result in further deactivation since the page is not active. - There is a \l{Page::status}{status} property that tracks the lifecycle. The value of status is - an enumeration with values \c PageStatus.Inactive, \c PageStatus.Activating, \c PageStatus.Active - and \c PageStatus.Deactivating. Combined with the normal \c Component.onComplete and + There is an attached \l{Stack::status}{Stack.status} property that tracks the lifecycle. The value of status is + an enumeration with values \c Stack.Inactive, \c Stack.Activating, \c Stack.Active + and \c Stack.Deactivating. Combined with the normal \c Component.onComplete and \c Component.onDestruction signals the entire lifecycle is thus: \list \li Created: Component.onCompleted() - \li Activating: onStatusChanged (status is PageStatus.Activating) - \li Acivated: onStatusChanged (status is PageStatus.Active) - \li Deactivating: onStatusChanged (status is PageStatus.Deactivating) - \li Deactivated: onStatusChanged (status is PageStatus.Inactive) + \li Activating: Stack.onStatusChanged (Stack.status is Stack.Activating) + \li Acivated: Stack.onStatusChanged (Stack.status is Stack.Active) + \li Deactivating: Stack.onStatusChanged (Stack.status is Stack.Deactivating) + \li Deactivated: Stack.onStatusChanged (Stack.status is Stack.Inactive) \li Destruction: Component.onDestruction() \endlist @@ -372,12 +363,12 @@ import "Private/PageStack.js" as JSArray \endqml A single Page can also override the transition to use when itself is pushed or popped. This can - be done by just assigning another PageTransition object to \l{Page::pageTransition}{Page.pageTransition}. + be done by just assigning another PageTransition object to \l{Stack::pageTransition}{Stack.pageTransition}. \section2 Advanced usage After PageStack finds the correct transition to use (it first checks - \l{Page::pageTransition}{Page.pageTransition}, then \l {PageStack::pageTransition}{pageTransition}) + \l{Stack::pageTransition}{Stack.pageTransition}, then \l {PageStack::pageTransition}{pageTransition}) it calls \l {PageTransition::getAnimation(properties)}{PageTransition.getAnimation(properties)}. The base implementation of this function just looks for a property named \c properties.name inside itself (root), which is how it finds \c {property Component pushAnimation} in the examples above. @@ -493,7 +484,7 @@ Item { /*! The animations to use for page transitions. For better understanding on how to apply custom page transitions, read \l{Transitions}. - \sa {Page::animations}{Page.transitions} */ + \sa {Stack::animations}{Stack.transitions} */ property PageTransition pageTransition: PageSlideTransition {} /*! Pushes a page onto the stack. The function takes a property list as argument, which @@ -867,11 +858,9 @@ Item { // Mark the page as no longer part of the PageStack. It // might reenter on pop if pushed several times: page.visible = false - __setPageStatus(page, PageStatus.Inactive) - if (page.hasOwnProperty("__pageStack")) - page.__pageStack = null - if (page.hasOwnProperty("__index")) - page.__index = -1 + __setPageStatus(page, Stack.Inactive) + page.Stack.__pageStack = null + page.Stack.__index = -1 if (element.originalParent) page.parent = element.originalParent } @@ -879,8 +868,7 @@ Item { /*! \internal */ function __setPageStatus(page, status) { - if (page.hasOwnProperty("__status")) - page.__status = status + page.Stack.__status = status } /*! \internal */ @@ -888,7 +876,7 @@ Item { { // Animate page in "outElement" out, and page in "inElement" in. Set a guard to protect // the user from pushing new pages on signals that will fire while preparing for the transition - // (e.g Page.onCompleted, Page.onStatusChanged, Page.onIndexChanged etc). Otherwise, we will enter + // (e.g Stack.onCompleted, Stack.onStatusChanged, Stack.onIndexChanged etc). Otherwise, we will enter // this function several times, which causes the pages to be half-way updated. if (__currentTransition) __currentTransition.animation.complete() @@ -900,17 +888,15 @@ Item { // Since a page can be pushed several times, we need to update its properties: enterPage.parent = root - if (enterPage.hasOwnProperty("__pageStack")) - enterPage.__pageStack = root - if (enterPage.hasOwnProperty("__index")) - enterPage.__index = transition.inElement.index + enterPage.Stack.__pageStack = root + enterPage.Stack.__index = transition.inElement.index __currentPage = enterPage if (!transition.outElement) { // A transition consists of two pages, but we got just one. So just show the page: enterPage.visible = true - __setPageStatus(enterPage, PageStatus.Activating) - __setPageStatus(enterPage, PageStatus.Active) + __setPageStatus(enterPage, Stack.Activating) + __setPageStatus(enterPage, Stack.Active) return } @@ -919,9 +905,9 @@ Item { if (enterPage === exitPage) return - __searchForAnimationIn(transition.transitionElement.page, transition) + __searchForAnimationIn(transition.transitionElement.page.Stack.pageTransition, transition) if (!transition.animation) - __searchForAnimationIn(root, transition) + __searchForAnimationIn(root.pageTransition, transition) if (!transition.animation) { console.warn("Warning: PageStack: no", transition.name, "found!") return @@ -931,9 +917,9 @@ Item { console.warn("Warning: PageStack: cannot transition a page that is anchored!") __currentTransition = transition - __setPageStatus(exitPage, PageStatus.Deactivating) + __setPageStatus(exitPage, Stack.Deactivating) enterPage.visible = true - __setPageStatus(enterPage, PageStatus.Activating) + __setPageStatus(enterPage, Stack.Activating) transition.animation.runningChanged.connect(animationFinished) transition.animation.start() // NB! For empty animations, "animationFinished" is already @@ -945,15 +931,14 @@ Item { /*! \internal */ function __searchForAnimationIn(obj, transition) { - var t = obj.pageTransition - if (t) { - transition.pageTransition = t + if (obj) { + transition.pageTransition = obj transition.properties = { "name":transition.name, "enterPage":transition.enterPage, "exitPage":transition.exitPage, "immediate":transition.immediate } - var anim = t.getAnimation(transition.properties) + var anim = obj.getAnimation(transition.properties) if (anim.createObject) { anim = anim.createObject(null, transition.properties) anim.runningChanged.connect(function(){ if (anim.running === false) anim.destroy() }) @@ -970,8 +955,8 @@ Item { __currentTransition.animation.runningChanged.disconnect(animationFinished) __currentTransition.exitPage.visible = false - __setPageStatus(__currentTransition.exitPage, PageStatus.Inactive); - __setPageStatus(__currentTransition.enterPage, PageStatus.Active); + __setPageStatus(__currentTransition.exitPage, Stack.Inactive); + __setPageStatus(__currentTransition.enterPage, Stack.Active); __currentTransition.properties.animation = __currentTransition.animation __currentTransition.pageTransition.cleanupAnimation(__currentTransition.properties) diff --git a/src/controls/controls.pro b/src/controls/controls.pro index df9f120f3a7a5b230a99d77a602997a4b7cbdcfc..51716652b9a45549ef9af4a9e68205e95dfcc857 100644 --- a/src/controls/controls.pro +++ b/src/controls/controls.pro @@ -14,7 +14,6 @@ QML_FILES = \ Label.qml \ MenuBar.qml \ Menu.qml \ - Page.qml \ PageAnimation.qml \ PageStack.qml \ PageTransition.qml \ diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp index 20d2f394f8ee6e6648c3551fbc0f623ce3adbd2d..b7dd36cd3051210a8293f4c4d1c4d7b4584fd52c 100644 --- a/src/controls/plugin.cpp +++ b/src/controls/plugin.cpp @@ -44,7 +44,7 @@ #include "qtexclusivegroup_p.h" #include "qtmenu_p.h" #include "qtmenubar_p.h" -#include "qpagestatus.h" +#include "qtstack_p.h" #include <qimage.h> #include <qqml.h> @@ -86,7 +86,7 @@ void StylePlugin::registerTypes(const char *uri) qmlRegisterUncreatableType<QtMenuBase>(uri, 1, 0, "MenuBase", QLatin1String("Do not create objects of type MenuBase")); - qmlRegisterUncreatableType<QPageStatus>(uri, 1, 0, "PageStatus", QLatin1String("Do not create objects of type PageStatus")); + qmlRegisterUncreatableType<QtStack>(uri, 1, 0, "Stack", QLatin1String("Do not create objects of type Stack")); } void StylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) diff --git a/src/controls/plugin.pri b/src/controls/plugin.pri index 61bda5da61d328b95facb6993c73e2b6f5576571..82f42ea352bd4ac49bd9fda713cae7b58eede49d 100644 --- a/src/controls/plugin.pri +++ b/src/controls/plugin.pri @@ -7,7 +7,7 @@ HEADERS += \ $$PWD/qtmenuitem_p.h \ $$PWD/qtmenuitemcontainer_p.h \ $$PWD/qtmenupopupwindow_p.h \ - $$PWD/qpagestatus.h + $$PWD/qtstack_p.h SOURCES += \ $$PWD/plugin.cpp \ @@ -16,7 +16,8 @@ SOURCES += \ $$PWD/qtmenu.cpp \ $$PWD/qtmenubar.cpp \ $$PWD/qtmenuitem.cpp \ - $$PWD/qtmenupopupwindow.cpp + $$PWD/qtmenupopupwindow.cpp \ + $$PWD/qtstack.cpp OTHER_FILES += \ $$PWD/plugin.json diff --git a/src/controls/qmldir b/src/controls/qmldir index 377b55ee13168005b4b48b6b92d699daf57f0bff..be9fff4f0d0bdcb7f96ef24716a6a2f55c1f0a7b 100644 --- a/src/controls/qmldir +++ b/src/controls/qmldir @@ -8,7 +8,6 @@ GroupBox 1.0 GroupBox.qml Label 1.0 Label.qml MenuBar 1.0 MenuBar.qml Menu 1.0 Menu.qml -Page 1.0 Page.qml PageAnimation 1.0 PageAnimation.qml PageStack 1.0 PageStack.qml PageTransition 1.0 PageTransition.qml diff --git a/src/controls/qtstack.cpp b/src/controls/qtstack.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09f2c534d83ac4428d986fae45603b755334dd67 --- /dev/null +++ b/src/controls/qtstack.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtstack_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Stack + \instantiates QtStack + \inqmlmodule QtQuick.Controls 1.0 + \ingroup views + \brief Provides attached properties for items pushed onto a PageStack. + + The Stack attached property provides information when an item becomes + active or inactive through the \l{Stack::status}{Stack.status} property. + Status will be \c Stack.Activating when an item is transitioning into + being the current item on the screen, and \c Stack.Active once the + transition stops. When it leaves the screen, it will be + \c Stack.Deactivating, and then \c Stack.Inactive. + + \sa PageStack +*/ + +QtStack::QtStack(QObject *object) + : QObject(object), + m_index(-1), + m_status(Inactive), + m_pageStack(0), + m_pageTransition(0) +{ +} + +QtStack *QtStack::qmlAttachedProperties(QObject *object) +{ + return new QtStack(object); +} + +/*! + \readonly + \qmlproperty int Stack::index + + This property holds the index of the item inside \l{pageStack}{PageStack}, + so that \l{PageStack::get()}{pageStack.get(index)} will return the item itself. + If \l{Stack::pageStack}{pageStack} is \c null, \a index will be \c -1. +*/ +int QtStack::index() const +{ + return m_index; +} + +void QtStack::setIndex(int index) +{ + if (m_index != index) { + m_index = index; + emit indexChanged(); + } +} + +/*! + \readonly + \qmlproperty enumeration Stack::status + + This property holds the status of the item. It can have one of the following values: + \list + \li \c Stack.Inactive: the item is not visible + \li \c Stack.Activating: the item is transitioning into becoming an active item on the stack + \li \c Stack.Active: the item is on top of the stack + \li \c Stack.Deactivating: the item is transitioning into becoming inactive + \endlist +*/ +QtStack::Status QtStack::status() const +{ + return m_status; +} + +void QtStack::setStatus(Status status) +{ + if (m_status != status) { + m_status = status; + emit statusChanged(); + } +} + +/*! + \readonly + \qmlproperty PageStack Stack::pageStack + + This property holds the PageStack the item is in. If the item is not inside + a PageStack, \a pageStack will be \c null. +*/ +QQuickItem *QtStack::pageStack() const +{ + return m_pageStack; +} + +void QtStack::setPageStack(QQuickItem *pageStack) +{ + if (m_pageStack != pageStack) { + m_pageStack = pageStack; + emit pageStackChanged(); + } +} + +/*! + \qmlproperty PageTransition Stack::pageTransition + + This property can be set to override the default animations used + during a page transition. To better understand how to use this + property, refer to the \l{PageStack#Transitions}{transition documentation} in PageStack. + \sa {PageStack::animations}{PageStack.animations} +*/ +QObject *QtStack::pageTransition() const +{ + return m_pageTransition; +} + +void QtStack::setPageTransition(QObject* pageTransition) +{ + if (m_pageTransition != pageTransition) { + m_pageTransition = pageTransition; + emit pageTransitionChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qpagestatus.h b/src/controls/qtstack_p.h similarity index 60% rename from src/controls/qpagestatus.h rename to src/controls/qtstack_p.h index b4c0db8fc65a8aa2c49ed07fc504bbf8a0b23586..aa22bf8c768439a3b92051412ed1b320ad1d3b89 100644 --- a/src/controls/qpagestatus.h +++ b/src/controls/qtstack_p.h @@ -39,27 +39,65 @@ ** ****************************************************************************/ -#ifndef QPAGESTATUS_H -#define QPAGESTATUS_H +#ifndef QTSTACK_P_H +#define QTSTACK_P_H -#include <QtCore/qobject.h> +#include <QtQuick/qquickitem.h> QT_BEGIN_NAMESPACE -class QPageStatus : public QObject +class QtStack : public QObject { Q_OBJECT - Q_ENUMS(PageStatus) + Q_PROPERTY(int index READ index NOTIFY indexChanged) + Q_PROPERTY(int __index READ index WRITE setIndex NOTIFY indexChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(Status __status READ status WRITE setStatus NOTIFY statusChanged) + Q_PROPERTY(QQuickItem* pageStack READ pageStack NOTIFY pageStackChanged) + Q_PROPERTY(QQuickItem* __pageStack READ pageStack WRITE setPageStack NOTIFY pageStackChanged) + Q_PROPERTY(QObject* pageTransition READ pageTransition WRITE setPageTransition NOTIFY pageTransitionChanged) + Q_ENUMS(Status) public: - enum PageStatus { + QtStack(QObject *object = 0); + + static QtStack *qmlAttachedProperties(QObject *object); + + int index() const; + void setIndex(int index); + + enum Status { Inactive = 0, Deactivating = 1, Activating = 2, Active = 3 }; + + Status status() const; + void setStatus(Status status); + + QQuickItem *pageStack() const; + void setPageStack(QQuickItem *pageStack); + + QObject *pageTransition() const; + void setPageTransition(QObject* pageTransition); + +signals: + void statusChanged(); + void pageStackChanged(); + void indexChanged(); + void pageTransitionChanged(); + +private: + int m_index; + Status m_status; + QQuickItem *m_pageStack; + QObject *m_pageTransition; }; QT_END_NAMESPACE -#endif // QPAGESTATUS_H +QML_DECLARE_TYPE(QtStack) +QML_DECLARE_TYPEINFO(QtStack, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QTSTACK_P_H diff --git a/tests/auto/controls/data/tst_pagestack.qml b/tests/auto/controls/data/tst_pagestack.qml index e5c56dbdbacda0c86dd53557e287989ba1d30c25..f03235718260a966c7d3a55d858f9b763397af1b 100644 --- a/tests/auto/controls/data/tst_pagestack.qml +++ b/tests/auto/controls/data/tst_pagestack.qml @@ -52,7 +52,7 @@ TestCase { Item { id: anItem } Component { id: pageComponent - Page {} + Item {} } Component { diff --git a/tests/auto/controls/data/tst_page.qml b/tests/auto/controls/data/tst_stack.qml similarity index 75% rename from tests/auto/controls/data/tst_page.qml rename to tests/auto/controls/data/tst_stack.qml index acb0f627bad2cbaae6d338772308a0435eec26ee..f51251e9ff0ced8282cc7a3df54c1a405850be68 100644 --- a/tests/auto/controls/data/tst_page.qml +++ b/tests/auto/controls/data/tst_stack.qml @@ -43,14 +43,23 @@ import QtTest 1.0 TestCase { id: testCase - name: "Tests_Page" + name: "Tests_Stack" when:windowShown width:400 height:400 - function test_createPage() { - var page = Qt.createQmlObject('import QtQuick.Controls 1.0; Page {}', testCase, ''); + function test_index() { + var item = Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Controls 1.0; Item { property int index: Stack.index }', testCase, ''); + compare(item.index, -1); } + function test_status() { + var item = Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Controls 1.0; Item { property int status: Stack.status }', testCase, ''); + compare(item.status, 0); // Stack.Inactive + } + function test_pageStack() { + var item = Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Controls 1.0; Item { property PageStack pageStack: Stack.pageStack }', testCase, ''); + compare(item.pageStack, null); + } } diff --git a/tests/manual/PageStack.qml b/tests/manual/PageStack.qml index 0b3713af3537684faba4af261492a956c234a6d6..e84b67876fe26ae90c988b6273a40fdbce32b637 100644 --- a/tests/manual/PageStack.qml +++ b/tests/manual/PageStack.qml @@ -133,23 +133,25 @@ Window { Component { id: pageComponent - Page { + Item { id: page - Component.onDestruction: console.log("destroyed component page: " + index) + width: parent.width + height: parent.height + Component.onDestruction: console.log("destroyed component page: " + Stack.index) property bool pushFromOnCompleted: false Component.onCompleted: if (pushFromOnCompleted) pageStack.push(pageComponent) //pageTransition: rotateTransition Rectangle { anchors.fill: parent - color: index % 2 ? "green" : "yellow" + color: page.Stack.index % 2 ? "green" : "yellow" Column { Text { - text: "This is component page: " + page.index + text: "This is component page: " + page.Stack.index } Text { - text: "Current status: " + page.status + text: "Current status: " + page.Stack.status } Text { text:" " } Button { @@ -194,11 +196,11 @@ Window { } Button { text: "Search for page 3, and pop down to it" - onClicked: pageStack.pop(pageStack.find(function(page) { if (page.index === 3) return true })) + onClicked: pageStack.pop(pageStack.find(function(page) { if (page.Stack.index === 3) return true })) } Button { text: "Search for page 3, and pop down to it (dontLoad == true)" - onClicked: pageStack.pop(pageStack.find(function(page) { if (page.index === 3) return true }, true)) + onClicked: pageStack.pop(pageStack.find(function(page) { if (page.Stack.index === 3) return true }, true)) } Button { text: "Clear" @@ -229,22 +231,25 @@ Window { } } - Page { + Item { id: pageInline - Component.onDestruction: console.log("destroyed inline page: " + index) + visible: false + width: parent.width + height: parent.height + Component.onDestruction: console.log("destroyed inline page: " + Stack.index) - pageTransition: rotateTransition + Stack.pageTransition: rotateTransition Rectangle { anchors.fill: parent - color: pageInline.index % 2 ? "green" : "yellow" + color: pageInline.Stack.index % 2 ? "green" : "yellow" Column { Text { - text: "This is inline page: " + pageInline.index + text: "This is inline page: " + pageInline.Stack.index } Text { - text: "Current status: " + pageInline.status + text: "Current status: " + pageInline.Stack.status } Button { text: "Push component page" @@ -280,11 +285,11 @@ Window { } Button { text: "Search for page 3, and pop down to it" - onClicked: pageStack.pop(pageStack.find(function(page) { if (page.index === 3) return true })) + onClicked: pageStack.pop(pageStack.find(function(page) { if (pageInline.Stack.index === 3) return true })) } Button { text: "Search for page 3, and pop down to it (dontLoad == true)" - onClicked: pageStack.pop(pageStack.find(function(page) { if (page.index === 3) return true }, true)) + onClicked: pageStack.pop(pageStack.find(function(page) { if (pageInline.Stack.index === 3) return true }, true)) } Button { text: "Clear"