Merge pull request #171 from dimitarnestorov/master
Added isSeparator and setSeparator to QAction
This commit is contained in:
commit
e1f3a3fe27
@ -25,6 +25,8 @@ class QActionWrap : public Napi::ObjectWrap<QActionWrap>{
|
||||
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
|
||||
};
|
||||
|
||||
@ -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<Napi::Boolean>();
|
||||
this->instance->setSeparator(isSeparator);
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
|
||||
}
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
- `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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user