diff --git a/src/index.ts b/src/index.ts index 0e989d741..1d148bd03 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,7 +40,7 @@ export { QWindow } from './lib/QtGui/QWindow'; export { WidgetEventTypes } from './lib/core/EventWidget'; // Abstract: export { QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget'; -export { NodeLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout'; +export { QLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout'; export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea'; export { QAbstractSlider, QAbstractSliderSignals, SliderAction } from './lib/QtWidgets/QAbstractSlider'; export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton'; diff --git a/src/lib/QtWidgets/QBoxLayout.ts b/src/lib/QtWidgets/QBoxLayout.ts index daffb431f..5c57c4935 100644 --- a/src/lib/QtWidgets/QBoxLayout.ts +++ b/src/lib/QtWidgets/QBoxLayout.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NodeLayout, QLayoutSignals } from './QLayout'; +import { QLayout, QLayoutSignals } from './QLayout'; import { NativeElement } from '../core/Component'; import { AlignmentFlag, Direction } from '../QtEnums'; @@ -25,8 +25,8 @@ boxLayout.addWidget(new QCalendarWidget()); centralWidget.setLayout(boxLayout); ``` */ -export class QBoxLayout extends NodeLayout { - childLayouts: Set>; +export class QBoxLayout extends QLayout { + childLayouts: Set; constructor(dir: Direction, parent?: QWidget) { let native: NativeElement; if (parent) { @@ -38,7 +38,7 @@ export class QBoxLayout extends NodeLayout { this.setNodeParent(parent); this.childLayouts = new Set(); } - addLayout(layout: NodeLayout, stretch = 0): void { + addLayout(layout: QLayout, stretch = 0): void { this.native.addLayout(layout.native, stretch); this.childLayouts.add(layout); } @@ -62,7 +62,7 @@ export class QBoxLayout extends NodeLayout { direction(): Direction { return this.native.direction(); } - insertLayout(index: number, layout: NodeLayout, stretch = 0): void { + insertLayout(index: number, layout: QLayout, stretch = 0): void { this.native.insertLayout(index, layout.native, stretch); this.childLayouts.add(layout); } diff --git a/src/lib/QtWidgets/QGridLayout.ts b/src/lib/QtWidgets/QGridLayout.ts index d2bbe1fd4..9672d8fe0 100644 --- a/src/lib/QtWidgets/QGridLayout.ts +++ b/src/lib/QtWidgets/QGridLayout.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NodeLayout, QLayoutSignals } from './QLayout'; +import { QLayout, QLayoutSignals } from './QLayout'; import { NativeElement } from '../core/Component'; import { AlignmentFlag } from '../QtEnums'; @@ -29,7 +29,7 @@ layout.addWidget(label2); ``` */ -export class QGridLayout extends NodeLayout { +export class QGridLayout extends QLayout { constructor(parent?: QWidget) { let native: NativeElement; if (parent) { @@ -42,7 +42,7 @@ export class QGridLayout extends NodeLayout { } addLayout( - layout: NodeLayout, + layout: QLayout, row: number, column: number, rowSpan = 1, diff --git a/src/lib/QtWidgets/QLayout.ts b/src/lib/QtWidgets/QLayout.ts index ec0879526..e0c2864b3 100644 --- a/src/lib/QtWidgets/QLayout.ts +++ b/src/lib/QtWidgets/QLayout.ts @@ -9,21 +9,21 @@ import { QObject, QObjectSignals } from '../QtCore/QObject'; **This class implements all methods, properties of Qt's [QLayout class](https://doc.qt.io/qt-5/qlayout.html) so that it can be inherited by all layouts** -`NodeLayout` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all layout's easily. Additionally it helps in typechecking process. +`QLayout` is an abstract class and hence no instances of the same should be created. ### Example ```javascript const { - NodeLayout, + QLayout, FlexLayout, GridLayout, QPushButton, QWidget } = require("@nodegui/nodegui"); -// addChildToLayout can accept any layout since it expects NodeLayout -const addChildToLayout = (layout: NodeLayout, widget: QWidget) => { +// addChildToLayout can accept any layout since it expects QLayout +const addChildToLayout = (layout: QLayout, widget: QWidget) => { layout.addWidget(widget); }; @@ -31,7 +31,7 @@ addChildToLayout(new FlexLayout(), new QPushButton()); addChildToLayout(new GridLayout(), new QWidget()); ``` */ -export abstract class NodeLayout extends QObject { +export abstract class QLayout extends QObject { type = 'layout'; abstract addWidget(childWidget: QWidget, ...args: any[]): void; abstract removeWidget(childWidget: QWidget): void; @@ -67,10 +67,6 @@ export abstract class NodeLayout extends QObject } } -// export class QLayout extends NodeLayout { //Dont need QLayout for now -// native: any; -// } - export enum SizeConstraint { SetDefaultConstraint = 0, SetNoConstraint = 1, diff --git a/src/lib/QtWidgets/QMainWindow.ts b/src/lib/QtWidgets/QMainWindow.ts index f782508c5..bd906c702 100644 --- a/src/lib/QtWidgets/QMainWindow.ts +++ b/src/lib/QtWidgets/QMainWindow.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget, QWidgetSignals } from './QWidget'; -import { NodeLayout } from './QLayout'; +import { QLayout } from './QLayout'; import { QMenuBar } from './QMenuBar'; import { QStatusBar } from './QStatusBar'; import { NativeElement } from '../core/Component'; @@ -46,7 +46,7 @@ export class QMainWindow extends QWidget { super(native); this.setNodeParent(parent); - this.setLayout = (parentLayout: NodeLayout): void => { + this.setLayout = (parentLayout: QLayout): void => { if (this.centralWidget) { this.centralWidget.setLayout(parentLayout); } else { @@ -80,7 +80,7 @@ export class QMainWindow extends QWidget { setMenuWidget(menuWidget: QWidget): void { this.native.setMenuWidget(menuWidget.native); } - get layout(): NodeLayout | undefined { + get layout(): QLayout | undefined { if (this.centralWidget) { return this.centralWidget.layout; } diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index 2f0039ffb..d514a24c4 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -1,5 +1,5 @@ import addon from '../utils/addon'; -import { NodeLayout } from './QLayout'; +import { QLayout } from './QLayout'; import { NativeElement } from '../core/Component'; import { FlexLayout } from '../core/FlexLayout'; import { WidgetAttribute, WindowType, ContextMenuPolicy, FocusReason, FocusPolicy } from '../QtEnums'; @@ -41,7 +41,7 @@ view.setLayout(new FlexLayout()); ``` */ export class QWidget extends YogaWidget { - _layout?: NodeLayout; + _layout?: QLayout; _rawInlineStyle: string; type: string; private _effect?: QGraphicsEffect | null; @@ -68,10 +68,10 @@ export class QWidget extends Yo this.setObjectName = memoizeOne(this.setObjectName); } - get layout(): NodeLayout | undefined { + get layout(): QLayout | undefined { return this._layout; } - set layout(l: NodeLayout | undefined) { + set layout(l: QLayout | undefined) { this._layout = l; } // *** Public Functions *** @@ -380,7 +380,7 @@ export class QWidget extends Yo this.native.setStyleSheet(style); } } - setLayout(parentLayout: NodeLayout): void { + setLayout(parentLayout: QLayout): void { const flexLayout = parentLayout as FlexLayout; this.native.setLayout(parentLayout.native); if (flexLayout.setFlexNode) { diff --git a/src/lib/core/FlexLayout.ts b/src/lib/core/FlexLayout.ts index ec643d3fc..2f8d56d57 100644 --- a/src/lib/core/FlexLayout.ts +++ b/src/lib/core/FlexLayout.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget } from '../QtWidgets/QWidget'; -import { NodeLayout, QLayoutSignals } from '../QtWidgets/QLayout'; +import { QLayout, QLayoutSignals } from '../QtWidgets/QLayout'; import { FlexNode } from './YogaWidget'; export type FlexLayoutSignals = QLayoutSignals; @@ -31,7 +31,7 @@ layout.addWidget(label); layout.addWidget(label2); ``` */ -export class FlexLayout extends NodeLayout { +export class FlexLayout extends QLayout { protected flexNode?: FlexNode; constructor(parent?: QWidget) {