From: Kevin Krammer Date: Fri, 2 Nov 2012 14:29:44 +0000 (+0100) Subject: Refactor color dialog attached to common base class X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=2b2b2c009e7c26631ad52632b037ac6d0af8dacc;p=konrad%2FDeclarativeWidgets.git Refactor color dialog attached to common base class --- diff --git a/lib/declarativecolordialog.cpp b/lib/declarativecolordialog.cpp index 84a3bd4..8f5e46a 100644 --- a/lib/declarativecolordialog.cpp +++ b/lib/declarativecolordialog.cpp @@ -26,13 +26,12 @@ class DeclarativeColorDialogAttached::Private Private() : options(0) {} public: - QPointer dialogParent; QString title; QColorDialog::ColorDialogOptions options; }; DeclarativeColorDialogAttached::DeclarativeColorDialogAttached(QObject *parent) - : QObject(parent), d(new Private) + : StaticDialogMethodAttached(parent), d(new Private) { } @@ -41,20 +40,6 @@ DeclarativeColorDialogAttached::~DeclarativeColorDialogAttached() delete d; } -void DeclarativeColorDialogAttached::setDialogParent(QObject *parent) -{ - if (parent == d->dialogParent) - return; - - d->dialogParent = parent; - emit dialogParentChanged(parent); -} - -QObject *DeclarativeColorDialogAttached::dialogParent() const -{ - return d->dialogParent; -} - void DeclarativeColorDialogAttached::setTitle(const QString &title) { if (title == d->title) @@ -71,34 +56,13 @@ QString DeclarativeColorDialogAttached::title() const QColor DeclarativeColorDialogAttached::getColor(const QColor &initialColor) { - QWidget *parent = bestParentWindow(d->dialogParent); + QWidget *parent = bestParentWindow(); if (!d->title.isEmpty() || d->options != 0) return QColorDialog::getColor(initialColor, parent, d->title, d->options); else return QColorDialog::getColor(initialColor, 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(parent); - if (declarativeObject) - parent = declarativeObject->object(); - - while (parent) { - QWidget *widget = qobject_cast(parent); - if (widget) - return widget->topLevelWidget(); - - parent = parent->parent(); - } - - return 0; -} - DeclarativeColorDialog::DeclarativeColorDialog(QObject *parent) : DeclarativeWidgetProxy(parent) { connectAllSignals(m_proxiedObject, this); diff --git a/lib/declarativecolordialog_p.h b/lib/declarativecolordialog_p.h index abdd429..2986a15 100644 --- a/lib/declarativecolordialog_p.h +++ b/lib/declarativecolordialog_p.h @@ -23,12 +23,13 @@ #include "declarativewidgetproxy_p.h" +#include "staticdialogmethodattached_p.h" + #include -class DeclarativeColorDialogAttached : public QObject +class DeclarativeColorDialogAttached : public StaticDialogMethodAttached { Q_OBJECT - Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) // TODO option @@ -36,21 +37,15 @@ class DeclarativeColorDialogAttached : public QObject DeclarativeColorDialogAttached(QObject *parent = 0); ~DeclarativeColorDialogAttached(); - void setDialogParent(QObject *parent); - QObject *dialogParent() const; - void setTitle(const QString &title); QString title() const; Q_INVOKABLE QColor getColor(const QColor &initialColor); Q_SIGNALS: - void dialogParentChanged(QObject *parent); void titleChanged(const QString &title); private: - QWidget *bestParentWindow(QObject *parent) const; - class Private; Private *const d; };