Co-authored-by: wuxiaofeng <wuxiaofeng@erayt.com>
This commit is contained in:
feng8848 2020-04-01 17:54:38 +08:00 committed by GitHub
parent c54822686e
commit 44e64b007b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 23 deletions

View File

@ -30,6 +30,10 @@ class DLL_EXPORT QBoxLayoutWrap : public Napi::ObjectWrap<QBoxLayoutWrap> {
Napi::Value insertWidget(const Napi::CallbackInfo& info);
Napi::Value direction(const Napi::CallbackInfo& info);
Napi::Value insertLayout(const Napi::CallbackInfo& info);
Napi::Value insertSpacing(const Napi::CallbackInfo& info);
Napi::Value insertStretch(const Napi::CallbackInfo& info);
Napi::Value removeWidget(const Napi::CallbackInfo& info);
Napi::Value setDirection(const Napi::CallbackInfo& info);
Napi::Value setStretch(const Napi::CallbackInfo& info);
Napi::Value count(const Napi::CallbackInfo& info);
};

View File

@ -12,26 +12,49 @@
*/
#ifndef QLAYOUT_WRAPPED_METHODS_DECLARATION
#define QLAYOUT_WRAPPED_METHODS_DECLARATION \
QOBJECT_WRAPPED_METHODS_DECLARATION \
\
Napi::Value activate(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
bool wasRedone = this->instance->activate(); \
return Napi::Boolean::New(env, wasRedone); \
} \
Napi::Value invalidate(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->invalidate(); \
return env.Null(); \
} \
Napi::Value update(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->update(); \
return env.Null(); \
#define QLAYOUT_WRAPPED_METHODS_DECLARATION \
QOBJECT_WRAPPED_METHODS_DECLARATION \
\
Napi::Value activate(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
bool wasRedone = this->instance->activate(); \
return Napi::Boolean::New(env, wasRedone); \
} \
Napi::Value setEnabled(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
bool enable = info[0].As<Napi::Boolean>().Value(); \
this->instance->setEnabled(enable); \
return env.Null(); \
} \
Napi::Value isEnabled(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
bool enabled = this->instance->isEnabled(); \
return Napi::Boolean::New(env, enabled); \
} \
Napi::Value setContentsMargins(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
int left = info[0].As<Napi::Number>().Int32Value(); \
int top = info[1].As<Napi::Number>().Int32Value(); \
int right = info[2].As<Napi::Number>().Int32Value(); \
int bottom = info[3].As<Napi::Number>().Int32Value(); \
this->instance->setContentsMargins(left, top, right, bottom); \
return env.Null(); \
} \
Napi::Value invalidate(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->invalidate(); \
return env.Null(); \
} \
Napi::Value update(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->update(); \
return env.Null(); \
}
#endif // QLAYOUT_WRAPPED_METHODS_DECLARATION
@ -41,6 +64,10 @@
\
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(LayoutWrapName) \
InstanceMethod("activate", &LayoutWrapName::activate), \
InstanceMethod("setEnabled", &LayoutWrapName::setEnabled), \
InstanceMethod("isEnabled", &LayoutWrapName::isEnabled), \
InstanceMethod("setContentsMargins", \
&LayoutWrapName::setContentsMargins), \
InstanceMethod("invalidate", &LayoutWrapName::invalidate), \
InstanceMethod("update", &LayoutWrapName::update),

View File

@ -18,8 +18,12 @@ Napi::Object QBoxLayoutWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("insertWidget", &QBoxLayoutWrap::insertWidget),
InstanceMethod("direction", &QBoxLayoutWrap::direction),
InstanceMethod("insertLayout", &QBoxLayoutWrap::insertLayout),
InstanceMethod("insertSpacing", &QBoxLayoutWrap::insertSpacing),
InstanceMethod("insertStretch", &QBoxLayoutWrap::insertStretch),
InstanceMethod("removeWidget", &QBoxLayoutWrap::removeWidget),
InstanceMethod("setDirection", &QBoxLayoutWrap::setDirection),
InstanceMethod("setStretch", &QBoxLayoutWrap::setStretch),
InstanceMethod("count", &QBoxLayoutWrap::count),
QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QBoxLayoutWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -131,6 +135,26 @@ Napi::Value QBoxLayoutWrap::insertLayout(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QBoxLayoutWrap::insertSpacing(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int index = info[0].As<Napi::Number>().Int32Value();
int size = info[1].As<Napi::Number>().Int32Value();
this->instance->insertSpacing(index, size);
return env.Null();
}
Napi::Value QBoxLayoutWrap::insertStretch(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int index = info[0].As<Napi::Number>().Int32Value();
int stretch = info[1].As<Napi::Number>().Int32Value();
this->instance->insertStretch(index, stretch);
return env.Null();
}
Napi::Value QBoxLayoutWrap::removeWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
@ -149,4 +173,22 @@ Napi::Value QBoxLayoutWrap::setDirection(const Napi::CallbackInfo& info) {
info[0].As<Napi::Number>().Int32Value());
this->instance->setDirection(dir);
return env.Null();
}
}
Napi::Value QBoxLayoutWrap::setStretch(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int index = info[0].As<Napi::Number>().Int32Value();
int stretch = info[1].As<Napi::Number>().Int32Value();
this->instance->setStretch(index, stretch);
return env.Null();
}
Napi::Value QBoxLayoutWrap::count(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int count = this->instance->count();
return Napi::Number::New(env, count);
}

