From 0c4fabfa85d76f51b4c0296c745f7990bdb91ae9 Mon Sep 17 00:00:00 2001 From: Dimitar Nestorov Date: Fri, 1 Nov 2019 21:46:43 +0200 Subject: [PATCH] Added isSeparator and setSeparator to QAction --- .../nodegui/QtWidgets/QAction/qaction_wrap.h | 2 ++ .../lib/QtWidgets/QAction/qaction_wrap.cpp | 23 +++++++++++++++ src/demo.ts | 4 +++ src/lib/QtWidgets/QAction/index.ts | 6 ++++ website/docs/api/QAction.md | 28 ++++++++++++++----- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h b/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h index 7ced9a27e..618fe74f9 100644 --- a/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h @@ -25,6 +25,8 @@ class QActionWrap : public Napi::ObjectWrap{ Napi::Value setCheckable(const Napi::CallbackInfo& info); Napi::Value isChecked(const Napi::CallbackInfo& info); Napi::Value setChecked(const Napi::CallbackInfo& info); + Napi::Value isSeparator(const Napi::CallbackInfo& info); + Napi::Value setSeparator(const Napi::CallbackInfo& info); EVENTWIDGET_WRAPPED_METHODS_DECLARATION }; diff --git a/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp b/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp index 3656b1ece..638fc242c 100644 --- a/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp @@ -23,6 +23,8 @@ Napi::Object QActionWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("setCheckable", &QActionWrap::setCheckable), InstanceMethod("isChecked", &QActionWrap::isChecked), InstanceMethod("setChecked", &QActionWrap::setChecked), + InstanceMethod("isSeparator", &QActionWrap::isSeparator), + InstanceMethod("setSeparator", &QActionWrap::setSeparator), COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QActionWrap) }); @@ -153,3 +155,24 @@ Napi::Value QActionWrap::setChecked(const Napi::CallbackInfo& info) { return env.Null(); } + +Napi::Value QActionWrap::isSeparator(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + return Napi::Boolean::New(env, this->instance->isSeparator()); +} + +Napi::Value QActionWrap::setSeparator(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + if (info.Length() == 1) { + Napi::Boolean isSeparator = info[0].As(); + this->instance->setSeparator(isSeparator); + } else { + Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException(); + } + + return env.Null(); +} diff --git a/src/demo.ts b/src/demo.ts index e973ca97c..7010395c3 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -78,6 +78,10 @@ actionWithSubmenu.setMenu(subMenu); actionWithSubmenu.setText("subMenu"); menu.addAction(actionWithSubmenu); +const separatorAction = new QAction(); +separatorAction.setSeparator(true); +menu.addAction(separatorAction); + const quitAction = new QAction(); quitAction.setText("Quit"); quitAction.addEventListener("triggered", () => { diff --git a/src/lib/QtWidgets/QAction/index.ts b/src/lib/QtWidgets/QAction/index.ts index 8bdc464dd..78be4df78 100644 --- a/src/lib/QtWidgets/QAction/index.ts +++ b/src/lib/QtWidgets/QAction/index.ts @@ -59,4 +59,10 @@ export class QAction extends QObject { setChecked(isChecked: boolean) { this.native.setChecked(isChecked); } + isSeparator(): boolean { + return this.native.isSeparator(); + } + setSeparator(isSeparator: boolean) { + this.native.setSeparator(isSeparator); + } } diff --git a/website/docs/api/QAction.md b/website/docs/api/QAction.md index 6ac1ffb93..b378a5dab 100644 --- a/website/docs/api/QAction.md +++ b/website/docs/api/QAction.md @@ -77,29 +77,43 @@ This property holds the context in which the action is valid. It calls the nativ ### `action.isCheckable()` -Returns true if this action has been marked as checkable. It calls the native method [QIcon: isCheckable](https://doc.qt.io/qt-5/qaction.html#checkable-prop). +Returns true if this action has been marked as checkable. It calls the native method [QAction: isCheckable](https://doc.qt.io/qt-5/qaction.html#checkable-prop). -### `icon.setCheckable(isCheckable)` +### `action.setCheckable(isCheckable)` Indicate that this action is checkable. A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is `false`. -It calls the native method [QIcon: setCheckable](https://doc.qt.io/qt-5/qaction.html#checkable-prop). +It calls the native method [QAction: setCheckable](https://doc.qt.io/qt-5/qaction.html#checkable-prop). - `isCheckable`: boolean ### `action.isChecked()` -Returns true if this action has been marked as checked. It calls the native method [QIcon: isChecked](https://doc.qt.io/qt-5/qaction.html#checked-prop). +Returns true if this action has been marked as checked. It calls the native method [QAction: isChecked](https://doc.qt.io/qt-5/qaction.html#checked-prop). -### `icon.setChecked(isChecked)` +### `action.setChecked(isChecked)` Indicate that this action is checked. Only checkable actions can be checked. By default, this is false (the action is unchecked). -It calls the native method [QIcon: setChecked](https://doc.qt.io/qt-5/qaction.html#checkable-prop). +It calls the native method [QAction: setChecked](https://doc.qt.io/qt-5/qaction.html#checkable-prop). -- `isChecked`: boolean \ No newline at end of file +- `isChecked`: boolean + +### `action.isSeparator()` + +Returns `true` if this action is a separator action; otherwise it returns `false`. It calls the native method [QAction: isSeparator](https://doc.qt.io/qt-5/qaction.html#isSeparator). + +### `action.setSeparator(isSeparator)` + +If `isSeparator` is `true` then this action will be considered a separator. + +How a separator is represented depends on the widget it is inserted into. Under most circumstances the text, submenu, and icon will be ignored for separator actions. + +It calls the native method [QAction: setSeparator](https://doc.qt.io/qt-5/qaction.html#setSeparator). + +- `isSeparator`: boolean