diff --git a/config/application.gypi b/config/application.gypi index d6fc1813f..def9f671a 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -25,6 +25,7 @@ "../src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp", "../src/cpp/QtWidgets/QProgressBar/qprogressbar_wrap.cpp", "../src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp", + "../src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.cpp", ], } ] diff --git a/demo.ts b/demo.ts index 8636ccc96..e9754232e 100644 --- a/demo.ts +++ b/demo.ts @@ -6,6 +6,7 @@ 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"; +import { QLineEdit } from "./src/lib/QtWidgets/QLineEdit"; const win = new QMainWindow(); const view = new QWidget(); @@ -29,12 +30,15 @@ const progressbar = new QProgressBar(); const radiobutton = new QRadioButton(); +const lineedit = new QLineEdit(); + gridLayout.addWidget(label); gridLayout.addWidget(label2); gridLayout.addWidget(button1); gridLayout.addWidget(checkbox); gridLayout.addWidget(progressbar); gridLayout.addWidget(radiobutton); +gridLayout.addWidget(lineedit); view.setLayout(gridLayout); diff --git a/src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.cpp b/src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.cpp new file mode 100644 index 000000000..3c1ea90c2 --- /dev/null +++ b/src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.cpp @@ -0,0 +1,47 @@ + +#include "qlineedit_wrap.h" +#include "src/cpp/QtGui/QWidget/qwidget_wrap.h" +#include "src/cpp/Extras/Utils/utils.h" +#include + + +Napi::FunctionReference QLineEditWrap::constructor; + +Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QLineEdit"; + Napi::Function func = DefineClass(env, CLASSNAME, { + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap) + }); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QLineEdit* QLineEditWrap::getInternalInstance() { + return this->instance; +} + +QLineEditWrap::QLineEditWrap(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 QLineEdit(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 QLineEdit(); + }else { + extrautils::throwTypeError(env, "Wrong number of arguments"); + } +} + +QLineEditWrap::~QLineEditWrap() { + delete this->instance; +} + diff --git a/src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.h b/src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.h new file mode 100644 index 000000000..6a3e8938e --- /dev/null +++ b/src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.h @@ -0,0 +1,22 @@ +#ifndef QLINEEDIT_WRAP_H +#define QLINEEDIT_WRAP_H +#include +#include +#include "src/cpp/QtGui/QWidget/qwidget_macro.h" + +class QLineEditWrap : public Napi::ObjectWrap{ + private: + QLineEdit* instance; + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QLineEditWrap(const Napi::CallbackInfo& info); + ~QLineEditWrap(); + QLineEdit* 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 8886e6da7..d41734a83 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -8,6 +8,7 @@ #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 "src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.h" #include //private : will not be accessibe in js @@ -25,6 +26,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QCheckBoxWrap::init(env, exports); QProgressBarWrap::init(env, exports); QRadioButtonWrap::init(env, exports); + QLineEditWrap::init(env, exports); return QLabelWrap::init(env, exports); } diff --git a/src/lib/QtWidgets/QLineEdit/index.ts b/src/lib/QtWidgets/QLineEdit/index.ts new file mode 100644 index 000000000..9a7890ac1 --- /dev/null +++ b/src/lib/QtWidgets/QLineEdit/index.ts @@ -0,0 +1,17 @@ +import addon from "../../core/addon"; +import { NodeWidget } from "../../QtGui/QWidget"; +import { QLayout } from "../QLayout"; + +export class QLineEdit extends NodeWidget { + native: any; + layout?: QLayout; + constructor(parent?: NodeWidget) { + super(); + if (parent) { + this.native = new addon.QLineEdit(parent.native); + this.parent = parent; + } else { + this.native = new addon.QLineEdit(); + } + } +}