From 50526a46c41a760bddc83da3369236f80647aad4 Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Mon, 14 Jan 2013 18:04:54 +0100 Subject: [PATCH] Port main window --- lib/declarativemainwindow.cpp | 69 ------------------------------ lib/declarativemainwindow_p.h | 40 ----------------- lib/declarativemainwindowextension.cpp | 73 ++++++++++++++++++++++++++++++++ lib/declarativemainwindowextension_p.h | 47 ++++++++++++++++++++ lib/declarativewidgetsdocument.cpp | 7 ++- lib/lib.pro | 4 +- 6 files changed, 127 insertions(+), 113 deletions(-) delete mode 100644 lib/declarativemainwindow.cpp delete mode 100644 lib/declarativemainwindow_p.h create mode 100644 lib/declarativemainwindowextension.cpp create mode 100644 lib/declarativemainwindowextension_p.h diff --git a/lib/declarativemainwindow.cpp b/lib/declarativemainwindow.cpp deleted file mode 100644 index 87da5c7..0000000 --- a/lib/declarativemainwindow.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Krammer, krake@kdab.com - Author: Tobias Koenig, tokoe@kdab.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "declarativemainwindow_p.h" - -#include -#include -#include -#include - -DeclarativeMainWindow::DeclarativeMainWindow(QObject *parent) - : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - QMenuBar *menuBar = qobject_cast(widget); - QToolBar *toolBar = qobject_cast(widget); - QStatusBar *statusBar = qobject_cast(widget); - QDialog *dialog = qobject_cast(widget); - - if (menuBar) { - m_proxiedObject->setMenuBar(menuBar); - } else if (toolBar) { - m_proxiedObject->addToolBar(toolBar); - } else if (statusBar) { - m_proxiedObject->setStatusBar(statusBar); - } else if (dialog) { - // We allow to place dialogs on the mainwindow - dialog->setParent(m_proxiedObject, dialog->windowFlags()); - } else if (widget) { - if (m_proxiedObject->centralWidget()) { - qmlInfo(declarativeObject) << "The QMainWindow contains a central widget already"; - return; - } - - m_proxiedObject->setCentralWidget(widget); - } - - m_children.append(declarativeObject); -} - -void DeclarativeMainWindow::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not set a QLayout to a QMainWindow"; -} - -CUSTOM_METAOBJECT(DeclarativeMainWindow, QMainWindow) diff --git a/lib/declarativemainwindow_p.h b/lib/declarativemainwindow_p.h deleted file mode 100644 index 4778ad7..0000000 --- a/lib/declarativemainwindow_p.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Krammer, krake@kdab.com - Author: Tobias Koenig, tokoe@kdab.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef DECLARATIVEMAINWINDOW_P_H -#define DECLARATIVEMAINWINDOW_P_H - -#include "declarativewidgetproxy_p.h" - -#include - -class DeclarativeMainWindow : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - explicit DeclarativeMainWindow(QObject *parent = 0); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -#endif diff --git a/lib/declarativemainwindowextension.cpp b/lib/declarativemainwindowextension.cpp new file mode 100644 index 0000000..fdaa7ab --- /dev/null +++ b/lib/declarativemainwindowextension.cpp @@ -0,0 +1,73 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativemainwindowextension_p.h" + +#include +#include +#include +#include +#include +#include + +DeclarativeMainWindowExtension::DeclarativeMainWindowExtension(QObject *parent) + : DeclarativeWidgetExtension(parent) +{ +} + +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); + QStatusBar *statusBar = qobject_cast(widget); + QDialog *dialog = qobject_cast(widget); + + if (menuBar) { + extendedMainWindow()->setMenuBar(menuBar); + } else if (toolBar) { + extendedMainWindow()->addToolBar(toolBar); + } else if (statusBar) { + extendedMainWindow()->setStatusBar(statusBar); + } else if (dialog) { + // We allow to place dialogs on the mainwindow + dialog->setParent(extendedMainWindow(), dialog->windowFlags()); + } else if (widget) { + if (extendedMainWindow()->centralWidget()) { + qmlInfo(extendedMainWindow()) << "The MainWindow already contains a central widget"; + return; + } + + extendedMainWindow()->setCentralWidget(widget); + } +} + +void DeclarativeMainWindowExtension::setLayout(QLayout *layout) +{ + Q_UNUSED(layout); + qmlInfo(this) << "Can not set a Layout to a MainWindow"; +} diff --git a/lib/declarativemainwindowextension_p.h b/lib/declarativemainwindowextension_p.h new file mode 100644 index 0000000..0fcd4e2 --- /dev/null +++ b/lib/declarativemainwindowextension_p.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEMAINWINDOW_P_H +#define DECLARATIVEMAINWINDOW_P_H + +#include "declarativewidgetextension.h" + +class QMainWindow; + +class DeclarativeMainWindowExtension : public DeclarativeWidgetExtension +{ + 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 DeclarativeMainWindowExtension(QObject *parent = 0); + + QMainWindow *extendedMainWindow() const; + + protected: + 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 \ -- 1.7.2.5