Port main window
authorKevin Krammer <kevin.krammer@kdab.com>
Mon, 14 Jan 2013 17:04:54 +0000 (18:04 +0100)
committerKevin Krammer <kevin.krammer@kdab.com>
Tue, 15 Jan 2013 12:05:41 +0000 (13:05 +0100)
lib/declarativemainwindowextension.cpp [moved from lib/declarativemainwindow.cpp with 58% similarity]
lib/declarativemainwindowextension_p.h [moved from lib/declarativemainwindow_p.h with 64% similarity]
lib/declarativewidgetsdocument.cpp
lib/lib.pro

similarity index 58%
rename from lib/declarativemainwindow.cpp
rename to lib/declarativemainwindowextension.cpp
index 87da5c7..fdaa7ab 100644 (file)
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-#include "declarativemainwindow_p.h"
+#include "declarativemainwindowextension_p.h"
 
+#include <QDeclarativeInfo>
 #include <QDialog>
+#include <QMainWindow>
 #include <QMenuBar>
 #include <QStatusBar>
 #include <QToolBar>
 
-DeclarativeMainWindow::DeclarativeMainWindow(QObject *parent)
-  : DeclarativeWidgetProxy<QMainWindow>(parent)
+DeclarativeMainWindowExtension::DeclarativeMainWindowExtension(QObject *parent)
+  : DeclarativeWidgetExtension(parent)
 {
-  connectAllSignals(m_proxiedObject, this);
 }
 
-void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject)
+QMainWindow *DeclarativeMainWindowExtension::extendedMainWindow() const
+{
+  QMainWindow *mainWindow = qobject_cast<QMainWindow*>(extendedWidget());
+  Q_ASSERT(mainWindow);
+
+  return mainWindow;
+}
+
+void DeclarativeMainWindowExtension::addWidget(QWidget *widget)
 {
   QMenuBar *menuBar = qobject_cast<QMenuBar*>(widget);
   QToolBar *toolBar = qobject_cast<QToolBar*>(widget);
@@ -39,31 +48,26 @@ void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject
   QDialog *dialog = qobject_cast<QDialog*>(widget);
 
   if (menuBar) {
-    m_proxiedObject->setMenuBar(menuBar);
+    extendedMainWindow()->setMenuBar(menuBar);
   } else if (toolBar) {
-    m_proxiedObject->addToolBar(toolBar);
+    extendedMainWindow()->addToolBar(toolBar);
   } else if (statusBar) {
-    m_proxiedObject->setStatusBar(statusBar);
+    extendedMainWindow()->setStatusBar(statusBar);
   } else if (dialog) {
     // We allow to place dialogs on the mainwindow
-    dialog->setParent(m_proxiedObject, dialog->windowFlags());
+    dialog->setParent(extendedMainWindow(), dialog->windowFlags());
   } else if (widget) {
-    if (m_proxiedObject->centralWidget()) {
-      qmlInfo(declarativeObject) << "The QMainWindow contains a central widget already";
+    if (extendedMainWindow()->centralWidget()) {
+      qmlInfo(extendedMainWindow()) << "The MainWindow already contains a central widget";
       return;
     }
 
-    m_proxiedObject->setCentralWidget(widget);
+    extendedMainWindow()->setCentralWidget(widget);
   }
-
-  m_children.append(declarativeObject);
 }
 
-void DeclarativeMainWindow::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject)
+void DeclarativeMainWindowExtension::setLayout(QLayout *layout)
 {
   Q_UNUSED(layout);
-  Q_UNUSED(declarativeObject);
-  qmlInfo(this) << "Can not set a QLayout to a QMainWindow";
+  qmlInfo(this) << "Can not set a Layout to a MainWindow";
 }
-
-CUSTOM_METAOBJECT(DeclarativeMainWindow, QMainWindow)
similarity index 64%
rename from lib/declarativemainwindow_p.h
rename to lib/declarativemainwindowextension_p.h
index 4778ad7..0fcd4e2 100644 (file)
 #ifndef DECLARATIVEMAINWINDOW_P_H
 #define DECLARATIVEMAINWINDOW_P_H
 
