Add QWidget.mapTo() and QWidget.mapFrom()
This commit is contained in:
parent
8058433031
commit
b4c9c0d51b
@ -58,6 +58,19 @@
|
||||
bool hasClosed = this->instance->close(); \
|
||||
return Napi::Boolean::New(env, hasClosed); \
|
||||
} \
|
||||
Napi::Value mapFrom(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::Object widgetObject = info[0].As<Napi::Object>(); \
|
||||
NodeWidgetWrap* widgetWrap = \
|
||||
Napi::ObjectWrap<NodeWidgetWrap>::Unwrap(widgetObject); \
|
||||
Napi::Object posObject = info[1].As<Napi::Object>(); \
|
||||
QPointWrap* posWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(posObject); \
|
||||
QPoint pt = this->instance->mapFrom(widgetWrap->getInternalInstance(), \
|
||||
*posWrap->getInternalInstance()); \
|
||||
auto instance = QPointWrap::constructor.New( \
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value mapFromGlobal(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::Object posObject = info[0].As<Napi::Object>(); \
|
||||
@ -96,6 +109,19 @@
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value mapTo(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::Object widgetObject = info[0].As<Napi::Object>(); \
|
||||
NodeWidgetWrap* widgetWrap = \
|
||||
Napi::ObjectWrap<NodeWidgetWrap>::Unwrap(widgetObject); \
|
||||
Napi::Object posObject = info[1].As<Napi::Object>(); \
|
||||
QPointWrap* posWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(posObject); \
|
||||
QPoint pt = this->instance->mapTo(widgetWrap->getInternalInstance(), \
|
||||
*posWrap->getInternalInstance()); \
|
||||
auto instance = QPointWrap::constructor.New( \
|
||||
{Napi::External<QPoint>::New(env, new QPoint(pt.x(), pt.y()))}); \
|
||||
return instance; \
|
||||
} \
|
||||
Napi::Value setLayout(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::Object layoutObject = info[0].As<Napi::Object>(); \
|
||||
@ -550,10 +576,12 @@
|
||||
InstanceMethod("show", &WidgetWrapName::show), \
|
||||
InstanceMethod("resize", &WidgetWrapName::resize), \
|
||||
InstanceMethod("close", &WidgetWrapName::close), \
|
||||
InstanceMethod("mapFrom", &WidgetWrapName::mapFrom), \
|
||||
InstanceMethod("mapFromGlobal", &WidgetWrapName::mapFromGlobal), \
|
||||
InstanceMethod("mapFromParent", &WidgetWrapName::mapFromParent), \
|
||||
InstanceMethod("mapToGlobal", &WidgetWrapName::mapToGlobal), \
|
||||
InstanceMethod("mapToParent", &WidgetWrapName::mapToParent), \
|
||||
InstanceMethod("mapTo", &WidgetWrapName::mapTo), \
|
||||
InstanceMethod("setLayout", &WidgetWrapName::setLayout), \
|
||||
InstanceMethod("setStyleSheet", &WidgetWrapName::setStyleSheet), \
|
||||
InstanceMethod("setCursor", &WidgetWrapName::setCursor), \
|
||||
@ -661,3 +689,8 @@
|
||||
});
|
||||
|
||||
#endif // QWIDGET_SIGNALS
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
// ^ Yes, this is weird due to the mutual dependency between the methods macro
|
||||
// and `NodeWidgetWrap`. Having this here makes everything work regardless if
|
||||
// `qwidget_wrap.h` is included first or `qwidget_macro.h`.
|
||||
|
||||
@ -8,21 +8,6 @@
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nwidget.hpp"
|
||||
|
||||
class DLL_EXPORT QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap> {
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
private:
|
||||
QPointer<NWidget> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QWidgetWrap(const Napi::CallbackInfo& info);
|
||||
~QWidgetWrap();
|
||||
NWidget* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
};
|
||||
|
||||
// NodeWidgetWrap is exactly like QWidgetWrap but it is used only to unwrap any
|
||||
// N<SomeWidget> to QWidget*
|
||||
class DLL_EXPORT NodeWidgetWrap : public Napi::ObjectWrap<NodeWidgetWrap> {
|
||||
@ -38,3 +23,18 @@ class DLL_EXPORT NodeWidgetWrap : public Napi::ObjectWrap<NodeWidgetWrap> {
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
};
|
||||
|
||||
class DLL_EXPORT QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap> {
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
private:
|
||||
QPointer<NWidget> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QWidgetWrap(const Napi::CallbackInfo& info);
|
||||
~QWidgetWrap();
|
||||
NWidget* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
};
|
||||
|
||||
@ -219,20 +219,24 @@ export abstract class NodeWidget<Signals extends QWidgetSignals> extends YogaWid
|
||||
// TODO: QLayout * layout() const
|
||||
// TODO: Qt::LayoutDirection layoutDirection() const
|
||||
// TODO: QLocale locale() const
|
||||
// TODO: QPoint mapFrom(const QWidget *parent, const QPoint &pos) const
|
||||
mapFrom(parent: QWidget, pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapFrom(parent.native, pos.native));
|
||||
}
|
||||
mapFromGlobal(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapFromGlobal(pos.native));
|
||||
}
|
||||
mapFromParent(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapFromParent(pos.native));
|
||||
}
|
||||
// TODO: QPoint mapTo(const QWidget *parent, const QPoint &pos) const
|
||||
mapToGlobal(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapToGlobal(pos.native));
|
||||
}
|
||||
mapToParent(pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapToParent(pos.native));
|
||||
}
|
||||
mapTo(parent: QWidget, pos: QPoint): QPoint {
|
||||
return new QPoint(this.native.mapTo(parent.native, pos.native));
|
||||
}
|
||||
// TODO: QRegion mask() const
|
||||
maximumHeight(): number {
|
||||
return this.property('maximumHeight').toInt();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user