cleans up demo file and fixes qgroupbox

This commit is contained in:
Atul R 2019-12-07 18:49:42 +01:00
parent 1e8a1b7b76
commit 8039e6b09a
2 changed files with 28 additions and 109 deletions

View File

@ -1,8 +1,7 @@
#include "QtWidgets/QGroupBox/qgroupbox_wrap.h"
#include <QWidget>
#include "Extras/Utils/nutils.h"
#include "QtWidgets/QGroupBox/qgroupbox_wrap.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
Napi::FunctionReference QGroupBoxWrap::constructor;
@ -10,19 +9,19 @@ 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)});
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;
@ -48,7 +47,7 @@ QGroupBoxWrap::QGroupBoxWrap(const Napi::CallbackInfo& info)
}
this->rawData = extrautils::configureQWidget(
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
true);
false);
}
QGroupBoxWrap::~QGroupBoxWrap() { extrautils::safeDelete(this->instance); }
@ -83,7 +82,7 @@ Napi::Value QGroupBoxWrap::isFlat(const Napi::CallbackInfo& info) {
Napi::Value QGroupBoxWrap::setAlignment(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::HandleScope scope(env);
int alignment = info[0].As<Napi::Number>().Int32Value();
this->instance->setAlignment(alignment);
return env.Null();
@ -108,7 +107,7 @@ Napi::Value QGroupBoxWrap::setFlat(const Napi::CallbackInfo& info) {
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();
std::string text = info[0].As<Napi::String>().Utf8Value();
this->instance->setTitle(text.c_str());
return env.Null();
}

View File

@ -1,99 +1,19 @@
import { QWidget, QScrollArea, FlexLayout, QPushButton } from './index';
import { QLabel } from './lib/QtWidgets/QLabel';
import { QMainWindow } from './lib/QtWidgets/QMainWindow';
import { QComboBox, QComboBoxEvents } from './lib/QtWidgets/QComboBox';
import { SizeAdjustPolicy } from './lib/QtEnums';
import { QMainWindow, QPushButton, QLabel, QWidget, FlexLayout } from './index';
const win = new QMainWindow();
const scroll = new QScrollArea();
const top = new QWidget();
top.setLayout(new FlexLayout());
const center = new QWidget();
const button = new QPushButton();
button.setText('Hello');
const hello = new QLabel();
hello.setText('hello text');
center.setLayout(new FlexLayout());
center.layout?.addWidget(button);
center.layout?.addWidget(hello);
const btn = new QPushButton();
btn.setText('helloo');
const text = new QLabel();
text.setText('1 oncererer');
const combo = new QComboBox();
combo.addItem('test');
combo.addItem('test2');
combo.addEventListener(QComboBoxEvents.currentTextChanged, e => {
console.log('text changed', e);
});
combo.addEventListener(QComboBoxEvents.currentIndexChanged, e => {
console.log('index changed', e);
});
combo.addEventListener(QComboBoxEvents.editTextChanged, e => {
console.log('edit changed', e);
});
const btn1 = new QPushButton();
const btn2 = new QPushButton();
const btn3 = new QPushButton();
const btn4 = new QPushButton();
const btn5 = new QPushButton();
btn1.setText('add to index 1');
btn1.addEventListener('clicked', () => {
combo.insertItem(1, 'inserted');
});
btn2.setText('remove index 1');
btn2.addEventListener('clicked', () => {
combo.removeItem(1);
});
btn3.setText('editable');
btn3.addEventListener('clicked', () => {
combo.setEditable(!combo.isEditable());
});
btn4.setText('max 4');
btn4.addEventListener('clicked', () => {
combo.setMaxVisibleItems(4);
});
btn5.setText('Adjust Size');
btn5.addEventListener('clicked', () => {
combo.setSizeAdjustPolicy(SizeAdjustPolicy.AdjustToContents);
});
center.layout?.addWidget(combo);
center.layout?.addWidget(btn1);
center.layout?.addWidget(btn2);
center.layout?.addWidget(btn3);
center.layout?.addWidget(btn4);
center.layout?.addWidget(btn5);
btn.addEventListener('clicked', () => {
text.setText(`
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
Yoloooooooooo
`);
});
center.layout?.addWidget(btn);
center.layout?.addWidget(text);
scroll.setWidgetResizable(true);
center.setInlineStyle(`border: 3px solid blue; align-items:'center'; justify-content:'center';flex:1;`);
scroll.setWidget(top);
top.layout?.addWidget(center);
top.setInlineStyle(`border: 1px solid yellow;`);
win.setCentralWidget(scroll);
win.setCentralWidget(center);
win.show();
(global as any).win = win;