555 const QRectF &viewRectF,
556 const QColor ¤tColor,
557 const QColor &baseColor)
559 qreal dpr = gc.device()->devicePixelRatioF();
560 QSizeF cacheSizeF = viewRectF.size() * dpr;
561 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
562 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
564 m_d->cache = QPixmap(cacheSize);
565 m_d->cache.fill(Qt::transparent);
568 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
569 bool canvasMirror =
m_d->canvas->xAxisMirrored();
570 if (needsNewCache || !
qFuzzyCompare(canvasRotationAngle,
m_d->cacheRotation) || canvasMirror !=
m_d->cacheMirror) {
571 m_d->cacheRotation = canvasRotationAngle;
572 m_d->cacheMirror = canvasMirror;
574 QPainter cachePainter(&
m_d->cache);
575 cachePainter.setRenderHint(QPainter::Antialiasing);
578 QRectF rect(0.0, 0.0,
m_d->haveSample ? size * 2.0 : size, size);
579 rect.moveTopLeft(-rect.center());
582 QPointF offset = QRectF(
m_d->cache.rect()).center();
583 tf.translate(offset.x(), offset.y());
584 tf.rotate(canvasMirror ? canvasRotationAngle : -canvasRotationAngle);
585 cachePainter.setTransform(tf);
587 if (
m_d->haveSample) {
588 qreal centerX = rect.center().x();
589 QRectF currentRect(rect.topLeft(), QPointF(centerX + 1.0, rect.bottom()));
590 QRectF baseRect(QPointF(centerX, rect.top()), rect.bottomRight());
591 if (
m_d->canvas->xAxisMirrored()) {
592 std::swap(currentRect, baseRect);
594 cachePainter.fillRect(currentRect, currentColor);
595 cachePainter.fillRect(baseRect, baseColor);
597 cachePainter.fillRect(rect, currentColor);
601 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);
605 const QRectF &viewRectF,
606 const QColor ¤tColor,
607 const QColor &baseColor)
609 if (!
m_d->haveSample) {
615 qreal dpr = gc.device()->devicePixelRatioF();
616 QSizeF cacheSizeF = viewRectF.size() * dpr;
617 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
618 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
620 m_d->cache = QPixmap(cacheSize);
621 m_d->cache.fill(Qt::transparent);
624 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
625 if (
m_d->canvas->xAxisMirrored()) {
626 canvasRotationAngle = -canvasRotationAngle;
629 QPainter cachePainter(&
m_d->cache);
630 cachePainter.setRenderHint(QPainter::Antialiasing);
632 QRectF cacheRect =
m_d->cache.rect();
637 QPointF cacheCenter = cacheRect.center();
639 tf.translate(cacheCenter.x(), cacheCenter.y());
640 tf.rotate(-canvasRotationAngle);
641 tf.translate(-cacheCenter.x(), -cacheCenter.y());
643 bool needsDualColor = currentColor != baseColor;
644 if (needsNewCache || (needsDualColor && !
qFuzzyCompare(
m_d->cacheRotation, canvasRotationAngle))) {
645 m_d->cacheRotation = canvasRotationAngle;
648 qreal penWidth =
m_d->circlePreviewDiameter > 100 ? (2.0 * dpr) : (1.0 * dpr);
649 QPen pen = QPen(backgroundColor, penWidth);
650 if (
m_d->circlePreviewOutlineEnabled) {
651 cachePainter.setPen(pen);
653 cachePainter.setPen(Qt::NoPen);
656 QRectF outerRect = cacheRect.marginsRemoved(QMarginsF(penWidth, penWidth, penWidth, penWidth));
658 if (needsDualColor) {
663 QPainterPath clipPath;
664 clipPath.addPolygon(tf.map(QPolygonF(QRectF(0, 0, cacheRect.width(), cacheRect.height() / 2.0 + 1.0))));
665 cachePainter.setClipPath(clipPath);
667 bool flipped =
m_d->canvas->yAxisMirrored();
668 cachePainter.setBrush(flipped ? baseColor : currentColor);
669 cachePainter.drawEllipse(outerRect);
671 cachePainter.setBrush(baseColor);
674 tf.map(QRectF(0, cacheRect.height() / 2.0, cacheRect.width(), cacheRect.height() / 2.0)));
675 cachePainter.setClipPath(clipPath);
677 cachePainter.setBrush(flipped ? currentColor : baseColor);
678 cachePainter.drawEllipse(outerRect);
680 cachePainter.setClipPath(QPainterPath(), Qt::NoClip);
682 cachePainter.setBrush(currentColor);
683 cachePainter.drawEllipse(outerRect);
686 qreal innerX = cacheRect.width() * (1.0 -
m_d->circlePreviewThickness);
687 qreal innerY = cacheRect.height() * (1.0 -
m_d->circlePreviewThickness);
688 QRectF innerRect = cacheRect.marginsRemoved(QMarginsF(innerX, innerY, innerX, innerY));
689 QPainterPath innerEllipse;
690 innerEllipse.addEllipse(innerRect);
692 QPainterPath innerPath;
693 innerPath.addPath(innerEllipse);
695 if (
m_d->circlePreviewThickness < 0.5 &&
m_d->circlePreviewExtraCircles) {
696 qreal extraMargin = 0.1*
m_d->circlePreviewThickness*innerRect.width();
697 QPointF leftCenter = QPointF(innerRect.left() - extraMargin, innerRect.top() + innerRect.height()/2.0);
698 QPointF rightCenter = QPointF(innerRect.right() + extraMargin, innerRect.top() + innerRect.height()/2.0);
700 innerPath.setFillRule(Qt::OddEvenFill);
701 innerPath.addEllipse(leftCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
702 innerPath.addEllipse(rightCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
704 innerPath = innerPath.intersected(innerEllipse);
707 m_d->cacheCircleInnerClip = innerPath;
710 if (
m_d->circlePreviewOutlineEnabled) {
711 cachePainter.setBrush(Qt::transparent);
712 cachePainter.setPen(pen);
713 cachePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
714 cachePainter.drawPath(tf.map(
m_d->cacheCircleInnerClip));
718 cachePainter.setPen(Qt::NoPen);
719 cachePainter.setBrush(
m_d->backgroundColor);
722 cachePainter.setCompositionMode(QPainter::CompositionMode_Clear);
723 cachePainter.drawPath(tf.map(
m_d->cacheCircleInnerClip));
727 bool shouldPaintPreview = !(
m_d->cacheCanvasPreviewImage.isNull() &&
m_d->canvasPreviewFetchCookie);
730 if (
m_d->circleZoomPreviewEnabled && (shouldPaintPreview ||
m_d->zoomPreviewHasPainted)) {
740 cachePainter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
741 cachePainter.drawPath(tf.map(
m_d->cacheCircleInnerClip));
743 m_d->zoomPreviewHasPainted =
true;
746 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);
794 if (!document || !document->referenceImagesLayer())
return;
798 gc.setCompositionMode(QPainter::CompositionMode_SourceOver);
799 gc.setClipPath(clip);
801 QRectF zoomDocRectF =
m_d->zoomDocRectF;
803 QList<KoShape*> shapeList = document->referenceImagesLayer()->shapeManager()->shapesAt(zoomDocRectF);
806 Q_FOREACH(
KoShape *shape, shapeList) {
808 if (!refImage)
continue;
820 qreal xScale = refImage->
size().width() / image.width();
821 qreal yScale = refImage->
size().height() / image.height();
824 if (xScale == 0 || yScale == 0)
continue;
826 QRect refPixelRect = QRect(refPixelPoint, QSize(zoomDocRectF.width() / xScale, zoomDocRectF.height() / yScale));
828 refPixelRect =
m_d->standardizeZoomPreviewPixelRect(refPixelRect);
830 refPixelRect.moveCenter(refPixelPoint);
834 gc.translate(viewRectF.center());
836 gc.translate(-viewRectF.center());
838 gc.drawImage(viewRectF, image, refPixelRect);