* make custom prefixes work again
* make non-frame based indicators work (sliders now show focus again) * shave ~8ms off of creation time (bringing it down to ~1ms) * allow sharing of the FrameSvg object * constify and sanitize the previously existing constructor * use QStringBuilder svn path=/trunk/KDE/kdelibs/; revision=1178168
This commit is contained in:
parent
bbe18dd67d
commit
86794f694f
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QGraphicsSceneResizeEvent>
|
#include <QGraphicsSceneResizeEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
|
||||||
#include <plasma/theme.h>
|
#include <plasma/theme.h>
|
||||||
@ -31,18 +32,30 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, QString widget)
|
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, const QString &widget)
|
||||||
: QGraphicsWidget(parent),
|
: QGraphicsWidget(parent),
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
m_background(0),
|
m_background(new Plasma::FrameSvg(this)),
|
||||||
m_isUnderMouse(false)
|
m_isUnderMouse(false)
|
||||||
|
{
|
||||||
|
m_background->setImagePath(widget);
|
||||||
|
init(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, FrameSvg *svg)
|
||||||
|
: QGraphicsWidget(parent),
|
||||||
|
m_parent(parent),
|
||||||
|
m_background(svg),
|
||||||
|
m_isUnderMouse(false)
|
||||||
|
{
|
||||||
|
init(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FocusIndicator::init(QGraphicsWidget *parent)
|
||||||
{
|
{
|
||||||
setFlag(QGraphicsItem::ItemStacksBehindParent);
|
setFlag(QGraphicsItem::ItemStacksBehindParent);
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
|
|
||||||
m_background = new Plasma::FrameSvg(this);
|
|
||||||
m_background->setImagePath(widget);
|
|
||||||
m_background->setElementPrefix("hover");
|
|
||||||
m_background->setCacheAllRenderedFrames(true);
|
m_background->setCacheAllRenderedFrames(true);
|
||||||
|
|
||||||
m_fade = Animator::create(Animator::FadeAnimation, this);
|
m_fade = Animator::create(Animator::FadeAnimation, this);
|
||||||
@ -53,16 +66,15 @@ FocusIndicator::FocusIndicator(QGraphicsWidget *parent, QString widget)
|
|||||||
m_hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation);
|
m_hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation);
|
||||||
m_hoverAnimation->setProperty("duration", 250);
|
m_hoverAnimation->setProperty("duration", 250);
|
||||||
m_hoverAnimation->setTargetWidget(this);
|
m_hoverAnimation->setTargetWidget(this);
|
||||||
if (m_background->hasElementPrefix("shadow")) {
|
|
||||||
m_background->setElementPrefix("shadow");
|
m_testPrefix = "hover";
|
||||||
|
if (m_background->hasElementPrefix("shadow") ||
|
||||||
|
m_background->hasElement("shadow")) {
|
||||||
m_prefix = "shadow";
|
m_prefix = "shadow";
|
||||||
syncGeometry();
|
|
||||||
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parent->installEventFilter(this);
|
parent->installEventFilter(this);
|
||||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncGeometry()));
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncGeometry()));
|
||||||
syncGeometry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FocusIndicator::~FocusIndicator()
|
FocusIndicator::~FocusIndicator()
|
||||||
@ -79,7 +91,22 @@ void FocusIndicator::setCustomGeometry(const QRectF &geometry)
|
|||||||
|
|
||||||
void FocusIndicator::setCustomPrefix(const QString &prefix)
|
void FocusIndicator::setCustomPrefix(const QString &prefix)
|
||||||
{
|
{
|
||||||
|
if (!m_prefix.isEmpty() && !m_customPrefix.isEmpty()) {
|
||||||
|
m_prefix.remove(m_customPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
m_customPrefix = prefix;
|
m_customPrefix = prefix;
|
||||||
|
|
||||||
|
if (!m_prefix.isEmpty()) {
|
||||||
|
m_prefix.prepend(m_customPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_testPrefix = m_customPrefix % "hover";
|
||||||
|
if (m_prefix.isEmpty()) {
|
||||||
|
m_prefix = m_customPrefix % "shadow";
|
||||||
|
}
|
||||||
|
syncGeometry();
|
||||||
|
resizeEvent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
|
bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
|
||||||
@ -95,64 +122,97 @@ bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverEnter) {
|
if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverEnter) {
|
||||||
m_prefix = m_customPrefix + "hover";
|
m_prefix = m_customPrefix % "hover";
|
||||||
syncGeometry();
|
syncGeometry();
|
||||||
m_hoverAnimation->stop();
|
m_hoverAnimation->stop();
|
||||||
m_background->setElementPrefix("shadow");
|
if (m_background->hasElementPrefix(m_testPrefix)) {
|
||||||
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
m_background->setElementPrefix(m_customPrefix % "shadow");
|
||||||
m_background->setElementPrefix("hover");
|
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
||||||
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
m_background->setElementPrefix(m_customPrefix % "hover");
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
||||||
|
} else if (m_background->hasElement(m_testPrefix)) {
|
||||||
|
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "shadow"));
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "hover"));
|
||||||
|
}
|
||||||
|
|
||||||
m_hoverAnimation->start();
|
m_hoverAnimation->start();
|
||||||
} else if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverLeave) {
|
} else if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverLeave) {
|
||||||
m_prefix = m_customPrefix + "shadow";
|
m_prefix = m_customPrefix % "shadow";
|
||||||
syncGeometry();
|
syncGeometry();
|
||||||
m_hoverAnimation->stop();
|
m_hoverAnimation->stop();
|
||||||
m_background->setElementPrefix("hover");
|
|
||||||
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
if (m_background->hasElementPrefix(m_testPrefix)) {
|
||||||
m_background->setElementPrefix("shadow");
|
m_background->setElementPrefix(m_customPrefix % "hover");
|
||||||
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
||||||
|
m_background->setElementPrefix(m_customPrefix % "shadow");
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
||||||
|
} else if (m_background->hasElement(m_testPrefix)) {
|
||||||
|
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "hover"));
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "shadow"));
|
||||||
|
}
|
||||||
m_hoverAnimation->start();
|
m_hoverAnimation->start();
|
||||||
} else if (event->type() == QEvent::GraphicsSceneResize) {
|
} else if (event->type() == QEvent::GraphicsSceneResize) {
|
||||||
syncGeometry();
|
syncGeometry();
|
||||||
} else if (event->type() == QEvent::FocusIn) {
|
} else if (event->type() == QEvent::FocusIn) {
|
||||||
m_prefix = m_customPrefix + "focus";
|
m_prefix = m_customPrefix % "focus";
|
||||||
syncGeometry();
|
|
||||||
m_hoverAnimation->stop();
|
|
||||||
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
|
||||||
m_background->setElementPrefix("focus");
|
|
||||||
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
|
||||||
m_hoverAnimation->start();
|
|
||||||
} else if (!m_isUnderMouse && event->type() == QEvent::FocusOut) {
|
|
||||||
m_prefix = m_customPrefix + "shadow";
|
|
||||||
syncGeometry();
|
syncGeometry();
|
||||||
m_hoverAnimation->stop();
|
m_hoverAnimation->stop();
|
||||||
|
|
||||||
m_background->setElementPrefix("focus");
|
if (m_background->hasElementPrefix(m_customPrefix % "focus")) {
|
||||||
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
//m_background->setElementPrefix(m_customPrefix % "shadow");
|
||||||
m_background->setElementPrefix("shadow");
|
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
||||||
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
m_background->setElementPrefix(m_customPrefix % "focus");
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
||||||
|
} else if (m_background->hasElement(m_customPrefix % "focus")) {
|
||||||
|
//m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "shadow"));
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "focus"));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_hoverAnimation->start();
|
||||||
|
} else if (!m_isUnderMouse && event->type() == QEvent::FocusOut) {
|
||||||
|
m_prefix = m_customPrefix % "shadow";
|
||||||
|
syncGeometry();
|
||||||
|
m_hoverAnimation->stop();
|
||||||
|
|
||||||
|
if (m_background->hasElementPrefix(m_customPrefix % "focus")) {
|
||||||
|
m_background->setElementPrefix("focus");
|
||||||
|
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
||||||
|
m_background->setElementPrefix("shadow");
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
||||||
|
} else if (m_background->hasElement(m_customPrefix % "focus")) {
|
||||||
|
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "focus"));
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "shadow"));
|
||||||
|
}
|
||||||
|
|
||||||
m_hoverAnimation->start();
|
m_hoverAnimation->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *event)
|
void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *)
|
||||||
{
|
{
|
||||||
m_background->setElementPrefix("shadow");
|
if (m_background->hasElementPrefix(m_testPrefix)) {
|
||||||
m_background->resizeFrame(event->newSize());
|
m_background->setElementPrefix(m_customPrefix % "shadow");
|
||||||
m_background->setElementPrefix("hover");
|
m_background->resizeFrame(size());
|
||||||
m_background->resizeFrame(event->newSize());
|
m_background->setElementPrefix(m_customPrefix % "hover");
|
||||||
m_background->setElementPrefix("focus");
|
m_background->resizeFrame(size());
|
||||||
m_background->resizeFrame(event->newSize());
|
m_background->setElementPrefix(m_customPrefix % "focus");
|
||||||
|
m_background->resizeFrame(size());
|
||||||
|
}
|
||||||
|
|
||||||
if (m_hoverAnimation->state() == QAbstractAnimation::Running) {
|
if (m_hoverAnimation->state() == QAbstractAnimation::Running) {
|
||||||
m_hoverAnimation->stop();
|
m_hoverAnimation->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_background->setElementPrefix(m_prefix);
|
if (m_background->hasElementPrefix(m_testPrefix)) {
|
||||||
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
m_background->setElementPrefix(m_prefix);
|
||||||
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
|
||||||
|
} else if (m_background->hasElement(m_testPrefix)) {
|
||||||
|
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_prefix));
|
||||||
|
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_prefix));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FocusIndicator::animateVisibility(const bool visible)
|
void FocusIndicator::animateVisibility(const bool visible)
|
||||||
@ -186,15 +246,15 @@ void FocusIndicator::syncGeometry()
|
|||||||
geom = m_parent->boundingRect();
|
geom = m_parent->boundingRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_background->hasElementPrefix(m_prefix)) {
|
if (m_background->hasElementPrefix(m_testPrefix)) {
|
||||||
//always take borders from hover to make it stable
|
//always take borders from hover to make it stable
|
||||||
m_background->setElementPrefix("hover");
|
m_background->setElementPrefix(m_testPrefix);
|
||||||
qreal left, top, right, bottom;
|
qreal left, top, right, bottom;
|
||||||
m_background->getMargins(left, top, right, bottom);
|
m_background->getMargins(left, top, right, bottom);
|
||||||
m_background->setElementPrefix(m_prefix);
|
m_background->setElementPrefix(m_prefix);
|
||||||
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom)));
|
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom)));
|
||||||
} else if (m_background->hasElement(m_prefix)) {
|
} else if (m_background->hasElement(m_testPrefix)) {
|
||||||
QRectF elementRect = m_background->elementRect(m_prefix);
|
QRectF elementRect = m_background->elementRect(m_testPrefix);
|
||||||
elementRect.moveCenter(geom.center());
|
elementRect.moveCenter(geom.center());
|
||||||
setGeometry(elementRect);
|
setGeometry(elementRect);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user