From 41015a670a54464e73e0d35602f90e557e7d3fdf Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Mon, 24 Mar 2014 23:11:54 +0000 Subject: [PATCH] libhawaiishell: Move configuring property from QuickView to Containment The configuration logic does really belong here. Issue: #151 --- src/libhawaiishell/containment.cpp | 18 ++++++++ src/libhawaiishell/containment.h | 18 ++++++++ src/libhawaiishell/containmentitem.cpp | 14 ++++++ src/libhawaiishell/containmentitem.h | 18 ++++++++ src/libhawaiishell/quickview.cpp | 61 ++++++++++++++------------ src/libhawaiishell/quickview.h | 36 ++++++++------- 6 files changed, 121 insertions(+), 44 deletions(-) diff --git a/src/libhawaiishell/containment.cpp b/src/libhawaiishell/containment.cpp index cbd03705..37fc3d2e 100644 --- a/src/libhawaiishell/containment.cpp +++ b/src/libhawaiishell/containment.cpp @@ -54,6 +54,7 @@ class ContainmentPrivate Types::FormFactor formFactor; Types::Location location; bool immutable; + bool configuring; Package package; }; @@ -63,6 +64,7 @@ ContainmentPrivate::ContainmentPrivate() , formFactor(Types::Plane) , location(Types::Desktop) , immutable(false) + , configuring(false) { } @@ -168,6 +170,22 @@ void Containment::setImmutable(bool value) } } +bool Containment::isConfiguring() const +{ + Q_D(const Containment); + return d->configuring; +} + +void Containment::setConfiguring(bool value) +{ + Q_D(Containment); + + if (d->configuring != value) { + d->configuring = value; + Q_EMIT configuringChanged(value); + } +} + Package Containment::package() const { Q_D(const Containment); diff --git a/src/libhawaiishell/containment.h b/src/libhawaiishell/containment.h index 84f4f5d1..3ef0b6e0 100644 --- a/src/libhawaiishell/containment.h +++ b/src/libhawaiishell/containment.h @@ -45,6 +45,7 @@ class HAWAIISHELL_EXPORT Containment : public QObject Q_PROPERTY(Hawaii::Shell::Types::FormFactor formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged) Q_PROPERTY(Hawaii::Shell::Types::Location location READ location WRITE setLocation NOTIFY locationChanged) Q_PROPERTY(bool immutable READ isImmutable WRITE setImmutable NOTIFY immutableChanged) + Q_PROPERTY(bool configuring READ isConfiguring WRITE setConfiguring NOTIFY configuringChanged) public: explicit Containment(Mantle *mantle, QObject *parent = 0); ~Containment(); @@ -93,6 +94,17 @@ class HAWAIISHELL_EXPORT Containment : public QObject */ void setImmutable(bool value); + /*! + * \return whether this containment is in configuration mode. + */ + bool isConfiguring() const; + + /*! + * Enable or disable the configuration mode. + * \param value whether configuration mode is enabled or not. + */ + void setConfiguring(bool value); + /*! * \return the package loaded for this containment. */ @@ -134,6 +146,12 @@ class HAWAIISHELL_EXPORT Containment : public QObject */ void immutableChanged(bool newValue); + /*! + * Emitted when the configuration mode is enabled or disabled. + * \param newValue whether the containment is now in configuration mode or not. + */ + void configuringChanged(bool newValue); + /*! * Emitted when the package for this containment is changed. * \param package the new package. diff --git a/src/libhawaiishell/containmentitem.cpp b/src/libhawaiishell/containmentitem.cpp index df23cdd8..cbf1234f 100644 --- a/src/libhawaiishell/containmentitem.cpp +++ b/src/libhawaiishell/containmentitem.cpp @@ -110,6 +110,8 @@ ContainmentItem::ContainmentItem(Containment *containment, QQuickItem *parent) this, &ContainmentItem::locationChanged); connect(containment, &Containment::immutableChanged, this, &ContainmentItem::immutableChanged); + connect(containment, &Containment::configuringChanged, + this, &ContainmentItem::configuringChanged); // Reinizialize this item when the package is changed connect(containment, SIGNAL(packageChanged(Package)), @@ -170,6 +172,18 @@ void ContainmentItem::setImmutable(bool value) d->containment->setImmutable(value); } +bool ContainmentItem::isConfiguring() const +{ + Q_D(const ContainmentItem); + return d->containment->isConfiguring(); +} + +void ContainmentItem::setConfiguring(bool value) +{ + Q_D(ContainmentItem); + d->containment->setConfiguring(value); +} + void ContainmentItem::initialize() { Q_D(ContainmentItem); diff --git a/src/libhawaiishell/containmentitem.h b/src/libhawaiishell/containmentitem.h index 440141bd..f4b45349 100644 --- a/src/libhawaiishell/containmentitem.h +++ b/src/libhawaiishell/containmentitem.h @@ -45,6 +45,7 @@ class HAWAIISHELL_EXPORT ContainmentItem : public QQuickItem Q_PROPERTY(Hawaii::Shell::Types::FormFactor formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged) Q_PROPERTY(Hawaii::Shell::Types::Location location READ location WRITE setLocation NOTIFY locationChanged) Q_PROPERTY(bool immutable READ isImmutable WRITE setImmutable NOTIFY immutableChanged) + Q_PROPERTY(bool configuring READ isConfiguring WRITE setConfiguring NOTIFY configuringChanged) public: /*! * \brief Constructor. @@ -104,6 +105,17 @@ class HAWAIISHELL_EXPORT ContainmentItem : public QQuickItem */ void setImmutable(bool value); + /*! + * \return whether this containment is in configuration mode. + */ + bool isConfiguring() const; + + /*! + * Enable or disable the configuration mode. + * \param value whether configuration mode is enabled or not. + */ + void setConfiguring(bool value); + /*! * Initializes the containment item. */ @@ -131,6 +143,12 @@ class HAWAIISHELL_EXPORT ContainmentItem : public QQuickItem */ void immutableChanged(bool newValue); + /*! + * Emitted when the configuration mode is enabled or disabled. + * \param newValue whether the containment is now in configuration mode or not. + */ + void configuringChanged(bool newValue); + private: Q_DECLARE_PRIVATE(ContainmentItem) ContainmentItemPrivate *const d_ptr; diff --git a/src/libhawaiishell/quickview.cpp b/src/libhawaiishell/quickview.cpp index ea3fbfdf..4d42f61f 100644 --- a/src/libhawaiishell/quickview.cpp +++ b/src/libhawaiishell/quickview.cpp @@ -49,17 +49,17 @@ class QuickViewPrivate Mantle *mantle; QPointer containment; - bool configuring; void initialize(); + void _q_configuringChanged(bool value); + protected: QuickView *const q_ptr; }; QuickViewPrivate::QuickViewPrivate(QuickView *view) - : configuring(false) - , q_ptr(view) + : q_ptr(view) { } @@ -84,6 +84,18 @@ void QuickViewPrivate::initialize() q->setResizeMode(QQuickView::SizeViewToRootObject); } +void QuickViewPrivate::_q_configuringChanged(bool value) +{ + Q_Q(QuickView); + + // Views inheriting QuickView will have to override these methods + // implementing their window setup code + if (value) + q->showConfigurationWindow(); + else + q->hideConfigurationWindow(); +} + /* * QuickView */ @@ -148,6 +160,8 @@ void QuickView::setContainment(Containment *containment) this, &QuickView::formFactorChanged); connect(containment, &Containment::immutableChanged, this, &QuickView::immutableChanged); + connect(containment, SIGNAL(configuringChanged(bool)), + this, SLOT(_q_configuringChanged(bool))); QQuickItem *item = qobject_cast(d->containment.data()->property("_graphicObject").value()); if (item) { @@ -161,30 +175,6 @@ void QuickView::setContainment(Containment *containment) } } -bool QuickView::isConfiguring() const -{ - Q_D(const QuickView); - return d->configuring; -} - -void QuickView::setConfiguring(bool value) -{ - Q_D(QuickView); - - if (d->configuring != value) { - // Views inheriting QuickView will have to override these methods - // implementing their window setup code - if (value) - showConfigurationWindow(); - else - hideConfigurationWindow(); - - // Now we can actually change the property - d->configuring = value; - Q_EMIT configuringChanged(value); - } -} - Hawaii::Shell::Types::FormFactor QuickView::formFactor() const { Q_D(const QuickView); @@ -236,6 +226,23 @@ void QuickView::setImmutable(bool value) d->containment.data()->setImmutable(value); } +bool QuickView::isConfiguring() const +{ + Q_D(const QuickView); + + if (!d->containment) + return false; + return d->containment.data()->isConfiguring(); +} + +void QuickView::setConfiguring(bool value) +{ + Q_D(QuickView); + + if (isConfiguring() != value) + d->containment.data()->setConfiguring(value); +} + QRectF QuickView::screenGeometry() const { return screen()->geometry(); diff --git a/src/libhawaiishell/quickview.h b/src/libhawaiishell/quickview.h index 1bde5f3d..664495ad 100644 --- a/src/libhawaiishell/quickview.h +++ b/src/libhawaiishell/quickview.h @@ -82,17 +82,6 @@ class HAWAIISHELL_EXPORT QuickView : public QQuickView */ void setContainment(Containment *containment); - /*! - * \return whether this view is in configuration mode. - */ - bool isConfiguring() const; - - /*! - * Enable or disable the configuration mode. - * \param value whether configuration mode is enabled or not. - */ - void setConfiguring(bool value); - /*! * \return the form factor of this view. */ @@ -127,6 +116,17 @@ class HAWAIISHELL_EXPORT QuickView : public QQuickView */ void setImmutable(bool value); + /*! + * \return whether this view is in configuration mode. + */ + bool isConfiguring() const; + + /*! + * Enable or disable the configuration mode. + * \param value whether configuration mode is enabled or not. + */ + void setConfiguring(bool value); + /*! * \return the geometry of the screen where this view is located. */ @@ -153,12 +153,6 @@ class HAWAIISHELL_EXPORT QuickView : public QQuickView */ void containmentChanged(); - /*! - * Emitted when the configuration mode is enabled or disabled. - * \param newValue whether the view is now in configuration mode or not. - */ - void configuringChanged(bool newValue); - /*! * Emitted when the form factor is changed. * \param formFactor the new form factorof the view @@ -178,6 +172,12 @@ class HAWAIISHELL_EXPORT QuickView : public QQuickView */ void immutableChanged(bool newValue); + /*! + * Emitted when the configuration mode is enabled or disabled. + * \param newValue whether the view is now in configuration mode or not. + */ + void configuringChanged(bool newValue); + /*! * Emitted when the screen geometry is changed. * \param geometry the new screen geometry @@ -187,6 +187,8 @@ class HAWAIISHELL_EXPORT QuickView : public QQuickView private: Q_DECLARE_PRIVATE(QuickView) QuickViewPrivate *const d_ptr; + + Q_PRIVATE_SLOT(d_func(), void _q_configuringChanged(bool value)) }; } // namespace Shell