Index: sources/storage/Settings.cpp =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -rff2fa0d776798aeab1a600bad55484d4870eec7e --- sources/storage/Settings.cpp (.../Settings.cpp) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/storage/Settings.cpp (.../Settings.cpp) (revision ff2fa0d776798aeab1a600bad55484d4870eec7e) @@ -17,6 +17,7 @@ #include #include #include +#include // Project #include "StorageGlobals.h" @@ -155,6 +156,8 @@ QStringList keyValue = line.split('='); key = keyValue[0].trimmed().replace("\\n","\n"); value = keyValue[1].trimmed().replace("\\n","\n"); + + key = convertToRichText(key); } else { key = line; @@ -170,6 +173,45 @@ } /*! + * \brief Settings::convertToRichText + * \details Helper function to color text converting syntax of <$HEX>text to Qt rich text text + * \param vInput - the input line to parse and replace + * \return QString - updated text + */ + +QString Settings::convertToRichText(const QString &vInput) +{ + QString result = vInput; + + // Regex to match <$HEX>text + QRegularExpression re("<\\$([#0-9A-Fa-f]{6})>(.*?)"); + QRegularExpressionMatch match; + + // Iterate over all matches + int offset = 0; // track the shift after replacements + QRegularExpressionMatchIterator i = re.globalMatch(result); + while (i.hasNext()) { + match = i.next(); + + QString color = match.captured(1); + QString text = match.captured(2); + + QString richText = QString("%2").arg(color.remove('#')).arg(text); + + // Replace in result string + int start = match.capturedStart() + offset; + int length = match.capturedLength(); + + result.replace(start, length, richText); + + // Adjust offset because we changed string length + offset += richText.length() - length; + } + + return result; +} + +/*! * \brief Settings::save * \details Writes the setting in the configuration files * \return Index: sources/storage/Settings.h =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -rff2fa0d776798aeab1a600bad55484d4870eec7e --- sources/storage/Settings.h (.../Settings.h) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/storage/Settings.h (.../Settings.h) (revision ff2fa0d776798aeab1a600bad55484d4870eec7e) @@ -269,6 +269,7 @@ static bool parse (const Detail &vDetail ); static int readCategory (Category_Enum vCategory ); static int configurationsPOST (Location_Enum vLoc = Location_Enum::eSecured) { Q_UNUSED(vLoc); return true; } + static QString convertToRichText(const QString &vInput ); }; }