the focus indicator can load also simple svg elements instead of

framesvgs
the slider uses it to show a glow behind the handle on mouse over or
keyboard focus

svn path=/trunk/KDE/kdelibs/; revision=1048126
This commit is contained in:
Marco Martin 2009-11-12 19:31:39 +00:00
parent 486fa5527d
commit 86682cb176
3 changed files with 27 additions and 5 deletions

View File

@ -32,7 +32,8 @@ namespace Plasma
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, QString widget)
: QGraphicsWidget(parent),
m_parent(parent),
m_background(0)
m_background(0),
m_prefix("hover")
{
setFlag(QGraphicsItem::ItemStacksBehindParent);
setAcceptsHoverEvents(true);
@ -71,6 +72,7 @@ bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverEnter) {
m_background->setElementPrefix("hover");
m_prefix = "hover";
m_fade->setProperty("startOpacity", 0.0);
m_fade->setProperty("targetOpacity", 1.0);
m_fade->start();
@ -82,6 +84,7 @@ bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
syncGeometry();
} else if (event->type() == QEvent::FocusIn) {
m_background->setElementPrefix("focus");
m_prefix = "focus";
m_fade->setProperty("startOpacity", 0.0);
m_fade->setProperty("targetOpacity", 1.0);
m_fade->start();
@ -101,7 +104,14 @@ void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *event)
void FocusIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
m_background->paintFrame(painter);
Q_UNUSED(option)
Q_UNUSED(widget)
if (m_background->hasElementPrefix(m_prefix)) {
m_background->paintFrame(painter);
} else {
m_background->paint(painter, QPoint(0,0), m_prefix);
}
}
void FocusIndicator::syncGeometry()
@ -113,9 +123,15 @@ void FocusIndicator::syncGeometry()
geom = m_parent->boundingRect();
}
qreal left, top, right, bottom;
m_background->getMargins(left, top, right, bottom);
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom)));
if (m_background->hasElementPrefix(m_prefix)) {
qreal left, top, right, bottom;
m_background->getMargins(left, top, right, bottom);
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom)));
} else {
QRectF elementRect = m_background->elementRect(m_prefix);
elementRect.moveCenter(geom.center());
setGeometry(elementRect);
}
}
}

View File

@ -52,6 +52,7 @@ private:
Plasma::FrameSvg *m_background;
AbstractAnimation *m_fade;
QRectF m_customGeometry;
QString m_prefix;
};
}
#endif

View File

@ -30,6 +30,7 @@
#include "framesvg.h"
#include "private/style_p.h"
#include "private/focusindicator_p.h"
namespace Plasma
{
@ -47,6 +48,7 @@ public:
Plasma::FrameSvg *background;
Plasma::Style::Ptr style;
FocusIndicator *focusIndicator;
};
Slider::Slider(QGraphicsWidget *parent)
@ -58,6 +60,8 @@ Slider::Slider(QGraphicsWidget *parent)
connect(native, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int)));
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
d->focusIndicator = new FocusIndicator(this, "widgets/slider");
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
@ -153,6 +157,7 @@ void Slider::paint(QPainter *painter,
QRect elementRect = d->background->elementRect(handle).toRect();
elementRect.moveCenter(handleRect.center());
d->focusIndicator->setCustomGeometry(elementRect);
d->background->paint(painter, elementRect, handle);
}