diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QDragLeaveEvent/qdragleaveevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QDragLeaveEvent/qdragleaveevent_wrap.h index 0b9daf230..df910030c 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QDragLeaveEvent/qdragleaveevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QDragLeaveEvent/qdragleaveevent_wrap.h @@ -11,6 +11,7 @@ class DLL_EXPORT QDragLeaveEventWrap : public Napi::ObjectWrap { COMPONENT_WRAPPED_METHODS_DECLARATION + QEVENT_WRAPPED_METHODS_DECLARATION private: QDragLeaveEvent* instance; @@ -23,6 +24,4 @@ class DLL_EXPORT QDragLeaveEventWrap // class constructor static Napi::FunctionReference constructor; // wrapped methods (none) - // Methods from QEvent - QEVENT_WRAPPED_METHODS_DECLARATION }; \ No newline at end of file diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QDragMoveEvent/qdragmoveevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QDragMoveEvent/qdragmoveevent_wrap.h index 3e138bbec..572963f3b 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QDragMoveEvent/qdragmoveevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QDragMoveEvent/qdragmoveevent_wrap.h @@ -7,11 +7,6 @@ #include "Extras/Export/export.h" #include "core/Component/component_macro.h" -/* -NOTE : QDragMoveEvent inherits from QDropEvent -- Is it possible to inherit from QDropEventWrap directly? -*/ - class DLL_EXPORT QDragMoveEventWrap : public Napi::ObjectWrap { COMPONENT_WRAPPED_METHODS_DECLARATION @@ -51,4 +46,4 @@ class DLL_EXPORT QDragMoveEventWrap Napi::Value setAccepted(const Napi::CallbackInfo& info); Napi::Value spontaneous(const Napi::CallbackInfo& info); Napi::Value _type(const Napi::CallbackInfo& info); -}; \ No newline at end of file +}; diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h index 09f68975a..142df953e 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h @@ -5,10 +5,12 @@ #include #include "Extras/Export/export.h" +#include "QtGui/QEvent/QEvent/qevent_macro.h" #include "core/Component/component_macro.h" class DLL_EXPORT QKeyEventWrap : public Napi::ObjectWrap { COMPONENT_WRAPPED_METHODS_DECLARATION + QEVENT_WRAPPED_METHODS_DECLARATION private: QKeyEvent* instance; @@ -26,4 +28,4 @@ class DLL_EXPORT QKeyEventWrap : public Napi::ObjectWrap { Napi::Value modifiers(const Napi::CallbackInfo& info); Napi::Value count(const Napi::CallbackInfo& info); Napi::Value isAutoRepeat(const Napi::CallbackInfo& info); -}; \ No newline at end of file +}; diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h index 2c190f2f7..898d63681 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h @@ -5,10 +5,12 @@ #include #include "Extras/Export/export.h" +#include "QtGui/QEvent/QEvent/qevent_macro.h" #include "core/Component/component_macro.h" class DLL_EXPORT QMouseEventWrap : public Napi::ObjectWrap { COMPONENT_WRAPPED_METHODS_DECLARATION + QEVENT_WRAPPED_METHODS_DECLARATION private: QMouseEvent* instance; diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h index 6612e0421..a7a0742a3 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.h @@ -5,10 +5,12 @@ #include #include "Extras/Export/export.h" +#include "QtGui/QEvent/QEvent/qevent_macro.h" #include "core/Component/component_macro.h" class DLL_EXPORT QTabletEventWrap : public Napi::ObjectWrap { COMPONENT_WRAPPED_METHODS_DECLARATION + QEVENT_WRAPPED_METHODS_DECLARATION private: QTabletEvent* instance; diff --git a/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp b/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp index ce8254bc3..b481f1ece 100644 --- a/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp +++ b/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp @@ -13,4 +13,10 @@ class DLL_EXPORT NScrollArea : public QScrollArea, public NodeWidget { using QScrollArea::QScrollArea; // inherit all constructors of QScrollArea void connectSignalsToEventEmitter() { QABSTRACTSCROLLAREA_SIGNALS } + + // By-pass `protected` access and expose it. + void setViewportMargins(int left, int top, int right, int bottom) { + QScrollArea::setViewportMargins(left, top, right, bottom); + } + QMargins viewportMargins() const { return QScrollArea::viewportMargins(); } }; diff --git a/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h b/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h index 1c3022e9e..2e6862503 100644 --- a/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h @@ -26,4 +26,6 @@ class DLL_EXPORT QScrollAreaWrap : public Napi::ObjectWrap { Napi::Value ensureWidgetVisible(const Napi::CallbackInfo& info); Napi::Value setWidget(const Napi::CallbackInfo& info); Napi::Value takeWidget(const Napi::CallbackInfo& info); + Napi::Value setViewportMargins(const Napi::CallbackInfo& info); + Napi::Value viewportMargins(const Napi::CallbackInfo& info); }; diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h index 252609f55..0511667a2 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h @@ -439,6 +439,12 @@ int reason = info[0].As().Int32Value(); \ this->instance->setFocus(static_cast(reason)); \ return env.Null(); \ + } \ + Napi::Value clearFocus(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + this->instance->clearFocus(); \ + return env.Null(); \ } #endif // QWIDGET_WRAPPED_METHODS_DECLARATION @@ -501,7 +507,8 @@ InstanceMethod("setGraphicsEffect", &WidgetWrapName::setGraphicsEffect), \ InstanceMethod("acceptDrops", &WidgetWrapName::acceptDrops), \ InstanceMethod("setAcceptDrops", &WidgetWrapName::setAcceptDrops), \ - InstanceMethod("setFocus", &WidgetWrapName::setFocus), + InstanceMethod("setFocus", &WidgetWrapName::setFocus), \ + InstanceMethod("clearFocus", &WidgetWrapName::clearFocus), #endif // QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE diff --git a/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp b/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp index fd9951e3b..8306e54c4 100644 --- a/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp +++ b/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp @@ -16,7 +16,8 @@ Napi::Object QKeyEventWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("modifiers", &QKeyEventWrap::modifiers), InstanceMethod("count", &QKeyEventWrap::count), InstanceMethod("isAutoRepeat", &QKeyEventWrap::isAutoRepeat), - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QKeyEventWrap)}); + COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QKeyEventWrap) + QEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QKeyEventWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; diff --git a/src/cpp/lib/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.cpp b/src/cpp/lib/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.cpp index 0ff995f62..a70d69178 100644 --- a/src/cpp/lib/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.cpp +++ b/src/cpp/lib/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.cpp @@ -18,7 +18,8 @@ Napi::Object QMouseEventWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("globalX", &QMouseEventWrap::globalX), InstanceMethod("globalY", &QMouseEventWrap::globalY), - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap)}); + COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap) + QEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QMouseEventWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; diff --git a/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp b/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp index 0c4713edb..5557211d5 100644 --- a/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp +++ b/src/cpp/lib/QtGui/QEvent/QTabletEvent/qtabletevent_wrap.cpp @@ -34,7 +34,8 @@ Napi::Object QTabletEventWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("yTilt", &QTabletEventWrap::yTilt), InstanceMethod("z", &QTabletEventWrap::z), - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QTabletEventWrap)}); + COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QTabletEventWrap) + QEVENT_WRAPPED_METHODS_EXPORT_DEFINE(QTabletEventWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; diff --git a/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp b/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp index 8d8fb069e..85db8ffc7 100644 --- a/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp @@ -99,8 +99,10 @@ Napi::Value QBoxLayoutWrap::addWidget(const Napi::CallbackInfo& info) { NodeWidgetWrap* widget = Napi::ObjectWrap::Unwrap(qwidgetObject); int stretch = info[1].As().Int32Value(); + Qt::Alignment alignment = + static_cast(info[2].As().Int32Value()); - this->instance->addWidget(widget->getInternalInstance(), stretch); + this->instance->addWidget(widget->getInternalInstance(), stretch, alignment); return env.Null(); } diff --git a/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp b/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp index 40d74d2bb..bd4399350 100644 --- a/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp @@ -15,6 +15,9 @@ Napi::Object QScrollAreaWrap::init(Napi::Env env, Napi::Object exports) { &QScrollAreaWrap::ensureWidgetVisible), InstanceMethod("setWidget", &QScrollAreaWrap::setWidget), InstanceMethod("takeWidget", &QScrollAreaWrap::takeWidget), + InstanceMethod("setViewportMargins", + &QScrollAreaWrap::setViewportMargins), + InstanceMethod("viewportMargins", &QScrollAreaWrap::viewportMargins), QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(QScrollAreaWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -100,3 +103,38 @@ Napi::Value QScrollAreaWrap::takeWidget(const Napi::CallbackInfo& info) { // We will not return the value here since we are doing it in js side anyway return env.Null(); } + +Napi::Value QScrollAreaWrap::setViewportMargins( + const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + NScrollArea* nScrollArea = qobject_cast(this->instance); + if (nScrollArea != nullptr) { + int left = info[0].As().Int32Value(); + int top = info[1].As().Int32Value(); + int right = info[2].As().Int32Value(); + int bottom = info[3].As().Int32Value(); + nScrollArea->setViewportMargins(left, top, right, bottom); + } + return env.Null(); +} + +Napi::Value QScrollAreaWrap::viewportMargins(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + NScrollArea* nScrollArea = qobject_cast(this->instance); + + QMargins margins; + if (nScrollArea != nullptr) { + margins = nScrollArea->viewportMargins(); + } + + Napi::Array resultNapi = Napi::Array::New(env, 4); + resultNapi[uint32_t(0)] = Napi::Number::From(env, margins.left()); + resultNapi[1] = Napi::Value::From(env, margins.top()); + resultNapi[2] = Napi::Value::From(env, margins.right()); + resultNapi[3] = Napi::Value::From(env, margins.bottom()); + return resultNapi; +} diff --git a/src/index.ts b/src/index.ts index 4e90b8a25..530d7595e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -150,3 +150,4 @@ export { FlexLayout, FlexLayoutSignals } from './lib/core/FlexLayout'; export { StyleSheet } from './lib/core/Style/StyleSheet'; export { NativeElement, Component } from './lib/core/Component'; export { checkIfNativeElement, checkIfNapiExternal } from './lib/utils/helpers'; +export { Margins } from './lib/utils/Margins'; diff --git a/src/lib/QtGui/QEvent/QDragLeaveEvent.ts b/src/lib/QtGui/QEvent/QDragLeaveEvent.ts index d956f29ac..439911630 100644 --- a/src/lib/QtGui/QEvent/QDragLeaveEvent.ts +++ b/src/lib/QtGui/QEvent/QDragLeaveEvent.ts @@ -1,49 +1,9 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; +import { QEvent } from './QEvent'; -export class QDragLeaveEvent { - native: NativeElement; +export class QDragLeaveEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QDragLeaveEvent(event); - } - //Methods from QEvent --------------------------- - /** - * Sets the accept flag of the event object, the equivalent of calling setAccepted(true). - * Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget - */ - accept(): void { - return this.native.accept(); - } - /** - * Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false). - * Clearing the accept parameter indicates that the event receiver does not want the event. - * Unwanted events might be propagated to the parent widget. - */ - ignore(): void { - return this.native.ignore(); - } - isAccepted(): boolean { - return this.native.isAccepted(); - } - /** - * Sets the accept flag of the event object - */ - setAccepted(accepted: boolean): void { - return this.native.setAccepted(accepted); - } - /** - * Returns true if the event originated outside the application (a system event); otherwise returns false. - * - * The return value of this function is not defined for paint events. - */ - spontaneous(): boolean { - return this.native.spontaneous(); - } - /** - * Returns the event type - * @returns {Number} This is QEvent::Type - */ - type(): number { - return this.native._type(); + super(new addon.QDragLeaveEvent(event)); } } diff --git a/src/lib/QtGui/QEvent/QDragMoveEvent.ts b/src/lib/QtGui/QEvent/QDragMoveEvent.ts index f52151d7b..c79537345 100644 --- a/src/lib/QtGui/QEvent/QDragMoveEvent.ts +++ b/src/lib/QtGui/QEvent/QDragMoveEvent.ts @@ -1,12 +1,12 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; import { DropAction } from '../../QtEnums'; import { QMimeData } from '../../QtCore/QMimeData'; +import { QEvent } from './QEvent'; -export class QDragMoveEvent { - native: NativeElement; +export class QDragMoveEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QDragMoveEvent(event); + super(new addon.QDragMoveEvent(event)); } /** @@ -114,30 +114,4 @@ export class QDragMoveEvent { // source(): QObject { // return this.native.source(); // } - - //Methods from QEvent --------------------------- - isAccepted(): boolean { - return this.native.isAccepted(); - } - /** - * Sets the accept flag of the event object - */ - setAccepted(accepted: boolean): void { - return this.native.setAccepted(accepted); - } - /** - * Returns true if the event originated outside the application (a system event); otherwise returns false. - * - * The return value of this function is not defined for paint events. - */ - spontaneous(): boolean { - return this.native.spontaneous(); - } - /** - * Returns the event type - * @returns {Number} This is QEvent::Type - */ - type(): number { - return this.native._type(); - } } diff --git a/src/lib/QtGui/QEvent/QDropEvent.ts b/src/lib/QtGui/QEvent/QDropEvent.ts index f7a7cf41b..fe2b96737 100644 --- a/src/lib/QtGui/QEvent/QDropEvent.ts +++ b/src/lib/QtGui/QEvent/QDropEvent.ts @@ -1,12 +1,12 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; import { DropAction } from '../../QtEnums'; import { QMimeData } from '../../QtCore/QMimeData'; +import { QEvent } from './QEvent'; -export class QDropEvent { - native: NativeElement; +export class QDropEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QDropEvent(event); + super(new addon.QDropEvent(event)); } /** Sets the drop action to be the proposed action */ @@ -82,45 +82,4 @@ export class QDropEvent { // source(): QObject { // return this.native.source(); // } - - //Methods from QEvent --------------------------- - /** - * Sets the accept flag of the event object, the equivalent of calling setAccepted(true). - * Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget - */ - accept(): void { - return this.native.accept(); - } - /** - * Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false). - * Clearing the accept parameter indicates that the event receiver does not want the event. - * Unwanted events might be propagated to the parent widget. - */ - ignore(): void { - return this.native.ignore(); - } - isAccepted(): boolean { - return this.native.isAccepted(); - } - /** - * Sets the accept flag of the event object - */ - setAccepted(accepted: boolean): void { - return this.native.setAccepted(accepted); - } - /** - * Returns true if the event originated outside the application (a system event); otherwise returns false. - * - * The return value of this function is not defined for paint events. - */ - spontaneous(): boolean { - return this.native.spontaneous(); - } - /** - * Returns the event type - * @returns {Number} This is QEvent::Type - */ - type(): number { - return this.native._type(); - } } diff --git a/src/lib/QtGui/QEvent/QEvent.ts b/src/lib/QtGui/QEvent/QEvent.ts new file mode 100644 index 000000000..2536f78b0 --- /dev/null +++ b/src/lib/QtGui/QEvent/QEvent.ts @@ -0,0 +1,51 @@ +import { NativeElement } from '../../core/Component'; + +export abstract class QEvent { + native: NativeElement; + + constructor(native: NativeElement) { + this.native = native; + } + + //Methods from QEvent --------------------------- + /** + * Sets the accept flag of the event object, the equivalent of calling setAccepted(true). + * Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget + */ + accept(): void { + return this.native.accept(); + } + + /** + * Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false). + * Clearing the accept parameter indicates that the event receiver does not want the event. + * Unwanted events might be propagated to the parent widget. + */ + ignore(): void { + return this.native.ignore(); + } + isAccepted(): boolean { + return this.native.isAccepted(); + } + /** + * Sets the accept flag of the event object + */ + setAccepted(accepted: boolean): void { + return this.native.setAccepted(accepted); + } + /** + * Returns true if the event originated outside the application (a system event); otherwise returns false. + * + * The return value of this function is not defined for paint events. + */ + spontaneous(): boolean { + return this.native.spontaneous(); + } + /** + * Returns the event type + * @returns {Number} This is QEvent::Type + */ + type(): number { + return this.native._type(); + } +} diff --git a/src/lib/QtGui/QEvent/QKeyEvent.ts b/src/lib/QtGui/QEvent/QKeyEvent.ts index 2f4834974..9670ff0be 100644 --- a/src/lib/QtGui/QEvent/QKeyEvent.ts +++ b/src/lib/QtGui/QEvent/QKeyEvent.ts @@ -1,10 +1,10 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; +import { QEvent } from './QEvent'; -export class QKeyEvent { - native: NativeElement; +export class QKeyEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QKeyEvent(event); + super(new addon.QKeyEvent(event)); } text(): string { return this.native.text(); diff --git a/src/lib/QtGui/QEvent/QMouseEvent.ts b/src/lib/QtGui/QEvent/QMouseEvent.ts index b9c6df2ac..73cf92707 100644 --- a/src/lib/QtGui/QEvent/QMouseEvent.ts +++ b/src/lib/QtGui/QEvent/QMouseEvent.ts @@ -1,10 +1,10 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; +import { QEvent } from './QEvent'; -export class QMouseEvent { - native: NativeElement; +export class QMouseEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QMouseEvent(event); + super(new addon.QMouseEvent(event)); } button(): number { return this.native.button(); diff --git a/src/lib/QtGui/QEvent/QNativeGestureEvent.ts b/src/lib/QtGui/QEvent/QNativeGestureEvent.ts index 3e9cb7722..38fc78258 100644 --- a/src/lib/QtGui/QEvent/QNativeGestureEvent.ts +++ b/src/lib/QtGui/QEvent/QNativeGestureEvent.ts @@ -1,11 +1,11 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; import { NativeGestureType } from '../../QtEnums'; +import { QEvent } from './QEvent'; -export class QNativeGestureEvent { - native: NativeElement; +export class QNativeGestureEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QNativeGestureEvent(event); + super(new addon.QNativeGestureEvent(event)); } //Needs QTouchDevice to implement this diff --git a/src/lib/QtGui/QEvent/QPaintEvent.ts b/src/lib/QtGui/QEvent/QPaintEvent.ts index 1c22c057d..115e3b04b 100644 --- a/src/lib/QtGui/QEvent/QPaintEvent.ts +++ b/src/lib/QtGui/QEvent/QPaintEvent.ts @@ -1,11 +1,11 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; import { QRect } from '../../..'; +import { QEvent } from './QEvent'; -export class QPaintEvent { - native: NativeElement; +export class QPaintEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QPaintEvent(event); + super(new addon.QPaintEvent(event)); } rect(): QRect { return this.native.rect(); diff --git a/src/lib/QtGui/QEvent/QTabletEvent.ts b/src/lib/QtGui/QEvent/QTabletEvent.ts index 3c9bbbd47..02fecd09d 100644 --- a/src/lib/QtGui/QEvent/QTabletEvent.ts +++ b/src/lib/QtGui/QEvent/QTabletEvent.ts @@ -1,5 +1,6 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; +import { QEvent } from './QEvent'; enum PointerType { /** An unknown device */ @@ -28,14 +29,14 @@ enum TabletDevice { /** * The QTabletEvent class contains parameters that describe a Tablet event */ -export class QTabletEvent { +export class QTabletEvent extends QEvent { static readonly PointerType = PointerType; static readonly TabletDevice = TabletDevice; readonly PointerType = PointerType; readonly TabletDevice = TabletDevice; - native: NativeElement; + constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QTabletEvent(event); + super(new addon.QTabletEvent(event)); } /** * Returns the button that caused the event. diff --git a/src/lib/QtGui/QEvent/QWheelEvent.ts b/src/lib/QtGui/QEvent/QWheelEvent.ts index b3a86217b..5b8bad387 100644 --- a/src/lib/QtGui/QEvent/QWheelEvent.ts +++ b/src/lib/QtGui/QEvent/QWheelEvent.ts @@ -1,11 +1,11 @@ import addon from '../../utils/addon'; -import { NativeElement, NativeRawPointer } from '../../core/Component'; +import { NativeRawPointer } from '../../core/Component'; import { ScrollPhase } from '../../QtEnums'; +import { QEvent } from './QEvent'; -export class QWheelEvent { - native: NativeElement; +export class QWheelEvent extends QEvent { constructor(event: NativeRawPointer<'QEvent'>) { - this.native = new addon.QWheelEvent(event); + super(new addon.QWheelEvent(event)); } /** * Returns the relative amount that the wheel was rotated, in eighths of a degree. diff --git a/src/lib/QtWidgets/QBoxLayout.ts b/src/lib/QtWidgets/QBoxLayout.ts index cb550d516..39df53f36 100644 --- a/src/lib/QtWidgets/QBoxLayout.ts +++ b/src/lib/QtWidgets/QBoxLayout.ts @@ -2,10 +2,10 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; import { NodeLayout, QLayoutSignals } from './QLayout'; import { NativeElement } from '../core/Component'; -import { Direction } from '../QtEnums'; +import { AlignmentFlag, Direction } from '../QtEnums'; /** - + > Lines up child widgets horizontally or vertically. * **This class is a JS wrapper around Qt's [QBoxLayout class](https://doc.qt.io/qt-5/qboxlayout.html)** @@ -55,8 +55,8 @@ export class QBoxLayout extends NodeLayout { addStrut(size: number): void { this.native.addStrut(size); } - addWidget(widget: NodeWidget, stretch = 0): void { - this.native.addWidget(widget.native, stretch); + addWidget(widget: NodeWidget, stretch = 0, alignment: AlignmentFlag = 0): void { + this.native.addWidget(widget.native, stretch, alignment); this.nodeChildren.add(widget); } insertWidget(index: number, widget: NodeWidget, stretch = 0): void { diff --git a/src/lib/QtWidgets/QScrollArea.ts b/src/lib/QtWidgets/QScrollArea.ts index 347875cd8..bdd4fbb5c 100644 --- a/src/lib/QtWidgets/QScrollArea.ts +++ b/src/lib/QtWidgets/QScrollArea.ts @@ -3,9 +3,10 @@ import { NodeWidget } from './QWidget'; import { NativeElement } from '../core/Component'; import { QAbstractScrollArea, QAbstractScrollAreaSignals } from './QAbstractScrollArea'; import { AlignmentFlag } from '../QtEnums'; +import { Margins } from '../utils/Margins'; /** - + > A `QScrollArea` provides a scrolling view onto another widget. * **This class is a JS wrapper around Qt's [QScrollArea class](https://doc.qt.io/qt-5/qscrollarea.html)** @@ -81,6 +82,21 @@ export class QScrollArea extends QAbstractScrollArea { } return null; } + setViewportMargins(left: number, top: number, right: number, bottom: number): void { + // Technically part of QAbstractScrollArea, but the C++ side has subclass specific + // code needed, and setViewportMargins() isn't implemented yet for all of the + // subclasses. + this.native.setViewportMargins(left, top, right, bottom); + } + viewportMargins(): Margins { + const marginsArray = this.native.viewportMargins(); + return { + left: marginsArray[0], + top: marginsArray[1], + right: marginsArray[2], + bottom: marginsArray[3], + }; + } } export type QScrollAreaSignals = QAbstractScrollAreaSignals; diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index 8a18b64f5..7eb3fb9f0 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -289,9 +289,12 @@ export abstract class NodeWidget extends YogaWid acceptDrops(): boolean { return this.native.acceptDrops(); } - setFocus(reason: FocusReason): void { + setFocus(reason = FocusReason.OtherFocusReason): void { this.native.setFocus(reason); } + clearFocus(): void { + this.native.clearFocus(); + } } export interface QWidgetSignals extends QObjectSignals { diff --git a/src/lib/utils/Margins.ts b/src/lib/utils/Margins.ts new file mode 100644 index 000000000..976275f6c --- /dev/null +++ b/src/lib/utils/Margins.ts @@ -0,0 +1,6 @@ +export interface Margins { + left: number; + top: number; + right: number; + bottom: number; +}