Provide a valid size before being painted
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=697570
This commit is contained in:
parent
99f22093f9
commit
21394705f1
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 by Aaron Seigo <aseigo@kde.org>
|
||||||
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
* Copyright (C) 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
||||||
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
|
* Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com>
|
||||||
* Copyright 2006-2007 Fredrik Höglund <fredrik@kde.org>
|
* Copyright (C) 2006-2007 Fredrik Höglund <fredrik@kde.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
@ -55,8 +55,8 @@ namespace Plasma
|
|||||||
Icon::Private::Private()
|
Icon::Private::Private()
|
||||||
: svg("widgets/iconbutton"),
|
: svg("widgets/iconbutton"),
|
||||||
svgElements(0),
|
svgElements(0),
|
||||||
size(128*1.1, 128*1.1),
|
size(48*1.1, 48*1.1),
|
||||||
iconSize(128, 128),
|
iconSize(48, 48),
|
||||||
state(Private::NoState),
|
state(Private::NoState),
|
||||||
orientation(Qt::Vertical),
|
orientation(Qt::Vertical),
|
||||||
calculateSizeRequested(true) // First time always true
|
calculateSizeRequested(true) // First time always true
|
||||||
@ -316,6 +316,8 @@ void Icon::init()
|
|||||||
d->setVerticalMargin(Private::TextMargin, 6, 2);
|
d->setVerticalMargin(Private::TextMargin, 6, 2);
|
||||||
d->setVerticalMargin(Private::IconMargin, focusHMargin, focusVMargin);
|
d->setVerticalMargin(Private::IconMargin, focusHMargin, focusVMargin);
|
||||||
d->setVerticalMargin(Private::ItemMargin, 0, 0);
|
d->setVerticalMargin(Private::ItemMargin, 0, 0);
|
||||||
|
|
||||||
|
calculateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Icon::addAction(QAction *action)
|
void Icon::addAction(QAction *action)
|
||||||
@ -382,6 +384,21 @@ QSizeF Icon::Private::displaySizeHint(const QStyleOptionGraphicsItem *option) co
|
|||||||
return addMargin(size, TextMargin);
|
return addMargin(size, TextMargin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Icon::calculateSize()
|
||||||
|
{
|
||||||
|
if (d->calculateSizeRequested = true) {
|
||||||
|
// 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.
|
||||||
|
QStyleOptionGraphicsItem option;
|
||||||
|
option.state = QStyle::State_None;
|
||||||
|
option.rect = boundingRect().toRect();
|
||||||
|
calculateSize(&option);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
d->calculateSizeRequested = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Icon::calculateSize(const QStyleOptionGraphicsItem *option)
|
void Icon::calculateSize(const QStyleOptionGraphicsItem *option)
|
||||||
{
|
{
|
||||||
if (!d->calculateSizeRequested)
|
if (!d->calculateSizeRequested)
|
||||||
@ -601,7 +618,6 @@ QSizeF Icon::Private::layoutText(QTextLayout &layout, const QString &text, qreal
|
|||||||
}
|
}
|
||||||
layout.endLayout();
|
layout.endLayout();
|
||||||
|
|
||||||
// return layout.boundingRect().size(); // ARGH!
|
|
||||||
return QSizeF(widthUsed, height);
|
return QSizeF(widthUsed, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +852,7 @@ void Icon::drawActionButtonBase(QPainter* painter, const QSize &size, int elemen
|
|||||||
void Icon::setText(const QString& text)
|
void Icon::setText(const QString& text)
|
||||||
{
|
{
|
||||||
d->text = text;
|
d->text = text;
|
||||||
d->calculateSizeRequested = true;
|
calculateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Icon::text() const
|
QString Icon::text() const
|
||||||
@ -847,7 +863,7 @@ QString Icon::text() const
|
|||||||
void Icon::setInfoText(const QString& text)
|
void Icon::setInfoText(const QString& text)
|
||||||
{
|
{
|
||||||
d->infoText = text;
|
d->infoText = text;
|
||||||
d->calculateSizeRequested = true;
|
calculateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Icon::infoText() const
|
QString Icon::infoText() const
|
||||||
@ -873,7 +889,7 @@ void Icon::setIcon(const QString& icon)
|
|||||||
void Icon::setIcon(const KIcon& icon)
|
void Icon::setIcon(const KIcon& icon)
|
||||||
{
|
{
|
||||||
d->icon = icon;
|
d->icon = icon;
|
||||||
d->calculateSizeRequested = true;
|
calculateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF Icon::iconSize() const
|
QSizeF Icon::iconSize() const
|
||||||
@ -884,7 +900,7 @@ QSizeF Icon::iconSize() const
|
|||||||
void Icon::setIconSize(const QSizeF& s)
|
void Icon::setIconSize(const QSizeF& s)
|
||||||
{
|
{
|
||||||
d->iconSize = s;
|
d->iconSize = s;
|
||||||
d->calculateSizeRequested = true;
|
calculateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Icon::setIconSize(int w, int h)
|
void Icon::setIconSize(int w, int h)
|
||||||
@ -971,6 +987,7 @@ void Icon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
QGraphicsItem::mouseMoveEvent(event);
|
QGraphicsItem::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
QSizeF Icon::sizeHint() const
|
QSizeF Icon::sizeHint() const
|
||||||
{
|
{
|
||||||
return d->size;
|
return d->size;
|
||||||
@ -1022,6 +1039,7 @@ void Icon::setGeometry(const QRectF &r)
|
|||||||
setIconSize(r.size());
|
setIconSize(r.size());
|
||||||
setPos(r.x(),r.y());
|
setPos(r.x(),r.y());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007 by Siraj Razick <siraj@kde.org>
|
* Copyright (C) 2007 by Siraj Razick <siraj@kde.org>
|
||||||
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
* Copyright (C) 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
||||||
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
|
* Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
@ -148,6 +148,7 @@ public:
|
|||||||
void addAction(QAction* action);
|
void addAction(QAction* action);
|
||||||
|
|
||||||
// Layout stuff - no need to document
|
// Layout stuff - no need to document
|
||||||
|
/*
|
||||||
Qt::Orientations expandingDirections() const;
|
Qt::Orientations expandingDirections() const;
|
||||||
|
|
||||||
QSizeF minimumSize() const;
|
QSizeF minimumSize() const;
|
||||||
@ -163,6 +164,7 @@ public:
|
|||||||
void setGeometry(const QRectF& r);
|
void setGeometry(const QRectF& r);
|
||||||
|
|
||||||
QSizeF sizeHint() const;
|
QSizeF sizeHint() const;
|
||||||
|
*/
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -198,6 +200,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
void calculateSize();
|
||||||
void calculateSize(const QStyleOptionGraphicsItem *option);
|
void calculateSize(const QStyleOptionGraphicsItem *option);
|
||||||
|
|
||||||
Private * const d;
|
Private * const d;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 by Aaron Seigo <aseigo@kde.org>
|
||||||
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
|
* Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com>
|
||||||
* Copyright 2006-2007 Fredrik Höglund <fredrik@kde.org>
|
* Copyright (C) 2006-2007 Fredrik Höglund <fredrik@kde.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
|
Loading…
x
Reference in New Issue
Block a user