Adds Signals inheritance (#288)
* Inherit signals * export signals * Fix Qvariant build * Adds Abstract button signals * added more test cases
This commit is contained in:
parent
01a6476f9c
commit
42e92ecbff
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "QtCore/QObject/qobject_macro.h"
|
||||
#include "core/Events/eventwidget.h"
|
||||
#include "core/Events/eventwidget_macro.h"
|
||||
|
||||
@ -9,4 +10,6 @@ class NObject : public QObject, public EventWidget {
|
||||
EVENTWIDGET_IMPLEMENTATIONS(QObject)
|
||||
public:
|
||||
using QObject::QObject;
|
||||
|
||||
void connectSignalsToEventEmitter() { QOBJECT_SIGNALS }
|
||||
};
|
||||
|
||||
@ -72,3 +72,16 @@
|
||||
InstanceMethod("objectName", &ComponentWrapName::objectName),
|
||||
|
||||
#endif // QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
#ifndef QOBJECT_SIGNALS
|
||||
#define QOBJECT_SIGNALS \
|
||||
QObject::connect(this, &QObject::objectNameChanged, \
|
||||
[=](const QString& objectName) { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->emitOnNode.Call( \
|
||||
{Napi::String::New(env, "objectNameChanged"), \
|
||||
Napi::Value::From(env, objectName.toStdString())}); \
|
||||
});
|
||||
|
||||
#endif // QOBJECT_SIGNALS
|
||||
|
||||
@ -23,3 +23,7 @@ class QVariantWrap : public Napi::ObjectWrap<QVariantWrap> {
|
||||
// wrapped methods
|
||||
COMPONENT_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
namespace StaticQVariantWrapMethods {
|
||||
Napi::Value converToQVariant(const Napi::CallbackInfo& info);
|
||||
} // namespace StaticQVariantWrapMethods
|
||||
@ -12,7 +12,7 @@ class NMovie : public QMovie, public EventWidget {
|
||||
public:
|
||||
using QMovie::QMovie;
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QMovie::error,
|
||||
[=](QImageReader::ImageReaderError error) {
|
||||
|
||||
@ -43,3 +43,31 @@
|
||||
InstanceMethod("setIcon", &WidgetWrapName::setIcon),
|
||||
|
||||
#endif // QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
#ifndef QABSTRACT_BUTTON_SIGNALS
|
||||
#define QABSTRACT_BUTTON_SIGNALS \
|
||||
QWIDGET_SIGNALS \
|
||||
QObject::connect(this, &QAbstractButton::clicked, [=](bool checked) { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->emitOnNode.Call( \
|
||||
{Napi::String::New(env, "clicked"), Napi::Value::From(env, checked)}); \
|
||||
}); \
|
||||
QObject::connect(this, &QAbstractButton::pressed, [=]() { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->emitOnNode.Call({Napi::String::New(env, "pressed")}); \
|
||||
}); \
|
||||
QObject::connect(this, &QAbstractButton::released, [=]() { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->emitOnNode.Call({Napi::String::New(env, "released")}); \
|
||||
}); \
|
||||
QObject::connect(this, &QAbstractButton::toggled, [=](bool checked) { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->emitOnNode.Call( \
|
||||
{Napi::String::New(env, "toggled"), Napi::Value::From(env, checked)}); \
|
||||
});
|
||||
|
||||
#endif
|
||||
|
||||
@ -10,7 +10,7 @@ class NAction : public QAction, public EventWidget {
|
||||
EVENTWIDGET_IMPLEMENTATIONS(QAction)
|
||||
public:
|
||||
using QAction::QAction; // inherit all constructors of QAction
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QAction::triggered, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
class QActionWrap : public Napi::ObjectWrap<QActionWrap> {
|
||||
private:
|
||||
QPointer<NAction> instance;
|
||||
bool disableDeletion;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
#include <QCheckBox>
|
||||
|
||||
#include "QtWidgets/QAbstractButton/qabstractbutton_macro.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
@ -11,12 +13,5 @@ class NCheckBox : public QCheckBox, public NodeWidget {
|
||||
public:
|
||||
using QCheckBox::QCheckBox; // inherit all constructors of QCheckBox
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
QObject::connect(this, &QCheckBox::toggled, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "toggled"), Napi::Value::From(env, checked)});
|
||||
});
|
||||
}
|
||||
void connectSignalsToEventEmitter() { QABSTRACT_BUTTON_SIGNALS }
|
||||
};
|
||||
|
||||
@ -11,7 +11,7 @@ class NComboBox : public QComboBox, public NodeWidget {
|
||||
NODEWIDGET_IMPLEMENTATIONS(QComboBox)
|
||||
using QComboBox::QComboBox;
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(
|
||||
this, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
|
||||
@ -10,7 +10,7 @@ class NDial : public QDial, public NodeWidget {
|
||||
public:
|
||||
using QDial::QDial; // inherit all constructors of QDial
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QDial::valueChanged, [=](int value) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
|
||||
@ -11,7 +11,7 @@ class NFileDialog : public QFileDialog, public NodeWidget {
|
||||
NODEWIDGET_IMPLEMENTATIONS(QFileDialog)
|
||||
using QFileDialog::QFileDialog;
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(
|
||||
this, &QFileDialog::currentChanged, [=](const QString &path) {
|
||||
|
||||
@ -11,7 +11,7 @@ class NGroupBox : public QGroupBox, public NodeWidget {
|
||||
public:
|
||||
using QGroupBox::QGroupBox; // inherit all constructors of QGroupBox
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
QObject::connect(this, &QGroupBox::clicked, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NLabel : public QLabel, public NodeWidget {
|
||||
@ -10,8 +11,8 @@ class NLabel : public QLabel, public NodeWidget {
|
||||
public:
|
||||
using QLabel::QLabel; // inherit all constructors of QLabel
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
void connectSignalsToEventEmitter() {
|
||||
QWIDGET_SIGNALS
|
||||
QObject::connect(this, &QLabel::linkActivated, [=](const QString &link) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -10,7 +10,7 @@ class NLineEdit : public QLineEdit, public NodeWidget {
|
||||
public:
|
||||
using QLineEdit::QLineEdit; // inherit all constructors of QLineEdit
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QLineEdit::cursorPositionChanged,
|
||||
[=](int oldPost, int newPos) {
|
||||
|
||||
@ -11,7 +11,7 @@ class NPlainTextEdit : public QPlainTextEdit, public NodeWidget {
|
||||
using QPlainTextEdit::QPlainTextEdit; // inherit all constructors of
|
||||
// QPlainTextEdit
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QPlainTextEdit::textChanged, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "QtWidgets/QAbstractButton/qabstractbutton_macro.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
@ -11,29 +13,5 @@ class NPushButton : public QPushButton, public NodeWidget {
|
||||
public:
|
||||
using QPushButton::QPushButton; // inherit all constructors of QPushButton
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QPushButton::clicked, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "clicked"), Napi::Value::From(env, checked)});
|
||||
});
|
||||
QObject::connect(this, &QPushButton::released, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "released")});
|
||||
});
|
||||
QObject::connect(this, &QPushButton::pressed, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "pressed")});
|
||||
});
|
||||
QObject::connect(this, &QPushButton::toggled, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "toggled"), Napi::Value::From(env, checked)});
|
||||
});
|
||||
}
|
||||
void connectSignalsToEventEmitter() { QABSTRACT_BUTTON_SIGNALS }
|
||||
};
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
#include <QRadioButton>
|
||||
|
||||
#include "QtWidgets/QAbstractButton/qabstractbutton_macro.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NRadioButton : public QRadioButton, public NodeWidget {
|
||||
@ -9,4 +11,8 @@ class NRadioButton : public QRadioButton, public NodeWidget {
|
||||
NODEWIDGET_IMPLEMENTATIONS(QRadioButton)
|
||||
public:
|
||||
using QRadioButton::QRadioButton; // inherit all constructors of QRadioButton
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QABSTRACT_BUTTON_SIGNALS
|
||||
}
|
||||
};
|
||||
|
||||
@ -10,7 +10,7 @@ class NShortcut : public QShortcut, public EventWidget {
|
||||
EVENTWIDGET_IMPLEMENTATIONS(QShortcut)
|
||||
public:
|
||||
using QShortcut::QShortcut; // inherit all constructors of QShortcut
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QShortcut::activated, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
|
||||
@ -11,7 +11,7 @@ class NSpinBox : public QSpinBox, public NodeWidget {
|
||||
public:
|
||||
using QSpinBox::QSpinBox; // inherit all constructors of QSpinBox
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(
|
||||
this, QOverload<int>::of(&QSpinBox::valueChanged), [=](int val) {
|
||||
|
||||
@ -12,7 +12,7 @@ class NStackedWidget : public QStackedWidget, public NodeWidget {
|
||||
using QStackedWidget::QStackedWidget; // inherit all constructors of
|
||||
// QStackedWidget
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QStackedWidget::currentChanged, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
|
||||
@ -11,7 +11,7 @@ class NSystemTrayIcon : public QSystemTrayIcon, public EventWidget {
|
||||
public:
|
||||
// inherit all constructors of QSystemTrayIcon
|
||||
using QSystemTrayIcon::QSystemTrayIcon;
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
QObject::connect(this, &QSystemTrayIcon::activated, [=](int reason) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -11,7 +11,7 @@ class NTabWidget : public QTabWidget, public NodeWidget {
|
||||
public:
|
||||
using QTabWidget::QTabWidget; // inherit all constructors of QTabWidget
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QTabWidget::currentChanged, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
|
||||
@ -10,7 +10,7 @@ class NTableWidget : public QTableWidget, public NodeWidget {
|
||||
Q_OBJECT
|
||||
NODEWIDGET_IMPLEMENTATIONS(QTableWidget)
|
||||
using QTableWidget::QTableWidget;
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(
|
||||
this, &QTableWidget::cellActivated, [=](int row, int column) {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QAction>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "QtWidgets/QAbstractButton/qabstractbutton_macro.h"
|
||||
#include "QtWidgets/QAction/qaction_wrap.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
@ -13,36 +14,17 @@ class NToolButton : public QToolButton, public NodeWidget {
|
||||
public:
|
||||
using QToolButton::QToolButton; // inherit all constructors of QToolButton
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QToolButton::clicked, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "clicked"), Napi::Value::From(env, checked)});
|
||||
});
|
||||
QObject::connect(this, &QToolButton::released, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "released")});
|
||||
});
|
||||
QObject::connect(this, &QToolButton::pressed, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "pressed")});
|
||||
});
|
||||
QObject::connect(this, &QToolButton::toggled, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "toggled"), Napi::Value::From(env, checked)});
|
||||
});
|
||||
QABSTRACT_BUTTON_SIGNALS
|
||||
QObject::connect(this, &QToolButton::triggered, [=](QAction *action) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
// disable deletion of the native instance for these by passing true
|
||||
auto instance = QActionWrap::constructor.New(
|
||||
{Napi::External<QAction>::New(env, action)});
|
||||
{Napi::External<QAction>::New(env, action),
|
||||
Napi::Boolean::New(env, true)});
|
||||
this->emitOnNode.Call({Napi::String::New(env, "triggered"), instance});
|
||||
});
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ class NTreeWidget : public QTreeWidget, public NodeWidget {
|
||||
public:
|
||||
using QTreeWidget::QTreeWidget; // inherit all constructors of QTreeWidget
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
QObject::connect(this, &QTreeWidget::itemSelectionChanged, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <QStyleOption>
|
||||
#include <QWidget>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NWidget : public QWidget, public NodeWidget {
|
||||
@ -12,11 +13,13 @@ class NWidget : public QWidget, public NodeWidget {
|
||||
public:
|
||||
using QWidget::QWidget;
|
||||
// https://doc.qt.io/qt-5/stylesheet-reference.html
|
||||
void paintEvent(QPaintEvent *e) override {
|
||||
void paintEvent(QPaintEvent* e) override {
|
||||
QStyleOption opt;
|
||||
opt.init(this);
|
||||
QPainter p(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
QWidget::paintEvent(e);
|
||||
}
|
||||
|
||||
void connectSignalsToEventEmitter() { QWIDGET_SIGNALS }
|
||||
};
|
||||
|
||||
@ -363,3 +363,34 @@
|
||||
InstanceMethod("showNormal", &WidgetWrapName::showNormal),
|
||||
|
||||
#endif // QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
#ifndef QWIDGET_SIGNALS
|
||||
#define QWIDGET_SIGNALS \
|
||||
QOBJECT_SIGNALS \
|
||||
QObject::connect( \
|
||||
this, &QWidget::windowTitleChanged, [=](const QString& title) { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->emitOnNode.Call({Napi::String::New(env, "windowTitleChanged"), \
|
||||
Napi::Value::From(env, title.toStdString())}); \
|
||||
}); \
|
||||
QObject::connect(this, &QWidget::windowIconChanged, [=](const QIcon& icon) { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
auto instance = QIconWrap::constructor.New( \
|
||||
{Napi::External<QIcon>::New(env, new QIcon(icon))}); \
|
||||
this->emitOnNode.Call( \
|
||||
{Napi::String::New(env, "windowIconChanged"), instance}); \
|
||||
}); \
|
||||
QObject::connect( \
|
||||
this, &QWidget::customContextMenuRequested, [=](const QPoint& pos) { \
|
||||
Napi::Env env = this->emitOnNode.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
auto instance = Napi::Object::New(env); \
|
||||
instance.Set("x", Napi::Number::New(env, pos.x())); \
|
||||
instance.Set("y", Napi::Number::New(env, pos.y())); \
|
||||
this->emitOnNode.Call( \
|
||||
{Napi::String::New(env, "customContextMenuRequested"), instance}); \
|
||||
});
|
||||
|
||||
#endif // QWIDGET_SIGNALS
|
||||
|
||||
@ -16,7 +16,7 @@ class EventWidget {
|
||||
|
||||
void event(QEvent* event);
|
||||
|
||||
void connectWidgetSignalsToEventEmitter();
|
||||
void connectSignalsToEventEmitter();
|
||||
|
||||
~EventWidget();
|
||||
};
|
||||
@ -19,7 +19,7 @@
|
||||
Napi::Env env = info.Env(); \
|
||||
this->instance->emitOnNode = \
|
||||
Napi::Persistent(info[0].As<Napi::Function>()); \
|
||||
this->instance->connectWidgetSignalsToEventEmitter(); \
|
||||
this->instance->connectSignalsToEventEmitter(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
|
||||
@ -13,6 +13,8 @@ Napi::Object QVariantWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("toInt", &QVariantWrap::toInt),
|
||||
InstanceMethod("toDouble", &QVariantWrap::toDouble),
|
||||
InstanceMethod("toBool", &QVariantWrap::toBool),
|
||||
StaticMethod("converToQVariant",
|
||||
&StaticQVariantWrapMethods::converToQVariant),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -26,9 +28,8 @@ QVariantWrap::QVariantWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
if (info.Length() == 1) {
|
||||
Napi::Value value = info[0].As<Napi::Value>();
|
||||
this->instance =
|
||||
QSharedPointer<QVariant>(extrautils::convertToQVariant(env, value));
|
||||
QSharedPointer<QVariant>(info[0].As<Napi::External<QVariant>>().Data());
|
||||
} else {
|
||||
this->instance = QSharedPointer<QVariant>(new QVariant());
|
||||
}
|
||||
@ -59,3 +60,16 @@ Napi::Value QVariantWrap::toBool(const Napi::CallbackInfo& info) {
|
||||
bool value = this->instance->value<bool>();
|
||||
return Napi::Value::From(env, value);
|
||||
}
|
||||
|
||||
Napi::Value StaticQVariantWrapMethods::converToQVariant(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Value value = info[0];
|
||||
QVariant* variant = extrautils::convertToQVariant(env, value);
|
||||
// Use the variant from extrautils::convertToQVariant function as is and do
|
||||
// not create a copy to prevent memory leak
|
||||
auto instance = QVariantWrap::constructor.New(
|
||||
{Napi::External<QVariant>::New(env, variant)});
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -38,22 +38,34 @@ QActionWrap::QActionWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QActionWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NAction(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NAction();
|
||||
if (info.Length() > 0 && info[0].IsExternal()) {
|
||||
// --- if external ---
|
||||
this->instance = info[0].As<Napi::External<NAction>>().Data();
|
||||
if (info.Length() == 2) {
|
||||
this->disableDeletion = info[1].As<Napi::Boolean>().Value();
|
||||
}
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
// --- regular cases ---
|
||||
if (info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NAction(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NAction();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
this->rawData = extrautils::configureQObject(this->getInternalInstance());
|
||||
}
|
||||
|
||||
QActionWrap::~QActionWrap() { extrautils::safeDelete(this->instance); }
|
||||
QActionWrap::~QActionWrap() {
|
||||
if (!this->disableDeletion) {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QActionWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -47,7 +47,7 @@ void EventWidget::event(QEvent* event) {
|
||||
}
|
||||
}
|
||||
|
||||
void EventWidget::connectWidgetSignalsToEventEmitter() {
|
||||
void EventWidget::connectSignalsToEventEmitter() {
|
||||
// Do nothing
|
||||
// This method should be overriden in sub classes to connect all signals to
|
||||
// event emiiter of node. See Push button
|
||||
|
||||
64
src/index.ts
64
src/index.ts
@ -22,39 +22,43 @@ export { NodeWidget } from './lib/QtWidgets/QWidget';
|
||||
export { NodeLayout } from './lib/QtWidgets/QLayout';
|
||||
export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea';
|
||||
export { QAbstractSlider } from './lib/QtWidgets/QAbstractSlider';
|
||||
export { QAbstractButton } from './lib/QtWidgets/QAbstractButton';
|
||||
export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton';
|
||||
// Widgets:
|
||||
export { QWidget } from './lib/QtWidgets/QWidget';
|
||||
export { QCheckBox } from './lib/QtWidgets/QCheckBox';
|
||||
export { QLabel } from './lib/QtWidgets/QLabel';
|
||||
export { QDial } from './lib/QtWidgets/QDial';
|
||||
export { QFileDialog } from './lib/QtWidgets/QFileDialog';
|
||||
export { QLineEdit, EchoMode } from './lib/QtWidgets/QLineEdit';
|
||||
export { QMainWindow } from './lib/QtWidgets/QMainWindow';
|
||||
export { QProgressBar } from './lib/QtWidgets/QProgressBar';
|
||||
export { QComboBox, InsertPolicy } from './lib/QtWidgets/QComboBox';
|
||||
export { QPushButton } from './lib/QtWidgets/QPushButton';
|
||||
export { QToolButton, ToolButtonPopupMode } from './lib/QtWidgets/QToolButton';
|
||||
export { QSpinBox } from './lib/QtWidgets/QSpinBox';
|
||||
export { QRadioButton } from './lib/QtWidgets/QRadioButton';
|
||||
export { QStackedWidget } from './lib/QtWidgets/QStackedWidget';
|
||||
export { QTabWidget } from './lib/QtWidgets/QTabWidget';
|
||||
export { QTableWidget } from './lib/QtWidgets/QTableWidget';
|
||||
export { QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget';
|
||||
export { QCheckBox, QCheckBoxSignals } from './lib/QtWidgets/QCheckBox';
|
||||
export { QLabel, QLabelSignals } from './lib/QtWidgets/QLabel';
|
||||
export { QDial, QDialSignals } from './lib/QtWidgets/QDial';
|
||||
export { QFileDialog, QFileDialogSignals } from './lib/QtWidgets/QFileDialog';
|
||||
export { QLineEdit, QLineEditSignals, EchoMode } from './lib/QtWidgets/QLineEdit';
|
||||
export { QMainWindow, QMainWindowSignals } from './lib/QtWidgets/QMainWindow';
|
||||
export { QProgressBar, QProgressBarSignals } from './lib/QtWidgets/QProgressBar';
|
||||
export { QComboBox, QComboBoxSignals, InsertPolicy } from './lib/QtWidgets/QComboBox';
|
||||
export { QPushButton, QPushButtonSignals } from './lib/QtWidgets/QPushButton';
|
||||
export { QToolButton, QToolButtonSignals, ToolButtonPopupMode } from './lib/QtWidgets/QToolButton';
|
||||
export { QSpinBox, QSpinBoxSignals } from './lib/QtWidgets/QSpinBox';
|
||||
export { QRadioButton, QRadioButtonSignals } from './lib/QtWidgets/QRadioButton';
|
||||
export { QStackedWidget, QStackedWidgetSignals } from './lib/QtWidgets/QStackedWidget';
|
||||
export { QTabWidget, QTabWidgetSignals } from './lib/QtWidgets/QTabWidget';
|
||||
export { QTableWidget, QTableWidgetSignals } from './lib/QtWidgets/QTableWidget';
|
||||
export { QTableWidgetItem } from './lib/QtWidgets/QTableWidgetItem';
|
||||
export { QMenu } from './lib/QtWidgets/QMenu';
|
||||
export { QMenuBar } from './lib/QtWidgets/QMenuBar';
|
||||
export { QPlainTextEdit, LineWrapMode } from './lib/QtWidgets/QPlainTextEdit';
|
||||
export { QScrollArea } from './lib/QtWidgets/QScrollArea';
|
||||
export { QTreeWidget } from './lib/QtWidgets/QTreeWidget';
|
||||
export { QMenu, QMenuSignals } from './lib/QtWidgets/QMenu';
|
||||
export { QMenuBar, QMenuBarSignals } from './lib/QtWidgets/QMenuBar';
|
||||
export { QPlainTextEdit, QPlainTextEditSignals, LineWrapMode } from './lib/QtWidgets/QPlainTextEdit';
|
||||
export { QScrollArea, QScrollAreaSignals } from './lib/QtWidgets/QScrollArea';
|
||||
export { QTreeWidget, QTreeWidgetSignals } from './lib/QtWidgets/QTreeWidget';
|
||||
export { QTreeWidgetItem } from './lib/QtWidgets/QTreeWidgetItem';
|
||||
export { QPainter, RenderHint } from './lib/QtWidgets/QPainter';
|
||||
|
||||
export { QSystemTrayIcon, QSystemTrayIconActivationReason } from './lib/QtWidgets/QSystemTrayIcon';
|
||||
export { QAction } from './lib/QtWidgets/QAction';
|
||||
export { QShortcut } from './lib/QtWidgets/QShortcut';
|
||||
export { QGroupBox } from './lib/QtWidgets/QGroupBox';
|
||||
export {
|
||||
QSystemTrayIcon,
|
||||
QSystemTrayIconSignals,
|
||||
QSystemTrayIconActivationReason,
|
||||
} from './lib/QtWidgets/QSystemTrayIcon';
|
||||
export { QAction, QActionSignals } from './lib/QtWidgets/QAction';
|
||||
export { QShortcut, QShortcutSignals } from './lib/QtWidgets/QShortcut';
|
||||
export { QGroupBox, QGroupBoxSignals } from './lib/QtWidgets/QGroupBox';
|
||||
// Core
|
||||
export { QObject, NodeObject } from './lib/QtCore/QObject';
|
||||
export { QObject, QObjectSignals, NodeObject } from './lib/QtCore/QObject';
|
||||
export { QVariant } from './lib/QtCore/QVariant';
|
||||
export { QSize } from './lib/QtCore/QSize';
|
||||
export { QRect } from './lib/QtCore/QRect';
|
||||
@ -62,9 +66,9 @@ export { QPoint } from './lib/QtCore/QPoint';
|
||||
export { QColor } from './lib/QtCore/QColor';
|
||||
export { QUrl, ParsingMode } from './lib/QtCore/QUrl';
|
||||
// Layouts:
|
||||
export { QBoxLayout } from './lib/QtWidgets/QBoxLayout';
|
||||
export { QGridLayout } from './lib/QtWidgets/QGridLayout';
|
||||
export { FlexLayout } from './lib/core/FlexLayout';
|
||||
export { QBoxLayout, QBoxLayoutSignals } from './lib/QtWidgets/QBoxLayout';
|
||||
export { QGridLayout, QGridLayoutSignals } from './lib/QtWidgets/QGridLayout';
|
||||
export { FlexLayout, FlexLayoutSignals } from './lib/core/FlexLayout';
|
||||
// Others:
|
||||
export { StyleSheet } from './lib/core/Style/StyleSheet';
|
||||
export { NativeElement, Component } from './lib/core/Component';
|
||||
|
||||
@ -2,15 +2,14 @@ import { EventWidget } from '../core/EventWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import addon from '../utils/addon';
|
||||
import { QVariant } from './QVariant';
|
||||
import { QVariant, QVariantType } from './QVariant';
|
||||
|
||||
export abstract class NodeObject<Signals> extends EventWidget<Signals> {
|
||||
inherits(className: string): boolean {
|
||||
return this.native.inherits(className);
|
||||
}
|
||||
setProperty(name: string, value: any): boolean {
|
||||
const finalValue = value.native || value;
|
||||
return this.native.setProperty(name, finalValue);
|
||||
setProperty(name: string, value: QVariantType): boolean {
|
||||
return this.native.setProperty(name, value);
|
||||
}
|
||||
property(name: string): QVariant {
|
||||
const nativeVariant = this.native.property(name);
|
||||
@ -24,6 +23,10 @@ export abstract class NodeObject<Signals> extends EventWidget<Signals> {
|
||||
}
|
||||
}
|
||||
|
||||
export interface QObjectSignals {
|
||||
objectNameChanged: (objectName: string) => void;
|
||||
}
|
||||
|
||||
export class QObject extends NodeObject<QObjectSignals> {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
@ -45,5 +48,3 @@ export class QObject extends NodeObject<QObjectSignals> {
|
||||
this.native = native;
|
||||
}
|
||||
}
|
||||
|
||||
type QObjectSignals = {};
|
||||
|
||||
@ -2,7 +2,7 @@ import { NativeElement, Component } from '../core/Component';
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
|
||||
type QVariantType = Component | string | number | boolean;
|
||||
export type QVariantType = NativeElement | string | number | boolean;
|
||||
|
||||
export class QVariant extends Component {
|
||||
native: NativeElement;
|
||||
@ -11,11 +11,10 @@ export class QVariant extends Component {
|
||||
constructor(variant: QVariantType);
|
||||
constructor(arg?: QVariantType | NativeElement) {
|
||||
super();
|
||||
if (checkIfNativeElement(arg)) {
|
||||
if (checkIfNativeElement(arg) && arg instanceof addon.QVariant) {
|
||||
this.native = arg as NativeElement;
|
||||
} else if (arg) {
|
||||
const component = (arg as Component).native || arg;
|
||||
this.native = new addon.QVariant(component);
|
||||
this.native = new addon.QVariant.converToQVariant(arg);
|
||||
} else {
|
||||
this.native = new addon.QVariant();
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ describe('QColor', () => {
|
||||
|
||||
it('initialize from QVariant', () => {
|
||||
const color = new QColor(10, 10, 10);
|
||||
const variant = new QVariant(color);
|
||||
const variant = new QVariant(color.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QColor.fromQVariant(variant).red()).toBe(10);
|
||||
});
|
||||
|
||||
@ -27,7 +27,7 @@ describe('QPoint', () => {
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const point = new QPoint(10, 10);
|
||||
const variant = new QVariant(point);
|
||||
const variant = new QVariant(point.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QPoint.fromQVariant(variant).x()).toBe(point.x());
|
||||
});
|
||||
|
||||
@ -32,7 +32,7 @@ describe('QRect', () => {
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const rect = new QRect(10, 10, 300, 200);
|
||||
const variant = new QVariant(rect);
|
||||
const variant = new QVariant(rect.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QRect.fromQVariant(variant).left()).toBe(rect.left());
|
||||
});
|
||||
|
||||
@ -22,7 +22,7 @@ describe('QSize', () => {
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const size = new QSize(300, 200);
|
||||
const variant = new QVariant(size);
|
||||
const variant = new QVariant(size.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QSize.fromQVariant(variant).height()).toBe(size.height());
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ describe('QUrl', () => {
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const url = new QUrl('https://google.com');
|
||||
const variant = new QVariant(url);
|
||||
const variant = new QVariant(url.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QUrl.fromQVariant(variant).toString()).toBe('https://google.com');
|
||||
});
|
||||
|
||||
@ -29,7 +29,7 @@ describe('QVariant', () => {
|
||||
});
|
||||
it('initialize with complex objects', () => {
|
||||
const pixmap = new QPixmap(path.resolve(__dirname, 'nodegui.png'));
|
||||
const variant = new QVariant(pixmap);
|
||||
const variant = new QVariant(pixmap.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QPixmap.fromQVariant(variant).height()).toBe(pixmap.height());
|
||||
});
|
||||
|
||||
@ -75,7 +75,7 @@ export class QMovie extends NodeObject<QMovieSignals> {
|
||||
}
|
||||
}
|
||||
|
||||
interface QMovieSignals {
|
||||
export interface QMovieSignals {
|
||||
error: (error: ImageReaderError) => void;
|
||||
finished: () => void;
|
||||
frameChanged: (frameNumber?: number) => void;
|
||||
|
||||
@ -19,7 +19,7 @@ describe('QIcon', () => {
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const icon = new QIcon(testImagePath);
|
||||
const variant = new QVariant(icon);
|
||||
const variant = new QVariant(icon.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QIcon.fromQVariant(variant).cacheKey()).toBe(icon.cacheKey());
|
||||
});
|
||||
|
||||
@ -24,7 +24,7 @@ describe('QPixmap', () => {
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
const variant = new QVariant(pixmap);
|
||||
const variant = new QVariant(pixmap.native);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QPixmap.fromQVariant(variant).height()).toBe(pixmap.height());
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NodeWidget, QWidgetSignals } from './QWidget';
|
||||
import { QIcon } from '../QtGui/QIcon';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
|
||||
@ -17,3 +17,9 @@ export abstract class QAbstractButton<Signals> extends NodeWidget<Signals> {
|
||||
return QSize.fromQVariant(iconSize);
|
||||
}
|
||||
}
|
||||
export interface QAbstractButtonSignals extends QWidgetSignals {
|
||||
clicked: (checked: boolean) => void;
|
||||
pressed: () => void;
|
||||
released: () => void;
|
||||
toggled: (checked: boolean) => void;
|
||||
}
|
||||
|
||||
@ -6,8 +6,9 @@ import { QIcon } from '../QtGui/QIcon';
|
||||
import { QKeySequence } from '../QtGui/QKeySequence';
|
||||
import { ShortcutContext } from '../QtEnums';
|
||||
import { NodeObject } from '../QtCore/QObject';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
|
||||
interface QActionSignals {
|
||||
export interface QActionSignals {
|
||||
triggered: (checked: boolean) => void;
|
||||
changed: () => void;
|
||||
hovered: () => void;
|
||||
@ -19,10 +20,13 @@ export class QAction extends NodeObject<QActionSignals> {
|
||||
icon?: QIcon;
|
||||
menu?: QMenu;
|
||||
constructor();
|
||||
constructor(native: NativeElement);
|
||||
constructor(parent: NodeWidget<any>);
|
||||
constructor(parent?: NodeWidget<any>) {
|
||||
constructor(parent?: NativeElement | NodeWidget<any>) {
|
||||
let native;
|
||||
if (parent) {
|
||||
if (checkIfNativeElement(parent)) {
|
||||
native = parent as NativeElement;
|
||||
} else if (parent) {
|
||||
native = new addon.QAction(parent.native);
|
||||
} else {
|
||||
native = new addon.QAction();
|
||||
|
||||
@ -4,7 +4,7 @@ import { NodeLayout } from './QLayout';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { Direction } from '../QtEnums';
|
||||
|
||||
type QBoxLayoutSignals = {};
|
||||
export type QBoxLayoutSignals = {};
|
||||
export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
|
||||
native: NativeElement;
|
||||
childLayouts: Set<NodeLayout<any>>;
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractButton } from './QAbstractButton';
|
||||
import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton';
|
||||
|
||||
interface QCheckBoxSignals {
|
||||
//List all Signals below
|
||||
toggled: (checked: boolean) => void;
|
||||
}
|
||||
export type QCheckBoxSignals = QAbstractButtonSignals;
|
||||
|
||||
export class QCheckBox extends QAbstractButton<QCheckBoxSignals> {
|
||||
native: NativeElement;
|
||||
|
||||
@ -5,7 +5,7 @@ import { SizeAdjustPolicy } from '../QtEnums';
|
||||
import { QIcon } from '../QtGui/QIcon';
|
||||
import { QVariant } from '../QtCore/QVariant';
|
||||
|
||||
interface QComboBoxSignals {
|
||||
export interface QComboBoxSignals {
|
||||
//List all Signals below
|
||||
currentIndexChanged: (index: number) => void;
|
||||
currentTextChanged: (text: string) => void;
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractSlider } from './QAbstractSlider';
|
||||
|
||||
interface QDialSignals {
|
||||
export interface QDialSignals {
|
||||
valueChanged: (value: number) => void;
|
||||
rangeChanged: (min: number, max: number) => void;
|
||||
sliderMoved: (value: number) => void;
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { AcceptMode, DialogLabel, FileMode, Option, ViewMode } from '../QtEnums';
|
||||
|
||||
interface QFileDialogSignals {
|
||||
export interface QFileDialogSignals {
|
||||
currentChanged: (path: string) => void;
|
||||
currentUrlChanged: (url: string) => void;
|
||||
directoryEntered: (directory: string) => void;
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import { NodeLayout } from './QLayout';
|
||||
import { NativeElement } from '../core/Component';
|
||||
|
||||
type QGridLayoutSignals = {};
|
||||
export type QGridLayoutSignals = {};
|
||||
|
||||
export class QGridLayout extends NodeLayout<QGridLayoutSignals> {
|
||||
native: NativeElement;
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { AlignmentFlag } from '../QtEnums/AlignmentFlag';
|
||||
|
||||
interface QGroupBoxSignals {
|
||||
export interface QGroupBoxSignals {
|
||||
clicked: (checked: boolean) => void;
|
||||
toggled: (on: boolean) => void;
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NodeWidget, QWidgetSignals } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QPixmap } from '../QtGui/QPixmap';
|
||||
import { QMovie } from '../QtGui/QMovie';
|
||||
import { AlignmentFlag } from '../QtEnums/AlignmentFlag';
|
||||
import { TextFormat } from '../QtEnums/TextFormat';
|
||||
|
||||
type QLabelSignals = {};
|
||||
export type QLabelSignals = QWidgetSignals;
|
||||
export class QLabel extends NodeWidget<QLabelSignals> {
|
||||
native: NativeElement;
|
||||
private _pixmap?: QPixmap;
|
||||
|
||||
@ -8,7 +8,7 @@ export enum EchoMode {
|
||||
Password,
|
||||
PasswordEchoOnEdit,
|
||||
}
|
||||
interface QLineEditSignals {
|
||||
export interface QLineEditSignals {
|
||||
cursorPositionChanged: (oldPos: number, newPos: number) => void;
|
||||
editingFinished: () => void;
|
||||
inputRejected: () => void;
|
||||
|
||||
@ -4,7 +4,7 @@ import { NativeElement } from '../core/Component';
|
||||
import { NodeLayout } from './QLayout';
|
||||
import { QMenuBar } from './QMenuBar';
|
||||
|
||||
type QMainWindowSignals = {};
|
||||
export type QMainWindowSignals = {};
|
||||
export class QMainWindow extends NodeWidget<QMainWindowSignals> {
|
||||
native: NativeElement;
|
||||
public centralWidget?: NodeWidget<any> | null;
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import addon from '../utils/addon';
|
||||
import { QAction } from './QAction';
|
||||
|
||||
type QMenuSignals = {};
|
||||
export type QMenuSignals = {};
|
||||
export class QMenu extends NodeWidget<QMenuSignals> {
|
||||
native: NativeElement;
|
||||
actions: Set<QAction>;
|
||||
|
||||
@ -4,7 +4,7 @@ import { NodeWidget } from './QWidget';
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
|
||||
type QMenuBarSignals = {};
|
||||
export type QMenuBarSignals = {};
|
||||
|
||||
export class QMenuBar extends NodeWidget<QMenuBarSignals> {
|
||||
native: NativeElement;
|
||||
|
||||
@ -4,7 +4,7 @@ import { NativeElement } from '../core/Component';
|
||||
import { QAbstractScrollArea } from './QAbstractScrollArea';
|
||||
import { QTextOptionWrapMode } from '../QtGui/QTextOption';
|
||||
|
||||
interface QPlainTextEditSignals {
|
||||
export interface QPlainTextEditSignals {
|
||||
textChanged: () => void;
|
||||
blockCountChanged: (blockCount: number) => void;
|
||||
copyAvailable: (yes: boolean) => void;
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { Orientation } from '../QtEnums';
|
||||
|
||||
type QProgressBarSignals = {};
|
||||
export type QProgressBarSignals = {};
|
||||
export class QProgressBar extends NodeWidget<QProgressBarSignals> {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractButton } from './QAbstractButton';
|
||||
import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton';
|
||||
|
||||
interface QPushButtonSignals {
|
||||
clicked: (checked: boolean) => void;
|
||||
pressed: () => void;
|
||||
released: () => void;
|
||||
toggled: (checked: boolean) => void;
|
||||
}
|
||||
export type QPushButtonSignals = QAbstractButtonSignals;
|
||||
|
||||
export class QPushButton extends QAbstractButton<QPushButtonSignals> {
|
||||
native: NativeElement;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractButton } from './QAbstractButton';
|
||||
import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton';
|
||||
|
||||
type QRadioButtonSignals = {};
|
||||
export type QRadioButtonSignals = QAbstractButtonSignals;
|
||||
export class QRadioButton extends QAbstractButton<QRadioButtonSignals> {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
|
||||
@ -3,7 +3,7 @@ import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractScrollArea } from './QAbstractScrollArea';
|
||||
|
||||
type QScrollAreaSignals = {};
|
||||
export type QScrollAreaSignals = {};
|
||||
export class QScrollArea extends QAbstractScrollArea<QScrollAreaSignals> {
|
||||
native: NativeElement;
|
||||
contentWidget?: NodeWidget<any> | null;
|
||||
|
||||
@ -5,7 +5,7 @@ import { QKeySequence } from '../QtGui/QKeySequence';
|
||||
import { ShortcutContext } from '../QtEnums';
|
||||
import { NodeObject } from '../QtCore/QObject';
|
||||
|
||||
interface QShortcutSignals {
|
||||
export interface QShortcutSignals {
|
||||
activated: () => void;
|
||||
activatedAmbiguously: () => void;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
|
||||
interface QSpinBoxSignals {
|
||||
export interface QSpinBoxSignals {
|
||||
valueChanged: (value: number) => void;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
|
||||
interface QStackedWidgetSignals {
|
||||
export interface QStackedWidgetSignals {
|
||||
currentChanged: (index: number) => void;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import { QIcon } from '../QtGui/QIcon';
|
||||
import { QMenu } from './QMenu';
|
||||
import { NodeObject } from '../QtCore/QObject';
|
||||
|
||||
interface QSystemTrayIconSignals {
|
||||
export interface QSystemTrayIconSignals {
|
||||
activated: (reason: QSystemTrayIconActivationReason) => void;
|
||||
messageClicked: () => void;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import { NativeElement } from '../core/Component';
|
||||
import { QIcon } from '../QtGui/QIcon';
|
||||
import { TabPosition } from '../QtEnums';
|
||||
|
||||
interface QTabWidgetSignals {
|
||||
export interface QTabWidgetSignals {
|
||||
currentChanged: (index: number) => void;
|
||||
tabBarClicked: (index: number) => void;
|
||||
tabBarDoubleClicked: (index: number) => void;
|
||||
|
||||
@ -5,7 +5,7 @@ import { ScrollHint, SortOrder } from '../QtEnums';
|
||||
import { QTableWidgetItem } from './QTableWidgetItem';
|
||||
import { QAbstractScrollArea } from './QAbstractScrollArea';
|
||||
|
||||
interface QTableWidgetSignals {
|
||||
export interface QTableWidgetSignals {
|
||||
cellActivated: (row: number, col: number) => void;
|
||||
cellChanged: (row: number, col: number) => void;
|
||||
cellClicked: (row: number, col: number) => void;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractButton } from './QAbstractButton';
|
||||
import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton';
|
||||
import { ToolButtonStyle } from '../QtEnums/ToolButtonStyle';
|
||||
import { ArrowType } from '../QtEnums/ArrowType';
|
||||
import { QAction } from '../QtWidgets/QAction';
|
||||
@ -13,11 +13,7 @@ export enum ToolButtonPopupMode {
|
||||
InstantPopup,
|
||||
}
|
||||
|
||||
interface QToolButtonSignals {
|
||||
clicked: (checked: boolean) => void;
|
||||
pressed: () => void;
|
||||
released: () => void;
|
||||
toggled: (checked: boolean) => void;
|
||||
export interface QToolButtonSignals extends QAbstractButtonSignals {
|
||||
triggered: (nativeAction: NativeElement) => void;
|
||||
}
|
||||
export class QToolButton extends QAbstractButton<QToolButtonSignals> {
|
||||
|
||||
@ -4,7 +4,7 @@ import { NativeElement } from '../core/Component';
|
||||
import { QAbstractScrollArea } from './QAbstractScrollArea';
|
||||
import { QTreeWidgetItem } from './QTreeWidgetItem';
|
||||
|
||||
interface QTreeWidgetSignals {
|
||||
export interface QTreeWidgetSignals {
|
||||
itemSelectionChanged: () => void;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import addon from '../utils/addon';
|
||||
import { NodeLayout } from './QLayout';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { FlexLayout } from '../core/FlexLayout';
|
||||
import { WidgetAttribute, WindowType } from '../QtEnums';
|
||||
import { WidgetAttribute, WindowType, ContextMenuPolicy } from '../QtEnums';
|
||||
import { QIcon } from '../QtGui/QIcon';
|
||||
import { QCursor } from '../QtGui/QCursor';
|
||||
import { CursorShape, WindowState } from '../QtEnums';
|
||||
@ -11,6 +11,7 @@ import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { YogaWidget } from '../core/YogaWidget';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
import { QRect } from '../QtCore/QRect';
|
||||
import { QObjectSignals } from '../QtCore/QObject';
|
||||
// All Widgets should extend from NodeWidget
|
||||
// Implement all native QWidget methods here so that all widgets get access to those aswell
|
||||
export abstract class NodeWidget<Signals> extends YogaWidget<Signals> {
|
||||
@ -157,6 +158,9 @@ export abstract class NodeWidget<Signals> extends YogaWidget<Signals> {
|
||||
this.setInlineStyle(this._rawInlineStyle);
|
||||
}
|
||||
}
|
||||
setContextMenuPolicy(contextMenuPolicy: ContextMenuPolicy): void {
|
||||
this.setProperty('contextMenuPolicy', contextMenuPolicy);
|
||||
}
|
||||
showFullScreen(): void {
|
||||
this.native.showFullScreen();
|
||||
}
|
||||
@ -171,7 +175,11 @@ export abstract class NodeWidget<Signals> extends YogaWidget<Signals> {
|
||||
}
|
||||
}
|
||||
|
||||
type QWidgetSignals = {};
|
||||
export interface QWidgetSignals extends QObjectSignals {
|
||||
windowTitleChanged: (title: string) => void;
|
||||
windowIconChanged: (iconNative: NativeElement) => void;
|
||||
customContextMenuRequested: (pos: { x: number; y: number }) => void;
|
||||
}
|
||||
export class QWidget extends NodeWidget<QWidgetSignals> {
|
||||
native: NativeElement;
|
||||
constructor(arg?: NodeWidget<QWidgetSignals> | NativeElement) {
|
||||
|
||||
@ -37,4 +37,20 @@ describe('QCheckBox', () => {
|
||||
expect(returnedSize.width()).toBe(111);
|
||||
expect(returnedSize.height()).toBe(111);
|
||||
});
|
||||
it('check if signals are working from QObject', () => {
|
||||
const widget = new QCheckBox();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('objectNameChanged', mock);
|
||||
widget.setObjectName('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
it('check if signals are working from QWidget', () => {
|
||||
const widget = new QCheckBox();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('windowTitleChanged', mock);
|
||||
widget.setWindowTitle('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -35,4 +35,20 @@ describe('QLabel', () => {
|
||||
label.setMovie(movie);
|
||||
expect(label.movie()).toEqual(movie);
|
||||
});
|
||||
it('check if signals are working', () => {
|
||||
const widget = new QLabel();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('objectNameChanged', mock);
|
||||
widget.setObjectName('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
it('check if signals are working from QWidget', () => {
|
||||
const widget = new QLabel();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('windowTitleChanged', mock);
|
||||
widget.setWindowTitle('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -35,4 +35,20 @@ describe('QPushButton', () => {
|
||||
expect(returnedSize.width()).toBe(111);
|
||||
expect(returnedSize.height()).toBe(111);
|
||||
});
|
||||
it('check if signals are working', () => {
|
||||
const widget = new QPushButton();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('objectNameChanged', mock);
|
||||
widget.setObjectName('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
it('check if signals are working from QWidget', () => {
|
||||
const widget = new QPushButton();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('windowTitleChanged', mock);
|
||||
widget.setWindowTitle('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -30,4 +30,20 @@ describe('QRadioButton', () => {
|
||||
expect(returnedSize.width()).toBe(111);
|
||||
expect(returnedSize.height()).toBe(111);
|
||||
});
|
||||
it('check if signals are working', () => {
|
||||
const widget = new QRadioButton();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('objectNameChanged', mock);
|
||||
widget.setObjectName('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
it('check if signals are working from QWidget', () => {
|
||||
const widget = new QRadioButton();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('windowTitleChanged', mock);
|
||||
widget.setWindowTitle('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
49
src/lib/QtWidgets/__tests__/QToolButton.test.ts
Normal file
49
src/lib/QtWidgets/__tests__/QToolButton.test.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { QToolButton } from '../QToolButton';
|
||||
import { QIcon } from '../../QtGui/QIcon';
|
||||
import path from 'path';
|
||||
import { QSize } from '../../QtCore/QSize';
|
||||
|
||||
describe('QToolButton', () => {
|
||||
it('instantiate a button instance', () => {
|
||||
const button = new QToolButton();
|
||||
expect(button.inherits('QToolButton')).toBe(true);
|
||||
});
|
||||
it('setText', () => {
|
||||
const button = new QToolButton();
|
||||
button.setText('hello');
|
||||
expect(button.property('text').toString()).toEqual('hello');
|
||||
});
|
||||
it('setIcon', () => {
|
||||
const button = new QToolButton();
|
||||
const testImagePath = path.resolve(__dirname, 'assets', 'nodegui.png');
|
||||
const icon = new QIcon(testImagePath);
|
||||
button.setIcon(icon);
|
||||
expect(QIcon.fromQVariant(button.property('icon')).cacheKey()).toEqual(icon.cacheKey());
|
||||
});
|
||||
it('setIconSize', () => {
|
||||
const button = new QToolButton();
|
||||
const testImagePath = path.resolve(__dirname, 'assets', 'nodegui.png');
|
||||
const icon = new QIcon(testImagePath);
|
||||
button.setIcon(icon);
|
||||
button.setIconSize(new QSize(111, 111));
|
||||
const returnedSize = button.iconSize();
|
||||
expect(returnedSize.width()).toBe(111);
|
||||
expect(returnedSize.height()).toBe(111);
|
||||
});
|
||||
it('check if signals are working', () => {
|
||||
const widget = new QToolButton();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('objectNameChanged', mock);
|
||||
widget.setObjectName('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
it('check if signals are working from QWidget', () => {
|
||||
const widget = new QToolButton();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('windowTitleChanged', mock);
|
||||
widget.setWindowTitle('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@ -82,4 +82,20 @@ describe('QWidget', () => {
|
||||
view.setWindowOpacity(0.6);
|
||||
expect(view.windowOpacity().toFixed(1)).toBe(`0.6`);
|
||||
});
|
||||
it('check if signals are working', () => {
|
||||
const widget = new QWidget();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('objectNameChanged', mock);
|
||||
widget.setObjectName('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
it('check if signals are working from QWidget', () => {
|
||||
const widget = new QWidget();
|
||||
const mock = jest.fn();
|
||||
widget.addEventListener('windowTitleChanged', mock);
|
||||
widget.setWindowTitle('testName');
|
||||
expect(mock).toBeCalledWith('testName');
|
||||
expect(mock).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,7 +4,7 @@ import { NodeLayout } from '../QtWidgets/QLayout';
|
||||
import { FlexNode } from './YogaWidget';
|
||||
import { NativeElement } from './Component';
|
||||
|
||||
type FlexLayoutSignals = {};
|
||||
export type FlexLayoutSignals = {};
|
||||
export class FlexLayout extends NodeLayout<FlexLayoutSignals> {
|
||||
native: NativeElement;
|
||||
protected flexNode?: FlexNode;
|
||||
|
||||
@ -107,7 +107,7 @@ public:
|
||||
using QPushButton::QPushButton; //inherit all constructors of QPushButton
|
||||
|
||||
// override this method and implement all signals here
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QPushButton::clicked, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
@ -145,4 +145,4 @@ We need to run Qt's MOC (Meta Object Compiler) on the file whenever we use Q_OBJ
|
||||
|
||||
1. On JS side for each widget instance we create an instance of NodeJS's Event Emitter. This is done by the class `EventWidget` from which `NodeWidget` inherits
|
||||
2. We send this event emiiter's `emit` function to the C++ side by calling `initNodeEventEmitter` method and store a pointer to the event emitter's emit function using `emitOnNode`. initNodeEventEmitter function is added by a macro from EventWidget (c++). You can find the initNodeEventEmitter method with the event widget macros.
|
||||
3. We setup Qt's connect method for all the signals that we want to listen to and call the emitOnNode (which is actually emit from Event emitter) whenever a signal arrives. This is done manually on every widget by overriding the method `connectWidgetSignalsToEventEmitter`. Check `npushbutton.h` for details. This takes care of all the signals of the widgets. Now to export all qt events of the widget, we had overriden the widgets `event(Event*)` method to listen to events received by the widget and send it to the event emitter. This is done inside the EVENTWIDGET_IMPLEMENTATIONS macro
|
||||
3. We setup Qt's connect method for all the signals that we want to listen to and call the emitOnNode (which is actually emit from Event emitter) whenever a signal arrives. This is done manually on every widget by overriding the method `connectSignalsToEventEmitter`. Check `npushbutton.h` for details. This takes care of all the signals of the widgets. Now to export all qt events of the widget, we had overriden the widgets `event(Event*)` method to listen to events received by the widget and send it to the event emitter. This is done inside the EVENTWIDGET_IMPLEMENTATIONS macro
|
||||
|
||||
Loading…
Reference in New Issue
Block a user