From af100c2d138661a2e9593f158c802a7c219a9d5e Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 19 Sep 2021 11:34:30 +0300 Subject: [PATCH] Fix poll answer check in custom chat themes. --- .../history/view/media/history_view_poll.cpp | 60 +++++++++++++++---- .../history/view/media/history_view_poll.h | 1 + Telegram/SourceFiles/ui/chat/chat.style | 4 ++ Telegram/SourceFiles/ui/chat/chat_style.cpp | 6 ++ Telegram/SourceFiles/ui/chat/chat_style.h | 1 + 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 4693b1e2f7..6c635a81c4 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -1207,31 +1207,67 @@ void Poll::paintFilling( top += st::historyPollAnswerPadding.top(); - PainterHighQualityEnabler hq(p); - p.setPen(Qt::NoPen); const auto thickness = st::historyPollFillingHeight; const auto max = awidth - st::historyPollFillingRight; const auto size = anim::interpolate(st::historyPollFillingMin, max, filling); const auto radius = st::historyPollFillingRadius; const auto ftop = bottom - st::historyPollFillingBottom - thickness; - if (chosen && !correct) { - p.setBrush(st->boxTextFgError()); - } else if (chosen && correct && _poll->quiz() && !context.outbg) { - p.setBrush(st->boxTextFgGood()); - } else { - p.setBrush(stm->msgWaveformActive); - } + enum class Style { + Incorrect, + Correct, + Default, + }; + const auto style = [&] { + if (chosen && !correct) { + return Style::Incorrect; + } else if (chosen && correct && _poll->quiz() && !context.outbg) { + return Style::Correct; + } else { + return Style::Default; + } + }(); auto barleft = aleft; auto barwidth = size; + const auto &color = (style == Style::Incorrect) + ? st->boxTextFgError() + : (style == Style::Correct) + ? st->boxTextFgGood() + : stm->msgFileBg; + p.setPen(Qt::NoPen); + p.setBrush(color); + PainterHighQualityEnabler hq(p); if (chosen || correct) { - const auto &icon = (chosen && !correct) + const auto &icon = (style == Style::Incorrect) ? st->historyPollChoiceWrong() - : st->historyPollChoiceRight(); + : (style == Style::Correct) + ? st->historyPollChoiceRight() + : stm->historyPollChoiceRight; const auto cleft = aleft - st::historyPollPercentSkip - icon.width(); const auto ctop = ftop - (icon.height() - thickness) / 2; p.drawEllipse(cleft, ctop, icon.width(), icon.height()); - icon.paint(p, cleft, ctop, width); + + const auto paintContent = [&](Painter &p) { + icon.paint(p, cleft, ctop, width); + }; + if (style == Style::Default && usesBubblePattern(context)) { + const auto add = st::lineWidth * 2; + const auto target = QRect( + cleft, + ctop, + icon.width(), + icon.height() + ).marginsAdded({ add, add, add, add }); + Ui::PaintPatternBubblePart( + p, + context.viewport, + context.bubblesPattern->pixmap, + target, + paintContent, + _fillingIconCache); + } else { + paintContent(p); + } //barleft += icon.width() - radius; //barwidth -= icon.width() - radius; } diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.h b/Telegram/SourceFiles/history/view/media/history_view_poll.h index e06dee711f..195fcc2457 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.h +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.h @@ -214,6 +214,7 @@ private: Ui::Animations::Simple _wrongAnswerAnimation; mutable QPoint _lastLinkPoint; mutable QImage _userpicCircleCache; + mutable QImage _fillingIconCache; mutable std::unique_ptr _close; diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index c7bdbc5262..e83ff119b9 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -741,6 +741,10 @@ historyPollBottomButtonSkip: 15px; historyPollBottomButtonTop: 4px; historyPollChoiceRight: icon {{ "poll_choice_right", activeButtonFg }}; historyPollChoiceWrong: icon {{ "poll_choice_wrong", activeButtonFg }}; +historyPollOutChoiceRight: icon {{ "poll_choice_right", historyFileOutIconFg }}; +historyPollOutChoiceRightSelected: icon {{ "poll_choice_right", historyFileOutIconFgSelected }}; +historyPollInChoiceRight: icon {{ "poll_choice_right", historyFileInIconFg }}; +historyPollInChoiceRightSelected: icon {{ "poll_choice_right", historyFileInIconFgSelected }}; historyPollOutChosen: icon {{ "poll_select_check", historyFileOutIconFg }}; historyPollOutChosenSelected: icon {{ "poll_select_check", historyFileOutIconFgSelected }}; historyPollInChosen: icon {{ "poll_select_check", historyFileInIconFg }}; diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index e361a5efbd..66066ab372 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -391,6 +391,12 @@ ChatStyle::ChatStyle() { st::historyPollInChosenSelected, st::historyPollOutChosen, st::historyPollOutChosenSelected); + make( + &MessageStyle::historyPollChoiceRight, + st::historyPollInChoiceRight, + st::historyPollInChoiceRightSelected, + st::historyPollOutChoiceRight, + st::historyPollOutChoiceRightSelected); make( &MessageImageStyle::msgDateImgBg, st::msgDateImgBg, diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index 8215b881ab..5c57bf1b9a 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -69,6 +69,7 @@ struct MessageStyle { style::icon historyQuizTimer = { Qt::Uninitialized }; style::icon historyQuizExplain = { Qt::Uninitialized }; style::icon historyPollChosen = { Qt::Uninitialized }; + style::icon historyPollChoiceRight = { Qt::Uninitialized }; }; struct MessageImageStyle {