Add QStackedWidget (for page style navigation) (#245)
* Add possibility to set row, col, rowSpan, colSpan in QGridLayout's addWidget Add QStackedWidget * Add .idea to .gitignore * Lint fixes * Update Yoga configuration
This commit is contained in:
parent
76664f6732
commit
98be88f8ae
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ dist
|
||||
.vscode
|
||||
.cache
|
||||
coverage
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
/.idea/
|
||||
|
||||
@ -62,6 +62,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp"
|
||||
@ -87,6 +88,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QRadioButton/nradiobutton.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/nplaintextedit.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QStackedWidget/nstackedwidget.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTabWidget/ntabwidget.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/nsystemtrayicon.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QAction/naction.hpp"
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <QStackedWidget>
|
||||
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
class NStackedWidget : public QStackedWidget, public NodeWidget {
|
||||
Q_OBJECT
|
||||
NODEWIDGET_IMPLEMENTATIONS(QStackedWidget)
|
||||
public:
|
||||
using QStackedWidget::QStackedWidget; // inherit all constructors of
|
||||
// QStackedWidget
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QStackedWidget::currentChanged, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "currentChanged"),
|
||||
Napi::Value::From(env, index)});
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QStackedWidget/nstackedwidget.hpp"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
|
||||
class QStackedWidgetWrap : public Napi::ObjectWrap<QStackedWidgetWrap> {
|
||||
private:
|
||||
QPointer<NStackedWidget> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QStackedWidgetWrap(const Napi::CallbackInfo &info);
|
||||
~QStackedWidgetWrap();
|
||||
NStackedWidget *getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
Napi::Value addWidget(const Napi::CallbackInfo &info);
|
||||
Napi::Value removeWidget(const Napi::CallbackInfo &info);
|
||||
Napi::Value setCurrentIndex(const Napi::CallbackInfo &info);
|
||||
Napi::Value currentIndex(const Napi::CallbackInfo &info);
|
||||
Napi::Value setCurrentWidget(const Napi::CallbackInfo &info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
@ -45,8 +45,13 @@ Napi::Value QGridLayoutWrap::addWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object qwidgetObject = info[0].As<Napi::Object>();
|
||||
Napi::Number qrow = info[1].As<Napi::Number>();
|
||||
Napi::Number qcol = info[2].As<Napi::Number>();
|
||||
Napi::Number qrowSpan = info[3].As<Napi::Number>();
|
||||
Napi::Number qcolSpan = info[4].As<Napi::Number>();
|
||||
QWidgetWrap* widget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(qwidgetObject);
|
||||
this->instance->addWidget(widget->getInternalInstance());
|
||||
this->instance->addWidget(widget->getInternalInstance(), qrow, qcol, qrowSpan,
|
||||
qcolSpan);
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
105
src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp
Normal file
105
src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
#include "QtWidgets/QStackedWidget/qstackedwidget_wrap.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
|
||||
Napi::FunctionReference QStackedWidgetWrap::constructor;
|
||||
|
||||
Napi::Object QStackedWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QStackedWidget";
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("addWidget", &QStackedWidgetWrap::addWidget),
|
||||
InstanceMethod("removeWidget", &QStackedWidgetWrap::removeWidget),
|
||||
InstanceMethod("setCurrentIndex", &QStackedWidgetWrap::setCurrentIndex),
|
||||
InstanceMethod("currentIndex", &QStackedWidgetWrap::currentIndex),
|
||||
InstanceMethod("setCurrentWidget",
|
||||
&QStackedWidgetWrap::setCurrentWidget),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QStackedWidgetWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
NStackedWidget* QStackedWidgetWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QStackedWidgetWrap::~QStackedWidgetWrap() {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
|
||||
QStackedWidgetWrap::QStackedWidgetWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QStackedWidgetWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NStackedWidget(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NStackedWidget();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
this->rawData = extrautils::configureQWidget(
|
||||
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
|
||||
true);
|
||||
}
|
||||
|
||||
Napi::Value QStackedWidgetWrap::addWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object qwidgetObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* widget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(qwidgetObject);
|
||||
this->instance->addWidget(widget->getInternalInstance());
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QStackedWidgetWrap::removeWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object qwidgetObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* widget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(qwidgetObject);
|
||||
this->instance->removeWidget(widget->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QStackedWidgetWrap::setCurrentIndex(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Number index = info[0].As<Napi::Number>();
|
||||
this->instance->setCurrentIndex(index.Int32Value());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QStackedWidgetWrap::currentIndex(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int value = this->instance->currentIndex();
|
||||
return Napi::Number::New(env, value);
|
||||
}
|
||||
|
||||
Napi::Value QStackedWidgetWrap::setCurrentWidget(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object qwidgetObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* widget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(qwidgetObject);
|
||||
|
||||
this->instance->setCurrentWidget(widget->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
@ -32,6 +32,7 @@
|
||||
#include "QtWidgets/QScrollArea/qscrollarea_wrap.h"
|
||||
#include "QtWidgets/QShortcut/qshortcut_wrap.h"
|
||||
#include "QtWidgets/QSpinBox/qspinbox_wrap.h"
|
||||
#include "QtWidgets/QStackedWidget/qstackedwidget_wrap.h"
|
||||
#include "QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h"
|
||||
#include "QtWidgets/QTabWidget/qtabwidget_wrap.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
@ -66,6 +67,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QCheckBoxWrap::init(env, exports);
|
||||
QProgressBarWrap::init(env, exports);
|
||||
QRadioButtonWrap::init(env, exports);
|
||||
QStackedWidgetWrap::init(env, exports);
|
||||
QTabWidgetWrap::init(env, exports);
|
||||
QLineEditWrap::init(env, exports);
|
||||
QKeyEventWrap::init(env, exports);
|
||||
|
||||
@ -32,6 +32,7 @@ export { QProgressBar, QProgressBarEvents } from './lib/QtWidgets/QProgressBar';
|
||||
export { QPushButton, QPushButtonEvents } from './lib/QtWidgets/QPushButton';
|
||||
export { QSpinBox, QSpinBoxEvents } from './lib/QtWidgets/QSpinBox';
|
||||
export { QRadioButton, QRadioButtonEvents } from './lib/QtWidgets/QRadioButton';
|
||||
export { QStackedWidget, QStackedWidgetEvents } from './lib/QtWidgets/QStackedWidget';
|
||||
export { QTabWidget, QTabWidgetEvents } from './lib/QtWidgets/QTabWidget';
|
||||
export { QMenu, QMenuEvents } from './lib/QtWidgets/QMenu';
|
||||
export { QMenuBar, QMenuBarEvents } from './lib/QtWidgets/QMenuBar';
|
||||
|
||||
@ -16,8 +16,8 @@ export class QGridLayout extends NodeLayout {
|
||||
this.nodeParent = parent;
|
||||
this.native = native;
|
||||
}
|
||||
addWidget(widget: NodeWidget): void {
|
||||
this.native.addWidget(widget.native);
|
||||
addWidget(widget: NodeWidget, row = 0, col = 0, rowSpan = 1, colSpan = 1): void {
|
||||
this.native.addWidget(widget.native, row, col, rowSpan, colSpan);
|
||||
this.nodeChildren.add(widget);
|
||||
}
|
||||
removeWidget(widget: NodeWidget): void {
|
||||
|
||||
@ -61,9 +61,9 @@ export class QMainWindow extends NodeWidget {
|
||||
get layout(): NodeLayout | undefined {
|
||||
if (this.centralWidget) {
|
||||
return this.centralWidget.layout;
|
||||
} else {
|
||||
return super.layout;
|
||||
}
|
||||
|
||||
return super.layout;
|
||||
}
|
||||
center(): void {
|
||||
this.native.center();
|
||||
|
||||
46
src/lib/QtWidgets/QStackedWidget.ts
Normal file
46
src/lib/QtWidgets/QStackedWidget.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget, QWidget } from './QWidget';
|
||||
import { BaseWidgetEvents } from '../core/EventWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
|
||||
export const QStackedWidgetEvents = Object.freeze({
|
||||
...BaseWidgetEvents,
|
||||
currentChanged: 'currentChanged',
|
||||
});
|
||||
|
||||
export class QStackedWidget extends NodeWidget {
|
||||
native: NativeElement;
|
||||
constructor(parent?: NodeWidget) {
|
||||
let native;
|
||||
if (parent) {
|
||||
native = new addon.QStackedWidget(parent.native);
|
||||
} else {
|
||||
native = new addon.QStackedWidget();
|
||||
}
|
||||
super(native);
|
||||
this.nodeParent = parent;
|
||||
this.native = native;
|
||||
}
|
||||
|
||||
addWidget(widget: NodeWidget): void {
|
||||
this.native.addWidget(widget.native);
|
||||
this.nodeChildren.add(widget);
|
||||
}
|
||||
|
||||
removeWidget(widget: NodeWidget): void {
|
||||
this.native.removeWidget(widget.native);
|
||||
this.nodeChildren.delete(widget);
|
||||
}
|
||||
|
||||
setCurrentIndex(index: number): void {
|
||||
this.native.setCurrentIndex(index);
|
||||
}
|
||||
|
||||
currentIndex(): number {
|
||||
return this.native.currentIndex();
|
||||
}
|
||||
|
||||
setCurrentWidget(widget: NodeWidget): void {
|
||||
this.native.setCurrentWidget(widget.native);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user