diff --git a/src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp b/src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp index 8f6864c91..92c93f5ee 100644 --- a/src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp +++ b/src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp @@ -9,6 +9,7 @@ Napi::Object QPixmapWrap::init(Napi::Env env, Napi::Object exports) char CLASSNAME[] = "QPixmap"; Napi::Function func = DefineClass(env, CLASSNAME,{ InstanceMethod("load", &QPixmapWrap::load), + InstanceMethod("scaled",&QPixmapWrap::scaled), }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -20,9 +21,13 @@ QPixmapWrap::QPixmapWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(); - QString imageUrl = QString::fromUtf8(url.Utf8Value().c_str()); - this->instance = new QPixmap(imageUrl); + if(info[0].IsExternal()){ + this->instance = info[0].As>().Data(); + } else { + Napi::String url = info[0].As(); + QString imageUrl = QString::fromUtf8(url.Utf8Value().c_str()); + this->instance = new QPixmap(imageUrl); + } }else if (info.Length() == 0){ this->instance = new QPixmap(); }else { @@ -55,3 +60,14 @@ Napi::Value QPixmapWrap::load(const Napi::CallbackInfo& info) return Napi::Boolean::New(env, loadSuccess); } +Napi::Value QPixmapWrap::scaled(const Napi::CallbackInfo& info) +{ + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + Napi::Number width = info[0].As(); + Napi::Number height = info[1].As(); + + QPixmap* updatedPixMap = new QPixmap(this->instance->scaled(width, height)); + auto instance = QPixmapWrap::constructor.New({ Napi::External::New(env, updatedPixMap) }); + return instance; +} diff --git a/src/cpp/QtGui/QPixmap/qpixmap_wrap.h b/src/cpp/QtGui/QPixmap/qpixmap_wrap.h index ed0c7bdb3..dee7982e1 100644 --- a/src/cpp/QtGui/QPixmap/qpixmap_wrap.h +++ b/src/cpp/QtGui/QPixmap/qpixmap_wrap.h @@ -14,5 +14,6 @@ public: QPixmap* getInternalInstance(); // Wrapped methods Napi::Value load(const Napi::CallbackInfo& info); + Napi::Value scaled(const Napi::CallbackInfo& info); }; diff --git a/src/lib/QtGui/QPixmap/index.ts b/src/lib/QtGui/QPixmap/index.ts index 1990c01b0..2b18362c7 100644 --- a/src/lib/QtGui/QPixmap/index.ts +++ b/src/lib/QtGui/QPixmap/index.ts @@ -14,4 +14,7 @@ export class QPixmap extends Component { load = (imageUrl: string) => { return this.native.load(imageUrl); }; + scaled = (width: number, height: number) => { + return this.native.scaled(width, height); + }; }