diff --git a/config/application.gypi b/config/application.gypi index c342def21..d6fc1813f 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -24,6 +24,7 @@ "../src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp", "../src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp", "../src/cpp/QtWidgets/QProgressBar/qprogressbar_wrap.cpp", + "../src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp", ], } ] diff --git a/demo.ts b/demo.ts index 9689c7fbc..8636ccc96 100644 --- a/demo.ts +++ b/demo.ts @@ -5,6 +5,7 @@ import { QLabel } from "./src/lib/QtWidgets/QLabel"; import { QPushButton } from "./src/lib/QtWidgets/QPushButton"; import { QCheckBox } from "./src/lib/QtWidgets/QCheckBox"; import { QProgressBar } from "./src/lib/QtWidgets/QProgressBar"; +import { QRadioButton } from "./src/lib/QtWidgets/QRadioButton"; const win = new QMainWindow(); const view = new QWidget(); @@ -26,11 +27,14 @@ checkbox.setText("Pumpkeen"); const progressbar = new QProgressBar(); +const radiobutton = new QRadioButton(); + gridLayout.addWidget(label); gridLayout.addWidget(label2); gridLayout.addWidget(button1); gridLayout.addWidget(checkbox); gridLayout.addWidget(progressbar); +gridLayout.addWidget(radiobutton); view.setLayout(gridLayout); diff --git a/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp new file mode 100644 index 000000000..78b7d162c --- /dev/null +++ b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp @@ -0,0 +1,47 @@ + +#include "qradiobutton_wrap.h" +#include "src/cpp/QtGui/QWidget/qwidget_wrap.h" +#include "src/cpp/Extras/Utils/utils.h" +#include + + +Napi::FunctionReference QRadioButtonWrap::constructor; + +Napi::Object QRadioButtonWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QRadioButton"; + Napi::Function func = DefineClass(env, CLASSNAME, { + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap) + }); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QRadioButton* QRadioButtonWrap::getInternalInstance() { + return this->instance; +} + +QRadioButtonWrap::QRadioButtonWrap(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 QRadioButton(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 QRadioButton(); + }else { + extrautils::throwTypeError(env, "Wrong number of arguments"); + } +} + +QRadioButtonWrap::~QRadioButtonWrap() { + delete this->instance; +} + diff --git a/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h new file mode 100644 index 000000000..4725a3ca4 --- /dev/null +++ b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h @@ -0,0 +1,22 @@ +#ifndef QRADIOBUTTON_WRAP_H +#define QRADIOBUTTON_WRAP_H +#include +#include +#include "src/cpp/QtGui/QWidget/qwidget_macro.h" + +class QRadioButtonWrap : public Napi::ObjectWrap{ + private: + QRadioButton* instance; + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QRadioButtonWrap(const Napi::CallbackInfo& info); + ~QRadioButtonWrap(); + QRadioButton* getInternalInstance(); + //class constructor + static Napi::FunctionReference constructor; + //wrapped methods + + QWIDGET_WRAPPED_METHODS_DECLARATION +}; + +#endif \ No newline at end of file diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 9510fb357..8886e6da7 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -7,6 +7,7 @@ #include "src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h" #include "src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h" #include "src/cpp/QtWidgets/QProgressBar/qprogressbar_wrap.h" +#include "src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h" #include //private : will not be accessibe in js @@ -23,6 +24,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QPushButtonWrap::init(env, exports); QCheckBoxWrap::init(env, exports); QProgressBarWrap::init(env, exports); + QRadioButtonWrap::init(env, exports); return QLabelWrap::init(env, exports); } diff --git a/src/lib/QtWidgets/QRadioButton/index.ts b/src/lib/QtWidgets/QRadioButton/index.ts new file mode 100644 index 000000000..bc6f56a14 --- /dev/null +++ b/src/lib/QtWidgets/QRadioButton/index.ts @@ -0,0 +1,17 @@ +import addon from "../../core/addon"; +import { NodeWidget } from "../../QtGui/QWidget"; +import { QLayout } from "../QLayout"; + +export class QRadioButton extends NodeWidget { + native: any; + layout?: QLayout; + constructor(parent?: NodeWidget) { + super(); + if (parent) { + this.native = new addon.QRadioButton(parent.native); + this.parent = parent; + } else { + this.native = new addon.QRadioButton(); + } + } +}