Added QCheckBox

This commit is contained in:
Kakul Gupta 2019-06-01 16:19:52 +02:00
parent e2686afff2
commit cb0bdfa08d
6 changed files with 110 additions and 1 deletions

View File

@ -18,7 +18,8 @@
"../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp",
"../src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp",
"../src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp",
"../src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp"
"../src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp",
"../src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp",
],
}
]

View File

@ -3,6 +3,7 @@ import { QWidget } from "./src/lib/QtGui/QWidget";
import { QGridLayout } from "./src/lib/QtWidgets/QGridLayout";
import { QLabel } from "./src/lib/QtWidgets/QLabel";
import { QPushButton } from "./src/lib/QtWidgets/QPushButton";
import { QCheckBox } from "./src/lib/QtWidgets/QCheckBox";
const win = new QMainWindow();
const view = new QWidget();
@ -19,9 +20,13 @@ label2.setStyleSheet("background-color:blue; color:white;");
const button1 = new QPushButton();
button1.setText("Yolo");
const checkbox = new QCheckBox();
checkbox.setText("Pumpkeen");
gridLayout.addWidget(label);
gridLayout.addWidget(label2);
gridLayout.addWidget(button1);
gridLayout.addWidget(checkbox);
view.setLayout(gridLayout);

View File

@ -0,0 +1,58 @@
#include "qcheckbox_wrap.h"
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
#include "src/cpp/Extras/Utils/utils.h"
#include <QWidget>
Napi::FunctionReference QCheckBoxWrap::constructor;
Napi::Object QCheckBoxWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QCheckBox";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setText", &QCheckBoxWrap::setText),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QCheckBoxWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QCheckBox* QCheckBoxWrap::getInternalInstance() {
return this->instance;
}
QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QCheckBoxWrap>(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 QCheckBox(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 QCheckBox();
}else {
extrautils::throwTypeError(env, "Wrong number of arguments");
}
}
QCheckBoxWrap::~QCheckBoxWrap() {
delete this->instance;
}
Napi::Value QCheckBoxWrap::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();
}

View File

@ -0,0 +1,23 @@
#ifndef QCHECKBOX_WRAP_H
#define QCHECKBOX_WRAP_H
#include <napi.h>
#include <QCheckBox>
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
private:
QCheckBox* instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QCheckBoxWrap(const Napi::CallbackInfo& info);
~QCheckBoxWrap();
QCheckBox* getInternalInstance();
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value setText(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};
#endif

View File

@ -5,6 +5,7 @@
#include "src/cpp/QtWidgets/QLabel/qlabel_wrap.h"
#include "src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h"
#include "src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h"
#include "src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h"
#include <napi.h>
//private : will not be accessibe in js
@ -19,6 +20,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
QGridLayoutWrap::init(env, exports);
QMainWindowWrap::init(env,exports);
QPushButtonWrap::init(env, exports);
QCheckBoxWrap::init(env, exports);
return QLabelWrap::init(env, exports);
}

View File

@ -0,0 +1,20 @@
import addon from "../../core/addon";
import { NodeWidget } from "../../QtGui/QWidget";
import { QLayout } from "../QLayout";
export class QCheckBox extends NodeWidget {
native: any;
layout?: QLayout;
constructor(parent?: NodeWidget) {
super();
if (parent) {
this.native = new addon.QCheckBox(parent.native);
this.parent = parent;
} else {
this.native = new addon.QCheckBox();
}
}
setText(text: string) {
this.native.setText(text);
}
}