use the glow to indicate focus/hover

svn path=/trunk/KDE/kdelibs/; revision=1027297
This commit is contained in:
Marco Martin 2009-09-23 19:15:51 +00:00
parent 034e5a4a62
commit cfb045bf3d
2 changed files with 50 additions and 0 deletions

View File

@ -22,10 +22,13 @@
#include <QApplication>
#include <QPainter>
#include <QStyleOptionSpinBox>
#include <knuminput.h>
#include <kmimetype.h>
#include <plasma/theme.h>
#include <plasma/framesvg.h>
#include <plasma/private/style_p.h>
namespace Plasma
@ -65,6 +68,7 @@ public:
SpinBox *q;
Plasma::Style::Ptr style;
Plasma::FrameSvg *background;
bool customFont;
};
@ -81,6 +85,10 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
native->setAttribute(Qt::WA_NoSystemBackground);
native->setAutoFillBackground(false);
d->background = new Plasma::FrameSvg(this);
d->background->setImagePath("widgets/lineedit");
d->background->setCacheAllRenderedFrames(true);
d->style = Plasma::Style::sharedStyle();
native->setStyle(d->style.data());
d->setPalette();
@ -153,6 +161,45 @@ void SpinBox::changeEvent(QEvent *event)
QGraphicsProxyWidget::changeEvent(event);
}
void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
}
void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
}
void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
if (hasFocus() || isUnderMouse()) {
if (hasFocus()) {
d->background->setElementPrefix("focus");
} else {
d->background->setElementPrefix("hover");
}
qreal left, top, right, bottom;
d->background->getMargins(left, top, right, bottom);
QStyleOptionSpinBox spinOpt;
spinOpt.initFrom(nativeWidget());
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
d->background->resizeFrame(controlrect.size()+QSizeF(left+right, top+bottom));
d->background->paintFrame(painter, QPoint(-left, -top));
}
QGraphicsProxyWidget::paint(painter, option, widget);
}
} // namespace Plasma
#include <spinbox.moc>

View File

@ -86,6 +86,9 @@ public:
protected:
void changeEvent(QEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
public Q_SLOTS:
/**