From ec82a760edf56ac0677bacd39148cf04fceee52b Mon Sep 17 00:00:00 2001 From: Balthild Date: Tue, 17 Sep 2019 11:34:08 +0800 Subject: [PATCH 1/3] Converting QIcon ot QPixmap --- src/cpp/QtGui/QIcon/qicon_wrap.cpp | 29 +++++++++++++++++++++++++++++ src/cpp/QtGui/QIcon/qicon_wrap.h | 1 + src/lib/QtGui/QIcon/index.ts | 20 ++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/src/cpp/QtGui/QIcon/qicon_wrap.cpp b/src/cpp/QtGui/QIcon/qicon_wrap.cpp index 218a744de..10e7d614e 100644 --- a/src/cpp/QtGui/QIcon/qicon_wrap.cpp +++ b/src/cpp/QtGui/QIcon/qicon_wrap.cpp @@ -1,4 +1,5 @@ #include "qicon_wrap.h" +#include "src/cpp/QtGui/QPixmap/qpixmap_wrap.h" #include "src/cpp/Extras/Utils/nutils.h" #include "deps/spdlog/spdlog.h" @@ -9,6 +10,7 @@ Napi::Object QIconWrap::init(Napi::Env env, Napi::Object exports) Napi::HandleScope scope(env); char CLASSNAME[] = "QIcon"; Napi::Function func = DefineClass(env, CLASSNAME, { + InstanceMethod("pixmap", &QIconWrap::pixmap), COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE }); constructor = Napi::Persistent(func); @@ -45,3 +47,30 @@ QIcon *QIconWrap::getInternalInstance() { return this->instance.get(); } + +Napi::Value QIconWrap::pixmap(const Napi::CallbackInfo& info) +{ + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + Napi::Number widthValue = info[0].As(); + Napi::Number heightValue = info[1].As(); + int width = widthValue.Int32Value(); + int height = heightValue.Int32Value(); + + QIcon::Mode mode = QIcon::Normal; + if (info.Length() > 2){ + int modeInt = info[2].As().Int32Value(); + mode = static_cast(modeInt); + } + + QIcon::State state = QIcon::Off; + if (info.Length() > 3){ + int stateInt = info[3].As().Int32Value(); + state = static_cast(stateInt); + } + + QPixmap* pixmap = new QPixmap(this->instance->pixmap(width, height, mode)); + auto instance = QPixmapWrap::constructor.New({ Napi::External::New(env, pixmap) }); + return instance; +} diff --git a/src/cpp/QtGui/QIcon/qicon_wrap.h b/src/cpp/QtGui/QIcon/qicon_wrap.h index a4e9dd953..549a0e60c 100644 --- a/src/cpp/QtGui/QIcon/qicon_wrap.h +++ b/src/cpp/QtGui/QIcon/qicon_wrap.h @@ -17,4 +17,5 @@ public: ~QIconWrap(); QIcon *getInternalInstance(); // Wrapped methods + Napi::Value pixmap(const Napi::CallbackInfo& info); }; diff --git a/src/lib/QtGui/QIcon/index.ts b/src/lib/QtGui/QIcon/index.ts index 70c1de6a2..4405ec5dd 100644 --- a/src/lib/QtGui/QIcon/index.ts +++ b/src/lib/QtGui/QIcon/index.ts @@ -1,5 +1,9 @@ import addon from "../../core/addon"; import { Component, NativeElement } from "../../core/Component"; +import { QPixmap } from "../../QtGui/QPixmap"; + +export enum QIconMode { Normal, Disabled, Active, Selected } +export enum QIconState { Off, On } type arg = string | NativeElement; export class QIcon extends Component { @@ -13,4 +17,20 @@ export class QIcon extends Component { this.native = new addon.QIcon(); } } + pixmap = ( + width: number, + height: number, + mode?: QIconMode, + state?: QIconState, + ): QPixmap => { + let nativePixmap; + if (mode && state) { + nativePixmap = this.native.pixmap(width, height, mode, state); + } else if (mode) { + nativePixmap = this.native.pixmap(width, height, mode); + } else { + nativePixmap = this.native.pixmap(width, height); + } + return new QPixmap(nativePixmap); + }; } From ec5c560ca1396859f440f0cc009d0e808d891b2a Mon Sep 17 00:00:00 2001 From: Balthild Date: Tue, 17 Sep 2019 11:37:36 +0800 Subject: [PATCH 2/3] Fix code format --- src/cpp/QtGui/QIcon/qicon_wrap.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cpp/QtGui/QIcon/qicon_wrap.cpp b/src/cpp/QtGui/QIcon/qicon_wrap.cpp index 10e7d614e..d2a7642c5 100644 --- a/src/cpp/QtGui/QIcon/qicon_wrap.cpp +++ b/src/cpp/QtGui/QIcon/qicon_wrap.cpp @@ -59,15 +59,15 @@ Napi::Value QIconWrap::pixmap(const Napi::CallbackInfo& info) int height = heightValue.Int32Value(); QIcon::Mode mode = QIcon::Normal; - if (info.Length() > 2){ - int modeInt = info[2].As().Int32Value(); - mode = static_cast(modeInt); + if (info.Length() > 2) { + int modeInt = info[2].As().Int32Value(); + mode = static_cast(modeInt); } QIcon::State state = QIcon::Off; - if (info.Length() > 3){ - int stateInt = info[3].As().Int32Value(); - state = static_cast(stateInt); + if (info.Length() > 3) { + int stateInt = info[3].As().Int32Value(); + state = static_cast(stateInt); } QPixmap* pixmap = new QPixmap(this->instance->pixmap(width, height, mode)); From fbb2b12d85aba4c43775b8cc6cedcb36a2b43276 Mon Sep 17 00:00:00 2001 From: Balthild Date: Tue, 17 Sep 2019 14:58:16 +0800 Subject: [PATCH 3/3] Fix mode arg --- src/cpp/QtGui/QIcon/qicon_wrap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/QtGui/QIcon/qicon_wrap.cpp b/src/cpp/QtGui/QIcon/qicon_wrap.cpp index d2a7642c5..5185c6768 100644 --- a/src/cpp/QtGui/QIcon/qicon_wrap.cpp +++ b/src/cpp/QtGui/QIcon/qicon_wrap.cpp @@ -70,7 +70,7 @@ Napi::Value QIconWrap::pixmap(const Napi::CallbackInfo& info) state = static_cast(stateInt); } - QPixmap* pixmap = new QPixmap(this->instance->pixmap(width, height, mode)); + QPixmap* pixmap = new QPixmap(this->instance->pixmap(width, height, mode, state)); auto instance = QPixmapWrap::constructor.New({ Napi::External::New(env, pixmap) }); return instance; }