nodeguy/src/lib/QtWidgets/QMenu.ts
gluaxspeed 34d32a1e74 Improving Menu Bars (#347)
* menu and menubar changes so far

* attempting to add a simpler way to create menubars

* menu and menubar changes so far

* attempting to add a simpler way to create menubars

* attempting to add a simpler way to create menubars

* rebased from master

* rebased from master

* Move qaction creation to qwidget macro

* removed addMenuWithName

* exec, and popup working

Co-authored-by: Atul R <atulanand94@gmail.com>
2020-01-22 22:06:12 +01:00

56 lines
1.5 KiB
TypeScript

import { NativeElement } from '../core/Component';
import { NodeWidget, QWidgetSignals } from './QWidget';
import addon from '../utils/addon';
import { QAction } from './QAction';
import { QPoint } from '../QtCore/QPoint';
/**
> The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
* **This class is a JS wrapper around Qt's [QMenu class](https://doc.qt.io/qt-5/qmenu.html)**
### Example
```javascript
const { QMenu } = require("@nodegui/nodegui");
const menu = new QMenu();
```
*/
export class QMenu extends NodeWidget<QMenuSignals> {
native: NativeElement;
constructor();
constructor(parent: NodeWidget<any>);
constructor(parent?: NodeWidget<any>) {
let native;
if (parent) {
native = new addon.QMenu(parent.native);
} else {
native = new addon.QMenu();
}
super(native);
this.native = native;
this.setNodeParent(parent);
}
setTitle(title: string): void {
this.native.setTitle(title);
}
addSeparator(): QAction {
return this.native.addSeparator();
}
exec(point?: QPoint, action?: QAction): void {
if (point && action) {
this.native.exec(point.native, action.native);
return;
}
this.native.exec();
}
popup(point: QPoint, action?: QAction): void {
this.native.popup(point.native, action?.native);
}
}
export type QMenuSignals = QWidgetSignals;