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),
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();

View File

@ -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<Applet*> 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())

View File

@ -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;

View File

@ -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.