From a6d8012a8ef48c9c4ae00659bab1d6c6458c1cb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Borecki?=
Date: Thu, 22 Aug 2019 21:30:05 +0200
Subject: [PATCH 1/2] Added move/get position widget capability
---
src/cpp/QtWidgets/QWidget/qwidget_macro.h | 30 +++++++++++++++++++++++
src/lib/QtGui/QWidget/index.ts | 9 +++++++
2 files changed, 39 insertions(+)
diff --git a/src/cpp/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/QtWidgets/QWidget/qwidget_macro.h
index 824fe5cf4..e993de2db 100644
--- a/src/cpp/QtWidgets/QWidget/qwidget_macro.h
+++ b/src/cpp/QtWidgets/QWidget/qwidget_macro.h
@@ -69,6 +69,14 @@ Napi::Value hide(const Napi::CallbackInfo& info) { \
this->instance->hide(); \
return env.Null(); \
} \
+Napi::Value move(const Napi::CallbackInfo& info){ \
+ Napi::Env env = info.Env(); \
+ Napi::HandleScope scope(env); \
+ int x = info[0].As().Int32Value(); \
+ int y = info[1].As().Int32Value(); \
+ this->instance->move(x, y); \
+ return env.Null(); \
+} \
\
Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
@@ -105,6 +113,16 @@ Napi::Value setFixedSize(const Napi::CallbackInfo& info){ \
this->instance->setFixedSize(width, height); \
return env.Null(); \
} \
+Napi::Value setGeometry(const Napi::CallbackInfo& info){ \
+ Napi::Env env = info.Env(); \
+ Napi::HandleScope scope(env); \
+ int x = info[0].As().Int32Value(); \
+ int y = info[1].As().Int32Value(); \
+ int width = info[2].As().Int32Value(); \
+ int height = info[3].As().Int32Value(); \
+ this->instance->setGeometry(x, y, width, height); \
+ return env.Null(); \
+} \
Napi::Value setMaximumSize(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
@@ -139,6 +157,15 @@ Napi::Value updateGeometry(const Napi::CallbackInfo& info){ \
this->instance->updateGeometry(); \
return env.Null(); \
} \
+Napi::Value pos(const Napi::CallbackInfo& info){ \
+ Napi::Env env = info.Env(); \
+ Napi::HandleScope scope(env); \
+ QPoint pos = this->instance->pos(); \
+ Napi::Object posObj = Napi::Object::New(env); \
+ posObj.Set("x", pos.x()); \
+ posObj.Set("y", pos.y()); \
+ return posObj; \
+} \
Napi::Value size(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
@@ -194,16 +221,19 @@ Napi::Value setWindowFlag(const Napi::CallbackInfo& info){ \
InstanceMethod("setStyleSheet",&WidgetWrapName::setStyleSheet), \
InstanceMethod("styleSheet",&WidgetWrapName::styleSheet), \
InstanceMethod("hide",&WidgetWrapName::hide), \
+ InstanceMethod("move",&WidgetWrapName::move), \
InstanceMethod("setObjectName",&WidgetWrapName::setObjectName), \
InstanceMethod("objectName",&WidgetWrapName::objectName), \
InstanceMethod("setMouseTracking",&WidgetWrapName::setMouseTracking), \
InstanceMethod("setEnabled",&WidgetWrapName::setEnabled), \
InstanceMethod("setFixedSize",&WidgetWrapName::setFixedSize), \
+ InstanceMethod("setGeometry",&WidgetWrapName::setGeometry), \
InstanceMethod("setMaximumSize",&WidgetWrapName::setMaximumSize), \
InstanceMethod("setMinimumSize",&WidgetWrapName::setMinimumSize), \
InstanceMethod("repaint",&WidgetWrapName::repaint), \
InstanceMethod("update",&WidgetWrapName::update), \
InstanceMethod("updateGeometry",&WidgetWrapName::updateGeometry), \
+ InstanceMethod("pos",&WidgetWrapName::pos), \
InstanceMethod("size",&WidgetWrapName::size), \
InstanceMethod("setAttribute",&WidgetWrapName::setAttribute), \
InstanceMethod("testAttribute",&WidgetWrapName::testAttribute), \
diff --git a/src/lib/QtGui/QWidget/index.ts b/src/lib/QtGui/QWidget/index.ts
index 15a3f7c18..ad582039c 100644
--- a/src/lib/QtGui/QWidget/index.ts
+++ b/src/lib/QtGui/QWidget/index.ts
@@ -46,6 +46,9 @@ export abstract class NodeWidget extends EventWidget {
hide = () => {
this.native.hide();
};
+ move = (x: number, y: number) => {
+ this.native.move(x, y);
+ };
setObjectName = (objectName: string) => {
this.native.setObjectName(objectName);
};
@@ -61,6 +64,9 @@ export abstract class NodeWidget extends EventWidget {
setFixedSize = (width: number, height: number) => {
this.native.setFixedSize(width, height);
};
+ setGeometry = (x: number, y: number, w: number, h: number) => {
+ this.native.setGeometry(x, y, w, h);
+ };
setMaximumSize = (maxw: number, maxh: number) => {
this.native.setMaximumSize(maxw, maxh);
};
@@ -76,6 +82,9 @@ export abstract class NodeWidget extends EventWidget {
updateGeometry = () => {
this.native.updateGeometry();
};
+ pos = (): { x: number; y: number } => {
+ return this.native.pos();
+ };
size = (): { width: number; height: number } => {
return this.native.size();
};
From 4e9f2d32ccf26862ed86e6b2556e9a5f105119f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Borecki?=
Date: Thu, 22 Aug 2019 21:34:49 +0200
Subject: [PATCH 2/2] Added docs for widget move/position capabilities
---
docs/api/NodeWidget.md | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/docs/api/NodeWidget.md b/docs/api/NodeWidget.md
index a04011d8f..7d0895b18 100644
--- a/docs/api/NodeWidget.md
+++ b/docs/api/NodeWidget.md
@@ -90,6 +90,13 @@ Gets the property that holds the widget's style sheet. It calls the native metho
Hides the widget and its children. It calls the native method [QWidget: hide](https://doc.qt.io/qt-5/qwidget.html#hide).
+#### `widget.move(x, y)`
+
+Sets the screen position of the widget. It calls the native method [QWidget: move](https://doc.qt.io/qt-5/qwidget.html#move-1).
+
+- `x` number - Pixels.
+- `y` number - Pixels.
+
#### `widget.setObjectName(objectName)`
Sets the object name of the widget in Qt. It calls the native method [QObject: setObjectName](https://doc.qt.io/qt-5/qobject.html#objectName-prop). Object name can be analogous to `id` of an element in the web world. Using the objectName of the widget one can reference it in the Qt's stylesheet much like what we do with id in the web world.
@@ -119,6 +126,15 @@ Sets both the minimum and maximum sizes of the widget. It calls the native metho
- `width` number - Pixels.
- `height` number - Pixels.
+#### `widget.setGeometry(x, y, width, height)`
+
+Sets the screen position as well as size of the widget. It calls the native method [QWidget: setGeometry](https://doc.qt.io/qt-5/qwidget.html#setGeometry-1).
+
+- `x` number - Pixels.
+- `y` number - Pixels.
+- `width` number - Pixels.
+- `height` number - Pixels.
+
#### `widget.setMaximumSize(width, height)`
Sets the maximum size of the widget. It calls the native method [QWidget: setMaximumSize](https://doc.qt.io/qt-5/qwidget.html#setMaximumSize-1).
@@ -141,6 +157,10 @@ Repaints the widget. It calls the native method [QWidget: repaint](https://doc.q
Updates the widget. It calls the native method [QWidget: update](https://doc.qt.io/qt-5/qwidget.html#update).
+#### `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.
+
#### `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.