CUSTOM_METAOBJECT(DeclarativeMenuBar, QMenuBar)
+// DeclarativeMessageBox
+DeclarativeMessageBoxAttached::DeclarativeMessageBoxAttached(QObject *parent) : QObject(parent)
+{
+}
+
+void DeclarativeMessageBoxAttached::about(QObject *parent, const QString &title, const QString &text)
+{
+ QMessageBox::about(bestParentWindow(parent), title, text);
+}
+
+void DeclarativeMessageBoxAttached::aboutQt(QObject *parent, const QString &title)
+{
+ QMessageBox::aboutQt(bestParentWindow(parent), title);
+}
+
+int DeclarativeMessageBoxAttached::critical(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton)
+{
+ return QMessageBox::critical(bestParentWindow(parent), title, text, static_cast<QMessageBox::StandardButtons>(buttons), static_cast<QMessageBox::StandardButton>(defaultButton));
+}
+
+int DeclarativeMessageBoxAttached::information(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton)
+{
+ return QMessageBox::information(bestParentWindow(parent), title, text, static_cast<QMessageBox::StandardButtons>(buttons), static_cast<QMessageBox::StandardButton>(defaultButton));
+}
+
+int DeclarativeMessageBoxAttached::question(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton)
+{
+ return QMessageBox::question(bestParentWindow(parent), title, text, static_cast<QMessageBox::StandardButtons>(buttons), static_cast<QMessageBox::StandardButton>(defaultButton));
+}
+
+int DeclarativeMessageBoxAttached::warning(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton)
+{
+ return QMessageBox::warning(bestParentWindow(parent), title, text, static_cast<QMessageBox::StandardButtons>(buttons), static_cast<QMessageBox::StandardButton>(defaultButton));
+}
+
+QWidget *DeclarativeMessageBoxAttached::bestParentWindow(QObject *parent) const
+{
+ if (!parent)
+ parent = this->parent();
+
+ // if parent is a Declarative Object, search the proxied hierarchy
+ AbstractDeclarativeObject *declarativeObject = dynamic_cast<AbstractDeclarativeObject*>(parent);
+ if (declarativeObject)
+ parent = declarativeObject->object();
+
+ while (parent) {
+ QWidget *widget = qobject_cast<QWidget*>(parent);
+ if (widget)
+ return widget->topLevelWidget();
+
+ parent = parent->parent();
+ }
+
+ return 0;
+}
+
+DeclarativeMessageBox::DeclarativeMessageBox(QObject *parent) : DeclarativeObjectProxy<QMessageBox>(parent)
+{
+ connectAllSignals(m_proxiedObject, this);
+}
+
+DeclarativeMessageBoxAttached *DeclarativeMessageBox::qmlAttachedProperties(QObject *parent)
+{
+ return new DeclarativeMessageBoxAttached(parent);
+}
+
+CUSTOM_METAOBJECT(DeclarativeMessageBox, QMessageBox)
+
// DeclarativePushButton
DeclarativePushButton::DeclarativePushButton(QObject *parent) : DeclarativeWidgetProxy<QPushButton>(parent)
{
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
+#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <QtGui/QSlider>
#include <QtGui/QStatusBar>
void setAlignment(Qt::Alignment alignment);
Qt::Alignment alignment() const;
+ Q_INVOKABLE QString foo() const { qDebug() << Q_FUNC_INFO; return "foo"; }
+
Q_SIGNALS:
void stretchChanged(int stretch);
void alignmentChanged(Qt::Alignment alignment);
virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject);
};
+class DeclarativeMessageBoxAttached : public QObject
+{
+ Q_OBJECT
+ Q_FLAGS(StandardButtons)
+
+ public:
+ typedef QMessageBox::StandardButton StandardButton;
+ Q_DECLARE_FLAGS(StandardButtons, StandardButton);
+
+ DeclarativeMessageBoxAttached(QObject *parent = 0);
+
+ Q_INVOKABLE void about(QObject *parent, const QString &title, const QString &text);
+ Q_INVOKABLE void aboutQt(QObject *parent, const QString &title);
+ Q_INVOKABLE int critical(QObject *parent, const QString &title, const QString &text,
+ int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton);
+ Q_INVOKABLE int information(QObject *parent, const QString &title, const QString &text,
+ int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton);
+ Q_INVOKABLE int question(QObject *parent, const QString &title, const QString &text,
+ int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton);
+ Q_INVOKABLE int warning(QObject *parent, const QString &title, const QString &text,
+ int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton);
+
+ private:
+ QWidget *bestParentWindow(QObject *parent) const;
+};
+
+class DeclarativeMessageBox : public DeclarativeObjectProxy<QMessageBox>
+{
+ DECLARATIVE_OBJECT
+
+ public:
+ DeclarativeMessageBox(QObject *parent = 0);
+
+ static DeclarativeMessageBoxAttached *qmlAttachedProperties(QObject *parent);
+};
+
+QML_DECLARE_TYPEINFO(DeclarativeMessageBox, QML_HAS_ATTACHED_PROPERTIES)
+
class DeclarativePushButton : public DeclarativeWidgetProxy<QPushButton>
{
DECLARATIVE_OBJECT
qmlRegisterType<DeclarativeMainWindow>("QtGui", 1, 0, "MainWindow");
qmlRegisterType<DeclarativeMenu>("QtGui", 1, 0, "Menu");
qmlRegisterType<DeclarativeMenuBar>("QtGui", 1, 0, "MenuBar");
+ qmlRegisterType<DeclarativeMessageBoxAttached>();
+ qmlRegisterType<DeclarativeMessageBox>("QtGui", 1, 0, "MessageBox");
qmlRegisterType<DeclarativePushButton>("QtGui", 1, 0, "PushButton");
qmlRegisterType<DeclarativeSlider>("QtGui", 1, 0, "Slider");
qmlRegisterType<DeclarativeStatusBarAttached>();
editor.qml \
gallery.qml \
layouts.qml \
- test.qml
+ test.qml \
+ messagebox.qml
--- /dev/null
+import QtGui 1.0
+
+Widget {
+ VBoxLayout {
+ PushButton {
+ text: "MessageBox instance"
+
+ onClicked: messageBox.show()
+ }
+
+ PushButton {
+ id: aboutButton
+ text: "MessageBox::about"
+ onClicked: MessageBox.about(aboutButton, "title", "text")
+ }
+ PushButton {
+ text: "MessageBox::aboutQt"
+ onClicked: MessageBox.aboutQt(0, "text")
+ }
+ PushButton {
+ text: "MessageBox::critical"
+ onClicked: {
+ var button = MessageBox.critical(0, "title", "text")
+ console.log("MessageBox.critical returned " + button)
+ }
+ }
+ PushButton {
+ text: "MessageBox::information"
+ onClicked: {
+ var button = MessageBox.information(0, "title", "text")
+ console.log("MessageBox.information returned " + button)
+ }
+ }
+ PushButton {
+ text: "MessageBox::question"
+ onClicked: {
+ var button = MessageBox.question(0, "title", "text", MessageBox.Retry | MessageBox.Abort | MessageBox.Ignore, MessageBox.Abort)
+ console.log("MessageBox.question returned " + button)
+ }
+ }
+ PushButton {
+ text: "MessageBox::warning"
+ onClicked: {
+ var button = MessageBox.warning(0, "title", "text", MessageBox.Ok | MessageBox.Cancel)
+ console.log("MessageBox.warning returned " + button)
+ }
+ }
+ }
+
+ MessageBox {
+ id: messageBox
+
+ windowTitle: "MessageBox instance"
+ text: "text"
+ detailedText: "detailedText"
+ }
+}