migrate focusindicator to the new api
change the api of fade to be abe to set a start and an end taget opacities svn path=/trunk/KDE/kdelibs/; revision=1039087
This commit is contained in:
parent
71528727ea
commit
03bb063c62
@ -29,7 +29,8 @@ namespace Plasma
|
||||
|
||||
FadeAnimation::FadeAnimation(QObject *parent)
|
||||
: Animation(parent),
|
||||
m_animFactor(0.5)
|
||||
m_startOpacity(0),
|
||||
m_targetOpacity(1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -37,14 +38,24 @@ FadeAnimation::~FadeAnimation()
|
||||
{
|
||||
}
|
||||
|
||||
void FadeAnimation::setFactor(qreal factor)
|
||||
void FadeAnimation::setStartOpacity(qreal factor)
|
||||
{
|
||||
m_animFactor = qBound(qreal(0.0), factor, qreal(1.0));
|
||||
m_startOpacity = qBound(qreal(0.0), factor, qreal(1.0));
|
||||
}
|
||||
|
||||
qreal FadeAnimation::factor() const
|
||||
qreal FadeAnimation::startOpacity() const
|
||||
{
|
||||
return m_animFactor;
|
||||
return m_startOpacity;
|
||||
}
|
||||
|
||||
void FadeAnimation::setTargetOpacity(qreal factor)
|
||||
{
|
||||
m_targetOpacity = qBound(qreal(0.0), factor, qreal(1.0));
|
||||
}
|
||||
|
||||
qreal FadeAnimation::targetOpacity() const
|
||||
{
|
||||
return m_targetOpacity;
|
||||
}
|
||||
|
||||
void FadeAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
|
||||
@ -56,7 +67,7 @@ void FadeAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
|
||||
|
||||
if (widget) {
|
||||
effect = new QGraphicsOpacityEffect(widget);
|
||||
effect->setOpacity(qreal(1.0));
|
||||
effect->setOpacity(m_startOpacity);
|
||||
widget->setGraphicsEffect(effect);
|
||||
m_opacityEffect = effect;
|
||||
}
|
||||
@ -66,8 +77,8 @@ QAbstractAnimation* FadeAnimation::render(QObject* parent)
|
||||
{
|
||||
//create animation
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(m_opacityEffect.data(), "opacity", parent);
|
||||
anim->setStartValue(qreal(1.0));
|
||||
anim->setEndValue(m_animFactor);
|
||||
anim->setStartValue(m_startOpacity);
|
||||
anim->setEndValue(m_targetOpacity);
|
||||
anim->setDuration(duration());
|
||||
|
||||
return anim;
|
||||
|
@ -43,14 +43,18 @@ class FadeAnimationPrivate;
|
||||
class FadeAnimation : public Animation
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal factor READ factor WRITE setFactor)
|
||||
Q_PROPERTY(qreal startOpacity READ startOpacity WRITE setStartOpacity)
|
||||
Q_PROPERTY(qreal targetOpacity READ targetOpacity WRITE setTargetOpacity)
|
||||
|
||||
public:
|
||||
FadeAnimation(QObject *parent = 0);
|
||||
virtual ~FadeAnimation();
|
||||
|
||||
qreal factor() const;
|
||||
void setFactor(qreal);
|
||||
qreal startOpacity() const;
|
||||
void setStartOpacity(qreal);
|
||||
|
||||
qreal targetOpacity() const;
|
||||
void setTargetOpacity(qreal);
|
||||
|
||||
void setWidgetToAnimate(QGraphicsWidget *widget);
|
||||
|
||||
@ -59,7 +63,8 @@ protected:
|
||||
|
||||
private:
|
||||
QWeakPointer<QGraphicsOpacityEffect> m_opacityEffect;
|
||||
qreal m_animFactor;
|
||||
qreal m_startOpacity;
|
||||
qreal m_targetOpacity;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -23,29 +23,29 @@
|
||||
|
||||
#include <plasma/theme.h>
|
||||
#include <plasma/framesvg.h>
|
||||
#include <plasma/animations/fade.h>
|
||||
|
||||
#include <plasma/animator.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
FocusIndicator::FocusIndicator(QGraphicsWidget *parent)
|
||||
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, QString widget)
|
||||
: QGraphicsWidget(parent),
|
||||
m_parent(parent)
|
||||
m_parent(parent),
|
||||
m_background(0)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemStacksBehindParent);
|
||||
setAcceptsHoverEvents(true);
|
||||
|
||||
m_background = new Plasma::FrameSvg(this);
|
||||
m_background->setImagePath("widgets/lineedit");
|
||||
m_background->setImagePath(widget);
|
||||
m_background->setElementPrefix("hover");
|
||||
m_background->setCacheAllRenderedFrames(true);
|
||||
|
||||
m_fadeIn = new FadeAnimation();
|
||||
m_fadeIn->setFactor(1.0);
|
||||
m_fadeIn->setWidgetToAnimate(this);
|
||||
m_fadeOut = new FadeAnimation();
|
||||
m_fadeOut->setFactor(0);
|
||||
m_fadeOut->setWidgetToAnimate(this);
|
||||
setOpacity(0);
|
||||
m_fade = Animator::create(Animator::FadeAnimation, this);
|
||||
m_fade->setWidgetToAnimate(this);
|
||||
m_fade->setProperty("startOpacity", 0.0);
|
||||
m_fade->setProperty("targetOpacity", 1.0);
|
||||
|
||||
parent->installEventFilter(this);
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncGeometry()));
|
||||
@ -54,8 +54,7 @@ FocusIndicator::FocusIndicator(QGraphicsWidget *parent)
|
||||
|
||||
FocusIndicator::~FocusIndicator()
|
||||
{
|
||||
delete m_fadeIn;
|
||||
delete m_fadeOut;
|
||||
delete m_fade;
|
||||
}
|
||||
|
||||
void FocusIndicator::setCustomGeometry(const QRectF &geometry)
|
||||
@ -72,16 +71,24 @@ bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
|
||||
|
||||
if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverEnter) {
|
||||
m_background->setElementPrefix("hover");
|
||||
m_fadeIn->start();
|
||||
m_fade->setProperty("startOpacity", 0.0);
|
||||
m_fade->setProperty("targetOpacity", 1.0);
|
||||
m_fade->start();
|
||||
} else if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverLeave) {
|
||||
m_fadeOut->start();
|
||||
m_fade->setProperty("startOpacity", 1.0);
|
||||
m_fade->setProperty("targetOpacity", 0.0);
|
||||
m_fade->start();
|
||||
} else if (event->type() == QEvent::GraphicsSceneResize) {
|
||||
syncGeometry();
|
||||
} else if (event->type() == QEvent::FocusIn) {
|
||||
m_background->setElementPrefix("focus");
|
||||
m_fadeIn->start();
|
||||
m_fade->setProperty("startOpacity", 0.0);
|
||||
m_fade->setProperty("targetOpacity", 1.0);
|
||||
m_fade->start();
|
||||
} else if (!m_parent->isUnderMouse() && event->type() == QEvent::FocusOut) {
|
||||
m_fadeOut->start();
|
||||
m_fade->setProperty("startOpacity", 1.0);
|
||||
m_fade->setProperty("targetOpacity", 0.0);
|
||||
m_fade->start();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -94,8 +101,6 @@ void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
|
||||
void FocusIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
m_background->paintFrame(painter);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
#include <plasma/animations/abstractanimation.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class FrameSvg;
|
||||
@ -31,7 +33,7 @@ class FocusIndicator : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FocusIndicator(QGraphicsWidget *parent);
|
||||
FocusIndicator(QGraphicsWidget *parent = 0, QString widget = "widgets/lineedit");
|
||||
~FocusIndicator();
|
||||
|
||||
void setCustomGeometry(const QRectF &geometry);
|
||||
@ -48,8 +50,7 @@ private Q_SLOTS:
|
||||
private:
|
||||
QGraphicsWidget *m_parent;
|
||||
Plasma::FrameSvg *m_background;
|
||||
FadeAnimation *m_fadeIn;
|
||||
FadeAnimation *m_fadeOut;
|
||||
AbstractAnimation *m_fade;
|
||||
QRectF m_customGeometry;
|
||||
};
|
||||
}
|
||||
|
@ -75,12 +75,13 @@ LineEdit::LineEdit(QGraphicsWidget *parent)
|
||||
: QGraphicsProxyWidget(parent),
|
||||
d(new LineEditPrivate(this))
|
||||
{
|
||||
FocusIndicator *focusIndicator = new FocusIndicator(this);
|
||||
d->style = Plasma::Style::sharedStyle();
|
||||
d->background = new Plasma::FrameSvg(this);
|
||||
d->background->setImagePath("widgets/lineedit");
|
||||
d->background->setCacheAllRenderedFrames(true);
|
||||
|
||||
FocusIndicator *focusIndicator = new FocusIndicator(this, "widgets/lineedit");
|
||||
|
||||
setNativeWidget(new KLineEdit);
|
||||
|
||||
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
|
||||
|
@ -40,6 +40,7 @@ class SpinBoxPrivate
|
||||
public:
|
||||
SpinBoxPrivate(SpinBox *spinBox)
|
||||
: q(spinBox),
|
||||
focusIndicator(0),
|
||||
customFont(false)
|
||||
{
|
||||
}
|
||||
@ -80,11 +81,11 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
|
||||
{
|
||||
KIntSpinBox *native = new KIntSpinBox;
|
||||
|
||||
d->focusIndicator = new FocusIndicator(this);
|
||||
|
||||
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
|
||||
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
|
||||
|
||||
d->focusIndicator = new FocusIndicator(this, "widgets/lineedit");
|
||||
|
||||
setWidget(native);
|
||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||
native->setAutoFillBackground(false);
|
||||
@ -93,6 +94,7 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
|
||||
d->background->setImagePath("widgets/lineedit");
|
||||
d->background->setCacheAllRenderedFrames(true);
|
||||
|
||||
|
||||
d->style = Plasma::Style::sharedStyle();
|
||||
native->setStyle(d->style.data());
|
||||
d->setPalette();
|
||||
@ -182,7 +184,9 @@ void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
QStyleOptionSpinBox spinOpt;
|
||||
spinOpt.initFrom(nativeWidget());
|
||||
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
|
||||
d->focusIndicator->setCustomGeometry(controlrect);
|
||||
if (d->focusIndicator) {
|
||||
d->focusIndicator->setCustomGeometry(controlrect);
|
||||
}
|
||||
}
|
||||
|
||||
void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
|
Loading…
Reference in New Issue
Block a user