-
-
Notifications
You must be signed in to change notification settings - Fork 311
Added missing QWidget set methods and QCursor support #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ## Class: QCursor | ||
|
|
||
| > The QCursor class provides scalable icons in different modes and states. | ||
|
|
||
| **This class is a JS wrapper around Qt's [QCursor class](https://doc.qt.io/qt-5/qcursor.html)** | ||
|
|
||
| ### Example | ||
|
|
||
| ```javascript | ||
| const { QCursor } = require("@nodegui/nodegui"); | ||
|
|
||
| const cursor = new QCursor(); | ||
| ``` | ||
|
|
||
| ### `new QCursor(cursor)` | ||
|
|
||
| - `cursor` CursorShape (_optional_). Defines shape for the cursor. [CursorShape is an enum from Qt](api/QtEnums.md) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include "qcursor_wrap.h" | ||
| #include "src/cpp/Extras/Utils/nutils.h" | ||
| #include "deps/spdlog/spdlog.h" | ||
| #include "src/cpp/QtGui/QPixmap/qpixmap_wrap.h" | ||
|
|
||
| Napi::FunctionReference QCursorWrap::constructor; | ||
|
|
||
| Napi::Object QCursorWrap::init(Napi::Env env, Napi::Object exports) | ||
| { | ||
| Napi::HandleScope scope(env); | ||
| char CLASSNAME[] = "QCursor"; | ||
| Napi::Function func = DefineClass(env, CLASSNAME, { | ||
| InstanceMethod("pos", &QCursorWrap::pos), | ||
| InstanceMethod("setPos", &QCursorWrap::setPos), | ||
| COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE | ||
| }); | ||
| constructor = Napi::Persistent(func); | ||
| exports.Set(CLASSNAME, func); | ||
| return exports; | ||
| } | ||
|
|
||
| QCursorWrap::QCursorWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap<QCursorWrap>(info) | ||
| { | ||
| Napi::Env env = info.Env(); | ||
| Napi::HandleScope scope(env); | ||
| if (info.Length() == 1) | ||
| { | ||
| Napi::Number cursor = info[0].As<Napi::Number>(); | ||
| this->instance = new QCursor(static_cast<Qt::CursorShape>(cursor.Int32Value())); | ||
| } | ||
| else if (info.Length() == 0) | ||
| { | ||
| this->instance = new QCursor(); | ||
| } | ||
| else | ||
| { | ||
| Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException(); | ||
| } | ||
| } | ||
|
|
||
| QCursorWrap::~QCursorWrap() | ||
| { | ||
| delete this->instance; | ||
| } | ||
|
|
||
| QCursor *QCursorWrap::getInternalInstance() | ||
| { | ||
| return this->instance; | ||
| } | ||
|
|
||
| Napi::Value QCursorWrap::pos(const Napi::CallbackInfo& info) { | ||
| Napi::Env env = info.Env(); | ||
| Napi::HandleScope scope(env); | ||
| QPoint pos = this->instance->pos(); | ||
| Napi::Object posObj = Napi::Object::New(env); | ||
| posObj.Set("x", pos.x()); | ||
| posObj.Set("y", pos.y()); | ||
| return posObj; | ||
| } | ||
|
|
||
| Napi::Value QCursorWrap::setPos(const Napi::CallbackInfo& info) { | ||
| Napi::Env env = info.Env(); | ||
| Napi::HandleScope scope(env); | ||
| Napi::Number x = info[0].As<Napi::Number>(); | ||
| Napi::Number y = info[1].As<Napi::Number>(); | ||
| this->instance->setPos(x.Int32Value(), y.Int32Value()); | ||
| return env.Null(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #pragma once | ||
|
|
||
| #include <napi.h> | ||
| #include <QCursor> | ||
| #include "src/cpp/core/Component/component_macro.h" | ||
|
|
||
| class QCursorWrap : public Napi::ObjectWrap<QCursorWrap> | ||
| { | ||
| private: | ||
| QCursor *instance; | ||
|
|
||
| public: | ||
| static Napi::FunctionReference constructor; | ||
| static Napi::Object init(Napi::Env env, Napi::Object exports); | ||
| QCursorWrap(const Napi::CallbackInfo &info); | ||
| ~QCursorWrap(); | ||
| QCursor *getInternalInstance(); | ||
| // Wrapped methods | ||
| Napi::Value pos(const Napi::CallbackInfo& info); | ||
| Napi::Value setPos(const Napi::CallbackInfo& info); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import addon from "../../core/addon"; | ||
| import { Component, NativeElement } from "../../core/Component"; | ||
| import { QPixmap } from "../QPixmap"; | ||
|
|
||
| type arg = NativeElement | number | QPixmap; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be just number
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually was left intentionally because I intend to add full support for QBitmap /QPixmap/QMasks/QCursor instances cursors, just did not have time on hand right now.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No its okay. Let it be.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will merge this PR then ? @Uriziel01
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM 👍 |
||
| export class QCursor extends Component { | ||
| native: NativeElement; | ||
| constructor(arg?: arg) { | ||
| super(); | ||
| if (arg) { | ||
| this.native = new addon.QCursor(arg); | ||
| } else { | ||
| this.native = new addon.QCursor(); | ||
| } | ||
| } | ||
| pos = (): { x: number; y: number } => { | ||
| return this.native.pos(); | ||
| } | ||
| setPos = (x: number, y: number) => { | ||
| return this.native.setPos(x, y); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