From: Tobias Koenig Date: Wed, 31 Oct 2012 09:12:35 +0000 (+0100) Subject: Add support for StackedLayout X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=55eb2f5b94fc61cfce246c0afccb150702a8746b;p=web%2Fkonrad%2FDeclarativeWidgets.git Add support for StackedLayout --- diff --git a/declarativeobjects.cpp b/declarativeobjects.cpp index 6cee37d..fd13166 100644 --- a/declarativeobjects.cpp +++ b/declarativeobjects.cpp @@ -574,6 +574,25 @@ void DeclarativeHBoxLayout::addLayout(QLayout *layout, AbstractDeclarativeObject CUSTOM_METAOBJECT(DeclarativeHBoxLayout, QHBoxLayout) +// DeclarativeStackedLayout +DeclarativeStackedLayout::DeclarativeStackedLayout(QObject *parent) : DeclarativeLayoutProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeStackedLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + m_proxiedObject->addWidget(widget); + m_children.append(declarativeObject); +} + +void DeclarativeStackedLayout::addLayout(QLayout*, AbstractDeclarativeObject *declarativeObject) +{ + qmlInfo(declarativeObject) << "StackedLayout does not support child layouts"; +} + +CUSTOM_METAOBJECT(DeclarativeStackedLayout, StackedLayout) + // DeclarativeVBoxLayout DeclarativeVBoxLayout::DeclarativeVBoxLayout(QObject *parent) : DeclarativeLayoutProxy(parent) { diff --git a/declarativeobjects_p.h b/declarativeobjects_p.h index 9063756..df5073f 100644 --- a/declarativeobjects_p.h +++ b/declarativeobjects_p.h @@ -439,6 +439,18 @@ class DeclarativeHBoxLayout : public DeclarativeLayoutProxy QML_DECLARE_TYPEINFO(DeclarativeHBoxLayout, QML_HAS_ATTACHED_PROPERTIES) +class DeclarativeStackedLayout : public DeclarativeLayoutProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeStackedLayout(QObject *parent = 0); + + protected: + void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + class DeclarativeVBoxLayout : public DeclarativeLayoutProxy { DECLARATIVE_OBJECT diff --git a/declarativewidgetdocument.cpp b/declarativewidgetdocument.cpp index 328ef5c..441a805 100644 --- a/declarativewidgetdocument.cpp +++ b/declarativewidgetdocument.cpp @@ -43,6 +43,7 @@ DeclarativeWidgetDocument::DeclarativeWidgetDocument(const QUrl &url, QObject *p qmlRegisterType("QtGui", 1, 0, "FormLayout"); qmlRegisterType("QtGui", 1, 0, "GridLayout"); qmlRegisterType("QtGui", 1, 0, "HBoxLayout"); + qmlRegisterType("QtGui", 1, 0, "StackedLayout"); qmlRegisterType("QtGui", 1, 0, "VBoxLayout"); // widgets diff --git a/layouts.qml b/layouts.qml index 8bab331..c02389f 100644 --- a/layouts.qml +++ b/layouts.qml @@ -156,4 +156,28 @@ TabWidget { } } } + + Widget { + TabWidget.label: "Stacked Layout" + VBoxLayout { + PushButton { + text: "Next Page" + onClicked: { + stackedLayout.currentIndex = ((stackedLayout.currentIndex + 1) % stackedLayout.count) + } + } + StackedLayout { + id: stackedLayout + Label { + text: "Page 1" + } + Label { + text: "Page 2" + } + Label { + text: "Page 3" + } + } + } + } } diff --git a/objectadaptors_p.h b/objectadaptors_p.h index 84209a4..30a75cb 100644 --- a/objectadaptors_p.h +++ b/objectadaptors_p.h @@ -5,6 +5,7 @@ #include #include #include +#include #include class ActionItem : public QObject @@ -93,6 +94,13 @@ class InputDialog : public QInputDialog void customDoubleValueChanged(); }; +class StackedLayout : public QStackedLayout +{ + Q_OBJECT + + Q_PROPERTY(int count READ count) +}; + class TextEdit : public QTextEdit { Q_OBJECT diff --git a/qwidgets.list b/qwidgets.list index 2002ae7..bf54942 100644 --- a/qwidgets.list +++ b/qwidgets.list @@ -25,7 +25,6 @@ qprintpreviewwidget.h qscrollarea.h qsplashscreen.h qsplitter.h -qstackedlayout.h qstackedwidget.h qtabbar.h qtableview.h