Adds QSize and few more test cases for pixmap, qsize and qvariant (#194)
* Adds qsize, qvariant adn qpixmap testcases * lint
This commit is contained in:
parent
8f26fd515b
commit
e3667c0bbd
@ -44,6 +44,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QVariant/qvariant_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QSize/qsize_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp"
|
||||
|
||||
31
src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h
Normal file
31
src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QSize>
|
||||
|
||||
#include "core/Component/component_macro.h"
|
||||
|
||||
class QSizeWrap : public Napi::ObjectWrap<QSizeWrap> {
|
||||
private:
|
||||
std::unique_ptr<QSize> instance;
|
||||
|
||||
public:
|
||||
static Napi::FunctionReference constructor;
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QSizeWrap(const Napi::CallbackInfo& info);
|
||||
~QSizeWrap();
|
||||
QSize* getInternalInstance();
|
||||
// Wrapped methods
|
||||
Napi::Value setHeight(const Napi::CallbackInfo& info);
|
||||
Napi::Value setWidth(const Napi::CallbackInfo& info);
|
||||
Napi::Value height(const Napi::CallbackInfo& info);
|
||||
Napi::Value width(const Napi::CallbackInfo& info);
|
||||
|
||||
COMPONENT_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
namespace StaticQSizeWrapMethods {
|
||||
Napi::Value fromQVariant(const Napi::CallbackInfo& info);
|
||||
} // namespace StaticQSizeWrapMethods
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QSize>
|
||||
|
||||
#include "QtCore/QObject/qobject_macro.h"
|
||||
#include "QtCore/QSize/qsize_wrap.h"
|
||||
#include "QtGui/QIcon/qicon_wrap.h"
|
||||
#include "QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "core/YogaWidget/yogawidget_macro.h"
|
||||
@ -14,254 +15,253 @@
|
||||
*/
|
||||
|
||||
#ifndef QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
QOBJECT_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(); \
|
||||
this->instance->setStyleSheet(style.c_str()); \
|
||||
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 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 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 geometry(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QRect geometry = this->instance->geometry(); \
|
||||
Napi::Object geometryObj = Napi::Object::New(env); \
|
||||
geometryObj.Set("width", geometry.width()); \
|
||||
geometryObj.Set("height", geometry.height()); \
|
||||
geometryObj.Set("x", geometry.x()); \
|
||||
geometryObj.Set("y", geometry.y()); \
|
||||
return geometryObj; \
|
||||
} \
|
||||
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(); \
|
||||
Napi::Object sizeObj = Napi::Object::New(env); \
|
||||
sizeObj.Set("width", size.width()); \
|
||||
sizeObj.Set("height", size.height()); \
|
||||
return sizeObj; \
|
||||
} \
|
||||
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(); \
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
QOBJECT_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(); \
|
||||
this->instance->setStyleSheet(style.c_str()); \
|
||||
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 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 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 geometry(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QRect geometry = this->instance->geometry(); \
|
||||
Napi::Object geometryObj = Napi::Object::New(env); \
|
||||
geometryObj.Set("width", geometry.width()); \
|
||||
geometryObj.Set("height", geometry.height()); \
|
||||
geometryObj.Set("x", geometry.x()); \
|
||||
geometryObj.Set("y", geometry.y()); \
|
||||
return geometryObj; \
|
||||
} \
|
||||
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(); \
|
||||
}
|
||||
|
||||
#endif // QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
86
src/cpp/lib/QtCore/QSize/qsize_wrap.cpp
Normal file
86
src/cpp/lib/QtCore/QSize/qsize_wrap.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include "QtCore/QSize/qsize_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QVariant/qvariant_wrap.h"
|
||||
|
||||
Napi::FunctionReference QSizeWrap::constructor;
|
||||
|
||||
Napi::Object QSizeWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QSize";
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("setHeight", &QSizeWrap::setHeight),
|
||||
InstanceMethod("setWidth", &QSizeWrap::setWidth),
|
||||
InstanceMethod("height", &QSizeWrap::height),
|
||||
InstanceMethod("width", &QSizeWrap::width),
|
||||
StaticMethod("fromQVariant", &StaticQSizeWrapMethods::fromQVariant),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QSizeWrap::QSizeWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QSizeWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 2) {
|
||||
int width = info[0].As<Napi::Number>().Int32Value();
|
||||
int height = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance = std::make_unique<QSize>(width, height);
|
||||
} else if (info.Length() == 1) {
|
||||
this->instance =
|
||||
std::unique_ptr<QSize>(info[0].As<Napi::External<QSize>>().Data());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<QSize>();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
this->rawData = this->getInternalInstance();
|
||||
}
|
||||
|
||||
QSizeWrap::~QSizeWrap() { this->instance.reset(); }
|
||||
|
||||
QSize* QSizeWrap::getInternalInstance() { return this->instance.get(); }
|
||||
|
||||
Napi::Value QSizeWrap::setHeight(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int height = info[0].As<Napi::Number>().Int32Value();
|
||||
this->instance->setHeight(height);
|
||||
return env.Null();
|
||||
}
|
||||
Napi::Value QSizeWrap::setWidth(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int width = info[0].As<Napi::Number>().Int32Value();
|
||||
this->instance->setWidth(width);
|
||||
return env.Null();
|
||||
}
|
||||
Napi::Value QSizeWrap::height(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
return Napi::Value::From(env, this->instance->height());
|
||||
}
|
||||
Napi::Value QSizeWrap::width(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
return Napi::Value::From(env, this->instance->width());
|
||||
}
|
||||
|
||||
Napi::Value StaticQSizeWrapMethods::fromQVariant(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Object variantObject = info[0].As<Napi::Object>();
|
||||
QVariantWrap* variantWrap =
|
||||
Napi::ObjectWrap<QVariantWrap>::Unwrap(variantObject);
|
||||
QVariant* variant = variantWrap->getInternalInstance();
|
||||
QSize size = variant->value<QSize>();
|
||||
auto instance = QSizeWrap::constructor.New({Napi::External<QSize>::New(
|
||||
env, new QSize(size.width(), size.height()))});
|
||||
return instance;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
#include <napi.h>
|
||||
|
||||
#include "QtCore/QObject/qobject_wrap.h"
|
||||
#include "QtCore/QSize/qsize_wrap.h"
|
||||
#include "QtCore/QVariant/qvariant_wrap.h"
|
||||
#include "QtGui/QApplication/qapplication_wrap.h"
|
||||
#include "QtGui/QClipboard/qclipboard_wrap.h"
|
||||
@ -40,6 +41,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QApplicationWrap::init(env, exports);
|
||||
QObjectWrap::init(env, exports);
|
||||
QVariantWrap::init(env, exports);
|
||||
QSizeWrap::init(env, exports);
|
||||
QClipboardWrap::init(env, exports);
|
||||
QWidgetWrap::init(env, exports);
|
||||
QPixmapWrap::init(env, exports);
|
||||
|
||||
@ -40,6 +40,7 @@ export { QShortcut, QShortcutEvents } from './lib/QtWidgets/QShortcut';
|
||||
// Core
|
||||
export { QObject, NodeObject } from './lib/QtCore/QObject';
|
||||
export { QVariant } from './lib/QtCore/QVariant';
|
||||
export { QSize } from './lib/QtCore/QSize';
|
||||
// Layouts:
|
||||
export { QGridLayout } from './lib/QtWidgets/QGridLayout';
|
||||
export { FlexLayout } from './lib/core/FlexLayout';
|
||||
|
||||
35
src/lib/QtCore/QSize.ts
Normal file
35
src/lib/QtCore/QSize.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { NativeElement, Component } from '../core/Component';
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { QVariant } from './QVariant';
|
||||
|
||||
type argument = number | NativeElement;
|
||||
|
||||
export class QSize extends Component {
|
||||
native: NativeElement;
|
||||
constructor(arg?: argument, height?: number) {
|
||||
super();
|
||||
if (!arg) {
|
||||
this.native = new addon.QSize();
|
||||
} else if (checkIfNativeElement(arg)) {
|
||||
this.native = arg as NativeElement;
|
||||
} else {
|
||||
this.native = new addon.QSize(arg, height);
|
||||
}
|
||||
}
|
||||
setWidth(width: number): void {
|
||||
return this.native.setWidth(width);
|
||||
}
|
||||
width(): number {
|
||||
return this.native.width();
|
||||
}
|
||||
setHeight(height: number): void {
|
||||
return this.native.setHeight(height);
|
||||
}
|
||||
height(): number {
|
||||
return this.native.height();
|
||||
}
|
||||
static fromQVariant(variant: QVariant): QSize {
|
||||
return addon.QSize.fromQVariant(variant.native);
|
||||
}
|
||||
}
|
||||
29
src/lib/QtCore/__tests__/QSize.test.ts
Normal file
29
src/lib/QtCore/__tests__/QSize.test.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { QSize } from '../QSize';
|
||||
import { QVariant } from '../QVariant';
|
||||
|
||||
describe('QSize', () => {
|
||||
it('initialize empty', () => {
|
||||
const size = new QSize();
|
||||
expect(size).toBeTruthy();
|
||||
});
|
||||
it('initialize with width and height', () => {
|
||||
const size = new QSize(300, 200);
|
||||
expect(size).toBeTruthy();
|
||||
});
|
||||
it('width', () => {
|
||||
const size = new QSize();
|
||||
size.setWidth(300);
|
||||
expect(size.width()).toBe(300);
|
||||
});
|
||||
it('height', () => {
|
||||
const size = new QSize();
|
||||
size.setHeight(200);
|
||||
expect(size.height()).toBe(200);
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const size = new QSize(300, 200);
|
||||
const variant = new QVariant(size);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QSize.fromQVariant(variant).height()).toBe(size.height());
|
||||
});
|
||||
});
|
||||
@ -3,38 +3,34 @@ import { QPixmap } from '../../QtGui/QPixmap';
|
||||
import path from 'path';
|
||||
|
||||
describe('QVariant', () => {
|
||||
it('inherits from QVariant', () => {
|
||||
const variant = new QVariant();
|
||||
expect(variant.constructor.name).toEqual('QVariant');
|
||||
});
|
||||
it('initialize empty', () => {
|
||||
const variant = new QVariant();
|
||||
expect(variant.constructor.name).toEqual('QVariant');
|
||||
expect(variant).toBeTruthy();
|
||||
});
|
||||
it('initialize with string', () => {
|
||||
const variant = new QVariant('hello');
|
||||
expect(variant.constructor.name).toBe('QVariant');
|
||||
expect(variant).toBeTruthy();
|
||||
expect(variant.toString()).toEqual('hello');
|
||||
});
|
||||
it('initialize with int', () => {
|
||||
const variant = new QVariant(123);
|
||||
expect(variant.constructor.name).toBe('QVariant');
|
||||
expect(variant).toBeTruthy();
|
||||
expect(variant.toInt()).toEqual(123);
|
||||
});
|
||||
it('initialize with double', () => {
|
||||
const variant = new QVariant(12.33);
|
||||
expect(variant.constructor.name).toBe('QVariant');
|
||||
expect(variant).toBeTruthy();
|
||||
expect(variant.toDouble()).toEqual(12.33);
|
||||
});
|
||||
it('initialize with boolean', () => {
|
||||
const variant = new QVariant(true);
|
||||
expect(variant.constructor.name).toBe('QVariant');
|
||||
expect(variant).toBeTruthy();
|
||||
expect(variant.toBool()).toEqual(true);
|
||||
});
|
||||
it('initialize with complex objects', () => {
|
||||
const pixmap = new QPixmap(path.resolve(__dirname, 'nodegui.png'));
|
||||
const variant = new QVariant(pixmap);
|
||||
expect(variant.constructor.name).toBe('QVariant');
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QPixmap.fromQVariant(variant).height()).toBe(pixmap.height());
|
||||
});
|
||||
});
|
||||
|
||||
@ -21,14 +21,13 @@ export class QPixmap extends Component {
|
||||
this.native = new addon.QPixmap();
|
||||
}
|
||||
}
|
||||
load = (imageUrl: string): boolean => {
|
||||
load(imageUrl: string): boolean {
|
||||
return this.native.load(imageUrl);
|
||||
};
|
||||
save = (fileName: string, format?: ReadWriteImageFormats): boolean => {
|
||||
//TODO: quality argument
|
||||
}
|
||||
save(fileName: string, format?: ReadWriteImageFormats): boolean {
|
||||
return format ? this.native.save(fileName, format) : this.native.save(fileName);
|
||||
};
|
||||
scaled = (width: number, height: number, aspectRatioMode?: AspectRatioMode): QPixmap => {
|
||||
}
|
||||
scaled(width: number, height: number, aspectRatioMode?: AspectRatioMode): QPixmap {
|
||||
let nativePixmap;
|
||||
if (aspectRatioMode) {
|
||||
nativePixmap = this.native.scaled(width, height, aspectRatioMode);
|
||||
@ -36,7 +35,7 @@ export class QPixmap extends Component {
|
||||
nativePixmap = this.native.scaled(width, height);
|
||||
}
|
||||
return new QPixmap(nativePixmap);
|
||||
};
|
||||
}
|
||||
height(): number {
|
||||
return this.native.height();
|
||||
}
|
||||
|
||||
66
src/lib/QtGui/__tests__/QPixmap.test.ts
Normal file
66
src/lib/QtGui/__tests__/QPixmap.test.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { QPixmap } from '../QPixmap';
|
||||
import path from 'path';
|
||||
import { QVariant } from '../../QtCore/QVariant';
|
||||
import { AspectRatioMode } from '../../QtEnums';
|
||||
import fs from 'fs';
|
||||
|
||||
const testImagePath = path.resolve(__dirname, 'assets', 'nodegui.png');
|
||||
describe('QPixmap', () => {
|
||||
it('initialize empty', () => {
|
||||
const pixmap = new QPixmap();
|
||||
expect(pixmap).toBeTruthy();
|
||||
});
|
||||
it('initialize with string', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
expect(pixmap).toBeTruthy();
|
||||
});
|
||||
it('width', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
expect(pixmap.width()).toBe(1000);
|
||||
});
|
||||
it('height', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
expect(pixmap.height()).toBe(1083);
|
||||
});
|
||||
it('initialize from QVariant', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
const variant = new QVariant(pixmap);
|
||||
expect(variant).toBeTruthy();
|
||||
expect(QPixmap.fromQVariant(variant).height()).toBe(pixmap.height());
|
||||
});
|
||||
it('scaled without aspect ratio', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
const newPixmap = pixmap.scaled(300, 340, AspectRatioMode.IgnoreAspectRatio);
|
||||
expect(newPixmap.width()).toBe(300);
|
||||
expect(newPixmap.height()).toBe(340);
|
||||
});
|
||||
it('scaled with aspect ratio', () => {
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
const newPixmap = pixmap.scaled(100, 100, AspectRatioMode.KeepAspectRatio);
|
||||
expect(newPixmap.width()).toBe(92);
|
||||
expect(newPixmap.height()).toBe(100);
|
||||
});
|
||||
it('load from file', () => {
|
||||
const pixmap = new QPixmap();
|
||||
expect(pixmap.height()).toBe(0);
|
||||
const isLoaded = pixmap.load(testImagePath);
|
||||
expect(isLoaded).toBe(true);
|
||||
expect(pixmap.height()).toBe(1083);
|
||||
});
|
||||
it('save to a file', async () => {
|
||||
const outputFilePath = path.resolve(__dirname, 'assets', 'nodegui_save.png');
|
||||
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));
|
||||
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));
|
||||
const pixmap = new QPixmap(testImagePath);
|
||||
pixmap.save(outputFilePath, 'JPG');
|
||||
const exists = await new Promise(resolve => fs.exists(outputFilePath, resolve));
|
||||
expect(exists).toBe(true);
|
||||
});
|
||||
});
|
||||
2
src/lib/QtGui/__tests__/assets/.gitignore
vendored
Normal file
2
src/lib/QtGui/__tests__/assets/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
nodegui_save.png
|
||||
nodegui_save.jpg
|
||||
BIN
src/lib/QtGui/__tests__/assets/nodegui.png
Normal file
BIN
src/lib/QtGui/__tests__/assets/nodegui.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@ -10,6 +10,7 @@ import { CursorShape, WindowState } from '../QtEnums';
|
||||
import { applyStyleSheet, StyleSheet, prepareInlineStyleSheet } from '../core/Style/StyleSheet';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { YogaWidget } from '../core/YogaWidget';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
// All Widgets should extend from NodeWidget
|
||||
// Implement all native QWidget methods here so that all widgets get access to those aswell
|
||||
export abstract class NodeWidget extends YogaWidget {
|
||||
@ -90,8 +91,8 @@ export abstract class NodeWidget extends YogaWidget {
|
||||
resize(width: number, height: number): void {
|
||||
this.native.resize(width, height);
|
||||
}
|
||||
size(): { width: number; height: number } {
|
||||
return this.native.size();
|
||||
size(): QSize {
|
||||
return new QSize(this.native.size());
|
||||
}
|
||||
move(x: number, y: number): void {
|
||||
this.native.move(x, y);
|
||||
|
||||
@ -64,7 +64,9 @@ describe('QWidget', () => {
|
||||
});
|
||||
it('setFixedSize', () => {
|
||||
view.setFixedSize(10, 12);
|
||||
expect(view.size()).toEqual({ width: 10, height: 12 });
|
||||
const size = view.size();
|
||||
expect(size.width()).toBe(10);
|
||||
expect(size.height()).toBe(12);
|
||||
});
|
||||
it('setWindowOpacity', () => {
|
||||
view.setWindowOpacity(0.6);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user