Add view solution button to polls.

This commit is contained in:
John Preston 2020-04-10 12:09:44 +04:00
parent 3cb76fb80b
commit 423daecbde
7 changed files with 65 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -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 {

View File

@ -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;

View File

@ -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

View File

@ -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;