11
11
#include < QString>
12
12
#include < QBrush>
13
13
#include < QLinearGradient>
14
+ #include < QRadialGradient>
14
15
15
16
// libmyth headers
16
17
#include " mythlogging.h"
@@ -174,39 +175,12 @@ int XMLParseBase::parseAlignment(QDomElement &element)
174
175
175
176
QBrush XMLParseBase::parseGradient (const QDomElement &element)
176
177
{
177
- QLinearGradient gradient ;
178
+ QBrush brush ;
178
179
QString gradientStart = element.attribute (" start" , " " );
179
180
QString gradientEnd = element.attribute (" end" , " " );
180
181
int gradientAlpha = element.attribute (" alpha" , " 255" ).toInt ();
181
182
QString direction = element.attribute (" direction" , " vertical" );
182
183
183
- float x1, y1, x2, y2 = 0.0 ;
184
- if (direction == " vertical" )
185
- {
186
- x1 = 0.5 ;
187
- x2 = 0.5 ;
188
- y1 = 0.0 ;
189
- y2 = 1.0 ;
190
- }
191
- else if (direction == " diagonal" )
192
- {
193
- x1 = 0.0 ;
194
- x2 = 1.0 ;
195
- y1 = 0.0 ;
196
- y2 = 1.0 ;
197
- }
198
- else
199
- {
200
- x1 = 0.0 ;
201
- x2 = 1.0 ;
202
- y1 = 0.5 ;
203
- y2 = 0.5 ;
204
- }
205
-
206
- gradient.setCoordinateMode (QGradient::ObjectBoundingMode);
207
- gradient.setStart (x1, y1);
208
- gradient.setFinalStop (x2, y2);
209
-
210
184
QGradientStops stops;
211
185
212
186
if (!gradientStart.isEmpty ())
@@ -217,14 +191,6 @@ QBrush XMLParseBase::parseGradient(const QDomElement &element)
217
191
stops.append (stop);
218
192
}
219
193
220
- if (!gradientEnd.isEmpty ())
221
- {
222
- QColor endColor = QColor (gradientEnd);
223
- endColor.setAlpha (gradientAlpha);
224
- QGradientStop stop (1.0 , endColor);
225
- stops.append (stop);
226
- }
227
-
228
194
for (QDomNode child = element.firstChild (); !child.isNull ();
229
195
child = child.nextSibling ())
230
196
{
@@ -243,9 +209,60 @@ QBrush XMLParseBase::parseGradient(const QDomElement &element)
243
209
}
244
210
}
245
211
246
- gradient.setStops (stops);
212
+ if (!gradientEnd.isEmpty ())
213
+ {
214
+ QColor endColor = QColor (gradientEnd);
215
+ endColor.setAlpha (gradientAlpha);
216
+ QGradientStop stop (1.0 , endColor);
217
+ stops.append (stop);
218
+ }
219
+
220
+ if (direction == " radial" )
221
+ {
222
+ QRadialGradient gradient;
223
+ gradient.setCoordinateMode (QGradient::ObjectBoundingMode);
224
+ float x1 = 0.5 , y1 = 0.5 , radius = 0.5 ;
225
+ gradient.setCenter (x1,y1);
226
+ gradient.setFocalPoint (x1,y1);
227
+ gradient.setRadius (radius);
228
+ gradient.setStops (stops);
229
+ brush = QBrush (gradient);
230
+ }
231
+ else // Linear
232
+ {
233
+ QLinearGradient gradient;
234
+ gradient.setCoordinateMode (QGradient::ObjectBoundingMode);
235
+ float x1 = 0.0 , y1 = 0.0 , x2 = 0.0 , y2 = 0.0 ;
236
+ if (direction == " vertical" )
237
+ {
238
+ x1 = 0.5 ;
239
+ x2 = 0.5 ;
240
+ y1 = 0.0 ;
241
+ y2 = 1.0 ;
242
+ }
243
+ else if (direction == " diagonal" )
244
+ {
245
+ x1 = 0.0 ;
246
+ x2 = 1.0 ;
247
+ y1 = 0.0 ;
248
+ y2 = 1.0 ;
249
+ }
250
+ else // Horizontal
251
+ {
252
+ x1 = 0.0 ;
253
+ x2 = 1.0 ;
254
+ y1 = 0.5 ;
255
+ y2 = 0.5 ;
256
+ }
257
+
258
+ gradient.setStart (x1, y1);
259
+ gradient.setFinalStop (x2, y2);
260
+ gradient.setStops (stops);
261
+ brush = QBrush (gradient);
262
+ }
263
+
247
264
248
- return QBrush (gradient) ;
265
+ return brush ;
249
266
}
250
267
251
268
QString XMLParseBase::parseText (QDomElement &element)
0 commit comments