[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin/scripting2] scripting: ASDFA ASDFASDFEWRWER
From:       David Edmundson <null () kde ! org>
Date:       2018-07-31 21:37:18
Message-ID: E1fkcKU-0001yG-RK () code ! kde ! org
[Download RAW message or body]

Git commit a8393c8b8249262317593d02ac959c9dc4bab565 by David Edmundson.
Committed on 31/07/2018 at 20:28.
Pushed by davidedmundson into branch 'scripting2'.

ASDFA ASDFASDFEWRWER

M  +104  -109  scripting/scriptedeffect.cpp
M  +6    -2    scripting/scriptedeffect.h

https://commits.kde.org/kwin/a8393c8b8249262317593d02ac959c9dc4bab565

diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp
index 1a2e9109b..a642b7717 100644
--- a/scripting/scriptedeffect.cpp
+++ b/scripting/scriptedeffect.cpp
@@ -103,108 +103,95 @@ AnimationSettings animationSettingsFromObject(QJSValue \
&object)  //takes exactly one argument, an object
 //returns list of animations and the effect window
 
-//QList<AnimationSettings> animationSettings(QScriptContext *context, ScriptedEffect \
                *effect, EffectWindow **window)
-//{
-//    QList<AnimationSettings> settings;
-//    if (!effect) {
-//        context->throwError(QScriptContext::ReferenceError, \
                QStringLiteral("Internal Scripted KWin Effect error"));
-//        return settings;
-//    }
-//    if (context->argumentCount() != 1) {
-//        context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly \
                one argument expected"));
-//        return settings;
-//    }
-//    if (!context->argument(0).isObject()) {
-//        context->throwError(QScriptContext::TypeError, QStringLiteral("Argument \
                needs to be an object"));
-//        return settings;
-//    }
-//    QJSValue object = context->argument(0);
-//    QJSValue windowProperty = object.property(QStringLiteral("window"));
-//    if (!windowProperty.isValid() || !windowProperty.isObject()) {
+QList<AnimationSettings> animationSettings(const QJSValue& object EffectWindow \
**window) +{
+   QList<AnimationSettings> settings;
+   QJSValue windowProperty = object.property(QStringLiteral("window"));
+   if (!windowProperty.isValid() || !windowProperty.isObject()) {
 //        context->throwError(QScriptContext::TypeError, QStringLiteral("Window \
                property missing in animation options"));
-//        return settings;
-//    }
-//    *window = qobject_cast<EffectWindow*>(windowProperty.toQObject());
-
-//    settings << animationSettingsFromObject(object); // global
-
-//    QJSValue animations = object.property(QStringLiteral("animations")); // array
-//    if (!animations.isNull()) {
-//        if (!animations.isArray()) {
-//            context->throwError(QScriptContext::TypeError, \
                QStringLiteral("Animations provided but not an array"));
-//            settings.clear();
-//            return settings;
-//        }
-//        const int length = \
                static_cast<int>(animations.property(QStringLiteral("length")).toInteger());
                
-//        for (int i=0; i<length; ++i) {
-//            QJSValue value = animations.property(QString::number(i));
-//            if (!value.isValid()) {
-//                continue;
-//            }
-//            if (value.isObject()) {
-//                AnimationSettings s = animationSettingsFromObject(value);
-//                const uint set = s.set | settings.at(0).set;
-//                // Catch show stoppers (incompletable animation)
-//                if (!(set & AnimationSettings::Type)) {
-//                    context->throwError(QScriptContext::TypeError, \
                QStringLiteral("Type property missing in animation options"));
-//                    continue;
-//                }
-//                if (!(set & AnimationSettings::Duration)) {
-//                    context->throwError(QScriptContext::TypeError, \
                QStringLiteral("Duration property missing in animation options"));
-//                    continue;
-//                }
-//                // Complete local animations from global settings
-//                if (!(s.set & AnimationSettings::Duration)) {
-//                    s.duration = settings.at(0).duration;
-//                }
-//                if (!(s.set & AnimationSettings::Curve)) {
-//                    s.curve = settings.at(0).curve;
-//                }
-//                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) {
-//                    QJSValue metaVal = value.property(*it);
-//                    if (metaVal.isNumber()) {
-//                        AnimationEffect::setMetaData(it.key(), metaVal.toInt(), \
                s.metaData);
-//                    }
-//                }
-
-//                settings << s;
-//            }
-//        }
-//    }
-
-//    if (settings.count() == 1) {
-//        const uint set = settings.at(0).set;
-//        if (!(set & AnimationSettings::Type)) {
-//            context->throwError(QScriptContext::TypeError, QStringLiteral("Type \
                property missing in animation options"));
-//            settings.clear();
-//        }
-//        if (!(set & AnimationSettings::Duration)) {
-//            context->throwError(QScriptContext::TypeError, \
                QStringLiteral("Duration property missing in animation options"));
-//            settings.clear();
-//        }
-//    } else if (!(settings.at(0).set & AnimationSettings::Type)) { // invalid \
                global
-//        settings.removeAt(0); // -> get rid of it, only used to complete the \
                others
-//    }
-
-//    return settings;
-//}
+       return settings;
+   }
+   *window = qobject_cast<EffectWindow*>(windowProperty.toQObject());
+
+   settings << animationSettingsFromObject(object); // global
+
+   QJSValue animations = object.property(QStringLiteral("animations")); // array
+   if (!animations.isNull()) {
+       if (!animations.isArray()) {
+           context->throwError(QScriptContext::TypeError, QStringLiteral("Animations \
provided but not an array")); +           settings.clear();
+           return settings;
+       }
+       const int length = \
static_cast<int>(animations.property(QStringLiteral("length")).toInteger()); +       \
for (int i=0; i<length; ++i) { +           QJSValue value = \
animations.property(QString::number(i)); +           if (!value.isValid()) {
+               continue;
+           }
+           if (value.isObject()) {
+               AnimationSettings s = animationSettingsFromObject(value);
+               const uint set = s.set | settings.at(0).set;
+               // Catch show stoppers (incompletable animation)
+               if (!(set & AnimationSettings::Type)) {
+                   context->throwError(QScriptContext::TypeError, \
QStringLiteral("Type property missing in animation options")); +                   \
continue; +               }
+               if (!(set & AnimationSettings::Duration)) {
+                   context->throwError(QScriptContext::TypeError, \
QStringLiteral("Duration property missing in animation options")); +                  \
continue; +               }
+               // Complete local animations from global settings
+               if (!(s.set & AnimationSettings::Duration)) {
+                   s.duration = settings.at(0).duration;
+               }
+               if (!(s.set & AnimationSettings::Curve)) {
+                   s.curve = settings.at(0).curve;
+               }
+               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) { +                   QJSValue metaVal = value.property(*it);
+                   if (metaVal.isNumber()) {
+                       AnimationEffect::setMetaData(it.key(), metaVal.toInt(), \
s.metaData); +                   }
+               }
+
+               settings << s;
+           }
+       }
+   }
+
+   if (settings.count() == 1) {
+       const uint set = settings.at(0).set;
+       if (!(set & AnimationSettings::Type)) {
+           context->throwError(QScriptContext::TypeError, QStringLiteral("Type \
property missing in animation options")); +           settings.clear();
+       }
+       if (!(set & AnimationSettings::Duration)) {
+           context->throwError(QScriptContext::TypeError, QStringLiteral("Duration \
property missing in animation options")); +           settings.clear();
+       }
+   } else if (!(settings.at(0).set & AnimationSettings::Type)) { // invalid global
+       settings.removeAt(0); // -> get rid of it, only used to complete the others
+   }
+
+   return settings;
+}
 
 QJSValue kwinEffectAnimate(QScriptContext *context, QJSEngine *engine)
 {
@@ -415,19 +402,13 @@ bool ScriptedEffect::init(const QString &effectName, const \
                QString &pathToScript
     engine()->globalObject().setProperty("registerTouchScreenEdge", \
                selfWrapper.property("registerTouchScreenEdge"));
     engine()->globalObject().setProperty("unregisterTouchScreenEdge", \
selfWrapper.property("unregisterTouchScreenEdge"));  
-//    engine()->globalObject().setProperty("animate", \
                selfWrapper.property("animateInternal"));
-//     engine()->globalObject().setProperty("set", \
selfWrapper.property("setInternal")); +    \
engine()->globalObject().setProperty("animate", \
selfWrapper.property("animateGlobal")); +    \
                engine()->globalObject().setProperty("set", \
                selfWrapper.property("setGlobal"));
     engine()->globalObject().setProperty("retarget", \
                selfWrapper.property("retarget"));
     engine()->globalObject().setProperty("cancel", selfWrapper.property("cancel"));
 
     engine()->globalObject().setProperty("print", selfWrapper.property("print"));
 
-
-//    MetaScripting::registration(m_engine);
-//    qScriptRegisterMetaType<KWin::FPx2>(m_engine, fpx2ToScriptValue, \
                fpx2FromScriptValue);
-//    qScriptRegisterSequenceMetaType<QList< KWin::EffectWindow* > >(m_engine);
-
-
     QJSValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll()));
 
     if (ret.isError()) {
@@ -522,6 +503,20 @@ bool ScriptedEffect::retarget(QList<quint64> animationIds, const \
QJSValue &newTa  return true;
 }
 
+QJSValue ScriptedEffect::animateGlobal(const QJSValue &args)
+{
+    return startAnimation(args, false);
+}
+
+QJSValue ScriptedEffect::setGlobal(const QJSValue &args)
+{
+    return startAnimation(args, true);
+}
+
+QJSValue startAnimation(const QJSValue &value, bool set)
+{
+}
+
 bool ScriptedEffect::cancel(quint64 animationId)
 {
     return AnimationEffect::cancel(animationId);
diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h
index eca4d61ed..a56ca6794 100644
--- a/scripting/scriptedeffect.h
+++ b/scripting/scriptedeffect.h
@@ -115,8 +115,10 @@ public Q_SLOTS:
     bool cancel(quint64 animationId);
     bool cancel(QList<quint64> animationIds);
 
-//     QJSValue animateInternal(const QJSValue &args) {}
-//     QJSValue setInternal(const QJSValue &args) {}
+    //takes a big object blob of data, returns an array of
+    //or throws an error
+    QJSValue animateGlobal(const QJSValue &args);
+    QJSValue setGlobal(const QJSValue &args);
 
     bool borderActivated(ElectricBorder border) override;
 
@@ -134,6 +136,8 @@ protected:
     void animationEnded(KWin::EffectWindow *w, Attribute a, uint meta);
 
 private:
+    //wrapper round animateGlobal/setGlobal that parses the animations blob.
+    QJSValue startAnimation(const QJSValue &value, bool set);
     QJSEngine *m_engine;
     QString m_effectName;
     QString m_scriptFile;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic