diff --git a/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h b/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h index 982946699..59bb21345 100644 --- a/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtCore/QRect/qrect_wrap.h b/src/cpp/include/nodegui/QtCore/QRect/qrect_wrap.h index faa6951fd..9ec4bd9f0 100644 --- a/src/cpp/include/nodegui/QtCore/QRect/qrect_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QRect/qrect_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h b/src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h index e69927d62..0b5cf9e7c 100644 --- a/src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtCore/QUrl/qurl_wrap.h b/src/cpp/include/nodegui/QtCore/QUrl/qurl_wrap.h index b57f6b5a0..65d1c3b7f 100644 --- a/src/cpp/include/nodegui/QtCore/QUrl/qurl_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QUrl/qurl_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h b/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h index 06c28666e..5d9837c36 100644 --- a/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h index 3ee7f86be..b10e5544a 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h index 83fc97ddc..3823d4ed1 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QFontDatabase/qfontdatabase_wrap.h b/src/cpp/include/nodegui/QtGui/QFontDatabase/qfontdatabase_wrap.h index 02be27f61..0be0e4858 100644 --- a/src/cpp/include/nodegui/QtGui/QFontDatabase/qfontdatabase_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QFontDatabase/qfontdatabase_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h b/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h index 5d17e946f..58732d0f2 100644 --- a/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h b/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h index 9dcf08eb4..3ca538ff3 100644 --- a/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QMovie/qmovie_wrap.h b/src/cpp/include/nodegui/QtGui/QMovie/qmovie_wrap.h index df52cf949..95d0ec453 100644 --- a/src/cpp/include/nodegui/QtGui/QMovie/qmovie_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QMovie/qmovie_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h b/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h index ea38c9381..57a0561fa 100644 --- a/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h index 7d0394fad..67bd663f2 100644 --- a/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h index e98acdeaa..318f58a0a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h index 8bb1da1a1..56b09f098 100644 --- a/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QDial/ndial.hpp b/src/cpp/include/nodegui/QtWidgets/QDial/ndial.hpp index 9cb4c5f78..e1662b514 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDial/ndial.hpp +++ b/src/cpp/include/nodegui/QtWidgets/QDial/ndial.hpp @@ -12,20 +12,24 @@ class NDial : public QDial, public NodeWidget { void connectWidgetSignalsToEventEmitter() { // Qt Connects: Implement all signal connects here - QObject::connect(this, &QDial::valueChanged, [=]() { + QObject::connect(this, &QDial::valueChanged, [=](int value) { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); - this->emitOnNode.Call({Napi::String::New(env, "valueChanged")}); + this->emitOnNode.Call({Napi::String::New(env, "valueChanged"), + Napi::Number::New(env, value)}); }); - QObject::connect(this, &QDial::rangeChanged, [=]() { + QObject::connect(this, &QDial::rangeChanged, [=](int min, int max) { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); - this->emitOnNode.Call({Napi::String::New(env, "rangeChanged")}); + this->emitOnNode.Call({Napi::String::New(env, "rangeChanged"), + Napi::Number::New(env, min), + Napi::Number::New(env, max)}); }); - QObject::connect(this, &QDial::sliderMoved, [=]() { + QObject::connect(this, &QDial::sliderMoved, [=](int value) { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); - this->emitOnNode.Call({Napi::String::New(env, "sliderMoved")}); + this->emitOnNode.Call({Napi::String::New(env, "sliderMoved"), + Napi::Number::New(env, value)}); }); QObject::connect(this, &QDial::sliderPressed, [=]() { Napi::Env env = this->emitOnNode.Env(); diff --git a/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h index dcb549c11..53b3e066f 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h index cc7e51597..2d939c94b 100644 --- a/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h index ed2cea870..928e7b683 100644 --- a/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h index 476dabd9e..d12126c14 100644 --- a/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h index a273257db..e2b8a9de7 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h index 8bc2e32c5..8350ee1f4 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h index 9694bbdbe..89383fbb5 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h index 29beed394..0e53fcb6a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h index a7d56d655..674b272b0 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QPainter/qpainter_wrap.h b/src/cpp/include/nodegui/QtWidgets/QPainter/qpainter_wrap.h index 36eb707aa..c049e6f96 100644 --- a/src/cpp/include/nodegui/QtWidgets/QPainter/qpainter_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QPainter/qpainter_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/nplaintextedit.hpp b/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/nplaintextedit.hpp index ac515fecf..24834e077 100644 --- a/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/nplaintextedit.hpp +++ b/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/nplaintextedit.hpp @@ -37,11 +37,11 @@ class NPlainTextEdit : public QPlainTextEdit, public NodeWidget { this->emitOnNode.Call({Napi::String::New(env, "cursorPositionChanged")}); }); QObject::connect( - this, &QPlainTextEdit::modificationChanged, [=](bool charged) { + this, &QPlainTextEdit::modificationChanged, [=](bool changed) { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); this->emitOnNode.Call({Napi::String::New(env, "modificationChanged"), - Napi::Value::From(env, charged)}); + Napi::Value::From(env, changed)}); }); QObject::connect(this, &QPlainTextEdit::redoAvailable, [=](bool available) { Napi::Env env = this->emitOnNode.Env(); diff --git a/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h index 0d3545892..ec1588372 100644 --- a/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h index 904210426..497d4ce7c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h b/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h index f5898b008..55f8636e3 100644 --- a/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h b/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h index c0fb38d48..88281a3d0 100644 --- a/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h b/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h index 396d9f966..25079450f 100644 --- a/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h index 16e437e9a..ff4af03f2 100644 --- a/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h index 0fd915047..6eb28d17c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h index 3bd840ba9..755291e72 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h b/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h index 3a861bea1..0c79ece4e 100644 --- a/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h index 5d13812a3..cc5bab715 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QTreeWidgetItem/qtreewidgetitem_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTreeWidgetItem/qtreewidgetitem_wrap.h index 9f3181d1f..1dbed6b1a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTreeWidgetItem/qtreewidgetitem_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTreeWidgetItem/qtreewidgetitem_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h index adb238ef6..9bfcb110b 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/cpp/include/nodegui/core/FlexLayout/flexlayout_wrap.h b/src/cpp/include/nodegui/core/FlexLayout/flexlayout_wrap.h index 630799cc5..19626485f 100644 --- a/src/cpp/include/nodegui/core/FlexLayout/flexlayout_wrap.h +++ b/src/cpp/include/nodegui/core/FlexLayout/flexlayout_wrap.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include diff --git a/src/demo.ts b/src/demo.ts index 402ee642f..7974eb37b 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -1,24 +1,87 @@ -import { Direction, QMainWindow, QBoxLayout, QWidget, QLabel } from './index'; +import { + FlexLayout, + PenStyle, + WidgetEventTypes, + QColor, + QMainWindow, + QPainter, + QPoint, + QWidget, + RenderHint, +} from './index'; const win = new QMainWindow(); const center = new QWidget(); -const box = new QBoxLayout(Direction.TopToBottom); -center.setLayout(box); +const layout = new FlexLayout(); +const hourHand = [new QPoint(7, 8), new QPoint(-7, 8), new QPoint(0, -40)]; +const minuteHand = [new QPoint(7, 8), new QPoint(-7, 8), new QPoint(0, -70)]; +const secondHand = [new QPoint(4, 8), new QPoint(-4, 8), new QPoint(0, -70)]; +const hourColor = new QColor(127, 0, 127); +const minuteColor = new QColor(0, 127, 127, 191); +const secondColor = new QColor(0, 0, 0); -[1, 2, 3, 4].forEach(num => { - const label = new QLabel(); - label.setText(`Hello Label ${num}`); - const color = `#${(2 * num).toString().repeat(6)}`; - label.setInlineStyle(`border: 2px solid ${color}`); - box.addWidget(label, num); - return label; +center.setLayout(layout); +win.setWindowTitle('Analog Clock'); + +const side = Math.min(win.geometry().width(), win.geometry().height()); + +function repaint(): void { + win.repaint(); + setTimeout(repaint, 1000); +} + +setTimeout(repaint, 1000); +win.addEventListener(WidgetEventTypes.Paint, () => { + const time = new Date(); + + const painter = new QPainter(win); + painter.setRenderHint(RenderHint.Antialiasing); + painter.translate(win.geometry().width() / 2, win.geometry().height() / 2); + painter.scale(side / 200.0, side / 200.0); + + painter.setPen(PenStyle.NoPen); + painter.setBrush(hourColor); + + painter.save(); + painter.rotate(30.0 * (time.getHours() + time.getMinutes() / 60.0)); + painter.drawConvexPolygon(hourHand); + painter.restore(); + + painter.setPen(hourColor); + + for (let i = 0; i < 12; ++i) { + painter.drawLine(88, 0, 96, 0); + painter.rotate(30.0); + } + + painter.setPen(PenStyle.NoPen); + painter.setBrush(minuteColor); + + painter.save(); + painter.rotate(6.0 * (time.getMinutes() + time.getSeconds() / 60.0)); + painter.drawConvexPolygon(minuteHand); + painter.restore(); + + painter.setBrush(secondColor); + painter.setPen(PenStyle.NoPen); + + painter.save(); + painter.rotate(360 * (time.getSeconds() / 60.0)); + painter.drawConvexPolygon(secondHand); + painter.restore(); + + painter.setPen(minuteColor); + for (let j = 0; j < 60; ++j) { + if (j % 5 != 0) { + painter.drawLine(92, 0, 96, 0); + } + painter.rotate(6.0); + } + painter.end(); }); -const label = new QLabel(); -label.setText('Inserted label'); -box.insertWidget(2, label, 5); + win.setCentralWidget(center); -win.resize(200, 400); -win.setWindowTitle('box stretch'); +win.resize(400, 400); win.show(); (global as any).win = win; diff --git a/src/index.ts b/src/index.ts index cfe8c2543..0d369a557 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ export { QApplication } from './lib/QtGui/QApplication'; export { QKeySequence } from './lib/QtGui/QKeySequence'; export { QPixmap, ImageFormats } from './lib/QtGui/QPixmap'; export { QIcon, QIconMode, QIconState } from './lib/QtGui/QIcon'; -export { QMovie, CacheMode, MovieState, QMovieEvents } from './lib/QtGui/QMovie'; +export { QMovie, CacheMode, MovieState } from './lib/QtGui/QMovie'; export { QCursor } from './lib/QtGui/QCursor'; export { QTextOptionWrapMode } from './lib/QtGui/QTextOption'; export { QClipboard, QClipboardMode } from './lib/QtGui/QClipboard'; @@ -16,7 +16,7 @@ export { QFontDatabase, SystemFont, WritingSystem } from './lib/QtGui/QFontDatab // Events: Maybe a separate module ? export { QKeyEvent } from './lib/QtGui/QEvent/QKeyEvent'; export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent'; -export { NativeEvent, BaseWidgetEvents } from './lib/core/EventWidget'; +export { WidgetEventTypes } from './lib/core/EventWidget'; // Abstract: export { NodeWidget } from './lib/QtWidgets/QWidget'; export { NodeLayout } from './lib/QtWidgets/QLayout'; @@ -24,39 +24,35 @@ export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea'; export { QAbstractSlider } from './lib/QtWidgets/QAbstractSlider'; export { QAbstractButton } from './lib/QtWidgets/QAbstractButton'; // Widgets: -export { QWidget, QWidgetEvents } from './lib/QtWidgets/QWidget'; -export { QCheckBox, QCheckBoxEvents } from './lib/QtWidgets/QCheckBox'; -export { QLabel, QLabelEvents } from './lib/QtWidgets/QLabel'; -export { QDial, QDialEvents } from './lib/QtWidgets/QDial'; -export { QFileDialog, QFileDialogEvents } from './lib/QtWidgets/QFileDialog'; -export { QLineEdit, QLineEditEvents, EchoMode } from './lib/QtWidgets/QLineEdit'; -export { QMainWindow, QMainWindowEvents } from './lib/QtWidgets/QMainWindow'; -export { QProgressBar, QProgressBarEvents } from './lib/QtWidgets/QProgressBar'; -export { QComboBox, QComboBoxEvents, InsertPolicy } from './lib/QtWidgets/QComboBox'; -export { QPushButton, QPushButtonEvents } from './lib/QtWidgets/QPushButton'; -export { QToolButton, QToolButtonEvents, ToolButtonPopupMode } from './lib/QtWidgets/QToolButton'; -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 { QTableWidget, QTableWidgetEvents } from './lib/QtWidgets/QTableWidget'; +export { QWidget } from './lib/QtWidgets/QWidget'; +export { QCheckBox } from './lib/QtWidgets/QCheckBox'; +export { QLabel } from './lib/QtWidgets/QLabel'; +export { QDial } from './lib/QtWidgets/QDial'; +export { QFileDialog } from './lib/QtWidgets/QFileDialog'; +export { QLineEdit, EchoMode } from './lib/QtWidgets/QLineEdit'; +export { QMainWindow } from './lib/QtWidgets/QMainWindow'; +export { QProgressBar } from './lib/QtWidgets/QProgressBar'; +export { QComboBox, InsertPolicy } from './lib/QtWidgets/QComboBox'; +export { QPushButton } from './lib/QtWidgets/QPushButton'; +export { QToolButton, ToolButtonPopupMode } from './lib/QtWidgets/QToolButton'; +export { QSpinBox } from './lib/QtWidgets/QSpinBox'; +export { QRadioButton } from './lib/QtWidgets/QRadioButton'; +export { QStackedWidget } from './lib/QtWidgets/QStackedWidget'; +export { QTabWidget } from './lib/QtWidgets/QTabWidget'; +export { QTableWidget } from './lib/QtWidgets/QTableWidget'; export { QTableWidgetItem } from './lib/QtWidgets/QTableWidgetItem'; -export { QMenu, QMenuEvents } from './lib/QtWidgets/QMenu'; -export { QMenuBar, QMenuBarEvents } from './lib/QtWidgets/QMenuBar'; -export { QPlainTextEdit, QPlainTextEditEvents, LineWrapMode } from './lib/QtWidgets/QPlainTextEdit'; -export { QScrollArea, QScrollAreaEvents } from './lib/QtWidgets/QScrollArea'; -export { QTreeWidget, QTreeWidgetEvents } from './lib/QtWidgets/QTreeWidget'; +export { QMenu } from './lib/QtWidgets/QMenu'; +export { QMenuBar } from './lib/QtWidgets/QMenuBar'; +export { QPlainTextEdit, LineWrapMode } from './lib/QtWidgets/QPlainTextEdit'; +export { QScrollArea } from './lib/QtWidgets/QScrollArea'; +export { QTreeWidget } from './lib/QtWidgets/QTreeWidget'; export { QTreeWidgetItem } from './lib/QtWidgets/QTreeWidgetItem'; export { QPainter, RenderHint } from './lib/QtWidgets/QPainter'; -export { - QSystemTrayIcon, - QSystemTrayIconEvents, - QSystemTrayIconActivationReason, -} from './lib/QtWidgets/QSystemTrayIcon'; -export { QAction, QActionEvents } from './lib/QtWidgets/QAction'; -export { QShortcut, QShortcutEvents } from './lib/QtWidgets/QShortcut'; -export { QGroupBox, QGroupBoxEvents } from './lib/QtWidgets/QGroupBox'; +export { QSystemTrayIcon, QSystemTrayIconActivationReason } from './lib/QtWidgets/QSystemTrayIcon'; +export { QAction } from './lib/QtWidgets/QAction'; +export { QShortcut } from './lib/QtWidgets/QShortcut'; +export { QGroupBox } from './lib/QtWidgets/QGroupBox'; // Core export { QObject, NodeObject } from './lib/QtCore/QObject'; export { QVariant } from './lib/QtCore/QVariant'; diff --git a/src/lib/QtCore/QColor.ts b/src/lib/QtCore/QColor.ts index b8d362afc..36fae191c 100644 --- a/src/lib/QtCore/QColor.ts +++ b/src/lib/QtCore/QColor.ts @@ -2,9 +2,15 @@ import { Component, NativeElement } from '../core/Component'; import addon from '../utils/addon'; import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; +import { GlobalColor } from '../QtEnums'; export class QColor extends Component { native: NativeElement; + constructor(); + constructor(nativeElement: NativeElement); + constructor(colorString: string); + constructor(color: GlobalColor); + constructor(r?: number, g?: number, b?: number, a?: number); constructor(arg?: NativeElement | number | string, g = 0, b = 0, a = 255) { super(); if (checkIfNativeElement(arg)) { diff --git a/src/lib/QtCore/QObject.ts b/src/lib/QtCore/QObject.ts index 3e8f91dd8..fc8c2adb8 100644 --- a/src/lib/QtCore/QObject.ts +++ b/src/lib/QtCore/QObject.ts @@ -4,7 +4,7 @@ import { checkIfNativeElement } from '../utils/helpers'; import addon from '../utils/addon'; import { QVariant } from './QVariant'; -export abstract class NodeObject extends EventWidget { +export abstract class NodeObject extends EventWidget { inherits(className: string): boolean { return this.native.inherits(className); } @@ -24,15 +24,18 @@ export abstract class NodeObject extends EventWidget { } } -export class QObject extends NodeObject { +export class QObject extends NodeObject { native: NativeElement; - constructor(arg?: NodeObject | NativeElement) { + constructor(); + constructor(nativeElement: NativeElement); + constructor(parent: NodeObject); + constructor(arg?: NodeObject | NativeElement) { let native; let parent; if (checkIfNativeElement(arg)) { native = arg as NativeElement; - } else if (arg as NodeObject) { - parent = arg as NodeObject; + } else if (arg as NodeObject) { + parent = arg as NodeObject; native = new addon.QObject(parent.native); } else { native = new addon.QObject(); @@ -42,3 +45,5 @@ export class QObject extends NodeObject { this.native = native; } } + +type QObjectSignals = {}; diff --git a/src/lib/QtCore/QPoint.ts b/src/lib/QtCore/QPoint.ts index 647e2e3b5..cafb4328a 100644 --- a/src/lib/QtCore/QPoint.ts +++ b/src/lib/QtCore/QPoint.ts @@ -4,6 +4,9 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; export class QPoint extends Component { native: NativeElement; + constructor(); + constructor(nativeElement: NativeElement); + constructor(x?: number, y?: number); constructor(arg?: NativeElement | number, y = 0) { super(); if (checkIfNativeElement(arg)) { diff --git a/src/lib/QtCore/QRect.ts b/src/lib/QtCore/QRect.ts index 5ad616d4f..49de66ca1 100644 --- a/src/lib/QtCore/QRect.ts +++ b/src/lib/QtCore/QRect.ts @@ -5,6 +5,9 @@ import { QVariant } from './QVariant'; export class QRect extends Component { native: NativeElement; + constructor(); + constructor(nativeElement: NativeElement); + constructor(x?: number, y?: number, width?: number, height?: number); constructor(arg?: NativeElement | number, y = 0, width = 0, height = 0) { super(); const count = arguments.length; diff --git a/src/lib/QtCore/QSize.ts b/src/lib/QtCore/QSize.ts index 8e780353d..bcbf36b6a 100644 --- a/src/lib/QtCore/QSize.ts +++ b/src/lib/QtCore/QSize.ts @@ -3,11 +3,12 @@ import addon from '../utils/addon'; import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; -type argument = number | NativeElement; - export class QSize extends Component { native: NativeElement; - constructor(arg?: argument, height?: number) { + constructor(); + constructor(nativeElement: NativeElement); + constructor(width?: number, height?: number); + constructor(arg?: number | NativeElement, height?: number) { super(); if (!arg) { this.native = new addon.QSize(); diff --git a/src/lib/QtCore/QUrl.ts b/src/lib/QtCore/QUrl.ts index 831edc8ab..e12ab5785 100644 --- a/src/lib/QtCore/QUrl.ts +++ b/src/lib/QtCore/QUrl.ts @@ -9,11 +9,12 @@ export enum ParsingMode { DecodedMode, } -type argument = string | NativeElement; - export class QUrl extends Component { native: NativeElement; - constructor(arg?: argument, parsingMode: ParsingMode = ParsingMode.TolerantMode) { + constructor(); + constructor(nativeElement: NativeElement); + constructor(url: string, parsingMode?: ParsingMode); + constructor(arg?: string | NativeElement, parsingMode: ParsingMode = ParsingMode.TolerantMode) { super(); if (!arg) { this.native = new addon.QUrl(); diff --git a/src/lib/QtCore/QVariant.ts b/src/lib/QtCore/QVariant.ts index 59bceaf97..f5b8a939e 100644 --- a/src/lib/QtCore/QVariant.ts +++ b/src/lib/QtCore/QVariant.ts @@ -2,11 +2,14 @@ import { NativeElement, Component } from '../core/Component'; import addon from '../utils/addon'; import { checkIfNativeElement } from '../utils/helpers'; -type QVariantType = NativeElement | Component | string | number | boolean; +type QVariantType = Component | string | number | boolean; export class QVariant extends Component { native: NativeElement; - constructor(arg?: QVariantType) { + constructor(); + constructor(nativeElement: NativeElement); + constructor(variant: QVariantType); + constructor(arg?: QVariantType | NativeElement) { super(); if (checkIfNativeElement(arg)) { this.native = arg as NativeElement; diff --git a/src/lib/QtGui/QApplication.ts b/src/lib/QtGui/QApplication.ts index 2edcf35d0..7843812d8 100644 --- a/src/lib/QtGui/QApplication.ts +++ b/src/lib/QtGui/QApplication.ts @@ -4,10 +4,11 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QClipboard } from './QClipboard'; import { QStyle } from './QStyle'; -type arg = NativeElement; export class QApplication extends Component { native: NativeElement; - constructor(arg?: arg) { + constructor(); + constructor(native: NativeElement); + constructor(arg?: NativeElement) { super(); if (checkIfNativeElement(arg)) { this.native = arg as NativeElement; diff --git a/src/lib/QtGui/QCursor.ts b/src/lib/QtGui/QCursor.ts index a104a6ebd..85592d9b9 100644 --- a/src/lib/QtGui/QCursor.ts +++ b/src/lib/QtGui/QCursor.ts @@ -1,11 +1,12 @@ import addon from '../utils/addon'; import { Component, NativeElement } from '../core/Component'; -import { QPixmap } from './QPixmap'; - -type arg = NativeElement | number | QPixmap; +import { CursorShape } from '../QtEnums'; export class QCursor extends Component { native: NativeElement; - constructor(arg?: arg) { + constructor(); + constructor(native: NativeElement); + constructor(shape: CursorShape); + constructor(arg?: NativeElement | CursorShape) { super(); if (arg) { this.native = new addon.QCursor(arg); diff --git a/src/lib/QtGui/QEvent/QKeyEvent.ts b/src/lib/QtGui/QEvent/QKeyEvent.ts index ee7c39961..663219c71 100644 --- a/src/lib/QtGui/QEvent/QKeyEvent.ts +++ b/src/lib/QtGui/QEvent/QKeyEvent.ts @@ -1,10 +1,9 @@ import addon from '../../utils/addon'; import { NativeElement } from '../../core/Component'; -import { NativeEvent } from '../../core/EventWidget'; export class QKeyEvent { native: NativeElement; - constructor(event: NativeEvent) { + constructor(event: NativeElement) { this.native = new addon.QKeyEvent(event); } text(): string { diff --git a/src/lib/QtGui/QEvent/QMouseEvent.ts b/src/lib/QtGui/QEvent/QMouseEvent.ts index 46d7fdc31..ab77d624a 100644 --- a/src/lib/QtGui/QEvent/QMouseEvent.ts +++ b/src/lib/QtGui/QEvent/QMouseEvent.ts @@ -1,10 +1,9 @@ import addon from '../../utils/addon'; import { NativeElement } from '../../core/Component'; -import { NativeEvent } from '../../core/EventWidget'; export class QMouseEvent { native: NativeElement; - constructor(event: NativeEvent) { + constructor(event: NativeElement) { this.native = new addon.QMouseEvent(event); } button(): string { diff --git a/src/lib/QtGui/QFontDatabase.ts b/src/lib/QtGui/QFontDatabase.ts index 118cf1488..350f73d32 100644 --- a/src/lib/QtGui/QFontDatabase.ts +++ b/src/lib/QtGui/QFontDatabase.ts @@ -1,6 +1,29 @@ import addon from '../utils/addon'; import { Component, NativeElement } from '../core/Component'; +export class QFontDatabase extends Component { + native: NativeElement; + constructor() { + super(); + this.native = new addon.QFontDatabase(); + } + bold(family: string, style: string): boolean { + return this.native.bold(family, style); + } + italic(family: string, style: string): boolean { + return this.native.italic(family, style); + } + weight(family: string, style: string): number { + return this.native.weight(family, style); + } + static addApplicationFont(fileName: string): number { + return addon.QFontDatabase.addApplicationFont(fileName); + } + static removeApplicationFont(id: number): boolean { + return addon.QFontDatabase.removeApplicationFont(id); + } +} + export enum SystemFont { GeneralFont, FixedFont, @@ -45,26 +68,3 @@ export enum WritingSystem { Runic = 32, Nko = 33, } - -export class QFontDatabase extends Component { - native: NativeElement; - constructor() { - super(); - this.native = new addon.QFontDatabase(); - } - bold(family: string, style: string): boolean { - return this.native.bold(family, style); - } - italic(family: string, style: string): boolean { - return this.native.italic(family, style); - } - weight(family: string, style: string): number { - return this.native.weight(family, style); - } - static addApplicationFont(fileName: string): number { - return addon.QFontDatabase.addApplicationFont(fileName); - } - static removeApplicationFont(id: number): boolean { - return addon.QFontDatabase.removeApplicationFont(id); - } -} diff --git a/src/lib/QtGui/QIcon.ts b/src/lib/QtGui/QIcon.ts index 6bf2aec5e..5b498d9e5 100644 --- a/src/lib/QtGui/QIcon.ts +++ b/src/lib/QtGui/QIcon.ts @@ -15,14 +15,16 @@ export enum QIconState { On, } -type arg = string | NativeElement; export class QIcon extends Component { native: NativeElement; - constructor(arg?: arg) { + constructor(); + constructor(native: NativeElement); + constructor(filePath: string); + constructor(arg?: string | NativeElement) { super(); if (typeof arg === 'string') { - const imageUrl = arg; - this.native = new addon.QIcon(imageUrl); + const imagePath = arg; + this.native = new addon.QIcon(imagePath); } else if (checkIfNativeElement(arg)) { this.native = arg as NativeElement; } else { diff --git a/src/lib/QtGui/QKeySequence.ts b/src/lib/QtGui/QKeySequence.ts index 7ef96b120..6e15adede 100644 --- a/src/lib/QtGui/QKeySequence.ts +++ b/src/lib/QtGui/QKeySequence.ts @@ -3,6 +3,8 @@ import { Component, NativeElement } from '../core/Component'; export class QKeySequence extends Component { native: NativeElement; + constructor(); + constructor(keySequence: string); constructor(keySequence?: string) { super(); if (typeof keySequence === 'string') { diff --git a/src/lib/QtGui/QMovie.ts b/src/lib/QtGui/QMovie.ts index c6338d18a..bd4c57fb8 100644 --- a/src/lib/QtGui/QMovie.ts +++ b/src/lib/QtGui/QMovie.ts @@ -1,37 +1,29 @@ import addon from '../utils/addon'; import { NativeElement } from '../core/Component'; import { checkIfNativeElement } from '../utils/helpers'; -import { QObject } from '../QtCore/QObject'; +import { NodeObject } from '../QtCore/QObject'; import { QSize } from '../QtCore/QSize'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { QPixmap } from './QPixmap'; - -export const QMovieEvents = Object.freeze({ - ...BaseWidgetEvents, - error: 'error', - finished: 'finished', - frameChanged: 'frameChanged', - resized: 'resized', - started: 'started', - stateChanged: 'stateChanged', - updated: 'updated', -}); - -type supportedFormats = 'gif' | 'webp'; -export class QMovie extends QObject { +export class QMovie extends NodeObject { native: NativeElement; - constructor(arg?: QObject | NativeElement) { - super(); + constructor(); + constructor(native: NativeElement); + constructor(parent: NodeObject); + constructor(arg?: NodeObject | NativeElement) { + let native: NativeElement; if (arg) { if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QMovie(arg); + native = new addon.QMovie(arg); } } else { - this.native = new addon.QMovie(); + native = new addon.QMovie(); } + super(native); + this.native = native; } + //Methods setFileName(fileName: string): void { this.native.setFileName(fileName); this.jumpToFrame(0); @@ -42,13 +34,12 @@ export class QMovie extends QObject { fileName(): string { return this.native.fileName(); } - setFormat(formatName: supportedFormats): void { + setFormat(formatName: SupportedFormats): void { this.native.setFormat(formatName); } format(): string { return this.native.format(); } - setScaledSize(size: QSize): void { this.native.setScaledSize(size.native); } @@ -84,6 +75,16 @@ export class QMovie extends QObject { } } +interface QMovieSignals { + error: (error: ImageReaderError) => void; + finished: () => void; + frameChanged: (frameNumber?: number) => void; + resized: (qSizeNative?: NativeElement) => void; + started: () => void; + stateChanged: (state: MovieState) => void; + updated: (qRectNative: NativeElement) => void; +} + export enum CacheMode { CacheNone, CacheAll, @@ -94,3 +95,13 @@ export enum MovieState { Paused, Running, } + +export enum ImageReaderError { + FileNotFoundError = 1, + DeviceError = 2, + UnsupportedFormatError = 3, + InvalidDataError = 4, + UnknownError = 0, +} + +type SupportedFormats = 'gif' | 'webp'; diff --git a/src/lib/QtGui/QPixmap.ts b/src/lib/QtGui/QPixmap.ts index 378ac48de..d97406a08 100644 --- a/src/lib/QtGui/QPixmap.ts +++ b/src/lib/QtGui/QPixmap.ts @@ -6,22 +6,24 @@ import { QVariant } from '../QtCore/QVariant'; export type ImageFormats = 'BMP' | 'GIF' | 'JPG' | 'JPEG' | 'PNG' | 'PBM' | 'PGM' | 'PPM' | 'XBM' | 'XPM' | 'SVG'; -type arg = string | NativeElement; export class QPixmap extends Component { native: NativeElement; - constructor(arg?: arg) { + constructor(); + constructor(native: NativeElement); + constructor(filePath: string); + constructor(arg?: string | NativeElement) { super(); if (typeof arg === 'string') { - const imageUrl = arg; - this.native = new addon.QPixmap(imageUrl); + const imagePath = arg; + this.native = new addon.QPixmap(imagePath); } else if (checkIfNativeElement(arg)) { this.native = arg as NativeElement; } else { this.native = new addon.QPixmap(); } } - load(imageUrl: string): boolean { - return this.native.load(imageUrl); + load(imagePath: string): boolean { + return this.native.load(imagePath); } loadFromData(buffer: Buffer, format?: ImageFormats): boolean { return format ? this.native.loadFromData(buffer, format) : this.native.loadFromData(buffer); diff --git a/src/lib/QtGui/__tests__/QMovie.test.ts b/src/lib/QtGui/__tests__/QMovie.test.ts index 8d89b5887..e5a08e17b 100644 --- a/src/lib/QtGui/__tests__/QMovie.test.ts +++ b/src/lib/QtGui/__tests__/QMovie.test.ts @@ -81,7 +81,7 @@ describe('QMovie', () => { movie.loadFromData(Buffer.from(arrayBuffer)); movie.start(); movie.stop(); - movie.jumpToFrame(2); + movie.jumpToNextFrame(); const pixmap = movie.currentPixmap(); expect(pixmap).toBeInstanceOf(QPixmap); expect(pixmap.height()).toBe(270); diff --git a/src/lib/QtWidgets/QAbstractButton.ts b/src/lib/QtWidgets/QAbstractButton.ts index e630f15fa..9deba7161 100644 --- a/src/lib/QtWidgets/QAbstractButton.ts +++ b/src/lib/QtWidgets/QAbstractButton.ts @@ -2,7 +2,7 @@ import { NodeWidget } from './QWidget'; import { QIcon } from '../QtGui/QIcon'; import { QSize } from '../QtCore/QSize'; -export abstract class QAbstractButton extends NodeWidget { +export abstract class QAbstractButton extends NodeWidget { setText(text: string): void { this.native.setText(text); } diff --git a/src/lib/QtWidgets/QAbstractScrollArea.ts b/src/lib/QtWidgets/QAbstractScrollArea.ts index 45b0c2fd2..2ec32fb44 100644 --- a/src/lib/QtWidgets/QAbstractScrollArea.ts +++ b/src/lib/QtWidgets/QAbstractScrollArea.ts @@ -1,9 +1,9 @@ import { NodeWidget, QWidget } from './QWidget'; import { ScrollBarPolicy } from '../QtEnums/ScrollBarPolicy'; -export abstract class QAbstractScrollArea extends NodeWidget { - viewportWidget?: NodeWidget; - setViewport(widget: NodeWidget): void { +export abstract class QAbstractScrollArea extends NodeWidget { + viewportWidget?: NodeWidget; + setViewport(widget: NodeWidget): void { this.viewportWidget = widget; this.native.setViewport(widget.native); } diff --git a/src/lib/QtWidgets/QAbstractSlider.ts b/src/lib/QtWidgets/QAbstractSlider.ts index 48df3cdca..e43af90f4 100644 --- a/src/lib/QtWidgets/QAbstractSlider.ts +++ b/src/lib/QtWidgets/QAbstractSlider.ts @@ -1,7 +1,7 @@ import { NodeWidget } from './QWidget'; import { Orientation } from '../QtEnums'; -export abstract class QAbstractSlider extends NodeWidget { +export abstract class QAbstractSlider extends NodeWidget { setSingleStep(step: number): void { this.native.setSingleStep(step); } diff --git a/src/lib/QtWidgets/QAction.ts b/src/lib/QtWidgets/QAction.ts index dfe40004b..a7c7c6915 100644 --- a/src/lib/QtWidgets/QAction.ts +++ b/src/lib/QtWidgets/QAction.ts @@ -7,17 +7,20 @@ import { QKeySequence } from '../QtGui/QKeySequence'; import { ShortcutContext } from '../QtEnums'; import { NodeObject } from '../QtCore/QObject'; -export const QActionEvents = Object.freeze({ - triggered: 'triggered', - changed: 'changed', - hovered: 'hovered', - toggled: 'toggled', -}); -export class QAction extends NodeObject { +interface QActionSignals { + triggered: (checked: boolean) => void; + changed: () => void; + hovered: () => void; + toggled: (checked: boolean) => void; +} + +export class QAction extends NodeObject { native: NativeElement; icon?: QIcon; menu?: QMenu; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QAction(parent.native); diff --git a/src/lib/QtWidgets/QBoxLayout.ts b/src/lib/QtWidgets/QBoxLayout.ts index 0f7894f79..9df35c861 100644 --- a/src/lib/QtWidgets/QBoxLayout.ts +++ b/src/lib/QtWidgets/QBoxLayout.ts @@ -4,10 +4,13 @@ import { NodeLayout } from './QLayout'; import { NativeElement } from '../core/Component'; import { Direction } from '../QtEnums'; -export class QBoxLayout extends NodeLayout { +type QBoxLayoutSignals = {}; +export class QBoxLayout extends NodeLayout { native: NativeElement; - childLayouts: Set; - constructor(dir: Direction, parent?: NodeWidget) { + childLayouts: Set>; + constructor(dir: Direction); + constructor(dir: Direction, parent: NodeWidget); + constructor(dir: Direction, parent?: NodeWidget) { let native: NativeElement; if (parent) { native = new addon.QBoxLayout(dir, parent.native); @@ -19,7 +22,7 @@ export class QBoxLayout extends NodeLayout { this.native = native; this.childLayouts = new Set(); } - addLayout(layout: NodeLayout, stretch = 0): void { + addLayout(layout: NodeLayout, stretch = 0): void { this.native.addLayout(layout.native, stretch); this.childLayouts.add(layout); } @@ -32,22 +35,22 @@ export class QBoxLayout extends NodeLayout { addStrut(size: number): void { this.native.addStrut(size); } - addWidget(widget: NodeWidget, stretch = 0): void { + addWidget(widget: NodeWidget, stretch = 0): void { this.native.addWidget(widget.native, stretch); this.nodeChildren.add(widget); } - insertWidget(index: number, widget: NodeWidget, stretch = 0): void { + insertWidget(index: number, widget: NodeWidget, stretch = 0): void { this.native.insertWidget(index, widget.native, stretch); this.nodeChildren.add(widget); } direction(): Direction { return this.native.direction(); } - insertLayout(index: number, layout: NodeLayout, stretch = 0): void { + insertLayout(index: number, layout: NodeLayout, stretch = 0): void { this.native.insertLayout(index, layout.native, stretch); this.childLayouts.add(layout); } - removeWidget(widget: NodeWidget): void { + removeWidget(widget: NodeWidget): void { this.native.removeWidget(widget.native); this.nodeChildren.delete(widget); } diff --git a/src/lib/QtWidgets/QCheckBox.ts b/src/lib/QtWidgets/QCheckBox.ts index fa68bb8cb..ad95eb4f2 100644 --- a/src/lib/QtWidgets/QCheckBox.ts +++ b/src/lib/QtWidgets/QCheckBox.ts @@ -1,16 +1,18 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractButton } from './QAbstractButton'; -export const QCheckBoxEvents = Object.freeze({ - ...BaseWidgetEvents, - toggled: 'toggled', -}); -export class QCheckBox extends QAbstractButton { +interface QCheckBoxSignals { + //List all Signals below + toggled: (checked: boolean) => void; +} + +export class QCheckBox extends QAbstractButton { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QCheckBox(parent.native); diff --git a/src/lib/QtWidgets/QComboBox.ts b/src/lib/QtWidgets/QComboBox.ts index f774174fe..8a5cdf61b 100644 --- a/src/lib/QtWidgets/QComboBox.ts +++ b/src/lib/QtWidgets/QComboBox.ts @@ -1,20 +1,21 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { SizeAdjustPolicy } from '../QtEnums'; import { QIcon } from '../QtGui/QIcon'; import { QVariant } from '../QtCore/QVariant'; -export const QComboBoxEvents = Object.freeze({ - currentIndexChanged: 'currentIndexChanged', - currentTextChanged: 'currentTextChanged', - editTextChanged: 'editTextChanged', - ...BaseWidgetEvents, -}); -export class QComboBox extends NodeWidget { +interface QComboBoxSignals { + //List all Signals below + currentIndexChanged: (index: number) => void; + currentTextChanged: (text: string) => void; + editTextChanged: (text: string) => void; +} +export class QComboBox extends NodeWidget { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QComboBox(parent.native); diff --git a/src/lib/QtWidgets/QDial.ts b/src/lib/QtWidgets/QDial.ts index fb9eb4bbf..2cc94d342 100644 --- a/src/lib/QtWidgets/QDial.ts +++ b/src/lib/QtWidgets/QDial.ts @@ -1,20 +1,20 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractSlider } from './QAbstractSlider'; -export const QDialEvents = Object.freeze({ - ...BaseWidgetEvents, - valueChanged: 'valueChanged', - rangeChanged: 'rangeChanged', - sliderMoved: 'sliderMoved', - sliderPressed: 'sliderPressed', - sliderReleased: 'sliderReleased', -}); -export class QDial extends QAbstractSlider { +interface QDialSignals { + valueChanged: (value: number) => void; + rangeChanged: (min: number, max: number) => void; + sliderMoved: (value: number) => void; + sliderPressed: () => void; + sliderReleased: () => void; +} +export class QDial extends QAbstractSlider { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QDial(parent.native); @@ -26,27 +26,21 @@ export class QDial extends QAbstractSlider { this.setNodeParent(parent); } setNotchesVisible(visible: boolean): void { - // react:✓ this.native.setNotchesVisible(visible); } notchesVisible(): boolean { - // react:✓ return this.native.notchesVisible(); } setWrapping(on: boolean): void { - // react:✓ this.native.setWrapping(on); } wrapping(): boolean { - // react:✓ return this.native.wrapping(); } setNotchTarget(target: number): void { - // react:✓ this.native.setNotchTarget(target); } notchTarget(): number { - // react:✓ return this.native.notchTarget(); } } diff --git a/src/lib/QtWidgets/QFileDialog.ts b/src/lib/QtWidgets/QFileDialog.ts index 7ba432fe6..def0a0afa 100644 --- a/src/lib/QtWidgets/QFileDialog.ts +++ b/src/lib/QtWidgets/QFileDialog.ts @@ -1,24 +1,25 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { AcceptMode, DialogLabel, FileMode, Option, ViewMode } from '../QtEnums'; -export const QFileDialogEvents = Object.freeze({ - currentChanged: 'currentChanged', - currentUrlChanged: 'currentUrlChanged', - directoryEntered: 'directoryEntered', - directoryUrlEntered: 'directoryUrlEntered', - fileSelected: 'fileSelected', - filesSelected: 'filesSelected', - filterSelected: 'filterSelected', - urlSelected: 'urlSelected', - urlsSelected: 'urlsSelected', - ...BaseWidgetEvents, -}); -export class QFileDialog extends NodeWidget { +interface QFileDialogSignals { + currentChanged: (path: string) => void; + currentUrlChanged: (url: string) => void; + directoryEntered: (directory: string) => void; + directoryUrlEntered: (url: string) => void; + fileSelected: (file: string) => void; + filesSelected: (selected: string[]) => void; + filterSelected: (filter: string) => void; + urlSelected: (url: string) => void; + urlsSelected: (urls: string[]) => void; +} + +export class QFileDialog extends NodeWidget { native: NativeElement; - constructor(parent: NodeWidget | undefined = undefined, caption = 'Select File', directory = '', filter = '') { + constructor(); + constructor(parent: NodeWidget, caption?: string, directory?: string, filter?: string); + constructor(parent?: NodeWidget, caption = 'Select File', directory = '', filter = '') { let native; if (parent) { native = new addon.QFileDialog(parent.native, caption, directory, filter); diff --git a/src/lib/QtWidgets/QGridLayout.ts b/src/lib/QtWidgets/QGridLayout.ts index 582f91b2d..365d7db84 100644 --- a/src/lib/QtWidgets/QGridLayout.ts +++ b/src/lib/QtWidgets/QGridLayout.ts @@ -3,9 +3,13 @@ import { NodeWidget } from './QWidget'; import { NodeLayout } from './QLayout'; import { NativeElement } from '../core/Component'; -export class QGridLayout extends NodeLayout { +type QGridLayoutSignals = {}; + +export class QGridLayout extends NodeLayout { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native: NativeElement; if (parent) { native = new addon.QGridLayout(parent.native); @@ -16,11 +20,11 @@ export class QGridLayout extends NodeLayout { this.setNodeParent(parent); this.native = native; } - addWidget(widget: NodeWidget, row = 0, col = 0, rowSpan = 1, colSpan = 1): void { + 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 { + removeWidget(widget: NodeWidget): void { this.native.removeWidget(widget.native); this.nodeChildren.delete(widget); } diff --git a/src/lib/QtWidgets/QGroupBox.ts b/src/lib/QtWidgets/QGroupBox.ts index ce25af406..e5cefabd1 100644 --- a/src/lib/QtWidgets/QGroupBox.ts +++ b/src/lib/QtWidgets/QGroupBox.ts @@ -1,17 +1,17 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { AlignmentFlag } from '../QtEnums/AlignmentFlag'; -export const QGroupBoxEvents = Object.freeze({ - ...BaseWidgetEvents, - clicked: 'clicked', - toggled: 'toggled', -}); -export class QGroupBox extends NodeWidget { +interface QGroupBoxSignals { + clicked: (checked: boolean) => void; + toggled: (on: boolean) => void; +} +export class QGroupBox extends NodeWidget { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QGroupBox(parent.native); diff --git a/src/lib/QtWidgets/QLabel.ts b/src/lib/QtWidgets/QLabel.ts index ac92f7f31..acfe0375b 100644 --- a/src/lib/QtWidgets/QLabel.ts +++ b/src/lib/QtWidgets/QLabel.ts @@ -1,20 +1,19 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QPixmap } from '../QtGui/QPixmap'; import { QMovie } from '../QtGui/QMovie'; import { AlignmentFlag } from '../QtEnums/AlignmentFlag'; import { TextFormat } from '../QtEnums/TextFormat'; -export const QLabelEvents = Object.freeze({ - ...BaseWidgetEvents, -}); -export class QLabel extends NodeWidget { +type QLabelSignals = {}; +export class QLabel extends NodeWidget { native: NativeElement; private _pixmap?: QPixmap; private _movie?: QMovie; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QLabel(parent.native); diff --git a/src/lib/QtWidgets/QLayout.ts b/src/lib/QtWidgets/QLayout.ts index d3d7a6854..1181f6d9d 100644 --- a/src/lib/QtWidgets/QLayout.ts +++ b/src/lib/QtWidgets/QLayout.ts @@ -2,10 +2,10 @@ import { NodeWidget } from './QWidget'; import { NodeObject } from '../QtCore/QObject'; // All Layouts should extend this abstract class. -export abstract class NodeLayout extends NodeObject { +export abstract class NodeLayout extends NodeObject { type = 'layout'; - abstract addWidget(childWidget: NodeWidget, ...args: any[]): void; - abstract removeWidget(childWidget: NodeWidget): void; + abstract addWidget(childWidget: NodeWidget, ...args: any[]): void; + abstract removeWidget(childWidget: NodeWidget): void; activate(): boolean { return this.native.activate(); } diff --git a/src/lib/QtWidgets/QLineEdit.ts b/src/lib/QtWidgets/QLineEdit.ts index 16ac53f87..5390703d4 100644 --- a/src/lib/QtWidgets/QLineEdit.ts +++ b/src/lib/QtWidgets/QLineEdit.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; export enum EchoMode { @@ -9,20 +8,21 @@ export enum EchoMode { Password, PasswordEchoOnEdit, } -export const QLineEditEvents = Object.freeze({ - ...BaseWidgetEvents, - cursorPositionChanged: 'cursorPositionChanged', - editingFinished: 'editingFinished', - inputRejected: 'inputRejected', - returnPressed: 'returnPressed', - selectionChanged: 'selectionChanged', - textChanged: 'textChanged', - textEdited: 'textEdited', -}); -export class QLineEdit extends NodeWidget { +interface QLineEditSignals { + cursorPositionChanged: (oldPos: number, newPos: number) => void; + editingFinished: () => void; + inputRejected: () => void; + returnPressed: () => void; + selectionChanged: () => void; + textChanged: (text: string) => void; + textEdited: (text: string) => void; +} +export class QLineEdit extends NodeWidget { native: NativeElement; placeholderText?: string; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QLineEdit(parent.native); diff --git a/src/lib/QtWidgets/QMainWindow.ts b/src/lib/QtWidgets/QMainWindow.ts index b302e28bb..c6df33ade 100644 --- a/src/lib/QtWidgets/QMainWindow.ts +++ b/src/lib/QtWidgets/QMainWindow.ts @@ -1,18 +1,17 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { NodeLayout } from './QLayout'; import { QMenuBar } from './QMenuBar'; -export const QMainWindowEvents = Object.freeze({ - ...BaseWidgetEvents, -}); -export class QMainWindow extends NodeWidget { +type QMainWindowSignals = {}; +export class QMainWindow extends NodeWidget { native: NativeElement; - public centralWidget?: NodeWidget | null; + public centralWidget?: NodeWidget | null; private _menuBar?: QMenuBar; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QMainWindow(parent.native); @@ -23,7 +22,7 @@ export class QMainWindow extends NodeWidget { this.native = native; this.setNodeParent(parent); - this.setLayout = (parentLayout: NodeLayout): void => { + this.setLayout = (parentLayout: NodeLayout): void => { if (this.centralWidget) { this.centralWidget.setLayout(parentLayout); } else { @@ -32,13 +31,13 @@ export class QMainWindow extends NodeWidget { } }; } - setCentralWidget(widget: NodeWidget): void { + setCentralWidget(widget: NodeWidget): void { // react:✓ this.native.setCentralWidget(widget.native); this.centralWidget = widget; this.centralWidget.setFlexNodeSizeControlled(true); } - takeCentralWidget(): NodeWidget | null { + takeCentralWidget(): NodeWidget | null { // react:✓ const centralWidget = this.centralWidget; this.centralWidget = null; @@ -55,10 +54,10 @@ export class QMainWindow extends NodeWidget { menuBar(): QMenuBar | undefined { return this._menuBar; } - setMenuWidget(menuWidget: NodeWidget): void { + setMenuWidget(menuWidget: NodeWidget): void { this.native.setMenuWidget(menuWidget.native); } - get layout(): NodeLayout | undefined { + get layout(): NodeLayout | undefined { if (this.centralWidget) { return this.centralWidget.layout; } diff --git a/src/lib/QtWidgets/QMenu.ts b/src/lib/QtWidgets/QMenu.ts index 0891e3248..ba7777de0 100644 --- a/src/lib/QtWidgets/QMenu.ts +++ b/src/lib/QtWidgets/QMenu.ts @@ -1,16 +1,15 @@ -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { NodeWidget } from './QWidget'; import addon from '../utils/addon'; import { QAction } from './QAction'; -export const QMenuEvents = Object.freeze({ - ...BaseWidgetEvents, -}); -export class QMenu extends NodeWidget { +type QMenuSignals = {}; +export class QMenu extends NodeWidget { native: NativeElement; actions: Set; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QMenu(parent.native); diff --git a/src/lib/QtWidgets/QMenuBar.ts b/src/lib/QtWidgets/QMenuBar.ts index b716e8283..b17e20eaa 100644 --- a/src/lib/QtWidgets/QMenuBar.ts +++ b/src/lib/QtWidgets/QMenuBar.ts @@ -1,26 +1,24 @@ import { QMenu } from './QMenu'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { NodeWidget } from './QWidget'; import addon from '../utils/addon'; import { checkIfNativeElement } from '../utils/helpers'; -export const QMenuBarEvents = Object.freeze({ - ...BaseWidgetEvents, -}); +type QMenuBarSignals = {}; -type arg = NodeWidget | NativeElement; - -export class QMenuBar extends NodeWidget { +export class QMenuBar extends NodeWidget { native: NativeElement; - constructor(arg?: arg) { + constructor(); + constructor(parent: NodeWidget); + constructor(native: NativeElement); + constructor(arg?: NodeWidget | NativeElement) { let native; let parent; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (typeof arg === 'object') { native = new addon.QMenuBar(arg.native); - parent = arg as NodeWidget; + parent = arg as NodeWidget; } else { native = new addon.QMenuBar(); } diff --git a/src/lib/QtWidgets/QPainter.ts b/src/lib/QtWidgets/QPainter.ts index 3f19201f1..fd07b286d 100644 --- a/src/lib/QtWidgets/QPainter.ts +++ b/src/lib/QtWidgets/QPainter.ts @@ -16,7 +16,8 @@ export enum RenderHint { export class QPainter extends Component { native: NativeElement; - + constructor(); + constructor(device: Component); constructor(device?: Component) { let native; if (device) { diff --git a/src/lib/QtWidgets/QPlainTextEdit.ts b/src/lib/QtWidgets/QPlainTextEdit.ts index c760fdd38..e41549d2a 100644 --- a/src/lib/QtWidgets/QPlainTextEdit.ts +++ b/src/lib/QtWidgets/QPlainTextEdit.ts @@ -1,30 +1,30 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractScrollArea } from './QAbstractScrollArea'; import { QTextOptionWrapMode } from '../QtGui/QTextOption'; -export const QPlainTextEditEvents = Object.freeze({ - ...BaseWidgetEvents, - textChanged: 'textChanged', - blockCountChanged: 'blockCountChanged', - copyAvailable: 'copyAvailable', - cursorPositionChanged: 'cursorPositionChanged', - modificationChanged: 'modificationChanged', - redoAvailable: 'redoAvailable', - selectionChanged: 'selectionChanged', - undoAvailable: 'undoAvailable', -}); +interface QPlainTextEditSignals { + textChanged: () => void; + blockCountChanged: (blockCount: number) => void; + copyAvailable: (yes: boolean) => void; + cursorPositionChanged: () => void; + modificationChanged: (changed: boolean) => void; + redoAvailable: (available: boolean) => void; + selectionChanged: () => void; + undoAvailable: (available: boolean) => void; +} export enum LineWrapMode { NoWrap, WidgetWidth, } -export class QPlainTextEdit extends QAbstractScrollArea { +export class QPlainTextEdit extends QAbstractScrollArea { native: NativeElement; placeholderText?: string; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QPlainTextEdit(parent.native); diff --git a/src/lib/QtWidgets/QProgressBar.ts b/src/lib/QtWidgets/QProgressBar.ts index fb1319d36..791ed72ce 100644 --- a/src/lib/QtWidgets/QProgressBar.ts +++ b/src/lib/QtWidgets/QProgressBar.ts @@ -1,15 +1,14 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { Orientation } from '../QtEnums'; -export const QProgressBarEvents = Object.freeze({ - ...BaseWidgetEvents, -}); -export class QProgressBar extends NodeWidget { +type QProgressBarSignals = {}; +export class QProgressBar extends NodeWidget { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QProgressBar(parent.native); diff --git a/src/lib/QtWidgets/QPushButton.ts b/src/lib/QtWidgets/QPushButton.ts index a80ac4ba2..456a56494 100644 --- a/src/lib/QtWidgets/QPushButton.ts +++ b/src/lib/QtWidgets/QPushButton.ts @@ -1,20 +1,20 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractButton } from './QAbstractButton'; -export const QPushButtonEvents = Object.freeze({ - ...BaseWidgetEvents, - clicked: 'clicked', - pressed: 'pressed', - released: 'released', - toggled: 'toggled', -}); +interface QPushButtonSignals { + clicked: (checked: boolean) => void; + pressed: () => void; + released: () => void; + toggled: (checked: boolean) => void; +} -export class QPushButton extends QAbstractButton { +export class QPushButton extends QAbstractButton { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QPushButton(parent.native); diff --git a/src/lib/QtWidgets/QRadioButton.ts b/src/lib/QtWidgets/QRadioButton.ts index 0eb46c52f..98c5acbf2 100644 --- a/src/lib/QtWidgets/QRadioButton.ts +++ b/src/lib/QtWidgets/QRadioButton.ts @@ -1,15 +1,14 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractButton } from './QAbstractButton'; -export const QRadioButtonEvents = Object.freeze({ - ...BaseWidgetEvents, -}); -export class QRadioButton extends QAbstractButton { +type QRadioButtonSignals = {}; +export class QRadioButton extends QAbstractButton { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QRadioButton(parent.native); diff --git a/src/lib/QtWidgets/QScrollArea.ts b/src/lib/QtWidgets/QScrollArea.ts index 576695492..1ae3b17cb 100644 --- a/src/lib/QtWidgets/QScrollArea.ts +++ b/src/lib/QtWidgets/QScrollArea.ts @@ -1,16 +1,15 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractScrollArea } from './QAbstractScrollArea'; -export const QScrollAreaEvents = Object.freeze({ - ...BaseWidgetEvents, -}); -export class QScrollArea extends QAbstractScrollArea { +type QScrollAreaSignals = {}; +export class QScrollArea extends QAbstractScrollArea { native: NativeElement; - contentWidget?: NodeWidget | null; - constructor(parent?: NodeWidget) { + contentWidget?: NodeWidget | null; + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QScrollArea(parent.native); @@ -22,13 +21,13 @@ export class QScrollArea extends QAbstractScrollArea { this.setNodeParent(parent); this.setWidgetResizable(true); } - setWidget(widget: NodeWidget): void { + setWidget(widget: NodeWidget): void { // react:✓, //TODO:getter this.contentWidget = widget; this.native.setWidget(widget.native); this.contentWidget.setFlexNodeSizeControlled(this.widgetResizable()); } - takeWidget(): NodeWidget | null { + takeWidget(): NodeWidget | null { // react:✓ const contentWidget = this.contentWidget; this.contentWidget = null; diff --git a/src/lib/QtWidgets/QShortcut.ts b/src/lib/QtWidgets/QShortcut.ts index 548791889..c2b33dc49 100644 --- a/src/lib/QtWidgets/QShortcut.ts +++ b/src/lib/QtWidgets/QShortcut.ts @@ -5,14 +5,14 @@ import { QKeySequence } from '../QtGui/QKeySequence'; import { ShortcutContext } from '../QtEnums'; import { NodeObject } from '../QtCore/QObject'; -export const QShortcutEvents = Object.freeze({ - activated: 'activated', - activatedAmbiguously: 'activatedAmbiguously', -}); +interface QShortcutSignals { + activated: () => void; + activatedAmbiguously: () => void; +} -export class QShortcut extends NodeObject { +export class QShortcut extends NodeObject { native: NativeElement; - constructor(parent: NodeWidget) { + constructor(parent: NodeWidget) { const native = new addon.QShortcut(parent.native); super(native); this.native = native; diff --git a/src/lib/QtWidgets/QSpinBox.ts b/src/lib/QtWidgets/QSpinBox.ts index 7db48c31f..3011aabda 100644 --- a/src/lib/QtWidgets/QSpinBox.ts +++ b/src/lib/QtWidgets/QSpinBox.ts @@ -1,16 +1,16 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; -export const QSpinBoxEvents = Object.freeze({ - ...BaseWidgetEvents, - valueChanged: 'valueChanged', -}); +interface QSpinBoxSignals { + valueChanged: (value: number) => void; +} -export class QSpinBox extends NodeWidget { +export class QSpinBox extends NodeWidget { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QSpinBox(parent.native); diff --git a/src/lib/QtWidgets/QStackedWidget.ts b/src/lib/QtWidgets/QStackedWidget.ts index 5e31c0c26..ea25cc346 100644 --- a/src/lib/QtWidgets/QStackedWidget.ts +++ b/src/lib/QtWidgets/QStackedWidget.ts @@ -1,16 +1,16 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; -export const QStackedWidgetEvents = Object.freeze({ - ...BaseWidgetEvents, - currentChanged: 'currentChanged', -}); +interface QStackedWidgetSignals { + currentChanged: (index: number) => void; +} -export class QStackedWidget extends NodeWidget { +export class QStackedWidget extends NodeWidget { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QStackedWidget(parent.native); @@ -22,13 +22,13 @@ export class QStackedWidget extends NodeWidget { this.native = native; } - addWidget(widget: NodeWidget): void { + addWidget(widget: NodeWidget): void { this.native.addWidget(widget.native); this.nodeChildren.add(widget); widget.setFlexNodeSizeControlled(true); } - removeWidget(widget: NodeWidget): void { + removeWidget(widget: NodeWidget): void { this.native.removeWidget(widget.native); this.nodeChildren.delete(widget); } @@ -41,7 +41,7 @@ export class QStackedWidget extends NodeWidget { return this.native.currentIndex(); } - setCurrentWidget(widget: NodeWidget): void { + setCurrentWidget(widget: NodeWidget): void { this.native.setCurrentWidget(widget.native); } } diff --git a/src/lib/QtWidgets/QSystemTrayIcon.ts b/src/lib/QtWidgets/QSystemTrayIcon.ts index cbf490cf2..352fd77a1 100644 --- a/src/lib/QtWidgets/QSystemTrayIcon.ts +++ b/src/lib/QtWidgets/QSystemTrayIcon.ts @@ -1,27 +1,21 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QIcon } from '../QtGui/QIcon'; import { QMenu } from './QMenu'; import { NodeObject } from '../QtCore/QObject'; -export const QSystemTrayIconEvents = Object.freeze({ - ...BaseWidgetEvents, - activated: 'activated', - messageClicked: 'messageClicked', -}); -export const QSystemTrayIconActivationReason = Object.freeze({ - Unknown: 0, - Context: 1, - DoubleClick: 2, - Trigger: 3, - MiddleClick: 4, -}); -export class QSystemTrayIcon extends NodeObject { +interface QSystemTrayIconSignals { + activated: (reason: QSystemTrayIconActivationReason) => void; + messageClicked: () => void; +} + +export class QSystemTrayIcon extends NodeObject { native: NativeElement; contextMenu?: QMenu; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QSystemTrayIcon(parent.native); @@ -54,3 +48,11 @@ export class QSystemTrayIcon extends NodeObject { this.native.setContextMenu(this.contextMenu.native); } } + +export enum QSystemTrayIconActivationReason { + Unknown = 0, + Context = 1, + DoubleClick = 2, + Trigger = 3, + MiddleClick = 4, +} diff --git a/src/lib/QtWidgets/QTabWidget.ts b/src/lib/QtWidgets/QTabWidget.ts index 61825c619..50b2dac41 100644 --- a/src/lib/QtWidgets/QTabWidget.ts +++ b/src/lib/QtWidgets/QTabWidget.ts @@ -1,22 +1,22 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QIcon } from '../QtGui/QIcon'; import { TabPosition } from '../QtEnums'; -export const QTabWidgetEvents = Object.freeze({ - ...BaseWidgetEvents, - currentChanged: 'currentChanged', - tabBarClicked: 'tabBarClicked', - tabBarDoubleClicked: 'tabBarDoubleClicked', - tabCloseRequested: 'tabCloseRequested', -}); +interface QTabWidgetSignals { + currentChanged: (index: number) => void; + tabBarClicked: (index: number) => void; + tabBarDoubleClicked: (index: number) => void; + tabCloseRequested: (index: number) => void; +} -export class QTabWidget extends NodeWidget { +export class QTabWidget extends NodeWidget { native: NativeElement; - tabs: NodeWidget[]; - constructor(parent?: NodeWidget) { + tabs: NodeWidget[]; + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QTabWidget(parent.native); @@ -29,7 +29,7 @@ export class QTabWidget extends NodeWidget { this.native = native; } - addTab(page: NodeWidget, icon: QIcon, label: string): void { + addTab(page: NodeWidget, icon: QIcon, label: string): void { this.native.addTab(page.native, icon.native, label); this.tabs.push(page); page.setFlexNodeSizeControlled(true); diff --git a/src/lib/QtWidgets/QTableWidget.ts b/src/lib/QtWidgets/QTableWidget.ts index b1a0c591a..4fe93f439 100644 --- a/src/lib/QtWidgets/QTableWidget.ts +++ b/src/lib/QtWidgets/QTableWidget.ts @@ -1,35 +1,31 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement, Component } from '../core/Component'; import { ScrollHint, SortOrder } from '../QtEnums'; import { QTableWidgetItem } from './QTableWidgetItem'; import { QAbstractScrollArea } from './QAbstractScrollArea'; -export const QTableWidgetEvents = Object.freeze({ - ...BaseWidgetEvents, - cellActivated: 'cellActivated', - cellChanged: 'cellChanged', - cellClicked: 'cellClicked', - cellDoubleClicked: 'cellDoubleClicked', - cellEntered: 'cellEntered', - cellPressed: 'cellPressed', - currentCellChanged: 'currentCellChanged', -}); - -interface Range { - topRow: number; - rightColumn: number; - bottomRow: number; - leftColumn: number; - columnCount: number; - rowCount: number; +interface QTableWidgetSignals { + cellActivated: (row: number, col: number) => void; + cellChanged: (row: number, col: number) => void; + cellClicked: (row: number, col: number) => void; + cellDoubleClicked: (row: number, col: number) => void; + cellEntered: (row: number, col: number) => void; + cellPressed: (row: number, col: number) => void; + currentCellChanged: ( + currentRow: number, + currentColumn: number, + previousRow: number, + previousColumn: number, + ) => void; } -export class QTableWidget extends QAbstractScrollArea { +export class QTableWidget extends QAbstractScrollArea { native: NativeElement; items: Set; - constructor(rows: number, columns: number, parent?: NodeWidget) { + constructor(rows: number, columns: number); + constructor(rows: number, columns: number, parent: NodeWidget); + constructor(rows: number, columns: number, parent?: NodeWidget) { let native; if (parent) { native = new addon.QTableWidget(rows, columns, parent); @@ -50,7 +46,7 @@ export class QTableWidget extends QAbstractScrollArea { editItem(item: Component): void { this.native.editItem(item.native); } - setCellWidget(row: number, column: number, widget: NodeWidget): void { + setCellWidget(row: number, column: number, widget: NodeWidget): void { this.native.setCellWidget(row, column, widget.native); this.items.add(widget); } @@ -148,3 +144,12 @@ export class QTableWidget extends QAbstractScrollArea { return this.native.isSortingEnabled(); } } + +interface Range { + topRow: number; + rightColumn: number; + bottomRow: number; + leftColumn: number; + columnCount: number; + rowCount: number; +} diff --git a/src/lib/QtWidgets/QTableWidgetItem.ts b/src/lib/QtWidgets/QTableWidgetItem.ts index 39b5b7847..a168d9996 100644 --- a/src/lib/QtWidgets/QTableWidgetItem.ts +++ b/src/lib/QtWidgets/QTableWidgetItem.ts @@ -4,6 +4,8 @@ import { AlignmentFlag } from '../QtEnums'; export class QTableWidgetItem extends Component { native: NativeElement; + constructor(); + constructor(text: string); constructor(text?: string) { let native; if (text) { diff --git a/src/lib/QtWidgets/QToolButton.ts b/src/lib/QtWidgets/QToolButton.ts index 101d8314a..d9c4bdc38 100644 --- a/src/lib/QtWidgets/QToolButton.ts +++ b/src/lib/QtWidgets/QToolButton.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractButton } from './QAbstractButton'; import { ToolButtonStyle } from '../QtEnums/ToolButtonStyle'; @@ -14,18 +13,18 @@ export enum ToolButtonPopupMode { InstantPopup, } -export const QToolButtonEvents = Object.freeze({ - ...BaseWidgetEvents, - clicked: 'clicked', - pressed: 'pressed', - released: 'released', - toggled: 'toggled', - triggered: 'triggered', -}); - -export class QToolButton extends QAbstractButton { +interface QToolButtonSignals { + clicked: (checked: boolean) => void; + pressed: () => void; + released: () => void; + toggled: (checked: boolean) => void; + triggered: (nativeAction: NativeElement) => void; +} +export class QToolButton extends QAbstractButton { native: NativeElement; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QToolButton(parent.native); diff --git a/src/lib/QtWidgets/QTreeWidget.ts b/src/lib/QtWidgets/QTreeWidget.ts index d1bdb43af..aff2e2186 100644 --- a/src/lib/QtWidgets/QTreeWidget.ts +++ b/src/lib/QtWidgets/QTreeWidget.ts @@ -1,19 +1,19 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { QAbstractScrollArea } from './QAbstractScrollArea'; import { QTreeWidgetItem } from './QTreeWidgetItem'; -export const QTreeWidgetEvents = Object.freeze({ - ...BaseWidgetEvents, - itemSelectionChanged: 'itemSelectionChanged', -}); +interface QTreeWidgetSignals { + itemSelectionChanged: () => void; +} -export class QTreeWidget extends QAbstractScrollArea { +export class QTreeWidget extends QAbstractScrollArea { native: NativeElement; topLevelItems: Set; - constructor(parent?: NodeWidget) { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { native = new addon.QTreeWidget(parent.native); diff --git a/src/lib/QtWidgets/QTreeWidgetItem.ts b/src/lib/QtWidgets/QTreeWidgetItem.ts index 9fc3bf337..bd3c22ddf 100644 --- a/src/lib/QtWidgets/QTreeWidgetItem.ts +++ b/src/lib/QtWidgets/QTreeWidgetItem.ts @@ -5,7 +5,11 @@ import { QTreeWidget } from './QTreeWidget'; export class QTreeWidgetItem extends Component { native: NativeElement; - + constructor(); + constructor(parent: QTreeWidgetItem, strings?: string[]); + constructor(parent: QTreeWidget, strings?: string[]); + constructor(native: NativeElement); + constructor(strings: string[]); constructor(parent?: NativeElement | QTreeWidgetItem | QTreeWidget | string[], strings?: string[]) { super(); if (checkIfNativeElement(parent)) { diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index 4e0b5b2e9..75d7310f8 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeLayout } from './QLayout'; -import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component'; import { FlexLayout } from '../core/FlexLayout'; import { WidgetAttribute, WindowType } from '../QtEnums'; @@ -14,8 +13,8 @@ import { QSize } from '../QtCore/QSize'; import { QRect } from '../QtCore/QRect'; // All Widgets should extend from NodeWidget // Implement all native QWidget methods here so that all widgets get access to those aswell -export abstract class NodeWidget extends YogaWidget { - layout?: NodeLayout; +export abstract class NodeWidget extends YogaWidget { + layout?: NodeLayout; _rawInlineStyle = ''; type = 'widget'; show(): void { @@ -131,7 +130,7 @@ export abstract class NodeWidget extends YogaWidget { // react:⛔️ return this.native.setWindowFlag(windowType, switchOn); } - setLayout(parentLayout: NodeLayout): void { + setLayout(parentLayout: NodeLayout): void { const flexLayout = parentLayout as FlexLayout; this.native.setLayout(parentLayout.native); if (flexLayout.setFlexNode) { @@ -172,15 +171,16 @@ export abstract class NodeWidget extends YogaWidget { } } -export class QWidget extends NodeWidget { +type QWidgetSignals = {}; +export class QWidget extends NodeWidget { native: NativeElement; - constructor(arg?: NodeWidget | NativeElement) { + constructor(arg?: NodeWidget | NativeElement) { let native; let parent; if (checkIfNativeElement(arg)) { native = arg as NativeElement; - } else if (arg as NodeWidget) { - parent = arg as NodeWidget; + } else if (arg as NodeWidget) { + parent = arg as NodeWidget; native = new addon.QWidget(parent.native); } else { native = new addon.QWidget(); @@ -190,5 +190,3 @@ export class QWidget extends NodeWidget { this.native = native; } } - -export const QWidgetEvents = BaseWidgetEvents; diff --git a/src/lib/core/EventWidget.ts b/src/lib/core/EventWidget.ts index 99c42d500..1eaf936bc 100644 --- a/src/lib/core/EventWidget.ts +++ b/src/lib/core/EventWidget.ts @@ -1,8 +1,6 @@ import { EventEmitter } from 'events'; import { NativeElement, Component } from './Component'; - -export type NativeEvent = {}; -export abstract class EventWidget extends Component { +export abstract class EventWidget extends Component { private emitter: EventEmitter; constructor(native: NativeElement) { super(); @@ -14,167 +12,171 @@ export abstract class EventWidget extends Component { } } - addEventListener(eventType: string, callback: (payload?: NativeEvent | any) => void): void { - this.native.subscribeToQtEvent(eventType); - this.emitter.addListener(eventType, callback); + addEventListener(signalType: SignalType, callback: Signals[SignalType]): void; + addEventListener(eventType: WidgetEventTypes, callback: (event?: NativeElement) => void): void; + addEventListener(eventOrSignalType: string, callback: (...payloads: any[]) => void): void { + this.native.subscribeToQtEvent(eventOrSignalType); + this.emitter.addListener(eventOrSignalType, callback); } - removeEventListener(eventType: string, callback?: (payload?: NativeEvent | any) => void): void { + removeEventListener(signalType: SignalType, callback: Signals[SignalType]): void; + removeEventListener(eventType: WidgetEventTypes, callback: (event?: NativeElement) => void): void; + removeEventListener(eventOrSignalType: string, callback?: (...payloads: any[]) => void): void { if (callback) { - this.emitter.removeListener(eventType, callback); + this.emitter.removeListener(eventOrSignalType, callback); } else { - this.emitter.removeAllListeners(eventType); + this.emitter.removeAllListeners(eventOrSignalType); } - if (this.emitter.listenerCount(eventType) < 1) { - this.native.unSubscribeToQtEvent(eventType); + if (this.emitter.listenerCount(eventOrSignalType) < 1) { + this.native.unSubscribeToQtEvent(eventOrSignalType); } } } -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', -}); +export enum WidgetEventTypes { + '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', +} diff --git a/src/lib/core/FlexLayout.ts b/src/lib/core/FlexLayout.ts index d0f3015ea..a455ef1f6 100644 --- a/src/lib/core/FlexLayout.ts +++ b/src/lib/core/FlexLayout.ts @@ -4,16 +4,28 @@ import { NodeLayout } from '../QtWidgets/QLayout'; import { FlexNode } from './YogaWidget'; import { NativeElement } from './Component'; -export class FlexLayout extends NodeLayout { +type FlexLayoutSignals = {}; +export class FlexLayout extends NodeLayout { native: NativeElement; - constructor() { - const native = new addon.FlexLayout(); - super(native); - this.native = native; - } protected flexNode?: FlexNode; - addWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void { + constructor(); + constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { + let native; + if (parent) { + native = new addon.FlexLayout(parent.native); + } else { + native = new addon.FlexLayout(); + } + super(native); + this.native = native; + if (parent) { + this.setFlexNode(parent.getFlexNode()); + } + } + + addWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void { const childYogaNode = childFlexNode || childWidget.getFlexNode(); if (this.nodeChildren.has(childWidget)) { this.removeWidget(childWidget, childYogaNode); @@ -23,8 +35,8 @@ export class FlexLayout extends NodeLayout { } insertChildBefore( - childWidget: NodeWidget, - beforeChildWidget: NodeWidget, + childWidget: NodeWidget, + beforeChildWidget: NodeWidget, childFlexNode?: FlexNode, beforeChildFlexNode?: FlexNode, ): void { @@ -37,7 +49,7 @@ export class FlexLayout extends NodeLayout { this.native.insertChildBefore(childWidget.native, beforeChildYogaNode, childYogaNode); } - removeWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void { + removeWidget(childWidget: NodeWidget, childFlexNode?: FlexNode): void { if (!this.nodeChildren.has(childWidget)) { return; } diff --git a/src/lib/core/Style/StyleSheet.ts b/src/lib/core/Style/StyleSheet.ts index a635858f2..8f12148d3 100644 --- a/src/lib/core/Style/StyleSheet.ts +++ b/src/lib/core/Style/StyleSheet.ts @@ -13,7 +13,7 @@ export class StyleSheet { } } -export function prepareInlineStyleSheet(widget: NodeWidget, rawStyle: string): string { +export function prepareInlineStyleSheet(widget: NodeWidget, rawStyle: string): string { const inlineStyle = 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. diff --git a/src/lib/core/YogaWidget.ts b/src/lib/core/YogaWidget.ts index 2fd6829ef..88000fdf9 100644 --- a/src/lib/core/YogaWidget.ts +++ b/src/lib/core/YogaWidget.ts @@ -1,7 +1,7 @@ import { NodeObject } from '../QtCore/QObject'; export type FlexNode = {}; -export abstract class YogaWidget extends NodeObject { +export abstract class YogaWidget extends NodeObject { getFlexNode(): FlexNode { return this.native.getFlexNode(); }