Pass transformationMode to scaled method (#269)

This commit is contained in:
Maksim Karelov 2019-12-16 18:23:18 +03:00 committed by Atul R
parent 3af2ff5e02
commit 47ea1861da
2 changed files with 21 additions and 8 deletions

View File

@ -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<Napi::Number>().Int32Value();
aspectRatioMode = static_cast<Qt::AspectRatioMode>(aspectRatioModeInt);
}
QPixmap* updatedPixMap =
new QPixmap(this->instance->scaled(width, height, aspectRatioMode));
if (info.Length() > 3) {
int transformationModeInt = info[3].As<Napi::Number>().Int32Value();
transformationMode =
static_cast<Qt::TransformationMode>(transformationModeInt);
}
QPixmap* updatedPixMap = new QPixmap(this->instance->scaled(
width, height, aspectRatioMode, transformationMode));
auto instance = QPixmapWrap::constructor.New(
{Napi::External<QPixmap>::New(env, updatedPixMap)});
return instance;

View File

@ -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 {