Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include "Extras/Export/export.h"
#include "QtGui/QEvent/QEvent/qevent_macro.h"
#include "QtGui/QEvent/QInputEvent/qinputevent_macro.h"
#include "QtGui/QEvent/QSinglePointEvent/qsinglepointevent_macro.h"
#include "core/Component/component_macro.h"

class DLL_EXPORT QMouseEventWrap : public Napi::ObjectWrap<QMouseEventWrap> {
COMPONENT_WRAPPED_METHODS_DECLARATION
QEVENT_WRAPPED_METHODS_DECLARATION
QINPUTEVENT_WRAPPED_METHODS_DECLARATION

QSINGLEPOINTEVENT_WRAPPED_METHODS_DECLARATION
private:
QMouseEvent* instance;

Expand All @@ -25,8 +26,6 @@ class DLL_EXPORT QMouseEventWrap : public Napi::ObjectWrap<QMouseEventWrap> {
// class constructor
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "QtCore/QPointF/qpointf_wrap.h"

#ifndef QSINGLEPOINTEVENT_WRAPPED_METHODS_DECLARATION
#define QSINGLEPOINTEVENT_WRAPPED_METHODS_DECLARATION \
Napi::Value button(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
int button = static_cast<int>(this->instance->button()); \
return Napi::Number::From(env, button); \
} \
Napi::Value 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 position(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
QPointF point = this->instance->position(); \
qreal x = static_cast<qreal>(point.x()); \
qreal y = static_cast<qreal>(point.y()); \
Napi::Object obj = Napi::Object::New(env); \
obj.Set("x", Napi::Number::From(env, x)); \
obj.Set("y", Napi::Number::From(env, y)); \
return obj; \
} \
Napi::Value globalPosition(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
QPointF point = static_cast<QPointF>(this->instance->globalPosition()); \
qreal x = static_cast<qreal>(point.x()); \
qreal y = static_cast<qreal>(point.y()); \
Napi::Object obj = Napi::Object::New(env); \
obj.Set("x", Napi::Number::From(env, x)); \
obj.Set("y", Napi::Number::From(env, y)); \
return obj; \
} \
Napi::Value scenePosition(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
QPointF point = this->instance->scenePosition(); \
qreal x = static_cast<qreal>(point.x()); \
qreal y = static_cast<qreal>(point.y()); \
Napi::Object obj = Napi::Object::New(env); \
obj.Set("x", Napi::Number::From(env, x)); \
obj.Set("y", Napi::Number::From(env, y)); \
return obj; \
}
#endif

#ifndef QSINGLEPOINTEVENT_WRAPPED_METHODS_EXPORT_DEFINE
#define QSINGLEPOINTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
InstanceMethod("button", &WidgetWrapName::button), \
InstanceMethod("buttons", &WidgetWrapName::buttons), \
InstanceMethod("position", &WidgetWrapName::position), \
InstanceMethod("globalPosition", &WidgetWrapName::globalPosition), \
InstanceMethod("scenePosition", &WidgetWrapName::scenePosition),
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "Extras/Export/export.h"
#include "QtGui/QEvent/QEvent/qevent_macro.h"
#include "QtGui/QEvent/QInputEvent/qinputevent_macro.h"
#include "QtGui/QEvent/QSinglePointEvent/qsinglepointevent_macro.h"
#include "core/Component/component_macro.h"

class DLL_EXPORT QWheelEventWrap : public Napi::ObjectWrap<QWheelEventWrap> {
COMPONENT_WRAPPED_METHODS_DECLARATION
QEVENT_WRAPPED_METHODS_DECLARATION
QINPUTEVENT_WRAPPED_METHODS_DECLARATION
QSINGLEPOINTEVENT_WRAPPED_METHODS_DECLARATION

private:
QWheelEvent* instance;
Expand All @@ -26,10 +28,7 @@ class DLL_EXPORT QWheelEventWrap : public Napi::ObjectWrap<QWheelEventWrap> {
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value angleDelta(const Napi::CallbackInfo& info);
Napi::Value buttons(const Napi::CallbackInfo& info);
Napi::Value globalPosition(const Napi::CallbackInfo& info);
Napi::Value inverted(const Napi::CallbackInfo& info);
Napi::Value phase(const Napi::CallbackInfo& info);
Napi::Value pixelDelta(const Napi::CallbackInfo& info);
Napi::Value position(const Napi::CallbackInfo& info);
};
2 changes: 1 addition & 1 deletion src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class DLL_EXPORT NMenu : public QMenu, public NodeWidget {
if (instance != nullptr) {
this->emitOnNode.Call({Napi::String::New(env, "triggered"), instance});
}
});
});
}
};
20 changes: 4 additions & 16 deletions src/cpp/lib/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ Napi::Object QMouseEventWrap::init(Napi::Env env, Napi::Object exports) {
char CLASSNAME[] = "QMouseEvent";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("button", &QMouseEventWrap::button),
InstanceMethod("buttons", &QMouseEventWrap::buttons),
InstanceMethod("x", &QMouseEventWrap::x),
{InstanceMethod("x", &QMouseEventWrap::x),
InstanceMethod("y", &QMouseEventWrap::y),
InstanceMethod("globalX", &QMouseEventWrap::globalX),
InstanceMethod("globalY", &QMouseEventWrap::globalY),

COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap)
QEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap)
QINPUTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap)});
QINPUTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap)
QSINGLEPOINTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(
QMouseEventWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
Expand All @@ -46,18 +46,6 @@ QMouseEventWrap::~QMouseEventWrap() {
// Do not destroy instance here. It will be done by Qt Event loop.
}

Napi::Value QMouseEventWrap::button(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int button = static_cast<int>(this->instance->button());
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());
Expand Down
38 changes: 3 additions & 35 deletions src/cpp/lib/QtGui/QEvent/QWheelEvent/qwheelevent_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ Napi::Object QWheelEventWrap::init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("angleDelta", &QWheelEventWrap::angleDelta),
InstanceMethod("buttons", &QWheelEventWrap::buttons),
InstanceMethod("globalPosition", &QWheelEventWrap::globalPosition),
InstanceMethod("inverted", &QWheelEventWrap::inverted),
InstanceMethod("phase", &QWheelEventWrap::phase),
InstanceMethod("pixelDelta", &QWheelEventWrap::pixelDelta),
InstanceMethod("position", &QWheelEventWrap::position),

COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QWheelEventWrap)
QEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QWheelEventWrap)
QINPUTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QWheelEventWrap)});
QINPUTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QWheelEventWrap)
QSINGLEPOINTEVENT_WRAPPED_METHODS_EXPORT_DEFINE(
QWheelEventWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
Expand Down Expand Up @@ -61,25 +60,6 @@ Napi::Value QWheelEventWrap::angleDelta(const Napi::CallbackInfo& info) {
return obj;
}

Napi::Value QWheelEventWrap::buttons(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int b = static_cast<int>(this->instance->buttons());
return Napi::Number::From(env, b);
}

Napi::Value QWheelEventWrap::globalPosition(const Napi::CallbackInfo& info) {
// Uses QPointF, not QPoint
// qreal is typedef double unless configued with -qreal float option
Napi::Env env = info.Env();
QPointF point = static_cast<QPointF>(this->instance->globalPosition());
qreal x = static_cast<qreal>(point.x());
qreal y = static_cast<qreal>(point.y());
Napi::Object obj = Napi::Object::New(env);
obj.Set("x", Napi::Number::From(env, x));
obj.Set("y", Napi::Number::From(env, y));
return obj;
}

Napi::Value QWheelEventWrap::inverted(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool b = static_cast<bool>(this->instance->inverted());
Expand All @@ -103,15 +83,3 @@ Napi::Value QWheelEventWrap::pixelDelta(const Napi::CallbackInfo& info) {
obj.Set("y", Napi::Number::From(env, y));
return obj;
}

Napi::Value QWheelEventWrap::position(const Napi::CallbackInfo& info) {
// Uses QPointF
Napi::Env env = info.Env();
QPointF point = static_cast<QPointF>(this->instance->position());
qreal x = static_cast<qreal>(point.x());
qreal y = static_cast<qreal>(point.y());
Napi::Object obj = Napi::Object::New(env);
obj.Set("x", Napi::Number::From(env, x));
obj.Set("y", Napi::Number::From(env, y));
return obj;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent';
export { QMoveEvent } from './lib/QtGui/QEvent/QMoveEvent';
export { QWheelEvent } from './lib/QtGui/QEvent/QWheelEvent';
export { QNativeGestureEvent } from './lib/QtGui/QEvent/QNativeGestureEvent';
export { QSinglePointEvent } from './lib/QtGui/QEvent/QSinglePointEvent';
export { QTabletEvent } from './lib/QtGui/QEvent/QTabletEvent';
export { QTimerEvent } from './lib/QtGui/QEvent/QTimerEvent';
export { QDrag } from './lib/QtGui/QDrag';
Expand Down
10 changes: 2 additions & 8 deletions src/lib/QtGui/QEvent/QMouseEvent.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import addon from '../../utils/addon';
import { NativeRawPointer } from '../../core/Component';
import { QInputEvent } from './QInputEvent';
import { QSinglePointEvent } from './QSinglePointEvent';

export class QMouseEvent extends QInputEvent {
export class QMouseEvent extends QSinglePointEvent {
constructor(event: NativeRawPointer<'QEvent'>) {
super(new addon.QMouseEvent(event));
}
button(): number {
return this.native.button();
}
buttons(): number {
return this.native.buttons();
}
x(): number {
return this.native.x();
}
Expand Down
32 changes: 32 additions & 0 deletions src/lib/QtGui/QEvent/QSinglePointEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { QInputEvent } from './QInputEvent';
import { QPointF } from '../../QtCore/QPointF';

Check warning on line 2 in src/lib/QtGui/QEvent/QSinglePointEvent.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

'QPointF' is defined but never used

Check warning on line 2 in src/lib/QtGui/QEvent/QSinglePointEvent.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'QPointF' is defined but never used

Check warning on line 2 in src/lib/QtGui/QEvent/QSinglePointEvent.ts

View workflow job for this annotation

GitHub Actions / build (macos-13)

'QPointF' is defined but never used

export abstract class QSinglePointEvent extends QInputEvent {
button(): number {
return this.native.button();
}
buttons(): number {
return this.native.buttons();
}
/**
* Returns the position of the mouse cursor relative to the widget that received the event.
* If you move your widgets around in response to mouse events, use globalPosition() instead of this function.
* This function was introduced in Qt 5.14
*/
position(): { x: number; y: number } {
return this.native.position();
}
/**
* Returns the global position of the mouse pointer at the time of
* the event. This is important on asynchronous window systems such
* as X11; whenever you move your widgets around in response to mouse
* events, globalPosition() can differ a lot from the current cursor
* position returned by QCursor::pos().
*/
globalPosition(): { x: number; y: number } {
return this.native.globalPosition();
}
scenePosition(): { x: number; y: number } {
return this.native.scenePosition();
}
}
16 changes: 2 additions & 14 deletions src/lib/QtGui/QEvent/QWheelEvent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import addon from '../../utils/addon';
import { NativeRawPointer } from '../../core/Component';
import { ScrollPhase } from '../../QtEnums';
import { QInputEvent } from './QInputEvent';
import { QSinglePointEvent } from './QSinglePointEvent';

export class QWheelEvent extends QInputEvent {
export class QWheelEvent extends QSinglePointEvent {
constructor(event: NativeRawPointer<'QEvent'>) {
super(new addon.QWheelEvent(event));
}
Expand Down Expand Up @@ -38,9 +38,6 @@ export class QWheelEvent extends QInputEvent {
angleDelta(): { x: number; y: number } {
return this.native.angleDelta();
}
buttons(): number {
return this.native.buttons();
}
/**
* Returns the global position of the mouse pointer at the time of
* the event. This is important on asynchronous window systems such
Expand Down Expand Up @@ -74,13 +71,4 @@ export class QWheelEvent extends QInputEvent {
pixelDelta(): { x: number; y: number } {
return this.native.pixelDelta();
}

/**
* Returns the position of the mouse cursor relative to the widget that received the event.
* If you move your widgets around in response to mouse events, use globalPosition() instead of this function.
* This function was introduced in Qt 5.14
*/
position(): { x: number; y: number } {
return this.native.position();
}
}