Add support for QDialog and QDialogButtonBox
authorTobias Koenig <tobias.koenig@kdab.com>
Fri, 19 Oct 2012 16:36:27 +0000 (18:36 +0200)
committerTobias Koenig <tobias.koenig@kdab.com>
Fri, 19 Oct 2012 16:36:27 +0000 (18:36 +0200)
declarativeobjects.cpp
declarativeobjects_p.h
declarativewidgetdocument.cpp
editor.qml

index d38dfa8..51e0256 100644 (file)
@@ -635,6 +635,22 @@ DeclarativeCheckBox::DeclarativeCheckBox(QObject *parent) : DeclarativeWidgetPro
 
 CUSTOM_METAOBJECT(DeclarativeCheckBox, QCheckBox)
 
+// DeclarativeDialog
+DeclarativeDialog::DeclarativeDialog(QObject *parent) : DeclarativeWidgetProxy<QDialog>(parent)
+{
+  connectAllSignals(m_proxiedObject, this);
+}
+
+CUSTOM_METAOBJECT(DeclarativeDialog, QDialog)
+
+// DeclarativeDialogButtonBox
+DeclarativeDialogButtonBox::DeclarativeDialogButtonBox(QObject *parent) : DeclarativeWidgetProxy<QDialogButtonBox>(parent)
+{
+  connectAllSignals(m_proxiedObject, this);
+}
+
+CUSTOM_METAOBJECT(DeclarativeDialogButtonBox, QDialogButtonBox)
+
 // DeclarativeLabel
 DeclarativeLabel::DeclarativeLabel(QObject *parent) : DeclarativeWidgetProxy<QLabel>(parent)
 {
@@ -654,6 +670,7 @@ void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject
   QMenuBar *menuBar = qobject_cast<QMenuBar*>(widget);
   QToolBar *toolBar = qobject_cast<QToolBar*>(widget);
   QStatusBar *statusBar = qobject_cast<QStatusBar*>(widget);
+  QDialog *dialog = qobject_cast<QDialog*>(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";
index f4de211..8d0b86e 100644 (file)
@@ -8,6 +8,8 @@
 #include <QtGui/QAction>
 #include <QtGui/QCalendarWidget>
 #include <QtGui/QCheckBox>
+#include <QtGui/QDialog>
+#include <QtGui/QDialogButtonBox>
 #include <QtGui/QFormLayout>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QLabel>
@@ -141,7 +143,7 @@ class DeclarativeWidgetProxy : public DeclarativeObjectProxy<T>
     {
       Q_UNUSED(declarativeObject);
       DeclarativeObjectProxy<T>::m_children.append(declarativeObject);
-      widget->setParent(DeclarativeObjectProxy<T>::m_proxiedObject);
+      widget->setParent(DeclarativeObjectProxy<T>::m_proxiedObject, widget->windowFlags());
     }
 
     virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject)
@@ -393,6 +395,22 @@ class DeclarativeCheckBox : public DeclarativeWidgetProxy<QCheckBox>
     DeclarativeCheckBox(QObject *parent = 0);
 };
 
+class DeclarativeDialog : public DeclarativeWidgetProxy<QDialog>
+{
+  DECLARATIVE_OBJECT
+
+  public:
+    DeclarativeDialog(QObject *parent = 0);
+};
+
+class DeclarativeDialogButtonBox : public DeclarativeWidgetProxy<QDialogButtonBox>
+{
+  DECLARATIVE_OBJECT
+
+  public:
+    DeclarativeDialogButtonBox(QObject *parent = 0);
+};
+
 class DeclarativeLabel : public DeclarativeWidgetProxy<QLabel>
 {
   DECLARATIVE_OBJECT
index b2f3e94..6607a4a 100644 (file)
@@ -46,6 +46,8 @@ DeclarativeWidgetDocument::DeclarativeWidgetDocument(const QUrl &url, QObject *p
   // widgets
   qmlRegisterType<DeclarativeCalendarWidget>("QtGui", 1, 0, "CalendarWidget");
   qmlRegisterType<DeclarativeCheckBox>("QtGui", 1, 0, "CheckBox");
+  qmlRegisterType<DeclarativeDialog>("QtGui", 1, 0, "Dialog");
+  qmlRegisterType<DeclarativeDialogButtonBox>("QtGui", 1, 0, "DialogButtonBox");
   qmlRegisterType<DeclarativeLabel>("QtGui", 1, 0, "Label");
   qmlRegisterType<DeclarativeMainWindow>("QtGui", 1, 0, "MainWindow");
   qmlRegisterType<DeclarativeMenu>("QtGui", 1, 0, "Menu");
index efd35e0..1ad187a 100644 (file)
@@ -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 {