From 47ea1861dacaf004b7d9fa7b773bc26f180c37cb Mon Sep 17 00:00:00 2001 From: Maksim Karelov Date: Mon, 16 Dec 2019 18:23:18 +0300 Subject: [PATCH] Pass `transformationMode` to `scaled` method (#269) --- src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp | 10 ++++++++-- src/lib/QtGui/QPixmap.ts | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp b/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp index 6c73147ab..57dcdf7f5 100644 --- a/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp +++ b/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp @@ -115,12 +115,18 @@ Napi::Value QPixmapWrap::scaled(const Napi::CallbackInfo& info) { int width = widthValue.Int32Value(); int height = heightValue.Int32Value(); Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio; + Qt::TransformationMode transformationMode = Qt::FastTransformation; if (info.Length() > 2) { int aspectRatioModeInt = info[2].As().Int32Value(); aspectRatioMode = static_cast(aspectRatioModeInt); } - QPixmap* updatedPixMap = - new QPixmap(this->instance->scaled(width, height, aspectRatioMode)); + if (info.Length() > 3) { + int transformationModeInt = info[3].As().Int32Value(); + transformationMode = + static_cast(transformationModeInt); + } + QPixmap* updatedPixMap = new QPixmap(this->instance->scaled( + width, height, aspectRatioMode, transformationMode)); auto instance = QPixmapWrap::constructor.New( {Napi::External::New(env, updatedPixMap)}); return instance; diff --git a/src/lib/QtGui/QPixmap.ts b/src/lib/QtGui/QPixmap.ts index b06f50221..378ac48de 100644 --- a/src/lib/QtGui/QPixmap.ts +++ b/src/lib/QtGui/QPixmap.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { Component, NativeElement } from '../core/Component'; -import { AspectRatioMode } from '../QtEnums'; +import { AspectRatioMode, TransformationMode } from '../QtEnums'; import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from '../QtCore/QVariant'; @@ -29,13 +29,20 @@ export class QPixmap extends Component { save(fileName: string, format?: ImageFormats): boolean { return format ? this.native.save(fileName, format) : this.native.save(fileName); } - scaled(width: number, height: number, aspectRatioMode?: AspectRatioMode): QPixmap { - let nativePixmap; + scaled( + width: number, + height: number, + aspectRatioMode?: AspectRatioMode, + transformationMode?: TransformationMode, + ): QPixmap { + const args = [width, height]; if (aspectRatioMode) { - nativePixmap = this.native.scaled(width, height, aspectRatioMode); - } else { - nativePixmap = this.native.scaled(width, height); + args.push(aspectRatioMode); } + if (aspectRatioMode && transformationMode) { + args.push(transformationMode); + } + const nativePixmap = this.native.scaled(...args); return new QPixmap(nativePixmap); } height(): number {