381 const QRectF &viewRectF,
382 const QColor ¤tColor,
383 const QColor &baseColor)
385 qreal dpr = gc.device()->devicePixelRatioF();
386 QSizeF cacheSizeF = viewRectF.size() * dpr;
387 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
388 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
390 m_d->cache = QPixmap(cacheSize);
391 m_d->cache.fill(Qt::transparent);
394 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
395 bool canvasMirror =
m_d->canvas->xAxisMirrored();
396 if (needsNewCache || !
qFuzzyCompare(canvasRotationAngle,
m_d->cacheRotation) || canvasMirror !=
m_d->cacheMirror) {
397 m_d->cacheRotation = canvasRotationAngle;
398 m_d->cacheMirror = canvasMirror;
400 QPainter cachePainter(&
m_d->cache);
401 cachePainter.setRenderHint(QPainter::Antialiasing);
404 QRectF
rect(0.0, 0.0,
m_d->haveSample ? size * 2.0 : size, size);
408 QPointF offset = QRectF(
m_d->cache.rect()).center();
409 tf.translate(offset.x(), offset.y());
410 tf.rotate(canvasMirror ? canvasRotationAngle : -canvasRotationAngle);
411 cachePainter.setTransform(tf);
413 if (
m_d->haveSample) {
414 qreal centerX =
rect.center().x();
415 QRectF currentRect(
rect.topLeft(), QPointF(centerX + 1.0,
rect.bottom()));
416 QRectF baseRect(QPointF(centerX,
rect.top()),
rect.bottomRight());
417 if (
m_d->canvas->xAxisMirrored()) {
418 std::swap(currentRect, baseRect);
420 cachePainter.fillRect(currentRect, currentColor);
421 cachePainter.fillRect(baseRect, baseColor);
423 cachePainter.fillRect(
rect, currentColor);
427 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);
431 const QRectF &viewRectF,
432 const QColor ¤tColor,
433 const QColor &baseColor)
435 if (!
m_d->haveSample) {
443 qreal dpr = gc.device()->devicePixelRatioF();
444 QSizeF cacheSizeF = viewRectF.size() * dpr;
445 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
446 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
448 m_d->cache = QPixmap(cacheSize);
449 m_d->cache.fill(Qt::transparent);
452 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
453 if (
m_d->canvas->xAxisMirrored()) {
454 canvasRotationAngle = -canvasRotationAngle;
457 bool needsDualColor = currentColor != baseColor;
458 if (needsNewCache || (needsDualColor && !
qFuzzyCompare(
m_d->cacheRotation, canvasRotationAngle))) {
459 m_d->cacheRotation = canvasRotationAngle;
461 QPainter cachePainter(&
m_d->cache);
462 cachePainter.setRenderHint(QPainter::Antialiasing);
465 qreal penWidth =
m_d->circlePreviewDiameter > 100 ? (2.0 * dpr) : (1.0 * dpr);
466 QPen pen = QPen(backgroundColor, penWidth);
467 if (
m_d->circlePreviewOutlineEnabled) {
468 cachePainter.setPen(pen);
470 cachePainter.setPen(Qt::NoPen);
473 QRectF cacheRect =
m_d->cache.rect();
474 QRectF outerRect = cacheRect.marginsRemoved(QMarginsF(penWidth, penWidth, penWidth, penWidth));
478 QPointF cacheCenter = cacheRect.center();
479 tf.translate(cacheCenter.x(), cacheCenter.y());
480 tf.rotate(-canvasRotationAngle);
481 tf.translate(-cacheCenter.x(), -cacheCenter.y());
484 if (needsDualColor) {
490 QPainterPath clipPath;
491 clipPath.addPolygon(tf.map(QPolygonF(QRectF(0, 0, cacheRect.width(), cacheRect.height() / 2.0 + 1.0))));
492 cachePainter.setClipPath(clipPath);
494 bool flipped =
m_d->canvas->yAxisMirrored();
495 cachePainter.setBrush(flipped ? baseColor : currentColor);
496 cachePainter.drawEllipse(outerRect);
498 cachePainter.setBrush(baseColor);
501 tf.map(QRectF(0, cacheRect.height() / 2.0, cacheRect.width(), cacheRect.height() / 2.0)));
502 cachePainter.setClipPath(clipPath);
504 cachePainter.setBrush(flipped ? currentColor : baseColor);
505 cachePainter.drawEllipse(outerRect);
507 cachePainter.setClipPath(QPainterPath(), Qt::NoClip);
509 cachePainter.setBrush(currentColor);
510 cachePainter.drawEllipse(outerRect);
513 qreal innerX = cacheRect.width() * (1.0 -
m_d->circlePreviewThickness);
514 qreal innerY = cacheRect.height() * (1.0 -
m_d->circlePreviewThickness);
515 QRectF innerRect = cacheRect.marginsRemoved(QMarginsF(innerX, innerY, innerX, innerY));
516 QPainterPath innerEllipse;
517 innerEllipse.addEllipse(innerRect);
519 QPainterPath innerPath;
520 innerPath.addPath(innerEllipse);
523 if (
m_d->circlePreviewThickness < 0.5 &&
m_d->circlePreviewExtraCircles) {
524 qreal extraMargin = 0.1*
m_d->circlePreviewThickness*innerRect.width();
525 QPointF leftCenter = QPointF(innerRect.left() - extraMargin, innerRect.top() + innerRect.height()/2.0);
526 QPointF rightCenter = QPointF(innerRect.right() + extraMargin, innerRect.top() + innerRect.height()/2.0);
528 innerPath.setFillRule(Qt::OddEvenFill);
529 innerPath.addEllipse(leftCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
530 innerPath.addEllipse(rightCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
532 innerPath = innerPath.intersected(innerEllipse);
535 cachePainter.setPen(Qt::NoPen);
536 cachePainter.setCompositionMode(QPainter::CompositionMode_Clear);
537 cachePainter.drawPath(tf.map(innerPath));
539 if (
m_d->circlePreviewOutlineEnabled) {
540 cachePainter.setBrush(Qt::transparent);
541 cachePainter.setPen(pen);
542 cachePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
543 cachePainter.drawPath(tf.map(innerPath));
546 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);