diff --git a/config/application.gypi b/config/application.gypi index d3348c057..5d61f939a 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -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", ], } ] diff --git a/demo.ts b/demo.ts index ffc82f89f..a1487d234 100644 --- a/demo.ts +++ b/demo.ts @@ -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); diff --git a/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp new file mode 100644 index 000000000..e194ad1f2 --- /dev/null +++ b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp @@ -0,0 +1,58 @@ +#include "qcheckbox_wrap.h" +#include "src/cpp/QtGui/QWidget/qwidget_wrap.h" +#include "src/cpp/Extras/Utils/utils.h" +#include + + +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(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(); + QWidgetWrap* w_parent = Napi::ObjectWrap::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(); + std::string label = text.Utf8Value(); + this->instance->setText(label.c_str()); + + return env.Null(); +} + diff --git a/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h new file mode 100644 index 000000000..b0be3f4b7 --- /dev/null +++ b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h @@ -0,0 +1,23 @@ +#ifndef QCHECKBOX_WRAP_H +#define QCHECKBOX_WRAP_H +#include +#include +#include "src/cpp/QtGui/QWidget/qwidget_macro.h" + +class QCheckBoxWrap : public Napi::ObjectWrap{ + 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 \ No newline at end of file diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index e85731c4b..7a1b7cb06 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -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 //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); } diff --git a/src/lib/QtWidgets/QCheckBox/index.ts b/src/lib/QtWidgets/QCheckBox/index.ts new file mode 100644 index 000000000..1b53fb37b --- /dev/null +++ b/src/lib/QtWidgets/QCheckBox/index.ts @@ -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); + } +}