Add an AnimationData class for meta values
Objects of AnimationData can be instantiated by scripts and expose all relevant data as properties, so that the ScriptedEffect can construct the meta value out of it. This is probably something that could be done a little bit better. Still need to think about it, so API not yet final. REVIEW: 103823
This commit is contained in:
parent
6baafd28cd
commit
4e0ab36ae9
2 changed files with 162 additions and 2 deletions
|
@ -30,6 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QtScript/QScriptValueIterator>
|
||||
|
||||
typedef KWin::EffectWindow* KEffectWindowRef;
|
||||
|
||||
Q_DECLARE_METATYPE(KWin::AnimationData*)
|
||||
Q_SCRIPT_DECLARE_QMETAOBJECT(KWin::AnimationData, QObject*)
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
|
@ -146,6 +150,7 @@ bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript
|
|||
m_engine->globalObject().setProperty("effects", effectsObject, QScriptValue::Undeletable);
|
||||
m_engine->globalObject().setProperty("Effect", m_engine->newQMetaObject(&ScriptedEffect::staticMetaObject));
|
||||
m_engine->globalObject().setProperty("effect", m_engine->newQObject(this, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater), QScriptValue::Undeletable);
|
||||
m_engine->globalObject().setProperty("AnimationData", m_engine->scriptValueFromQMetaObject<AnimationData>());
|
||||
MetaScripting::registration(m_engine);
|
||||
qScriptRegisterMetaType<KEffectWindowRef>(m_engine, effectWindowToScriptValue, effectWindowFromScriptValue);
|
||||
qScriptRegisterMetaType<KWin::FPx2>(m_engine, fpx2ToScriptValue, fpx2FromScriptValue);
|
||||
|
@ -188,8 +193,32 @@ void ScriptedEffect::signalHandlerException(const QScriptValue &value)
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptedEffect::animate(EffectWindow* w, AnimationEffect::Attribute a, int ms, FPx2 to, FPx2 from, uint meta, QEasingCurve curve, int delay)
|
||||
void ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, KWin::AnimationData* data, QEasingCurve curve, int delay)
|
||||
{
|
||||
uint meta = 0;
|
||||
if (data) {
|
||||
if (data->axis() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::Axis, data->axis() -1, meta);
|
||||
}
|
||||
if (data->sourceAnchor() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::SourceAnchor, data->sourceAnchor(), meta);
|
||||
}
|
||||
if (data->targetAnchor() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::TargetAnchor, data->targetAnchor(), meta);
|
||||
}
|
||||
if (data->relativeSourceX() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::RelativeSourceX, data->relativeSourceX(), meta);
|
||||
}
|
||||
if (data->relativeSourceY() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::RelativeSourceY, data->relativeSourceY(), meta);
|
||||
}
|
||||
if (data->relativeTargetX() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::RelativeTargetX, data->relativeTargetX(), meta);
|
||||
}
|
||||
if (data->relativeTargetY() != 0) {
|
||||
AnimationEffect::setMetaData(AnimationEffect::RelativeTargetY, data->relativeTargetY(), meta);
|
||||
}
|
||||
}
|
||||
AnimationEffect::animate(w, a, meta, ms, to, curve, delay, from);
|
||||
}
|
||||
|
||||
|
@ -215,4 +244,86 @@ QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultVa
|
|||
return cg.readEntry(key, defaultValue);
|
||||
}
|
||||
|
||||
AnimationData::AnimationData (QObject* parent)
|
||||
: QObject (parent)
|
||||
, m_sourceAnchor((AnimationEffect::Anchor)0)
|
||||
, m_targetAnchor((AnimationEffect::Anchor)0)
|
||||
, m_relativeSourceX(0)
|
||||
, m_relativeSourceY(0)
|
||||
, m_relativeTargetX(0)
|
||||
, m_relativeTargetY(0)
|
||||
, m_axis((AnimationData::Axis)0)
|
||||
{
|
||||
}
|
||||
|
||||
AnimationData::Axis AnimationData::axis() const
|
||||
{
|
||||
return m_axis;
|
||||
}
|
||||
|
||||
int AnimationData::relativeSourceX() const
|
||||
{
|
||||
return m_relativeSourceX;
|
||||
}
|
||||
|
||||
int AnimationData::relativeSourceY() const
|
||||
{
|
||||
return m_relativeSourceY;
|
||||
}
|
||||
|
||||
int AnimationData::relativeTargetX() const
|
||||
{
|
||||
return m_relativeTargetX;
|
||||
}
|
||||
|
||||
int AnimationData::relativeTargetY() const
|
||||
{
|
||||
return m_relativeTargetY;
|
||||
}
|
||||
|
||||
void AnimationData::setRelativeSourceX(int relativeSourceX)
|
||||
{
|
||||
m_relativeSourceX = relativeSourceX;
|
||||
}
|
||||
|
||||
void AnimationData::setRelativeSourceY(int relativeSourceY)
|
||||
{
|
||||
m_relativeSourceY = relativeSourceY;
|
||||
}
|
||||
|
||||
void AnimationData::setRelativeTargetX(int relativeTargetX)
|
||||
{
|
||||
m_relativeTargetX = relativeTargetX;
|
||||
}
|
||||
|
||||
void AnimationData::setRelativeTargetY(int relativeTargetY)
|
||||
{
|
||||
m_relativeTargetY = relativeTargetY;
|
||||
}
|
||||
|
||||
void AnimationData::setAxis(AnimationData::Axis axis)
|
||||
{
|
||||
m_axis = axis;
|
||||
}
|
||||
|
||||
void AnimationData::setSourceAnchor(AnimationEffect::Anchor sourceAnchor)
|
||||
{
|
||||
m_sourceAnchor = sourceAnchor;
|
||||
}
|
||||
|
||||
void AnimationData::setTargetAnchor(AnimationEffect::Anchor targetAnchor)
|
||||
{
|
||||
m_targetAnchor = targetAnchor;
|
||||
}
|
||||
|
||||
AnimationEffect::Anchor AnimationData::sourceAnchor() const
|
||||
{
|
||||
return m_sourceAnchor;
|
||||
}
|
||||
|
||||
AnimationEffect::Anchor AnimationData::targetAnchor() const
|
||||
{
|
||||
return m_targetAnchor;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -28,11 +28,60 @@ class QScriptValue;
|
|||
|
||||
namespace KWin
|
||||
{
|
||||
class ScriptedEffect;
|
||||
class AnimationData : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Axis)
|
||||
Q_PROPERTY(KWin::AnimationEffect::Anchor sourceAnchor READ sourceAnchor WRITE setSourceAnchor)
|
||||
Q_PROPERTY(KWin::AnimationEffect::Anchor targetAnchor READ targetAnchor WRITE setTargetAnchor)
|
||||
Q_PROPERTY(int relativeSourceX READ relativeSourceX WRITE setRelativeSourceX)
|
||||
Q_PROPERTY(int relativeSourceY READ relativeSourceY WRITE setRelativeSourceY)
|
||||
Q_PROPERTY(int relativeTargetX READ relativeTargetX WRITE setRelativeTargetX)
|
||||
Q_PROPERTY(int relativeTargetY READ relativeTargetY WRITE setRelativeTargetY)
|
||||
Q_PROPERTY(Axis axis READ axis WRITE setAxis)
|
||||
public:
|
||||
enum Axis {
|
||||
XAxis = 1,
|
||||
YAxis,
|
||||
ZAxis
|
||||
};
|
||||
explicit AnimationData(QObject* parent = 0);
|
||||
|
||||
// getter
|
||||
AnimationEffect::Anchor sourceAnchor() const;
|
||||
AnimationEffect::Anchor targetAnchor() const;
|
||||
int relativeSourceX() const;
|
||||
int relativeSourceY() const;
|
||||
int relativeTargetX() const;
|
||||
int relativeTargetY() const;
|
||||
Axis axis() const;
|
||||
|
||||
// setter
|
||||
void setSourceAnchor(AnimationEffect::Anchor sourceAnchor);
|
||||
void setTargetAnchor(AnimationEffect::Anchor targetAnchor);
|
||||
void setRelativeSourceX(int relativeSourceX);
|
||||
void setRelativeSourceY(int relativeSourceY);
|
||||
void setRelativeTargetX(int relativeTargetX);
|
||||
void setRelativeTargetY(int relativeTargetY);
|
||||
void setAxis(Axis axis);
|
||||
|
||||
private:
|
||||
AnimationEffect::Anchor m_sourceAnchor;
|
||||
AnimationEffect::Anchor m_targetAnchor;
|
||||
int m_relativeSourceX;
|
||||
int m_relativeSourceY;
|
||||
int m_relativeTargetX;
|
||||
int m_relativeTargetY;
|
||||
Axis m_axis;
|
||||
};
|
||||
|
||||
class ScriptedEffect : public KWin::AnimationEffect
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(DataRole)
|
||||
Q_ENUMS(KWin::AnimationData::Axis)
|
||||
Q_ENUMS(Anchor)
|
||||
Q_ENUMS(MetaType)
|
||||
public:
|
||||
// copied from kwineffects.h
|
||||
|
@ -70,7 +119,7 @@ public:
|
|||
Q_SCRIPTABLE QVariant readConfig(const QString &key, const QVariant defaultValue = QVariant());
|
||||
|
||||
public Q_SLOTS:
|
||||
void animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint meta = 0, QEasingCurve curve = QEasingCurve(), int delay = 0);
|
||||
void animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), KWin::AnimationData *data = NULL, QEasingCurve curve = QEasingCurve(), int delay = 0);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue