@cervisebas/nodegui-plugin-animation 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.clang-format +8 -0
  2. package/CMakeLists.txt +37 -0
  3. package/README.md +47 -0
  4. package/config/tests/setup.js +7 -0
  5. package/config/tests/teardown.js +3 -0
  6. package/dist/demo.d.ts +1 -0
  7. package/dist/demo.js +19 -0
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.js +15 -0
  10. package/dist/lib/QAbstractAnimation.d.ts +28 -0
  11. package/dist/lib/QAbstractAnimation.js +76 -0
  12. package/dist/lib/QPropertyAnimation.d.ts +158 -0
  13. package/dist/lib/QPropertyAnimation.js +33 -0
  14. package/dist/lib/QVariantAnimation.d.ts +159 -0
  15. package/dist/lib/QVariantAnimation.js +44 -0
  16. package/dist/lib/types/PropertyNames.d.ts +1 -0
  17. package/dist/lib/types/PropertyNames.js +2 -0
  18. package/dist/lib/utils/addon.d.ts +2 -0
  19. package/dist/lib/utils/addon.js +5 -0
  20. package/package.json +60 -0
  21. package/src/cpp/QAbstractAnimation/qabstractanimation_macro.h +150 -0
  22. package/src/cpp/QPropertyAnimation/npropertyanimation.hpp +13 -0
  23. package/src/cpp/QPropertyAnimation/qpropertyanimation_wrap.cpp +82 -0
  24. package/src/cpp/QPropertyAnimation/qpropertyanimation_wrap.h +26 -0
  25. package/src/cpp/QVariantAnimation/nvariantanimation.hpp +13 -0
  26. package/src/cpp/QVariantAnimation/qvariantanimation_macro.h +66 -0
  27. package/src/cpp/QVariantAnimation/qvariantanimation_wrap.cpp +47 -0
  28. package/src/cpp/QVariantAnimation/qvariantanimation_wrap.h +21 -0
  29. package/src/cpp/main.cpp +12 -0
  30. package/src/demo.ts +23 -0
  31. package/src/index.ts +4 -0
  32. package/src/lib/QAbstractAnimation.ts +57 -0
  33. package/src/lib/QPropertyAnimation.ts +36 -0
  34. package/src/lib/QVariantAnimation.ts +38 -0
  35. package/src/lib/types/PropertyNames.ts +8 -0
  36. package/src/lib/utils/addon.ts +4 -0
@@ -0,0 +1 @@
1
+ export type PropertyName = 'geometry' | 'pos' | 'size' | 'minimumSize' | 'maximumSize' | 'windowOpacity' | 'visible';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ declare const addon: any;
2
+ export default addon;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
4
+ const addon = require('../../../build/Release/nodegui_plugin_animation.node');
5
+ exports.default = addon;
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@cervisebas/nodegui-plugin-animation",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "typings": "dist/index.d.ts",
6
+ "scripts": {
7
+ "build": "tsc && npm run build:addon",
8
+ "postinstall": "npm run build:addon",
9
+ "build:addon": "cross-env CMAKE_BUILD_PARALLEL_LEVEL=8 cmake-js compile",
10
+ "dev": "tsc && qode dist/demo.js",
11
+ "test": "qode ./node_modules/.bin/jest",
12
+ "lint:cpp": "clang-format -i --glob=src/cpp/**/*.[h,c,cpp]*",
13
+ "lint:ts": "tsc --noEmit && eslint './src/**/*.{ts,tsx,js,jsx}' --fix"
14
+ },
15
+ "author": "Cervisebas",
16
+ "license": "MIT",
17
+ "peerDependencies": {
18
+ "@nodegui/nodegui": "^0.71.0"
19
+ },
20
+ "files": [
21
+ "config",
22
+ "dist",
23
+ "src",
24
+ ".clang-format",
25
+ "CMakeLists.txt",
26
+ "package.json",
27
+ "README.md"
28
+ ],
29
+ "dependencies": {
30
+ "bluebird": "^3.7.2",
31
+ "cmake-js": "^7.4.0",
32
+ "cross-env": "^10.1.0",
33
+ "node-addon-api": "^8.5.0"
34
+ },
35
+ "devDependencies": {
36
+ "@eslint/js": "^9.39.2",
37
+ "@nodegui/nodegui": "^0.73.0",
38
+ "@types/jest": "^30.0.0",
39
+ "@types/node": "^25.0.6",
40
+ "@typescript-eslint/eslint-plugin": "~8.52.0",
41
+ "@typescript-eslint/parser": "~8.52.0",
42
+ "clang-format": "~1.8.0",
43
+ "eslint": "^9.39.2",
44
+ "eslint-config-prettier": "~10.1.8",
45
+ "eslint-plugin-prettier": "~5.5.4",
46
+ "globals": "^17.0.0",
47
+ "husky": "^9.1.7",
48
+ "jest": "~30.2.0",
49
+ "jiti": "^2.6.1",
50
+ "prettier": "^3.7.4",
51
+ "ts-jest": "~29.4.6",
52
+ "typescript": "~5.9.3",
53
+ "typescript-eslint": "^8.52.0"
54
+ },
55
+ "husky": {
56
+ "hooks": {
57
+ "pre-push": "npm run lint:ts && npm run lint:cpp && npm run test"
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,150 @@
1
+
2
+ #pragma once
3
+ #include <nodegui/QtCore/QObject/qobject_macro.h>
4
+
5
+ #include <QAbstractAnimation>
6
+
7
+ /*
8
+
9
+ This macro adds common QAbstractAnimation macro exported methods
10
+ The exported methods are taken into this macro to avoid writing them in each
11
+ and every time we export.
12
+ */
13
+
14
+ #ifndef QABSTRACTANIMATION_WRAPPED_METHODS_DECLARATION
15
+ #define QABSTRACTANIMATION_WRAPPED_METHODS_DECLARATION \
16
+ QOBJECT_WRAPPED_METHODS_DECLARATION \
17
+ \
18
+ Napi::Value start(const Napi::CallbackInfo& info) { \
19
+ Napi::Env env = info.Env(); \
20
+ Napi::HandleScope scope(env); \
21
+ if (info.Length() == 1) { \
22
+ Napi::Number deletionPolicy = info[0].As<Napi::Number>(); \
23
+ this->instance->start(static_cast<QAbstractAnimation::DeletionPolicy>( \
24
+ deletionPolicy.Int32Value())); \
25
+ } else { \
26
+ this->instance->start(); \
27
+ } \
28
+ return env.Null(); \
29
+ } \
30
+ Napi::Value stop(const Napi::CallbackInfo& info) { \
31
+ Napi::Env env = info.Env(); \
32
+ Napi::HandleScope scope(env); \
33
+ this->instance->stop(); \
34
+ return env.Null(); \
35
+ } \
36
+ Napi::Value currentLoop(const Napi::CallbackInfo& info) { \
37
+ Napi::Env env = info.Env(); \
38
+ Napi::HandleScope scope(env); \
39
+ int loop = this->instance->currentLoop(); \
40
+ return Napi::Value::From(env, loop); \
41
+ } \
42
+ Napi::Value currentLoopTime(const Napi::CallbackInfo& info) { \
43
+ Napi::Env env = info.Env(); \
44
+ Napi::HandleScope scope(env); \
45
+ int time = this->instance->currentLoopTime(); \
46
+ return Napi::Value::From(env, time); \
47
+ } \
48
+ Napi::Value currentTime(const Napi::CallbackInfo& info) { \
49
+ Napi::Env env = info.Env(); \
50
+ Napi::HandleScope scope(env); \
51
+ int time = this->instance->currentTime(); \
52
+ return Napi::Value::From(env, time); \
53
+ } \
54
+ Napi::Value direction(const Napi::CallbackInfo& info) { \
55
+ Napi::Env env = info.Env(); \
56
+ Napi::HandleScope scope(env); \
57
+ int value = static_cast<int>(this->instance->direction()); \
58
+ return Napi::Value::From(env, value); \
59
+ } \
60
+ Napi::Value duration(const Napi::CallbackInfo& info) { \
61
+ Napi::Env env = info.Env(); \
62
+ Napi::HandleScope scope(env); \
63
+ int duration = this->instance->duration(); \
64
+ return Napi::Value::From(env, duration); \
65
+ } \
66
+ Napi::Value loopCount(const Napi::CallbackInfo& info) { \
67
+ Napi::Env env = info.Env(); \
68
+ Napi::HandleScope scope(env); \
69
+ int loopCount = this->instance->loopCount(); \
70
+ return Napi::Value::From(env, loopCount); \
71
+ } \
72
+ Napi::Value setDirection(const Napi::CallbackInfo& info) { \
73
+ Napi::Env env = info.Env(); \
74
+ Napi::HandleScope scope(env); \
75
+ Napi::Number directionValue = info[0].As<Napi::Number>(); \
76
+ int direction = directionValue.Int32Value(); \
77
+ \
78
+ this->instance->setDirection( \
79
+ static_cast<QAbstractAnimation::Direction>(direction)); \
80
+ return env.Null(); \
81
+ } \
82
+ Napi::Value setLoopCount(const Napi::CallbackInfo& info) { \
83
+ Napi::Env env = info.Env(); \
84
+ Napi::HandleScope scope(env); \
85
+ Napi::Number loopCount = info[0].As<Napi::Number>(); \
86
+ this->instance->setLoopCount(loopCount.Int32Value()); \
87
+ return env.Null(); \
88
+ } \
89
+ Napi::Value state(const Napi::CallbackInfo& info) { \
90
+ Napi::Env env = info.Env(); \
91
+ Napi::HandleScope scope(env); \
92
+ int value = static_cast<int>(this->instance->state()); \
93
+ return Napi::Value::From(env, value); \
94
+ } \
95
+ Napi::Value totalDuration(const Napi::CallbackInfo& info) { \
96
+ Napi::Env env = info.Env(); \
97
+ Napi::HandleScope scope(env); \
98
+ int value = this->instance->totalDuration(); \
99
+ return Napi::Value::From(env, value); \
100
+ } \
101
+ Napi::Value pause(const Napi::CallbackInfo& info) { \
102
+ Napi::Env env = info.Env(); \
103
+ Napi::HandleScope scope(env); \
104
+ this->instance->pause(); \
105
+ return env.Null(); \
106
+ } \
107
+ Napi::Value resume(const Napi::CallbackInfo& info) { \
108
+ Napi::Env env = info.Env(); \
109
+ Napi::HandleScope scope(env); \
110
+ this->instance->resume(); \
111
+ return env.Null(); \
112
+ } \
113
+ Napi::Value setCurrentTime(const Napi::CallbackInfo& info) { \
114
+ Napi::Env env = info.Env(); \
115
+ Napi::HandleScope scope(env); \
116
+ Napi::Number time = info[0].As<Napi::Number>(); \
117
+ this->instance->setCurrentTime(time.Int32Value()); \
118
+ return env.Null(); \
119
+ } \
120
+ Napi::Value setPaused(const Napi::CallbackInfo& info) { \
121
+ Napi::Env env = info.Env(); \
122
+ Napi::HandleScope scope(env); \
123
+ Napi::Boolean value = info[0].As<Napi::Boolean>(); \
124
+ this->instance->setPaused(value.Value()); \
125
+ return env.Null(); \
126
+ }
127
+ #endif
128
+
129
+ #ifndef QABSTRACTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE
130
+ #define QABSTRACTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE(ComponentWrapName) \
131
+ \
132
+ QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(ComponentWrapName) \
133
+ InstanceMethod("start", &ComponentWrapName::start), \
134
+ InstanceMethod("stop", &ComponentWrapName::stop), \
135
+ InstanceMethod("currentLoop", &ComponentWrapName::currentLoop), \
136
+ InstanceMethod("currentLoopTime", &ComponentWrapName::currentLoopTime), \
137
+ InstanceMethod("currentTime", &ComponentWrapName::currentTime), \
138
+ InstanceMethod("direction", &ComponentWrapName::direction), \
139
+ InstanceMethod("duration", &ComponentWrapName::duration), \
140
+ InstanceMethod("loopCount", &ComponentWrapName::loopCount), \
141
+ InstanceMethod("setDirection", &ComponentWrapName::setDirection), \
142
+ InstanceMethod("setLoopCount", &ComponentWrapName::setLoopCount), \
143
+ InstanceMethod("state", &ComponentWrapName::state), \
144
+ InstanceMethod("totalDuration", &ComponentWrapName::totalDuration), \
145
+ InstanceMethod("pause", &ComponentWrapName::pause), \
146
+ InstanceMethod("resume", &ComponentWrapName::resume), \
147
+ InstanceMethod("setCurrentTime", &ComponentWrapName::setCurrentTime), \
148
+ InstanceMethod("setPaused", &ComponentWrapName::setPaused),
149
+
150
+ #endif
@@ -0,0 +1,13 @@
1
+ #pragma once
2
+
3
+ #include <nodegui/core/Events/eventwidget.h>
4
+ #include <nodegui/core/Events/eventwidget_macro.h>
5
+
6
+ #include <QPropertyAnimation>
7
+
8
+ class NPropertyAnimation : public QPropertyAnimation, public EventWidget {
9
+ Q_OBJECT
10
+ EVENTWIDGET_IMPLEMENTATIONS(QPropertyAnimation)
11
+ public:
12
+ using QPropertyAnimation::QPropertyAnimation;
13
+ };
@@ -0,0 +1,82 @@
1
+ #include "qpropertyanimation_wrap.h"
2
+
3
+ #include <nodegui/Extras/Utils/nutils.h>
4
+ #include <nodegui/QtCore/QObject/qobject_wrap.h>
5
+
6
+ #include <QString>
7
+
8
+ Napi::FunctionReference QPropertyAnimationWrap::constructor;
9
+
10
+ Napi::Object QPropertyAnimationWrap::init(Napi::Env env, Napi::Object exports) {
11
+ Napi::HandleScope scope(env);
12
+ char CLASSNAME[] = "QPropertyAnimation";
13
+ Napi::Function func = DefineClass(
14
+ env, CLASSNAME,
15
+ {InstanceMethod("setPropertyName",
16
+ &QPropertyAnimationWrap::setPropertyName),
17
+ InstanceMethod("setTargetObject",
18
+ &QPropertyAnimationWrap::setTargetObject),
19
+ InstanceMethod("propertyName", &QPropertyAnimationWrap::propertyName),
20
+ QVARIANTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE(
21
+ QPropertyAnimationWrap)});
22
+ constructor = Napi::Persistent(func);
23
+ exports.Set(CLASSNAME, func);
24
+ return exports;
25
+ }
26
+
27
+ NPropertyAnimation *QPropertyAnimationWrap::getInternalInstance() {
28
+ return this->instance;
29
+ }
30
+
31
+ QPropertyAnimationWrap::QPropertyAnimationWrap(const Napi::CallbackInfo &info)
32
+ : Napi::ObjectWrap<QPropertyAnimationWrap>(info) {
33
+ Napi::Env env = info.Env();
34
+ Napi::HandleScope scope(env);
35
+
36
+ if (info.Length() == 1) {
37
+ Napi::Object parentObject = info[0].As<Napi::Object>();
38
+ QObjectWrap *parentObjectWrap =
39
+ Napi::ObjectWrap<QObjectWrap>::Unwrap(parentObject);
40
+ this->instance =
41
+ new NPropertyAnimation(parentObjectWrap->getInternalInstance());
42
+ } else if (info.Length() == 0) {
43
+ this->instance = new NPropertyAnimation();
44
+ } else {
45
+ Napi::TypeError::New(env, "Wrong number of arguments")
46
+ .ThrowAsJavaScriptException();
47
+ }
48
+ }
49
+
50
+ QPropertyAnimationWrap::~QPropertyAnimationWrap() {
51
+ extrautils::safeDelete(this->instance);
52
+ }
53
+
54
+ Napi::Value QPropertyAnimationWrap::setPropertyName(
55
+ const Napi::CallbackInfo &info) {
56
+ Napi::Env env = info.Env();
57
+ Napi::HandleScope scope(env);
58
+ Napi::String name = info[0].As<Napi::String>();
59
+ std::string nameString = name.Utf8Value();
60
+ QByteArray byteArray(nameString.c_str(), nameString.length());
61
+ this->instance->setPropertyName(byteArray);
62
+ return env.Null();
63
+ }
64
+ Napi::Value QPropertyAnimationWrap::propertyName(
65
+ const Napi::CallbackInfo &info) {
66
+ Napi::Env env = info.Env();
67
+ Napi::HandleScope scope(env);
68
+ QString name = this->instance->propertyName();
69
+ return Napi::String::From(env, name.toStdString());
70
+ }
71
+ Napi::Value QPropertyAnimationWrap::setTargetObject(
72
+ const Napi::CallbackInfo &info) {
73
+ Napi::Env env = info.Env();
74
+ Napi::HandleScope scope(env);
75
+
76
+ Napi::Object qobjectWrapObject = info[0].As<Napi::Object>();
77
+ QObjectWrap *objectWrap =
78
+ Napi::ObjectWrap<QObjectWrap>::Unwrap(qobjectWrapObject);
79
+ this->instance->setTargetObject(objectWrap->getInternalInstance());
80
+
81
+ return env.Null();
82
+ }
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+ #include <napi.h>
3
+ #include <stdlib.h>
4
+
5
+ #include <QPointer>
6
+
7
+ #include "QVariantAnimation/qvariantanimation_macro.h"
8
+ #include "npropertyanimation.hpp"
9
+
10
+ class QPropertyAnimationWrap : public Napi::ObjectWrap<QPropertyAnimationWrap> {
11
+ private:
12
+ QPointer<NPropertyAnimation> instance;
13
+
14
+ public:
15
+ static Napi::Object init(Napi::Env env, Napi::Object exports);
16
+ QPropertyAnimationWrap(const Napi::CallbackInfo &info);
17
+ ~QPropertyAnimationWrap();
18
+ NPropertyAnimation *getInternalInstance();
19
+ static Napi::FunctionReference constructor;
20
+ // wrapped methods
21
+ Napi::Value setPropertyName(const Napi::CallbackInfo &info);
22
+ Napi::Value propertyName(const Napi::CallbackInfo &info);
23
+ Napi::Value setTargetObject(const Napi::CallbackInfo &info);
24
+
25
+ QVARIANTANIMATION_WRAPPED_METHODS_DECLARATION
26
+ };
@@ -0,0 +1,13 @@
1
+ #pragma once
2
+
3
+ #include <nodegui/core/Events/eventwidget.h>
4
+ #include <nodegui/core/Events/eventwidget_macro.h>
5
+
6
+ #include <QVariantAnimation>
7
+
8
+ class NVariantAnimation : public QVariantAnimation, public EventWidget {
9
+ Q_OBJECT
10
+ EVENTWIDGET_IMPLEMENTATIONS(QVariantAnimation)
11
+ public:
12
+ using QVariantAnimation::QVariantAnimation;
13
+ };
@@ -0,0 +1,66 @@
1
+
2
+ #pragma once
3
+ #include <nodegui/Extras/Utils/nutils.h>
4
+
5
+ #include "QAbstractAnimation/qabstractanimation_macro.h"
6
+ /*
7
+
8
+ This macro adds common QVariantAnimation macro exported methods
9
+ The exported methods are taken into this macro to avoid writing them in each
10
+ and every time we export.
11
+ */
12
+
13
+ #ifndef QVARIANTANIMATION_WRAPPED_METHODS_DECLARATION
14
+ #define QVARIANTANIMATION_WRAPPED_METHODS_DECLARATION \
15
+ QABSTRACTANIMATION_WRAPPED_METHODS_DECLARATION \
16
+ \
17
+ Napi::Value setDuration(const Napi::CallbackInfo &info) { \
18
+ Napi::Env env = info.Env(); \
19
+ Napi::HandleScope scope(env); \
20
+ Napi::Number duration = info[0].As<Napi::Number>(); \
21
+ this->instance->setDuration(duration.Int32Value()); \
22
+ return env.Null(); \
23
+ } \
24
+ \
25
+ Napi::Value setStartValue(const Napi::CallbackInfo &info) { \
26
+ Napi::Env env = info.Env(); \
27
+ Napi::HandleScope scope(env); \
28
+ Napi::Value value = info[0]; \
29
+ auto variant = \
30
+ QSharedPointer<QVariant>(extrautils::convertToQVariant(env, value)); \
31
+ this->instance->setStartValue(*variant); \
32
+ return env.Null(); \
33
+ } \
34
+ \
35
+ Napi::Value setEndValue(const Napi::CallbackInfo &info) { \
36
+ Napi::Env env = info.Env(); \
37
+ Napi::HandleScope scope(env); \
38
+ Napi::Value value = info[0]; \
39
+ auto variant = \
40
+ QSharedPointer<QVariant>(extrautils::convertToQVariant(env, value)); \
41
+ this->instance->setEndValue(*variant); \
42
+ return env.Null(); \
43
+ } \
44
+ Napi::Value setKeyValueAt(const Napi::CallbackInfo &info) { \
45
+ Napi::Env env = info.Env(); \
46
+ Napi::HandleScope scope(env); \
47
+ Napi::Number step = info[0].As<Napi::Number>(); \
48
+ Napi::Value value = info[1]; \
49
+ auto variant = \
50
+ QSharedPointer<QVariant>(extrautils::convertToQVariant(env, value)); \
51
+ this->instance->setKeyValueAt(step.DoubleValue(), *variant); \
52
+ return env.Null(); \
53
+ }
54
+
55
+ #endif
56
+
57
+ #ifndef QVARIANTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE
58
+ #define QVARIANTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE(ComponentWrapName) \
59
+ \
60
+ QABSTRACTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE(ComponentWrapName) \
61
+ InstanceMethod("setDuration", &ComponentWrapName::setDuration), \
62
+ InstanceMethod("setStartValue", &ComponentWrapName::setStartValue), \
63
+ InstanceMethod("setEndValue", &ComponentWrapName::setEndValue), \
64
+ InstanceMethod("setKeyValueAt", &ComponentWrapName::setKeyValueAt),
65
+
66
+ #endif
@@ -0,0 +1,47 @@
1
+ #include "qvariantanimation_wrap.h"
2
+
3
+ #include <nodegui/Extras/Utils/nutils.h>
4
+ #include <nodegui/QtCore/QObject/qobject_wrap.h>
5
+
6
+ #include <QSharedPointer>
7
+ #include <QString>
8
+
9
+ Napi::FunctionReference QVariantAnimationWrap::constructor;
10
+
11
+ Napi::Object QVariantAnimationWrap::init(Napi::Env env, Napi::Object exports) {
12
+ Napi::HandleScope scope(env);
13
+ char CLASSNAME[] = "QVariantAnimation";
14
+ Napi::Function func = DefineClass(
15
+ env, CLASSNAME,
16
+ {QVARIANTANIMATION_WRAPPED_METHODS_EXPORT_DEFINE(QVariantAnimationWrap)});
17
+ constructor = Napi::Persistent(func);
18
+ exports.Set(CLASSNAME, func);
19
+ return exports;
20
+ }
21
+
22
+ NVariantAnimation *QVariantAnimationWrap::getInternalInstance() {
23
+ return this->instance;
24
+ }
25
+
26
+ QVariantAnimationWrap::QVariantAnimationWrap(const Napi::CallbackInfo &info)
27
+ : Napi::ObjectWrap<QVariantAnimationWrap>(info) {
28
+ Napi::Env env = info.Env();
29
+ Napi::HandleScope scope(env);
30
+
31
+ if (info.Length() == 1) {
32
+ Napi::Object parentObject = info[0].As<Napi::Object>();
33
+ QObjectWrap *parentObjectWrap =
34
+ Napi::ObjectWrap<QObjectWrap>::Unwrap(parentObject);
35
+ this->instance =
36
+ new NVariantAnimation(parentObjectWrap->getInternalInstance());
37
+ } else if (info.Length() == 0) {
38
+ this->instance = new NVariantAnimation();
39
+ } else {
40
+ Napi::TypeError::New(env, "Wrong number of arguments")
41
+ .ThrowAsJavaScriptException();
42
+ }
43
+ }
44
+
45
+ QVariantAnimationWrap::~QVariantAnimationWrap() {
46
+ extrautils::safeDelete(this->instance);
47
+ }
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+ #include <napi.h>
3
+ #include <stdlib.h>
4
+
5
+ #include <QPointer>
6
+
7
+ #include "nvariantanimation.hpp"
8
+ #include "qvariantanimation_macro.h"
9
+
10
+ class QVariantAnimationWrap : public Napi::ObjectWrap<QVariantAnimationWrap> {
11
+ private:
12
+ QPointer<NVariantAnimation> instance;
13
+
14
+ public:
15
+ static Napi::Object init(Napi::Env env, Napi::Object exports);
16
+ QVariantAnimationWrap(const Napi::CallbackInfo &info);
17
+ ~QVariantAnimationWrap();
18
+ NVariantAnimation *getInternalInstance();
19
+ static Napi::FunctionReference constructor;
20
+ QVARIANTANIMATION_WRAPPED_METHODS_DECLARATION
21
+ };
@@ -0,0 +1,12 @@
1
+ #include <napi.h>
2
+
3
+ #include "QPropertyAnimation/qpropertyanimation_wrap.h"
4
+ #include "QVariantAnimation/qvariantanimation_wrap.h"
5
+
6
+ Napi::Object Main(Napi::Env env, Napi::Object exports) {
7
+ QPropertyAnimationWrap::init(env, exports);
8
+ QVariantAnimationWrap::init(env, exports);
9
+ return exports;
10
+ }
11
+
12
+ NODE_API_MODULE(NODE_GYP_MODULE_NAME, Main)
package/src/demo.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { QPropertyAnimation } from './index';
2
+ import { QPushButton } from '@nodegui/nodegui';
3
+
4
+ const animation = new QPropertyAnimation();
5
+
6
+ const button = new QPushButton();
7
+ button.setText('Animated Button');
8
+ button.show();
9
+
10
+ animation.setPropertyName('windowOpacity');
11
+ animation.setTargetObject(button);
12
+
13
+ animation.setDuration(5000);
14
+ animation.setStartValue(0.4);
15
+ animation.setKeyValueAt(0.5, 1.0);
16
+ animation.setEndValue(1.0);
17
+
18
+ animation.start();
19
+
20
+ Object.assign(global, {
21
+ button: button,
22
+ animation: animation,
23
+ });
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { DeletionPolicy, Direction, State, QAbstractAnimation } from './lib/QAbstractAnimation';
2
+ export { NodeVariantAnimation, QVariantAnimation, QVariantAnimationEvents } from './lib/QVariantAnimation';
3
+ export { QPropertyAnimation, QPropertyAnimationEvents } from './lib/QPropertyAnimation';
4
+ export { PropertyName } from './lib/types/PropertyNames';
@@ -0,0 +1,57 @@
1
+ import { QObject, QObjectSignals } from '@nodegui/nodegui';
2
+ export abstract class QAbstractAnimation extends QObject<QObjectSignals> {
3
+ start(policy?: DeletionPolicy): void {
4
+ if (policy) {
5
+ this.native?.start(policy);
6
+ } else {
7
+ this.native?.start();
8
+ }
9
+ }
10
+ stop(): void {
11
+ this.native?.stop();
12
+ }
13
+ currentLoop(): number {
14
+ return this.native?.currentLoop();
15
+ }
16
+ currentLoopTime(): number {
17
+ return this.native?.currentLoopTime();
18
+ }
19
+ currentTime(): number {
20
+ return this.native?.currentTime();
21
+ }
22
+ direction(): Direction {
23
+ return this.native?.direction();
24
+ }
25
+ duration(): number {
26
+ return this.native?.duration();
27
+ }
28
+ loopCount(): number {
29
+ return this.native?.loopCount();
30
+ }
31
+ setDirection(direction: Direction): void {
32
+ return this.native?.setDirection(direction);
33
+ }
34
+ setLoopCount(loopCount: number): void {
35
+ return this.native?.setLoopCount(loopCount);
36
+ }
37
+ state(): State {
38
+ return this.native?.state();
39
+ }
40
+ totalDuration(): number {
41
+ return this.native?.totalDuration();
42
+ }
43
+ }
44
+
45
+ export enum DeletionPolicy {
46
+ KeepWhenStopped = 0,
47
+ DeleteWhenStopped = 1,
48
+ }
49
+ export enum Direction {
50
+ Forward = 0,
51
+ Backward = 1,
52
+ }
53
+ export enum State {
54
+ Stopped = 0,
55
+ Paused = 1,
56
+ Running = 2,
57
+ }
@@ -0,0 +1,36 @@
1
+ import { NativeElement, QObject } from '@nodegui/nodegui';
2
+ import addon from './utils/addon';
3
+ import { NodeVariantAnimation, QVariantAnimationEvents } from './QVariantAnimation';
4
+ import { PropertyName } from './types/PropertyNames';
5
+
6
+ export const QPropertyAnimationEvents = Object.freeze({
7
+ ...QVariantAnimationEvents,
8
+ });
9
+ export class QPropertyAnimation extends NodeVariantAnimation {
10
+ public native: NativeElement;
11
+ public nodeParent?: QObject<never>;
12
+
13
+ constructor(parent?: QObject<never>) {
14
+ let native;
15
+ if (parent) {
16
+ native = new addon.QPropertyAnimation(parent.native);
17
+ } else {
18
+ native = new addon.QPropertyAnimation();
19
+ }
20
+ super(native);
21
+ this.native = native;
22
+ this.nodeParent = parent;
23
+ }
24
+
25
+ setPropertyName(name: PropertyName): void {
26
+ this.native.setPropertyName(name);
27
+ }
28
+
29
+ propertyName(): PropertyName {
30
+ return this.native.propertyName();
31
+ }
32
+
33
+ setTargetObject(object: QObject<never>): void {
34
+ return this.native.setTargetObject(object.native);
35
+ }
36
+ }