Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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>
  • Loading branch information...
commit abc491141bd715f5ceab9f82a34ca6658e2bfb54 1 parent 461a41c
@stuartm stuartm authored
Showing with 55 additions and 38 deletions.
  1. +55 −38 mythtv/libs/libmythui/xmlparsebase.cpp
View
93 mythtv/libs/libmythui/xmlparsebase.cpp
@@ -11,6 +11,7 @@
#include <QString>
#include <QBrush>
#include <QLinearGradient>
+#include <QRadialGradient>
// libmyth headers
#include "mythlogging.h"
@@ -174,39 +175,12 @@ int XMLParseBase::parseAlignment(QDomElement &element)
QBrush XMLParseBase::parseGradient(const QDomElement &element)
{
- QLinearGradient gradient;
+ QBrush brush;
QString gradientStart = element.attribute("start", "");
QString gradientEnd = element.attribute("end", "");
int gradientAlpha = element.attribute("alpha", "255").toInt();
QString direction = element.attribute("direction", "vertical");
- float x1, y1, x2, y2 = 0.0;
- if (direction == "vertical")
- {
- x1 = 0.5;
- x2 = 0.5;
- y1 = 0.0;
- y2 = 1.0;
- }
- else if (direction == "diagonal")
- {
- x1 = 0.0;
- x2 = 1.0;
- y1 = 0.0;
- y2 = 1.0;
- }
- else
- {
- x1 = 0.0;
- x2 = 1.0;
- y1 = 0.5;
- y2 = 0.5;
- }
-
- gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
- gradient.setStart(x1, y1);
- gradient.setFinalStop(x2, y2);
-
QGradientStops stops;
if (!gradientStart.isEmpty())
@@ -217,14 +191,6 @@ QBrush XMLParseBase::parseGradient(const QDomElement &element)
stops.append(stop);
}
- if (!gradientEnd.isEmpty())
- {
- QColor endColor = QColor(gradientEnd);
- endColor.setAlpha(gradientAlpha);
- QGradientStop stop(1.0, endColor);
- stops.append(stop);
- }
-
for (QDomNode child = element.firstChild(); !child.isNull();
child = child.nextSibling())
{
@@ -243,9 +209,60 @@ QBrush XMLParseBase::parseGradient(const QDomElement &element)
}
}
- gradient.setStops(stops);
+ if (!gradientEnd.isEmpty())
+ {
+ QColor endColor = QColor(gradientEnd);
+ endColor.setAlpha(gradientAlpha);
+ QGradientStop stop(1.0, endColor);
+ stops.append(stop);
+ }
+
+ if (direction == "radial")
+ {
+ QRadialGradient gradient;
+ gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
+ float x1 = 0.5, y1 = 0.5, radius = 0.5;
+ gradient.setCenter(x1,y1);
+ gradient.setFocalPoint(x1,y1);
+ gradient.setRadius(radius);
+ gradient.setStops(stops);
+ brush = QBrush(gradient);
+ }
+ else // Linear
+ {
+ QLinearGradient gradient;
+ gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
+ float x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
+ if (direction == "vertical")
+ {
+ x1 = 0.5;
+ x2 = 0.5;
+ y1 = 0.0;
+ y2 = 1.0;
+ }
+ else if (direction == "diagonal")
+ {
+ x1 = 0.0;
+ x2 = 1.0;
+ y1 = 0.0;
+ y2 = 1.0;
+ }
+ else // Horizontal
+ {
+ x1 = 0.0;
+ x2 = 1.0;
+ y1 = 0.5;
+ y2 = 0.5;
+ }
+
+ gradient.setStart(x1, y1);
+ gradient.setFinalStop(x2, y2);
+ gradient.setStops(stops);
+ brush = QBrush(gradient);
+ }
+
- return QBrush(gradient);
+ return brush;
}
QString XMLParseBase::parseText(QDomElement &element)
Please sign in to comment.
Something went wrong with that request. Please try again.