diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-02-22 17:25:25 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-20 13:04:00 +0100 |
commit | c0df0b6fc002acd22f40284f8ca5377ae96fa1ce (patch) | |
tree | 65809c103291c104d49fa1ca99375eaf1ccfccff /src | |
parent | beeb0840b745a29895ee4e9aeac0b07f63998c69 (diff) | |
download | qtquickcontrols-c0df0b6fc002acd22f40284f8ca5377ae96fa1ce.tar.gz |
Remove the Page control - use attached properties instead
Change-Id: I69599daeea4ba49689fbbbe58c5d4a60fccc8824
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/Page.qml | 99 | ||||
-rw-r--r-- | src/controls/PageStack.qml | 73 | ||||
-rw-r--r-- | src/controls/controls.pro | 1 | ||||
-rw-r--r-- | src/controls/plugin.cpp | 4 | ||||
-rw-r--r-- | src/controls/plugin.pri | 5 | ||||
-rw-r--r-- | src/controls/qmldir | 1 | ||||
-rw-r--r-- | src/controls/qtstack.cpp | 164 | ||||
-rw-r--r-- | src/controls/qtstack_p.h (renamed from src/controls/qpagestatus.h) | 52 |
8 files changed, 243 insertions, 156 deletions
diff --git a/src/controls/Page.qml b/src/controls/Page.qml deleted file mode 100644 index 4295f65c..00000000 --- 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 89cf0170..388a766e 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 df9f120f..51716652 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 20d2f394..b7dd36cd 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 61bda5da..82f42ea3 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 377b55ee..be9fff4f 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 00000000..09f2c534 --- /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 index b4c0db8f..aa22bf8c 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 |