From a9a1535a12a511fb21a05f9c0a9b5d673c2c2679 Mon Sep 17 00:00:00 2001 From: Atul R Date: Sat, 26 Oct 2019 22:21:17 +0200 Subject: [PATCH] Adds menubar, menu, systemtrayicon, shortcut and action docs --- src/lib/QtWidgets/QAction/index.ts | 4 +- src/lib/QtWidgets/QShortcut/index.ts | 4 +- src/lib/QtWidgets/QSystemTrayIcon/index.ts | 5 +- website/docs/api/QAction.md | 76 ++++++++++++++++++++++ website/docs/api/QKeySequence.md | 39 +++++++++++ website/docs/api/QMainWindow.md | 12 ++++ website/docs/api/QMenu.md | 46 +++++++++++++ website/docs/api/QMenuBar.md | 50 ++++++++++++++ website/docs/api/QShortcut.md | 68 +++++++++++++++++++ website/docs/api/QSystemTrayIcon.md | 4 +- website/sidebars.js | 18 +++-- 11 files changed, 314 insertions(+), 12 deletions(-) create mode 100644 website/docs/api/QAction.md create mode 100644 website/docs/api/QKeySequence.md create mode 100644 website/docs/api/QMenu.md create mode 100644 website/docs/api/QMenuBar.md create mode 100644 website/docs/api/QShortcut.md diff --git a/src/lib/QtWidgets/QAction/index.ts b/src/lib/QtWidgets/QAction/index.ts index d305bae59..94f919f60 100644 --- a/src/lib/QtWidgets/QAction/index.ts +++ b/src/lib/QtWidgets/QAction/index.ts @@ -1,11 +1,11 @@ import addon from "../../utils/addon"; import { NodeWidget } from "../QWidget"; -import { EventWidget, BaseWidgetEvents } from "../../core/EventWidget"; import { NativeElement } from "../../core/Component"; import { QMenu } from "../QMenu"; import { QIcon } from "../../QtGui/QIcon"; import { QKeySequence } from "../../QtGui/QKeySequence"; import { ShortcutContext } from "../../QtEnums"; +import { QObject } from "../../QtCore/QObject"; export const QActionEvents = Object.freeze({ triggered: "triggered", @@ -13,7 +13,7 @@ export const QActionEvents = Object.freeze({ hovered: "hovered", toggled: "toggled" }); -export class QAction extends EventWidget { +export class QAction extends QObject { native: NativeElement; icon?: QIcon; menu?: QMenu; diff --git a/src/lib/QtWidgets/QShortcut/index.ts b/src/lib/QtWidgets/QShortcut/index.ts index 01e797857..8dbdf3507 100644 --- a/src/lib/QtWidgets/QShortcut/index.ts +++ b/src/lib/QtWidgets/QShortcut/index.ts @@ -1,16 +1,16 @@ import addon from "../../utils/addon"; import { NodeWidget } from "../QWidget"; -import { EventWidget } from "../../core/EventWidget"; import { NativeElement } from "../../core/Component"; import { QKeySequence } from "../../QtGui/QKeySequence"; import { ShortcutContext } from "../../QtEnums"; +import { QObject } from "../../QtCore/QObject"; export const QShortcutEvents = Object.freeze({ activated: "activated", activatedAmbiguously: "activatedAmbiguously" }); -export class QShortcut extends EventWidget { +export class QShortcut extends QObject { native: NativeElement; constructor(parent: NodeWidget) { let native = new addon.QShortcut(parent.native); diff --git a/src/lib/QtWidgets/QSystemTrayIcon/index.ts b/src/lib/QtWidgets/QSystemTrayIcon/index.ts index 183e49d7e..1cf92df28 100644 --- a/src/lib/QtWidgets/QSystemTrayIcon/index.ts +++ b/src/lib/QtWidgets/QSystemTrayIcon/index.ts @@ -1,14 +1,15 @@ import addon from "../../utils/addon"; import { NodeWidget } from "../QWidget"; -import { EventWidget, BaseWidgetEvents } from "../../core/EventWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; import { NativeElement } from "../../core/Component"; import { QIcon } from "../../QtGui/QIcon"; import { QMenu } from "../QMenu"; +import { QObject } from "../../QtCore/QObject"; export const QSystemTrayIconEvents = Object.freeze({ ...BaseWidgetEvents }); -export class QSystemTrayIcon extends EventWidget { +export class QSystemTrayIcon extends QObject { native: NativeElement; contextMenu?: QMenu; constructor(parent?: NodeWidget) { diff --git a/website/docs/api/QAction.md b/website/docs/api/QAction.md new file mode 100644 index 000000000..69850b9a4 --- /dev/null +++ b/website/docs/api/QAction.md @@ -0,0 +1,76 @@ +--- +sidebar_label: QAction +title: QAction +--- + +> The QAction class provides an abstract user interface action that can be inserted into widgets. + +**This class is a JS wrapper around Qt's [QAction class](https://doc.qt.io/qt-5/qaction.html)** + +**QAction inherits from [EventWidget](api/EventWidget.md)** + +### Example + +```javascript +const { QAction, QMenu } = require("@nodegui/nodegui"); + +const menu = new QMenu(); +const menuAction = new QAction(); +menuAction.setText("subAction"); +menuAction.addEventListener("triggered", () => { + console.log("Action clicked"); +}); +menu.addAction(menuAction); +``` + +### `new QAction(parent?)` + +- `parent` NodeWidget. Constructs an action with parent. If parent is an action group the action will be automatically inserted into the group. + +## Static Methods + +QAction can access all the static methods defined in [EventWidget](api/EventWidget.md) + +## Instance Properties + +QAction can access all the instance properties defined in [EventWidget](api/EventWidget.md) + +## Instance Methods + +QAction can access all the instance methods defined in [EventWidget](api/EventWidget.md). Additionally it also has the following instance methods: + +### `action.setEnabled(enabled)` + +This property holds whether the action is enabled. It calls the native method [QAction: setEnabled](https://doc.qt.io/qt-5/qaction.html#enabled-prop). + +- `enabled` - Boolean + +### `action.setText(on)` + +This property holds the action's descriptive text. It calls the native method [QAction: setText](https://doc.qt.io/qt-5/qaction.html#text-prop). + +- `text` - string + +### `action.setIcon(icon)` + +Sets the icon of action. It calls the native method [QAction: setIcon](https://doc.qt.io/qt-5/qaction.html#icon-prop). + +- `icon` [QIcon](api/QIcon.md) + +### `action.setMenu(menu)` + +Sets the menu contained by this action to the specified menu. It calls the native method [QAction: setMenu](https://doc.qt.io/qt-5/qaction.html#setMenu). + +- `menu` [QMenu](api/QMenu.md) + +### `action.setShortcut(keySequence)` + +This property holds the action's key sequence. It calls the native method [QAction: setShortcut](https://doc.qt.io/qt-5/qaction.html#shortcut-prop). + +- `keySequence` [QKeySequence](api/QKeySequence.md) + +### `action.setShortcutContext(contextEnum)` + +This property holds the context in which the action is valid. It calls the native method [QAction: setShortcutContext](https://doc.qt.io/qt-5/qaction.html#shortcutContext-prop). + +- `contextEnum` - ShortcutContext enum. diff --git a/website/docs/api/QKeySequence.md b/website/docs/api/QKeySequence.md new file mode 100644 index 000000000..d73f5c29b --- /dev/null +++ b/website/docs/api/QKeySequence.md @@ -0,0 +1,39 @@ +--- +sidebar_label: QKeySequence +title: QKeySequence +--- + +> The QKeySequence class encapsulates a key sequence as used by shortcuts. . + +**This class is a JS wrapper around Qt's [QKeySequence class](https://doc.qt.io/qt-5/qkeysequence.html)** + +**QKeySequence inherits from [Component](api/Component.md)** + +### Example + +```javascript +const { QKeySequence } = require("@nodegui/nodegui"); + +const keySequence = new QKeySequence(`Ctrl+L`); +``` + +### `new QKeySequence(sequence?)` + +- `sequence` string (_optional_). String representation of the key sequence. For example: `Ctrl+M` + +## Static Methods + +QKeySequence can access all the static methods defined in [Component](api/Component.md) + +## Instance Properties + +QKeySequence can access all the instance properties defined in [Component](api/Component.md) + +## Instance Methods + +QKeySequence can access all the instance methods defined in [Component](api/Component.md) +Additionally it also has the following instance methods: + +### `keySequence.count()` + +Returns the number of keys in the key sequence. The maximum is 4. It calls the native method [QKeySequence: count](https://doc.qt.io/qt-5/QKeySequence.html#count). diff --git a/website/docs/api/QMainWindow.md b/website/docs/api/QMainWindow.md index 6c9b2a682..3dda05df5 100644 --- a/website/docs/api/QMainWindow.md +++ b/website/docs/api/QMainWindow.md @@ -58,3 +58,15 @@ Additionally it also has the following instance methods: Sets the given widget to be the main window's central widget. - `widget` NodeWidget - Any widget that inherits from NodeWidget class. + +### `win.setMenuBar(menuBar)` + +Sets the given menuBar to be the window's menubar widget. + +- `menuBar` [QMenuBar](api/QMenuBar) + +### `win.setMenuWidget(menuWidget)` + +Sets the given widget to be the window's menubar widget. + +- `menuWidget` NodeWidget diff --git a/website/docs/api/QMenu.md b/website/docs/api/QMenu.md new file mode 100644 index 000000000..c7c51bc01 --- /dev/null +++ b/website/docs/api/QMenu.md @@ -0,0 +1,46 @@ +--- +sidebar_label: QMenu +title: QMenu +--- + +> 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)** + +**QMenu inherits from [NodeWidget](api/NodeWidget.md)** + +### Example + +```javascript +const { QMenu } = require("@nodegui/nodegui"); + +const menu = new QMenu(); +``` + +### `new QMenu(parent?)` + +- `parent` NodeWidget (_optional_). Any widget inheriting from NodeWidget can be passed as a parent. This will make this widget, the child of the parent widget. + +## Static Methods + +QMenu can access all the static methods defined in [NodeWidget](api/NodeWidget.md) + +## Instance Properties + +QMenu can access all the instance properties defined in [NodeWidget](api/NodeWidget.md) + +## Instance Methods + +QMenu can access all the instance methods defined in [NodeWidget](api/NodeWidget.md). Additionally it also has the following instance methods: + +### `menu.setTitle(title)` + +This property holds the title of the menu. It calls the native method [QMenu: setTitle](https://doc.qt.io/qt-5/qmenu.html#title-prop). + +- `title` string + +### `menu.addAction(action)` + +Appends the action action to this widget's list of actions. It calls the native method [QMenu: addAction](https://doc.qt.io/qt-5/qwidget.html#addAction). + +- `action` [QAction](api/QAction). diff --git a/website/docs/api/QMenuBar.md b/website/docs/api/QMenuBar.md new file mode 100644 index 000000000..b5b64bbd9 --- /dev/null +++ b/website/docs/api/QMenuBar.md @@ -0,0 +1,50 @@ +--- +sidebar_label: QMenuBar +title: QMenuBar +--- + +> The QMenuBar 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 [QMenuBar class](https://doc.qt.io/qt-5/qmenu.html)** + +**QMenuBar inherits from [NodeWidget](api/NodeWidget.md)** + +### Example + +```javascript +const { QMenuBar, QMainWindow } = require("@nodegui/nodegui"); +const win = new QMainWindow(); +const menu = new QMenuBar(); +const menuBar = new QMenuBar(); +win.setMenuBar(menuBar); +win.show(); +global.win = win; +``` + +### `new QMenuBar(parent?)` + +- `parent` NodeWidget (_optional_). Any widget inheriting from NodeWidget can be passed as a parent. This will make this widget, the child of the parent widget. + +## Static Methods + +QMenuBar can access all the static methods defined in [NodeWidget](api/NodeWidget.md) + +## Instance Properties + +QMenuBar can access all the instance properties defined in [NodeWidget](api/NodeWidget.md) + +## Instance Methods + +QMenuBar can access all the instance methods defined in [NodeWidget](api/NodeWidget.md). Additionally it also has the following instance methods: + +### `menu.addMenu(menu)` + +Appends menu to the menu bar. It calls the native method [QMenuBar: addMenu](https://doc.qt.io/qt-5/qmenubar.html#addMenu). + +- `menu` [QMenu](api/QMenu). + +### `menu.setNativeMenuBar(nativeMenuBar)` + +This property holds whether or not a menubar will be used as a native menubar on platforms that support it. It calls the native method [QMenuBar: setNativeMenuBar](https://doc.qt.io/qt-5/qmenubar.html#nativeMenuBar-prop). + +- `nativeMenuBar` Boolean. diff --git a/website/docs/api/QShortcut.md b/website/docs/api/QShortcut.md new file mode 100644 index 000000000..c902b5dfc --- /dev/null +++ b/website/docs/api/QShortcut.md @@ -0,0 +1,68 @@ +--- +sidebar_label: QShortcut +title: QShortcut +--- + +> The QShortcut class is used to create keyboard shortcuts. + +**This class is a JS wrapper around Qt's [QShortcut class](https://doc.qt.io/qt-5/qshortcut.html)** + +**QShortcut inherits from [EventWidget](api/EventWidget.md)** + +### Example + +```javascript +const { QShortcut, QKeySequence, QMainWindow } = require("@nodegui/nodegui"); + +const win = new QMainWindow(); +const shortcut = new QShortcut(win); +shortcut.setKey(new QKeySequence("Ctrl+M")); +shortcut.setEnabled(true); +shortcut.addEventListener(QShortcutEvents.activated, () => { + console.log("Shortcut Activated"); +}); + +win.show(); +global.win = win; +global.shortcut = shortcut; +``` + +### `new QShortcut(parent)` + +- `parent` NodeWidget. Any widget inheriting from NodeWidget can be passed as a parent. This will make this shortcut bind to the parent widget. + +## Static Methods + +QShortcut can access all the static methods defined in [EventWidget](api/EventWidget.md) + +## Instance Properties + +QShortcut can access all the instance properties defined in [EventWidget](api/EventWidget.md) + +## Instance Methods + +QShortcut can access all the instance methods defined in [EventWidget](api/EventWidget.md). Additionally it also has the following instance methods: + +### `shortcut.setEnabled(enabled)` + +This property holds whether the shortcut is enabled. It calls the native method [QShortcut: setEnabled](https://doc.qt.io/qt-5/qshortcut.html#enabled-prop). + +- `enabled` - Boolean + +### `shortcut.setAutoRepeat(on)` + +This property holds whether the shortcut can auto repeat. It calls the native method [QShortcut: setAutoRepeat](https://doc.qt.io/qt-5/qshortcut.html#autoRepeat-prop). + +- `on` - Boolean + +### `shortcut.setKey(keySequence)` + +This property holds the shortcut's key sequence. It calls the native method [QShortcut: setKey](https://doc.qt.io/qt-5/qshortcut.html#key-prop). + +- `keySequence` [QKeySequence](api/QKeySequence.md) + +### `shortcut.setContext(contextEnum)` + +This property holds the context in which the shortcut is valid. It calls the native method [QShortcut: setContext](https://doc.qt.io/qt-5/qshortcut.html#context-prop). + +- `contextEnum` - ShortcutContext enum. diff --git a/website/docs/api/QSystemTrayIcon.md b/website/docs/api/QSystemTrayIcon.md index 54dc3d1f2..d373f8c74 100644 --- a/website/docs/api/QSystemTrayIcon.md +++ b/website/docs/api/QSystemTrayIcon.md @@ -1,6 +1,6 @@ --- -sidebar_label: QSsystemTrayIcon -title: QSsystemTrayIcon +sidebar_label: QSystemTrayIcon +title: QSystemTrayIcon --- > Create and control system tray icon. diff --git a/website/sidebars.js b/website/sidebars.js index e676cabfb..643c49c8f 100755 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -5,7 +5,6 @@ module.exports = { "api/QApplication", "api/QCheckBox", "api/QDial", - "api/QIcon", "api/QLabel", "api/QLineEdit", "api/QMainWindow", @@ -15,12 +14,23 @@ module.exports = { "api/QRadioButton", "api/QScrollArea", "api/QSpinBox", - "api/QSystemTrayIcon", "api/QTabWidget", - "api/QWidget" + "api/QWidget", + "api/QMenu", + "api/QMenuBar" ], Layouts: ["api/FlexLayout", "api/QGridLayout"], - Modules: ["api/QClipboard", "api/QCursor", "api/QPixmap", "api/QtEnums"], + Modules: [ + "api/QClipboard", + "api/QCursor", + "api/QPixmap", + "api/QtEnums", + "api/QShortcut", + "api/QAction", + "api/QKeySequence", + "api/QIcon", + "api/QSystemTrayIcon" + ], "Internal Modules": [ "api/Component", "api/EventWidget",