Changeset View
Changeset View
Standalone View
Standalone View
libs/flake/KoGradientBackground.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | KoGradientBackground::~KoGradientBackground() | 66 | KoGradientBackground::~KoGradientBackground() | ||
67 | { | 67 | { | ||
68 | Q_D(KoGradientBackground); | 68 | Q_D(KoGradientBackground); | ||
69 | delete d->gradient; | 69 | delete d->gradient; | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | bool KoGradientBackground::compareTo(const KoShapeBackground *other) const | ||||
73 | { | ||||
74 | Q_D(const KoGradientBackground); | ||||
75 | const KoGradientBackground *otherGradient = dynamic_cast<const KoGradientBackground*>(other); | ||||
76 | | ||||
77 | return otherGradient && | ||||
78 | d->matrix == otherGradient->d_func()->matrix && | ||||
79 | *d->gradient == *otherGradient->d_func()->gradient; | ||||
80 | } | ||||
81 | | ||||
72 | void KoGradientBackground::setTransform(const QTransform &matrix) | 82 | void KoGradientBackground::setTransform(const QTransform &matrix) | ||
73 | { | 83 | { | ||
74 | Q_D(KoGradientBackground); | 84 | Q_D(KoGradientBackground); | ||
75 | d->matrix = matrix; | 85 | d->matrix = matrix; | ||
76 | } | 86 | } | ||
77 | 87 | | |||
78 | QTransform KoGradientBackground::transform() const | 88 | QTransform KoGradientBackground::transform() const | ||
79 | { | 89 | { | ||
Show All 16 Lines | 105 | { | |||
96 | Q_D(const KoGradientBackground); | 106 | Q_D(const KoGradientBackground); | ||
97 | return d->gradient; | 107 | return d->gradient; | ||
98 | } | 108 | } | ||
99 | 109 | | |||
100 | void KoGradientBackground::paint(QPainter &painter, const KoViewConverter &/*converter*/, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const | 110 | void KoGradientBackground::paint(QPainter &painter, const KoViewConverter &/*converter*/, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const | ||
101 | { | 111 | { | ||
102 | Q_D(const KoGradientBackground); | 112 | Q_D(const KoGradientBackground); | ||
103 | if (!d->gradient) return; | 113 | if (!d->gradient) return; | ||
104 | QBrush brush(*d->gradient); | | |||
105 | brush.setTransform(d->matrix); | | |||
106 | 114 | | |||
107 | painter.setBrush(brush); | 115 | if (d->gradient->coordinateMode() == QGradient::ObjectBoundingMode) { | ||
116 | | ||||
117 | /** | ||||
118 | * NOTE: important hack! | ||||
119 | * | ||||
120 | * Qt has different notation of QBrush::setTransform() in comparison | ||||
121 | * to what SVG defines. SVG defines gradientToUser matrix to be postmultiplied | ||||
122 | * by QBrush::transform(), but Qt does exectly reverse! | ||||
123 | * | ||||
124 | * That most probably has beed caused by the fact that Qt uses transposed | ||||
125 | * matrices and someone just mistyped the stuff long ago :( | ||||
126 | * | ||||
127 | * So here we basically emulate this feature by converting the gradient into | ||||
128 | * QGradient::LogicalMode and doing transformations manually. | ||||
129 | */ | ||||
130 | | ||||
131 | const QRectF boundingRect = fillPath.boundingRect(); | ||||
132 | QTransform gradientToUser(boundingRect.width(), 0, 0, boundingRect.height(), | ||||
133 | boundingRect.x(), boundingRect.y()); | ||||
134 | | ||||
135 | // TODO: how about slicing the object? | ||||
136 | QGradient g = *d->gradient; | ||||
137 | g.setCoordinateMode(QGradient::LogicalMode); | ||||
138 | | ||||
139 | QBrush b(g); | ||||
140 | b.setTransform(d->matrix * gradientToUser); | ||||
141 | painter.setBrush(b); | ||||
142 | } else { | ||||
143 | QBrush b(*d->gradient); | ||||
144 | b.setTransform(d->matrix); | ||||
145 | painter.setBrush(b); | ||||
146 | } | ||||
147 | | ||||
108 | painter.drawPath(fillPath); | 148 | painter.drawPath(fillPath); | ||
109 | } | 149 | } | ||
110 | 150 | | |||
111 | void KoGradientBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context) | 151 | void KoGradientBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context) | ||
112 | { | 152 | { | ||
113 | Q_D(KoGradientBackground); | 153 | Q_D(KoGradientBackground); | ||
114 | if (!d->gradient) return; | 154 | if (!d->gradient) return; | ||
115 | QBrush brush(*d->gradient); | 155 | QBrush brush(*d->gradient); | ||
Show All 39 Lines |