Fix the push button size hint. Make PushButton::boundingRect() side-effect free.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=699467
This commit is contained in:
parent
1f99ac776a
commit
ca39faf71a
@ -62,7 +62,6 @@ public:
|
|||||||
QString text;
|
QString text;
|
||||||
KIcon icon;
|
KIcon icon;
|
||||||
QSizeF iconSize;
|
QSizeF iconSize;
|
||||||
QSizeF size;
|
|
||||||
bool flat;
|
bool flat;
|
||||||
ButtonState state;
|
ButtonState state;
|
||||||
};
|
};
|
||||||
@ -135,34 +134,6 @@ PushButton::PushButton(const KIcon &icon, const QString &text, Widget *parent)
|
|||||||
setIcon(icon);
|
setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PushButton::boundingRect() const
|
|
||||||
{
|
|
||||||
if (!d->size.isValid()) {
|
|
||||||
int width = 0;
|
|
||||||
int height = 0;
|
|
||||||
|
|
||||||
QStyleOptionButton option;
|
|
||||||
d->initStyleOption(&option, this);
|
|
||||||
|
|
||||||
if (!icon().isNull()) {
|
|
||||||
height += qMax(option.iconSize.height(), height);
|
|
||||||
width += 2 + option.iconSize.width() + 2; // add margin
|
|
||||||
}
|
|
||||||
|
|
||||||
QString display(option.text);
|
|
||||||
if (display.isEmpty())
|
|
||||||
display = "Plasma";
|
|
||||||
|
|
||||||
QSize textSize = option.fontMetrics.size(Qt::TextShowMnemonic, display);
|
|
||||||
width += textSize.width();
|
|
||||||
height = qMax(height, textSize.height());
|
|
||||||
d->size = QSizeF((QApplication::style()->sizeFromContents(QStyle::CT_PushButton, &option, QSize(width, height), 0).
|
|
||||||
expandedTo(QApplication::globalStrut())));
|
|
||||||
}
|
|
||||||
|
|
||||||
return QRectF(QPointF(0.0, 0.0), d->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
PushButton::~PushButton()
|
PushButton::~PushButton()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
@ -182,7 +153,6 @@ void PushButton::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *
|
|||||||
void PushButton::setText(const QString& text)
|
void PushButton::setText(const QString& text)
|
||||||
{
|
{
|
||||||
d->text = text;
|
d->text = text;
|
||||||
d->size = QSizeF();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +164,6 @@ QString PushButton::text() const
|
|||||||
void PushButton::setIcon(const KIcon &icon)
|
void PushButton::setIcon(const KIcon &icon)
|
||||||
{
|
{
|
||||||
d->icon = icon;
|
d->icon = icon;
|
||||||
d->size = QSizeF();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +193,6 @@ void PushButton::setIconSize(const QSizeF &size)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
d->iconSize = size;
|
d->iconSize = size;
|
||||||
d->size = QSizeF();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +241,25 @@ Qt::Orientations PushButton::expandingDirections() const
|
|||||||
|
|
||||||
QSizeF PushButton::sizeHint() const
|
QSizeF PushButton::sizeHint() const
|
||||||
{
|
{
|
||||||
return minimumSize();
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
|
||||||
|
QStyleOptionButton option;
|
||||||
|
d->initStyleOption(&option, this);
|
||||||
|
|
||||||
|
if (!icon().isNull()) {
|
||||||
|
height += qMax(option.iconSize.height(), height);
|
||||||
|
width += 2 + option.iconSize.width() + 2; // add margin
|
||||||
|
}
|
||||||
|
|
||||||
|
QString display(option.text);
|
||||||
|
|
||||||
|
QSize textSize = option.fontMetrics.size(Qt::TextShowMnemonic, display);
|
||||||
|
width += textSize.width();
|
||||||
|
height = qMax(height, textSize.height());
|
||||||
|
|
||||||
|
return QSizeF((QApplication::style()->sizeFromContents(QStyle::CT_PushButton, &option, QSize(width, height), 0).
|
||||||
|
expandedTo(QApplication::globalStrut())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,7 +150,6 @@ protected:
|
|||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||||
QRectF boundingRect() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private ;
|
class Private ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user