diff --git a/CMakeLists.txt b/CMakeLists.txt index 752fde426..7bdd5c41a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,9 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QMovie/qmovie_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QPalette/qpalette_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QStyle/qstyle_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QDate/qdate_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QDateTime/qdatetime_wrap.cpp" @@ -147,7 +149,6 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QStandardItem/qstandarditem_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QSvgWidget/qsvgwidget_wrap.cpp" - "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QStyleFactory/qstylefactory_wrap.cpp" # Custom widgets (include them for automoc since they contain Q_OBJECT) "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtCore/QAbstractItemModel/nabstractitemmodel.hpp" @@ -213,7 +214,6 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTextBrowser/ntextbrowser.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTextEdit/ntextedit.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QSvgWidget/nsvgwidget.hpp" - "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/nqdesktopwidget.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QHeaderView/nheaderview.hpp" ) diff --git a/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h b/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h index 5d4123c4d..0635b04f2 100644 --- a/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h +++ b/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h @@ -90,9 +90,9 @@ #endif // QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE -#ifndef QOBJECT_SIGNALS -#define QOBJECT_SIGNALS \ - QObject::connect(this, &QObject::objectNameChanged, \ +#ifndef QOBJECT_SIGNALS_ON_TARGET +#define QOBJECT_SIGNALS_ON_TARGET(target) \ + QObject::connect(target, &QObject::objectNameChanged, \ [=](const QString& objectName) { \ Napi::Env env = this->emitOnNode.Env(); \ Napi::HandleScope scope(env); \ @@ -100,5 +100,8 @@ {Napi::String::New(env, "objectNameChanged"), \ Napi::Value::From(env, objectName.toStdString())}); \ }); +#endif // QOBJECT_SIGNALS_ON_TARGET +#ifndef QOBJECT_SIGNALS +#define QOBJECT_SIGNALS QOBJECT_SIGNALS_ON_TARGET(this) #endif // QOBJECT_SIGNALS diff --git a/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h b/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h new file mode 100644 index 000000000..d53f02cbe --- /dev/null +++ b/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include +#include + +#include "Extras/Export/export.h" +#include "QtCore/QObject/qobject_macro.h" + +class DLL_EXPORT QScreenWrap : public Napi::ObjectWrap, public EventWidget { + QOBJECT_WRAPPED_METHODS_DECLARATION + // Note: We don't use EVENTWIDGET_IMPLEMENTATIONS() here because this class doesn't handle any QEvents. + + private: + QPointer instance; + + public: + // class constructor + static Napi::FunctionReference constructor; + + static Napi::Object init(Napi::Env env, Napi::Object exports); + QScreenWrap(const Napi::CallbackInfo& info); + QScreen* getInternalInstance(); + + virtual void connectSignalsToEventEmitter(); + + // Wrapped methods +}; diff --git a/src/cpp/include/nodegui/QtGui/QWindow/qwindow_wrap.h b/src/cpp/include/nodegui/QtGui/QWindow/qwindow_wrap.h new file mode 100644 index 000000000..0ae4009a3 --- /dev/null +++ b/src/cpp/include/nodegui/QtGui/QWindow/qwindow_wrap.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include +#include + +#include "Extras/Export/export.h" +#include "QtCore/QObject/qobject_macro.h" + +class DLL_EXPORT QWindowWrap : public Napi::ObjectWrap, public EventWidget { + QOBJECT_WRAPPED_METHODS_DECLARATION + // Note: We don't use EVENTWIDGET_IMPLEMENTATIONS() here because this class doesn't handle any QEvents. + + private: + QPointer instance; + + public: + // class constructor + static Napi::FunctionReference constructor; + + static Napi::Object init(Napi::Env env, Napi::Object exports); + QWindowWrap(const Napi::CallbackInfo& info); + QWindow* getInternalInstance(); + + virtual void connectSignalsToEventEmitter(); + + // wrapped methods + Napi::Value screen(const Napi::CallbackInfo& info); +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/nqdesktopwidget.hpp b/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/nqdesktopwidget.hpp deleted file mode 100644 index cd563fd87..000000000 --- a/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/nqdesktopwidget.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -#include "core/NodeWidget/nodewidget.h" - -class NQDesktopWidget : public QDesktopWidget, public NodeWidget { - public: - Q_OBJECT - NODEWIDGET_IMPLEMENTATIONS(QDesktopWidget) - public: - using QDesktopWidget::QDesktopWidget; // inherit all constructors of - // QStatusBar -}; diff --git a/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h deleted file mode 100644 index 845425907..000000000 --- a/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include - -#include "QtWidgets/QWidget/qwidget_macro.h" -#include "napi.h" -#include "nqdesktopwidget.hpp" - -class QDesktopWidgetWrap : public Napi::ObjectWrap { - private: - QPointer instance; - - public: - static Napi::Object init(Napi::Env env, Napi::Object exports); - QDesktopWidgetWrap(const Napi::CallbackInfo &info); - ~QDesktopWidgetWrap(); - NQDesktopWidget *getInternalInstance(); - static Napi::FunctionReference constructor; - // wrapped methods - Napi::Value availableGeometry(const Napi::CallbackInfo &info); - Napi::Value screenGeometry(const Napi::CallbackInfo &info); - Napi::Value screenNumber(const Napi::CallbackInfo &info); - - QWIDGET_WRAPPED_METHODS_DECLARATION -}; diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h index 91310178e..8fe90a218 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h @@ -10,6 +10,7 @@ #include "QtGui/QCursor/qcursor_wrap.h" #include "QtGui/QIcon/qicon_wrap.h" #include "QtGui/QStyle/qstyle_wrap.h" +#include "QtGui/QWindow/qwindow_wrap.h" #include "QtWidgets/QAction/qaction_wrap.h" #include "QtWidgets/QLayout/qlayout_wrap.h" #include "core/YogaWidget/yogawidget_macro.h" @@ -537,6 +538,17 @@ bool modified = info[0].As().Value(); \ this->instance->setWindowModified(modified); \ return env.Null(); \ + } \ + Napi::Value windowHandle(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + QWindow* window = this->instance->windowHandle(); \ + if (window) { \ + return QWindowWrap::constructor.New( \ + {Napi::External::New(env, window)}); \ + } else { \ + return env.Null(); \ + } \ } #endif // QWIDGET_WRAPPED_METHODS_DECLARATION @@ -613,7 +625,8 @@ InstanceMethod("setDisabled", &WidgetWrapName::setDisabled), \ InstanceMethod("setHidden", &WidgetWrapName::setHidden), \ InstanceMethod("setVisible", &WidgetWrapName::setVisible), \ - InstanceMethod("setWindowModified", &WidgetWrapName::setWindowModified), + InstanceMethod("setWindowModified", &WidgetWrapName::setWindowModified), \ + InstanceMethod("windowHandle", &WidgetWrapName::windowHandle), #endif // QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE diff --git a/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp b/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp new file mode 100644 index 000000000..0ab10ce8a --- /dev/null +++ b/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp @@ -0,0 +1,104 @@ +#include "QtGui/QScreen/qscreen_wrap.h" +#include "QtCore/QRect/qrect_wrap.h" +#include "QtCore/QSizeF/qsizef_wrap.h" +#include "Extras/Utils/nutils.h" + +Napi::FunctionReference QScreenWrap::constructor; + +Napi::Object QScreenWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QScreen"; + Napi::Function func = + DefineClass(env, CLASSNAME, + {//InstanceMethod("clear", &QScreenWrap::clear), + QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QScreenWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QScreenWrap::QScreenWrap(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + if (info[0].IsExternal()) { + this->instance = info[0].As>().Data(); + } else { + Napi::TypeError::New(env, "Incorrect initialization of QScreenWrap") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureComponent(this->getInternalInstance()); +} + +QScreen* QScreenWrap::getInternalInstance() { return this->instance; } + +void QScreenWrap::connectSignalsToEventEmitter() { + QOBJECT_SIGNALS_ON_TARGET(this->instance.data()); + + QObject::connect(this->instance.data(), &QScreen::availableGeometryChanged, [=](const QRect& geometry) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + auto instance = QRectWrap::constructor.New({Napi::External::New(env, + new QRect(geometry.x(), geometry.y(), geometry.width(), geometry.height()))}); + this->emitOnNode.Call({Napi::String::New(env, "availableGeometryChanged"), instance}); + }); + + QObject::connect(this->instance.data(), &QScreen::geometryChanged, [=](const QRect& geometry) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + auto instance = QRectWrap::constructor.New({Napi::External::New(env, + new QRect(geometry.x(), geometry.y(), geometry.width(), geometry.height()))}); + this->emitOnNode.Call({Napi::String::New(env, "geometryChanged"), instance}); + }); + + QObject::connect(this->instance.data(), &QScreen::logicalDotsPerInchChanged, [=](qreal dpi) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "logicalDotsPerInchChanged"), Napi::Value::From(env, dpi)}); + }); + + QObject::connect(this->instance.data(), &QScreen::orientationChanged, [=](Qt::ScreenOrientation orientation) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "orientationChanged"), Napi::Value::From(env, static_cast(orientation))}); + }); + + QObject::connect(this->instance.data(), &QScreen::physicalDotsPerInchChanged, [=](qreal dpi) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "physicalDotsPerInchChanged"), Napi::Value::From(env, dpi)}); + }); + + QObject::connect(this->instance.data(), &QScreen::physicalSizeChanged, [=](const QSizeF& size) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + auto instance = QSizeFWrap::constructor.New({Napi::External::New(env, + new QSizeF(size))}); + this->emitOnNode.Call({Napi::String::New(env, "physicalSizeChanged"), instance}); + }); + + QObject::connect(this->instance.data(), &QScreen::primaryOrientationChanged, [=](Qt::ScreenOrientation orientation) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "primaryOrientationChanged"), Napi::Value::From(env, static_cast(orientation))}); + }); + + QObject::connect(this->instance.data(), &QScreen::refreshRateChanged, [=](qreal refreshRate) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "refreshRateChanged"), Napi::Value::From(env, refreshRate)}); + }); + + QObject::connect(this->instance.data(), &QScreen::virtualGeometryChanged, [=](const QRect& rect) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + auto instance = QRectWrap::constructor.New({Napi::External::New(env, + new QRect(rect.x(), rect.y(), rect.width(), rect.height()))}); + this->emitOnNode.Call({Napi::String::New(env, "virtualGeometryChanged"), instance}); + }); +} diff --git a/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp b/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp new file mode 100644 index 000000000..4a994a080 --- /dev/null +++ b/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp @@ -0,0 +1,57 @@ +#include "QtGui/QWindow/qwindow_wrap.h" +#include "QtGui/QScreen/qscreen_wrap.h" +#include "Extras/Utils/nutils.h" + +Napi::FunctionReference QWindowWrap::constructor; + +Napi::Object QWindowWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QWindow"; + Napi::Function func = DefineClass( + env, CLASSNAME, + {InstanceMethod("screen", &QWindowWrap::screen), + QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QWindowWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QWindow* QWindowWrap::getInternalInstance() { return this->instance; } + +QWindowWrap::QWindowWrap(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + if (info.Length() == 1 && info[0].IsExternal()) { + this->instance = info[0].As>().Data(); + } else { + Napi::TypeError::New(env, "Wrong number of arguments to QWindow.") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureQObject(this->getInternalInstance()); +} + +void QWindowWrap::connectSignalsToEventEmitter() { + QOBJECT_SIGNALS_ON_TARGET(this->instance.data()); + + QObject::connect(this->instance.data(), &QWindow::screenChanged, [=](QScreen* screen) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "screenChanged")}); + }); +} + +Napi::Value QWindowWrap::screen(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + QScreen* screen = this->instance->screen(); + if (screen) { + auto instance = QScreenWrap::constructor.New( + {Napi::External::New(env, screen)}); + return instance; + } else { + return env.Null(); + } +} diff --git a/src/cpp/lib/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.cpp deleted file mode 100644 index 9bf8f5e50..000000000 --- a/src/cpp/lib/QtWidgets/QDesktopWidget/qdesktopwidget_wrap.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h" - -#include - -#include "Extras/Utils/nutils.h" -#include "QtCore/QRect/qrect_wrap.h" -#include "QtWidgets/QWidget/qwidget_wrap.h" - -Napi::FunctionReference QDesktopWidgetWrap::constructor; - -Napi::Object QDesktopWidgetWrap::init(Napi::Env env, Napi::Object exports) { - Napi::HandleScope scope(env); - char CLASSNAME[] = "QDesktopWidget"; - Napi::Function func = DefineClass( - env, CLASSNAME, - {InstanceMethod("screenGeometry", &QDesktopWidgetWrap::screenGeometry), - InstanceMethod("availableGeometry", - &QDesktopWidgetWrap::availableGeometry), - InstanceMethod("screenNumber", &QDesktopWidgetWrap::screenNumber), - QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QDesktopWidgetWrap)}); - constructor = Napi::Persistent(func); - exports.Set(CLASSNAME, func); - return exports; -} - -NQDesktopWidget *QDesktopWidgetWrap::getInternalInstance() { - return this->instance; -} - -QDesktopWidgetWrap::QDesktopWidgetWrap(const Napi::CallbackInfo &info) - : Napi::ObjectWrap(info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - if (info.Length() == 0) { - this->instance = new NQDesktopWidget(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); -} - -QDesktopWidgetWrap::~QDesktopWidgetWrap() { - extrautils::safeDelete(this->instance); -} - -Napi::Value QDesktopWidgetWrap::screenGeometry(const Napi::CallbackInfo &info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::Number screen = info[0].As(); - QRect rect = this->instance->screenGeometry(screen); - auto instance = QRectWrap::constructor.New( - {Napi::External::New(env, new QRect(rect))}); - return instance; -} - -Napi::Value QDesktopWidgetWrap::availableGeometry( - const Napi::CallbackInfo &info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::Number screen = info[0].As(); - QRect rect = this->instance->availableGeometry(screen); - auto instance = QRectWrap::constructor.New( - {Napi::External::New(env, new QRect(rect))}); - return instance; -} - -Napi::Value QDesktopWidgetWrap::screenNumber(const Napi::CallbackInfo &info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - int value = this->instance->screenNumber(); - return Napi::Value::From(env, value); -} diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 14963003c..ea7526d3e 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -45,7 +45,9 @@ #include "QtGui/QPen/qpen_wrap.h" #include "QtGui/QPicture/qpicture_wrap.h" #include "QtGui/QPixmap/qpixmap_wrap.h" +#include "QtGui/QScreen/qscreen_wrap.h" #include "QtGui/QStyle/qstyle_wrap.h" +#include "QtGui/QWindow/qwindow_wrap.h" #include "QtWidgets/QAction/qaction_wrap.h" #include "QtWidgets/QBoxLayout/qboxlayout_wrap.h" #include "QtWidgets/QButtonGroup/qbuttongroup_wrap.h" @@ -55,7 +57,6 @@ #include "QtWidgets/QComboBox/qcombobox_wrap.h" #include "QtWidgets/QDateEdit/qdateedit_wrap.h" #include "QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.h" -#include "QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h" #include "QtWidgets/QDial/qdial_wrap.h" #include "QtWidgets/QDialog/qdialog_wrap.h" #include "QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.h" @@ -225,13 +226,14 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QStandardItemModelWrap::init(env, exports); QStandardItemWrap::init(env, exports); QSvgWidgetWrap::init(env, exports); - QDesktopWidgetWrap::init(env, exports); QPaintEventWrap::init(env, exports); QPaletteWrap::init(env, exports); QAbstractItemModelWrap::init(env, exports); QHeaderViewWrap::init(env, exports); QItemSelectionModelWrap::init(env, exports); QStyleFactoryWrap::init(env, exports); + QScreenWrap::init(env, exports); + QWindowWrap::init(env, exports); return exports; } diff --git a/src/index.ts b/src/index.ts index a63d50611..6b0d63ac8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,6 +32,8 @@ export { QDropEvent } from './lib/QtGui/QEvent/QDropEvent'; export { QDragMoveEvent } from './lib/QtGui/QEvent/QDragMoveEvent'; export { QDragLeaveEvent } from './lib/QtGui/QEvent/QDragLeaveEvent'; export { QPaintEvent } from './lib/QtGui/QEvent/QPaintEvent'; +export { QScreen } from './lib/QtGui/QScreen'; +export { QWindow } from './lib/QtGui/QWindow'; export { WidgetEventTypes } from './lib/core/EventWidget'; // Abstract: export { NodeWidget, QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget'; @@ -61,7 +63,6 @@ export { QCheckBox, QCheckBoxSignals } from './lib/QtWidgets/QCheckBox'; export { QColorDialog, QColorDialogSignals } from './lib/QtWidgets/QColorDialog'; export { QDateEdit } from './lib/QtWidgets/QDateEdit'; export { QDateTimeEdit, NodeDateTimeEdit, QDateTimeEditSignals } from './lib/QtWidgets/QDateTimeEdit'; -export { QDesktopWidget } from './lib/QtWidgets/QDesktopWidget'; export { QLabel, QLabelSignals } from './lib/QtWidgets/QLabel'; export { QLCDNumber, QLCDNumberSignals, Mode, SegmentStyle } from './lib/QtWidgets/QLCDNumber'; export { QDial, QDialSignals } from './lib/QtWidgets/QDial'; diff --git a/src/lib/QtGui/QApplication.ts b/src/lib/QtGui/QApplication.ts index fdd9fad67..5802dbd80 100644 --- a/src/lib/QtGui/QApplication.ts +++ b/src/lib/QtGui/QApplication.ts @@ -4,7 +4,6 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QClipboard } from './QClipboard'; import { QStyle } from './QStyle'; import { QObjectSignals, NodeObject } from '../QtCore/QObject'; -import { QDesktopWidget } from '../QtWidgets/QDesktopWidget'; import { QPalette } from './QPalette'; import { StyleSheet } from '../core/Style/StyleSheet'; import memoizeOne from 'memoize-one'; @@ -80,9 +79,6 @@ export class QApplication extends NodeObject { static style(): QStyle { return new QStyle(addon.QApplication.style()); } - static desktop(): QDesktopWidget { - return new QDesktopWidget(); - } } export interface QApplicationSignals extends QObjectSignals { diff --git a/src/lib/QtGui/QScreen.ts b/src/lib/QtGui/QScreen.ts new file mode 100644 index 000000000..613f120d0 --- /dev/null +++ b/src/lib/QtGui/QScreen.ts @@ -0,0 +1,106 @@ +import { NativeElement } from '../core/Component'; +import { checkIfNativeElement } from '../utils/helpers'; +import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QRect } from '../QtCore/QRect'; +import { QSizeF } from '../QtCore/QSizeF'; +import { QSize } from '../QtCore/QSize'; + +export class QScreen extends NodeObject { + native: NativeElement; + constructor(native: NativeElement) { + super(native); + if (checkIfNativeElement(native)) { + this.native = native; + } else { + throw new Error('QScreen cannot be initialised this way.'); + } + } + + availableGeometry(): QRect { + return QRect.fromQVariant(this.property('availableGeometry')); + } + availableSize(): QSize { + return QSize.fromQVariant(this.property('availableSize')); + } + availableVirtualGeometry(): QRect { + return QRect.fromQVariant(this.property('availableVirtualGeometry')); + } + availableVirtualSize(): QSize { + return QSize.fromQVariant(this.property('availableVirtualSize')); + } + depth(): number { + return this.property('depth').toInt(); + } + devicePixelRatio(): number { + return this.property('devicePixelRatio').toDouble(); + } + geometry(): QRect { + return QRect.fromQVariant(this.property('geometry')); + } + logicalDotsPerInch(): number { + return this.property('logicalDotsPerInch').toDouble(); + } + logicalDotsPerInchX(): number { + return this.property('logicalDotsPerInchX').toDouble(); + } + logicalDotsPerInchY(): number { + return this.property('logicalDotsPerInchY').toDouble(); + } + manufacturer(): string { + return this.property('manufacturer').toString(); + } + model(): string { + return this.property('model').toString(); + } + name(): string { + return this.property('name').toString(); + } + nativeOrientation(): ScreenOrientation { + return this.property('nativeOrientation').toInt(); + } + orientation(): ScreenOrientation { + return this.property('orientation').toInt(); + } + physicalDotsPerInch(): number { + return this.property('physicalDotsPerInch').toDouble(); + } + physicalDotsPerInchX(): number { + return this.property('physicalDotsPerInchX').toDouble(); + } + physicalDotsPerInchY(): number { + return this.property('physicalDotsPerInchY').toDouble(); + } + physicalSize(): QSizeF { + return QSizeF.fromQVariant(this.property('physicalSize')); + } + primaryOrientation(): ScreenOrientation { + return this.property('primaryOrientation').toInt(); + } + refreshRate(): number { + return this.property('refreshRate').toDouble(); + } + serialNumber(): string { + return this.property('serialNumber').toString(); + } + size(): QSize { + return QSize.fromQVariant(this.property('size')); + } + virtualGeometry(): QRect { + return QRect.fromQVariant(this.property('virtualGeometry')); + } + virtualSize(): QSize { + return QSize.fromQVariant(this.property('virtualSize')); + } +} + +export interface QScreenSignals extends QObjectSignals { + availableGeometryChanged: (geometry: QRect) => void; + geometryChanged: (geometry: QRect) => void; + logicalDotsPerInchChanged: (dpi: number) => void; + orientationChanged: (orientation: ScreenOrientation) => void; + physicalDotsPerInchChanged: (dpi: number) => void; + physicalSizeChanged: (size: QSizeF) => void; + primaryOrientationChanged: (orientation: ScreenOrientation) => void; + refreshRateChanged: (refreshRate: number) => void; + virtualGeometryChanged: (rect: QRect) => void; +} diff --git a/src/lib/QtGui/QWindow.ts b/src/lib/QtGui/QWindow.ts new file mode 100644 index 000000000..0edec5903 --- /dev/null +++ b/src/lib/QtGui/QWindow.ts @@ -0,0 +1,26 @@ +import { NativeElement } from '../core/Component'; +import { checkIfNativeElement } from '../utils/helpers'; +import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QScreen } from './QScreen'; + +export class QWindow extends NodeObject { + native: NativeElement; + constructor(native: NativeElement) { + super(native); + + if (checkIfNativeElement(native)) { + this.native = native; + } else { + throw new Error('QWindow cannot be initialised this way.'); + } + } + + screen(): QScreen { + const screenNative = this.native.screen(); + return new QScreen(screenNative); + } +} + +export interface QWindowSignals extends QObjectSignals { + screenChanged: () => void; +} diff --git a/src/lib/QtWidgets/QDesktopWidget.ts b/src/lib/QtWidgets/QDesktopWidget.ts deleted file mode 100644 index 6cba77dbd..000000000 --- a/src/lib/QtWidgets/QDesktopWidget.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { QRect } from '../QtCore/QRect'; -import { NodeWidget, QWidgetSignals } from './QWidget'; -import { NativeElement } from '../core/Component'; -import addon from '../utils/addon'; - -/** - -> QDesktopWidget is a class that provides access to screen information on multi-head systems.. - -* **This class is a JS wrapper around Qt's [QDesktopWidget Class](https://doc.qt.io/qt-5/qdesktopwidget.html)** - -The QDesktopWidget class provides information about the user's desktop, such as its total size, number of screens, the geometry of each screen, and whether they are configured as separate desktops or a single virtual desktop. - -### Example - -```js -const { QDesktopWidget } = require("@nodegui/nodegui"); - -const desktop = new QDesktopWidget(); -const availableGeometry = desktop.availableGeometry(); -const screenGeometry = desktop.screenGeometry(); -console.log(availableGeometry.width() + 'x' + availableGeometry.height()); -console.log(screenGeometry.width() + 'x' + screenGeometry.height()); -console.log(desktop.screenNumber()); -``` - */ -export type QDesktopWidgetSignals = QWidgetSignals; -export class QDesktopWidget extends NodeWidget { - native: NativeElement; - constructor(parent?: NodeWidget) { - let native; - if (parent) { - native = new addon.QDesktopWidget(parent.native); - } else { - native = new addon.QDesktopWidget(); - } - super(native); - this.native = native; - this.nodeParent = parent; - } - availableGeometry(screen = -1): QRect { - return new QRect(this.native.availableGeometry(screen)); - } - screenGeometry(screen = -1): QRect { - return new QRect(this.native.screenGeometry(screen)); - } - screenNumber(): number { - return this.native.screenNumber(); - } -} diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index 437ec633a..5d52297fa 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -15,9 +15,10 @@ import { QRect } from '../QtCore/QRect'; import { QObjectSignals } from '../QtCore/QObject'; import { QFont } from '../QtGui/QFont'; import { QAction } from './QAction'; +import { QScreen } from '../QtGui/QScreen'; import memoizeOne from 'memoize-one'; import { QGraphicsEffect } from './QGraphicsEffect'; -import { QSizePolicyPolicy, QStyle } from '../..'; +import { QSizePolicyPolicy, QStyle, QWindow } from '../..'; /** @@ -246,6 +247,7 @@ export abstract class NodeWidget extends YogaWid resize(width: number, height: number): void { this.native.resize(width, height); } + // TODO: QScreen *QWidget::screen() const setAcceptDrops(on: boolean): void { this.native.setAcceptDrops(on); } @@ -421,7 +423,13 @@ export abstract class NodeWidget extends YogaWid // TODO: QWidget * window() const // TODO: QString windowFilePath() const // TODO: Qt::WindowFlags windowFlags() const - // TODO: QWindow * windowHandle() const + windowHandle(): QWindow | null { + const handle = this.native.windowHandle(); + if (handle != null) { + return new QWindow(handle); + } + return null; + } // TODO: QIcon windowIcon() const // TODO: Qt::WindowModality windowModality() const windowOpacity(): number {