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