diff --git a/.eslintrc.js b/.eslintrc.js index 6c187d317..a3180f798 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,28 +1,29 @@ module.exports = { - extends: [ - "plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. - ], - parserOptions: { - ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features - sourceType: "module" // Allows for the use of imports - }, - overrides: [ - { - files: ["*.ts", "*.tsx"], - parser: "@typescript-eslint/parser", // Specifies the ESLint parser - extends: [ - "plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin - "prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier - "plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. - ], - parserOptions: { + extends: [ + 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. + ], + parserOptions: { ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features - sourceType: "module" // Allows for the use of imports - }, - rules: { - "@typescript-eslint/camelcase": 0, - "@typescript-eslint/no-var-requires": 0 - } - } - ] + sourceType: 'module', // Allows for the use of imports + }, + overrides: [ + { + files: ['*.ts', '*.tsx'], + parser: '@typescript-eslint/parser', // Specifies the ESLint parser + extends: [ + 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin + 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier + 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. + ], + parserOptions: { + ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features + sourceType: 'module', // Allows for the use of imports + }, + rules: { + '@typescript-eslint/camelcase': 0, + '@typescript-eslint/no-var-requires': 0, + '@typescript-eslint/no-explicit-any': 0, + }, + }, + ], }; diff --git a/src/lib/QtCore/QObject/index.ts b/src/lib/QtCore/QObject/index.ts index 0c2bffcbe..fc2172b90 100644 --- a/src/lib/QtCore/QObject/index.ts +++ b/src/lib/QtCore/QObject/index.ts @@ -1,7 +1,7 @@ import { EventWidget } from '../../core/EventWidget'; export abstract class QObject extends EventWidget { - inherits(className: string) { + inherits(className: string): boolean { return this.native.inherits(className); } } diff --git a/src/lib/QtGui/QApplication/index.ts b/src/lib/QtGui/QApplication/index.ts index 120a3384b..c07fccad6 100644 --- a/src/lib/QtGui/QApplication/index.ts +++ b/src/lib/QtGui/QApplication/index.ts @@ -14,29 +14,29 @@ export class QApplication extends Component { this.native = new addon.QApplication(); } } - static clipboard = (): QClipboard => { + static clipboard(): QClipboard { return new QClipboard(addon.QApplication.clipboard()); - }; - processEvents = () => { + } + processEvents(): void { this.native.processEvents(); - }; - exec = (): number => { + } + exec(): number { return this.native.exec(); - }; - static instance = (): QApplication => { + } + static instance(): QApplication { const nativeQApp = addon.QApplication.instance(); return new QApplication(nativeQApp); - }; - quit = () => { + } + quit(): number { return this.native.quit(); - }; - exit = (exitCode: number) => { + } + exit(exitCode: number): number { return this.native.exit(exitCode); - }; - setQuitOnLastWindowClosed = (quit: boolean) => { + } + setQuitOnLastWindowClosed(quit: boolean): void { this.native.setQuitOnLastWindowClosed(quit); - }; - quitOnLastWindowClosed = () => { + } + quitOnLastWindowClosed(): boolean { return this.native.quitOnLastWindowClosed(); - }; + } } diff --git a/src/lib/QtGui/QClipboard/index.ts b/src/lib/QtGui/QClipboard/index.ts index cc1b03740..e7128287b 100644 --- a/src/lib/QtGui/QClipboard/index.ts +++ b/src/lib/QtGui/QClipboard/index.ts @@ -11,15 +11,15 @@ export class QClipboard extends Component { throw new Error('QClipboard cannot be initialised this way. Use QApplication::clipboard()'); } } - clear = (mode: QClipboardMode) => { + clear(mode: QClipboardMode): void { this.native.clear(mode); - }; - setText = (text: string, mode: QClipboardMode) => { + } + setText(text: string, mode: QClipboardMode): void { this.native.setText(text, mode); - }; - text = (mode: QClipboardMode): string => { + } + text(mode: QClipboardMode): string { return this.native.text(mode); - }; + } } export enum QClipboardMode { diff --git a/src/lib/QtGui/QCursor/index.ts b/src/lib/QtGui/QCursor/index.ts index 8089fa885..ec25af897 100644 --- a/src/lib/QtGui/QCursor/index.ts +++ b/src/lib/QtGui/QCursor/index.ts @@ -13,10 +13,10 @@ export class QCursor extends Component { this.native = new addon.QCursor(); } } - pos = (): { x: number; y: number } => { + pos(): { x: number; y: number } { return this.native.pos(); - }; - setPos = (x: number, y: number) => { + } + setPos(x: number, y: number): void { return this.native.setPos(x, y); - }; + } } diff --git a/src/lib/QtGui/QIcon/index.ts b/src/lib/QtGui/QIcon/index.ts index 4043cd1c5..8a6673eba 100644 --- a/src/lib/QtGui/QIcon/index.ts +++ b/src/lib/QtGui/QIcon/index.ts @@ -41,7 +41,7 @@ export class QIcon extends Component { return this.native.isMask(); } - setIsMask(isMask: boolean) { + setIsMask(isMask: boolean): void { this.native.setIsMask(isMask); } } diff --git a/src/lib/QtWidgets/QAbstractScrollArea/index.ts b/src/lib/QtWidgets/QAbstractScrollArea/index.ts index 7bd6cc9da..18eba182e 100644 --- a/src/lib/QtWidgets/QAbstractScrollArea/index.ts +++ b/src/lib/QtWidgets/QAbstractScrollArea/index.ts @@ -2,14 +2,14 @@ import { NodeWidget, QWidget } from '../QWidget'; export abstract class QAbstractScrollArea extends NodeWidget { viewportWidget?: NodeWidget; - setViewport = (widget: NodeWidget) => { + setViewport(widget: NodeWidget): void { this.viewportWidget = widget; this.native.setViewport(widget.native); - }; - viewport = (): QWidget => { + } + viewport(): QWidget { if (!this.viewportWidget) { this.viewportWidget = new QWidget(this.native.viewport()); } return this.viewportWidget; - }; + } } diff --git a/src/lib/QtWidgets/QAbstractSlider/index.ts b/src/lib/QtWidgets/QAbstractSlider/index.ts index 32bfc10ea..2079b9319 100644 --- a/src/lib/QtWidgets/QAbstractSlider/index.ts +++ b/src/lib/QtWidgets/QAbstractSlider/index.ts @@ -2,28 +2,28 @@ import { NodeWidget } from '../QWidget'; import { Orientation } from '../../QtEnums'; export abstract class QAbstractSlider extends NodeWidget { - setSingleStep = (step: number) => { + setSingleStep(step: number): void { this.native.setSingleStep(step); - }; - setMaximum(maximum: number) { + } + setMaximum(maximum: number): void { this.native.setMaximum(maximum); } maximum(): number { return this.native.maximum(); } - setMinimum(minimum: number) { + setMinimum(minimum: number): void { this.native.setMinimum(minimum); } minimum(): number { return this.native.minimum(); } - setValue(value: number) { + setValue(value: number): void { this.native.setValue(value); } value(): number { return this.native.value(); } - setOrientation(orientation: Orientation) { + setOrientation(orientation: Orientation): void { this.native.setOrientation(orientation); } } diff --git a/src/lib/QtWidgets/QAction/index.ts b/src/lib/QtWidgets/QAction/index.ts index 445252459..aa5eac168 100644 --- a/src/lib/QtWidgets/QAction/index.ts +++ b/src/lib/QtWidgets/QAction/index.ts @@ -27,42 +27,42 @@ export class QAction extends QObject { super(native); this.native = native; } - setText(text: string) { + setText(text: string): void { this.native.setText(text); } - setEnabled(enabled: boolean) { + setEnabled(enabled: boolean): void { this.native.setEnabled(enabled); } - setIcon(icon: QIcon) { + setIcon(icon: QIcon): void { this.icon = icon; this.native.setIcon(icon.native); } - setMenu(menu: QMenu) { + setMenu(menu: QMenu): void { this.menu = menu; this.native.setMenu(menu.native); } - setShortcut(keysequence: QKeySequence) { + setShortcut(keysequence: QKeySequence): void { this.native.setShortcut(keysequence.native); } - setShortcutContext(shortcutContext: ShortcutContext) { + setShortcutContext(shortcutContext: ShortcutContext): void { this.native.setShortcutContext(shortcutContext); } isCheckable(): boolean { return this.native.isCheckable(); } - setCheckable(isCheckable: boolean) { + setCheckable(isCheckable: boolean): void { this.native.setCheckable(isCheckable); } isChecked(): boolean { return this.native.isChecked(); } - setChecked(isChecked: boolean) { + setChecked(isChecked: boolean): void { this.native.setChecked(isChecked); } isSeparator(): boolean { return this.native.isSeparator(); } - setSeparator(isSeparator: boolean) { + setSeparator(isSeparator: boolean): void { this.native.setSeparator(isSeparator); } } diff --git a/src/lib/QtWidgets/QCheckBox/index.ts b/src/lib/QtWidgets/QCheckBox/index.ts index 0c72db421..b9dd377fa 100644 --- a/src/lib/QtWidgets/QCheckBox/index.ts +++ b/src/lib/QtWidgets/QCheckBox/index.ts @@ -19,18 +19,14 @@ export class QCheckBox extends NodeWidget { super(native); this.native = native; this.nodeParent = parent; - // bind member functions - this.setText.bind(this); - this.setChecked.bind(this); - this.isChecked.bind(this); } - setText(text: string) { + setText(text: string): void { // react:✓ //TODO:getter this.native.setText(text); } - setChecked(check: boolean) { + setChecked(check: boolean): void { // react:✓ - return this.native.setChecked(check); + this.native.setChecked(check); } isChecked(): boolean { // react:✓ diff --git a/src/lib/QtWidgets/QDial/index.ts b/src/lib/QtWidgets/QDial/index.ts index 444c709d6..c5b35d298 100644 --- a/src/lib/QtWidgets/QDial/index.ts +++ b/src/lib/QtWidgets/QDial/index.ts @@ -24,15 +24,8 @@ export class QDial extends QAbstractSlider { super(native); this.native = native; this.nodeParent = parent; - // bind member functions - this.setNotchesVisible.bind(this); - this.notchesVisible.bind(this); - this.setWrapping.bind(this); - this.wrapping.bind(this); - this.setNotchTarget.bind(this); - this.notchTarget.bind(this); } - setNotchesVisible(visible: boolean) { + setNotchesVisible(visible: boolean): void { // react:✓ this.native.setNotchesVisible(visible); } @@ -40,7 +33,7 @@ export class QDial extends QAbstractSlider { // react:✓ return this.native.notchesVisible(); } - setWrapping(on: boolean) { + setWrapping(on: boolean): void { // react:✓ this.native.setWrapping(on); } @@ -48,7 +41,7 @@ export class QDial extends QAbstractSlider { // react:✓ return this.native.wrapping(); } - setNotchTarget(target: number) { + setNotchTarget(target: number): void { // react:✓ this.native.setNotchTarget(target); } diff --git a/src/lib/QtWidgets/QGridLayout/index.ts b/src/lib/QtWidgets/QGridLayout/index.ts index dc4e92d22..10b7a1269 100644 --- a/src/lib/QtWidgets/QGridLayout/index.ts +++ b/src/lib/QtWidgets/QGridLayout/index.ts @@ -14,12 +14,12 @@ export class QGridLayout extends NodeLayout { this.native = new addon.QGridLayout(); } } - addWidget = (widget: NodeWidget) => { + addWidget(widget: NodeWidget): void { this.native.addWidget(widget.native); this.nodeChildren.add(widget); - }; - removeWidget = (widget: NodeWidget) => { + } + removeWidget(widget: NodeWidget): void { this.native.removeWidget(widget.native); this.nodeChildren.delete(widget); - }; + } } diff --git a/src/lib/QtWidgets/QLabel/index.ts b/src/lib/QtWidgets/QLabel/index.ts index fbfd81cd2..43a5a4841 100644 --- a/src/lib/QtWidgets/QLabel/index.ts +++ b/src/lib/QtWidgets/QLabel/index.ts @@ -21,26 +21,26 @@ export class QLabel extends NodeWidget { this.native = native; this.nodeParent = parent; } - setWordWrap(on: boolean) { + setWordWrap(on: boolean): void { this.native.setWordWrap(on); } wordWrap(): boolean { return this.native.wordWrap(); } - setText(text: string | number) { + setText(text: string | number): void { this.native.setText(`${text}`); } - text() { + text(): string { return this.native.text(); } - setPixmap(pixMap: QPixmap) { + setPixmap(pixMap: QPixmap): void { this.native.setPixmap(pixMap.native); this._pixmap = pixMap; } - pixmap() { + pixmap(): QPixmap | undefined { return this._pixmap; } - setOpenExternalLinks(open: boolean) { + setOpenExternalLinks(open: boolean): void { this.native.setOpenExternalLinks(open); } } diff --git a/src/lib/QtWidgets/QLayout/index.ts b/src/lib/QtWidgets/QLayout/index.ts index f9349a4c2..b7e7e2e33 100644 --- a/src/lib/QtWidgets/QLayout/index.ts +++ b/src/lib/QtWidgets/QLayout/index.ts @@ -4,16 +4,16 @@ import { NodeWidget } from '../QWidget'; // All Layouts should extend this abstract class. export abstract class NodeLayout extends Component { type = 'layout'; - abstract addWidget: (childWidget: NodeWidget, ...args: any[]) => void; + abstract addWidget(childWidget: NodeWidget, ...args: any[]): void; activate = (): boolean => { return this.native.activate(); }; - invalidate = () => { + invalidate(): void { this.native.invalidate(); - }; - update = () => { + } + update(): void { this.native.update(); - }; + } } // export class QLayout extends NodeLayout { //Dont need QLayout for now diff --git a/src/lib/QtWidgets/QLineEdit/index.ts b/src/lib/QtWidgets/QLineEdit/index.ts index 20a913ec4..dd592273f 100644 --- a/src/lib/QtWidgets/QLineEdit/index.ts +++ b/src/lib/QtWidgets/QLineEdit/index.ts @@ -26,14 +26,8 @@ export class QLineEdit extends NodeWidget { super(native); this.native = native; this.nodeParent = parent; - // bind member functions - this.setText.bind(this); - this.text.bind(this); - this.setPlaceholderText.bind(this); - this.setReadOnly.bind(this); - this.clear.bind(this); } - setText(text: string) { + setText(text: string): void { // react:✓ text && this.native.setText(text); } @@ -41,16 +35,16 @@ export class QLineEdit extends NodeWidget { // react:✓ return this.native.text(); } - setPlaceholderText(text: string) { + setPlaceholderText(text: string): void { // react:✓ TODO://getter this.placeholderText = text; this.native.setPlaceholderText(text); } - setReadOnly(isReadOnly: boolean) { + setReadOnly(isReadOnly: boolean): void { // react:✓ TODO://getter this.native.setReadOnly(isReadOnly); } - clear() { + clear(): void { // react:✓ this.native.clear(); } diff --git a/src/lib/QtWidgets/QMainWindow/index.ts b/src/lib/QtWidgets/QMainWindow/index.ts index cc44d6d61..fb855804b 100644 --- a/src/lib/QtWidgets/QMainWindow/index.ts +++ b/src/lib/QtWidgets/QMainWindow/index.ts @@ -12,7 +12,6 @@ export class QMainWindow extends NodeWidget { native: NativeElement; public centralWidget?: NodeWidget; private _menuBar?: QMenuBar; - private _menuBarWidget?: NodeWidget; constructor(parent?: NodeWidget) { let native; if (parent) { @@ -25,7 +24,7 @@ export class QMainWindow extends NodeWidget { this.nodeParent = parent; // bind member functions this.setCentralWidget.bind(this); - this.setLayout = (parentLayout: NodeLayout) => { + this.setLayout = (parentLayout: NodeLayout): void => { if (this.centralWidget) { this.centralWidget.setLayout(parentLayout); } else { @@ -34,29 +33,29 @@ export class QMainWindow extends NodeWidget { } }; } - setCentralWidget(widget: NodeWidget) { + setCentralWidget(widget: NodeWidget): void { // react:✓ this.native.setCentralWidget(widget.native, widget.getFlexNode()); this.centralWidget = widget; } - setMenuBar(menuBar: QMenuBar) { + setMenuBar(menuBar: QMenuBar): void { this.native.setMenuBar(menuBar.native); this._menuBar = menuBar; } menuBar(): QMenuBar | undefined { return this._menuBar; } - setMenuWidget(menuWidget: NodeWidget) { + setMenuWidget(menuWidget: NodeWidget): void { this.native.setMenuWidget(menuWidget.native); } - get layout() { + get layout(): NodeLayout | undefined { if (this.centralWidget) { return this.centralWidget.layout; } else { return super.layout; } } - center() { + center(): void { this.native.center(); } } diff --git a/src/lib/QtWidgets/QMenu.ts b/src/lib/QtWidgets/QMenu.ts index d3aedb190..739996f6a 100644 --- a/src/lib/QtWidgets/QMenu.ts +++ b/src/lib/QtWidgets/QMenu.ts @@ -22,7 +22,7 @@ export class QMenu extends NodeWidget { this.nodeParent = parent; this.actions = new Set(); } - setTitle(title: string) { + setTitle(title: string): void { this.native.setTitle(title); } addAction(action: QAction): QAction { diff --git a/src/lib/QtWidgets/QMenuBar.ts b/src/lib/QtWidgets/QMenuBar.ts index d1ac34ddc..374383c60 100644 --- a/src/lib/QtWidgets/QMenuBar.ts +++ b/src/lib/QtWidgets/QMenuBar.ts @@ -29,10 +29,10 @@ export class QMenuBar extends NodeWidget { this.nodeParent = parent; } - addMenu(menu: QMenu) { + addMenu(menu: QMenu): void { this.native.addMenu(menu.native); } - setNativeMenuBar(nativeMenuBar: boolean) { + setNativeMenuBar(nativeMenuBar: boolean): void { this.native.setNativeMenuBar(nativeMenuBar); } } diff --git a/src/lib/QtWidgets/QPlainTextEdit/index.ts b/src/lib/QtWidgets/QPlainTextEdit/index.ts index 67cd3d33e..889d4093a 100644 --- a/src/lib/QtWidgets/QPlainTextEdit/index.ts +++ b/src/lib/QtWidgets/QPlainTextEdit/index.ts @@ -34,22 +34,12 @@ export class QPlainTextEdit extends QAbstractScrollArea { super(native); this.native = native; this.nodeParent = parent; - // bind member functions - this.setPlainText.bind(this); - this.setPlaceholderText.bind(this); - this.toPlainText.bind(this); - this.setReadOnly.bind(this); - this.clear.bind(this); - this.setWordWrapMode.bind(this); - this.wordWrapMode.bind(this); - this.setLineWrapMode.bind(this); - this.lineWrapMode.bind(this); } - setPlainText(text: string | number) { + setPlainText(text: string | number): void { // react:✓ this.native.setPlainText(`${text}`); } - setPlaceholderText(text: string) { + setPlaceholderText(text: string): void { // react:✓, //TODO:getter this.placeholderText = text; this.native.setPlaceholderText(text); @@ -58,21 +48,21 @@ export class QPlainTextEdit extends QAbstractScrollArea { // react:✓ return this.native.toPlainText(); } - setReadOnly(isReadOnly: boolean) { + setReadOnly(isReadOnly: boolean): void { // react:✓ this.native.setReadOnly(isReadOnly); } - clear() { + clear(): void { // react:✓ this.native.clear(); } - setWordWrapMode(mode: QTextOptionWrapMode) { + setWordWrapMode(mode: QTextOptionWrapMode): void { this.native.setWordWrapMode(mode); } wordWrapMode(): QTextOptionWrapMode { return this.native.wordWrapMode(); } - setLineWrapMode(mode: LineWrapMode) { + setLineWrapMode(mode: LineWrapMode): void { this.native.setLineWrapMode(mode); } lineWrapMode(): LineWrapMode { diff --git a/src/lib/QtWidgets/QProgressBar/index.ts b/src/lib/QtWidgets/QProgressBar/index.ts index 9bc40c7cf..d75c4826f 100644 --- a/src/lib/QtWidgets/QProgressBar/index.ts +++ b/src/lib/QtWidgets/QProgressBar/index.ts @@ -19,14 +19,8 @@ export class QProgressBar extends NodeWidget { super(native); this.native = native; this.nodeParent = parent; - // bind member functions - this.setValue.bind(this); - this.setMinimum.bind(this); - this.setMaximum.bind(this); - this.setOrientation.bind(this); - this.value.bind(this); } - setValue(value: number) { + setValue(value: number): void { // react:✓ this.native.setValue(value); } @@ -34,15 +28,15 @@ export class QProgressBar extends NodeWidget { // react:✓ return this.native.value(); } - setMinimum(min: number) { + setMinimum(min: number): void { // react:✓ TODO://getter this.native.setMinimum(min); } - setMaximum(max: number) { + setMaximum(max: number): void { // react:✓ TODO://getter this.native.setMaximum(max); } - setOrientation(orientation: Orientation) { + setOrientation(orientation: Orientation): void { // react:✓ TODO://getter this.native.setOrientation(orientation); } diff --git a/src/lib/QtWidgets/QPushButton/index.ts b/src/lib/QtWidgets/QPushButton/index.ts index c3df06702..9f6ff15b4 100644 --- a/src/lib/QtWidgets/QPushButton/index.ts +++ b/src/lib/QtWidgets/QPushButton/index.ts @@ -24,19 +24,16 @@ export class QPushButton extends NodeWidget { super(native); this.nodeParent = parent; this.native = native; - // bind member functions - this.setText.bind(this); - this.setFlat.bind(this); } - setText(text: string | number) { + setText(text: string | number): void { // react:✓, //TODO:getter this.native.setText(`${text}`); } - setFlat(isFlat: boolean) { + setFlat(isFlat: boolean): void { // react:✓, //TODO:getter this.native.setFlat(isFlat); } - setIcon(icon: QIcon) { + setIcon(icon: QIcon): void { // react:✓, //TODO:getter this.native.setIcon(icon.native); } diff --git a/src/lib/QtWidgets/QRadioButton/index.ts b/src/lib/QtWidgets/QRadioButton/index.ts index d9001ff71..58a6e2a36 100644 --- a/src/lib/QtWidgets/QRadioButton/index.ts +++ b/src/lib/QtWidgets/QRadioButton/index.ts @@ -21,7 +21,7 @@ export class QRadioButton extends NodeWidget { // bind member functions this.setText.bind(this); } - setText(text: string | number) { + setText(text: string | number): void { // react:✓ TODO://getter this.native.setText(`${text}`); } diff --git a/src/lib/QtWidgets/QScrollArea/index.ts b/src/lib/QtWidgets/QScrollArea/index.ts index 1a3b76b6e..ff97e3960 100644 --- a/src/lib/QtWidgets/QScrollArea/index.ts +++ b/src/lib/QtWidgets/QScrollArea/index.ts @@ -20,11 +20,8 @@ export class QScrollArea extends QAbstractScrollArea { super(native); this.native = native; this.nodeParent = parent; - // bind member functions - this.setWidget.bind(this); - this.takeWidget.bind(this); } - setWidget(widget: NodeWidget) { + setWidget(widget: NodeWidget): void { // react:✓, //TODO:getter this.contentWidget = widget; this.native.setWidget(widget.native); @@ -39,7 +36,7 @@ export class QScrollArea extends QAbstractScrollArea { } return null; } - setWidgetResizable(resizable: boolean) { + setWidgetResizable(resizable: boolean): void { this.native.setWidgetResizable(resizable); } widgetResizable(): boolean { diff --git a/src/lib/QtWidgets/QShortcut/index.ts b/src/lib/QtWidgets/QShortcut/index.ts index 0688d4661..1cdcee61e 100644 --- a/src/lib/QtWidgets/QShortcut/index.ts +++ b/src/lib/QtWidgets/QShortcut/index.ts @@ -17,16 +17,16 @@ export class QShortcut extends QObject { super(native); this.native = native; } - setEnabled(enabled: boolean) { + setEnabled(enabled: boolean): void { this.native.setEnabled(enabled); } - setAutoRepeat(on: boolean) { + setAutoRepeat(on: boolean): void { this.native.setAutoRepeat(on); } - setKey(keysequence: QKeySequence) { + setKey(keysequence: QKeySequence): void { this.native.setKey(keysequence.native); } - setContext(shortcutContext: ShortcutContext) { + setContext(shortcutContext: ShortcutContext): void { this.native.setContext(shortcutContext); } } diff --git a/src/lib/QtWidgets/QSpinBox/index.ts b/src/lib/QtWidgets/QSpinBox/index.ts index 37d4bda88..404791dc2 100644 --- a/src/lib/QtWidgets/QSpinBox/index.ts +++ b/src/lib/QtWidgets/QSpinBox/index.ts @@ -2,7 +2,6 @@ import addon from '../../utils/addon'; import { NodeWidget } from '../QWidget'; import { BaseWidgetEvents } from '../../core/EventWidget'; import { NativeElement } from '../../core/Component'; -import { QIcon } from '../../QtGui/QIcon'; export const QSpinBoxEvents = Object.freeze({ ...BaseWidgetEvents, @@ -21,22 +20,12 @@ export class QSpinBox extends NodeWidget { super(native); this.nodeParent = parent; this.native = native; - // bind member functions - this.setPrefix.bind(this); - this.setSuffix.bind(this); - this.cleanText.bind(this); - this.setSingleStep.bind(this); - this.setRange.bind(this); - this.maximum.bind(this); - this.minimum.bind(this); - this.setValue.bind(this); - this.value.bind(this); } - setPrefix(prefix: string) { + setPrefix(prefix: string): void { // react:✓ this.native.setPrefix(prefix); } - setSuffix(suffix: string) { + setSuffix(suffix: string): void { // react:✓ this.native.setSuffix(suffix); } @@ -44,11 +33,11 @@ export class QSpinBox extends NodeWidget { // react:✓ return this.native.cleanText(); } - setSingleStep(val: number) { + setSingleStep(val: number): void { // react:✓ this.native.setSingleStep(val); } - setRange(minimum: number, maximum: number) { + setRange(minimum: number, maximum: number): void { // react:✓ this.native.setRange(minimum, maximum); } @@ -60,7 +49,7 @@ export class QSpinBox extends NodeWidget { // react:✓ return this.native.minimum(); } - setValue(val: number) { + setValue(val: number): void { // react:✓ this.native.setValue(val); } diff --git a/src/lib/QtWidgets/QSystemTrayIcon/index.ts b/src/lib/QtWidgets/QSystemTrayIcon/index.ts index dd3928768..0b6c6ddca 100644 --- a/src/lib/QtWidgets/QSystemTrayIcon/index.ts +++ b/src/lib/QtWidgets/QSystemTrayIcon/index.ts @@ -22,22 +22,22 @@ export class QSystemTrayIcon extends QObject { super(native); this.native = native; } - show() { + show(): void { this.native.show(); } - hide() { + hide(): void { this.native.hide(); } - setIcon(icon: QIcon) { + setIcon(icon: QIcon): void { this.native.setIcon(icon.native); } isVisible(): boolean { return this.native.isVisible(); } - setToolTip(tooltip: string) { + setToolTip(tooltip: string): void { this.native.setToolTip(tooltip); } - setContextMenu(menu: QMenu) { + setContextMenu(menu: QMenu): void { this.contextMenu = menu; this.native.setContextMenu(this.contextMenu.native); } diff --git a/src/lib/QtWidgets/QTabWidget/index.ts b/src/lib/QtWidgets/QTabWidget/index.ts index 72a8d0a26..ff4d68c7e 100644 --- a/src/lib/QtWidgets/QTabWidget/index.ts +++ b/src/lib/QtWidgets/QTabWidget/index.ts @@ -29,16 +29,16 @@ export class QTabWidget extends NodeWidget { this.addTab.bind(this); } - addTab(page: NodeWidget, icon: QIcon, label: string) { + addTab(page: NodeWidget, icon: QIcon, label: string): void { this.nodeChildren.add(page); this.native.addTab(page.native, icon.native, label); } - setTabPosition(tabPosition: TabPosition) { + setTabPosition(tabPosition: TabPosition): void { this.native.setTabPosition(tabPosition); } - setCurrentIndex(index: number) { + setCurrentIndex(index: number): void { this.native.setCurrentIndex(index); } @@ -46,11 +46,11 @@ export class QTabWidget extends NodeWidget { return this.native.currentIndex(); } - removeTab(index: number) { + removeTab(index: number): void { this.native.removeTab(index); } - setTabsClosable(closeable: boolean) { + setTabsClosable(closeable: boolean): void { this.native.setTabsClosable(closeable); } } diff --git a/src/lib/QtWidgets/QWidget/index.ts b/src/lib/QtWidgets/QWidget/index.ts index c03b28ec6..6892fc9df 100644 --- a/src/lib/QtWidgets/QWidget/index.ts +++ b/src/lib/QtWidgets/QWidget/index.ts @@ -15,109 +15,109 @@ import { YogaWidget } from '../../core/YogaWidget'; export abstract class NodeWidget extends YogaWidget { layout?: NodeLayout; type = 'widget'; - show() { + show(): void { this.native.show(); } - hide() { + hide(): void { this.native.hide(); } isVisible(): boolean { return this.native.isVisible(); } - close() { + close(): boolean { return this.native.close(); } - async setStyleSheet(styleSheet: string) { + async setStyleSheet(styleSheet: string): Promise { const preparedSheet = await StyleSheet.create(styleSheet); await applyStyleSheet(this, preparedSheet); } styleSheet(): string { return this.native.styleSheet(); } - async setInlineStyle(style: string) { + async setInlineStyle(style: string): Promise { const preparedSheet = await prepareInlineStyleSheet(this, style); await applyStyleSheet(this, preparedSheet); } - setGeometry(x: number, y: number, w: number, h: number) { + setGeometry(x: number, y: number, w: number, h: number): void { this.native.setGeometry(x, y, w, h); } geometry(): Rect { return this.native.geometry(); } - setObjectName(objectName: string) { + setObjectName(objectName: string): void { this.native.setObjectName(objectName); } objectName(): string { return this.native.objectName(); } - setMouseTracking(isMouseTracked: boolean) { + setMouseTracking(isMouseTracked: boolean): void { this.native.setMouseTracking(isMouseTracked); } hasMouseTracking(): boolean { return this.native.hasMouseTracking(); } - setEnabled(enabled: boolean) { + setEnabled(enabled: boolean): void { this.native.setEnabled(enabled); } isEnabled(): boolean { return this.native.isEnabled(); } - setWindowOpacity(opacity: number) { + setWindowOpacity(opacity: number): void { this.native.setWindowOpacity(opacity); } - windowOpacity() { + windowOpacity(): number { return this.native.windowOpacity(); } - setWindowTitle(title: string) { + setWindowTitle(title: string): void { //TODO:getter return this.native.setWindowTitle(title); } - setWindowState(state: WindowState) { + setWindowState(state: WindowState): void { //TODO:getter return this.native.setWindowState(state); } - setCursor(cursor: CursorShape | QCursor) { + setCursor(cursor: CursorShape | QCursor): void { //TODO:getter this.native.setCursor(cursor); } - setWindowIcon(icon: QIcon) { + setWindowIcon(icon: QIcon): void { //TODO:getter this.native.setWindowIcon(icon.native); } - setMinimumSize(minw: number, minh: number) { + setMinimumSize(minw: number, minh: number): void { this.native.setMinimumSize(minw, minh); } - setMaximumSize(maxw: number, maxh: number) { + setMaximumSize(maxw: number, maxh: number): void { this.native.setMaximumSize(maxw, maxh); } - setFixedSize(width: number, height: number) { + setFixedSize(width: number, height: number): void { this.native.setFixedSize(width, height); } - resize(width: number, height: number) { + resize(width: number, height: number): void { this.native.resize(width, height); } size(): { width: number; height: number } { return this.native.size(); } - move(x: number, y: number) { + move(x: number, y: number): void { this.native.move(x, y); } pos(): { x: number; y: number } { return this.native.pos(); } - repaint() { + repaint(): void { // react:⛔️ this.native.repaint(); } - update() { + update(): void { // react:⛔️ this.native.update(); } - updateGeometry() { + updateGeometry(): void { // react:⛔️ this.native.updateGeometry(); } - setAttribute(attribute: WidgetAttribute, switchOn: boolean) { + setAttribute(attribute: WidgetAttribute, switchOn: boolean): void { // react:⛔️ return this.native.setAttribute(attribute, switchOn); } @@ -125,11 +125,11 @@ export abstract class NodeWidget extends YogaWidget { // react:⛔️ return this.native.testAttribute(attribute); } - setWindowFlag(windowType: WindowType, switchOn: boolean) { + setWindowFlag(windowType: WindowType, switchOn: boolean): void { // react:⛔️ return this.native.setWindowFlag(windowType, switchOn); } - setLayout(parentLayout: NodeLayout) { + setLayout(parentLayout: NodeLayout): void { const flexLayout = parentLayout as FlexLayout; if (flexLayout.setFlexNode) { //if flex layout set the flexnode diff --git a/src/lib/core/EventWidget/index.ts b/src/lib/core/EventWidget/index.ts index 54bcd8099..81f2afb87 100644 --- a/src/lib/core/EventWidget/index.ts +++ b/src/lib/core/EventWidget/index.ts @@ -14,12 +14,12 @@ export abstract class EventWidget extends Component { } } - addEventListener = (eventType: string, callback: (payload?: NativeEvent | any) => void) => { + addEventListener(eventType: string, callback: (payload?: NativeEvent | any) => void): void { this.native.subscribeToQtEvent(eventType); this.emitter.addListener(eventType, callback); - }; + } - removeEventListener = (eventType: string, callback?: (payload?: NativeEvent | any) => void) => { + removeEventListener(eventType: string, callback?: (payload?: NativeEvent | any) => void): void { if (callback) { this.emitter.removeListener(eventType, callback); } else { @@ -28,7 +28,7 @@ export abstract class EventWidget extends Component { if (this.emitter.listenerCount(eventType) < 1) { this.native.unSubscribeToQtEvent(eventType); } - }; + } } export const BaseWidgetEvents = Object.freeze({ diff --git a/src/lib/core/FlexLayout/index.ts b/src/lib/core/FlexLayout/index.ts index 6add7d00e..b1394c053 100644 --- a/src/lib/core/FlexLayout/index.ts +++ b/src/lib/core/FlexLayout/index.ts @@ -8,35 +8,35 @@ export class FlexLayout extends NodeLayout { native: NativeElement = new addon.FlexLayout(); protected flexNode?: FlexNode; - addWidget = (childWidget: NodeWidget, childFlexNode?: FlexNode) => { + addWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void { const childYogaNode = childFlexNode || childWidget.getFlexNode(); this.nodeChildren.add(childWidget); this.native.addWidget(childWidget.native, childYogaNode); - }; + } - insertChildBefore = ( + insertChildBefore( childWidget: NodeWidget, beforeChildWidget: NodeWidget, childFlexNode?: FlexNode, beforeChildFlexNode?: FlexNode, - ) => { + ): void { const childYogaNode = childFlexNode || childWidget.getFlexNode(); const beforeChildYogaNode = beforeChildFlexNode || beforeChildWidget.getFlexNode(); this.nodeChildren.add(childWidget); // No orderer required yet, so just inserting at the end. this.native.insertChildBefore(childWidget.native, beforeChildYogaNode, childYogaNode); - }; + } - removeWidget = (childWidget: NodeWidget, childFlexNode?: FlexNode) => { + removeWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void { if (!this.nodeChildren.has(childWidget)) { return; } const childYogaNode = childFlexNode || childWidget.getFlexNode(); this.nodeChildren.delete(childWidget); this.native.removeWidget(childWidget.native, childYogaNode); - }; + } - setFlexNode = (flexNode: FlexNode) => { + setFlexNode(flexNode: FlexNode): void { this.flexNode = flexNode; this.native.setFlexNode(flexNode); - }; + } } diff --git a/src/lib/core/Style/StyleSheet.ts b/src/lib/core/Style/StyleSheet.ts index e7c27ac80..24112e7af 100644 --- a/src/lib/core/Style/StyleSheet.ts +++ b/src/lib/core/Style/StyleSheet.ts @@ -14,7 +14,7 @@ export class StyleSheet { }; } -export const prepareInlineStyleSheet = async (widget: NodeWidget, rawStyle: string) => { +export async function prepareInlineStyleSheet(widget: NodeWidget, rawStyle: string): Promise { const inlineStyle = await StyleSheet.create(rawStyle); // Make sure to not calculate ObjectName in the same pass of event loop as other props (incase of react) since the order will matter in that case // So doing it in multiple passes of event loop allows objectName to be set before using it. The above await solves it. @@ -28,9 +28,9 @@ export const prepareInlineStyleSheet = async (widget: NodeWidget, rawStyle: stri ${inlineStyle} } `; -}; +} -export const applyStyleSheet = async (widget: NodeWidget, styleSheet: string) => { +export async function applyStyleSheet(widget: NodeWidget, styleSheet: string): Promise { widget.native.setStyleSheet(styleSheet); widget.layout ? widget.layout.update() : widget.update(); -}; +} diff --git a/src/lib/core/bootstrap.ts b/src/lib/core/bootstrap.ts index c43321494..576b49fd7 100644 --- a/src/lib/core/bootstrap.ts +++ b/src/lib/core/bootstrap.ts @@ -9,21 +9,23 @@ This is required inorder to make the timers work nicely due to merger of event loops */ -const noop = () => {}; +function noop(): void { + return; +} const wrapWithActivateUvLoop = (func: Function) => { - return (...args: any[]) => { + return (...args: any[]): any => { const activateUvLoop = (process as any).activateUvLoop || noop; activateUvLoop(); return func(...args); }; }; -const main = () => { +function main(): void { process.nextTick = wrapWithActivateUvLoop(process.nextTick); global.setImmediate = wrapWithActivateUvLoop(global.setImmediate); global.setTimeout = wrapWithActivateUvLoop(global.setTimeout); global.setInterval = wrapWithActivateUvLoop(global.setInterval); -}; +} main(); diff --git a/src/lib/utils/helpers.ts b/src/lib/utils/helpers.ts index 76611185d..dc2943aef 100644 --- a/src/lib/utils/helpers.ts +++ b/src/lib/utils/helpers.ts @@ -1,6 +1,6 @@ import { NativeElement } from '../core/Component'; -export const checkIfNativeElement = (arg: any) => { +export function checkIfNativeElement(arg: any): boolean { const nativeArg = arg as NativeElement; return typeof nativeArg === 'object' && nativeArg.type === 'native'; -}; +}