From: Tobias Koenig Date: Fri, 19 Oct 2012 16:36:27 +0000 (+0200) Subject: Add support for QDialog and QDialogButtonBox X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f5bd67f799bef042bc43694d45c3d416c9849a5f;p=konrad%2FDeclarativeWidgets.git Add support for QDialog and QDialogButtonBox --- diff --git a/declarativeobjects.cpp b/declarativeobjects.cpp index d38dfa8..51e0256 100644 --- a/declarativeobjects.cpp +++ b/declarativeobjects.cpp @@ -635,6 +635,22 @@ DeclarativeCheckBox::DeclarativeCheckBox(QObject *parent) : DeclarativeWidgetPro CUSTOM_METAOBJECT(DeclarativeCheckBox, QCheckBox) +// DeclarativeDialog +DeclarativeDialog::DeclarativeDialog(QObject *parent) : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDialog, QDialog) + +// DeclarativeDialogButtonBox +DeclarativeDialogButtonBox::DeclarativeDialogButtonBox(QObject *parent) : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDialogButtonBox, QDialogButtonBox) + // DeclarativeLabel DeclarativeLabel::DeclarativeLabel(QObject *parent) : DeclarativeWidgetProxy(parent) { @@ -654,6 +670,7 @@ void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject 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); @@ -661,6 +678,9 @@ void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject 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"; diff --git a/declarativeobjects_p.h b/declarativeobjects_p.h index f4de211..8d0b86e 100644 --- a/declarativeobjects_p.h +++ b/declarativeobjects_p.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -141,7 +143,7 @@ class DeclarativeWidgetProxy : public DeclarativeObjectProxy { Q_UNUSED(declarativeObject); DeclarativeObjectProxy::m_children.append(declarativeObject); - widget->setParent(DeclarativeObjectProxy::m_proxiedObject); + widget->setParent(DeclarativeObjectProxy::m_proxiedObject, widget->windowFlags()); } virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) @@ -393,6 +395,22 @@ class DeclarativeCheckBox : public DeclarativeWidgetProxy DeclarativeCheckBox(QObject *parent = 0); }; +class DeclarativeDialog : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDialog(QObject *parent = 0); +}; + +class DeclarativeDialogButtonBox : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDialogButtonBox(QObject *parent = 0); +}; + class DeclarativeLabel : public DeclarativeWidgetProxy { DECLARATIVE_OBJECT diff --git a/declarativewidgetdocument.cpp b/declarativewidgetdocument.cpp index b2f3e94..6607a4a 100644 --- a/declarativewidgetdocument.cpp +++ b/declarativewidgetdocument.cpp @@ -46,6 +46,8 @@ DeclarativeWidgetDocument::DeclarativeWidgetDocument(const QUrl &url, QObject *p // widgets qmlRegisterType("QtGui", 1, 0, "CalendarWidget"); qmlRegisterType("QtGui", 1, 0, "CheckBox"); + qmlRegisterType("QtGui", 1, 0, "Dialog"); + qmlRegisterType("QtGui", 1, 0, "DialogButtonBox"); qmlRegisterType("QtGui", 1, 0, "Label"); qmlRegisterType("QtGui", 1, 0, "MainWindow"); qmlRegisterType("QtGui", 1, 0, "Menu"); diff --git a/editor.qml b/editor.qml index efd35e0..1ad187a 100644 --- a/editor.qml +++ b/editor.qml @@ -5,12 +5,35 @@ MainWindow { size: Qt.size(500, 300) + Dialog { + id: myDialog + + size: Qt.size(300, 200) + visible: false + + VBoxLayout { + Label { + text: "Hello World" + } + DialogButtonBox { + standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel + + onAccepted: myDialog.accept() + onRejected: myDialog.reject() + } + } + } + MenuBar { Menu { title: qsTr("File") Action { text: qsTr("New") + onTriggered: { + var result = myDialog.exec() + console.log("result="+result) + } } Action {