new property: preferredIconSize, aka the final solution to all layout problems

svn path=/trunk/KDE/kdelibs/; revision=1118322
This commit is contained in:
Marco Martin 2010-04-24 12:08:13 +00:00
parent b9de116f33
commit 5b49fc05e1
3 changed files with 34 additions and 0 deletions

View File

@ -104,6 +104,7 @@ IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
iconSvg(0), iconSvg(0),
hoverAnimation(new IconHoverAnimation(q)), hoverAnimation(new IconHoverAnimation(q)),
iconSize(48, 48), iconSize(48, 48),
preferredIconSize(-1, -1),
states(IconWidgetPrivate::NoState), states(IconWidgetPrivate::NoState),
orientation(Qt::Vertical), orientation(Qt::Vertical),
numDisplayLines(2), numDisplayLines(2),
@ -660,6 +661,9 @@ QString IconWidget::svg() const
QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{ {
if (which == Qt::PreferredSize) { if (which == Qt::PreferredSize) {
if (d->preferredIconSize.isValid()) {
return sizeFromIconSize(qMax(d->preferredIconSize.height(), d->preferredIconSize.height()));
}
int iconSize = KIconLoader::SizeMedium; int iconSize = KIconLoader::SizeMedium;
if (d->iconSvg) { if (d->iconSvg) {
QSizeF oldSize = d->iconSvg->size(); QSizeF oldSize = d->iconSvg->size();
@ -1261,6 +1265,17 @@ QSizeF IconWidget::iconSize() const
return d->iconSize; return d->iconSize;
} }
void IconWidget::setPreferredIconSize(const QSizeF &size)
{
d->preferredIconSize = size;
updateGeometry();
}
QSizeF IconWidget::preferredIconSize() const
{
return d->preferredIconSize;
}
bool IconWidget::isDown() bool IconWidget::isDown()
{ {
return d->states & IconWidgetPrivate::PressedState; return d->states & IconWidgetPrivate::PressedState;

View File

@ -91,6 +91,7 @@ class PLASMA_EXPORT IconWidget : public QGraphicsWidget
Q_PROPERTY(QAction *action READ action WRITE setAction) Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines) Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines)
Q_PROPERTY(QSizeF preferredIconSize READ preferredIconSize WRITE setPreferredIconSize)
public: public:
/** /**
@ -190,6 +191,23 @@ public:
*/ */
QSizeF iconSize() const; 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 * Plasma::IconWidget allows the user to specify a number of actions
* (currently four) to be displayed around the widget. This method * (currently four) to be displayed around the widget. This method

View File

@ -209,6 +209,7 @@ public:
QColor shadowColor; QColor shadowColor;
IconHoverAnimation *hoverAnimation; IconHoverAnimation *hoverAnimation;
QSizeF iconSize; QSizeF iconSize;
QSizeF preferredIconSize;
QIcon icon; QIcon icon;
QIcon oldIcon; QIcon oldIcon;
IconWidgetStates states; IconWidgetStates states;