Merge pull request #76 from Uriziel01/feature/missingQWidgetSetMethodsAndQCursor
Added missing QWidget set methods and QCursor support
This commit is contained in:
commit
3c51b99c0b
@ -14,6 +14,7 @@
|
||||
"../src/cpp/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp",
|
||||
"../src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp",
|
||||
"../src/cpp/QtGui/QIcon/qicon_wrap.cpp",
|
||||
"../src/cpp/QtGui/QCursor/qcursor_wrap.cpp",
|
||||
'../src/cpp/core/FlexLayout/flexlayout_wrap.cpp',
|
||||
"../src/cpp/QtWidgets/QWidget/qwidget_wrap.cpp",
|
||||
"../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp",
|
||||
|
||||
@ -82,6 +82,24 @@ Sets the property that holds the widget's style sheet. It calls the native metho
|
||||
|
||||
- `styleSheet` string - String which holds the widget's style sheet. Make sure you create this string using `StyleSheet.create()`
|
||||
|
||||
#### `widget.setCursor(cursor)`
|
||||
|
||||
Sets the window mouse cursor. It calls the native method [QWidget: setCursor](https://doc.qt.io/qt-5/qwidget.html#cursor-prop).
|
||||
|
||||
- `cursor` CursorShape - Specifies current cursor for the window [CursorShape is an enum from Qt](api/QtEnums.md)
|
||||
|
||||
#### `widget.setWindowIcon(icon)`
|
||||
|
||||
Sets the window icon. It calls the native method [QWidget: setWindowIcon](https://doc.qt.io/qt-5/qwidget.html#windowIcon-prop).
|
||||
|
||||
- `icon` QIcon - Specifies icon for the window.
|
||||
|
||||
#### `widget.setWindowState(state)`
|
||||
|
||||
Sets the window state. It calls the native method [QWidget: setWindowState](https://doc.qt.io/qt-5/qwidget.html#setWindowState).
|
||||
|
||||
- `state` WindowState - Specifies current state for the window [WindowState is an enum from Qt](api/QtEnums.md)
|
||||
|
||||
#### `widget.setWindowTitle(title)`
|
||||
|
||||
Sets the window title property. It calls the native method [QWidget: setWindowTitle](https://doc.qt.io/qt-5/qwidget.html#windowTitle-prop).
|
||||
|
||||
17
docs/api/QCursor.md
Normal file
17
docs/api/QCursor.md
Normal file
@ -0,0 +1,17 @@
|
||||
## Class: QCursor
|
||||
|
||||
> The QCursor class provides scalable icons in different modes and states.
|
||||
|
||||
**This class is a JS wrapper around Qt's [QCursor class](https://doc.qt.io/qt-5/qcursor.html)**
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const { QCursor } = require("@nodegui/nodegui");
|
||||
|
||||
const cursor = new QCursor();
|
||||
```
|
||||
|
||||
### `new QCursor(cursor)`
|
||||
|
||||
- `cursor` CursorShape (_optional_). Defines shape for the cursor. [CursorShape is an enum from Qt](api/QtEnums.md)
|
||||
BIN
extras/assets/nodegui.png
Normal file
BIN
extras/assets/nodegui.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
68
src/cpp/QtGui/QCursor/qcursor_wrap.cpp
Normal file
68
src/cpp/QtGui/QCursor/qcursor_wrap.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "qcursor_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
#include "src/cpp/QtGui/QPixmap/qpixmap_wrap.h"
|
||||
|
||||
Napi::FunctionReference QCursorWrap::constructor;
|
||||
|
||||
Napi::Object QCursorWrap::init(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QCursor";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("pos", &QCursorWrap::pos),
|
||||
InstanceMethod("setPos", &QCursorWrap::setPos),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QCursorWrap::QCursorWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap<QCursorWrap>(info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
if (info.Length() == 1)
|
||||
{
|
||||
Napi::Number cursor = info[0].As<Napi::Number>();
|
||||
this->instance = new QCursor(static_cast<Qt::CursorShape>(cursor.Int32Value()));
|
||||
}
|
||||
else if (info.Length() == 0)
|
||||
{
|
||||
this->instance = new QCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QCursorWrap::~QCursorWrap()
|
||||
{
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
QCursor *QCursorWrap::getInternalInstance()
|
||||
{
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QCursorWrap::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 QCursorWrap::setPos(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Number x = info[0].As<Napi::Number>();
|
||||
Napi::Number y = info[1].As<Napi::Number>();
|
||||
this->instance->setPos(x.Int32Value(), y.Int32Value());
|
||||
return env.Null();
|
||||
}
|
||||
21
src/cpp/QtGui/QCursor/qcursor_wrap.h
Normal file
21
src/cpp/QtGui/QCursor/qcursor_wrap.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include <QCursor>
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
class QCursorWrap : public Napi::ObjectWrap<QCursorWrap>
|
||||
{
|
||||
private:
|
||||
QCursor *instance;
|
||||
|
||||
public:
|
||||
static Napi::FunctionReference constructor;
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QCursorWrap(const Napi::CallbackInfo &info);
|
||||
~QCursorWrap();
|
||||
QCursor *getInternalInstance();
|
||||
// Wrapped methods
|
||||
Napi::Value pos(const Napi::CallbackInfo& info);
|
||||
Napi::Value setPos(const Napi::CallbackInfo& info);
|
||||
};
|
||||
@ -4,6 +4,7 @@
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
#include "src/cpp/core/Events/eventwidget_macro.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
#include "src/cpp/QtGui/QIcon/qicon_wrap.h"
|
||||
#include <QSize>
|
||||
/*
|
||||
|
||||
@ -57,6 +58,28 @@ Napi::Value setStyleSheet(const Napi::CallbackInfo& info){ \
|
||||
this->instance->setStyleSheet(style.c_str()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setCursor(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number cursor = info[0].As<Napi::Number>(); \
|
||||
this->instance->setCursor(static_cast<Qt::CursorShape>(cursor.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowIcon(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Object iconObject = info[0].As<Napi::Object>(); \
|
||||
QIconWrap *iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject); \
|
||||
this->instance->setWindowIcon(*iconWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowState(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number state = info[0].As<Napi::Number>(); \
|
||||
this->instance->setWindowState(static_cast<Qt::WindowState>(state.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setWindowTitle(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
@ -227,6 +250,9 @@ Napi::Value setWindowFlag(const Napi::CallbackInfo& info){ \
|
||||
InstanceMethod("close",&WidgetWrapName::close), \
|
||||
InstanceMethod("setLayout",&WidgetWrapName::setLayout), \
|
||||
InstanceMethod("setStyleSheet",&WidgetWrapName::setStyleSheet), \
|
||||
InstanceMethod("setCursor",&WidgetWrapName::setCursor), \
|
||||
InstanceMethod("setWindowIcon",&WidgetWrapName::setWindowIcon), \
|
||||
InstanceMethod("setWindowState",&WidgetWrapName::setWindowState), \
|
||||
InstanceMethod("setWindowTitle",&WidgetWrapName::setWindowTitle), \
|
||||
InstanceMethod("styleSheet",&WidgetWrapName::styleSheet), \
|
||||
InstanceMethod("hide",&WidgetWrapName::hide), \
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/QtGui/QPixmap/qpixmap_wrap.h"
|
||||
#include "src/cpp/QtGui/QIcon/qicon_wrap.h"
|
||||
#include "src/cpp/QtGui/QCursor/qcursor_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QDial/qdial_wrap.h"
|
||||
@ -29,6 +30,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QWidgetWrap::init(env, exports);
|
||||
QPixmapWrap::init(env, exports);
|
||||
QIconWrap::init(env, exports);
|
||||
QCursorWrap::init(env, exports);
|
||||
QGridLayoutWrap::init(env, exports);
|
||||
FlexLayoutWrap::init(env, exports);
|
||||
QMainWindowWrap::init(env, exports);
|
||||
|
||||
10
src/demo.ts
10
src/demo.ts
@ -14,6 +14,7 @@ import {
|
||||
} from "./index";
|
||||
import { QScrollArea } from "./lib/QtWidgets/QScrollArea";
|
||||
import { QPixmap } from "./lib/QtGui/QPixmap";
|
||||
import { CursorShape, WindowState } from "./lib/QtEnums"
|
||||
|
||||
const path = require("path");
|
||||
|
||||
@ -22,6 +23,7 @@ const win = new QMainWindow();
|
||||
const label = new QLabel();
|
||||
label.setText("Hello world 🧙");
|
||||
label.setInlineStyle("font-size: 20px;");
|
||||
label.setCursor(CursorShape.ForbiddenCursor);
|
||||
|
||||
const checkbox = new QCheckBox();
|
||||
checkbox.setText("Check me out?");
|
||||
@ -40,6 +42,10 @@ button.setText("Push Push Push!");
|
||||
button.setObjectName("btn");
|
||||
button.setFlat(true);
|
||||
|
||||
const nodeguiLogo = new QIcon(
|
||||
path.resolve(__dirname, "../extras/assets/nodegui.png")
|
||||
);
|
||||
|
||||
const icon = new QIcon(
|
||||
path.resolve(__dirname, "../extras/assets/start_icon.png")
|
||||
);
|
||||
@ -92,9 +98,11 @@ win.setStyleSheet(`
|
||||
}
|
||||
`);
|
||||
|
||||
win.setWindowTitle("hello");
|
||||
win.setWindowIcon(nodeguiLogo);
|
||||
win.setWindowTitle("NodeGUI Demo");
|
||||
|
||||
win.resize(400, 400);
|
||||
win.show();
|
||||
win.setWindowState(WindowState.WindowActive);
|
||||
|
||||
(global as any).win = win; // To prevent win from being garbage collected.
|
||||
|
||||
@ -4,6 +4,7 @@ export { QApplication } from "./lib/QtGui/QApplication";
|
||||
export { QWidget, QWidgetEvents } from "./lib/QtWidgets/QWidget";
|
||||
export { QPixmap } from "./lib/QtGui/QPixmap";
|
||||
export { QIcon } from "./lib/QtGui/QIcon";
|
||||
export { QCursor } from "./lib/QtGui/QCursor";
|
||||
// Abstract:
|
||||
export { NodeWidget } from "./lib/QtWidgets/QWidget";
|
||||
export { NodeLayout } from "./lib/QtWidgets/QLayout";
|
||||
|
||||
22
src/lib/QtGui/QCursor/index.ts
Normal file
22
src/lib/QtGui/QCursor/index.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import addon from "../../core/addon";
|
||||
import { Component, NativeElement } from "../../core/Component";
|
||||
import { QPixmap } from "../QPixmap";
|
||||
|
||||
type arg = NativeElement | number | QPixmap;
|
||||
export class QCursor extends Component {
|
||||
native: NativeElement;
|
||||
constructor(arg?: arg) {
|
||||
super();
|
||||
if (arg) {
|
||||
this.native = new addon.QCursor(arg);
|
||||
} else {
|
||||
this.native = new addon.QCursor();
|
||||
}
|
||||
}
|
||||
pos = (): { x: number; y: number } => {
|
||||
return this.native.pos();
|
||||
}
|
||||
setPos = (x: number, y: number) => {
|
||||
return this.native.setPos(x, y);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,9 @@ import { EventWidget, BaseWidgetEvents } from "../../core/EventWidget";
|
||||
import { NativeElement } from "../../core/Component";
|
||||
import { FlexLayout } from "../../core/FlexLayout";
|
||||
import { WidgetAttribute, WindowType } from "../../QtEnums";
|
||||
import { QIcon } from "../../QtGui/QIcon";
|
||||
import { QCursor } from "../../QtGui/QCursor";
|
||||
import { CursorShape, WindowState } from "../../QtEnums";
|
||||
import {
|
||||
applyStyleSheet,
|
||||
StyleSheet,
|
||||
@ -37,6 +40,15 @@ export abstract class NodeWidget extends EventWidget {
|
||||
const preparedSheet = await StyleSheet.create(styleSheet);
|
||||
await applyStyleSheet(this, preparedSheet);
|
||||
};
|
||||
setCursor(cursor: CursorShape | QCursor) {
|
||||
this.native.setCursor(cursor);
|
||||
}
|
||||
setWindowIcon(icon: QIcon) {
|
||||
this.native.setWindowIcon(icon.native);
|
||||
}
|
||||
setWindowState = async (state: WindowState) => {
|
||||
return this.native.setWindowState(state);
|
||||
};
|
||||
setWindowTitle = async (title: string) => {
|
||||
return this.native.setWindowTitle(title);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user