API review:

remainSquare(), aspectRatioMode() and their setters are merged in
aspectRatioMode() + setAspectRatioMode(Plasma::AspectRatio)
Plasma::AspectRatio has IgnoreAspectRatio, KeepAspectRatio and Square

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=802561
This commit is contained in:
Marco Martin 2008-04-29 20:31:18 +00:00
parent f4d9309b86
commit 43066e49ce
4 changed files with 36 additions and 33 deletions

View File

@ -114,12 +114,11 @@ public:
cachedBackground(0), cachedBackground(0),
mainConfig(0), mainConfig(0),
pendingConstraints(NoConstraint), pendingConstraints(NoConstraint),
aspectRatioMode(Qt::KeepAspectRatio), aspectRatioMode(Plasma::KeepAspectRatio),
immutability(NotImmutable), immutability(NotImmutable),
hasConfigurationInterface(false), hasConfigurationInterface(false),
failed(false), failed(false),
isContainment(false), isContainment(false),
square(false),
transient(false) transient(false)
{ {
if (appletId == 0) { if (appletId == 0) {
@ -362,12 +361,11 @@ public:
QPixmap* cachedBackground; QPixmap* cachedBackground;
KConfigGroup *mainConfig; KConfigGroup *mainConfig;
Plasma::Constraints pendingConstraints; Plasma::Constraints pendingConstraints;
Qt::AspectRatioMode aspectRatioMode; Plasma::AspectRatio aspectRatioMode;
ImmutabilityType immutability; ImmutabilityType immutability;
bool hasConfigurationInterface : 1; bool hasConfigurationInterface : 1;
bool failed : 1; bool failed : 1;
bool isContainment : 1; bool isContainment : 1;
bool square : 1;
bool transient : 1; bool transient : 1;
}; };
@ -1071,26 +1069,16 @@ Location Applet::location() const
return c ? c->d->location : Plasma::Desktop; return c ? c->d->location : Plasma::Desktop;
} }
Qt::AspectRatioMode Applet::aspectRatioMode() const Plasma::AspectRatio Applet::aspectRatioMode() const
{ {
return d->aspectRatioMode; return d->aspectRatioMode;
} }
void Applet::setAspectRatioMode(Qt::AspectRatioMode mode) void Applet::setAspectRatioMode(Plasma::AspectRatio mode)
{ {
d->aspectRatioMode = 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 ) void Applet::watchForMouseMove( QGraphicsItem * watched, bool watch )
{ {
if (!watched) { if (!watched) {
@ -1410,6 +1398,21 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
return QGraphicsWidget::itemChange(change, 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) void Applet::setGeometry(const QRectF& geometry)
{ {
QRectF beforeGeom = QGraphicsWidget::geometry(); QRectF beforeGeom = QGraphicsWidget::geometry();

View File

@ -70,7 +70,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired) Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry) Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources) Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode)
public: public:
typedef QList<Applet*> List; typedef QList<Applet*> List;
@ -223,24 +222,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/** /**
* @return the prefered aspect ratio mode for placement and resizing * @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 * Sets the prefered aspect ratio mode for placement and resizing
*/ */
void setAspectRatioMode(Qt::AspectRatioMode); void setAspectRatioMode(Plasma::AspectRatio);
/**
* @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);
/** /**
* Returns a list of all known applets. * Returns a list of all known applets.
@ -662,6 +649,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* Reimplemented from QGraphicsLayoutItem
*/
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
private: private:
Q_DISABLE_COPY(Applet) Q_DISABLE_COPY(Applet)
Q_PRIVATE_SLOT(d, void checkImmutability()) Q_PRIVATE_SLOT(d, void checkImmutability())

View File

@ -443,7 +443,7 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
min += QSizeF(16, 16); min += QSizeF(16, 16);
} }
bool ignoreAspectRatio = m_applet->aspectRatioMode() == Qt::IgnoreAspectRatio; bool ignoreAspectRatio = m_applet->aspectRatioMode() == Plasma::IgnoreAspectRatio;
if (QApplication::keyboardModifiers() & Qt::ControlModifier) { if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
ignoreAspectRatio = !ignoreAspectRatio; ignoreAspectRatio = !ignoreAspectRatio;

View File

@ -152,6 +152,14 @@ enum ImmutabilityType { NotImmutable = 1 /**The item can be modified in any way
}; };
/**
* 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, * The ComonentType enumeration refers to the various types of components,
* or plugins, supported by plasma. * or plugins, supported by plasma.