From 5b49fc05e15d0fd82c67836072fb3bfbd4d601e6 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sat, 24 Apr 2010 12:08:13 +0000 Subject: [PATCH] new property: preferredIconSize, aka the final solution to all layout problems svn path=/trunk/KDE/kdelibs/; revision=1118322 --- widgets/iconwidget.cpp | 15 +++++++++++++++ widgets/iconwidget.h | 18 ++++++++++++++++++ widgets/iconwidget_p.h | 1 + 3 files changed, 34 insertions(+) diff --git a/widgets/iconwidget.cpp b/widgets/iconwidget.cpp index 4e3cd1e7f..ab5e8d686 100644 --- a/widgets/iconwidget.cpp +++ b/widgets/iconwidget.cpp @@ -104,6 +104,7 @@ IconWidgetPrivate::IconWidgetPrivate(IconWidget *i) iconSvg(0), hoverAnimation(new IconHoverAnimation(q)), iconSize(48, 48), + preferredIconSize(-1, -1), states(IconWidgetPrivate::NoState), orientation(Qt::Vertical), numDisplayLines(2), @@ -660,6 +661,9 @@ QString IconWidget::svg() const QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const { if (which == Qt::PreferredSize) { + if (d->preferredIconSize.isValid()) { + return sizeFromIconSize(qMax(d->preferredIconSize.height(), d->preferredIconSize.height())); + } int iconSize = KIconLoader::SizeMedium; if (d->iconSvg) { QSizeF oldSize = d->iconSvg->size(); @@ -1261,6 +1265,17 @@ QSizeF IconWidget::iconSize() const return d->iconSize; } +void IconWidget::setPreferredIconSize(const QSizeF &size) +{ + d->preferredIconSize = size; + updateGeometry(); +} + +QSizeF IconWidget::preferredIconSize() const +{ + return d->preferredIconSize; +} + bool IconWidget::isDown() { return d->states & IconWidgetPrivate::PressedState; diff --git a/widgets/iconwidget.h b/widgets/iconwidget.h index e0b2a2d95..c21d5c94e 100644 --- a/widgets/iconwidget.h +++ b/widgets/iconwidget.h @@ -91,6 +91,7 @@ class PLASMA_EXPORT IconWidget : public QGraphicsWidget Q_PROPERTY(QAction *action READ action WRITE setAction) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines) + Q_PROPERTY(QSizeF preferredIconSize READ preferredIconSize WRITE setPreferredIconSize) public: /** @@ -190,6 +191,23 @@ public: */ QSizeF iconSize() const; + /** + * Set the size you prefer the icon will be when positioned in a layout. + * @param preferred icon size, pass an invalid size to unset this value + * + * @since 4.5 + */ + void setPreferredIconSize(const QSizeF &size); + + /** + * @return The size you prefer the icon will be when positioned in a layout. + * The default is QSizeF(-1, -1); an invalid size means the icon + * will attempt to be at its default and "optimal" size + * + * @since 4.5 + */ + QSizeF preferredIconSize() const; + /** * Plasma::IconWidget allows the user to specify a number of actions * (currently four) to be displayed around the widget. This method diff --git a/widgets/iconwidget_p.h b/widgets/iconwidget_p.h index 836a4a0f8..02991f9f0 100644 --- a/widgets/iconwidget_p.h +++ b/widgets/iconwidget_p.h @@ -209,6 +209,7 @@ public: QColor shadowColor; IconHoverAnimation *hoverAnimation; QSizeF iconSize; + QSizeF preferredIconSize; QIcon icon; QIcon oldIcon; IconWidgetStates states;