Fix segfault at plasma_applet_animation_example from kdeexample
Patch-by: Andre L. V. Loureiro <loureiro.andrew@gmail.com> svn path=/branches/KDE/4.4/kdelibs/; revision=1082153
This commit is contained in:
parent
2986feb951
commit
c85fbed752
@ -32,12 +32,12 @@ RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
|
|||||||
{
|
{
|
||||||
m_backRotation = new QGraphicsRotation(this);
|
m_backRotation = new QGraphicsRotation(this);
|
||||||
m_frontRotation = new QGraphicsRotation(this);
|
m_frontRotation = new QGraphicsRotation(this);
|
||||||
m_sLayout = new StackedLayout;
|
m_wLayout = new StackedLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
RotationStackedAnimation::~RotationStackedAnimation()
|
RotationStackedAnimation::~RotationStackedAnimation()
|
||||||
{
|
{
|
||||||
delete m_sLayout;
|
delete m_wLayout.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotationStackedAnimation::setMovementDirection(const qint8 &direction)
|
void RotationStackedAnimation::setMovementDirection(const qint8 &direction)
|
||||||
@ -69,15 +69,17 @@ void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget)
|
|||||||
{
|
{
|
||||||
m_backWidget = backWidget;
|
m_backWidget = backWidget;
|
||||||
|
|
||||||
if(targetWidget()) {
|
StackedLayout *layout = m_wLayout.data();
|
||||||
m_sLayout->addWidget(targetWidget());
|
|
||||||
m_sLayout->addWidget(m_backWidget.data());
|
if(targetWidget() && backWidget && layout) {
|
||||||
|
layout->addWidget(targetWidget());
|
||||||
|
layout->addWidget(backWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsLayoutItem *RotationStackedAnimation::layout()
|
QGraphicsLayoutItem *RotationStackedAnimation::layout()
|
||||||
{
|
{
|
||||||
return m_sLayout;
|
return m_wLayout.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotationStackedAnimation::updateState(
|
void RotationStackedAnimation::updateState(
|
||||||
@ -141,19 +143,24 @@ void RotationStackedAnimation::updateState(
|
|||||||
|
|
||||||
void RotationStackedAnimation::updateCurrentTime(int currentTime)
|
void RotationStackedAnimation::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
|
StackedLayout *layout = m_wLayout.data();
|
||||||
|
if (!layout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QGraphicsWidget *w = targetWidget();
|
QGraphicsWidget *w = targetWidget();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta;
|
qreal delta;
|
||||||
if (currentTime <= duration()/2) {
|
if (currentTime <= duration()/2) {
|
||||||
delta = Animation::easingCurve().valueForProgress(
|
delta = Animation::easingCurve().valueForProgress(
|
||||||
(currentTime * 2) / qreal(duration()));
|
(currentTime * 2) / qreal(duration()));
|
||||||
m_sLayout->setCurrentWidgetIndex(0);
|
layout->setCurrentWidgetIndex(0);
|
||||||
delta = m_frontEndAngle * delta;
|
delta = m_frontEndAngle * delta;
|
||||||
m_frontRotation->setAngle(delta);
|
m_frontRotation->setAngle(delta);
|
||||||
} else {
|
} else {
|
||||||
delta = Animation::easingCurve().valueForProgress(
|
delta = Animation::easingCurve().valueForProgress(
|
||||||
(currentTime/2) / qreal(duration()));
|
(currentTime/2) / qreal(duration()));
|
||||||
m_sLayout->setCurrentWidgetIndex(1);
|
layout->setCurrentWidgetIndex(1);
|
||||||
delta = m_backEndAngle * delta;
|
delta = m_backEndAngle * delta;
|
||||||
m_backRotation->setAngle(delta);
|
m_backRotation->setAngle(delta);
|
||||||
}
|
}
|
||||||
|
@ -115,13 +115,12 @@ private:
|
|||||||
int m_backEndAngle;
|
int m_backEndAngle;
|
||||||
/** Object the animation(s) should act upon. */
|
/** Object the animation(s) should act upon. */
|
||||||
QWeakPointer<QGraphicsWidget> m_backWidget;
|
QWeakPointer<QGraphicsWidget> m_backWidget;
|
||||||
|
/** Layout where widget would be added */
|
||||||
|
QWeakPointer<StackedLayout> m_wLayout;
|
||||||
/** Back Widget Rotation transform object */
|
/** Back Widget Rotation transform object */
|
||||||
QGraphicsRotation *m_backRotation;
|
QGraphicsRotation *m_backRotation;
|
||||||
/** Front Widget Rotation transform object */
|
/** Front Widget Rotation transform object */
|
||||||
QGraphicsRotation *m_frontRotation;
|
QGraphicsRotation *m_frontRotation;
|
||||||
/** rotation stacked layout where the widget would be added */
|
|
||||||
StackedLayout *m_sLayout;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // Plasma
|
} // Plasma
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
StackedLayout::StackedLayout(QGraphicsLayoutItem *parent)
|
StackedLayout::StackedLayout(QGraphicsLayoutItem *parent)
|
||||||
: QGraphicsLayout(parent), m_currentWidgetIndex(-1)
|
: QObject(0), m_currentWidgetIndex(-1), QGraphicsLayout(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,11 @@
|
|||||||
|
|
||||||
#include <QGraphicsLayout>
|
#include <QGraphicsLayout>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class StackedLayout : public QGraphicsLayout {
|
class StackedLayout : public QObject, public QGraphicsLayout
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit StackedLayout(QGraphicsLayoutItem *parent = 0);
|
explicit StackedLayout(QGraphicsLayoutItem *parent = 0);
|
||||||
~StackedLayout();
|
~StackedLayout();
|
||||||
|
Loading…
Reference in New Issue
Block a user