nodeguy/src/lib/QtWidgets/QMainWindow.ts
Atul R 6035b5d038
Re arrange folders to make more sense (#180)
* Re-arranged qtgui and core

* Re arranges qt widgets
2019-11-08 20:33:17 +01:00

61 lines
1.8 KiB
TypeScript

import addon from '../utils/addon';
import { NodeWidget } from './QWidget';
import { BaseWidgetEvents } from '../core/EventWidget';
import { NativeElement } from '../core/Component';
import { NodeLayout } from './QLayout';
import { QMenuBar } from './QMenuBar';
export const QMainWindowEvents = Object.freeze({
...BaseWidgetEvents,
});
export class QMainWindow extends NodeWidget {
native: NativeElement;
public centralWidget?: NodeWidget;
private _menuBar?: QMenuBar;
constructor(parent?: NodeWidget) {
let native;
if (parent) {
native = new addon.QMainWindow(parent.native);
} else {
native = new addon.QMainWindow();
}
super(native);
this.native = native;
this.nodeParent = parent;
this.setLayout = (parentLayout: NodeLayout): void => {
if (this.centralWidget) {
this.centralWidget.setLayout(parentLayout);
} else {
this.native.setLayout(parentLayout.native);
super.layout = parentLayout;
}
};
}
setCentralWidget(widget: NodeWidget): void {
// react:✓
this.native.setCentralWidget(widget.native, widget.getFlexNode());
this.centralWidget = widget;
}
setMenuBar(menuBar: QMenuBar): void {
this.native.setMenuBar(menuBar.native);
this._menuBar = menuBar;
}
menuBar(): QMenuBar | undefined {
return this._menuBar;
}
setMenuWidget(menuWidget: NodeWidget): void {
this.native.setMenuWidget(menuWidget.native);
}
get layout(): NodeLayout | undefined {
if (this.centralWidget) {
return this.centralWidget.layout;
} else {
return super.layout;
}
}
center(): void {
this.native.center();
}
}