376 const QRectF &viewRectF,
377 const QColor ¤tColor,
378 const QColor &baseColor)
380 qreal dpr = gc.device()->devicePixelRatioF();
381 QSizeF cacheSizeF = viewRectF.size() * dpr;
382 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
383 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
385 m_d->cache = QPixmap(cacheSize);
386 m_d->cache.fill(Qt::transparent);
389 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
390 bool canvasMirror =
m_d->canvas->xAxisMirrored();
391 if (needsNewCache || !
qFuzzyCompare(canvasRotationAngle,
m_d->cacheRotation) || canvasMirror !=
m_d->cacheMirror) {
392 m_d->cacheRotation = canvasRotationAngle;
393 m_d->cacheMirror = canvasMirror;
395 QPainter cachePainter(&
m_d->cache);
396 cachePainter.setRenderHint(QPainter::Antialiasing);
399 QRectF
rect(0.0, 0.0,
m_d->haveSample ? size * 2.0 : size, size);
403 QPointF offset = QRectF(
m_d->cache.rect()).center();
404 tf.translate(offset.x(), offset.y());
405 tf.rotate(canvasMirror ? canvasRotationAngle : -canvasRotationAngle);
406 cachePainter.setTransform(tf);
408 if (
m_d->haveSample) {
409 qreal centerX =
rect.center().x();
410 QRectF currentRect(
rect.topLeft(), QPointF(centerX + 1.0,
rect.bottom()));
411 QRectF baseRect(QPointF(centerX,
rect.top()),
rect.bottomRight());
412 if (
m_d->canvas->xAxisMirrored()) {
413 std::swap(currentRect, baseRect);
415 cachePainter.fillRect(currentRect, currentColor);
416 cachePainter.fillRect(baseRect, baseColor);
418 cachePainter.fillRect(
rect, currentColor);
422 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);
426 const QRectF &viewRectF,
427 const QColor ¤tColor,
428 const QColor &baseColor)
430 if (!
m_d->haveSample) {
438 qreal dpr = gc.device()->devicePixelRatioF();
439 QSizeF cacheSizeF = viewRectF.size() * dpr;
440 QSize cacheSize(qCeil(cacheSizeF.width()), qCeil(cacheSizeF.height()));
441 bool needsNewCache =
m_d->cache.isNull() ||
m_d->cache.size() != cacheSize;
443 m_d->cache = QPixmap(cacheSize);
444 m_d->cache.fill(Qt::transparent);
447 qreal canvasRotationAngle =
m_d->canvas->rotationAngle();
448 if (
m_d->canvas->xAxisMirrored()) {
449 canvasRotationAngle = -canvasRotationAngle;
452 bool needsDualColor = currentColor != baseColor;
453 if (needsNewCache || (needsDualColor && !
qFuzzyCompare(
m_d->cacheRotation, canvasRotationAngle))) {
454 m_d->cacheRotation = canvasRotationAngle;
456 QPainter cachePainter(&
m_d->cache);
457 cachePainter.setRenderHint(QPainter::Antialiasing);
459 QColor backgroundColor = colorWithAlpha(qApp->palette().color(QPalette::Base),
OPACITY_OPAQUE_U8 / 2 + 1);
460 qreal penWidth =
m_d->circlePreviewDiameter > 100 ? (2.0 * dpr) : (1.0 * dpr);
461 QPen pen = QPen(backgroundColor, penWidth);
462 if (
m_d->circlePreviewOutlineEnabled) {
463 cachePainter.setPen(pen);
465 cachePainter.setPen(Qt::NoPen);
468 QRectF cacheRect =
m_d->cache.rect();
469 QRectF outerRect = cacheRect.marginsRemoved(QMarginsF(penWidth, penWidth, penWidth, penWidth));
473 QPointF cacheCenter = cacheRect.center();
474 tf.translate(cacheCenter.x(), cacheCenter.y());
475 tf.rotate(-canvasRotationAngle);
476 tf.translate(-cacheCenter.x(), -cacheCenter.y());
479 if (needsDualColor) {
485 QPainterPath clipPath;
486 clipPath.addPolygon(tf.map(QPolygonF(QRectF(0, 0, cacheRect.width(), cacheRect.height() / 2.0 + 1.0))));
487 cachePainter.setClipPath(clipPath);
489 bool flipped =
m_d->canvas->yAxisMirrored();
490 cachePainter.setBrush(flipped ? baseColor : currentColor);
491 cachePainter.drawEllipse(outerRect);
493 cachePainter.setBrush(baseColor);
496 tf.map(QRectF(0, cacheRect.height() / 2.0, cacheRect.width(), cacheRect.height() / 2.0)));
497 cachePainter.setClipPath(clipPath);
499 cachePainter.setBrush(flipped ? currentColor : baseColor);
500 cachePainter.drawEllipse(outerRect);
502 cachePainter.setClipPath(QPainterPath(), Qt::NoClip);
504 cachePainter.setBrush(currentColor);
505 cachePainter.drawEllipse(outerRect);
508 qreal innerX = cacheRect.width() * (1.0 -
m_d->circlePreviewThickness);
509 qreal innerY = cacheRect.height() * (1.0 -
m_d->circlePreviewThickness);
510 QRectF innerRect = cacheRect.marginsRemoved(QMarginsF(innerX, innerY, innerX, innerY));
511 QPainterPath innerEllipse;
512 innerEllipse.addEllipse(innerRect);
514 QPainterPath innerPath;
515 innerPath.addPath(innerEllipse);
518 if (
m_d->circlePreviewThickness < 0.5 &&
m_d->circlePreviewExtraCircles) {
519 qreal extraMargin = 0.1*
m_d->circlePreviewThickness*innerRect.width();
520 QPointF leftCenter = QPointF(innerRect.left() - extraMargin, innerRect.top() + innerRect.height()/2.0);
521 QPointF rightCenter = QPointF(innerRect.right() + extraMargin, innerRect.top() + innerRect.height()/2.0);
523 innerPath.setFillRule(Qt::OddEvenFill);
524 innerPath.addEllipse(leftCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
525 innerPath.addEllipse(rightCenter,
m_d->circlePreviewThickness*cacheRect.width(),
m_d->circlePreviewThickness*cacheRect.width());
527 innerPath = innerPath.intersected(innerEllipse);
530 cachePainter.setPen(Qt::NoPen);
531 cachePainter.setCompositionMode(QPainter::CompositionMode_Clear);
532 cachePainter.drawPath(tf.map(innerPath));
534 if (
m_d->circlePreviewOutlineEnabled) {
535 cachePainter.setBrush(Qt::transparent);
536 cachePainter.setPen(pen);
537 cachePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
538 cachePainter.drawPath(tf.map(innerPath));
541 gc.drawPixmap(viewRectF.toRect(),
m_d->cache);