CUSTOM_METAOBJECT(DeclarativeCheckBox, QCheckBox)
// DeclarativeColorDialog
+DeclarativeColorDialogAttached::DeclarativeColorDialogAttached(QObject *parent) : QObject(parent)
+{
+}
+
+QColor DeclarativeColorDialogAttached::getColor(const QColor &initialColor, QObject *parent, const QString &title, int options)
+{
+ return QColorDialog::getColor(initialColor, bestParentWindow(parent), title, static_cast<QColorDialog::ColorDialogOptions>(options));
+}
+
+QColor DeclarativeColorDialogAttached::getColor(const QColor &initialColor, QObject *parent)
+{
+ return QColorDialog::getColor(initialColor, bestParentWindow(parent));
+}
+
+QWidget *DeclarativeColorDialogAttached::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;
+}
+
DeclarativeColorDialog::DeclarativeColorDialog(QObject *parent) : DeclarativeWidgetProxy<QColorDialog>(parent)
{
connectAllSignals(m_proxiedObject, this);
}
+DeclarativeColorDialogAttached *DeclarativeColorDialog::qmlAttachedProperties(QObject *parent)
+{
+ return new DeclarativeColorDialogAttached(parent);
+}
+
CUSTOM_METAOBJECT(DeclarativeColorDialog, QColorDialog)
// DeclarativeDialog
DeclarativeCheckBox(QObject *parent = 0);
};
+class DeclarativeColorDialogAttached : public QObject
+{
+ Q_OBJECT
+
+ public:
+ DeclarativeColorDialogAttached(QObject *parent = 0);
+
+ Q_INVOKABLE QColor getColor(const QColor &initialColor, QObject *parent, const QString &title, int options = 0);
+ Q_INVOKABLE QColor getColor(const QColor &initialColor, QObject *parent = 0);
+
+ private:
+ QWidget *bestParentWindow(QObject *parent) const;
+};
+
class DeclarativeColorDialog : public DeclarativeWidgetProxy<QColorDialog>
{
DECLARATIVE_OBJECT
public:
DeclarativeColorDialog(QObject *parent = 0);
+
+ static DeclarativeColorDialogAttached *qmlAttachedProperties(QObject *parent);
};
+QML_DECLARE_TYPEINFO(DeclarativeColorDialog, QML_HAS_ATTACHED_PROPERTIES)
+
class DeclarativeDialog : public DeclarativeWidgetProxy<QDialog>
{
DECLARATIVE_OBJECT
// widgets
qmlRegisterType<DeclarativeCalendarWidget>("QtGui", 1, 0, "CalendarWidget");
qmlRegisterType<DeclarativeCheckBox>("QtGui", 1, 0, "CheckBox");
+ qmlRegisterType<DeclarativeColorDialogAttached>();
qmlRegisterType<DeclarativeColorDialog>("QtGui", 1, 0, "ColorDialog");
qmlRegisterType<DeclarativeDialog>("QtGui", 1, 0, "Dialog");
qmlRegisterType<DeclarativeDialogButtonBox>("QtGui", 1, 0, "DialogButtonBox");
}
PushButton {
+ text: qsTr("Color Dialog::getColor")
+ onClicked: {
+ console.log("Selected color: " + ColorDialog.getColor("#ff0000"))
+ }
+ }
+
+ PushButton {
+ text: qsTr("Color Dialog::getColor with title")
+ onClicked: {
+ console.log("Selected color: " + ColorDialog.getColor("#ff0000", 0, "Pick a color"))
+ }
+ }
+
+ PushButton {
text: qsTr("File Dialog...")
onClicked: {
if (fileDialog.exec())