2 #include <QSyntaxStyle> 6 #include <QXmlStreamReader> 20 QXmlStreamReader
reader(fl);
22 while (!reader.atEnd() && !reader.hasError())
24 auto token = reader.readNext();
26 if(token == QXmlStreamReader::StartElement)
28 if (reader.name() ==
"style-scheme")
30 if (reader.attributes().hasAttribute(
"name"))
32 m_name = reader.attributes().value(
"name").toString();
35 else if (reader.name() ==
"style")
37 auto attributes = reader.attributes();
39 auto name = attributes.value(
"name");
43 if (attributes.hasAttribute(
"background"))
45 format.setBackground(QColor(attributes.value(
"background").toString()));
48 if (attributes.hasAttribute(
"foreground"))
50 format.setForeground(QColor(attributes.value(
"foreground").toString()));
53 if (attributes.hasAttribute(
"bold") &&
54 attributes.value(
"bold") ==
"true")
56 format.setFontWeight(QFont::Weight::Bold);
59 if (attributes.hasAttribute(
"italic") &&
60 attributes.value(
"italic") ==
"true")
62 format.setFontItalic(
true);
65 if (attributes.hasAttribute(
"underlineStyle"))
67 auto underline = attributes.value(
"underlineStyle");
69 auto s = QTextCharFormat::UnderlineStyle::NoUnderline;
73 s = QTextCharFormat::UnderlineStyle::SingleUnderline;
77 s = QTextCharFormat::UnderlineStyle::DashUnderline;
81 s = QTextCharFormat::UnderlineStyle::DotLine;
85 s = QTextCharFormat::DashDotLine;
89 s = QTextCharFormat::DashDotDotLine;
93 s = QTextCharFormat::WaveUnderline;
95 else if (
underline ==
"SpellCheckUnderline")
97 s = QTextCharFormat::SpellCheckUnderline;
101 qDebug() <<
"Unknown underline value " <<
underline;
104 format.setUnderlineStyle(
s);
128 return QTextCharFormat();
145 Q_INIT_RESOURCE(qcodeeditor_resources);
146 QFile fl(
":/default_style.xml");
148 if (!fl.open(QIODevice::ReadOnly))
153 if (!style.
load(fl.readAll()))
155 qDebug() <<
"Can't load default style.";
QString name() const
Method for getting style name.
bool load(QString fl)
Method for loading and parsing style.
QSyntaxStyle(QObject *parent=nullptr)
Constructor.
static const char * reader(lua_State *L, void *ud, size_t *size)
Class, that describes Qt style parser for QCodeEditor.
bool isLoaded() const
Method for checking is syntax style loaded.
QTextCharFormat getFormat(QString name) const
Method for getting format for property name.
static QSyntaxStyle * defaultStyle()
Static method for getting default style.
QMap< QString, QTextCharFormat > m_data
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)