Add support for StackedLayout
authorTobias Koenig <tobias.koenig@kdab.com>
Wed, 31 Oct 2012 09:12:35 +0000 (10:12 +0100)
committerTobias Koenig <tobias.koenig@kdab.com>
Wed, 31 Oct 2012 09:12:35 +0000 (10:12 +0100)
declarativeobjects.cpp
declarativeobjects_p.h
declarativewidgetdocument.cpp
layouts.qml
objectadaptors_p.h
qwidgets.list

index 6cee37d..fd13166 100644 (file)
@@ -574,6 +574,25 @@ void DeclarativeHBoxLayout::addLayout(QLayout *layout, AbstractDeclarativeObject
 
 CUSTOM_METAOBJECT(DeclarativeHBoxLayout, QHBoxLayout)
 
+// DeclarativeStackedLayout
+DeclarativeStackedLayout::DeclarativeStackedLayout(QObject *parent) : DeclarativeLayoutProxy<StackedLayout>(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<QVBoxLayout>(parent)
 {
index 9063756..df5073f 100644 (file)
@@ -439,6 +439,18 @@ class DeclarativeHBoxLayout : public DeclarativeLayoutProxy<QHBoxLayout>
 
 QML_DECLARE_TYPEINFO(DeclarativeHBoxLayout, QML_HAS_ATTACHED_PROPERTIES)
 
+class DeclarativeStackedLayout : public DeclarativeLayoutProxy<StackedLayout>
+{
+  DECLARATIVE_OBJECT
+
+  public:
+    DeclarativeStackedLayout(QObject *parent = 0);
+
+  protected:
+    void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject);
+    void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject);
+};
+
 class DeclarativeVBoxLayout : public DeclarativeLayoutProxy<QVBoxLayout>
 {
   DECLARATIVE_OBJECT
index 328ef5c..441a805 100644 (file)
@@ -43,6 +43,7 @@ DeclarativeWidgetDocument::DeclarativeWidgetDocument(const QUrl &url, QObject *p
   qmlRegisterType<DeclarativeFormLayout>("QtGui", 1, 0, "FormLayout");
   qmlRegisterType<DeclarativeGridLayout>("QtGui", 1, 0, "GridLayout");
   qmlRegisterType<DeclarativeHBoxLayout>("QtGui", 1, 0, "HBoxLayout");
+  qmlRegisterType<DeclarativeStackedLayout>("QtGui", 1, 0, "StackedLayout");
   qmlRegisterType<DeclarativeVBoxLayout>("QtGui", 1, 0, "VBoxLayout");
 
   // widgets
index 8bab331..c02389f 100644 (file)
@@ -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"
+        }
+      }
+    }
+  }
 }
index 84209a4..30a75cb 100644 (file)
@@ -5,6 +5,7 @@
 #include <QtGui/QButtonGroup>
 #include <QtGui/QFileDialog>
 #include <QtGui/QInputDialog>
+#include <QtGui/QStackedLayout>
 #include <QtGui/QTextEdit>
 
 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
index 2002ae7..bf54942 100644 (file)
@@ -25,7 +25,6 @@ qprintpreviewwidget.h
 qscrollarea.h
 qsplashscreen.h
 qsplitter.h
-qstackedlayout.h
 qstackedwidget.h
 qtabbar.h
 qtableview.h