| 69 | } |
| 70 | |
| 71 | void Background::draw(QPainter* painter, const QPolygonF& polygon, double radius) const { |
| 72 | Q_D(const Background); |
| 73 | const QRectF& rect = polygon.boundingRect(); |
| 74 | |
| 75 | // brush |
| 76 | if (d->type == Background::Type::Color) { |
| 77 | switch (d->colorStyle) { |
| 78 | case Background::ColorStyle::SingleColor: { |
| 79 | painter->setBrush(QBrush(d->firstColor)); |
| 80 | break; |
| 81 | } |
| 82 | case Background::ColorStyle::HorizontalLinearGradient: { |
| 83 | QLinearGradient linearGrad(rect.topLeft(), rect.topRight()); |
| 84 | linearGrad.setColorAt(0, d->firstColor); |
| 85 | linearGrad.setColorAt(1, d->secondColor); |
| 86 | painter->setBrush(QBrush(linearGrad)); |
| 87 | break; |
| 88 | } |
| 89 | case Background::ColorStyle::VerticalLinearGradient: { |
| 90 | QLinearGradient linearGrad(rect.topLeft(), rect.bottomLeft()); |
| 91 | linearGrad.setColorAt(0, d->firstColor); |
| 92 | linearGrad.setColorAt(1, d->secondColor); |
| 93 | painter->setBrush(QBrush(linearGrad)); |
| 94 | break; |
| 95 | } |
| 96 | case Background::ColorStyle::TopLeftDiagonalLinearGradient: { |
| 97 | QLinearGradient linearGrad(rect.topLeft(), rect.bottomRight()); |
| 98 | linearGrad.setColorAt(0, d->firstColor); |
| 99 | linearGrad.setColorAt(1, d->secondColor); |
| 100 | painter->setBrush(QBrush(linearGrad)); |
| 101 | break; |
| 102 | } |
| 103 | case Background::ColorStyle::BottomLeftDiagonalLinearGradient: { |
| 104 | QLinearGradient linearGrad(rect.bottomLeft(), rect.topRight()); |
| 105 | linearGrad.setColorAt(0, d->firstColor); |
| 106 | linearGrad.setColorAt(1, d->secondColor); |
| 107 | painter->setBrush(QBrush(linearGrad)); |
| 108 | break; |
| 109 | } |
| 110 | case Background::ColorStyle::RadialGradient: { |
| 111 | QRadialGradient radialGrad(rect.center(), rect.width() / 2); |
| 112 | radialGrad.setColorAt(0, d->firstColor); |
| 113 | radialGrad.setColorAt(1, d->secondColor); |
| 114 | painter->setBrush(QBrush(radialGrad)); |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | } else if (d->type == Background::Type::Image) { |
| 119 | if (!d->fileName.trimmed().isEmpty()) { |
| 120 | QPixmap pix(d->fileName); |
| 121 | switch (d->imageStyle) { |
| 122 | case Background::ImageStyle::ScaledCropped: |
| 123 | pix = pix.scaled(rect.size().toSize(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); |
| 124 | painter->setBrush(QBrush(pix)); |
| 125 | painter->setBrushOrigin(pix.size().width() / 2, pix.size().height() / 2); |
| 126 | break; |
| 127 | case Background::ImageStyle::Scaled: |
| 128 | pix = pix.scaled(rect.size().toSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |