From 300925260ed4e93fb40abf6d74bcd6a176b1f4ec Mon Sep 17 00:00:00 2001 From: Solant Date: Mon, 13 Apr 2020 11:18:30 +0300 Subject: [PATCH] Set cursor (#505) * implemented QCursor setter for QWidget::setCursor method * sorted includes, removed console.log statement from tests --- .../nodegui/QtWidgets/QWidget/qwidget_macro.h | 13 ++++++++++--- src/lib/QtWidgets/QWidget.ts | 6 +++++- src/lib/QtWidgets/__tests__/QWidget.test.ts | 7 +++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h index f26798705..a80a85e89 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h @@ -6,6 +6,7 @@ #include "QtCore/QObject/qobject_macro.h" #include "QtCore/QPoint/qpoint_wrap.h" #include "QtCore/QSize/qsize_wrap.h" +#include "QtGui/QCursor/qcursor_wrap.h" #include "QtGui/QIcon/qicon_wrap.h" #include "QtWidgets/QAction/qaction_wrap.h" #include "QtWidgets/QLayout/qlayout_wrap.h" @@ -117,9 +118,15 @@ Napi::Value setCursor(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ Napi::HandleScope scope(env); \ - Napi::Number cursor = info[0].As(); \ - this->instance->setCursor( \ - static_cast(cursor.Int32Value())); \ + if (info[0].IsNumber()) { \ + Napi::Number cursor = info[0].As(); \ + this->instance->setCursor( \ + static_cast(cursor.Int32Value())); \ + } else { \ + Napi::Object obj = info[0].As(); \ + QCursorWrap* wrap = Napi::ObjectWrap::Unwrap(obj); \ + this->instance->setCursor(*wrap->getInternalInstance()); \ + } \ return env.Null(); \ } \ Napi::Value setWindowIcon(const Napi::CallbackInfo& info) { \ diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index 6cb06c9ef..f201afc7b 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -136,7 +136,11 @@ export abstract class NodeWidget extends YogaWid } setCursor(cursor: CursorShape | QCursor): void { //TODO:getter - this.native.setCursor(cursor); + if (typeof cursor === 'number') { + this.native.setCursor(cursor); + } else { + this.native.setCursor(cursor.native); + } } setWindowIcon(icon: QIcon): void { //TODO:getter diff --git a/src/lib/QtWidgets/__tests__/QWidget.test.ts b/src/lib/QtWidgets/__tests__/QWidget.test.ts index a67aeca05..cd8653b5b 100644 --- a/src/lib/QtWidgets/__tests__/QWidget.test.ts +++ b/src/lib/QtWidgets/__tests__/QWidget.test.ts @@ -1,4 +1,6 @@ import { QWidget } from '../QWidget'; +import { CursorShape } from '../../QtEnums/CursorShape'; +import { QCursor } from '../../..'; describe('QWidget', () => { const view = new QWidget(); @@ -98,4 +100,9 @@ describe('QWidget', () => { expect(mock).toBeCalledWith('testName'); expect(mock).toBeCalledTimes(1); }); + it('should accept QCursor as setCursor argument', () => { + const widget = new QWidget(); + const cursor = new QCursor(CursorShape.BusyCursor); + expect(() => widget.setCursor(cursor)).not.toThrow(); + }); });