Add QLabel.buddy()

This commit is contained in:
Simon Edwards 2022-05-19 19:48:23 +02:00
parent 5191892950
commit c28fd5d5c3
3 changed files with 14 additions and 6 deletions

View File

@ -25,6 +25,7 @@ class DLL_EXPORT QLabelWrap : public Napi::ObjectWrap<QLabelWrap> {
Napi::Value setSelection(const Napi::CallbackInfo& info);
Napi::Value selectionStart(const Napi::CallbackInfo& info);
Napi::Value setBuddy(const Napi::CallbackInfo& info);
Napi::Value buddy(const Napi::CallbackInfo& info);
Napi::Value clear(const Napi::CallbackInfo& info);
Napi::Value setMovie(const Napi::CallbackInfo& info);
Napi::Value setNumDouble(const Napi::CallbackInfo& info);

View File

@ -18,6 +18,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
{InstanceMethod("setSelection", &QLabelWrap::setSelection),
InstanceMethod("selectionStart", &QLabelWrap::selectionStart),
InstanceMethod("setBuddy", &QLabelWrap::setBuddy),
InstanceMethod("buddy", &QLabelWrap::buddy),
InstanceMethod("clear", &QLabelWrap::clear),
InstanceMethod("setMovie", &QLabelWrap::setMovie),
InstanceMethod("setNumDouble", &QLabelWrap::setNumDouble),
@ -91,6 +92,16 @@ Napi::Value QLabelWrap::setBuddy(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QLabelWrap::buddy(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QObject* parent = this->instance->buddy();
if (parent) {
return WrapperCache::instance.getWrapper(env, parent);
} else {
return env.Null();
}
}
Napi::Value QLabelWrap::clear(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
this->instance->clear();

View File

@ -33,7 +33,7 @@ export class QLabel extends QFrame<QLabelSignals> {
private _picture?: QPicture;
private _pixmap?: QPixmap;
private _movie?: QMovie;
private _buddy?: QWidget | null;
// TODO
constructor(arg?: QWidget<QWidgetSignals> | NativeElement) {
let native: NativeElement;
@ -115,13 +115,9 @@ export class QLabel extends QFrame<QLabelSignals> {
}
setBuddy(buddy: QWidget): void {
this.native.setBuddy(buddy.native);
this._buddy = buddy;
}
buddy(): QWidget | null {
if (this._buddy) {
return this._buddy;
}
return null;
return wrapperCache.getWrapper(this.native.budd()) as QWidget;
}
setMovie(movie: QMovie): void {
this.native.setMovie(movie.native);