diff --git a/widgets/spinbox.cpp b/widgets/spinbox.cpp index c035fdfb6..b08190fdc 100644 --- a/widgets/spinbox.cpp +++ b/widgets/spinbox.cpp @@ -22,10 +22,13 @@ #include #include +#include + #include #include #include +#include #include 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 diff --git a/widgets/spinbox.h b/widgets/spinbox.h index 5bddb8330..35d3f4baa 100644 --- a/widgets/spinbox.h +++ b/widgets/spinbox.h @@ -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: /**