Add QGroupBox (#251)
This commit is contained in:
parent
ed84031fbb
commit
32a1b97012
@ -74,6 +74,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/core/FlexLayout/flexlayout_wrap.cpp"
|
||||
# Custom widgets (include them for automoc since they contain Q_OBJECT)
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtCore/QObject/nobject.hpp"
|
||||
@ -101,6 +102,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QGridLayout/ngridlayout.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QBoxLayout/nboxlayout.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QComboBox/ncombobox.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QGroupBox/ngroupbox.hpp"
|
||||
)
|
||||
|
||||
AddCommonConfig(${CORE_WIDGETS_ADDON})
|
||||
|
||||
28
src/cpp/include/nodegui/QtWidgets/QGroupBox/ngroupbox.hpp
Normal file
28
src/cpp/include/nodegui/QtWidgets/QGroupBox/ngroupbox.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <QGroupBox>
|
||||
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
class NGroupBox : public QGroupBox, public NodeWidget {
|
||||
Q_OBJECT
|
||||
NODEWIDGET_IMPLEMENTATIONS(QGroupBox)
|
||||
public:
|
||||
using QGroupBox::QGroupBox; // inherit all constructors of QGroupBox
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
QObject::connect(this, &QGroupBox::clicked, [=](bool checked) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "clicked"), Napi::Value::From(env, checked)});
|
||||
});
|
||||
QObject::connect(this, &QGroupBox::toggled, [=](bool on) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call(
|
||||
{Napi::String::New(env, "toggled"), Napi::Value::From(env, on)});
|
||||
});
|
||||
}
|
||||
};
|
||||
35
src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h
Normal file
35
src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "ngroupbox.hpp"
|
||||
|
||||
class QGroupBoxWrap : public Napi::ObjectWrap<QGroupBoxWrap> {
|
||||
private:
|
||||
QPointer<NGroupBox> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QGroupBoxWrap(const Napi::CallbackInfo& info);
|
||||
~QGroupBoxWrap();
|
||||
NGroupBox* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
Napi::Value alignment(const Napi::CallbackInfo& info);
|
||||
Napi::Value isCheckable(const Napi::CallbackInfo& info);
|
||||
Napi::Value isChecked(const Napi::CallbackInfo& info);
|
||||
Napi::Value isFlat(const Napi::CallbackInfo& info);
|
||||
Napi::Value setAlignment(const Napi::CallbackInfo& info);
|
||||
Napi::Value setCheckable(const Napi::CallbackInfo& info);
|
||||
Napi::Value setFlat(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTitle(const Napi::CallbackInfo& info);
|
||||
Napi::Value title(const Napi::CallbackInfo& info);
|
||||
Napi::Value setChecked(const Napi::CallbackInfo& info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
129
src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp
Normal file
129
src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
#include "QtWidgets/QGroupBox/qgroupbox_wrap.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
|
||||
Napi::FunctionReference QGroupBoxWrap::constructor;
|
||||
|
||||
Napi::Object QGroupBoxWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QGroupBox";
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("alignment", &QGroupBoxWrap::alignment),
|
||||
InstanceMethod("isCheckable", &QGroupBoxWrap::isCheckable),
|
||||
InstanceMethod("isChecked", &QGroupBoxWrap::isChecked),
|
||||
InstanceMethod("isFlat", &QGroupBoxWrap::isFlat),
|
||||
InstanceMethod("setAlignment", &QGroupBoxWrap::setAlignment),
|
||||
InstanceMethod("setCheckable", &QGroupBoxWrap::setCheckable),
|
||||
InstanceMethod("setFlat", &QGroupBoxWrap::setFlat),
|
||||
InstanceMethod("setTitle", &QGroupBoxWrap::setTitle),
|
||||
InstanceMethod("title", &QGroupBoxWrap::title),
|
||||
InstanceMethod("setChecked", &QGroupBoxWrap::setChecked),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QGroupBoxWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
NGroupBox* QGroupBoxWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QGroupBoxWrap::QGroupBoxWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QGroupBoxWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NGroupBox(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NGroupBox();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
this->rawData = extrautils::configureQWidget(
|
||||
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
|
||||
true);
|
||||
}
|
||||
|
||||
QGroupBoxWrap::~QGroupBoxWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QGroupBoxWrap::alignment(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int alignment = static_cast<int>(this->instance->alignment());
|
||||
return Napi::Value::From(env, alignment);
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::isCheckable(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool checkable = this->instance->isCheckable();
|
||||
return Napi::Value::From(env, checkable);
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::isChecked(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool checked = this->instance->isChecked();
|
||||
return Napi::Value::From(env, checked);
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::isFlat(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool flat = this->instance->isFlat();
|
||||
return Napi::Value::From(env, flat);
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::setAlignment(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int alignment = info[0].As<Napi::Number>().Int32Value();
|
||||
this->instance->setAlignment(alignment);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::setCheckable(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool checkable = info[0].As<Napi::Boolean>().Value();
|
||||
this->instance->setCheckable(checkable);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::setFlat(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool flat = info[0].As<Napi::Boolean>().Value();
|
||||
this->instance->setFlat(flat);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::setTitle(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
std::string text = info[0].As<Napi::String>().Utf8Value();
|
||||
this->instance->setTitle(text.c_str());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::title(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
QString text = this->instance->title();
|
||||
return Napi::String::New(env, text.toStdString().c_str());
|
||||
}
|
||||
|
||||
Napi::Value QGroupBoxWrap::setChecked(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool checked = info[0].As<Napi::Boolean>().Value();
|
||||
this->instance->setChecked(checked);
|
||||
return env.Null();
|
||||
}
|
||||
@ -21,6 +21,7 @@
|
||||
#include "QtWidgets/QComboBox/qcombobox_wrap.h"
|
||||
#include "QtWidgets/QDial/qdial_wrap.h"
|
||||
#include "QtWidgets/QGridLayout/qgridlayout_wrap.h"
|
||||
#include "QtWidgets/QGroupBox/qgroupbox_wrap.h"
|
||||
#include "QtWidgets/QLabel/qlabel_wrap.h"
|
||||
#include "QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "QtWidgets/QLineEdit/qlineedit_wrap.h"
|
||||
@ -64,6 +65,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QComboBoxWrap::init(env, exports);
|
||||
QBoxLayoutWrap::init(env, exports);
|
||||
QGridLayoutWrap::init(env, exports);
|
||||
QGroupBoxWrap::init(env, exports);
|
||||
FlexLayoutWrap::init(env, exports);
|
||||
QMainWindowWrap::init(env, exports);
|
||||
QPushButtonWrap::init(env, exports);
|
||||
|
||||
@ -43,6 +43,7 @@ export { QScrollArea, QScrollAreaEvents } from './lib/QtWidgets/QScrollArea';
|
||||
export { QSystemTrayIcon, QSystemTrayIconEvents } from './lib/QtWidgets/QSystemTrayIcon';
|
||||
export { QAction, QActionEvents } from './lib/QtWidgets/QAction';
|
||||
export { QShortcut, QShortcutEvents } from './lib/QtWidgets/QShortcut';
|
||||
export { QGroupBox, QGroupBoxEvents } from './lib/QtWidgets/QGroupBox';
|
||||
// Core
|
||||
export { QObject, NodeObject } from './lib/QtCore/QObject';
|
||||
export { QVariant } from './lib/QtCore/QVariant';
|
||||
|
||||
55
src/lib/QtWidgets/QGroupBox.ts
Normal file
55
src/lib/QtWidgets/QGroupBox.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { BaseWidgetEvents } from '../core/EventWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { AlignmentFlag } from '../QtEnums/AlignmentFlag';
|
||||
|
||||
export const QGroupBoxEvents = Object.freeze({
|
||||
...BaseWidgetEvents,
|
||||
clicked: 'clicked',
|
||||
toggled: 'toggled',
|
||||
});
|
||||
export class QGroupBox extends NodeWidget {
|
||||
native: NativeElement;
|
||||
constructor(parent?: NodeWidget) {
|
||||
let native;
|
||||
if (parent) {
|
||||
native = new addon.QGroupBox(parent.native);
|
||||
} else {
|
||||
native = new addon.QGroupBox();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.nodeParent = parent;
|
||||
}
|
||||
alignment(): AlignmentFlag {
|
||||
return this.native.alignment();
|
||||
}
|
||||
isCheckable(): boolean {
|
||||
return this.native.isCheckable();
|
||||
}
|
||||
isChecked(): boolean {
|
||||
return this.native.isChecked();
|
||||
}
|
||||
isFlat(): boolean {
|
||||
return this.native.isFlat();
|
||||
}
|
||||
setAlignment(alignment: number): void {
|
||||
this.native.setAlignment(alignment);
|
||||
}
|
||||
setCheckable(checkable: boolean): void {
|
||||
this.native.setCheckable(checkable);
|
||||
}
|
||||
setFlat(flat: boolean): void {
|
||||
this.native.setFlat(flat);
|
||||
}
|
||||
setTitle(title: string): void {
|
||||
this.native.setTitle(title);
|
||||
}
|
||||
title(): string {
|
||||
return this.native.title();
|
||||
}
|
||||
setChecked(checked: boolean): void {
|
||||
this.native.setChecked(checked);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user