13OsmcSymbol::OsmcSymbol(
const QString &tag,
int size)
16 , m_foreground(nullptr)
17 , m_foreground2(nullptr)
21 m_backgroundTypes <<
"round"
25 m_foregroundTypes <<
"dot"
51 m_precoloredForegroundTypes <<
"wolfshook"
66OsmcSymbol::~OsmcSymbol()
72bool OsmcSymbol::parseTag(
const QString &tag)
74 QStringList parts = tag.
split(
':');
76 if (parts.
size() < 2) {
82 m_foreground =
nullptr;
86 m_foreground2 =
nullptr;
91 m_wayColor.fromString(parts.
at(0));
96 if (!parseBackground(parts.
at(1))) {
100 if (parts.
size() == 3) {
101 m_foreground = parseForeground(parts.
at(2));
102 }
else if (parts.
size() == 4) {
104 m_text = parts.
at(2);
105 m_textColor = parts.
at(3);
107 m_foreground = parseForeground(parts.
at(2));
108 m_foreground2 = parseForeground(parts.
at(3));
110 }
else if (parts.
size() == 5) {
111 m_foreground = parseForeground(parts.
at(2));
113 m_text = parts.
at(3);
114 m_textColor = parts.
at(4);
118 }
else if (parts.
size() == 6) {
119 m_foreground = parseForeground(parts.
at(2));
120 m_foreground2 = parseForeground(parts.
at(3));
122 m_text = parts.
at(4);
123 m_textColor.fromString(parts.
at(5));
134bool OsmcSymbol::parseBackground(
const QString &bg)
136 QString color = bg.
section(
"_", 0, 0);
144 if (
type.isEmpty()) {
145 m_backgroundColor.fromString(color);
146 m_backgroundType =
type;
147 }
else if (m_backgroundTypes.contains(type)) {
148 m_backgroundColor.fromString(color);
149 m_backgroundType =
type;
161 if (m_precoloredForegroundTypes.contains(fg)) {
162 return new QSvgRenderer(QStringLiteral(
":/osmc-symbols/%1.svg").arg(fg));
165 QString color = fg.
section(
'_', 0, 0);
169 QFile file(QStringLiteral(
":/osmc-symbols/%1.svg").arg(type));
171 QByteArray baData = file.readAll();
179 setXMLAttribute(rootElement,
"path",
"fill", color);
188void OsmcSymbol::render()
193 QPainter painter(&m_image);
197 int w = m_side, h = m_side;
200 if (!m_text.isEmpty()) {
201 QFont font = painter.font();
204 painter.setFont(font);
205 QFontMetrics fm = QFontMetrics(font);
211 const QRect bgRect = QRect((m_side - w) / 2, (m_side - h) / 2, w, h);
214 if (m_backgroundType.isEmpty()) {
215 painter.fillRect(bgRect, m_backgroundColor);
216 }
else if (m_backgroundType ==
"round") {
217 painter.setBrush(m_backgroundColor);
218 painter.setPen(m_backgroundColor);
219 painter.drawEllipse(bgRect);
220 }
else if (m_backgroundType ==
"circle") {
222 painter.setPen(QPen(m_backgroundColor, m_side / 10));
223 painter.drawEllipse(bgRect);
224 }
else if (m_backgroundType ==
"frame") {
225 painter.setPen(QPen(m_backgroundColor, m_side / 10));
227 painter.drawRect(bgRect);
230 QPixmap foregrounds(bgRect.
size());
232 QPainter fgPainter(&foregrounds);
233 m_foreground ? m_foreground->render(&fgPainter) : void();
234 m_foreground2 ? m_foreground2->render(&fgPainter) : void();
235 painter.drawPixmap(bgRect, foregrounds);
237 if (!m_text.isEmpty()) {
239 painter.setPen(m_textColor);
246QImage OsmcSymbol::icon()
const
251QColor OsmcSymbol::wayColor()
const
264 for (
int i = 0; i < elem.
childNodes().count(); ++i) {
270 setXMLAttribute(child, tag, attr, attrValue);
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
bool isValidColorName(QAnyStringView name)
QDomElement documentElement() const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QByteArray toByteArray(int indent) const const
void setAttribute(const QString &name, const QString &value)
QString tagName() const const
QDomNodeList childNodes() const const
bool isElement() const const
QDomElement toElement() const const
QDomNode at(int index) const const
void setBold(bool enable)
void setPixelSize(int pixelSize)
int horizontalAdvance(QChar ch) const const
const_reference at(qsizetype i) const const
qsizetype size() const const
QString section(QChar sep, qsizetype start, qsizetype end, SectionFlags flags) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const