// SPDX-FileCopyrightText: 2023 James Graham // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #include #include #include #include namespace Utils { /** * @brief Get a color for a user from a hueF value. * * The lightness of the color will be modified depending on the current palette in * order to maintain contrast. */ inline QColor getUserColor(qreal hueF) { const auto lightness = static_cast(QGuiApplication::instance())->palette().color(QPalette::Active, QPalette::Window).lightnessF(); // https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal return QColor::fromHslF(hueF, 1, -0.7 * lightness + 0.9, 1); } } namespace TextRegex { static const QRegularExpression endTagType{QStringLiteral("(>| )")}; static const QRegularExpression attributeData{QStringLiteral("['\"](.*?)['\"]")}; static const QRegularExpression removeReply{QStringLiteral("> <.*?>.*?\\n\\n"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression removeRichReply{QStringLiteral(".*?"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression codePill{QStringLiteral("
]*>(.*?)
"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression userPill{QStringLiteral("(.*?)"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression blockQuote{QStringLiteral("
\n?(?:

)?(.*?)(?:

)?\n?
"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression strikethrough{QStringLiteral("(.*?)"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression mxcImage{QStringLiteral(R"AAA()AAA")}; static const QRegularExpression plainUrl( QStringLiteral( R"((*SKIP)(*F)|\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp):(//)?\w|(magnet|matrix):)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption); static const QRegularExpression url(QStringLiteral(R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|https?:(//)?\w)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption); static const QRegularExpression emailAddress(QStringLiteral(R"((*SKIP)(*F)|\b(mailto:)?((\w|\.|-)+@(\w|\.|-)+\.\w+\b))"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption); static const QRegularExpression mxId(QStringLiteral(R"((^|[][[:space:](){}`'";])([!#@][-a-z0-9_=#/.]{1,252}:\w(?:\w|\.|-)*\.\w+(?::\d{1,5})?))"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption); }