View File

@ -22,7 +22,7 @@ export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent';
export { WidgetEventTypes } from './lib/core/EventWidget';
// Abstract:
export { NodeWidget, QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget';
export { NodeLayout, QLayoutSignals } from './lib/QtWidgets/QLayout';
export { NodeLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout';
export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea';
export { QAbstractSlider, QAbstractSliderSignals } from './lib/QtWidgets/QAbstractSlider';
export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton';

View File

@ -70,6 +70,12 @@ export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
this.native.insertLayout(index, layout.native, stretch);
this.childLayouts.add(layout);
}
insertSpacing(index: number, size: number): void {
this.native.insertSpacing(index, size);
}
insertStretch(index: number, stretch = 0): void {
this.native.insertStretch(index, stretch);
}
removeWidget(widget: NodeWidget<any>): void {
this.native.removeWidget(widget.native);
this.nodeChildren.delete(widget);
@ -77,6 +83,12 @@ export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
setDirection(dir: Direction): void {
this.native.setDirection(dir);
}
setStretch(index: number, stretch: number): void {
this.native.setStretch(index, stretch);
}
count(): number {
return this.native.count();
}
}
export type QBoxLayoutSignals = QLayoutSignals;

View File

@ -36,9 +36,30 @@ export abstract class NodeLayout<Signals extends QLayoutSignals> extends NodeObj
type = 'layout';
abstract addWidget(childWidget: NodeWidget<any>, ...args: any[]): void;
abstract removeWidget(childWidget: NodeWidget<any>): void;
setSizeConstraint(constraint: SizeConstraint): void {
this.setProperty('sizeConstraint', constraint);
}
sizeConstraint(): SizeConstraint {
return this.property('sizeConstraint').toInt();
}
setSpacing(spacing: number): void {
this.setProperty('spacing', spacing);
}
spacing(): number {
return this.property('spacing').toInt();
}
activate(): boolean {
return this.native.activate();
}
setEnabled(enable: boolean): void {
this.native.setEnabled(enable);
}
isEnabled(): boolean {
return this.native.isEnabled();
}
setContentsMargins(left: number, top: number, right: number, bottom: number): void {
this.native.setContentsMargins(left, top, right, bottom);
}
invalidate(): void {
this.native.invalidate();
}
@ -51,4 +72,13 @@ export abstract class NodeLayout<Signals extends QLayoutSignals> extends NodeObj
// native: any;
// }
export enum SizeConstraint {
SetDefaultConstraint = 0,
SetNoConstraint = 1,
SetMinimumSize = 2,
SetFixedSize = 3,
SetMaximumSize = 4,
SetMinAndMaxSize = 5,
}
export type QLayoutSignals = QObjectSignals;

View File

@ -83,7 +83,7 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
}
insertTopLevelItem(index: number, item: QTreeWidgetItem): void {
this.topLevelItems.add(item)
this.topLevelItems.add(item);
this.native.insertTopLevelItem(index, item.native);
}