diff --git a/Telegram/Resources/icons/quiz_explain.png b/Telegram/Resources/icons/quiz_explain.png new file mode 100644 index 000000000..c49ccd4d0 Binary files /dev/null and b/Telegram/Resources/icons/quiz_explain.png differ diff --git a/Telegram/Resources/icons/quiz_explain@2x.png b/Telegram/Resources/icons/quiz_explain@2x.png new file mode 100644 index 000000000..3e9f8ba54 Binary files /dev/null and b/Telegram/Resources/icons/quiz_explain@2x.png differ diff --git a/Telegram/Resources/icons/quiz_explain@3x.png b/Telegram/Resources/icons/quiz_explain@3x.png new file mode 100644 index 000000000..2c3b51b85 Binary files /dev/null and b/Telegram/Resources/icons/quiz_explain@3x.png differ diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index ff132f2a0..02c07dc8b 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -38,7 +38,7 @@ constexpr auto kMaxOptionsCount = PollData::kMaxOptions; constexpr auto kOptionLimit = 100; constexpr auto kWarnQuestionLimit = 80; constexpr auto kWarnOptionLimit = 30; -constexpr auto kSolutionLimit = 400; +constexpr auto kSolutionLimit = 200; constexpr auto kErrorLimit = 99; class Options { diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index cf37a9d06..460269b93 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -618,6 +618,11 @@ historyAudioInDownloadSelected: icon {{ "history_audio_download", historyFileInI historyAudioOutDownload: icon {{ "history_audio_download", historyFileOutIconFg }}; historyAudioOutDownloadSelected: icon {{ "history_audio_download", historyFileOutIconFgSelected }}; +historyQuizExplainIn: icon {{ "quiz_explain", msgInDateFg }}; +historyQuizExplainInSelected: icon {{ "quiz_explain", msgInDateFgSelected }}; +historyQuizExplainOut: icon {{ "quiz_explain", msgOutDateFg }}; +historyQuizExplainOutSelected: icon {{ "quiz_explain", msgOutDateFgSelected }}; + historySlowmodeCounterMargins: margins(0px, 0px, 10px, 0px); largeEmojiSize: 36px; diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 4766bde39..23a76b1d7 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -418,7 +418,7 @@ void Poll::checkQuizAnswered() { } } -void Poll::showSolution() { +void Poll::showSolution() const { if (_poll->solution.text.isEmpty()) { return; } @@ -676,6 +676,7 @@ void Poll::draw(Painter &p, const QRect &r, TextSelection selection, crl::time m p.setPen(regular); _subtitle.drawLeftElided(p, padding.left(), tshift, paintw, width()); paintRecentVoters(p, padding.left() + _subtitle.maxWidth(), tshift, selection); + paintShowSolution(p, padding.left() + paintw, tshift, selection); tshift += st::msgDateFont->height + st::historyPollAnswersSkip; const auto progress = _answersAnimation @@ -822,6 +823,29 @@ void Poll::paintRecentVoters( } } +void Poll::paintShowSolution( + Painter &p, + int right, + int top, + TextSelection selection) const { + if (!showVotes() || _poll->solution.text.isEmpty()) { + return; + } + if (!_showSolutionLink) { + _showSolutionLink = std::make_shared( + crl::guard(this, [=] { showSolution(); })); + } + const auto outbg = _parent->hasOutLayout(); + const auto &icon = (selection == FullSelection) + ? (outbg + ? st::historyQuizExplainOutSelected + : st::historyQuizExplainInSelected) + : (outbg ? st::historyQuizExplainOut : st::historyQuizExplainIn); + const auto x = right - icon.width(); + const auto y = top + (st::normalFont->height - icon.height()) / 2; + icon.paint(p, x, y, width()); +} + int Poll::paintAnswer( Painter &p, const Answer &answer, @@ -1134,6 +1158,10 @@ TextState Poll::textState(QPoint point, StateRequest request) const { paintw -= padding.left() + padding.right(); tshift += _question.countHeight(paintw) + st::historyPollSubtitleSkip; + if (inShowSolution(point, padding.left() + paintw, tshift)) { + result.link = _showSolutionLink; + return result; + } tshift += st::msgDateFont->height + st::historyPollAnswersSkip; const auto awidth = paintw - st::historyPollAnswerPadding.left() @@ -1267,6 +1295,23 @@ void Poll::toggleRipple(Answer &answer, bool pressed) { } } +bool Poll::canShowSolution() const { + return showVotes() && !_poll->solution.text.isEmpty(); +} + +bool Poll::inShowSolution( + QPoint point, + int right, + int top) const { + if (!canShowSolution()) { + return false; + } + const auto &icon = st::historyQuizExplainIn; + const auto x = right - icon.width(); + const auto y = top + (st::normalFont->height - icon.height()) / 2; + return QRect(x, y, icon.width(), icon.height()).contains(point); +} + int Poll::bottomButtonHeight() const { const auto skip = st::historyPollChoiceRight.height() - st::historyPollFillingBottom diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.h b/Telegram/SourceFiles/history/view/media/history_view_poll.h index 360c9cd95..ebc9d04e2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.h +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.h @@ -96,6 +96,11 @@ private: int left, int top, TextSelection selection) const; + void paintShowSolution( + Painter &p, + int right, + int top, + TextSelection selection) const; int paintAnswer( Painter &p, const Answer &answer, @@ -155,7 +160,13 @@ private: void sendMultiOptions(); void showResults(); void checkQuizAnswered(); - void showSolution(); + void showSolution() const; + + [[nodiscard]] bool canShowSolution() const; + [[nodiscard]] bool inShowSolution( + QPoint point, + int right, + int top) const; [[nodiscard]] int bottomButtonHeight() const; @@ -174,6 +185,7 @@ private: Ui::Text::String _totalVotesLabel; ClickHandlerPtr _showResultsLink; ClickHandlerPtr _sendVotesLink; + mutable ClickHandlerPtr _showSolutionLink; mutable std::unique_ptr _linkRipple; mutable std::unique_ptr _answersAnimation;