void KisCoordinatesConverterTest::testImageCropping() { KisImageSP image; KisCoordinatesConverter converter; initImage(&image, &converter); converter.setImage(image); converter.setDocumentOffset(QPoint(0,0)); converter.setCanvasWidgetSize(QSize(500,500)); converter.setZoom(1.); // we do NOT crop here QCOMPARE(converter.viewportToImage(QRectF(900,900,200,200)), QRectF(900,900,200,200)); }
void KisCoordinatesConverterTest::testTransformations() { KisImageSP image; KisCoordinatesConverter converter; initImage(&image, &converter); converter.setImage(image); converter.setDocumentOffset(QPoint(20,30)); converter.setCanvasWidgetSize(QSize(500,500)); QRectF testRect(100,100,100,100); QTransform imageToWidget; QTransform documentToWidget; QTransform flakeToWidget; QTransform viewportToWidget; converter.setZoom(1.); imageToWidget = converter.imageToWidgetTransform(); documentToWidget = converter.documentToWidgetTransform(); flakeToWidget = converter.flakeToWidgetTransform(); viewportToWidget = converter.viewportToWidgetTransform(); CHECK_TRANSFORM(imageToWidget, testRect, QRectF(80,70,100,100)); CHECK_TRANSFORM(documentToWidget, testRect, QRectF(9980,9970,10000,10000)); CHECK_TRANSFORM(flakeToWidget, testRect, QRectF(80,70,100,100)); CHECK_TRANSFORM(viewportToWidget, testRect, QRectF(100,100,100,100)); converter.setZoom(0.5); imageToWidget = converter.imageToWidgetTransform(); documentToWidget = converter.documentToWidgetTransform(); flakeToWidget = converter.flakeToWidgetTransform(); viewportToWidget = converter.viewportToWidgetTransform(); CHECK_TRANSFORM(imageToWidget, testRect, QRectF(30,20,50,50)); CHECK_TRANSFORM(documentToWidget, testRect, QRectF(4980,4970,5000,5000)); CHECK_TRANSFORM(flakeToWidget, testRect, QRectF(80,70,100,100)); CHECK_TRANSFORM(viewportToWidget, testRect, QRectF(100,100,100,100)); }
void KisCoordinatesConverterTest::testConversion() { KisImageSP image; KisCoordinatesConverter converter; initImage(&image, &converter); converter.setImage(image); converter.setDocumentOffset(QPoint(20,20)); converter.setCanvasWidgetSize(QSize(500,500)); converter.setZoom(1.); QRectF testRect(100,100,100,100); QCOMPARE(converter.imageToViewport(testRect), QRectF(80,80,100,100)); QCOMPARE(converter.viewportToImage(testRect), QRectF(120,120,100,100)); QCOMPARE(converter.widgetToViewport(testRect), QRectF(100,100,100,100)); QCOMPARE(converter.viewportToWidget(testRect), QRectF(100,100,100,100)); QCOMPARE(converter.widgetToDocument(testRect), QRectF(1.20,1.20,1,1)); QCOMPARE(converter.documentToWidget(testRect), QRectF(9980,9980,10000,10000)); QCOMPARE(converter.imageToDocument(testRect), QRectF(1,1,1,1)); QCOMPARE(converter.documentToImage(testRect), QRectF(10000,10000,10000,10000)); converter.setZoom(0.5); QCOMPARE(converter.imageToViewport(testRect), QRectF(30,30,50,50)); QCOMPARE(converter.viewportToImage(testRect), QRectF(240,240,200,200)); QCOMPARE(converter.widgetToViewport(testRect), QRectF(100,100,100,100)); QCOMPARE(converter.viewportToWidget(testRect), QRectF(100,100,100,100)); QCOMPARE(converter.widgetToDocument(testRect), QRectF(2.4,2.4,2,2)); QCOMPARE(converter.documentToWidget(testRect), QRectF(4980,4980,5000,5000)); QCOMPARE(converter.imageToDocument(testRect), QRectF(1,1,1,1)); QCOMPARE(converter.documentToImage(testRect), QRectF(10000,10000,10000,10000)); }