Add new Theme helper method to custom-colourize links
authorMichael Schuster <michael@schuster.ms>
Thu, 19 Dec 2019 18:30:35 +0000 (19:30 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Thu, 19 Dec 2019 21:07:30 +0000 (22:07 +0100)
Signed-off-by: Michael Schuster <michael@schuster.ms>
src/libsync/theme.cpp
src/libsync/theme.h

index ae9d9c95824b7a0fa22bd1c11e6738cb866d97dd..8b2b15e5c061376e7d94043d708f3871068d747d 100644 (file)
@@ -584,7 +584,7 @@ QColor Theme::getBackgroundAwareLinkColor()
 
 void Theme::replaceLinkColorStringBackgroundAware(QString &linkString, const QColor &backgroundColor)
 {
-    linkString.replace(QRegularExpression("(<a href|<a style='color:#([a-zA-Z0-9]{6});' href)"), QString::fromLatin1("<a style='color:%1;' href").arg(getBackgroundAwareLinkColor(backgroundColor).name()));
+    replaceLinkColorString(linkString, getBackgroundAwareLinkColor(backgroundColor));
 }
 
 void Theme::replaceLinkColorStringBackgroundAware(QString &linkString)
@@ -592,6 +592,11 @@ void Theme::replaceLinkColorStringBackgroundAware(QString &linkString)
     replaceLinkColorStringBackgroundAware(linkString, QGuiApplication::palette().color(QPalette::Base));
 }
 
+void Theme::replaceLinkColorString(QString &linkString, const QColor &newColor)
+{
+    linkString.replace(QRegularExpression("(<a href|<a style='color:#([a-zA-Z0-9]{6});' href)"), QString::fromLatin1("<a style='color:%1;' href").arg(newColor.name()));
+}
+
 QIcon Theme::createColorAwareIcon(const QString &name, const QPalette &palette)
 {
     QImage img(name);
index 7df181ba0701e1541a7584189650caac9b69e326..966c9b5c9e8f204fce368e0fcf29360aacc87587 100644 (file)
@@ -402,6 +402,15 @@ public:
      */
     static void replaceLinkColorStringBackgroundAware(QString &linkString);
 
+    /**
+     * @brief Appends a CSS-style colour value to all HTML link tags in a given string, as specified by newColor.
+     *
+     * 2019/12/19: Implemented for the Dark Mode on macOS, because the app palette can not account for that (Qt 5.12.5).
+     *
+     * This way we also avoid having certain strings re-translated on Transifex.
+     */
+    static void replaceLinkColorString(QString &linkString, const QColor &newColor);
+
     /**
      * @brief Creates a colour-aware icon based on the specified palette's base colour.
      *