545 const QRectF &viewRectF,
546 const QColor ¤tColor,
547 const QColor &baseColor)
549 qreal dpr = gc.device()->devicePixelRatioF();
550 QSizeF cacheSizeF = viewRectF.size() * dpr;
551 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
552 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
554 m_d->cache = QPixmap(cacheSize);
555 m_d->cache.fill(Qt::transparent);
558 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
559 bool canvasMirror =
m_d->canvas->xAxisMirrored();
560 if (needsNewCache || !
qFuzzyCompare(canvasRotationAngle,
m_d->cacheRotation) || canvasMirror !=
m_d->cacheMirror) {
561 m_d->cacheRotation = canvasRotationAngle;
562 m_d->cacheMirror = canvasMirror;
564 QPainter cachePainter(&
m_d->cache);
565 cachePainter.setRenderHint(QPainter::Antialiasing);
568 QRectF rect(0.0, 0.0,
m_d->haveSample ? size * 2.0 : size, size);
569 rect.moveTopLeft(-rect.center());
572 QPointF offset = QRectF(
m_d->cache.rect()).center();
573 tf.translate(offset.x(), offset.y());
574 tf.rotate(canvasMirror ? canvasRotationAngle : -canvasRotationAngle);
575 cachePainter.setTransform(tf);
577 if (
m_d->haveSample) {
578 qreal centerX = rect.center().x();
579 QRectF currentRect(rect.topLeft(), QPointF(centerX + 1.0, rect.bottom()));
580 QRectF baseRect(QPointF(centerX, rect.top()), rect.bottomRight());
581 if (
m_d->canvas->xAxisMirrored()) {
582 std::swap(currentRect, baseRect);
584 cachePainter.fillRect(currentRect, currentColor);
585 cachePainter.fillRect(baseRect, baseColor);
587 cachePainter.fillRect(rect, currentColor);
591 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);
595 const QRectF &viewRectF,
596 const QColor ¤tColor,
597 const QColor &baseColor)
599 if (!
m_d->haveSample) {
605 qreal dpr = gc.device()->devicePixelRatioF();
606 QSizeF cacheSizeF = viewRectF.size() * dpr;
607 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
608 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
610 m_d->cache = QPixmap(cacheSize);
611 m_d->cache.fill(Qt::transparent);
614 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
615 if (
m_d->canvas->xAxisMirrored()) {
616 canvasRotationAngle = -canvasRotationAngle;
619 QPainter cachePainter(&
m_d->cache);
620 cachePainter.setRenderHint(QPainter::Antialiasing);
622 QRectF cacheRect =
m_d->cache.rect();
627 QPointF cacheCenter = cacheRect.center();
629 tf.translate(cacheCenter.x(), cacheCenter.y());
630 tf.rotate(-canvasRotationAngle);
631 tf.translate(-cacheCenter.x(), -cacheCenter.y());
633 bool needsDualColor = currentColor != baseColor;
634 if (needsNewCache || (needsDualColor && !
qFuzzyCompare(
m_d->cacheRotation, canvasRotationAngle))) {
635 m_d->cacheRotation = canvasRotationAngle;
638 qreal penWidth =
m_d->circlePreviewDiameter > 100 ? (2.0 * dpr) : (1.0 * dpr);
639 QPen pen = QPen(backgroundColor, penWidth);
640 if (
m_d->circlePreviewOutlineEnabled) {
641 cachePainter.setPen(pen);
643 cachePainter.setPen(Qt::NoPen);
646 QRectF outerRect = cacheRect.marginsRemoved(QMarginsF(penWidth, penWidth, penWidth, penWidth));
648 if (needsDualColor) {
653 QPainterPath clipPath;
654 clipPath.addPolygon(tf.map(QPolygonF(QRectF(0, 0, cacheRect.width(), cacheRect.height() / 2.0 + 1.0))));
655 cachePainter.setClipPath(clipPath);
657 bool flipped =
m_d->canvas->yAxisMirrored();
658 cachePainter.setBrush(flipped ? baseColor : currentColor);
659 cachePainter.drawEllipse(outerRect);
661 cachePainter.setBrush(baseColor);
664 tf.map(QRectF(0, cacheRect.height() / 2.0, cacheRect.width(), cacheRect.height() / 2.0)));
665 cachePainter.setClipPath(clipPath);
667 cachePainter.setBrush(flipped ? currentColor : baseColor);
668 cachePainter.drawEllipse(outerRect);
670 cachePainter.setClipPath(QPainterPath(), Qt::NoClip);
672 cachePainter.setBrush(currentColor);
673 cachePainter.drawEllipse(outerRect);
676 qreal innerX = cacheRect.width() * (1.0 -
m_d->circlePreviewThickness);
677 qreal innerY = cacheRect.height() * (1.0 -
m_d->circlePreviewThickness);
678 QRectF innerRect = cacheRect.marginsRemoved(QMarginsF(innerX, innerY, innerX, innerY));
679 QPainterPath innerEllipse;
680 innerEllipse.addEllipse(innerRect);
682 QPainterPath innerPath;
683 innerPath.addPath(innerEllipse);
685 if (
m_d->circlePreviewThickness < 0.5 &&
m_d->circlePreviewExtraCircles) {
686 qreal extraMargin = 0.1*
m_d->circlePreviewThickness*innerRect.width();
687 QPointF leftCenter = QPointF(innerRect.left() - extraMargin, innerRect.top() + innerRect.height()/2.0);
688 QPointF rightCenter = QPointF(innerRect.right() + extraMargin, innerRect.top() + innerRect.height()/2.0);
690 innerPath.setFillRule(Qt::OddEvenFill);
691 innerPath.addEllipse(leftCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
692 innerPath.addEllipse(rightCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
694 innerPath = innerPath.intersected(innerEllipse);
697 m_d->cacheCircleInnerClip = innerPath;
700 if (
m_d->circlePreviewOutlineEnabled) {
701 cachePainter.setBrush(Qt::transparent);
702 cachePainter.setPen(pen);
703 cachePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
704 cachePainter.drawPath(tf.map(
m_d->cacheCircleInnerClip));
708 cachePainter.setPen(Qt::NoPen);
709 cachePainter.setBrush(
m_d->backgroundColor);
712 cachePainter.setCompositionMode(QPainter::CompositionMode_Clear);
713 cachePainter.drawPath(tf.map(
m_d->cacheCircleInnerClip));
717 bool shouldPaintPreview = !(
m_d->cacheCanvasPreviewImage.isNull() &&
m_d->canvasPreviewFetchCookie);
720 if (
m_d->circleZoomPreviewEnabled && (shouldPaintPreview ||
m_d->zoomPreviewHasPainted)) {
730 cachePainter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
731 cachePainter.drawPath(tf.map(
m_d->cacheCircleInnerClip));
733 m_d->zoomPreviewHasPainted =
true;
736 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);
784 if (!document || !document->referenceImagesLayer())
return;
788 gc.setCompositionMode(QPainter::CompositionMode_SourceOver);
789 gc.setClipPath(clip);
791 QRectF zoomDocRectF =
m_d->zoomDocRectF;
793 QList<KoShape*> shapeList = document->referenceImagesLayer()->shapeManager()->shapesAt(zoomDocRectF);
796 Q_FOREACH(
KoShape *shape, shapeList) {
798 if (!refImage)
continue;
810 qreal xScale = refImage->
size().width() / image.width();
811 qreal yScale = refImage->
size().height() / image.height();
814 if (xScale == 0 || yScale == 0)
continue;
816 QRect refPixelRect = QRect(refPixelPoint, QSize(zoomDocRectF.width() / xScale, zoomDocRectF.height() / yScale));
818 refPixelRect =
m_d->standardizeZoomPreviewPixelRect(refPixelRect);
820 refPixelRect.moveCenter(refPixelPoint);
824 gc.translate(viewRectF.center());
826 gc.translate(-viewRectF.center());
828 gc.drawImage(viewRectF, image, refPixelRect);