Merge branch 'master' of https://github.com/nodegui/nodegui
This commit is contained in:
commit
e5d8c5cb48
@ -46,7 +46,7 @@ https://github.com/nodegui/examples
|
||||
- 🕵️♂️ Good Devtools support.
|
||||
- 📚 Good documentation and website.
|
||||
- 🧙♂️ Good documentation for contributors.
|
||||
- 🦹🏻♀️ Good support for dark mode (Thanks to QT).
|
||||
- 🦹🏻♀️ Good support for dark mode (Thanks to Qt).
|
||||
- 🏅First class Typescript support. (Works on regular JS projects too 😉).
|
||||
|
||||
## Getting Started
|
||||
|
||||
2424
package-lock.json
generated
2424
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,10 @@ class DLL_EXPORT QBoxLayoutWrap : public Napi::ObjectWrap<QBoxLayoutWrap> {
|
||||
Napi::Value insertWidget(const Napi::CallbackInfo& info);
|
||||
Napi::Value direction(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertLayout(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertSpacing(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertStretch(const Napi::CallbackInfo& info);
|
||||
Napi::Value removeWidget(const Napi::CallbackInfo& info);
|
||||
Napi::Value setDirection(const Napi::CallbackInfo& info);
|
||||
Napi::Value setStretch(const Napi::CallbackInfo& info);
|
||||
Napi::Value count(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
@ -12,26 +12,49 @@
|
||||
*/
|
||||
|
||||
#ifndef QLAYOUT_WRAPPED_METHODS_DECLARATION
|
||||
#define QLAYOUT_WRAPPED_METHODS_DECLARATION \
|
||||
QOBJECT_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value activate(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool wasRedone = this->instance->activate(); \
|
||||
return Napi::Boolean::New(env, wasRedone); \
|
||||
} \
|
||||
Napi::Value invalidate(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->invalidate(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value update(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->update(); \
|
||||
return env.Null(); \
|
||||
#define QLAYOUT_WRAPPED_METHODS_DECLARATION \
|
||||
QOBJECT_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value activate(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool wasRedone = this->instance->activate(); \
|
||||
return Napi::Boolean::New(env, wasRedone); \
|
||||
} \
|
||||
Napi::Value setEnabled(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool enable = info[0].As<Napi::Boolean>().Value(); \
|
||||
this->instance->setEnabled(enable); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value isEnabled(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool enabled = this->instance->isEnabled(); \
|
||||
return Napi::Boolean::New(env, enabled); \
|
||||
} \
|
||||
Napi::Value setContentsMargins(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int left = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int top = info[1].As<Napi::Number>().Int32Value(); \
|
||||
int right = info[2].As<Napi::Number>().Int32Value(); \
|
||||
int bottom = info[3].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setContentsMargins(left, top, right, bottom); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value invalidate(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->invalidate(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value update(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->update(); \
|
||||
return env.Null(); \
|
||||
}
|
||||
|
||||
#endif // QLAYOUT_WRAPPED_METHODS_DECLARATION
|
||||
@ -41,6 +64,10 @@
|
||||
\
|
||||
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(LayoutWrapName) \
|
||||
InstanceMethod("activate", &LayoutWrapName::activate), \
|
||||
InstanceMethod("setEnabled", &LayoutWrapName::setEnabled), \
|
||||
InstanceMethod("isEnabled", &LayoutWrapName::isEnabled), \
|
||||
InstanceMethod("setContentsMargins", \
|
||||
&LayoutWrapName::setContentsMargins), \
|
||||
InstanceMethod("invalidate", &LayoutWrapName::invalidate), \
|
||||
InstanceMethod("update", &LayoutWrapName::update),
|
||||
|
||||
|
||||
@ -36,10 +36,9 @@ class DLL_EXPORT QTreeWidgetWrap : public Napi::ObjectWrap<QTreeWidgetWrap> {
|
||||
Napi::Value setItemWidget(const Napi::CallbackInfo &info);
|
||||
Napi::Value currentItem(const Napi::CallbackInfo &info);
|
||||
Napi::Value findItems(const Napi::CallbackInfo &info);
|
||||
Napi::Value takeTopLevelItem(const Napi::CallbackInfo &info);
|
||||
Napi::Value clear(const Napi::CallbackInfo &info);
|
||||
|
||||
// Napi::Value addTopLevelItems(const Napi::CallbackInfo& info);
|
||||
// Napi::Value setHorizontalScrollBarPolicy(const Napi::CallbackInfo& info);
|
||||
// Napi::Value setVerticalScrollBarPolicy(const Napi::CallbackInfo& info);
|
||||
// Napi::Value takeTopLevelItem(const Napi::CallbackInfo& info);
|
||||
// Napi::Value findItems(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <QStyle>
|
||||
|
||||
#include "QtCore/QObject/qobject_macro.h"
|
||||
#include "QtCore/QPoint/qpoint_wrap.h"
|
||||
#include "QtCore/QSize/qsize_wrap.h"
|
||||
#include "QtGui/QIcon/qicon_wrap.h"
|
||||
#include "QtWidgets/QAction/qaction_wrap.h"
|
||||
@ -17,322 +18,364 @@
|
||||
*/
|
||||
|
||||
#ifndef QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
QOBJECT_WRAPPED_METHODS_DECLARATION \
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value show(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->show(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value resize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number width = info[0].As<Napi::Number>(); \
|
||||
Napi::Number height = info[1].As<Napi::Number>(); \
|
||||
this->instance->resize(width.Int32Value(), height.Int32Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value close(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool hasClosed = this->instance->close(); \
|
||||
return Napi::Boolean::New(env, hasClosed); \
|
||||
} \
|
||||
Napi::Value isVisible(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool isVisible = this->instance->isVisible(); \
|
||||
return Napi::Boolean::New(env, isVisible); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setLayout(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object layoutObject = info[0].As<Napi::Object>(); \
|
||||
QLayoutWrap* layoutWrap = \
|
||||
Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject); \
|
||||
this->instance->setLayout(layoutWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setStyleSheet(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::String text = info[0].As<Napi::String>(); \
|
||||
std::string style = text.Utf8Value(); \
|
||||
QString newStyle = QString::fromStdString(style); \
|
||||
QString currentStyleSheet = this->instance->styleSheet(); \
|
||||
if (newStyle != currentStyleSheet) { \
|
||||
this->instance->setStyleSheet(newStyle); \
|
||||
} \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setCursor(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number cursor = info[0].As<Napi::Number>(); \
|
||||
this->instance->setCursor( \
|
||||
static_cast<Qt::CursorShape>(cursor.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowIcon(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object iconObject = info[0].As<Napi::Object>(); \
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject); \
|
||||
this->instance->setWindowIcon(*iconWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowState(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number state = info[0].As<Napi::Number>(); \
|
||||
this->instance->setWindowState( \
|
||||
static_cast<Qt::WindowState>(state.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value windowState(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int state = static_cast<int>(this->instance->windowState()); \
|
||||
return Napi::Value::From(env, state); \
|
||||
} \
|
||||
Napi::Value setWindowTitle(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::String napiTitle = info[0].As<Napi::String>(); \
|
||||
std::string title = napiTitle.Utf8Value(); \
|
||||
this->instance->setWindowTitle(title.c_str()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value windowTitle(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QString title = this->instance->windowTitle(); \
|
||||
return Napi::String::New(env, title.toStdString()); \
|
||||
} \
|
||||
Napi::Value styleSheet(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QString stylesheet = this->instance->styleSheet(); \
|
||||
return Napi::String::New(env, stylesheet.toStdString()); \
|
||||
} \
|
||||
Napi::Value hide(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->hide(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value move(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int x = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int y = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->move(x, y); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setMouseTracking(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Boolean isMouseTracked = info[0].As<Napi::Boolean>(); \
|
||||
this->instance->setMouseTracking(isMouseTracked.Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value hasMouseTracking(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool isMouseTracked = this->instance->hasMouseTracking(); \
|
||||
return Napi::Value::From(env, isMouseTracked); \
|
||||
} \
|
||||
Napi::Value setEnabled(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Boolean enabled = info[0].As<Napi::Boolean>(); \
|
||||
this->instance->setEnabled(enabled.Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value isEnabled(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool enabled = this->instance->isEnabled(); \
|
||||
return Napi::Value::From(env, enabled); \
|
||||
} \
|
||||
Napi::Value setFixedSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int width = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setFixedSize(width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setGeometry(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int x = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int y = info[1].As<Napi::Number>().Int32Value(); \
|
||||
int width = info[2].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[3].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setGeometry(x, y, width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setMaximumSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int width = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setMaximumSize(width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setMinimumSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int width = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setMinimumSize(width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value repaint(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->repaint(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value update(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->update(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value updateGeometry(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->updateGeometry(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value pos(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QPoint pos = this->instance->pos(); \
|
||||
Napi::Object posObj = Napi::Object::New(env); \
|
||||
posObj.Set("x", pos.x()); \
|
||||
posObj.Set("y", pos.y()); \
|
||||
return posObj; \
|
||||
} \
|
||||
Napi::Value size(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QSize size = this->instance->size(); \
|
||||
auto sizeWrap = QSizeWrap::constructor.New({Napi::External<QSize>::New( \
|
||||
env, new QSize(size.width(), size.height()))}); \
|
||||
return sizeWrap; \
|
||||
} \
|
||||
Napi::Value setAttribute(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int attributeId = info[0].As<Napi::Number>().Int32Value(); \
|
||||
bool switchOn = info[1].As<Napi::Boolean>().Value(); \
|
||||
this->instance->setAttribute( \
|
||||
static_cast<Qt::WidgetAttribute>(attributeId), switchOn); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value testAttribute(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int attributeId = info[0].As<Napi::Number>().Int32Value(); \
|
||||
bool isOn = this->instance->testAttribute( \
|
||||
static_cast<Qt::WidgetAttribute>(attributeId)); \
|
||||
return Napi::Boolean::New(env, isOn); \
|
||||
} \
|
||||
Napi::Value setWindowOpacity(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
float opacity = info[0].As<Napi::Number>().FloatValue(); \
|
||||
this->instance->setWindowOpacity(opacity); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value windowOpacity(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
float opacity = this->instance->windowOpacity(); \
|
||||
return Napi::Value::From(env, opacity); \
|
||||
} \
|
||||
Napi::Value setWindowFlag(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int windowType = info[0].As<Napi::Number>().Int32Value(); \
|
||||
bool switchOn = info[1].As<Napi::Boolean>().Value(); \
|
||||
this->instance->setWindowFlag(static_cast<Qt::WindowType>(windowType), \
|
||||
switchOn); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value adjustSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->adjustSize(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value activateWindow(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->activateWindow(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value raise(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->raise(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value lower(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->lower(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showFullScreen(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showFullScreen(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showMaximized(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showMaximized(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showMinimized(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showMinimized(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showNormal(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showNormal(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value addAction(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object actionObject = info[0].As<Napi::Object>(); \
|
||||
QActionWrap* actionWrap = \
|
||||
Napi::ObjectWrap<QActionWrap>::Unwrap(actionObject); \
|
||||
this->instance->addAction(actionWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value repolish(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->style()->unpolish(this->instance); \
|
||||
this->instance->style()->polish(this->instance); \
|
||||
return env.Null(); \
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
QOBJECT_WRAPPED_METHODS_DECLARATION \
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value show(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->show(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value resize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number width = info[0].As<Napi::Number>(); \
|
||||
Napi::Number height = info[1].As<Napi::Number>(); \
|
||||
this->instance->resize(width.Int32Value(), height.Int32Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value close(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool hasClosed = this->instance->close(); \
|
||||
return Napi::Boolean::New(env, hasClosed); \
|
||||
} \
|
||||
Napi::Value mapFromGlobal(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object posObject = info[0].As<Napi::Object>(); \
|
||||
QPointWrap* posWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(posObject); \
|
||||
QPoint pt = \
|
||||
this->instance->mapFromGlobal(*posWrap->getInternalInstance()); \
|
||||
auto instance = QPointWrap::constructor.New( \
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value mapFromParent(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object posObject = info[0].As<Napi::Object>(); \
|
||||
QPointWrap* posWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(posObject); \
|
||||
QPoint pt = \
|
||||
this->instance->mapFromParent(*posWrap->getInternalInstance()); \
|
||||
auto instance = QPointWrap::constructor.New( \
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value mapToGlobal(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object posObject = info[0].As<Napi::Object>(); \
|
||||
QPointWrap* posWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(posObject); \
|
||||
QPoint pt = this->instance->mapToGlobal(*posWrap->getInternalInstance()); \
|
||||
auto instance = QPointWrap::constructor.New( \
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value mapToParent(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object posObject = info[0].As<Napi::Object>(); \
|
||||
QPointWrap* posWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(posObject); \
|
||||
QPoint pt = this->instance->mapToParent(*posWrap->getInternalInstance()); \
|
||||
auto instance = QPointWrap::constructor.New( \
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value isVisible(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool isVisible = this->instance->isVisible(); \
|
||||
return Napi::Boolean::New(env, isVisible); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setLayout(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object layoutObject = info[0].As<Napi::Object>(); \
|
||||
QLayoutWrap* layoutWrap = \
|
||||
Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject); \
|
||||
this->instance->setLayout(layoutWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setStyleSheet(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::String text = info[0].As<Napi::String>(); \
|
||||
std::string style = text.Utf8Value(); \
|
||||
QString newStyle = QString::fromStdString(style); \
|
||||
QString currentStyleSheet = this->instance->styleSheet(); \
|
||||
if (newStyle != currentStyleSheet) { \
|
||||
this->instance->setStyleSheet(newStyle); \
|
||||
} \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setCursor(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number cursor = info[0].As<Napi::Number>(); \
|
||||
this->instance->setCursor( \
|
||||
static_cast<Qt::CursorShape>(cursor.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowIcon(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object iconObject = info[0].As<Napi::Object>(); \
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject); \
|
||||
this->instance->setWindowIcon(*iconWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowState(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number state = info[0].As<Napi::Number>(); \
|
||||
this->instance->setWindowState( \
|
||||
static_cast<Qt::WindowState>(state.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value windowState(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int state = static_cast<int>(this->instance->windowState()); \
|
||||
return Napi::Value::From(env, state); \
|
||||
} \
|
||||
Napi::Value setWindowTitle(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::String napiTitle = info[0].As<Napi::String>(); \
|
||||
std::string title = napiTitle.Utf8Value(); \
|
||||
this->instance->setWindowTitle(title.c_str()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value windowTitle(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QString title = this->instance->windowTitle(); \
|
||||
return Napi::String::New(env, title.toStdString()); \
|
||||
} \
|
||||
Napi::Value styleSheet(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QString stylesheet = this->instance->styleSheet(); \
|
||||
return Napi::String::New(env, stylesheet.toStdString()); \
|
||||
} \
|
||||
Napi::Value hide(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->hide(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value move(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int x = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int y = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->move(x, y); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setMouseTracking(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Boolean isMouseTracked = info[0].As<Napi::Boolean>(); \
|
||||
this->instance->setMouseTracking(isMouseTracked.Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value hasMouseTracking(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool isMouseTracked = this->instance->hasMouseTracking(); \
|
||||
return Napi::Value::From(env, isMouseTracked); \
|
||||
} \
|
||||
Napi::Value setEnabled(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Boolean enabled = info[0].As<Napi::Boolean>(); \
|
||||
this->instance->setEnabled(enabled.Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value isEnabled(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
bool enabled = this->instance->isEnabled(); \
|
||||
return Napi::Value::From(env, enabled); \
|
||||
} \
|
||||
Napi::Value setFixedSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int width = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setFixedSize(width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setGeometry(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int x = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int y = info[1].As<Napi::Number>().Int32Value(); \
|
||||
int width = info[2].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[3].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setGeometry(x, y, width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setMaximumSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int width = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setMaximumSize(width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setMinimumSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int width = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int height = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setMinimumSize(width, height); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value repaint(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->repaint(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value update(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->update(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value updateGeometry(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->updateGeometry(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value pos(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QPoint pos = this->instance->pos(); \
|
||||
Napi::Object posObj = Napi::Object::New(env); \
|
||||
posObj.Set("x", pos.x()); \
|
||||
posObj.Set("y", pos.y()); \
|
||||
return posObj; \
|
||||
} \
|
||||
Napi::Value size(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QSize size = this->instance->size(); \
|
||||
auto sizeWrap = QSizeWrap::constructor.New({Napi::External<QSize>::New( \
|
||||
env, new QSize(size.width(), size.height()))}); \
|
||||
return sizeWrap; \
|
||||
} \
|
||||
Napi::Value setAttribute(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int attributeId = info[0].As<Napi::Number>().Int32Value(); \
|
||||
bool switchOn = info[1].As<Napi::Boolean>().Value(); \
|
||||
this->instance->setAttribute( \
|
||||
static_cast<Qt::WidgetAttribute>(attributeId), switchOn); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value testAttribute(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int attributeId = info[0].As<Napi::Number>().Int32Value(); \
|
||||
bool isOn = this->instance->testAttribute( \
|
||||
static_cast<Qt::WidgetAttribute>(attributeId)); \
|
||||
return Napi::Boolean::New(env, isOn); \
|
||||
} \
|
||||
Napi::Value setWindowOpacity(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
float opacity = info[0].As<Napi::Number>().FloatValue(); \
|
||||
this->instance->setWindowOpacity(opacity); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value windowOpacity(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
float opacity = this->instance->windowOpacity(); \
|
||||
return Napi::Value::From(env, opacity); \
|
||||
} \
|
||||
Napi::Value setWindowFlag(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int windowType = info[0].As<Napi::Number>().Int32Value(); \
|
||||
bool switchOn = info[1].As<Napi::Boolean>().Value(); \
|
||||
this->instance->setWindowFlag(static_cast<Qt::WindowType>(windowType), \
|
||||
switchOn); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value adjustSize(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->adjustSize(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value activateWindow(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->activateWindow(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value raise(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->raise(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value lower(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->lower(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showFullScreen(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showFullScreen(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showMaximized(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showMaximized(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showMinimized(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showMinimized(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value showNormal(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->showNormal(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value addAction(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object actionObject = info[0].As<Napi::Object>(); \
|
||||
QActionWrap* actionWrap = \
|
||||
Napi::ObjectWrap<QActionWrap>::Unwrap(actionObject); \
|
||||
this->instance->addAction(actionWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value repolish(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->style()->unpolish(this->instance); \
|
||||
this->instance->style()->polish(this->instance); \
|
||||
return env.Null(); \
|
||||
}
|
||||
|
||||
#endif // QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
@ -346,6 +389,10 @@
|
||||
InstanceMethod("resize", &WidgetWrapName::resize), \
|
||||
InstanceMethod("isVisible", &WidgetWrapName::isVisible), \
|
||||
InstanceMethod("close", &WidgetWrapName::close), \
|
||||
InstanceMethod("mapFromGlobal", &WidgetWrapName::mapFromGlobal), \
|
||||
InstanceMethod("mapFromParent", &WidgetWrapName::mapFromParent), \
|
||||
InstanceMethod("mapToGlobal", &WidgetWrapName::mapToGlobal), \
|
||||
InstanceMethod("mapToParent", &WidgetWrapName::mapToParent), \
|
||||
InstanceMethod("setLayout", &WidgetWrapName::setLayout), \
|
||||
InstanceMethod("setStyleSheet", &WidgetWrapName::setStyleSheet), \
|
||||
InstanceMethod("setCursor", &WidgetWrapName::setCursor), \
|
||||
|
||||
@ -18,8 +18,12 @@ Napi::Object QBoxLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("insertWidget", &QBoxLayoutWrap::insertWidget),
|
||||
InstanceMethod("direction", &QBoxLayoutWrap::direction),
|
||||
InstanceMethod("insertLayout", &QBoxLayoutWrap::insertLayout),
|
||||
InstanceMethod("insertSpacing", &QBoxLayoutWrap::insertSpacing),
|
||||
InstanceMethod("insertStretch", &QBoxLayoutWrap::insertStretch),
|
||||
InstanceMethod("removeWidget", &QBoxLayoutWrap::removeWidget),
|
||||
InstanceMethod("setDirection", &QBoxLayoutWrap::setDirection),
|
||||
InstanceMethod("setStretch", &QBoxLayoutWrap::setStretch),
|
||||
InstanceMethod("count", &QBoxLayoutWrap::count),
|
||||
QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QBoxLayoutWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -131,6 +135,26 @@ Napi::Value QBoxLayoutWrap::insertLayout(const Napi::CallbackInfo& info) {
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QBoxLayoutWrap::insertSpacing(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
int size = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance->insertSpacing(index, size);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QBoxLayoutWrap::insertStretch(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
int stretch = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance->insertStretch(index, stretch);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QBoxLayoutWrap::removeWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
@ -149,4 +173,22 @@ Napi::Value QBoxLayoutWrap::setDirection(const Napi::CallbackInfo& info) {
|
||||
info[0].As<Napi::Number>().Int32Value());
|
||||
this->instance->setDirection(dir);
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QBoxLayoutWrap::setStretch(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
int stretch = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance->setStretch(index, stretch);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QBoxLayoutWrap::count(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int count = this->instance->count();
|
||||
return Napi::Number::New(env, count);
|
||||
}
|
||||
|
||||
@ -73,22 +73,24 @@ Napi::Value QMenuWrap::exec(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 2) {
|
||||
if (info.Length() > 0) {
|
||||
Napi::Object pointObject = info[0].As<Napi::Object>();
|
||||
QPointWrap* pointWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(pointObject);
|
||||
QPoint* qpoint = pointWrap->getInternalInstance();
|
||||
|
||||
Napi::Object actionObject = info[1].As<Napi::Object>();
|
||||
QActionWrap* actionWrap =
|
||||
Napi::ObjectWrap<QActionWrap>::Unwrap(actionObject);
|
||||
this->instance->exec(*qpoint, actionWrap->getInternalInstance());
|
||||
QAction* action = nullptr;
|
||||
if (info.Length() == 2) {
|
||||
Napi::Object actionObject = info[1].As<Napi::Object>();
|
||||
QActionWrap* actionWrap =
|
||||
Napi::ObjectWrap<QActionWrap>::Unwrap(actionObject);
|
||||
action = actionWrap->getInternalInstance();
|
||||
}
|
||||
this->instance->exec(*pointWrap->getInternalInstance(), action);
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance->exec();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,8 @@ Napi::Object QTreeWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("setItemWidget", &QTreeWidgetWrap::setItemWidget),
|
||||
InstanceMethod("currentItem", &QTreeWidgetWrap::currentItem),
|
||||
InstanceMethod("findItems", &QTreeWidgetWrap::findItems),
|
||||
InstanceMethod("takeTopLevelItem", &QTreeWidgetWrap::takeTopLevelItem),
|
||||
InstanceMethod("clear", &QTreeWidgetWrap::clear),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QTreeWidgetWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -213,12 +215,15 @@ Napi::Value QTreeWidgetWrap::currentItem(const Napi::CallbackInfo& info) {
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
QTreeWidgetItem* currentItem = this->instance->currentItem();
|
||||
if (currentItem != nullptr) {
|
||||
Napi::Object value = QTreeWidgetItemWrap::constructor.New(
|
||||
{Napi::External<QTreeWidgetItem>::New(
|
||||
env, new QTreeWidgetItem(*currentItem))});
|
||||
|
||||
Napi::Object value = QTreeWidgetItemWrap::constructor.New(
|
||||
{Napi::External<QTreeWidgetItem>::New(
|
||||
env, new QTreeWidgetItem(*currentItem))});
|
||||
|
||||
return value;
|
||||
return value;
|
||||
} else {
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QTreeWidgetWrap::findItems(const Napi::CallbackInfo& info) {
|
||||
@ -242,3 +247,29 @@ Napi::Value QTreeWidgetWrap::findItems(const Napi::CallbackInfo& info) {
|
||||
}
|
||||
return napiItems;
|
||||
}
|
||||
|
||||
Napi::Value QTreeWidgetWrap::takeTopLevelItem(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
|
||||
QTreeWidgetItem* itemRemoved = this->instance->takeTopLevelItem(index);
|
||||
|
||||
if (itemRemoved != nullptr) {
|
||||
Napi::Object value = QTreeWidgetItemWrap::constructor.New(
|
||||
{Napi::External<QTreeWidgetItem>::New(
|
||||
env, new QTreeWidgetItem(*itemRemoved))});
|
||||
|
||||
return value;
|
||||
} else {
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QTreeWidgetWrap::clear(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->instance->clear();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
17
src/demo.ts
17
src/demo.ts
@ -1,16 +1,33 @@
|
||||
import { QMainWindow, QLabel, WidgetEventTypes, QMouseEvent } from './index';
|
||||
import { QPoint } from './lib/QtCore/QPoint';
|
||||
import { ContextMenuPolicy } from './lib/QtEnums';
|
||||
import { QMenu } from './lib/QtWidgets/QMenu';
|
||||
import { QAction } from './lib/QtWidgets/QAction';
|
||||
|
||||
const win = new QMainWindow();
|
||||
|
||||
const label = new QLabel();
|
||||
label.setText('Move your mouse here');
|
||||
label.setMouseTracking(true);
|
||||
label.setContextMenuPolicy(ContextMenuPolicy.CustomContextMenu);
|
||||
|
||||
label.addEventListener(WidgetEventTypes.MouseMove, (nativeEvt) => {
|
||||
const mouseEvt = new QMouseEvent(nativeEvt as any);
|
||||
console.log('mouseMoved at: ', { x: mouseEvt.x(), y: mouseEvt.y() });
|
||||
});
|
||||
|
||||
label.addEventListener('customContextMenuRequested', (pos: { x: number; y: number }): void => {
|
||||
console.log(pos);
|
||||
const position = new QPoint(pos.x, pos.y);
|
||||
const menu = new QMenu();
|
||||
const action = new QAction();
|
||||
|
||||
action.setText(`Hello World`);
|
||||
menu.addAction(action);
|
||||
const ptGlobal = label.mapToGlobal(position);
|
||||
menu.exec(ptGlobal);
|
||||
});
|
||||
|
||||
win.setCentralWidget(label);
|
||||
win.show();
|
||||
(global as any).win = win;
|
||||
|
||||
@ -22,7 +22,7 @@ export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent';
|
||||
export { WidgetEventTypes } from './lib/core/EventWidget';
|
||||
// Abstract:
|
||||
export { NodeWidget, QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget';
|
||||
export { NodeLayout, QLayoutSignals } from './lib/QtWidgets/QLayout';
|
||||
export { NodeLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout';
|
||||
export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea';
|
||||
export { QAbstractSlider, QAbstractSliderSignals } from './lib/QtWidgets/QAbstractSlider';
|
||||
export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton';
|
||||
@ -100,6 +100,7 @@ export { QShortcut, QShortcutSignals } from './lib/QtWidgets/QShortcut';
|
||||
export { QGroupBox, QGroupBoxSignals } from './lib/QtWidgets/QGroupBox';
|
||||
export { QStatusBar, QStatusBarSignals } from './lib/QtWidgets/QStatusBar';
|
||||
export { QStandardItemModel, QStandardItemModelSignals } from './lib/QtWidgets/QStandardItemModel';
|
||||
export { QStandardItem } from './lib/QtWidgets/QStandardItem';
|
||||
// Core
|
||||
export { QDate } from './lib/QtCore/QDate';
|
||||
export { QDateTime } from './lib/QtCore/QDateTime';
|
||||
|
||||
@ -57,18 +57,18 @@ describe('QPixmap', () => {
|
||||
});
|
||||
it('save to a file', async () => {
|
||||
const outputFilePath = path.resolve(__dirname, 'assets', 'nodegui_save.png');
|
||||
await new Promise(resolve => fs.unlink(outputFilePath, resolve));
|
||||
await new Promise((resolve) => fs.unlink(outputFilePath, resolve));
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
pixmap.save(outputFilePath);
|
||||
const exists = await new Promise(resolve => fs.exists(outputFilePath, resolve));
|
||||
const exists = await new Promise((resolve) => fs.exists(outputFilePath, resolve));
|
||||
expect(exists).toBe(true);
|
||||
});
|
||||
it('save to a file of different format', async () => {
|
||||
const outputFilePath = path.resolve(__dirname, 'assets', 'nodegui_save.jpg');
|
||||
await new Promise(resolve => fs.unlink(outputFilePath, resolve));
|
||||
await new Promise((resolve) => fs.unlink(outputFilePath, resolve));
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
pixmap.save(outputFilePath, 'JPG');
|
||||
const exists = await new Promise(resolve => fs.exists(outputFilePath, resolve));
|
||||
const exists = await new Promise((resolve) => fs.exists(outputFilePath, resolve));
|
||||
expect(exists).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@ -70,6 +70,12 @@ export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
|
||||
this.native.insertLayout(index, layout.native, stretch);
|
||||
this.childLayouts.add(layout);
|
||||
}
|
||||
insertSpacing(index: number, size: number): void {
|
||||
this.native.insertSpacing(index, size);
|
||||
}
|
||||
insertStretch(index: number, stretch = 0): void {
|
||||
this.native.insertStretch(index, stretch);
|
||||
}
|
||||
removeWidget(widget: NodeWidget<any>): void {
|
||||
this.native.removeWidget(widget.native);
|
||||
this.nodeChildren.delete(widget);
|
||||
@ -77,6 +83,12 @@ export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
|
||||
setDirection(dir: Direction): void {
|
||||
this.native.setDirection(dir);
|
||||
}
|
||||
setStretch(index: number, stretch: number): void {
|
||||
this.native.setStretch(index, stretch);
|
||||
}
|
||||
count(): number {
|
||||
return this.native.count();
|
||||
}
|
||||
}
|
||||
|
||||
export type QBoxLayoutSignals = QLayoutSignals;
|
||||
|
||||
@ -36,9 +36,30 @@ export abstract class NodeLayout<Signals extends QLayoutSignals> extends NodeObj
|
||||
type = 'layout';
|
||||
abstract addWidget(childWidget: NodeWidget<any>, ...args: any[]): void;
|
||||
abstract removeWidget(childWidget: NodeWidget<any>): void;
|
||||
setSizeConstraint(constraint: SizeConstraint): void {
|
||||
this.setProperty('sizeConstraint', constraint);
|
||||
}
|
||||
sizeConstraint(): SizeConstraint {
|
||||
return this.property('sizeConstraint').toInt();
|
||||
}
|
||||
setSpacing(spacing: number): void {
|
||||
this.setProperty('spacing', spacing);
|
||||
}
|
||||
spacing(): number {
|
||||
return this.property('spacing').toInt();
|
||||
}
|
||||
activate(): boolean {
|
||||
return this.native.activate();
|
||||
}
|
||||
setEnabled(enable: boolean): void {
|
||||
this.native.setEnabled(enable);
|
||||
}
|
||||
isEnabled(): boolean {
|
||||
return this.native.isEnabled();
|
||||
}
|
||||
setContentsMargins(left: number, top: number, right: number, bottom: number): void {
|
||||
this.native.setContentsMargins(left, top, right, bottom);
|
||||
}
|
||||
invalidate(): void {
|
||||
this.native.invalidate();
|
||||
}
|
||||
@ -51,4 +72,13 @@ export abstract class NodeLayout<Signals extends QLayoutSignals> extends NodeObj
|
||||
// native: any;
|
||||
// }
|
||||
|
||||
export enum SizeConstraint {
|
||||
SetDefaultConstraint = 0,
|
||||
SetNoConstraint = 1,
|
||||
SetMinimumSize = 2,
|
||||
SetFixedSize = 3,
|
||||
SetMaximumSize = 4,
|
||||
SetMinAndMaxSize = 5,
|
||||
}
|
||||
|
||||
export type QLayoutSignals = QObjectSignals;
|
||||
|
||||
@ -81,7 +81,7 @@ export class QListWidget extends NodeListView<QListWidgetSignals> {
|
||||
}
|
||||
findItems(text: string, flags: MatchFlag): QListWidgetItem[] {
|
||||
const nativeItems = this.native.findItems(text, flags);
|
||||
return nativeItems.map(function(item: QListWidgetItem) {
|
||||
return nativeItems.map(function (item: QListWidgetItem) {
|
||||
return new QListWidgetItem(item);
|
||||
});
|
||||
}
|
||||
@ -115,7 +115,7 @@ export class QListWidget extends NodeListView<QListWidgetSignals> {
|
||||
}
|
||||
selectedItems(): QListWidgetItem[] {
|
||||
const nativeItems = this.native.selectedItems();
|
||||
return nativeItems.map(function(item: QListWidgetItem) {
|
||||
return nativeItems.map(function (item: QListWidgetItem) {
|
||||
return new QListWidgetItem(item);
|
||||
});
|
||||
}
|
||||
|
||||
@ -36,16 +36,17 @@ export class QMenu extends NodeWidget<QMenuSignals> {
|
||||
setTitle(title: string): void {
|
||||
this.native.setTitle(title);
|
||||
}
|
||||
|
||||
addSeparator(): QAction {
|
||||
return this.native.addSeparator();
|
||||
}
|
||||
exec(point?: QPoint, action?: QAction): void {
|
||||
exec(point?: QPoint, action?: QAction | null): void {
|
||||
if (point && action) {
|
||||
this.native.exec(point.native, action.native);
|
||||
return;
|
||||
} else if (point) {
|
||||
this.native.exec(point.native);
|
||||
} else {
|
||||
this.native.exec();
|
||||
}
|
||||
this.native.exec();
|
||||
}
|
||||
popup(point: QPoint, action?: QAction): void {
|
||||
this.native.popup(point.native, action?.native);
|
||||
|
||||
@ -94,7 +94,7 @@ export class QPainter extends Component {
|
||||
}
|
||||
|
||||
drawConvexPolygon(points: QPoint[]): void {
|
||||
const nativePoints = points.map(point => point.native);
|
||||
const nativePoints = points.map((point) => point.native);
|
||||
this.native.drawConvexPolygon(nativePoints);
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
|
||||
|
||||
addTopLevelItems(items: QTreeWidgetItem[]): void {
|
||||
const napiItems: NativeElement[] = [];
|
||||
items.forEach(item => {
|
||||
items.forEach((item) => {
|
||||
this.topLevelItems.add(item);
|
||||
napiItems.push(item.native);
|
||||
});
|
||||
@ -89,7 +89,7 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
|
||||
|
||||
insertTopLevelItems(index: number, items: QTreeWidgetItem[]): void {
|
||||
const napiItems: NativeElement[] = [];
|
||||
items.forEach(item => {
|
||||
items.forEach((item) => {
|
||||
this.topLevelItems.add(item);
|
||||
napiItems.push(item.native);
|
||||
});
|
||||
@ -102,7 +102,7 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
|
||||
|
||||
selectedItems(): QTreeWidgetItem[] {
|
||||
const nativeItems = this.native.selectedItems();
|
||||
return nativeItems.map(function(eachItem: QTreeWidgetItem) {
|
||||
return nativeItems.map(function (eachItem: QTreeWidgetItem) {
|
||||
return new QTreeWidgetItem(eachItem);
|
||||
});
|
||||
}
|
||||
@ -145,8 +145,13 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
|
||||
/**
|
||||
* Returns the current item in the tree widget.
|
||||
*/
|
||||
currentItem(): QTreeWidgetItem {
|
||||
return new QTreeWidgetItem(this.native.currentItem());
|
||||
currentItem(): QTreeWidgetItem | void {
|
||||
const item = this.native.currentItem();
|
||||
if (item) {
|
||||
return new QTreeWidgetItem(item);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,10 +164,24 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
|
||||
|
||||
findItems(text: string, flags: MatchFlag, column: number): QTreeWidgetItem[] {
|
||||
const nativeItems = this.native.findItems(text, flags, column);
|
||||
return nativeItems.map(function(eachItem: QTreeWidgetItem) {
|
||||
return nativeItems.map(function (eachItem: QTreeWidgetItem) {
|
||||
return new QTreeWidgetItem(eachItem);
|
||||
});
|
||||
}
|
||||
|
||||
takeTopLevelItem(index: number): QTreeWidgetItem | void {
|
||||
const item = this.native.takeTopLevelItem(index);
|
||||
if (item) {
|
||||
return new QTreeWidgetItem(item);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.topLevelItems.clear();
|
||||
this.native.clear();
|
||||
}
|
||||
}
|
||||
|
||||
export interface QTreeWidgetSignals extends QAbstractScrollAreaSignals {
|
||||
|
||||
@ -9,6 +9,7 @@ import { CursorShape, WindowState } from '../QtEnums';
|
||||
import { StyleSheet, prepareInlineStyleSheet } from '../core/Style/StyleSheet';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { YogaWidget } from '../core/YogaWidget';
|
||||
import { QPoint } from '../QtCore/QPoint';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
import { QRect } from '../QtCore/QRect';
|
||||
import { QObjectSignals } from '../QtCore/QObject';
|
||||
@ -73,6 +74,18 @@ export abstract class NodeWidget<Signals extends QWidgetSignals> extends YogaWid
|
||||
close(): boolean {
|
||||
return this.native.close();
|
||||
}
|
||||
mapFromGlobal(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapFromGlobal(pos.native));
|
||||
}
|
||||
mapFromParent(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapFromParent(pos.native));
|
||||
}
|
||||
mapToGlobal(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapToGlobal(pos.native));
|
||||
}
|
||||
mapToParent(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapToParent(pos.native));
|
||||
}
|
||||
setStyleSheet(styleSheet: string): void {
|
||||
const preparedSheet = StyleSheet.create(styleSheet);
|
||||
this.native.setStyleSheet(preparedSheet);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user