still messed up, but less useless confusing code in there now =)

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=743202
This commit is contained in:
Aaron J. Seigo 2007-11-30 01:06:27 +00:00
parent e07afa49a8
commit 9d936d1d8f
2 changed files with 15 additions and 102 deletions

View File

@ -55,7 +55,6 @@ namespace Plasma
Icon::Private::Private() Icon::Private::Private()
: svg("widgets/iconbutton"), : svg("widgets/iconbutton"),
svgElements(0), svgElements(0),
size(48*1.1, 48*1.1),
iconSize(48, 48), iconSize(48, 48),
state(Private::NoState), state(Private::NoState),
orientation(Qt::Vertical), orientation(Qt::Vertical),
@ -63,7 +62,6 @@ Icon::Private::Private()
calculateSizeRequested(true) // First time always true calculateSizeRequested(true) // First time always true
{ {
svg.setContentType(Plasma::Svg::ImageSet); svg.setContentType(Plasma::Svg::ImageSet);
svg.resize(size);
//TODO: recheck when svg changes //TODO: recheck when svg changes
checkSvgElements(); checkSvgElements();
@ -339,13 +337,13 @@ void Icon::addAction(QAction *action)
iconAction->setRect(QRectF(6, 6, 32, 32)); iconAction->setRect(QRectF(6, 6, 32, 32));
break; break;
case Private::TopRight: case Private::TopRight:
iconAction->setRect(QRectF(d->size.width() - 38, 6, 32, 32)); iconAction->setRect(QRectF(size().width() - 38, 6, 32, 32));
break; break;
case Private::BottomLeft: case Private::BottomLeft:
iconAction->setRect(QRectF(6, d->size.height() - 38, 32, 32)); iconAction->setRect(QRectF(6, size().height() - 38, 32, 32));
break; break;
case Private::BottomRight: case Private::BottomRight:
iconAction->setRect(QRectF(d->size.width() - 38, d->size.height() - 38, 32, 32)); iconAction->setRect(QRectF(size().width() - 38, size().height() - 38, 32, 32));
break; break;
} }
} }
@ -390,7 +388,7 @@ QSizeF Icon::Private::displaySizeHint(const QStyleOptionGraphicsItem *option) co
void Icon::calculateSize() void Icon::calculateSize()
{ {
if (d->calculateSizeRequested = true) { if (d->calculateSizeRequested) {
// We do this to get size hint information before the icon has been drawn, as // We do this to get size hint information before the icon has been drawn, as
// we have no access to the style option before that time. So we create a dummy. // we have no access to the style option before that time. So we create a dummy.
QStyleOptionGraphicsItem option; QStyleOptionGraphicsItem option;
@ -415,19 +413,16 @@ void Icon::calculateSize(const QStyleOptionGraphicsItem *option)
const QSizeF decorationSize = d->addMargin(d->iconSize, Private::IconMargin); const QSizeF decorationSize = d->addMargin(d->iconSize, Private::IconMargin);
QSizeF newSize; QSizeF newSize;
if (d->orientation == Qt::Vertical) if (d->orientation == Qt::Vertical) {
{
newSize.rwidth() = qMax(decorationSize.width(), displaySize.width()); newSize.rwidth() = qMax(decorationSize.width(), displaySize.width());
newSize.rheight() = decorationSize.height() + displaySize.height() + 1; newSize.rheight() = decorationSize.height() + displaySize.height() + 1;
} } else {
else
{
newSize.rwidth() = decorationSize.width() + displaySize.width() + 1; newSize.rwidth() = decorationSize.width() + displaySize.width() + 1;
newSize.rheight() = qMax(decorationSize.height(), displaySize.height()); newSize.rheight() = qMax(decorationSize.height(), displaySize.height());
} }
d->size = d->addMargin(newSize, Private::ItemMargin); newSize = d->addMargin(newSize, Private::ItemMargin);
d->svg.resize(d->size); d->svg.resize(newSize);
d->calculateSizeRequested = false; d->calculateSizeRequested = false;
int count = 0; int count = 0;
@ -440,27 +435,23 @@ void Icon::calculateSize(const QStyleOptionGraphicsItem *option)
//iconAction->setRect(QRectF(6, 6, 32, 32)); //iconAction->setRect(QRectF(6, 6, 32, 32));
break; break;
case Private::TopRight: case Private::TopRight:
iconAction->setRect(QRectF(d->size.width() - 38, 6, 32, 32)); iconAction->setRect(QRectF(newSize.width() - 38, 6, 32, 32));
break; break;
case Private::BottomLeft: case Private::BottomLeft:
iconAction->setRect(QRectF(6, d->size.height() - 38, 32, 32)); iconAction->setRect(QRectF(6, newSize.height() - 38, 32, 32));
break; break;
case Private::BottomRight: case Private::BottomRight:
iconAction->setRect(QRectF(d->size.width() - 38, d->size.height() - 38, 32, 32)); iconAction->setRect(QRectF(newSize.width() - 38, newSize.height() - 38, 32, 32));
break; break;
} }
++count; ++count;
} }
resize(newSize);
update(); update();
} }
QRectF Icon::boundingRect() const
{
return QRectF(QPointF(0, 0), d->size);
}
void Icon::Private::drawBackground(QPainter *painter) void Icon::Private::drawBackground(QPainter *painter)
{ {
QString element; QString element;
@ -570,8 +561,9 @@ QRectF Icon::Private::labelRectangle(const QStyleOptionGraphicsItem *option, con
{ {
Q_UNUSED(string) Q_UNUSED(string)
if (icon.isNull()) if (icon.isNull()) {
return option->rect; return option->rect;
}
const QSizeF decoSize = addMargin(iconSize, Private::IconMargin); const QSizeF decoSize = addMargin(iconSize, Private::IconMargin);
@ -806,7 +798,7 @@ void Icon::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option
QRectF textBoundingRect; QRectF textBoundingRect;
d->layoutTextItems(option, icon, &labelLayout, &infoLayout, &textBoundingRect); d->layoutTextItems(option, icon, &labelLayout, &infoLayout, &textBoundingRect);
d->svg.resize(d->size); d->svg.resize(size());
d->drawBackground(painter); d->drawBackground(painter);
// draw icon // draw icon
@ -1001,75 +993,16 @@ void Icon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Widget::mouseMoveEvent(event); Widget::mouseMoveEvent(event);
} }
QSizeF Icon::sizeHint() const
{
return d->size;
}
Qt::Orientations Icon::expandingDirections() const
{
return 0;
}
void Icon::setAlignment(Qt::Alignment alignment) void Icon::setAlignment(Qt::Alignment alignment)
{ {
d->alignment=alignment; d->alignment=alignment;
} }
/*
QSizeF Icon::sizeHint() const
{
return d->size;
}
QSizeF Icon::minimumSize() const
{
return d->size; // probably should be more flexible on this =)
}
QSizeF Icon::maximumSize() const
{
return d->size;
}
Qt::Orientations Icon::expandingDirections() const Qt::Orientations Icon::expandingDirections() const
{ {
return Qt::Horizontal; return Qt::Horizontal;
} }
bool Icon::hasHeightForWidth() const
{
return true;
}
qreal Icon::heightForWidth(qreal w) const
{
return w; //FIXME: we shouldn't assume squareness but actually calculate based on text and what not
}
bool Icon::hasWidthForHeight() const
{
return true;
}
qreal Icon::widthForHeight(qreal h) const
{
return h; //FIXME: we shouldn't assume squareness but actually calculate based on text and what not
}
QRectF Icon::geometry() const
{
return boundingRect();
}
void Icon::setGeometry(const QRectF &r)
{
// TODO: this is wrong, but we should probably never call setGeometry anyway!
setIconSize(r.size());
setPos(r.x(),r.y());
}
*/
} // namespace Plasma } // namespace Plasma
#include "icon.moc" #include "icon.moc"

View File

@ -153,28 +153,8 @@ public:
*/ */
void setAlignment(Qt::Alignment alignment); void setAlignment(Qt::Alignment alignment);
// Layout stuff - no need to document
/*
Qt::Orientations expandingDirections() const; Qt::Orientations expandingDirections() const;
QSizeF minimumSize() const;
QSizeF maximumSize() const;
bool hasHeightForWidth() const;
qreal heightForWidth(qreal w) const;
bool hasWidthForHeight() const;
qreal widthForHeight(qreal h) const;
QRectF geometry() const;
void setGeometry(const QRectF& r);
QSizeF sizeHint() const;
*/
Qt::Orientations expandingDirections() const;
QSizeF sizeHint() const;
QRectF boundingRect() const;
protected: protected:
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);