diff --git a/applet.cpp b/applet.cpp index 27141f1c0..7f47159ea 100644 --- a/applet.cpp +++ b/applet.cpp @@ -114,12 +114,11 @@ public: cachedBackground(0), mainConfig(0), pendingConstraints(NoConstraint), - aspectRatioMode(Qt::KeepAspectRatio), + aspectRatioMode(Plasma::KeepAspectRatio), immutability(NotImmutable), hasConfigurationInterface(false), failed(false), isContainment(false), - square(false), transient(false) { if (appletId == 0) { @@ -362,12 +361,11 @@ public: QPixmap* cachedBackground; KConfigGroup *mainConfig; Plasma::Constraints pendingConstraints; - Qt::AspectRatioMode aspectRatioMode; + Plasma::AspectRatio aspectRatioMode; ImmutabilityType immutability; bool hasConfigurationInterface : 1; bool failed : 1; bool isContainment : 1; - bool square : 1; bool transient : 1; }; @@ -1071,26 +1069,16 @@ Location Applet::location() const return c ? c->d->location : Plasma::Desktop; } -Qt::AspectRatioMode Applet::aspectRatioMode() const +Plasma::AspectRatio Applet::aspectRatioMode() const { return d->aspectRatioMode; } -void Applet::setAspectRatioMode(Qt::AspectRatioMode mode) +void Applet::setAspectRatioMode(Plasma::AspectRatio mode) { d->aspectRatioMode = mode; } -bool Applet::remainSquare() const -{ - return d->square; -} - -void Applet::setRemainSquare(bool square) -{ - d->square = square; -} - void Applet::watchForMouseMove( QGraphicsItem * watched, bool watch ) { if (!watched) { @@ -1410,6 +1398,21 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value) return QGraphicsWidget::itemChange(change, value); } +QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const +{ + QSizeF hint = QGraphicsWidget::sizeHint(which, constraint); + + if (d->aspectRatioMode == Plasma::Square) { + if (formFactor() == Horizontal) { + hint.setWidth(hint.height()); + } else { + hint.setHeight(hint.width()); + } + } + + return hint; +} + void Applet::setGeometry(const QRectF& geometry) { QRectF beforeGeom = QGraphicsWidget::geometry(); diff --git a/applet.h b/applet.h index ccb8ea3a2..9fd90cecc 100644 --- a/applet.h +++ b/applet.h @@ -70,7 +70,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired) Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry) Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode) public: typedef QList List; @@ -223,24 +222,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget /** * @return the prefered aspect ratio mode for placement and resizing */ - Qt::AspectRatioMode aspectRatioMode() const; + Plasma::AspectRatio aspectRatioMode() const; /** * Sets the prefered aspect ratio mode for placement and resizing */ - void setAspectRatioMode(Qt::AspectRatioMode); - - /** - * @return whether or not to keep this applet square. - */ - bool remainSquare() const; - - /** - * Sets whether or not this applet should be kept square. - * - * @param square true if the applet should always be square in shape. - */ - void setRemainSquare(bool square); + void setAspectRatioMode(Plasma::AspectRatio); /** * Returns a list of all known applets. @@ -662,6 +649,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget */ QVariant itemChange(GraphicsItemChange change, const QVariant &value); + /** + * Reimplemented from QGraphicsLayoutItem + */ + QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const; + private: Q_DISABLE_COPY(Applet) Q_PRIVATE_SLOT(d, void checkImmutability()) diff --git a/applethandle.cpp b/applethandle.cpp index 3c17f9532..c88a49315 100644 --- a/applethandle.cpp +++ b/applethandle.cpp @@ -443,7 +443,7 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) min += QSizeF(16, 16); } - bool ignoreAspectRatio = m_applet->aspectRatioMode() == Qt::IgnoreAspectRatio; + bool ignoreAspectRatio = m_applet->aspectRatioMode() == Plasma::IgnoreAspectRatio; if (QApplication::keyboardModifiers() & Qt::ControlModifier) { ignoreAspectRatio = !ignoreAspectRatio; diff --git a/plasma.h b/plasma.h index e1f4c98aa..e0f2150ab 100644 --- a/plasma.h +++ b/plasma.h @@ -151,7 +151,15 @@ enum ImmutabilityType { NotImmutable = 1 /**The item can be modified in any way SystemImmutable = 4 /** the item is locked down by the system, the user can't unlock it **/ }; - + +/** + * Defines the aspect ratio used when scaling an applet + */ +enum AspectRatio { IgnoreAspectRatio = 0 /** The applet can be freely resized */, + KeepAspectRatio = 1 /** The applet keeps a fixed aspect ratio */, + Square = 2 /** The applet is always a square */ + }; + /** * The ComonentType enumeration refers to the various types of components, * or plugins, supported by plasma.