diff --git a/CMakeLists.txt b/CMakeLists.txt index 9319f8c7b..9cf7728d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QWheelEvent/qwheelevent_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QFontDatabase/qfontdatabase_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QPicture/qpicture_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp" diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.h new file mode 100644 index 000000000..745d8c7cf --- /dev/null +++ b/src/cpp/include/nodegui/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include + +#include "Extras/Export/export.h" +#include "core/Component/component_macro.h" + +class DLL_EXPORT QNativeGestureEventWrap + : public Napi::ObjectWrap { + COMPONENT_WRAPPED_METHODS_DECLARATION + + private: + QNativeGestureEvent* instance; + + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QNativeGestureEventWrap(const Napi::CallbackInfo& info); + ~QNativeGestureEventWrap(); + QNativeGestureEvent* getInternalInstance(); + // class constructor + static Napi::FunctionReference constructor; + // wrapped methods + Napi::Value gestureType(const Napi::CallbackInfo& info); + Napi::Value globalPos(const Napi::CallbackInfo& info); + Napi::Value localPos(const Napi::CallbackInfo& info); + Napi::Value pos(const Napi::CallbackInfo& info); + Napi::Value screenPos(const Napi::CallbackInfo& info); + Napi::Value windowPos(const Napi::CallbackInfo& info); + Napi::Value value(const Napi::CallbackInfo& info); +}; \ No newline at end of file diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h new file mode 100644 index 000000000..6c243ebf8 --- /dev/null +++ b/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include + +#include "Extras/Export/export.h" +#include "core/Component/component_macro.h" + +class DLL_EXPORT QTabletEventWrap : public Napi::ObjectWrap { + COMPONENT_WRAPPED_METHODS_DECLARATION + + private: + QTabletEvent* instance; + + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QTabletEventWrap(const Napi::CallbackInfo& info); + ~QTabletEventWrap(); + QTabletEvent* getInternalInstance(); + // class constructor + static Napi::FunctionReference constructor; + // wrapped methods + Napi::Value button(const Napi::CallbackInfo& info); + Napi::Value buttons(const Napi::CallbackInfo& info); + //Somehow this method isn't found on build? + // Napi::Value deviceType(const Napi::CallbackInfo& info); + Napi::Value globalPos(const Napi::CallbackInfo& info); + Napi::Value globalPosF(const Napi::CallbackInfo& info); + Napi::Value globalX(const Napi::CallbackInfo& info); + Napi::Value globalY(const Napi::CallbackInfo& info); + Napi::Value pointerType(const Napi::CallbackInfo& info); + Napi::Value pos(const Napi::CallbackInfo& info); + Napi::Value posF(const Napi::CallbackInfo& info); + Napi::Value pressure(const Napi::CallbackInfo& info); + Napi::Value rotation(const Napi::CallbackInfo& info); + Napi::Value tangentialPressure(const Napi::CallbackInfo& info); + Napi::Value uniqueId(const Napi::CallbackInfo& info); + Napi::Value x(const Napi::CallbackInfo& info); + Napi::Value xTilt(const Napi::CallbackInfo& info); + Napi::Value y(const Napi::CallbackInfo& info); + Napi::Value yTilt(const Napi::CallbackInfo& info); + Napi::Value z(const Napi::CallbackInfo& info); +}; \ No newline at end of file diff --git a/src/cpp/lib/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.cpp b/src/cpp/lib/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.cpp new file mode 100644 index 000000000..173966d83 --- /dev/null +++ b/src/cpp/lib/QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.cpp @@ -0,0 +1,128 @@ +#include "QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.h" + +#include +#include +#include + +#include "Extras/Utils/nutils.h" + +Napi::FunctionReference QNativeGestureEventWrap::constructor; + +Napi::Object QNativeGestureEventWrap::init(Napi::Env env, + Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QNativeGestureEvent"; + Napi::Function func = DefineClass( + env, CLASSNAME, + {InstanceMethod("gestureType", &QNativeGestureEventWrap::gestureType), + InstanceMethod("globalPos", &QNativeGestureEventWrap::globalPos), + InstanceMethod("localPos", &QNativeGestureEventWrap::localPos), + InstanceMethod("pos", &QNativeGestureEventWrap::pos), + InstanceMethod("screenPos", &QNativeGestureEventWrap::screenPos), + InstanceMethod("windowPos", &QNativeGestureEventWrap::windowPos), + InstanceMethod("value", &QNativeGestureEventWrap::value), + + COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QNativeGestureEventWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QNativeGestureEvent* QNativeGestureEventWrap::getInternalInstance() { + return this->instance; +} + +QNativeGestureEventWrap::QNativeGestureEventWrap(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + if (info.Length() == 1) { + Napi::External eventObject = + info[0].As>(); + this->instance = static_cast(eventObject.Data()); + } else { + Napi::TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureComponent(this->getInternalInstance()); +} + +QNativeGestureEventWrap::~QNativeGestureEventWrap() { + // Do not destroy instance here. It will be done by Qt Event loop. +} + +Napi::Value QNativeGestureEventWrap::gestureType( + const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int t = static_cast(this->instance->gestureType()); + return Napi::Number::From(env, t); +} + +Napi::Value QNativeGestureEventWrap::globalPos(const Napi::CallbackInfo& info) { + // Uses QPoint, not QPointF + Napi::Env env = info.Env(); + QPoint point = static_cast(this->instance->globalPos()); + int x = static_cast(point.x()); + int y = static_cast(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 QNativeGestureEventWrap::localPos(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(this->instance->localPos()); + qreal x = static_cast(point.x()); + qreal y = static_cast(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 QNativeGestureEventWrap::pos(const Napi::CallbackInfo& info) { + // Uses QPoint, not QPointF + Napi::Env env = info.Env(); + QPoint point = static_cast(this->instance->pos()); + int x = static_cast(point.x()); + int y = static_cast(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 QNativeGestureEventWrap::screenPos(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(this->instance->screenPos()); + qreal x = static_cast(point.x()); + qreal y = static_cast(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 QNativeGestureEventWrap::windowPos(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(this->instance->windowPos()); + qreal x = static_cast(point.x()); + qreal y = static_cast(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 QNativeGestureEventWrap::value(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + qreal v = static_cast(this->instance->value()); + return Napi::Number::From(env, v); +} \ No newline at end of file diff --git a/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp b/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp new file mode 100644 index 000000000..f23db9296 --- /dev/null +++ b/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp @@ -0,0 +1,182 @@ +#include "QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h" + +#include +#include +#include + +#include "Extras/Utils/nutils.h" + +Napi::FunctionReference QTabletEventWrap::constructor; + +Napi::Object QTabletEventWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QTabletEvent"; + Napi::Function func = DefineClass( + env, CLASSNAME, + {InstanceMethod("button", &QTabletEventWrap::button), + InstanceMethod("buttons", &QTabletEventWrap::buttons), + // InstanceMethod("deviceType", &QTabletEventWrap::deviceType), + InstanceMethod("globalPos", &QTabletEventWrap::globalPos), + InstanceMethod("globalPosF", &QTabletEventWrap::globalPosF), + InstanceMethod("globalX", &QTabletEventWrap::globalX), + InstanceMethod("globalY", &QTabletEventWrap::globalY), + InstanceMethod("pointerType", &QTabletEventWrap::pointerType), + InstanceMethod("pos", &QTabletEventWrap::pos), + InstanceMethod("posF", &QTabletEventWrap::posF), + InstanceMethod("pressure", &QTabletEventWrap::pressure), + InstanceMethod("rotation", &QTabletEventWrap::rotation), + InstanceMethod("tangentialPressure", &QTabletEventWrap::tangentialPressure), + InstanceMethod("uniqueId", &QTabletEventWrap::uniqueId), + InstanceMethod("x", &QTabletEventWrap::x), + InstanceMethod("xTilt", &QTabletEventWrap::xTilt), + InstanceMethod("y", &QTabletEventWrap::y), + InstanceMethod("yTilt", &QTabletEventWrap::yTilt), + InstanceMethod("z", &QTabletEventWrap::z), + + COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QTabletEventWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QTabletEvent* QTabletEventWrap::getInternalInstance() { return this->instance; } + +QTabletEventWrap::QTabletEventWrap(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + if (info.Length() == 1) { + Napi::External eventObject = + info[0].As>(); + this->instance = static_cast(eventObject.Data()); + } else { + Napi::TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureComponent(this->getInternalInstance()); +} + +QTabletEventWrap::~QTabletEventWrap() { + // Do not destroy instance here. It will be done by Qt Event loop. +} + + +Napi::Value QTabletEventWrap::button(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int b = static_cast(this->instance->button()); + return Napi::Number::From(env, b); +} +Napi::Value QTabletEventWrap::buttons(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int b = static_cast(this->instance->buttons()); + return Napi::Number::From(env, b); +} +// Napi::Value QTabletEventWrap::deviceType(const Napi::CallbackInfo& info) { +// Napi::Env env = info.Env(); +// int f = static_cast(this->instance->deviceType()); +// return Napi::Number::From(env, f); +// } +Napi::Value QTabletEventWrap::globalPos(const Napi::CallbackInfo& info) { + // Uses QPoint + Napi::Env env = info.Env(); + QPoint point = static_cast(this->instance->globalPos()); + int x = static_cast(point.x()); + int y = static_cast(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 QTabletEventWrap::globalPosF(const Napi::CallbackInfo& info) { + // Uses QPointF + Napi::Env env = info.Env(); + QPointF point = static_cast(this->instance->globalPosF()); + qreal x = static_cast(point.x()); + qreal y = static_cast(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 QTabletEventWrap::globalX(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->globalX()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::globalY(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->globalY()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::pointerType(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int f = static_cast(this->instance->pointerType()); + return Napi::Number::From(env, f); +} +Napi::Value QTabletEventWrap::pos(const Napi::CallbackInfo& info) { + // Uses QPoint + Napi::Env env = info.Env(); + QPoint point = static_cast(this->instance->pos()); + int x = static_cast(point.x()); + int y = static_cast(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 QTabletEventWrap::posF(const Napi::CallbackInfo& info) { + // Uses QPointF + Napi::Env env = info.Env(); + QPointF point = static_cast(this->instance->posF()); + qreal x = static_cast(point.x()); + qreal y = static_cast(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 QTabletEventWrap::pressure(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + qreal v = static_cast(this->instance->pressure()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::rotation(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + qreal v = static_cast(this->instance->rotation()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::tangentialPressure(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + qreal v = static_cast(this->instance->tangentialPressure()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::uniqueId(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + qint64 v = static_cast(this->instance->uniqueId()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::x(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->x()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::xTilt(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->xTilt()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::y(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->y()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::yTilt(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->yTilt()); + return Napi::Number::From(env, v); +} +Napi::Value QTabletEventWrap::z(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + int v = static_cast(this->instance->z()); + return Napi::Number::From(env, v); +} \ No newline at end of file diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index c11d0f463..98b4f818d 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -19,7 +19,9 @@ #include "QtGui/QCursor/qcursor_wrap.h" #include "QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h" #include "QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h" +#include "QtGui/QEvent/QNativeGestureEvent/qnativegestureevent_wrap.h" #include "QtGui/QEvent/QWheelEvent/qwheelevent_wrap.h" +#include "QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h" #include "QtGui/QFont/qfont_wrap.h" #include "QtGui/QFontDatabase/qfontdatabase_wrap.h" #include "QtGui/QIcon/qicon_wrap.h" @@ -168,6 +170,8 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QKeyEventWrap::init(env, exports); QMouseEventWrap::init(env, exports); QWheelEventWrap::init(env, exports); + QTabletEventWrap::init(env, exports); + QNativeGestureEventWrap::init(env, exports); QPlainTextEditWrap::init(env, exports); QDialWrap::init(env, exports); QLabelWrap::init(env, exports); diff --git a/src/index.ts b/src/index.ts index a0dd51c5c..c5b8a9d3d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,8 @@ export { QFontDatabase, SystemFont, WritingSystem } from './lib/QtGui/QFontDatab export { QKeyEvent } from './lib/QtGui/QEvent/QKeyEvent'; export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent'; export { QWheelEvent } from './lib/QtGui/QEvent/QWheelEvent'; +export { QNativeGestureEvent } from './lib/QtGui/QEvent/QNativeGestureEvent'; +export { QTabletEvent } from './lib/QtGui/QEvent/QTabletEvent'; export { WidgetEventTypes } from './lib/core/EventWidget'; // Abstract: export { NodeWidget, QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget'; diff --git a/src/lib/QtGui/QEvent/QNativeGestureEvent.ts b/src/lib/QtGui/QEvent/QNativeGestureEvent.ts new file mode 100644 index 000000000..c0c272c9f --- /dev/null +++ b/src/lib/QtGui/QEvent/QNativeGestureEvent.ts @@ -0,0 +1,62 @@ +import addon from '../../utils/addon'; +import { NativeElement } from '../../core/Component'; +import { NativeGestureType } from '../../QtEnums'; + +export class QNativeGestureEvent { + native: NativeElement; + constructor(event: NativeElement) { + this.native = new addon.QNativeGestureEvent(event); + } + + //Needs QTouchDevice to implement this + // device(): QTouchDevice { + // return undefined; + // } + /** Returns the gesture type */ + gestureType(): NativeGestureType { + return this.native.gestureType(); + } + /** + * Returns the position of the gesture as a QPointF in screen coordinates + */ + globalPos(): { x: number; y: number } { + return this.native.globalPos(); + } + /** + * Returns the position of the gesture as a QPointF, + * relative to the widget or item that received the event + */ + localPos(): { x: number; y: number } { + return this.native.localPos(); + } + /** + * Returns the position of the mouse cursor, + * relative to the widget or item that received the event + */ + pos(): { x: number; y: number } { + return this.native.pos(); + } + /** + * Returns the position of the gesture as a QPointF in screen coordinates + */ + screenPos(): { x: number; y: number } { + return this.native.screenPos(); + } + /** + * Returns the position of the gesture as a QPointF, + * relative to the window that received the event. + */ + windowPos(): { x: number; y: number } { + return this.native.windowPos(); + } + /** + * Returns the gesture value. + * + * The value should be interpreted based on the gesture type. + * For example, a Zoom gesture provides a scale factor while a + * Rotate gesture provides a rotation delta. + */ + value(): number { + return this.native.value(); + } +} diff --git a/src/lib/QtGui/QEvent/QTabletEvent.ts b/src/lib/QtGui/QEvent/QTabletEvent.ts new file mode 100644 index 000000000..f54a8386b --- /dev/null +++ b/src/lib/QtGui/QEvent/QTabletEvent.ts @@ -0,0 +1,202 @@ +import addon from '../../utils/addon'; +import { NativeElement } from '../../core/Component'; + +enum PointerType { + /** An unknown device */ + Idle = 0, + /** Tip end of a stylus-like device (the narrow end of the pen). */ + Loading = 1, + /** Any puck-like device. */ + Ready = 2, + /** Eraser end of a stylus-like device (the broad end of the pen). */ + Error = 3, +} +enum TabletDevice { + /** No device, or an unknown device. */ + NoDevice = 0, + /** A Puck (a device that is similar to a flat mouse with a transparent circle with cross-hairs). */ + Puck = 1, + /** A Stylus */ + Stylus = 2, + /** An airbrush */ + Airbrush = 3, + /** A 4D Mouse. */ + FourDMouse = 4, + /** A special stylus that also knows about rotation (a 6D stylus). */ + RotationStylus = 6, +} +/** + * The QTabletEvent class contains parameters that describe a Tablet event + */ +export class QTabletEvent { + static readonly PointerType = PointerType; + static readonly TabletDevice = TabletDevice; + readonly PointerType = PointerType; + readonly TabletDevice = TabletDevice; + native: NativeElement; + constructor(event: NativeElement) { + this.native = new addon.QTabletEvent(event); + } + /** + * Returns the button that caused the event. + * Note that the returned value is always Qt::NoButton for TabletMove, + * TabletEnterProximity and TabletLeaveProximity events + */ + button(): number { + return this.native.button(); + } + /** + * Returns the button state when the event was generated. + * The button state is a combination of buttons from the Qt::MouseButton enum using the OR operator. + * For TabletMove events, this is all buttons that are pressed down. + * For TabletPress events this includes the button that caused the event. + * For TabletRelease events this excludes the button that caused the event. + */ + buttons(): number { + return this.native.buttons(); + } + /* + * Returns the type of device that generated the event + * (see enum QTabletEvent::TabletDevice) + * + * Somehow the build couldn't find this method; may enable in the future + */ + // deviceType(): TabletDevice { + // return this.native.deviceType(); + // } + /** + * Returns the global position of the device at the time of the event. + * + * This is important on asynchronous windows systems like X11; + * whenever you move your widgets around in response to mouse events, + * globalPos() can differ significantly from the current position QCursor::pos(). + * + * use globalPosF for Floating point (more precise) + */ + globalPos(): { x: number; y: number } { + return this.native.globalPos(); + } + /** + * Returns the global position of the device at the time of the event. + * + * This is important on asynchronous windows systems like X11; + * whenever you move your widgets around in response to mouse events, + * globalPosF() can differ significantly from the current position QCursor::pos(). + */ + globalPosF(): { x: number; y: number } { + return this.native.globalPosF(); + } + /** + * Returns the global x position of the mouse pointer at the time of the event + */ + globalX(): number { + return this.native.globalX(); + } + /** + * Returns the global y position of the mouse pointer at the time of the event + */ + globalY(): number { + return this.native.globalY(); + } + /** + * Returns the type of point that generated the event. + * (See QTabletEvent::PointerType) + */ + pointerType(): PointerType { + return this.native.pointerType(); + } + /** + * Returns the position of the device, relative to the widget that received the event. + * + * If you move widgets around in response to mouse events, use globalPos() instead of this function. + */ + pos(): { x: number; y: number } { + return this.native.pos(); + } + /** + * Returns the position of the device, relative to the widget that received the event. + * + * If you move widgets around in response to mouse events, use globalPosF() instead of this function. + */ + posF(): { x: number; y: number } { + return this.native.posF(); + } + /** + * Returns the pressure for the device. 0.0 indicates that the stylus is not on the tablet, + * 1.0 indicates the maximum amount of pressure for the stylus + */ + pressure(): number { + return this.native.pressure(); + } + /** + * Returns the rotation of the current tool in degrees, where zero means the + * tip of the stylus is pointing towards the top of the tablet, + * a positive value means it's turned to the right, and a negative value means it's turned to the left. + * + * This can be given by a 4D Mouse or a rotation-capable stylus (such as the Wacom Art Pen or the Apple Pencil). + * + * If the device does not support rotation, this value is always 0.0. + */ + rotation(): number { + return this.native.rotation(); + } + /** + * Returns the tangential pressure for the device. + * This is typically given by a finger wheel on an airbrush tool. + * The range is from -1.0 to 1.0. 0.0 indicates a neutral position. + * Current airbrushes can only move in the positive direction from the neutrual position. + * If the device does not support tangential pressure, this value is always 0.0. + */ + tangentialPressure(): number { + return this.native.tangentialPressure(); + } + /** + * Returns a unique ID for the current device, + * making it possible to differentiate between multiple devices being used at the same time on the tablet. + * + * Support of this feature is dependent on the tablet. + * + * Values for the same device may vary from OS to OS. + */ + uniqueId(): number { + return this.native.uniqueId(); + } + /** + * Returns the x position of the device, relative to the widget that received the event + */ + x(): number { + return this.native.x(); + } + /** + * Returns the angle between the device (a pen, for example) and the + * perpendicular in the direction of the x axis. + * Positive values are towards the tablet's physical right. + * The angle is in the range -60 to +60 degrees. + */ + xTilt(): number { + return this.native.xTilt(); + } + /** + * Returns the y position of the device, relative to the widget that received the event. + */ + y(): number { + return this.native.y(); + } + /** + * Returns the angle between the device (a pen, for example) and + * the perpendicular in the direction of the y axis. + * Positive values are towards the bottom of the tablet. + * The angle is within the range -60 to +60 degrees. + */ + yTilt(): number { + return this.native.yTilt(); + } + /** + * Returns the z position of the device. + * Typically this is represented by a wheel on a 4D Mouse. If the device does not support a Z-axis, this value is always zero. + * This is not the same as pressure. + */ + z(): number { + return this.native.z(); + } +} diff --git a/src/lib/QtGui/QEvent/QWheelEvent.ts b/src/lib/QtGui/QEvent/QWheelEvent.ts index 8bc710e0b..7eb6f226a 100644 --- a/src/lib/QtGui/QEvent/QWheelEvent.ts +++ b/src/lib/QtGui/QEvent/QWheelEvent.ts @@ -1,5 +1,6 @@ import addon from '../../utils/addon'; import { NativeElement } from '../../core/Component'; +import { ScrollPhase } from '../../QtEnums'; export class QWheelEvent { native: NativeElement; @@ -58,7 +59,7 @@ export class QWheelEvent { * Returns the scrolling phase of this wheel event * Note: The Qt::ScrollBegin and Qt::ScrollEnd phases are currently supported only on macOS */ - phase(): number { + phase(): ScrollPhase { return this.native.phase(); } diff --git a/website/sidebars.js b/website/sidebars.js index fe297c392..aa03af60a 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -66,6 +66,8 @@ module.exports = { 'api/generated/classes/qmodelindex', 'api/generated/classes/qmouseevent', 'api/generated/classes/qwheelevent', + 'api/generated/classes/qnativegestureevent', + 'api/generated/classes/qtabletevent', 'api/generated/classes/qmovie', 'api/generated/classes/qobject', 'api/generated/classes/qpainter',