CUSTOM_METAOBJECT(DeclarativeFontDialog, QFontDialog)
// DeclarativeInputDialog
+DeclarativeInputDialogAttached::DeclarativeInputDialogAttached(QObject *parent) : QObject(parent)
+{
+}
+
+double DeclarativeInputDialogAttached::getDouble(QObject *parent, const QString &title, const QString &label,
+ double value, double min, double max, int decimals)
+{
+ return QInputDialog::getDouble(bestParentWindow(parent), title, label, value, min, max, decimals);
+}
+
+int DeclarativeInputDialogAttached::getInt(QObject *parent, const QString &title, const QString &label,
+ int value, int min, int max, int step)
+{
+ return QInputDialog::getInt(bestParentWindow(parent), title, label, value, min, max, step);
+}
+
+QString DeclarativeInputDialogAttached::getItem(QObject *parent, const QString &title, const QString &label,
+ const QStringList &items, int current, bool editable)
+{
+ return QInputDialog::getItem(bestParentWindow(parent), title, label, items, current, editable);
+}
+
+QString DeclarativeInputDialogAttached::getText(QObject *parent, const QString &title, const QString &label,
+ int echoMode, const QString &text)
+{
+ return QInputDialog::getText(bestParentWindow(parent), title, label, static_cast<QLineEdit::EchoMode>(echoMode), text);
+}
+
+QWidget *DeclarativeInputDialogAttached::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;
+}
+
DeclarativeInputDialog::DeclarativeInputDialog(QObject *parent) : DeclarativeWidgetProxy<InputDialog>(parent)
{
connectAllSignals(m_proxiedObject, this);
}
+DeclarativeInputDialogAttached *DeclarativeInputDialog::qmlAttachedProperties(QObject *parent)
+{
+ return new DeclarativeInputDialogAttached(parent);
+}
+
CUSTOM_METAOBJECT(DeclarativeInputDialog, InputDialog)
// DeclarativeLabel
DeclarativeFontDialog(QObject *parent = 0);
};
+class DeclarativeInputDialogAttached : public QObject
+{
+ Q_OBJECT
+
+ public:
+ DeclarativeInputDialogAttached(QObject *parent = 0);
+
+ Q_INVOKABLE double getDouble(QObject *parent, const QString &title, const QString &label,
+ double value = 0, double min = -2147483647, double max = 2147483647, int decimals = 1);
+
+ Q_INVOKABLE int getInt(QObject *parent, const QString &title, const QString &label,
+ int value = 0, int min = -2147483647, int max = 2147483647, int step = 1);
+
+ Q_INVOKABLE QString getItem(QObject *parent, const QString &title, const QString &label,
+ const QStringList &items, int current = 0, bool editable = true);
+
+ Q_INVOKABLE QString getText(QObject *parent, const QString &title, const QString &label,
+ int echoMode = QLineEdit::Normal, const QString &text = QString());
+
+ private:
+ QWidget *bestParentWindow(QObject *parent) const;
+};
+
class DeclarativeInputDialog : public DeclarativeWidgetProxy<InputDialog>
{
DECLARATIVE_OBJECT
public:
DeclarativeInputDialog(QObject *parent = 0);
+
+ static DeclarativeInputDialogAttached *qmlAttachedProperties(QObject *parent);
};
+QML_DECLARE_TYPEINFO(DeclarativeInputDialog, QML_HAS_ATTACHED_PROPERTIES)
+
class DeclarativeLabel : public DeclarativeWidgetProxy<QLabel>
{
DECLARATIVE_OBJECT
qmlRegisterType<DeclarativeFileDialogAttached>();
qmlRegisterType<DeclarativeFileDialog>("QtGui", 1, 0, "FileDialog");
qmlRegisterType<DeclarativeFontDialog>("QtGui", 1, 0, "FontDialog");
+ qmlRegisterType<DeclarativeInputDialogAttached>();
qmlRegisterType<DeclarativeInputDialog>("QtGui", 1, 0, "InputDialog");
qmlRegisterType<DeclarativeLabel>("QtGui", 1, 0, "Label");
qmlRegisterType<DeclarativeMainWindow>("QtGui", 1, 0, "MainWindow");
--- /dev/null
+import QtGui 1.0
+
+Widget {
+ VBoxLayout {
+ PushButton {
+ text: "InputDialog::getDouble"
+ onClicked: {
+ var value = InputDialog.getDouble(0, "Double Input", "A Double number")
+ console.log("InputDialog.getDouble returned " + value)
+ }
+ }
+
+ PushButton {
+ text: "InputDialog::getInt"
+ onClicked: {
+ var value = InputDialog.getInt(0, "Integer Input", "An Integer number")
+ console.log("InputDialog.getInt returned " + value)
+ }
+ }
+
+ PushButton {
+ text: "InputDialog::getItem"
+ onClicked: {
+ var items = [ "Item 1", "Item 2", "Item 3"]
+ var item = InputDialog.getItem(0, "Item Selection", "Select an item", items)
+ console.log("InputDialog.getItem returned " + item)
+ }
+ }
+
+ PushButton {
+ text: "InputDialog::getText"
+ onClicked: {
+ var text = InputDialog.getText(0, "Text Input", "Any text")
+ console.log("InputDialog.getText returned " + text)
+ }
+ }
+ }
+}