From 423daecbdea95cdd1c9bcfc4ad51f99b16fe75ca Mon Sep 17 00:00:00 2001 From: John Preston <johnprestonmail@gmail.com> 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)<h;3K|Lk000e1NJLTq000;O000;W1^@s6;CDUv00004XF*Lt006O% z3;baP0005iNkl<ZNDa+XO{;-H6rOt%8?r+FfTh9$8#^0o|3b1>N=mV{!p@FA;15Vq z%End}<YQ^U0_EI!PVQUGydT}J?maa#&79{v&zy5+K7<e?$J^}lZOjkizZZzbVxr&g zi|uwRE|-f~uh*j2>xoDt;y8KqKp8HVi)ytR-EKG1+4+2?LZP6<X}DB!fItp|K(pDT zL?S^xpN~?h6t&xJL$g>c+KH$FAOkT*CX>+;<nwtJK_;?XTFfIGRbVg}aB!p1unIIX zkv*}(sRFy*js@cJxK$t}lS#&HHXAFPDsVcTIMDC+TLlvQF!{PnaoT?{pU-9agve&I zyqZn2;q1Z_wlYP%R4Vb!_WL~rgF(eF$tVyA&~mwCT(w%&Vt|9N;=~^qkH;K58jZ;9 zc0XY}9uG|>6ZX$$Gs0fSV=4egI2<N44_2?&p9os57N4(HD++}|Pd<&1n!z_HolY~+ z@pv?{@Or(3M{vL2DH@I1k;88;0N-M<U=i7HCd=h=yq`{|PRQ*ADwPTozE0(G`F8}+ z;7+GQhr@xc*DJ5xZr3Q8T?IZK0J*%!v>)wNYB(GUSt4U#@6;R#yplo8sr`=<IlZk8 g_oEW&h|JEu06kwJz<+s>%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)<h;3K|Lk000e1NJLTq001xm001xu1^@s6R|5Hm00004XF*Lt006O% z3;baP000DCNkl<ZXa((A$t!+u6n|cG=3!xGp$t*7zy?{6g_I%-3lb|NStx&kVr$sQ zu#tsqlrm+CrHu?_C_+hO%6z`hd3%4p_uT1yo_p{2C*{<ed+u}2=bX>;oaf$iA1=li z@ZXOWpC6mKC-Gkb-@SsrEAZVb;OA5V85tR@y1JT`m6frSloXbbkiY<dot>Sr<KtsC zJ3Gs!r>EKF<)u?0zi{v|YWbI+pASn*OFUQa^6~Kj6B84Vl$2ySo=&dTlK1!bhk=0s z`276zp1I26>FEjD+uNNYAx|JWIvQ41R#a)pt2hCEetvd|$PvJqH%fkfejZv{T7d5d z2n`K|@bGZR$;pAPt}fW#-qvL}I5_zK5*Qj9(j>CKzYoR5#ioh4TrOyAY=oPe8;yT! zYpbcRPTec*#aE!Puuv0xd3hNkBO{f7rq`L7nQ(M;L~w9VBqt}E`k9arC!j8!y}dn% zh=`C5j3st^drL@+kB>{^cu0v6$jZth0Z}O`DzX|B8X6i19zJ5@<KwO1i4o}O=^+8< z=H{#f`|`m(q2AbSZEauUCM82`gnJ=;!zyKJYD%d}U-Q{uqobq5ud=d|=%NZ?#GQ2Y zgM$OI0_o}Lx^_nXdiS%lvkB(z?yeO~{e;y4A08e^u#k`tE5V3QSXdaryuZIE<LVsr zbm0<ue}Cuxe<dg==&xe&%EyO>=WU5J5=Ag^KRrDqqZJhuM7N^w_X=@4KR+kBs3Np% zeSLjoxp#JUARr(>$d@OgvE#E3Yinx+b7W*hW2fh<x~BzK8Mr}l!>K#Z-rim-0o^|6 ztCrHzQY(031d!D5@US{2)YjHY2kq|e*5J&{%t+&SCR&^Tw$Xeqkl^@q%FD|W4vsG? zwOm|WKx}NRFovo^#0j8dK|ujLKR=Tk_-7-;#l?9|pr)oqQ-;_R<>uyk^;IRUw3j1* zK+Vm~ga9h|S&8j|QJ~b+RJgmlBYuyMk6znwBRs`@c>?I%-``J?L8Y#)&XB;^*ch>Y zd3gceo*3FI67*(cjexJOFDxu9kfiXjs24amI2f?!SBjO!O%I#jvqk{@($dlZ+hC>e z;}i{v^73+}iTi^F-vf4H|K}_GCgu(rIXpaMTU%S?eo09Q(NW<?FXZ0h;v%!sHV_bx zVv7J`@UJw2TVG$#_!Eio5@Y<t!F|Y8RaHf7*4NjGZdb9jlz8eOBX4hS5EBz)D<&tb z^e2jPK=^uNV?&t3<m99<t}0O@Kl=m{6BFU&<islpYyk1BNH8%`JNpDMp{S@R=;-Kx z&CN}?zP<)5mDkr-xVpN6)zwvKYHEVOz(CQYgza3O+2DVErr3T8eK&2#2y}LKGTxcG z|0lpVgXS-ep^ekxSP5Z*{6pU~Ki<4Ce&}mzBRlBW3dja_(q4GS^Pq;dygUFuZj1!S z(8dhI%9vv%<m8OXVEy<K`XwN<-2cM%cLn~%tjb{i0iQ_?!~cjM;Q#;t07*qoM6N<$ Eg72(H-~a#s literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/quiz_explain@3x.png b/Telegram/Resources/icons/quiz_explain@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..2c3b51b85e4e95fa5ca571b57fd155a8fa1d30d2 GIT binary patch literal 1759 zcmV<51|a!~P)<h;3K|Lk000e1NJLTq002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>!G@l`3 zL?+wXHm=FAKN0OR{<lxUbeJCValiNEv9%8(KF+=u+1kYRJq^M^2M__pUE~0Ar$PL7 z01;5!MGhc$8pLl05CO$q<N$J~LHu?A5m4Mke*rF>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<LambdaClickHandler>( + 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<Ui::RippleAnimation> _linkRipple; mutable std::unique_ptr<AnswersAnimation> _answersAnimation;