-update geometry when the text changes

-return a good size hint based on svg margins

svn path=/trunk/KDE/kdelibs/; revision=1071052
This commit is contained in:
Marco Martin 2010-01-07 12:44:20 +00:00
parent 26b7d59e20
commit 291b11f8a2
2 changed files with 21 additions and 4 deletions

View File

@ -170,6 +170,11 @@ ToolButton::ToolButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ToolButtonPrivate(this))
{
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
d->background->setCacheAllRenderedFrames(true);
d->background->setElementPrefix("normal");
QToolButton *native = new QToolButton;
connect(native, SIGNAL(clicked()), this, SIGNAL(clicked()));
connect(native, SIGNAL(pressed()), this, SIGNAL(pressed()));
@ -178,10 +183,6 @@ ToolButton::ToolButton(QGraphicsWidget *parent)
native->setAttribute(Qt::WA_NoSystemBackground);
native->setAutoRaise(true);
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
d->background->setCacheAllRenderedFrames(true);
d->background->setElementPrefix("normal");
d->syncBorders();
setAcceptHoverEvents(true);
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
@ -215,6 +216,7 @@ bool ToolButton::autoRaise() const
void ToolButton::setText(const QString &text)
{
static_cast<QToolButton*>(widget())->setText(text);
updateGeometry();
}
QString ToolButton::text() const
@ -430,6 +432,20 @@ void ToolButton::changeEvent(QEvent *event)
QGraphicsProxyWidget::changeEvent(event);
}
QSizeF ToolButton::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
QSizeF hint = QGraphicsProxyWidget::sizeHint(which, constraint);
//replace the native margin with the Svg one
QStyleOption option;
option.initFrom(nativeWidget());
int nativeMargin = nativeWidget()->style()->pixelMetric(QStyle::PM_ButtonMargin, &option, nativeWidget());
qreal left, top, right, bottom;
d->background->getMargins(left, top, right, bottom);
hint = hint - QSize(nativeMargin, nativeMargin) + QSize(left+right, top+bottom);
return hint;
}
} // namespace Plasma
#include <toolbutton.moc>

View File

@ -172,6 +172,7 @@ protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
private:
Q_PRIVATE_SLOT(d, void syncBorders())