nodeguy/src/lib/QtCore/QObject.ts
mspencer92 fd270c18ac Added QMessageBox (#326)
* Added QMessageBox

* Adds Qdialog

* Fixes inheritance and adds pointer based event listener

* Cleans up Qmessagebox so that we create all buttons

* change to abstract button

* fix rawData fetching from the template

* formatting fixes

* change to Objectwrap for better type casting

* Adds Native element part in qpushbutton

* Adds NapiExternal check and use ptr for initialization

* Adds all button classes

* fix c

* fix merge conflicts

* lint fix

Co-authored-by: Atul R <atulanand94@gmail.com>
2020-01-05 15:53:49 +05:30

51 lines
1.6 KiB
TypeScript

import { EventWidget } from '../core/EventWidget';
import { NativeElement } from '../core/Component';
import { checkIfNativeElement } from '../utils/helpers';
import addon from '../utils/addon';
import { QVariant, QVariantType } from './QVariant';
export abstract class NodeObject<Signals extends QObjectSignals> extends EventWidget<Signals> {
inherits(className: string): boolean {
return this.native.inherits(className);
}
setProperty(name: string, value: QVariantType): boolean {
return this.native.setProperty(name, value);
}
property(name: string): QVariant {
const nativeVariant = this.native.property(name);
return new QVariant(nativeVariant);
}
setObjectName(objectName: string): void {
this.native.setObjectName(objectName);
}
objectName(): string {
return this.native.objectName();
}
}
export interface QObjectSignals {
objectNameChanged: (objectName: string) => void;
}
export class QObject extends NodeObject<QObjectSignals> {
native: NativeElement;
constructor();
constructor(nativeElement: NativeElement);
constructor(parent: NodeObject<any>);
constructor(arg?: NodeObject<any> | NativeElement) {
let native;
let parent;
if (checkIfNativeElement(arg)) {
native = arg as NativeElement;
} else if (arg) {
parent = arg as NodeObject<any>;
native = new addon.QObject(parent.native);
} else {
native = new addon.QObject();
}
super(native);
this.setNodeParent(parent);
this.native = native;
}
}