* fix issue #473 * fix ts lint Co-authored-by: wuxiaofeng <wuxiaofeng@erayt.com>
This commit is contained in:
parent
117be556cf
commit
e09333c948
@ -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), \
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
@ -164,7 +164,7 @@ 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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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