[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/plasma/private
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2010-09-22 8:55:29
Message-ID: 20100922090101.58CEAAC888 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1178168 by aseigo:
* 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
M +90 -30 focusindicator.cpp
--- trunk/KDE/kdelibs/plasma/private/focusindicator.cpp #1178167:1178168
@@ -21,6 +21,7 @@
#include <QGraphicsSceneResizeEvent>
#include <QPainter>
+#include <QStringBuilder>
#include <QStyleOptionGraphicsItem>
#include <plasma/theme.h>
@@ -31,18 +32,30 @@
namespace Plasma
{
-FocusIndicator::FocusIndicator(QGraphicsWidget *parent, QString widget)
+FocusIndicator::FocusIndicator(QGraphicsWidget *parent, const QString &widget)
: QGraphicsWidget(parent),
m_parent(parent),
- m_background(0),
+ m_background(new Plasma::FrameSvg(this)),
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);
setAcceptsHoverEvents(true);
- m_background = new Plasma::FrameSvg(this);
- m_background->setImagePath(widget);
- m_background->setElementPrefix("hover");
m_background->setCacheAllRenderedFrames(true);
m_fade = Animator::create(Animator::FadeAnimation, this);
@@ -53,16 +66,15 @@
m_hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation);
m_hoverAnimation->setProperty("duration", 250);
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";
- syncGeometry();
- m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
}
parent->installEventFilter(this);
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), \
SLOT(syncGeometry()));
- syncGeometry();
}
FocusIndicator::~FocusIndicator()
@@ -79,9 +91,24 @@
void FocusIndicator::setCustomPrefix(const QString &prefix)
{
+ if (!m_prefix.isEmpty() && !m_customPrefix.isEmpty()) {
+ m_prefix.remove(m_customPrefix);
+ }
+
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)
{
if (static_cast<QGraphicsWidget *>(watched) != m_parent || !m_parent) {
@@ -95,65 +122,98 @@
}
if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverEnter) {
- m_prefix = m_customPrefix + "hover";
+ m_prefix = m_customPrefix % "hover";
syncGeometry();
m_hoverAnimation->stop();
- m_background->setElementPrefix("shadow");
+ if (m_background->hasElementPrefix(m_testPrefix)) {
+ m_background->setElementPrefix(m_customPrefix % "shadow");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
- m_background->setElementPrefix("hover");
+ 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();
} else if (!m_parent->hasFocus() && event->type() == \
QEvent::GraphicsSceneHoverLeave) {
- m_prefix = m_customPrefix + "shadow";
+ m_prefix = m_customPrefix % "shadow";
syncGeometry();
m_hoverAnimation->stop();
- m_background->setElementPrefix("hover");
+
+ if (m_background->hasElementPrefix(m_testPrefix)) {
+ m_background->setElementPrefix(m_customPrefix % "hover");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
- m_background->setElementPrefix("shadow");
+ 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();
} else if (event->type() == QEvent::GraphicsSceneResize) {
syncGeometry();
} else if (event->type() == QEvent::FocusIn) {
- m_prefix = m_customPrefix + "focus";
+ m_prefix = m_customPrefix % "focus";
syncGeometry();
m_hoverAnimation->stop();
+
+ if (m_background->hasElementPrefix(m_customPrefix % "focus")) {
+ //m_background->setElementPrefix(m_customPrefix % "shadow");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
- m_background->setElementPrefix("focus");
+ 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";
+ 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();
}
return false;
}
-void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *event)
+void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *)
{
- m_background->setElementPrefix("shadow");
- m_background->resizeFrame(event->newSize());
- m_background->setElementPrefix("hover");
- m_background->resizeFrame(event->newSize());
- m_background->setElementPrefix("focus");
- m_background->resizeFrame(event->newSize());
+ if (m_background->hasElementPrefix(m_testPrefix)) {
+ m_background->setElementPrefix(m_customPrefix % "shadow");
+ m_background->resizeFrame(size());
+ m_background->setElementPrefix(m_customPrefix % "hover");
+ m_background->resizeFrame(size());
+ m_background->setElementPrefix(m_customPrefix % "focus");
+ m_background->resizeFrame(size());
+ }
if (m_hoverAnimation->state() == QAbstractAnimation::Running) {
m_hoverAnimation->stop();
}
+ if (m_background->hasElementPrefix(m_testPrefix)) {
m_background->setElementPrefix(m_prefix);
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)
{
@@ -186,15 +246,15 @@
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
- m_background->setElementPrefix("hover");
+ m_background->setElementPrefix(m_testPrefix);
qreal left, top, right, bottom;
m_background->getMargins(left, top, right, bottom);
m_background->setElementPrefix(m_prefix);
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + \
QSize(left+right, top+bottom)));
- } else if (m_background->hasElement(m_prefix)) {
- QRectF elementRect = m_background->elementRect(m_prefix);
+ } else if (m_background->hasElement(m_testPrefix)) {
+ QRectF elementRect = m_background->elementRect(m_testPrefix);
elementRect.moveCenter(geom.center());
setGeometry(elementRect);
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic