void KisCoordinatesConverterTest::testRotation() { KisImageSP image; KisCoordinatesConverter converter; initImage(&image, &converter); QSize widgetSize(1000,500); QRectF testRect(800, 100, 300, 300); converter.setImage(image); converter.setDocumentOffset(QPoint(0,0)); converter.setCanvasWidgetSize(widgetSize); converter.rotate(converter.widgetCenterPoint(), 30); converter.setZoom(1.); QTransform viewportToWidget = converter.viewportToWidgetTransform(); QRectF boundingRect = viewportToWidget.mapRect(testRect); QRectF directRect = converter.viewportToWidget(testRect); QCOMPARE(boundingRect, directRect); QRectF referenceRect(QPointF(742.82,53.5898), QSizeF(409.808,409.808)); #define FUZZY(a,b) ((a)-(b) < 0.01) QVERIFY(FUZZY(boundingRect.top(), referenceRect.top())); QVERIFY(FUZZY(boundingRect.left(), referenceRect.left())); QVERIFY(FUZZY(boundingRect.width(), referenceRect.width())); QVERIFY(FUZZY(boundingRect.height(), referenceRect.height())); }
void KisCoordinatesConverterTest::testConsistency() { 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 viewportToWidget; converter.setZoom(0.5); imageToWidget = converter.imageToWidgetTransform(); documentToWidget = converter.documentToWidgetTransform(); viewportToWidget = converter.viewportToWidgetTransform(); QRectF fromImage = converter.viewportToWidget(converter.imageToViewport(testRect)); QRectF fromDocument = converter.documentToWidget(testRect); QRectF fromViewport = converter.viewportToWidget(testRect); CHECK_TRANSFORM(imageToWidget, testRect, fromImage); CHECK_TRANSFORM(documentToWidget, testRect, fromDocument); CHECK_TRANSFORM(viewportToWidget, testRect, fromViewport); }
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 KisQPainterCanvas::paintEvent(QPaintEvent * ev) { KisImageWSP image = canvas()->image(); if (image == 0) return; setAutoFillBackground(false); if (m_buffer.size() != size()) { m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); } QPainter gc(&m_buffer); // we double buffer, so we paint on an image first, then from the image onto the canvas, // so copy the clip region since otherwise we're filling the whole buffer every time with // the background color _and_ the transparent squares. gc.setClipRegion(ev->region()); KisCoordinatesConverter *converter = coordinatesConverter(); QTransform imageTransform = converter->viewportToWidgetTransform(); gc.save(); gc.setCompositionMode(QPainter::CompositionMode_Source); gc.fillRect(QRect(QPoint(0, 0), size()), borderColor()); QTransform checkersTransform; QPointF brushOrigin; QPolygonF polygon; converter->getQPainterCheckersInfo(&checkersTransform, &brushOrigin, &polygon); gc.setPen(Qt::NoPen); gc.setBrush(m_d->checkBrush); gc.setBrushOrigin(brushOrigin); gc.setTransform(checkersTransform); gc.drawPolygon(polygon); gc.setTransform(imageTransform); gc.setRenderHint(QPainter::SmoothPixmapTransform, true); QRectF viewportRect = converter->widgetToViewport(ev->rect()); gc.setCompositionMode(QPainter::CompositionMode_SourceOver); gc.drawImage(viewportRect, m_d->prescaledProjection->prescaledQImage(), viewportRect); gc.restore(); #ifdef DEBUG_REPAINT QColor color = QColor(random() % 255, random() % 255, random() % 255, 150); gc.fillRect(ev->rect(), color); #endif drawDecorations(gc, ev->rect()); gc.end(); QPainter painter(this); painter.drawImage(ev->rect(), m_buffer, ev->rect()); }