* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
QssParser::QssParser()
{
_palette = QApplication::palette();
// Init palette color roles
_paletteColorRoles["alternate-base"] = QPalette::AlternateBase;
QssParser::QssParser()
{
_palette = QApplication::palette();
// Init palette color roles
_paletteColorRoles["alternate-base"] = QPalette::AlternateBase;
_paletteColorRoles["base"] = QPalette::Base;
_paletteColorRoles["bright-text"] = QPalette::BrightText;
_paletteColorRoles["button"] = QPalette::Button;
_paletteColorRoles["button-text"] = QPalette::ButtonText;
_paletteColorRoles["dark"] = QPalette::Dark;
_paletteColorRoles["base"] = QPalette::Base;
_paletteColorRoles["bright-text"] = QPalette::BrightText;
_paletteColorRoles["button"] = QPalette::Button;
_paletteColorRoles["button-text"] = QPalette::ButtonText;
_paletteColorRoles["dark"] = QPalette::Dark;
_paletteColorRoles["highlight"] = QPalette::Highlight;
_paletteColorRoles["highlighted-text"] = QPalette::HighlightedText;
_paletteColorRoles["light"] = QPalette::Light;
_paletteColorRoles["highlight"] = QPalette::Highlight;
_paletteColorRoles["highlighted-text"] = QPalette::HighlightedText;
_paletteColorRoles["light"] = QPalette::Light;
static const QRegExp blockrx("((?:ChatLine|ChatListItem|NickListItem)[^{]*)\\{([^}]+)\\}");
pos = 0;
while ((pos = blockrx.indexIn(ss, pos)) >= 0) {
static const QRegExp blockrx("((?:ChatLine|ChatListItem|NickListItem)[^{]*)\\{([^}]+)\\}");
pos = 0;
while ((pos = blockrx.indexIn(ss, pos)) >= 0) {
parseChatLineBlock(declaration, contents);
else if (declaration.startsWith("ChatListItem") || declaration.startsWith("NickListItem"))
parseListItemBlock(declaration, contents);
parseChatLineBlock(declaration, contents);
else if (declaration.startsWith("ChatListItem") || declaration.startsWith("NickListItem"))
parseListItemBlock(declaration, contents);
{
UiStyle::ItemFormatType fmtType = parseItemFormatType(decl);
if (fmtType == UiStyle::ItemFormatType::Invalid)
{
UiStyle::ItemFormatType fmtType = parseItemFormatType(decl);
if (fmtType == UiStyle::ItemFormatType::Invalid)
// Palette { ... } specifies the application palette
// ColorGroups can be specified like pseudo states, chaining is OR (contrary to normal CSS handling):
// Palette:inactive:disabled { ... } applies to both the Inactive and the Disabled state
// Palette { ... } specifies the application palette
// ColorGroups can be specified like pseudo states, chaining is OR (contrary to normal CSS handling):
// Palette:inactive:disabled { ... } applies to both the Inactive and the Disabled state
}
if (!rx.cap(1).isEmpty()) {
QStringList groups = rx.cap(1).split(':', QString::SkipEmptyParts);
}
if (!rx.cap(1).isEmpty()) {
QStringList groups = rx.cap(1).split(':', QString::SkipEmptyParts);
if ((g == "normal" || g == "active") && !colorGroups.contains(QPalette::Active))
colorGroups.append(QPalette::Active);
else if (g == "inactive" && !colorGroups.contains(QPalette::Inactive))
if ((g == "normal" || g == "active") && !colorGroups.contains(QPalette::Active))
colorGroups.append(QPalette::Active);
else if (g == "inactive" && !colorGroups.contains(QPalette::Inactive))
int idx = line.indexOf(':');
if (idx <= 0) {
qWarning() << Q_FUNC_INFO << tr("Invalid palette role assignment: %1").arg(line.trimmed());
int idx = line.indexOf(':');
if (idx <= 0) {
qWarning() << Q_FUNC_INFO << tr("Invalid palette role assignment: %1").arg(line.trimmed());
if (_paletteColorRoles.contains(rolestr)) {
QBrush brush = parseBrush(brushstr);
if (colorGroups.count()) {
if (_paletteColorRoles.contains(rolestr)) {
QBrush brush = parseBrush(brushstr);
if (colorGroups.count()) {
- foreach(QPalette::ColorGroup group, colorGroups)
- _palette.setBrush(group, _paletteColorRoles.value(rolestr), brush);
+ foreach (QPalette::ColorGroup group, colorGroups)
+ _palette.setBrush(group, _paletteColorRoles.value(rolestr), brush);
{
using FormatType = UiStyle::FormatType;
using MessageLabel = UiStyle::MessageLabel;
const std::pair<UiStyle::FormatType, UiStyle::MessageLabel> invalid{FormatType::Invalid, MessageLabel::None};
{
using FormatType = UiStyle::FormatType;
using MessageLabel = UiStyle::MessageLabel;
const std::pair<UiStyle::FormatType, UiStyle::MessageLabel> invalid{FormatType::Invalid, MessageLabel::None};
// $1: subelement; $2: msgtype; $3: conditionals
if (!rx.exactMatch(decl)) {
qWarning() << Q_FUNC_INFO << tr("Invalid block declaration: %1").arg(decl);
// $1: subelement; $2: msgtype; $3: conditionals
if (!rx.exactMatch(decl)) {
qWarning() << Q_FUNC_INFO << tr("Invalid block declaration: %1").arg(decl);
- foreach(const QString &cond, conditions.split(',', QString::SkipEmptyParts)) {
+ foreach (const QString& cond, conditions.split(',', QString::SkipEmptyParts)) {
label |= MessageLabel::Highlight;
else if (condValue == "selected")
label |= MessageLabel::Selected;
label |= MessageLabel::Highlight;
else if (condValue == "selected")
label |= MessageLabel::Selected;
// $1: item type; $2: properties
if (!rx.exactMatch(decl)) {
qWarning() << Q_FUNC_INFO << tr("Invalid block declaration: %1").arg(decl);
// $1: item type; $2: properties
if (!rx.exactMatch(decl)) {
qWarning() << Q_FUNC_INFO << tr("Invalid block declaration: %1").arg(decl);
QString type, state;
if (!properties.isEmpty()) {
QHash<QString, QString> props;
QString type, state;
if (!properties.isEmpty()) {
QHash<QString, QString> props;
- static const QRegExp propRx("\\s*([\\w\\-]+)\\s*=\\s*\"([\\w\\-]+)\"\\s*");
- foreach(const QString &prop, properties.split(',', QString::SkipEmptyParts)) {
+ static const QRegExp propRx(R"lit(\s*([\w\-]+)\s*=\s*"([\w\-]+)"\s*)lit");
+ foreach (const QString& prop, properties.split(',', QString::SkipEmptyParts)) {
if (!propRx.exactMatch(prop)) {
qWarning() << Q_FUNC_INFO << tr("Invalid proplist %1").arg(prop);
return ItemFormatType::Invalid;
if (!propRx.exactMatch(prop)) {
qWarning() << Q_FUNC_INFO << tr("Invalid proplist %1").arg(prop);
return ItemFormatType::Invalid;
int idx = line.indexOf(':');
if (idx <= 0) {
qWarning() << Q_FUNC_INFO << tr("Invalid property declaration: %1").arg(line.trimmed());
int idx = line.indexOf(':');
if (idx <= 0) {
qWarning() << Q_FUNC_INFO << tr("Invalid property declaration: %1").arg(line.trimmed());
// [0-9] Match any digit from 0-9
// Note that '\' must be escaped as '\\'
// Helpful interactive website for debugging and explaining: https://regex101.com/
// [0-9] Match any digit from 0-9
// Note that '\' must be escaped as '\\'
// Helpful interactive website for debugging and explaining: https://regex101.com/
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid palette color role specification: %1").arg(str);
return QBrush();
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid palette color role specification: %1").arg(str);
return QBrush();
- static const QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*");
- static const QRegExp rx(QString("qlineargradient\\s*\\(\\s*x1:%1,\\s*y1:%1,\\s*x2:%1,\\s*y2:%1,(.+)\\)").arg(rxFloat));
+ static const QString rxFloat(R"(\s*(-?\s*[0-9]*\.?[0-9]+)\s*)");
+ static const QRegExp rx(QString(R"(qlineargradient\s*\(\s*x1:%1,\s*y1:%1,\s*x2:%1,\s*y2:%1,(.+)\))").arg(rxFloat));
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str);
return QBrush();
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str);
return QBrush();
- static const QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*");
- static const QRegExp rx(QString("qconicalgradient\\s*\\(\\s*cx:%1,\\s*cy:%1,\\s*angle:%1,(.+)\\)").arg(rxFloat));
+ static const QString rxFloat(R"(\s*(-?\s*[0-9]*\.?[0-9]+)\s*)");
+ static const QRegExp rx(QString(R"(qconicalgradient\s*\(\s*cx:%1,\s*cy:%1,\s*angle:%1,(.+)\))").arg(rxFloat));
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str);
return QBrush();
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str);
return QBrush();
- static const QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*");
- static const QRegExp rx(QString("qradialgradient\\s*\\(\\s*cx:%1,\\s*cy:%1,\\s*radius:%1,\\s*fx:%1,\\s*fy:%1,(.+)\\)").arg(rxFloat));
+ static const QString rxFloat(R"(\s*(-?\s*[0-9]*\.?[0-9]+)\s*)");
+ static const QRegExp rx(QString(R"(qradialgradient\s*\(\s*cx:%1,\s*cy:%1,\s*radius:%1,\s*fx:%1,\s*fy:%1,(.+)\))").arg(rxFloat));
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str);
return QBrush();
if (!rx.exactMatch(str)) {
qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str);
return QBrush();
- return QColor(tuple.at(0), tuple.at(1), tuple.at(2), tuple.at(3));
+ return QColor(tuple.at(0), tuple.at(1), tuple.at(2), tuple.at(3)); // NOLINT(modernize-return-braced-init-list)
- static const QRegExp rx("\\(((\\s*[0-9]{1,3}%?\\s*)(,\\s*[0-9]{1,3}%?\\s*)*)\\)");
+ static const QRegExp rx(R"(\(((\s*[0-9]{1,3}%?\s*)(,\s*[0-9]{1,3}%?\s*)*)\))");
if (!rx.exactMatch(str.trimmed())) {
return ColorTuple();
}
QStringList values = rx.cap(1).split(',');
if (!rx.exactMatch(str.trimmed())) {
return ColorTuple();
}
QStringList values = rx.cap(1).split(',');
- static const QString rxFloat("(0?\\.[0-9]+|[01])"); // values between 0 and 1
- static const QRegExp rx(QString("\\s*,?\\s*stop:\\s*(%1)\\s+([^:]+)(,\\s*stop:|$)").arg(rxFloat));
+ static const QString rxFloat("(0?\\.[0-9]+|[01])"); // values between 0 and 1
+ static const QRegExp rx(QString(R"(\s*,?\s*stop:\s*(%1)\s+([^:]+)(,\s*stop:|$))").arg(rxFloat));
- static const QRegExp rx("((?:(?:normal|italic|oblique|underline|strikethrough|bold|100|200|300|400|500|600|700|800|900) ){0,2}) ?(\\d+)(pt|px)? \"(.*)\"");
+ static const QRegExp rx(
+ "((?:(?:normal|italic|oblique|underline|strikethrough|bold|100|200|300|400|500|600|700|800|900) ){0,2}) ?(\\d+)(pt|px)? \"(.*)\"");
if (!rx.exactMatch(value)) {
qWarning() << Q_FUNC_INFO << tr("Invalid font specification: %1").arg(value);
return;
if (!rx.exactMatch(value)) {
qWarning() << Q_FUNC_INFO << tr("Invalid font specification: %1").arg(value);
return;
format->setFontStrikeOut(false);
format->setFontWeight(QFont::Normal);
QStringList proplist = rx.cap(1).split(' ', QString::SkipEmptyParts);
format->setFontStrikeOut(false);
format->setFontWeight(QFont::Normal);
QStringList proplist = rx.cap(1).split(' ', QString::SkipEmptyParts);
else if (prop == "italic")
format->setFontItalic(true);
else if (prop == "underline")
format->setFontUnderline(true);
else if (prop == "strikethrough")
format->setFontStrikeOut(true);
else if (prop == "italic")
format->setFontItalic(true);
else if (prop == "underline")
format->setFontUnderline(true);
else if (prop == "strikethrough")
format->setFontStrikeOut(true);
// Oblique is not a property supported by QTextCharFormat
format->setFontItalic(true);
else if (prop == "bold")
format->setFontWeight(QFont::Bold);
// Oblique is not a property supported by QTextCharFormat
format->setFontItalic(true);
else if (prop == "bold")
format->setFontWeight(QFont::Bold);
format->setFontUnderline(true);
else if (value == "strikethrough")
format->setFontStrikeOut(true);
format->setFontUnderline(true);
else if (value == "strikethrough")
format->setFontStrikeOut(true);