From 1cb044332ce6993f3a55614246a48790f42ab428 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 4 Jun 2008 18:58:38 +0000 Subject: [PATCH] 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 --- applet.cpp | 19 ++++++++++++++++--- plasma.h | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/applet.cpp b/applet.cpp index eac9009f8..37c41a6ff 100644 --- a/applet.cpp +++ b/applet.cpp @@ -757,8 +757,8 @@ void Applet::flushPendingConstraintsEvents() } //enforce square size in panels - if (aspectRatioMode() == Plasma::Square && (c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) && - size().height() != size().width()) { + if ((c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) && + aspectRatioMode() == Plasma::Square && size().height() != size().width()) { if (formFactor() == Horizontal) { setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Expanding)); resize(QSizeF(size().height(), size().height())); @@ -771,12 +771,25 @@ void Applet::flushPendingConstraintsEvents() setMaximumHeight(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 - } 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); setMinimumSize(0, 0); } + + Containment* containment = qobject_cast(this); if (isContainment() && containment) { containment->d->containmentConstraintsEvent(c); diff --git a/plasma.h b/plasma.h index f78a1dd37..db0b065a4 100644 --- a/plasma.h +++ b/plasma.h @@ -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 */, 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*/ }; /**