Add QScreen and QWindow, remove the deprecated QDesktopWidget

This commit is contained in:
Simon Edwards 2021-10-22 22:13:17 +02:00
parent 8ddc4172cd
commit bfd45b3a54
17 changed files with 390 additions and 182 deletions

View File

@ -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"
)

View File

@ -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

View File

@ -0,0 +1,29 @@
#pragma once
#include <napi.h>
#include <QScreen>
#include <QPointer>
#include "Extras/Export/export.h"
#include "QtCore/QObject/qobject_macro.h"
class DLL_EXPORT QScreenWrap : public Napi::ObjectWrap<QScreenWrap>, public EventWidget {
QOBJECT_WRAPPED_METHODS_DECLARATION
// Note: We don't use EVENTWIDGET_IMPLEMENTATIONS() here because this class doesn't handle any QEvents.
private:
QPointer<QScreen> 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
};

View File

@ -0,0 +1,30 @@
#pragma once
#include <napi.h>
#include <QWindow>
#include <QPointer>
#include "Extras/Export/export.h"
#include "QtCore/QObject/qobject_macro.h"
class DLL_EXPORT QWindowWrap : public Napi::ObjectWrap<QWindowWrap>, public EventWidget {
QOBJECT_WRAPPED_METHODS_DECLARATION
// Note: We don't use EVENTWIDGET_IMPLEMENTATIONS() here because this class doesn't handle any QEvents.
private:
QPointer<QWindow> 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);
};

View File

@ -1,15 +0,0 @@
#pragma once
#include <QApplication>
#include <QDesktopWidget>
#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
};

View File

@ -1,24 +0,0 @@
#pragma once
#include <QPointer>
#include "QtWidgets/QWidget/qwidget_macro.h"
#include "napi.h"
#include "nqdesktopwidget.hpp"
class QDesktopWidgetWrap : public Napi::ObjectWrap<QDesktopWidgetWrap> {
private:
QPointer<NQDesktopWidget> 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
};

View File

@ -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<Napi::Boolean>().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<QWindow>::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

View File

@ -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<QScreenWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info[0].IsExternal()) {
this->instance = info[0].As<Napi::External<QScreen>>().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<QRect>::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<QRect>::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<int>(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<QSizeF>::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<int>(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<QRect>::New(env,
new QRect(rect.x(), rect.y(), rect.width(), rect.height()))});
this->emitOnNode.Call({Napi::String::New(env, "virtualGeometryChanged"), instance});
});
}

View File

@ -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<QWindowWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 1 && info[0].IsExternal()) {
this->instance = info[0].As<Napi::External<QWindow>>().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<QScreen>::New(env, screen)});
return instance;
} else {
return env.Null();
}
}

View File

@ -1,78 +0,0 @@
#include "QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h"
#include <QWidget>
#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<QDesktopWidgetWrap>(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<Napi::Number>();
QRect rect = this->instance->screenGeometry(screen);
auto instance = QRectWrap::constructor.New(
{Napi::External<QRect>::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<Napi::Number>();
QRect rect = this->instance->availableGeometry(screen);
auto instance = QRectWrap::constructor.New(
{Napi::External<QRect>::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);
}

View File

@ -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;
}

View File

@ -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';

View File

@ -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<QApplicationSignals> {
static style(): QStyle {
return new QStyle(addon.QApplication.style());
}
static desktop(): QDesktopWidget {
return new QDesktopWidget();
}
}
export interface QApplicationSignals extends QObjectSignals {

106
src/lib/QtGui/QScreen.ts Normal file
View File

@ -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<QScreenSignals> {
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 <any>this.property('nativeOrientation').toInt();
}
orientation(): ScreenOrientation {
return <any>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 <any>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;
}

26
src/lib/QtGui/QWindow.ts Normal file
View File

@ -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<QWindowSignals> {
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;
}

View File

@ -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<QDesktopWidgetSignals> {
native: NativeElement;
constructor(parent?: NodeWidget<any>) {
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();
}
}

View File

@ -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<Signals extends QWidgetSignals> 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<Signals extends QWidgetSignals> 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 {