Adds mouse tracking and fixes events for QWidget

This commit is contained in:
Atul R 2019-07-11 20:24:19 +02:00
parent 790fec5fd6
commit f9841c6ad6
4 changed files with 16 additions and 10 deletions

View File

@ -3,14 +3,12 @@
#include <QStyleOption>
#include <QPainter>
#include <QStyle>
#include "src/cpp/core/YogaWidget/yogawidget.h"
#include "src/cpp/core/Events/eventwidget.h"
#include "src/cpp/core/NodeWidget/nodewidget.h"
class NWidget: public QWidget, public YogaWidget, public EventWidget
class NWidget: public QWidget, public NodeWidget
{
NODEWIDGET_IMPLEMENTATIONS
public:
SET_YOGA_WIDGET_Q_PROPERTIES
using QWidget::QWidget; //inherit all constructors of QWidget
// https://doc.qt.io/qt-5/stylesheet-reference.html
void paintEvent(QPaintEvent *)
@ -20,7 +18,6 @@ public:
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Q_OBJECT
};

View File

@ -70,6 +70,13 @@ Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
this->instance->setObjectName(QString::fromStdString(objectName.Utf8Value())); \
return env.Null(); \
} \
Napi::Value setMouseTracking(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Boolean isMouseTracked = info[0].As<Napi::Boolean>(); \
this->instance->setMouseTracking(isMouseTracked.Value()); \
return env.Null(); \
} \
#endif //QWIDGET_WRAPPED_METHODS_DECLARATION
@ -85,6 +92,7 @@ Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
InstanceMethod("setStyleSheet",&WidgetWrapName::setStyleSheet), \
InstanceMethod("hide",&WidgetWrapName::hide), \
InstanceMethod("setObjectName",&WidgetWrapName::setObjectName), \
InstanceMethod("setMouseTracking",&WidgetWrapName::setMouseTracking), \
#endif // QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE

View File

@ -292,10 +292,8 @@ void *NWidget::qt_metacast(const char *_clname)
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_NWidget.stringdata0))
return static_cast<void*>(this);
if (!strcmp(_clname, "YogaWidget"))
return static_cast< YogaWidget*>(this);
if (!strcmp(_clname, "EventWidget"))
return static_cast< EventWidget*>(this);
if (!strcmp(_clname, "NodeWidget"))
return static_cast< NodeWidget*>(this);
return QWidget::qt_metacast(_clname);
}

View File

@ -30,6 +30,9 @@ export abstract class NodeWidget extends EventWidget {
setObjectName = (objectName: string) => {
this.native.setObjectName(objectName);
};
setMouseTracking = (isMouseTracked: boolean) => {
this.native.setMouseTracking(isMouseTracked);
};
}
export class QWidget extends NodeWidget {