center the icons properly and cut down on the amount of duplicated information we keep in here

svn path=/trunk/KDE/kdebase/workspace/lib/plasma/; revision=671917
This commit is contained in:
Aaron J. Seigo 2007-06-05 19:48:14 +00:00
parent fddaf2dcf2
commit 11651586c0

View File

@ -34,13 +34,12 @@ class Icon::Private
public: public:
Private() Private()
: size(128*1.1, 128*1.1), : size(128*1.1, 128*1.1),
iconSize(128, 128),
state(Private::NoState), state(Private::NoState),
svg("widgets/iconbutton") svg("widgets/iconbutton")
{ {
svg.setContentType(Plasma::Svg::ImageSet); svg.setContentType(Plasma::Svg::ImageSet);
svg.resize(size); svg.resize(size);
minSize = size;
maxSize = size;
if (svg.elementExists("background")) { if (svg.elementExists("background")) {
svgElements |= SvgBackground; svgElements |= SvgBackground;
@ -85,10 +84,9 @@ class Icon::Private
SvgForegroundPressed = 32 }; SvgForegroundPressed = 32 };
QString text; QString text;
QIcon icon;
QSizeF size; QSizeF size;
QSizeF minSize; QSizeF iconSize;
QSizeF maxSize; QIcon icon;
ButtonState state; ButtonState state;
Svg svg; Svg svg;
int svgElements; int svgElements;
@ -148,11 +146,10 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
element = QString(); element = QString();
} }
if (!d->icon.isNull()) { if (!d->icon.isNull()) {
qreal deltaX = d->size.width() * 0.1; qreal deltaX = (d->size.width() - d->iconSize.width()) / 2;
qreal deltaY = d->size.height() * 0.1; qreal deltaY = (d->size.height() - d->iconSize.height()) / 2 ;
painter->drawPixmap(deltaX, deltaY, d->icon.pixmap((d->size * 0.9).toSize())); painter->drawPixmap(deltaX, deltaY, d->icon.pixmap(d->iconSize.toSize()));
} }
//TODO: draw text //TODO: draw text
@ -216,13 +213,14 @@ QSizeF Icon::size() const
QSizeF Icon::iconSize() const QSizeF Icon::iconSize() const
{ {
return d->size * .9; return d->iconSize;
} }
void Icon::setSize(const QSizeF& s) void Icon::setSize(const QSizeF& s)
{ {
prepareGeometryChange(); prepareGeometryChange();
d->size = s.boundedTo(d->maxSize); //FIXME: maxSize always == size means it can be changed. wtf. =) d->iconSize = s;
d->size = s * 1.1;
d->svg.resize(d->size); d->svg.resize(d->size);
update(); update();
} }
@ -283,12 +281,12 @@ QSizeF Icon::sizeHint() const
QSizeF Icon::minimumSize() const QSizeF Icon::minimumSize() const
{ {
return d->minSize; return d->size; // probably should be more flexible on this =)
} }
QSizeF Icon::maximumSize() const QSizeF Icon::maximumSize() const
{ {
return d->maxSize; return d->size;
} }
Qt::Orientations Icon::expandingDirections() const Qt::Orientations Icon::expandingDirections() const