-#include "declarativewidgetproxy_p.h"
+#include "declarativewidgetextension.h"
 
-#include <QMainWindow>
+class QMainWindow;
 
-class DeclarativeMainWindow : public DeclarativeWidgetProxy<QMainWindow>
+class DeclarativeMainWindowExtension : public DeclarativeWidgetExtension
 {
-  DECLARATIVE_OBJECT
+  Q_OBJECT
+
+  // repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class
+  Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
+
+  Q_CLASSINFO("DefaultProperty", "data")
 
   public:
-    explicit DeclarativeMainWindow(QObject *parent = 0);
+    explicit DeclarativeMainWindowExtension(QObject *parent = 0);
+
+    QMainWindow *extendedMainWindow() const;
 
   protected:
-    void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject);
-    void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject);
+    void addWidget(QWidget *widget);
+    void setLayout(QLayout *layout);
 };
 
 #endif
index ce02609..64c6b11 100644 (file)
@@ -46,7 +46,7 @@
 #include "declarativeinputdialog_p.h"
 #include "declarativelcdnumber_p.h"
 #include "declarativelistview_p.h"
-#include "declarativemainwindow_p.h"
+#include "declarativemainwindowextension_p.h"
 #include "declarativemenubar_p.h"
 #include "declarativemenu_p.h"
 #include "declarativemessagebox_p.h"
@@ -79,6 +79,9 @@
 #include <QDeclarativeContext>
 #include <QDeclarativeEngine>
 #include <QLabel>
+#include <QMainWindow>
+#include <QMenu>
+#include <QMenuBar>
 #include <QRadioButton>
 #include <QWebView>
 
@@ -131,7 +134,6 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject
   qmlRegisterType<DeclarativeLabel>("QtGui", 1, 0, "Label");
   qmlRegisterType<DeclarativeLCDNumber>("QtGui", 1, 0, "LCDNumber");
   qmlRegisterType<DeclarativeListView>("QtGui", 1, 0, "ListView");
-  qmlRegisterType<DeclarativeMainWindow>("QtGui", 1, 0, "MainWindow");
   qmlRegisterType<DeclarativeMenu>("QtGui", 1, 0, "Menu");
   qmlRegisterType<DeclarativeMenuBar>("QtGui", 1, 0, "MenuBar");
   qmlRegisterType<DeclarativeMessageBoxAttached>();
@@ -176,6 +178,7 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject
   qmlRegisterExtendedType<QCheckBox, DeclarativeWidgetExtension>("QtGui", 1, 0, "CheckBox");
   qmlRegisterExtendedType<QLabel, DeclarativeWidgetExtension>("QtGui", 1, 0, "Label");
   qmlRegisterExtendedType<QLineEdit, DeclarativeWidgetExtension>("QtGui", 1, 0, "LineEdit");
+  qmlRegisterExtendedType<QMainWindow, DeclarativeMainWindowExtension>("QtGui", 1, 0, "MainWindow");
   qmlRegisterExtendedType<QPushButton, DeclarativeWidgetExtension>("QtGui", 1, 0, "PushButton");
   qmlRegisterExtendedType<QRadioButton, DeclarativeWidgetExtension>("QtGui", 1, 0, "RadioButton");
   qmlRegisterExtendedType<DeclarativeTabWidget, DeclarativeTabWidgetExtension>("QtGui", 1, 0, "TabWidget");
index 5b7d733..1d59628 100644 (file)
@@ -34,7 +34,7 @@ HEADERS = \
   declarativelayoutproxy_p.h \
   declarativelcdnumber_p.h \
   declarativelistview_p.h \
-  declarativemainwindow_p.h \
+  declarativemainwindowextension_p.h \
   declarativemenubar_p.h \
   declarativemenu_p.h \
   declarativemessagebox_p.h \
@@ -95,7 +95,7 @@ SOURCES = \
   declarativelayoutextension.cpp \
   declarativelcdnumber.cpp \
   declarativelistview.cpp \
-  declarativemainwindow.cpp \
+  declarativemainwindowextension.cpp \
   declarativemenubar.cpp \
   declarativemenu.cpp \
   declarativemessagebox.cpp \