paint correctly not autoraise buttons (default behaviour is autoraise)

and expose setautoraise in the api

svn path=/trunk/KDE/kdelibs/; revision=882816
This commit is contained in:
Marco Martin 2008-11-11 12:50:42 +00:00
parent bf6ef3f41d
commit ec70aa7179
2 changed files with 27 additions and 3 deletions

View File

@ -145,6 +145,7 @@ ToolButton::ToolButton(QGraphicsWidget *parent)
connect(native, SIGNAL(clicked()), this, SIGNAL(clicked()));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
native->setAutoRaise(true);
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
@ -160,6 +161,16 @@ ToolButton::~ToolButton()
delete d;
}
void ToolButton::setAutoRaise(bool raise)
{
nativeWidget()->setAutoRaise(raise);
}
bool ToolButton::autoRaise() const
{
return nativeWidget()->autoRaise();
}
void ToolButton::setText(const QString &text)
{
static_cast<QToolButton*>(widget())->setText(text);
@ -260,7 +271,7 @@ void ToolButton::paint(QPainter *painter,
buttonOpt.toolButtonStyle = button->toolButtonStyle();
if (d->animId || (buttonOpt.state & QStyle::State_MouseOver) || (buttonOpt.state & QStyle::State_On)) {
if (d->animId || !button->autoRaise() || (buttonOpt.state & QStyle::State_MouseOver) || (buttonOpt.state & QStyle::State_On)) {
if (button->isDown() || (buttonOpt.state & QStyle::State_On)) {
d->background->setElementPrefix("toolbutton-pressed");
} else {
@ -295,7 +306,7 @@ void ToolButton::paint(QPainter *painter,
void ToolButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (nativeWidget()->isDown()) {
if (nativeWidget()->isDown() || !nativeWidget()->autoRaise()) {
return;
}
@ -315,7 +326,7 @@ void ToolButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void ToolButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
if (nativeWidget()->isDown()) {
if (nativeWidget()->isDown() || !nativeWidget()->autoRaise()) {
return;
}

View File

@ -42,6 +42,7 @@ class PLASMA_EXPORT ToolButton : public QGraphicsProxyWidget
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString stylesheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QToolButton *nativeWidget READ nativeWidget)
@ -50,6 +51,18 @@ public:
explicit ToolButton(QGraphicsWidget *parent = 0);
~ToolButton();
/**
* Sets if the toolbutton has an autoraise behaviour
*
* @arg raise
*/
void setAutoRaise(bool raise);
/**
* @return true if the toolbutton has an autoraise behaviour
*/
bool autoRaise() const;
/**
* Sets the display text for this ToolButton
*