From: Kevin Krammer Date: Mon, 14 Jan 2013 17:04:54 +0000 (+0100) Subject: Port main window X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=50526a46c41a760bddc83da3369236f80647aad4;p=web%2Fkonrad%2FDeclarativeWidgets.git Port main window --- diff --git a/lib/declarativemainwindow.cpp b/lib/declarativemainwindowextension.cpp similarity index 58% rename from lib/declarativemainwindow.cpp rename to lib/declarativemainwindowextension.cpp index 87da5c7..fdaa7ab 100644 --- a/lib/declarativemainwindow.cpp +++ b/lib/declarativemainwindowextension.cpp @@ -18,20 +18,29 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "declarativemainwindow_p.h" +#include "declarativemainwindowextension_p.h" +#include #include +#include #include #include #include -DeclarativeMainWindow::DeclarativeMainWindow(QObject *parent) - : DeclarativeWidgetProxy(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(extendedWidget()); + Q_ASSERT(mainWindow); + + return mainWindow; +} + +void DeclarativeMainWindowExtension::addWidget(QWidget *widget) { QMenuBar *menuBar = qobject_cast(widget); QToolBar *toolBar = qobject_cast(widget); @@ -39,31 +48,26 @@ void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject QDialog *dialog = qobject_cast(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) diff --git a/lib/declarativemainwindow_p.h b/lib/declarativemainwindowextension_p.h similarity index 64% rename from lib/declarativemainwindow_p.h rename to lib/declarativemainwindowextension_p.h index 4778ad7..0fcd4e2 100644 --- a/lib/declarativemainwindow_p.h +++ b/lib/declarativemainwindowextension_p.h @@ -21,20 +21,27 @@ #ifndef DECLARATIVEMAINWINDOW_P_H #define DECLARATIVEMAINWINDOW_P_H -#include "declarativewidgetproxy_p.h" +#include "declarativewidgetextension.h" -#include +class QMainWindow; -class DeclarativeMainWindow : public DeclarativeWidgetProxy +class DeclarativeMainWindowExtension : public DeclarativeWidgetExtension { - DECLARATIVE_OBJECT + Q_OBJECT + + // repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class + Q_PROPERTY(QDeclarativeListProperty 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 diff --git a/lib/declarativewidgetsdocument.cpp b/lib/declarativewidgetsdocument.cpp index ce02609..64c6b11 100644 --- a/lib/declarativewidgetsdocument.cpp +++ b/lib/declarativewidgetsdocument.cpp @@ -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 #include #include +#include +#include +#include #include #include @@ -131,7 +134,6 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject qmlRegisterType("QtGui", 1, 0, "Label"); qmlRegisterType("QtGui", 1, 0, "LCDNumber"); qmlRegisterType("QtGui", 1, 0, "ListView"); - qmlRegisterType("QtGui", 1, 0, "MainWindow"); qmlRegisterType("QtGui", 1, 0, "Menu"); qmlRegisterType("QtGui", 1, 0, "MenuBar"); qmlRegisterType(); @@ -176,6 +178,7 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject qmlRegisterExtendedType("QtGui", 1, 0, "CheckBox"); qmlRegisterExtendedType("QtGui", 1, 0, "Label"); qmlRegisterExtendedType("QtGui", 1, 0, "LineEdit"); + qmlRegisterExtendedType("QtGui", 1, 0, "MainWindow"); qmlRegisterExtendedType("QtGui", 1, 0, "PushButton"); qmlRegisterExtendedType("QtGui", 1, 0, "RadioButton"); qmlRegisterExtendedType("QtGui", 1, 0, "TabWidget"); diff --git a/lib/lib.pro b/lib/lib.pro index 5b7d733..1d59628 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -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 \