Add extra QMouseEvent and QPainter methods (#837)

* Add `buttons()` to `QMouseEvent`

* Add `beginNativePainting()` and `endNativePainting()` to `QPainter`
This commit is contained in:
Simon Edwards 2021-06-12 17:51:42 +02:00 committed by GitHub
parent 4db29780e0
commit 953b553089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 1 deletions

View File

@ -22,6 +22,7 @@ class DLL_EXPORT QMouseEventWrap : public Napi::ObjectWrap<QMouseEventWrap> {
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value button(const Napi::CallbackInfo& info);
Napi::Value buttons(const Napi::CallbackInfo& info);
Napi::Value x(const Napi::CallbackInfo& info);
Napi::Value y(const Napi::CallbackInfo& info);
Napi::Value globalX(const Napi::CallbackInfo& info);

View File

@ -24,7 +24,9 @@ class DLL_EXPORT QPainterWrap : public Napi::ObjectWrap<QPainterWrap> {
Napi::Value drawPath(const Napi::CallbackInfo& info);
Napi::Value strokePath(const Napi::CallbackInfo& info);
Napi::Value begin(const Napi::CallbackInfo& info);
Napi::Value beginNativePainting(const Napi::CallbackInfo& info);
Napi::Value end(const Napi::CallbackInfo& info);
Napi::Value endNativePainting(const Napi::CallbackInfo& info);
Napi::Value rotate(const Napi::CallbackInfo& info);
Napi::Value setPen(const Napi::CallbackInfo& info);
Napi::Value setRenderHint(const Napi::CallbackInfo& info);

View File

@ -12,6 +12,7 @@ Napi::Object QMouseEventWrap::init(Napi::Env env, Napi::Object exports) {
Napi::Function func =
DefineClass(env, CLASSNAME,
{InstanceMethod("button", &QMouseEventWrap::button),
InstanceMethod("buttons", &QMouseEventWrap::buttons),
InstanceMethod("x", &QMouseEventWrap::x),
InstanceMethod("y", &QMouseEventWrap::y),
InstanceMethod("globalX", &QMouseEventWrap::globalX),
@ -50,6 +51,12 @@ Napi::Value QMouseEventWrap::button(const Napi::CallbackInfo& info) {
return Napi::Number::From(env, button);
}
Napi::Value QMouseEventWrap::buttons(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int buttons = static_cast<int>(this->instance->buttons());
return Napi::Number::From(env, buttons);
}
Napi::Value QMouseEventWrap::x(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int x = static_cast<int>(this->instance->x());

View File

@ -32,6 +32,9 @@ Napi::Object QPainterWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("drawConvexPolygon", &QPainterWrap::drawConvexPolygon),
InstanceMethod("save", &QPainterWrap::save),
InstanceMethod("restore", &QPainterWrap::restore),
InstanceMethod("beginNativePainting",
&QPainterWrap::beginNativePainting),
InstanceMethod("endNativePainting", &QPainterWrap::endNativePainting),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QPainterWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -244,3 +247,15 @@ Napi::Value QPainterWrap::setRenderHint(const Napi::CallbackInfo& info) {
this->instance->setRenderHint(hint, true);
return env.Null();
}
Napi::Value QPainterWrap::beginNativePainting(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->beginNativePainting();
return env.Null();
}
Napi::Value QPainterWrap::endNativePainting(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->endNativePainting();
return env.Null();
}

View File

@ -9,6 +9,9 @@ export class QMouseEvent {
button(): number {
return this.native.button();
}
buttons(): number {
return this.native.buttons();
}
x(): number {
return this.native.x();
}

View File

@ -7,7 +7,7 @@ import { QPoint } from '../QtCore/QPoint';
import { QPen } from '../QtGui/QPen';
/**
> Lets you paint on widgets.
* **This class is a JS wrapper around Qt's [QPainter class](https://doc.qt.io/qt-5/qpainter.html)**
@ -71,10 +71,18 @@ export class QPainter extends Component {
return this.native.begin(device.native);
}
beginNativePainting(): void {
this.native.beginNativePainting();
}
end(): boolean {
return this.native.end();
}
endNativePainting(): void {
this.native.endNativePainting();
}
rotate(angle: number): void {
this.native.rotate(angle);
}