From 423daecbdea95cdd1c9bcfc4ad51f99b16fe75ca Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 10 Apr 2020 12:09:44 +0400 Subject: [PATCH] Add view solution button to polls. --- Telegram/Resources/icons/quiz_explain.png | Bin 0 -> 542 bytes Telegram/Resources/icons/quiz_explain@2x.png | Bin 0 -> 1190 bytes Telegram/Resources/icons/quiz_explain@3x.png | Bin 0 -> 1759 bytes .../SourceFiles/boxes/create_poll_box.cpp | 2 +- Telegram/SourceFiles/history/history.style | 5 ++ .../history/view/media/history_view_poll.cpp | 47 +++++++++++++++++- .../history/view/media/history_view_poll.h | 14 +++++- 7 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 Telegram/Resources/icons/quiz_explain.png create mode 100644 Telegram/Resources/icons/quiz_explain@2x.png create mode 100644 Telegram/Resources/icons/quiz_explain@3x.png diff --git a/Telegram/Resources/icons/quiz_explain.png b/Telegram/Resources/icons/quiz_explain.png new file mode 100644 index 0000000000000000000000000000000000000000..c49ccd4d0488a980c3dcbb042572f0298b47ec80 GIT binary patch literal 542 zcmV+(0^$9MP)N=mV{!p@FA;15Vq z%End}xoDt;y8KqKp8HVi)ytR-EKG1+4+2?LZP6c+KH$FAOkT*CX>+;6ZX$$Gs0fSV=4egI2)wNYB(GUSt4U#@6;R#yplo8sr`=%K!iX07*qoM6N<$f)+~hF#rGn literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/quiz_explain@2x.png b/Telegram/Resources/icons/quiz_explain@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..3e9f8ba54282c7c913a66c69aaa1ebd8b239a414 GIT binary patch literal 1190 zcmV;X1X=ruP);oaf$iA1=li z@ZXOWpC6mKC-Gkb-@SsrEAZVb;OA5V85tR@y1JT`m6frSloXbbkiYSrEKF<)u?0zi{v|YWbI+pASn*OFUQa^6~Kj6B84Vl$2ySo=&dTlK1!bhk=0s z`276zp1I26>FEjD+uNNYAx|JWIvQ41R#a)pt2hCEetvd|$PvJqH%fkf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YgW@d)Hd-smv89%?h z#8pgnnP?WD0r7`c|hk95duHg?o1Tbr021(I#URzUoJ$PD>!G@l`3 zL?+wXHm=FAKN0OR{g_wA|(HZ~%002ovPDHLkV1hK3 BPKW>i literal 0 HcmV?d00001 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;