mirror of https://github.com/procxx/kepka.git
Add poll option select animation.
This commit is contained in:
parent
2981a16e17
commit
989fad8554
|
@ -151,6 +151,7 @@ struct Poll::Answer {
|
||||||
bool correct = false;
|
bool correct = false;
|
||||||
bool selected = false;
|
bool selected = false;
|
||||||
ClickHandlerPtr handler;
|
ClickHandlerPtr handler;
|
||||||
|
Ui::Animations::Simple selectedAnimation;
|
||||||
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
|
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -439,6 +440,11 @@ void Poll::toggleMultiOption(const QByteArray &option) {
|
||||||
if (i != end(_answers)) {
|
if (i != end(_answers)) {
|
||||||
const auto selected = i->selected;
|
const auto selected = i->selected;
|
||||||
i->selected = !selected;
|
i->selected = !selected;
|
||||||
|
i->selectedAnimation.start(
|
||||||
|
[=] { history()->owner().requestViewRepaint(_parent); },
|
||||||
|
selected ? 1. : 0.,
|
||||||
|
selected ? 0. : 1.,
|
||||||
|
st::defaultCheck.duration);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
const auto j = ranges::find(
|
const auto j = ranges::find(
|
||||||
_answers,
|
_answers,
|
||||||
|
@ -839,16 +845,10 @@ void Poll::paintRadio(
|
||||||
const auto over = ClickHandler::showAsActive(answer.handler);
|
const auto over = ClickHandler::showAsActive(answer.handler);
|
||||||
const auto ®ular = selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg);
|
const auto ®ular = selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg);
|
||||||
|
|
||||||
const auto checkmark = answer.selected;
|
const auto checkmark = answer.selectedAnimation.value(answer.selected ? 1. : 0.);
|
||||||
|
|
||||||
const auto o = p.opacity();
|
const auto o = p.opacity();
|
||||||
if (checkmark) {
|
if (checkmark < 1.) {
|
||||||
const auto color = outbg ? (selected ? st::msgFileThumbLinkOutFgSelected : st::msgFileThumbLinkOutFg) : (selected ? st::msgFileThumbLinkInFgSelected : st::msgFileThumbLinkInFg);
|
|
||||||
auto pen = color->p;
|
|
||||||
pen.setWidth(st.thickness);
|
|
||||||
p.setPen(pen);
|
|
||||||
p.setBrush(color);
|
|
||||||
} else {
|
|
||||||
p.setBrush(Qt::NoBrush);
|
p.setBrush(Qt::NoBrush);
|
||||||
p.setOpacity(o * (over ? st::historyPollRadioOpacityOver : st::historyPollRadioOpacity));
|
p.setOpacity(o * (over ? st::historyPollRadioOpacityOver : st::historyPollRadioOpacity));
|
||||||
}
|
}
|
||||||
|
@ -870,13 +870,21 @@ void Poll::paintRadio(
|
||||||
state.arcLength);
|
state.arcLength);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!checkmark) {
|
if (checkmark < 1.) {
|
||||||
auto pen = regular->p;
|
auto pen = regular->p;
|
||||||
pen.setWidth(st.thickness);
|
pen.setWidth(st.thickness);
|
||||||
p.setPen(pen);
|
p.setPen(pen);
|
||||||
}
|
|
||||||
p.drawEllipse(rect);
|
p.drawEllipse(rect);
|
||||||
if (checkmark) {
|
}
|
||||||
|
if (checkmark > 0.) {
|
||||||
|
const auto removeFull = (st.diameter / 2 - st.thickness);
|
||||||
|
const auto removeNow = removeFull * (1. - checkmark);
|
||||||
|
const auto color = outbg ? (selected ? st::msgFileThumbLinkOutFgSelected : st::msgFileThumbLinkOutFg) : (selected ? st::msgFileThumbLinkInFgSelected : st::msgFileThumbLinkInFg);
|
||||||
|
auto pen = color->p;
|
||||||
|
pen.setWidth(st.thickness);
|
||||||
|
p.setPen(pen);
|
||||||
|
p.setBrush(color);
|
||||||
|
p.drawEllipse(rect.marginsRemoved({ removeNow, removeNow, removeNow, removeNow }));
|
||||||
const auto &icon = outbg ? (selected ? st::historyPollOutChosenSelected : st::historyPollOutChosen) : (selected ? st::historyPollInChosenSelected : st::historyPollInChosen);
|
const auto &icon = outbg ? (selected ? st::historyPollOutChosenSelected : st::historyPollOutChosen) : (selected ? st::historyPollInChosenSelected : st::historyPollInChosen);
|
||||||
icon.paint(p, left + (st.diameter - icon.width()) / 2, top + (st.diameter - icon.height()) / 2, width());
|
icon.paint(p, left + (st.diameter - icon.width()) / 2, top + (st.diameter - icon.height()) / 2, width());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue