Marble
6 #include "OsmcSymbol.h"
9 #include <QDomDocument>
13 OsmcSymbol::OsmcSymbol(
const QString &tag,
int size)
16 , m_foreground(nullptr)
17 , m_foreground2(nullptr)
22 <<
"round" <<
"circle" <<
"frame";
25 <<
"dot" <<
"bowl" <<
"circle" <<
"bar"
26 <<
"stripe" <<
"cross" <<
"x" <<
"slash"
27 <<
"backslash" <<
"rectangle" <<
"rectangle_line"
28 <<
"triangle" <<
"triangle_turned" <<
"triangle_line"
29 <<
"diamond" <<
"pointer" <<
"fork" <<
"arch"
30 <<
"turned_T" <<
"L" <<
"lower" <<
"corner"
31 <<
"drop_line" <<
"horse" <<
"hiker";
33 m_precoloredForegroundTypes
34 <<
"wolfshook" <<
"shell" <<
"shell_modern" <<
"ammonit"
35 <<
"mine" <<
"hiker" <<
"heart" <<
"tower" <<
"bridleway";
42 OsmcSymbol::~OsmcSymbol()
48 bool OsmcSymbol::parseTag(
const QString &tag)
52 if (parts.
size() < 2) {
58 m_foreground =
nullptr;
62 m_foreground2 =
nullptr;
67 m_wayColor.setNamedColor(parts.
at(0));
72 if (!parseBackground(parts.
at(1))) {
76 if (parts.
size() == 3) {
77 m_foreground = parseForeground(parts.
at(2));
78 }
else if (parts.
size() == 4) {
81 m_textColor = parts.
at(3);
83 m_foreground = parseForeground(parts.
at(2));
84 m_foreground2 = parseForeground(parts.
at(3));
86 }
else if (parts.
size() == 5) {
87 m_foreground = parseForeground(parts.
at(2));
90 m_textColor = parts.
at(4);
94 }
else if (parts.
size() == 6) {
95 m_foreground = parseForeground(parts.
at(2));
96 m_foreground2 = parseForeground(parts.
at(3));
99 m_textColor.setNamedColor(parts.
at(5));
110 bool OsmcSymbol::parseBackground(
const QString &bg)
120 if (
type.isEmpty()) {
121 m_backgroundColor.setNamedColor(color);
122 m_backgroundType =
type;
123 }
else if (m_backgroundTypes.contains(type)) {
124 m_backgroundColor.setNamedColor(color);
125 m_backgroundType =
type;
137 if (m_precoloredForegroundTypes.contains(fg)) {
155 setXMLAttribute(rootElement,
"path",
"fill", color);
164 void OsmcSymbol::render()
173 int w = m_side, h = m_side;
176 if (!m_text.isEmpty()) {
177 QFont font = painter.font();
180 painter.setFont(font);
187 const QRect bgRect =
QRect((m_side - w) / 2, (m_side - h) / 2, w, h);
190 if (m_backgroundType.isEmpty()) {
191 painter.fillRect(bgRect, m_backgroundColor);
192 }
else if (m_backgroundType ==
"round") {
193 painter.setBrush(m_backgroundColor);
194 painter.setPen(m_backgroundColor);
195 painter.drawEllipse(bgRect);
196 }
else if (m_backgroundType ==
"circle") {
198 painter.setPen(
QPen(m_backgroundColor, m_side / 10));
199 painter.drawEllipse(bgRect);
200 }
else if (m_backgroundType ==
"frame") {
201 painter.setPen(
QPen(m_backgroundColor, m_side / 10));
203 painter.drawRect(bgRect);
209 m_foreground ? m_foreground->render(&fgPainter) : void();
210 m_foreground2 ? m_foreground2->render(&fgPainter) : void();
211 painter.drawPixmap(bgRect, foregrounds);
213 if (!m_text.isEmpty()) {
215 painter.setPen(m_textColor);
222 QImage OsmcSymbol::icon()
const
227 QColor OsmcSymbol::wayColor()
const
240 for (
int i = 0; i < elem.
childNodes().count(); ++i) {
246 setXMLAttribute(child, tag, attr, attrValue);
QString section(QChar sep, int start, int end, QString::SectionFlags flags) const const
QDomElement toElement() const const
QString tagName() const const
Type type(const QSqlDatabase &db)
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
int horizontalAdvance(const QString &text, int len) const const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
QDomNode at(int index) const const
void setAttribute(const QString &name, const QString &value)
void setPixelSize(int pixelSize)
const T & at(int i) const const
QDomNodeList childNodes() const const
QDomElement documentElement() const const
bool isValidColor(const QString &name)
void setBold(bool enable)
bool isElement() const const
QByteArray toByteArray(int indent) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:27 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.