inherits (#125)
This commit is contained in:
parent
92a23b185f
commit
4d617c9321
@ -88,6 +88,13 @@ Napi::Value setWindowTitle(const Napi::CallbackInfo& info){ \
|
||||
this->instance->setWindowTitle(title.c_str()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value inherits(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::String className = info[0].As<Napi::String>(); \
|
||||
std::string s = className.Utf8Value(); \
|
||||
return Napi::Boolean::New(env, this->instance->inherits(s.c_str())); \
|
||||
} \
|
||||
Napi::Value styleSheet(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
@ -261,6 +268,7 @@ Napi::Value setWindowFlag(const Napi::CallbackInfo& info){ \
|
||||
InstanceMethod("close",&WidgetWrapName::close), \
|
||||
InstanceMethod("setLayout",&WidgetWrapName::setLayout), \
|
||||
InstanceMethod("setStyleSheet",&WidgetWrapName::setStyleSheet), \
|
||||
InstanceMethod("inherits",&WidgetWrapName::inherits), \
|
||||
InstanceMethod("setCursor",&WidgetWrapName::setCursor), \
|
||||
InstanceMethod("setWindowIcon",&WidgetWrapName::setWindowIcon), \
|
||||
InstanceMethod("setWindowState",&WidgetWrapName::setWindowState), \
|
||||
|
||||
23
src/demo.ts
23
src/demo.ts
@ -84,10 +84,11 @@ if (tab1.layout && tab2.layout) {
|
||||
tabs.addTab(tab1, icon, "Tab 1");
|
||||
tabs.addTab(tab2, icon, "Tab 2");
|
||||
|
||||
const progressbar = new QProgressBar();
|
||||
progressbar.setValue(6);
|
||||
progressbar.setMinimum(1);
|
||||
progressbar.setMaximum(15);
|
||||
const progressBar = new QProgressBar();
|
||||
progressBar.setValue(6);
|
||||
equal(progressBar.value(), 6)
|
||||
progressBar.setMinimum(1);
|
||||
progressBar.setMaximum(15);
|
||||
|
||||
const radioButton = new QRadioButton();
|
||||
radioButton.setText("Roger that!");
|
||||
@ -103,6 +104,18 @@ textEdit.setWordWrapMode(QTextOptionWrapMode.NoWrap);
|
||||
const scrollArea = new QScrollArea();
|
||||
scrollArea.setInlineStyle("flex: 1; width:'100%';");
|
||||
|
||||
// NodeWidget.inherits tests
|
||||
ok(tab1.inherits("QWidget"))
|
||||
ok(tabs.inherits("QTabWidget"))
|
||||
ok(tabs.inherits("QWidget"))
|
||||
ok(tabs.inherits("QObject"))
|
||||
ok(!tabs.inherits("QProgressBar"))
|
||||
ok(progressBar.inherits("QProgressBar"))
|
||||
ok(!progressBar.inherits("QTabWidget"))
|
||||
ok(tabs.inherits("QWidget"))
|
||||
ok(tabs.inherits("QObject"))
|
||||
ok(!tabs.inherits("unknown"))
|
||||
|
||||
const imageLabel = new QLabel();
|
||||
const pixmap = new QPixmap(
|
||||
resolve(__dirname, "../extras/assets/kitchen.png")
|
||||
@ -142,7 +155,7 @@ if (rootView.layout) {
|
||||
rootView.layout.addWidget(radioButton);
|
||||
rootView.layout.addWidget(lineEdit);
|
||||
rootView.layout.addWidget(button);
|
||||
rootView.layout.addWidget(progressbar);
|
||||
rootView.layout.addWidget(progressBar);
|
||||
rootView.layout.addWidget(textEdit);
|
||||
rootView.layout.addWidget(scrollArea);
|
||||
rootView.layout.addWidget(dial);
|
||||
|
||||
@ -76,6 +76,9 @@ export abstract class NodeWidget extends EventWidget {
|
||||
// react:✓, //TODO:getter
|
||||
return this.native.setWindowTitle(title);
|
||||
};
|
||||
inherits(className: string) {
|
||||
return this.native.inherits(className);
|
||||
};
|
||||
setWindowState = async (state: WindowState) => {
|
||||
// react:✓, //TODO:getter
|
||||
return this.native.setWindowState(state);
|
||||
|
||||
@ -7,7 +7,7 @@ title: NodeWidget
|
||||
|
||||
**This class implements all methods, properties of Qt's [QWidget class](https://doc.qt.io/qt-5/qwidget.html) so that it can be inherited by all widgets**
|
||||
|
||||
`NodeWidget` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all widget's easily. Additionally it helps in typechecking process. If you wish to create a `div` like widget use [QWidget](api/QWidget.md) instead.
|
||||
`NodeWidget` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all widget's easily. Additionally it helps in type checking process. If you wish to create a `div` like widget use [QWidget](api/QWidget.md) instead.
|
||||
|
||||
**NodeWidget is the base class for all widgets. It inherits from another abstract class [EventWidget](api/EventWidget.md)**
|
||||
|
||||
@ -186,11 +186,11 @@ Updates the widget. It calls the native method [QWidget: update](https://doc.qt.
|
||||
|
||||
### `widget.pos()`
|
||||
|
||||
returns the current widget position. It calls the native method [QWidget: pos](https://doc.qt.io/qt-5/qwidget.html#pos-prop). The returned size object contains x and y coordinates in pixels.
|
||||
Returns the current widget position. It calls the native method [QWidget: pos](https://doc.qt.io/qt-5/qwidget.html#pos-prop). The returned size object contains x and y coordinates in pixels.
|
||||
|
||||
### `widget.size()`
|
||||
|
||||
returns the current widget size. It calls the native method [QWidget: size](https://doc.qt.io/qt-5/qwidget.html#size-prop). The returned size object contains width and height in pixels.
|
||||
Returns the current widget size. It calls the native method [QWidget: size](https://doc.qt.io/qt-5/qwidget.html#size-prop). The returned size object contains width and height in pixels.
|
||||
|
||||
### `widget.updateGeometry()`
|
||||
|
||||
@ -201,10 +201,23 @@ Notifies the layout system that this widget has changed and may need to change g
|
||||
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. It calls the native method [QWidget: setAttribute](https://doc.qt.io/qt-5/qwidget.html#setAttribute).
|
||||
|
||||
- `attributeName` WidgetAttribute - Enum from WidgetAttribute.
|
||||
- `switchOn` - set it to true if you want to enable an attribute.
|
||||
- `switchOn` boolean - set it to true if you want to enable an attribute.
|
||||
|
||||
### `widget.testAttribute(attributeName)`
|
||||
|
||||
Returns true if attribute attribute is set on this widget; otherwise returns false. It calls the native method [QWidget: testAttribute](https://doc.qt.io/qt-5/qwidget.html#testAttribute).
|
||||
|
||||
- `attributeName` WidgetAttribute - Enum from WidgetAttribute.
|
||||
|
||||
#### `widget.inherits(className)`
|
||||
|
||||
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. A class is considered to inherit itself. Example:
|
||||
|
||||
```ts
|
||||
const progressBar = new QProgressBar();
|
||||
progressBar.inherits("QObject"); // returns true
|
||||
progressBar.inherits("QProgressBar"); // returns true
|
||||
progressBar.inherits("QTabWidget"); // returns false
|
||||
```
|
||||
|
||||
- `className` string - Name of the class to get if this widget inherits from.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user