Added few basic widgets and a working kickass demo
This commit is contained in:
parent
3e17864ec5
commit
9c322da9f2
@ -1,50 +0,0 @@
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakBeforeBraces: Stroustrup
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: ''
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
MaxEmptyLinesToKeep: 1
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
NamespaceIndentation: None
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInParentheses: false
|
||||
Cpp11BracedListStyle: true
|
||||
Standard: Cpp11
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
@ -5,7 +5,15 @@
|
||||
"cflags_cc!": ["-fno-exceptions"],
|
||||
"sources": [
|
||||
"src/cpp/main.cpp",
|
||||
# non-wrapped cpps
|
||||
"src/cpp/Extras/Utils/utils.cpp",
|
||||
# wrapped cpps
|
||||
"src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
|
||||
"src/cpp/QtGui/QWidget/qwidget_wrap.cpp",
|
||||
"src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp",
|
||||
"src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp",
|
||||
"src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp",
|
||||
"src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp",
|
||||
],
|
||||
'conditions': [
|
||||
['OS=="mac"', {
|
||||
|
||||
27
demo.js
27
demo.js
@ -1,3 +1,26 @@
|
||||
const nodeDesktop = require("./src/index");
|
||||
const nodeDesktop = require("./index");
|
||||
const {QWidget,QGridLayout,QLabel,QMainWindow} = nodeDesktop;
|
||||
|
||||
console.log(nodeDesktop);
|
||||
const win = new QMainWindow();
|
||||
|
||||
const view = new QWidget();
|
||||
win.setCentralWidget(view);
|
||||
|
||||
const gridLayout = new QGridLayout();
|
||||
|
||||
const label = new QLabel();
|
||||
label.setText('Testing1234');
|
||||
|
||||
const label2 = new QLabel();
|
||||
label2.setText('Hello12321');
|
||||
label2.setStyleSheet('background-color:blue; color:white;');
|
||||
|
||||
gridLayout.addWidget(label);
|
||||
gridLayout.addWidget(label2);
|
||||
|
||||
view.setLayout(gridLayout);
|
||||
|
||||
win.show();
|
||||
|
||||
console.log("THIS RAN");
|
||||
setInterval(()=>console.log("SHOW OFF"), 1000);
|
||||
3
index.js
Normal file
3
index.js
Normal file
@ -0,0 +1,3 @@
|
||||
const addon = require("./build/Release/node_desktop.node");
|
||||
|
||||
module.exports = addon;
|
||||
@ -9,9 +9,10 @@
|
||||
"devDependencies": {
|
||||
"node-gyp": "^4.0.0"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"build": "node-gyp -j 8 rebuild",
|
||||
"dev": "node demo.js"
|
||||
"dev": "qode demo.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-addon-api": "^1.6.3"
|
||||
|
||||
8
src/cpp/Extras/Utils/utils.cpp
Normal file
8
src/cpp/Extras/Utils/utils.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "utils.h"
|
||||
#include <iostream>
|
||||
|
||||
void extrautils::noop(){}
|
||||
|
||||
void extrautils::throwTypeError(Napi::Env env, std::string errorMessage){
|
||||
Napi::TypeError::New(env, errorMessage.c_str()).ThrowAsJavaScriptException();
|
||||
}
|
||||
11
src/cpp/Extras/Utils/utils.h
Normal file
11
src/cpp/Extras/Utils/utils.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef EXTRAUTILS_WRAP_H
|
||||
#define EXTRAUTILS_WRAP_H
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
namespace extrautils {
|
||||
void noop();
|
||||
void throwTypeError(Napi::Env env, std::string errorMessage);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,8 +1,9 @@
|
||||
#ifndef QAPPLICATION_WRAP_H
|
||||
#define QAPPLICATION_WRAP_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <napi.h>
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
class QApplicationWrap : public Napi::ObjectWrap<QApplicationWrap> {
|
||||
private:
|
||||
|
||||
99
src/cpp/QtGui/QWidget/qwidget_wrap.cpp
Normal file
99
src/cpp/QtGui/QWidget/qwidget_wrap.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "qwidget_wrap.h"
|
||||
#include "../../QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "../../Extras/Utils/utils.h"
|
||||
|
||||
Napi::FunctionReference QWidgetWrap::constructor;
|
||||
|
||||
Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QWidget";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("show", &QWidgetWrap::show),
|
||||
InstanceMethod("resize",&QWidgetWrap::resize),
|
||||
InstanceMethod("close",&QWidgetWrap::close),
|
||||
InstanceMethod("setLayout",&QWidgetWrap::setLayout),
|
||||
InstanceMethod("setStyleSheet",&QWidgetWrap::setStyleSheet),
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QWidget* QWidgetWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QWidgetWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if(info.Length() == 1) {
|
||||
if(info[0].IsObject()){
|
||||
Napi::Object object_parent = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* w_parent = Napi::ObjectWrap<QWidgetWrap>::Unwrap(object_parent);
|
||||
this->instance = new QWidget(w_parent->getInternalInstance()); //this sets the parent to current widget
|
||||
}else{
|
||||
extrautils::throwTypeError(env, "Wrong type of arguments");
|
||||
}
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new QWidget();
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
}
|
||||
|
||||
QWidgetWrap::~QWidgetWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QWidgetWrap::show(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
this->instance->show();
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QWidgetWrap::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 QWidgetWrap::close(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
this->instance->close();
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QWidgetWrap::setLayout(const Napi::CallbackInfo& info){
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object layoutObject = info[0].As<Napi::Object>();
|
||||
QLayoutWrap* layoutParent = Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject);
|
||||
this->instance->setLayout(layoutParent->getInternalInstance());
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
Napi::Value QWidgetWrap::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();
|
||||
}
|
||||
25
src/cpp/QtGui/QWidget/qwidget_wrap.h
Normal file
25
src/cpp/QtGui/QWidget/qwidget_wrap.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef QWIDGET_WRAP_H
|
||||
#define QWIDGET_WRAP_H
|
||||
|
||||
#include <napi.h>
|
||||
#include <QWidget>
|
||||
|
||||
class QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap>{
|
||||
private:
|
||||
QWidget* instance;
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QWidgetWrap(const Napi::CallbackInfo& info);
|
||||
~QWidgetWrap();
|
||||
QWidget* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
Napi::Value show(const Napi::CallbackInfo& info);
|
||||
Napi::Value resize(const Napi::CallbackInfo& info);
|
||||
Napi::Value close(const Napi::CallbackInfo& info);
|
||||
Napi::Value setLayout(const Napi::CallbackInfo& info);
|
||||
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
#endif
|
||||
55
src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp
Normal file
55
src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "qgridlayout_wrap.h"
|
||||
#include "../../QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "../../Extras/Utils/utils.h"
|
||||
|
||||
Napi::FunctionReference QGridLayoutWrap::constructor;
|
||||
|
||||
Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QGridLayout";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("addWidget", &QGridLayoutWrap::addWidget)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QGridLayout* QGridLayoutWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QGridLayoutWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if(info.Length() == 1) {
|
||||
if(info[0].IsObject()){
|
||||
Napi::Object object_parent = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* w_parent = Napi::ObjectWrap<QWidgetWrap>::Unwrap(object_parent);
|
||||
this->instance = new QGridLayout(w_parent->getInternalInstance()); //this sets the parent to current widget
|
||||
}else{
|
||||
extrautils::throwTypeError(env, "Wrong type of arguments");
|
||||
}
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new QGridLayout();
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
}
|
||||
|
||||
QGridLayoutWrap::~QGridLayoutWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QGridLayoutWrap::addWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object qwidgetObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* widget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(qwidgetObject);
|
||||
this->instance->addWidget(widget->getInternalInstance());
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
22
src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.h
Normal file
22
src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef QGRIDLAYOUT_WRAP_H
|
||||
#define QGRIDLAYOUT_WRAP_H
|
||||
|
||||
#include <napi.h>
|
||||
#include <QGridLayout>
|
||||
|
||||
class QGridLayoutWrap : public Napi::ObjectWrap<QGridLayoutWrap>{
|
||||
private:
|
||||
QGridLayout* instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QGridLayoutWrap(const Napi::CallbackInfo& info);
|
||||
~QGridLayoutWrap();
|
||||
QGridLayout* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
Napi::Value addWidget(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
#endif
|
||||
79
src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp
Normal file
79
src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include "qlabel_wrap.h"
|
||||
#include "../../QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "../../Extras/Utils/utils.h"
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
Napi::FunctionReference QLabelWrap::constructor;
|
||||
|
||||
Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QLabel";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("setWordWrap", &QLabelWrap::setWordWrap),
|
||||
InstanceMethod("setText", &QLabelWrap::setText),
|
||||
InstanceMethod("setStyleSheet", &QLabelWrap::setStyleSheet)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QLabel* QLabelWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QLabelWrap::QLabelWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QLabelWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if(info.Length() == 1) {
|
||||
if(info[0].IsObject()){
|
||||
Napi::Object object_parent = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* w_parent = Napi::ObjectWrap<QWidgetWrap>::Unwrap(object_parent);
|
||||
this->instance = new QLabel(w_parent->getInternalInstance()); //this sets the parent to current widget
|
||||
}else{
|
||||
extrautils::throwTypeError(env, "Wrong type of arguments");
|
||||
}
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new QLabel();
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
}
|
||||
|
||||
QLabelWrap::~QLabelWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QLabelWrap::setWordWrap(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Boolean On = info[0].As<Napi::Boolean>();
|
||||
this->instance->setWordWrap(On);
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QLabelWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::String text = info[0].As<Napi::String>();
|
||||
std::string label = text.Utf8Value();
|
||||
this->instance->setText(label.c_str());
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QLabelWrap::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();
|
||||
}
|
||||
22
src/cpp/QtWidgets/QLabel/qlabel_wrap.h
Normal file
22
src/cpp/QtWidgets/QLabel/qlabel_wrap.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef QLABEL_WRAP_H
|
||||
#define QLABEL_WRAP_H
|
||||
#include <napi.h>
|
||||
#include <QLabel>
|
||||
|
||||
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||
private:
|
||||
QLabel* instance;
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QLabelWrap(const Napi::CallbackInfo& info);
|
||||
~QLabelWrap();
|
||||
QLabel* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
Napi::Value setWordWrap(const Napi::CallbackInfo& info);
|
||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
#endif
|
||||
22
src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp
Normal file
22
src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "qlayout_wrap.h"
|
||||
|
||||
Napi::FunctionReference QLayoutWrap::constructor;
|
||||
|
||||
void QLayoutWrap::init(Napi::Env env) {
|
||||
char CLASSNAME[] = "QLayout";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {});
|
||||
constructor = Napi::Persistent(func);
|
||||
}
|
||||
|
||||
QLayout* QLayoutWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QLayoutWrap::QLayoutWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QLayoutWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
}
|
||||
|
||||
QLayoutWrap::~QLayoutWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
19
src/cpp/QtWidgets/QLayout/qlayout_wrap.h
Normal file
19
src/cpp/QtWidgets/QLayout/qlayout_wrap.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef QLAYOUT_WRAP_H
|
||||
#define QLAYOUT_WRAP_H
|
||||
#include <napi.h>
|
||||
#include <QLayout>
|
||||
|
||||
//ABSTRACT CLASS
|
||||
class QLayoutWrap : public Napi::ObjectWrap<QLayoutWrap>{
|
||||
private:
|
||||
QLayout* instance;
|
||||
public:
|
||||
static void init(Napi::Env env);
|
||||
QLayoutWrap(const Napi::CallbackInfo& info);
|
||||
~QLayoutWrap();
|
||||
QLayout* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
};
|
||||
|
||||
#endif
|
||||
101
src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp
Normal file
101
src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include "qmainwindow_wrap.h"
|
||||
#include "../../QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "../../Extras/Utils/utils.h"
|
||||
|
||||
Napi::FunctionReference QMainWindowWrap::constructor;
|
||||
|
||||
Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QMainWindow";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("setStyleSheet", &QMainWindowWrap::setStyleSheet),
|
||||
InstanceMethod("show", &QMainWindowWrap::show),
|
||||
InstanceMethod("resize",&QMainWindowWrap::resize),
|
||||
InstanceMethod("close",&QMainWindowWrap::close),
|
||||
InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget),
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QMainWindow* QMainWindowWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QMainWindowWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if(info.Length() == 1) {
|
||||
if(info[0].IsObject()){
|
||||
Napi::Object object_parent = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* w_parent = Napi::ObjectWrap<QWidgetWrap>::Unwrap(object_parent);
|
||||
this->instance = new QMainWindow(w_parent->getInternalInstance()); //this sets the parent to current widget
|
||||
}else{
|
||||
extrautils::throwTypeError(env, "Wrong type of arguments");
|
||||
}
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new QMainWindow();
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
}
|
||||
|
||||
QMainWindowWrap::~QMainWindowWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::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 QMainWindowWrap::show(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
this->instance->show();
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::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 QMainWindowWrap::close(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
this->instance->close();
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info){
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object widgetObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* centralWidget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(widgetObject);
|
||||
this->instance->setCentralWidget(centralWidget->getInternalInstance());
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
|
||||
26
src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h
Normal file
26
src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef QMAINWINDOW_WRAP_H
|
||||
#define QMAINWINDOW_WRAP_H
|
||||
|
||||
#include <napi.h>
|
||||
#include <QMainWindow>
|
||||
|
||||
class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap>{
|
||||
private:
|
||||
QMainWindow* instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QMainWindowWrap(const Napi::CallbackInfo& info);
|
||||
~QMainWindowWrap();
|
||||
QMainWindow* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
|
||||
Napi::Value show(const Napi::CallbackInfo& info);
|
||||
Napi::Value resize(const Napi::CallbackInfo& info);
|
||||
Napi::Value close(const Napi::CallbackInfo& info);
|
||||
Napi::Value setCentralWidget(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,10 +1,26 @@
|
||||
#include <napi.h>
|
||||
#include "QtGui/QApplication/qapplication_wrap.h"
|
||||
#include "QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "QtWidgets/QGridLayout/qgridlayout_wrap.h"
|
||||
#include "QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "QtWidgets/QLabel/qlabel_wrap.h"
|
||||
#include "QtWidgets/QMainWindow/qmainwindow_wrap.h"
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Object Main(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
QApplicationWrap::init(env, exports);
|
||||
return exports;
|
||||
|
||||
|
||||
//private : will not be accessibe in js
|
||||
void InitPrivateHelpers(Napi::Env env){
|
||||
QLayoutWrap::init(env); //Abstact class wrapper for pointing to any layout
|
||||
}
|
||||
|
||||
Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
InitPrivateHelpers(env);
|
||||
QApplicationWrap::init(env, exports);
|
||||
QWidgetWrap::init(env, exports);
|
||||
QGridLayoutWrap::init(env, exports);
|
||||
QMainWindowWrap::init(env,exports);
|
||||
return QLabelWrap::init(env, exports);
|
||||
}
|
||||
|
||||
|
||||
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Main)
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
const addon = require("../build/Release/node_desktop.node");
|
||||
|
||||
module.exports = addon;
|
||||
Loading…
Reference in New Issue
Block a user