From d7f413742a63f84ac4d63377e5b576fe5d98409f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 18 Dec 2007 16:56:34 +0000 Subject: [PATCH] Now icons can be resized BUG: 152695 svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=750084 --- widgets/icon.cpp | 28 ++++++++++++++++++++++------ widgets/icon.h | 2 -- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/widgets/icon.cpp b/widgets/icon.cpp index 083cbc670..d7e084814 100644 --- a/widgets/icon.cpp +++ b/widgets/icon.cpp @@ -782,6 +782,17 @@ void Icon::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option } #endif + int iconWidth; + if (size().width() < size().height()) { + iconWidth = size().width() - + d->horizontalMargin[Private::IconMargin].left - + d->horizontalMargin[Private::IconMargin].right; + }else{ + iconWidth = size().height() - + d->verticalMargin[Private::IconMargin].top - + d->verticalMargin[Private::IconMargin].bottom; + } + d->iconSize = QSizeF(iconWidth, iconWidth); calculateSize(option); d->setActiveMargins(); @@ -798,13 +809,23 @@ void Icon::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option state = Private::HoverState; } - QPixmap icon = d->decoration(option, state != Private::NoState); + QPixmap icon = d->decoration(option, state != Private::NoState); const QPointF iconPos = d->iconPosition(option, icon); QTextLayout labelLayout, infoLayout; QRectF textBoundingRect; d->layoutTextItems(option, icon, &labelLayout, &infoLayout, &textBoundingRect); + //did the calculated icon size left room for the text? + if (!d->text.isEmpty() && iconPos.y()+ + d->iconSize.height()+ + textBoundingRect.height() > size().height()) { + int iconWidth = d->iconSize.width() - + textBoundingRect.height() + + iconPos.y(); + d->iconSize = QSizeF(iconWidth, iconWidth); + } + d->svg.resize(size()); d->drawBackground(painter, state); @@ -1032,11 +1053,6 @@ void Icon::setAlignment(Qt::Alignment alignment) d->alignment=alignment; } -Qt::Orientations Icon::expandingDirections() const -{ - return Qt::Horizontal; -} - } // namespace Plasma #include "icon.moc" diff --git a/widgets/icon.h b/widgets/icon.h index 6277a8223..11bf48b7d 100644 --- a/widgets/icon.h +++ b/widgets/icon.h @@ -153,8 +153,6 @@ public: */ void setAlignment(Qt::Alignment alignment); - Qt::Orientations expandingDirections() const; - public Q_SLOTS: /** * Sets the appearance of the icon to pressed or restores the appearance