Fix poll answer check in custom chat themes.

This commit is contained in:
John Preston 2021-09-19 11:34:30 +03:00
parent 1f25777929
commit af100c2d13
5 changed files with 60 additions and 12 deletions

View File

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

View File

@ -214,6 +214,7 @@ private:
Ui::Animations::Simple _wrongAnswerAnimation;
mutable QPoint _lastLinkPoint;
mutable QImage _userpicCircleCache;
mutable QImage _fillingIconCache;
mutable std::unique_ptr<CloseInformation> _close;

View File

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

View File

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

View File

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