Skip to content

Commit abc4911

Browse files
committed
Add support for radial gradients to libmythui
Basic radial (not eliptical) gradient support, currently with a fixed focus/centre of 50%x50% and radius of 50%. A later commit will add arguments to change these values. <step> is permitted and works as it does for linear gradients. Use the 'direction="radial"' argument to <gradient>
1 parent 461a41c commit abc4911

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

mythtv/libs/libmythui/xmlparsebase.cpp

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <QString>
1212
#include <QBrush>
1313
#include <QLinearGradient>
14+
#include <QRadialGradient>
1415

1516
// libmyth headers
1617
#include "mythlogging.h"
@@ -174,39 +175,12 @@ int XMLParseBase::parseAlignment(QDomElement &element)
174175

175176
QBrush XMLParseBase::parseGradient(const QDomElement &element)
176177
{
177-
QLinearGradient gradient;
178+
QBrush brush;
178179
QString gradientStart = element.attribute("start", "");
179180
QString gradientEnd = element.attribute("end", "");
180181
int gradientAlpha = element.attribute("alpha", "255").toInt();
181182
QString direction = element.attribute("direction", "vertical");
182183

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-
210184
QGradientStops stops;
211185

212186
if (!gradientStart.isEmpty())
@@ -217,14 +191,6 @@ QBrush XMLParseBase::parseGradient(const QDomElement &element)
217191
stops.append(stop);
218192
}
219193

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-
228194
for (QDomNode child = element.firstChild(); !child.isNull();
229195
child = child.nextSibling())
230196
{
@@ -243,9 +209,60 @@ QBrush XMLParseBase::parseGradient(const QDomElement &element)
243209
}
244210
}
245211

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+
247264

248-
return QBrush(gradient);
265+
return brush;
249266
}
250267

251268
QString XMLParseBase::parseText(QDomElement &element)

0 commit comments

Comments
 (0)