Adds qobject props to all layouts (#196)
This commit is contained in:
parent
68c910d107
commit
9e667c7a86
@ -86,6 +86,8 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QShortcut/nshortcut.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QMenuBar/nmenubar.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QLayout/nlayout.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QGridLayout/ngridlayout.hpp"
|
||||
)
|
||||
|
||||
AddCommonConfig(${CORE_WIDGETS_ADDON})
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <QGridLayout>
|
||||
|
||||
#include "core/Events/eventwidget_macro.h"
|
||||
|
||||
class NGridLayout : public QGridLayout, public EventWidget {
|
||||
public:
|
||||
Q_OBJECT
|
||||
EVENTWIDGET_IMPLEMENTATIONS(NGridLayout)
|
||||
using QGridLayout::QGridLayout;
|
||||
};
|
||||
@ -6,17 +6,18 @@
|
||||
#include <QGridLayout>
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QGridLayout/ngridlayout.hpp"
|
||||
#include "QtWidgets/QLayout/qlayout_macro.h"
|
||||
|
||||
class QGridLayoutWrap : public Napi::ObjectWrap<QGridLayoutWrap> {
|
||||
private:
|
||||
QPointer<QGridLayout> instance;
|
||||
QPointer<NGridLayout> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QGridLayoutWrap(const Napi::CallbackInfo& info);
|
||||
~QGridLayoutWrap();
|
||||
QGridLayout* getInternalInstance();
|
||||
NGridLayout* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
|
||||
11
src/cpp/include/nodegui/QtWidgets/QLayout/nlayout.hpp
Normal file
11
src/cpp/include/nodegui/QtWidgets/QLayout/nlayout.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <QLayout>
|
||||
|
||||
#include "core/Events/eventwidget_macro.h"
|
||||
|
||||
class NLayout : public QLayout, public EventWidget {
|
||||
public:
|
||||
Q_OBJECT
|
||||
EVENTWIDGET_IMPLEMENTATIONS(NLayout)
|
||||
using QLayout::QLayout;
|
||||
};
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QSize>
|
||||
|
||||
#include "QtCore/QObject/qobject_macro.h"
|
||||
|
||||
/*
|
||||
|
||||
This macro adds common QLayout exported methods
|
||||
@ -12,7 +13,7 @@
|
||||
|
||||
#ifndef QLAYOUT_WRAPPED_METHODS_DECLARATION
|
||||
#define QLAYOUT_WRAPPED_METHODS_DECLARATION \
|
||||
COMPONENT_WRAPPED_METHODS_DECLARATION \
|
||||
QOBJECT_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value activate(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
@ -38,7 +39,7 @@
|
||||
#ifndef QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(LayoutWrapName) \
|
||||
\
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE \
|
||||
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(LayoutWrapName) \
|
||||
InstanceMethod("activate", &LayoutWrapName::activate), \
|
||||
InstanceMethod("invalidate", &LayoutWrapName::invalidate), \
|
||||
InstanceMethod("update", &LayoutWrapName::update),
|
||||
|
||||
@ -6,18 +6,19 @@
|
||||
#include <QLayout>
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QLayout/nlayout.hpp"
|
||||
#include "QtWidgets/QLayout/qlayout_macro.h"
|
||||
|
||||
// ABSTRACT CLASS
|
||||
class QLayoutWrap : public Napi::ObjectWrap<QLayoutWrap> {
|
||||
private:
|
||||
QPointer<QLayout> instance;
|
||||
QPointer<NLayout> instance;
|
||||
|
||||
public:
|
||||
static void init(Napi::Env env);
|
||||
QLayoutWrap(const Napi::CallbackInfo& info);
|
||||
~QLayoutWrap();
|
||||
QLayout* getInternalInstance();
|
||||
NLayout* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
|
||||
@ -12,7 +12,7 @@ class NWidget : public QWidget, public NodeWidget {
|
||||
public:
|
||||
using QWidget::QWidget;
|
||||
// https://doc.qt.io/qt-5/stylesheet-reference.html
|
||||
void paintEvent(QPaintEvent *e) {
|
||||
void paintEvent(QPaintEvent *e) override {
|
||||
QStyleOption opt;
|
||||
opt.init(this);
|
||||
QPainter p(this);
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
|
||||
#ifndef EVENTWIDGET_IMPLEMENTATIONS
|
||||
#define EVENTWIDGET_IMPLEMENTATIONS(BaseWidgetName) \
|
||||
bool event(QEvent* event) { \
|
||||
bool event(QEvent* event) override { \
|
||||
EventWidget::event(event); \
|
||||
return BaseWidgetName::event(event); \
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <QLayout>
|
||||
|
||||
#include "core/Events/eventwidget_macro.h"
|
||||
#include "deps/yoga/YGNode.h"
|
||||
|
||||
/*
|
||||
@ -17,7 +18,7 @@ YGNodeNew(); FlexLayout * flayout = new FlexLayout(container,root);
|
||||
flayout->addWidget(btn2, child2);
|
||||
*/
|
||||
|
||||
class FlexLayout : public QLayout {
|
||||
class FlexLayout : public QLayout, public EventWidget {
|
||||
private:
|
||||
YGNodeRef node;
|
||||
YGNodeRef getRootNode(YGNodeRef node);
|
||||
@ -41,4 +42,6 @@ class FlexLayout : public QLayout {
|
||||
void setGeometry(const QRect &rect) override;
|
||||
void setFlexNode(YGNodeRef parentNode);
|
||||
static NodeContext *getNodeContext(YGNodeRef node);
|
||||
|
||||
EVENTWIDGET_IMPLEMENTATIONS(FlexLayout)
|
||||
};
|
||||
|
||||
@ -18,7 +18,7 @@ Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
QGridLayout* QGridLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
NGridLayout* QGridLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
QGridLayoutWrap::~QGridLayoutWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info)
|
||||
@ -30,9 +30,9 @@ QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new QGridLayout(parentWidgetWrap->getInternalInstance());
|
||||
this->instance = new NGridLayout(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new QGridLayout();
|
||||
this->instance = new NGridLayout();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
|
||||
@ -10,7 +10,7 @@ void QLayoutWrap::init(Napi::Env env) {
|
||||
constructor = Napi::Persistent(func);
|
||||
}
|
||||
|
||||
QLayout* QLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
NLayout* QLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QLayoutWrap::QLayoutWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QLayoutWrap>(info) {
|
||||
|
||||
@ -12,14 +12,14 @@ export class QKeyEvent {
|
||||
};
|
||||
key = (): number => {
|
||||
return this.native.key();
|
||||
};
|
||||
};
|
||||
modifiers = (): number => {
|
||||
return this.native.modifiers();
|
||||
};
|
||||
};
|
||||
count = (): number => {
|
||||
return this.native.count();
|
||||
};
|
||||
};
|
||||
isAutoRepeat = (): boolean => {
|
||||
return this.native.isAutoRepeat();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@ -6,13 +6,15 @@ import { NativeElement } from '../core/Component';
|
||||
export class QGridLayout extends NodeLayout {
|
||||
native: NativeElement;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native: NativeElement;
|
||||
if (parent) {
|
||||
this.native = new addon.QGridLayout(parent.native);
|
||||
this.nodeParent = parent;
|
||||
native = new addon.QGridLayout(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QGridLayout();
|
||||
native = new addon.QGridLayout();
|
||||
}
|
||||
super(native);
|
||||
this.nodeParent = parent;
|
||||
this.native = native;
|
||||
}
|
||||
addWidget(widget: NodeWidget): void {
|
||||
this.native.addWidget(widget.native);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Component } from '../core/Component';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NodeObject } from '../QtCore/QObject';
|
||||
|
||||
// All Layouts should extend this abstract class.
|
||||
export abstract class NodeLayout extends Component {
|
||||
export abstract class NodeLayout extends NodeObject {
|
||||
type = 'layout';
|
||||
abstract addWidget(childWidget: NodeWidget, ...args: any[]): void;
|
||||
activate = (): boolean => {
|
||||
|
||||
@ -5,7 +5,12 @@ import { FlexNode } from './YogaWidget';
|
||||
import { NativeElement } from './Component';
|
||||
|
||||
export class FlexLayout extends NodeLayout {
|
||||
native: NativeElement = new addon.FlexLayout();
|
||||
native: NativeElement;
|
||||
constructor() {
|
||||
const native = new addon.FlexLayout();
|
||||
super(native);
|
||||
this.native = native;
|
||||
}
|
||||
protected flexNode?: FlexNode;
|
||||
|
||||
addWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user