Remove AnimationData wrapper around metadata.

Instead allow to set metadata directly in animation
objects

REVIEW: 122679
This commit is contained in:
Thomas Lübking 2015-03-29 00:15:22 +01:00
parent c5bb84469d
commit 060f3e9403
2 changed files with 32 additions and 172 deletions

View file

@ -35,9 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
typedef KWin::EffectWindow* KEffectWindowRef;
Q_DECLARE_METATYPE(KWin::AnimationData*)
Q_SCRIPT_DECLARE_QMETAOBJECT(KWin::AnimationData, QObject*)
namespace KWin
{
@ -100,12 +97,14 @@ struct AnimationSettings {
int delay;
uint duration;
uint set;
uint metaData;
};
AnimationSettings animationSettingsFromObject(QScriptValue &object)
{
AnimationSettings settings;
settings.set = 0;
settings.metaData = 0;
settings.to = qscriptvalue_cast<FPx2>(object.property(QStringLiteral("to")));
settings.from = qscriptvalue_cast<FPx2>(object.property(QStringLiteral("from")));
@ -205,6 +204,27 @@ QList<AnimationSettings> animationSettings(QScriptContext *context, ScriptedEffe
if (!(s.set & AnimationSettings::Delay)) {
s.delay = settings.at(0).delay;
}
s.metaData = 0;
typedef QMap<AnimationEffect::MetaType, QString> MetaTypeMap;
static MetaTypeMap metaTypes({
{AnimationEffect::SourceAnchor, QStringLiteral("sourceAnchor")},
{AnimationEffect::TargetAnchor, QStringLiteral("targetAnchor")},
{AnimationEffect::RelativeSourceX, QStringLiteral("relativeSourceX")},
{AnimationEffect::RelativeSourceY, QStringLiteral("relativeSourceY")},
{AnimationEffect::RelativeTargetX, QStringLiteral("relativeTargetX")},
{AnimationEffect::RelativeTargetY, QStringLiteral("relativeTargetY")},
{AnimationEffect::Axis, QStringLiteral("axis")}
});
for (MetaTypeMap::const_iterator it = metaTypes.constBegin(),
end = metaTypes.constEnd(); it != end; ++it) {
QScriptValue metaVal = value.property(*it);
if (metaVal.isValid() && metaVal.isNumber()) {
AnimationEffect::setMetaData(it.key(), metaVal.toInt32(), s.metaData);
}
}
settings << s;
}
}
@ -248,7 +268,7 @@ QScriptValue kwinEffectAnimate(QScriptContext *context, QScriptEngine *engine)
setting.duration,
setting.to,
setting.from,
nullptr,
setting.metaData,
setting.curve,
setting.delay));
}
@ -277,7 +297,7 @@ QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine)
setting.duration,
setting.to,
setting.from,
nullptr,
setting.metaData,
setting.curve,
setting.delay));
}
@ -433,7 +453,6 @@ bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript
#endif
m_engine->globalObject().setProperty(QStringLiteral("QEasingCurve"), m_engine->newQMetaObject(&QEasingCurve::staticMetaObject));
m_engine->globalObject().setProperty(QStringLiteral("effect"), m_engine->newQObject(this, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater), QScriptValue::Undeletable);
m_engine->globalObject().setProperty(QStringLiteral("AnimationData"), m_engine->scriptValueFromQMetaObject<AnimationData>());
MetaScripting::registration(m_engine);
qScriptRegisterMetaType<KEffectWindowRef>(m_engine, effectWindowToScriptValue, effectWindowFromScriptValue);
qScriptRegisterMetaType<KWin::FPx2>(m_engine, fpx2ToScriptValue, fpx2FromScriptValue);
@ -493,43 +512,14 @@ void ScriptedEffect::signalHandlerException(const QScriptValue &value)
}
}
uint metaFromData(KWin::AnimationData* data)
quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, QEasingCurve::Type 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);
}
}
return meta;
return AnimationEffect::animate(w, a, metaData, ms, to, QEasingCurve(curve), delay, from);
}
quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, KWin::AnimationData* data, QEasingCurve::Type curve, int delay)
quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, QEasingCurve::Type curve, int delay)
{
return AnimationEffect::animate(w, a, metaFromData(data), ms, to, QEasingCurve(curve), delay, from);
}
quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, KWin::AnimationData* data, QEasingCurve::Type curve, int delay)
{
return AnimationEffect::set(w, a, metaFromData(data), ms, to, QEasingCurve(curve), delay, from);
return AnimationEffect::set(w, a, metaData, ms, to, QEasingCurve(curve), delay, from);
}
bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole)
@ -576,86 +566,4 @@ QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultVa
return m_config->property(key);
}
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

View file

@ -30,59 +30,11 @@ 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 = nullptr);
// 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(Qt::Axis)
Q_ENUMS(Anchor)
Q_ENUMS(MetaType)
public:
@ -135,8 +87,8 @@ public:
}
public Q_SLOTS:
quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), KWin::AnimationData *data = nullptr, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
quint64 set(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), KWin::AnimationData *data = nullptr, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
quint64 set(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
bool cancel(quint64 animationId) { return AnimationEffect::cancel(animationId); }
virtual bool borderActivated(ElectricBorder border);