From 770b5d0e59ab6d428e234b3773679de8261477ee Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 15 Dec 2022 19:10:04 +0400 Subject: [PATCH] Allow using text color -> preview color algo outside. --- ui/text/custom_emoji_instance.cpp | 9 ++++++--- ui/text/custom_emoji_instance.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/text/custom_emoji_instance.cpp b/ui/text/custom_emoji_instance.cpp index 2b25cbc..bac989b 100644 --- a/ui/text/custom_emoji_instance.cpp +++ b/ui/text/custom_emoji_instance.cpp @@ -89,6 +89,11 @@ void PaintScaledImage( } // namespace +QColor PreviewColorFromTextColor(QColor color) { + color.setAlpha((color.alpha() + 1) / 8); + return color; +} + Preview::Preview(QPainterPath path, float64 scale) : _data(ScaledPath{ std::move(path), scale }) { } @@ -131,9 +136,7 @@ void Preview::paintPath( const Context &context, const ScaledPath &path) { auto hq = PainterHighQualityEnabler(p); - auto copy = context.textColor.value(); - copy.setAlpha((copy.alpha() + 1) / 8); - p.setBrush(copy); + p.setBrush(PreviewColorFromTextColor(context.textColor)); p.setPen(Qt::NoPen); const auto scale = path.scale; const auto required = (scale != 1.) || context.scaled; diff --git a/ui/text/custom_emoji_instance.h b/ui/text/custom_emoji_instance.h index 4d65ec0..c86010e 100644 --- a/ui/text/custom_emoji_instance.h +++ b/ui/text/custom_emoji_instance.h @@ -25,6 +25,8 @@ namespace Ui::CustomEmoji { using Context = Ui::Text::CustomEmoji::Context; +[[nodiscard]] QColor PreviewColorFromTextColor(QColor color); + class Preview final { public: Preview() = default;