From e77ee16c6ee1f7f256924085eaa8cc1e8b7e8f6c Mon Sep 17 00:00:00 2001 From: Atul R Date: Sat, 15 Jun 2019 23:59:42 +0200 Subject: [PATCH] Single api for events and signals on JS side --- demo.ts | 10 +- examples/calculator/index.ts | 4 +- src/lib/QtWidgets/QCheckBox/index.ts | 5 + src/lib/QtWidgets/QLabel/index.ts | 4 + src/lib/QtWidgets/QLineEdit/index.ts | 4 + src/lib/QtWidgets/QMainWindow/index.ts | 5 + src/lib/QtWidgets/QProgressBar/index.ts | 4 + src/lib/QtWidgets/QPushButton/index.ts | 14 ++- src/lib/QtWidgets/QRadioButton/index.ts | 4 + src/lib/core/EventWidget/index.ts | 148 ++++++++++++++++++++++++ 10 files changed, 189 insertions(+), 13 deletions(-) diff --git a/demo.ts b/demo.ts index 2c1925a22..337e5daab 100644 --- a/demo.ts +++ b/demo.ts @@ -4,7 +4,7 @@ import { QGridLayout } from "./src/lib/QtWidgets/QGridLayout"; import { QLabel } from "./src/lib/QtWidgets/QLabel"; import { QPushButton, - QPushButtonSignal + QPushButtonEvents } from "./src/lib/QtWidgets/QPushButton"; import { QCheckBox } from "./src/lib/QtWidgets/QCheckBox"; import { QProgressBar } from "./src/lib/QtWidgets/QProgressBar"; @@ -25,16 +25,16 @@ const testGridLayout = () => { label.setStyleSheet("background-color:blue; color:white;"); const button1 = new QPushButton(); - button1.addEventListener(QPushButtonSignal.clicked, isChecked => { + button1.addEventListener(QPushButtonEvents.clicked, isChecked => { console.log("clicked", isChecked); }); - button1.addEventListener(QPushButtonSignal.pressed, (...args) => { + button1.addEventListener(QPushButtonEvents.pressed, (...args) => { console.log("pressed", ...args); }); - button1.addEventListener(QPushButtonSignal.released, (...args) => { + button1.addEventListener(QPushButtonEvents.released, (...args) => { console.log("released", ...args); }); - button1.addEventListener(QPushButtonSignal.toggled, isToggled => { + button1.addEventListener(QPushButtonEvents.toggled, isToggled => { console.log("toggled", isToggled); }); diff --git a/examples/calculator/index.ts b/examples/calculator/index.ts index 2ad3a0e08..7571da4b9 100644 --- a/examples/calculator/index.ts +++ b/examples/calculator/index.ts @@ -3,7 +3,7 @@ import { QWidget } from "../../src/lib/QtGui/QWidget"; import { FlexLayout } from "../../src/lib/core/FlexLayout"; import { QPushButton, - QPushButtonSignal + QPushButtonEvents } from "../../src/lib/QtWidgets/QPushButton"; import { QLabel } from "../../src/lib/QtWidgets/QLabel"; @@ -20,7 +20,7 @@ const getButton = ( const button = new QPushButton(); button.setText(label); button.setObjectName(`btn${value}`); - button.addEventListener(QPushButtonSignal.clicked, () => { + button.addEventListener(QPushButtonEvents.clicked, () => { onBtnClick(value, type); }); return { diff --git a/src/lib/QtWidgets/QCheckBox/index.ts b/src/lib/QtWidgets/QCheckBox/index.ts index a7df9acb6..ccbd05774 100644 --- a/src/lib/QtWidgets/QCheckBox/index.ts +++ b/src/lib/QtWidgets/QCheckBox/index.ts @@ -1,5 +1,10 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; + +export const QCheckBoxEvents = Object.freeze({ + ...BaseWidgetEvents +}); export class QCheckBox extends NodeWidget { native: any; constructor(parent?: NodeWidget) { diff --git a/src/lib/QtWidgets/QLabel/index.ts b/src/lib/QtWidgets/QLabel/index.ts index 18317821d..4dff662d1 100644 --- a/src/lib/QtWidgets/QLabel/index.ts +++ b/src/lib/QtWidgets/QLabel/index.ts @@ -1,6 +1,10 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; +export const QLabelEvents = Object.freeze({ + ...BaseWidgetEvents +}); export class QLabel extends NodeWidget { native: any; constructor(parent?: NodeWidget) { diff --git a/src/lib/QtWidgets/QLineEdit/index.ts b/src/lib/QtWidgets/QLineEdit/index.ts index 86c8fd745..911983100 100644 --- a/src/lib/QtWidgets/QLineEdit/index.ts +++ b/src/lib/QtWidgets/QLineEdit/index.ts @@ -1,6 +1,10 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; +export const QLineEditEvents = Object.freeze({ + ...BaseWidgetEvents +}); export class QLineEdit extends NodeWidget { native: any; constructor(parent?: NodeWidget) { diff --git a/src/lib/QtWidgets/QMainWindow/index.ts b/src/lib/QtWidgets/QMainWindow/index.ts index 0c9b975b6..ae654d4fd 100644 --- a/src/lib/QtWidgets/QMainWindow/index.ts +++ b/src/lib/QtWidgets/QMainWindow/index.ts @@ -1,6 +1,11 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; import { FlexNode } from "../../core/FlexLayout/FlexNode"; +import { BaseWidgetEvents } from "../../core/EventWidget"; + +export const QMainWindowEvents = Object.freeze({ + ...BaseWidgetEvents +}); export class QMainWindow extends NodeWidget { native: any; protected centralWidget?: NodeWidget; diff --git a/src/lib/QtWidgets/QProgressBar/index.ts b/src/lib/QtWidgets/QProgressBar/index.ts index b5ba2b58c..7e3ad5663 100644 --- a/src/lib/QtWidgets/QProgressBar/index.ts +++ b/src/lib/QtWidgets/QProgressBar/index.ts @@ -1,6 +1,10 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; +export const QProgressBarEvents = Object.freeze({ + ...BaseWidgetEvents +}); export class QProgressBar extends NodeWidget { native: any; constructor(parent?: NodeWidget) { diff --git a/src/lib/QtWidgets/QPushButton/index.ts b/src/lib/QtWidgets/QPushButton/index.ts index 1c371b7f0..c5e527a67 100644 --- a/src/lib/QtWidgets/QPushButton/index.ts +++ b/src/lib/QtWidgets/QPushButton/index.ts @@ -1,12 +1,14 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; -export enum QPushButtonSignal { - clicked = "clicked", - pressed = "pressed", - released = "released", - toggled = "toggled" -} +export const QPushButtonEvents = Object.freeze({ + ...BaseWidgetEvents, + clicked: "clicked", + pressed: "pressed", + released: "released", + toggled: "toggled" +}); export class QPushButton extends NodeWidget { native: any; diff --git a/src/lib/QtWidgets/QRadioButton/index.ts b/src/lib/QtWidgets/QRadioButton/index.ts index 291268491..d73847b29 100644 --- a/src/lib/QtWidgets/QRadioButton/index.ts +++ b/src/lib/QtWidgets/QRadioButton/index.ts @@ -1,6 +1,10 @@ import addon from "../../core/addon"; import { NodeWidget } from "../../QtGui/QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; +export const QRadioButtonEvents = Object.freeze({ + ...BaseWidgetEvents +}); export class QRadioButton extends NodeWidget { native: any; constructor(parent?: NodeWidget) { diff --git a/src/lib/core/EventWidget/index.ts b/src/lib/core/EventWidget/index.ts index 685b03364..2d583ef85 100644 --- a/src/lib/core/EventWidget/index.ts +++ b/src/lib/core/EventWidget/index.ts @@ -18,3 +18,151 @@ export abstract class EventWidget extends YogaWidget { this.emitter.on(eventType, callback); }; } + +export const BaseWidgetEvents = Object.freeze({ + None: "None", + ActionAdded: "ActionAdded", + ActionChanged: "ActionChanged", + ActionRemoved: "ActionRemoved", + ActivationChange: "ActivationChange", + ApplicationActivate: "ApplicationActivate", + ApplicationActivated: "ApplicationActivated", + ApplicationDeactivate: "ApplicationDeactivate", + ApplicationFontChange: "ApplicationFontChange", + ApplicationLayoutDirectionChange: "ApplicationLayoutDirectionChange", + ApplicationPaletteChange: "ApplicationPaletteChange", + ApplicationStateChange: "ApplicationStateChange", + ApplicationWindowIconChange: "ApplicationWindowIconChange", + ChildAdded: "ChildAdded", + ChildPolished: "ChildPolished", + ChildRemoved: "ChildRemoved", + Clipboard: "Clipboard", + Close: "Close", + CloseSoftwareInputPanel: "CloseSoftwareInputPanel", + ContentsRectChange: "ContentsRectChange", + ContextMenu: "ContextMenu", + CursorChange: "CursorChange", + DeferredDelete: "DeferredDelete", + DragEnter: "DragEnter", + DragLeave: "DragLeave", + DragMove: "DragMove", + Drop: "Drop", + DynamicPropertyChange: "DynamicPropertyChange", + EnabledChange: "EnabledChange", + Enter: "Enter", + EnterWhatsThisMode: "EnterWhatsThisMode", + Expose: "Expose", + FileOpen: "FileOpen", + FocusIn: "FocusIn", + FocusOut: "FocusOut", + FocusAboutToChange: "FocusAboutToChange", + FontChange: "FontChange", + Gesture: "Gesture", + GestureOverride: "GestureOverride", + GrabKeyboard: "GrabKeyboard", + GrabMouse: "GrabMouse", + GraphicsSceneContextMenu: "GraphicsSceneContextMenu", + GraphicsSceneDragEnter: "GraphicsSceneDragEnter", + GraphicsSceneDragLeave: "GraphicsSceneDragLeave", + GraphicsSceneDragMove: "GraphicsSceneDragMove", + GraphicsSceneDrop: "GraphicsSceneDrop", + GraphicsSceneHelp: "GraphicsSceneHelp", + GraphicsSceneHoverEnter: "GraphicsSceneHoverEnter", + GraphicsSceneHoverLeave: "GraphicsSceneHoverLeave", + GraphicsSceneHoverMove: "GraphicsSceneHoverMove", + GraphicsSceneMouseDoubleClick: "GraphicsSceneMouseDoubleClick", + GraphicsSceneMouseMove: "GraphicsSceneMouseMove", + GraphicsSceneMousePress: "GraphicsSceneMousePress", + GraphicsSceneMouseRelease: "GraphicsSceneMouseRelease", + GraphicsSceneMove: "GraphicsSceneMove", + GraphicsSceneResize: "GraphicsSceneResize", + GraphicsSceneWheel: "GraphicsSceneWheel", + Hide: "Hide", + HideToParent: "HideToParent", + HoverEnter: "HoverEnter", + HoverLeave: "HoverLeave", + HoverMove: "HoverMove", + IconDrag: "IconDrag", + IconTextChange: "IconTextChange", + InputMethod: "InputMethod", + InputMethodQuery: "InputMethodQuery", + KeyboardLayoutChange: "KeyboardLayoutChange", + KeyPress: "KeyPress", + KeyRelease: "KeyRelease", + LanguageChange: "LanguageChange", + LayoutDirectionChange: "LayoutDirectionChange", + LayoutRequest: "LayoutRequest", + Leave: "Leave", + LeaveWhatsThisMode: "LeaveWhatsThisMode", + LocaleChange: "LocaleChange", + NonClientAreaMouseButtonDblClick: "NonClientAreaMouseButtonDblClick", + NonClientAreaMouseButtonPress: "NonClientAreaMouseButtonPress", + NonClientAreaMouseButtonRelease: "NonClientAreaMouseButtonRelease", + NonClientAreaMouseMove: "NonClientAreaMouseMove", + MacSizeChange: "MacSizeChange", + MetaCall: "MetaCall", + ModifiedChange: "ModifiedChange", + MouseButtonDblClick: "MouseButtonDblClick", + MouseButtonPress: "MouseButtonPress", + MouseButtonRelease: "MouseButtonRelease", + MouseMove: "MouseMove", + MouseTrackingChange: "MouseTrackingChange", + Move: "Move", + NativeGesture: "NativeGesture", + OrientationChange: "OrientationChange", + Paint: "Paint", + PaletteChange: "PaletteChange", + ParentAboutToChange: "ParentAboutToChange", + ParentChange: "ParentChange", + PlatformPanel: "PlatformPanel", + PlatformSurface: "PlatformSurface", + Polish: "Polish", + PolishRequest: "PolishRequest", + QueryWhatsThis: "QueryWhatsThis", + ReadOnlyChange: "ReadOnlyChange", + RequestSoftwareInputPanel: "RequestSoftwareInputPanel", + Resize: "Resize", + ScrollPrepare: "ScrollPrepare", + Scroll: "Scroll", + Shortcut: "Shortcut", + ShortcutOverride: "ShortcutOverride", + Show: "Show", + ShowToParent: "ShowToParent", + SockAct: "SockAct", + StateMachineSignal: "StateMachineSignal", + StateMachineWrapped: "StateMachineWrapped", + StatusTip: "StatusTip", + StyleChange: "StyleChange", + TabletMove: "TabletMove", + TabletPress: "TabletPress", + TabletRelease: "TabletRelease", + TabletEnterProximity: "TabletEnterProximity", + TabletLeaveProximity: "TabletLeaveProximity", + TabletTrackingChange: "TabletTrackingChange", + ThreadChange: "ThreadChange", + Timer: "Timer", + ToolBarChange: "ToolBarChange", + ToolTip: "ToolTip", + ToolTipChange: "ToolTipChange", + TouchBegin: "TouchBegin", + TouchCancel: "TouchCancel", + TouchEnd: "TouchEnd", + TouchUpdate: "TouchUpdate", + UngrabKeyboard: "UngrabKeyboard", + UngrabMouse: "UngrabMouse", + UpdateLater: "UpdateLater", + UpdateRequest: "UpdateRequest", + WhatsThis: "WhatsThis", + WhatsThisClicked: "WhatsThisClicked", + Wheel: "Wheel", + WinEventAct: "WinEventAct", + WindowActivate: "WindowActivate", + WindowBlocked: "WindowBlocked", + WindowDeactivate: "WindowDeactivate", + WindowIconChange: "WindowIconChange", + WindowStateChange: "WindowStateChange", + WindowTitleChange: "WindowTitleChange", + WindowUnblocked: "WindowUnblocked", + WinIdChange: "WinIdChange", + ZOrderChange: "ZOrderChange" +});