new aspect ratio mode ConstrainedSquare

it makes applets in panel to not
be wider than tall in horizontal panels and not taller than wider in
vertical panels, but can be for instance less wide than tall in
horizontal panels, as opposed to square applets.
it makes poossible to have icons with a reasonable size in very big
panels as vertical panels usually are for instance

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=816757
This commit is contained in:
Marco Martin 2008-06-04 18:58:38 +00:00
parent 3d45aae7fb
commit 1cb044332c
2 changed files with 18 additions and 4 deletions

View File

@ -757,8 +757,8 @@ void Applet::flushPendingConstraintsEvents()
} }
//enforce square size in panels //enforce square size in panels
if (aspectRatioMode() == Plasma::Square && (c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) && if ((c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) &&
size().height() != size().width()) { aspectRatioMode() == Plasma::Square && size().height() != size().width()) {
if (formFactor() == Horizontal) { if (formFactor() == Horizontal) {
setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Expanding)); setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Expanding));
resize(QSizeF(size().height(), size().height())); resize(QSizeF(size().height(), size().height()));
@ -771,12 +771,25 @@ void Applet::flushPendingConstraintsEvents()
setMaximumHeight(size().width()); setMaximumHeight(size().width());
setMinimumHeight(size().width()); setMinimumHeight(size().width());
} }
//or enforce a ConstrainedSquare size
} else if ((c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) &&
aspectRatioMode() == Plasma::ConstrainedSquare && size().height() != size().width()) {
if (formFactor() == Horizontal) {
//FIXME: it shouldn't be used maximum and minimum sizes, layouts are weird
setMaximumSize(size().height(), QWIDGETSIZE_MAX);
} else if (formFactor() == Vertical) {
setMaximumSize(QWIDGETSIZE_MAX, size().width());
}
//if we are on desktop again restore maximum size //if we are on desktop again restore maximum size
} else if (aspectRatioMode() == Plasma::Square && (c & Plasma::FormFactorConstraint) && formFactor() != Horizontal && formFactor() != Vertical) { } else if ((c & Plasma::FormFactorConstraint) && aspectRatioMode() == Plasma::Square ||
aspectRatioMode() == Plasma::ConstrainedSquare && formFactor() != Horizontal && formFactor() != Vertical) {
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
setMinimumSize(0, 0); setMinimumSize(0, 0);
} }
Containment* containment = qobject_cast<Plasma::Containment*>(this); Containment* containment = qobject_cast<Plasma::Containment*>(this);
if (isContainment() && containment) { if (isContainment() && containment) {
containment->d->containmentConstraintsEvent(c); containment->d->containmentConstraintsEvent(c);

View File

@ -157,7 +157,8 @@ enum ImmutabilityType { Mutable = 1 /**< The item can be modified in any way **/
*/ */
enum AspectRatioMode { IgnoreAspectRatio = 0 /**< The applet can be freely resized */, enum AspectRatioMode { IgnoreAspectRatio = 0 /**< The applet can be freely resized */,
KeepAspectRatio = 1 /**< The applet keeps a fixed aspect ratio */, KeepAspectRatio = 1 /**< The applet keeps a fixed aspect ratio */,
Square = 2 /**< The applet is always a square */ Square = 2 /**< The applet is always a square */,
ConstrainedSquare = 3 /** The applet is no wider (in horizontal formfactors) or no higher (in vertical ones) than a square*/
}; };
/** /**