2018-12-18 13:56:38 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media.h"
|
2018-12-18 13:56:38 +00:00
|
|
|
|
2018-12-19 11:20:04 +00:00
|
|
|
struct PollAnswer;
|
|
|
|
|
2019-08-02 13:21:09 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
|
|
|
|
class Poll : public Media {
|
2018-12-18 13:56:38 +00:00
|
|
|
public:
|
2019-08-02 13:21:09 +00:00
|
|
|
Poll(
|
2018-12-18 13:56:38 +00:00
|
|
|
not_null<Element*> parent,
|
|
|
|
not_null<PollData*> poll);
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override;
|
2018-12-18 13:56:38 +00:00
|
|
|
TextState textState(QPoint point, StateRequest request) const override;
|
|
|
|
|
|
|
|
bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool dragItemByHandler(const ClickHandlerPtr &p) const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsBubble() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool customInfoLayout() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-24 10:03:13 +00:00
|
|
|
void clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &handler,
|
|
|
|
bool pressed) override;
|
|
|
|
|
2019-08-02 13:21:09 +00:00
|
|
|
~Poll();
|
2018-12-19 11:20:04 +00:00
|
|
|
|
2018-12-18 13:56:38 +00:00
|
|
|
private:
|
2018-12-22 19:32:04 +00:00
|
|
|
struct AnswerAnimation;
|
|
|
|
struct AnswersAnimation;
|
|
|
|
struct SendingAnimation;
|
|
|
|
struct Answer;
|
2018-12-22 18:36:00 +00:00
|
|
|
|
2018-12-18 13:56:38 +00:00
|
|
|
QSize countOptimalSize() override;
|
|
|
|
QSize countCurrentSize(int newWidth) override;
|
|
|
|
|
2019-08-20 12:05:51 +00:00
|
|
|
[[nodiscard]] bool showVotes() const;
|
|
|
|
[[nodiscard]] bool canVote() const;
|
2018-12-22 18:36:00 +00:00
|
|
|
|
2018-12-24 10:03:13 +00:00
|
|
|
[[nodiscard]] int countAnswerTop(
|
|
|
|
const Answer &answer,
|
|
|
|
int innerWidth) const;
|
|
|
|
[[nodiscard]] int countAnswerHeight(
|
|
|
|
const Answer &answer,
|
|
|
|
int innerWidth) const;
|
2018-12-19 11:20:04 +00:00
|
|
|
[[nodiscard]] ClickHandlerPtr createAnswerClickHandler(
|
|
|
|
const Answer &answer) const;
|
2018-12-18 13:56:38 +00:00
|
|
|
void updateTexts();
|
2018-12-22 10:23:22 +00:00
|
|
|
void updateAnswers();
|
2018-12-25 14:17:02 +00:00
|
|
|
void updateVotes();
|
|
|
|
void updateTotalVotes();
|
|
|
|
void updateAnswerVotes();
|
2018-12-19 11:20:04 +00:00
|
|
|
void updateAnswerVotesFromOriginal(
|
2018-12-25 14:17:02 +00:00
|
|
|
Answer &answer,
|
2018-12-19 11:20:04 +00:00
|
|
|
const PollAnswer &original,
|
2018-12-25 14:17:02 +00:00
|
|
|
int percent,
|
|
|
|
int maxVotes);
|
|
|
|
void checkSendingAnimation() const;
|
2018-12-19 11:20:04 +00:00
|
|
|
|
|
|
|
int paintAnswer(
|
|
|
|
Painter &p,
|
|
|
|
const Answer &answer,
|
2018-12-22 18:36:00 +00:00
|
|
|
const AnswerAnimation *animation,
|
2018-12-19 11:20:04 +00:00
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int width,
|
|
|
|
int outerWidth,
|
2019-04-02 09:13:30 +00:00
|
|
|
TextSelection selection) const;
|
2018-12-22 18:36:00 +00:00
|
|
|
void paintRadio(
|
|
|
|
Painter &p,
|
|
|
|
const Answer &answer,
|
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
TextSelection selection) const;
|
|
|
|
void paintPercent(
|
|
|
|
Painter &p,
|
|
|
|
const QString &percent,
|
|
|
|
int percentWidth,
|
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int outerWidth,
|
|
|
|
TextSelection selection) const;
|
|
|
|
void paintFilling(
|
|
|
|
Painter &p,
|
|
|
|
float64 filling,
|
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
TextSelection selection) const;
|
|
|
|
|
|
|
|
bool checkAnimationStart() const;
|
|
|
|
bool answerVotesChanged() const;
|
|
|
|
void saveStateInAnimation() const;
|
2018-12-22 19:32:04 +00:00
|
|
|
void startAnswersAnimation() const;
|
|
|
|
void resetAnswersAnimation() const;
|
2019-04-01 17:44:54 +00:00
|
|
|
void radialAnimationCallback() const;
|
2018-12-18 13:56:38 +00:00
|
|
|
|
2018-12-24 10:03:13 +00:00
|
|
|
void toggleRipple(Answer &answer, bool pressed);
|
|
|
|
|
2018-12-18 13:56:38 +00:00
|
|
|
not_null<PollData*> _poll;
|
|
|
|
int _pollVersion = 0;
|
2018-12-25 14:17:02 +00:00
|
|
|
int _totalVotes = 0;
|
|
|
|
bool _voted = false;
|
2018-12-19 11:20:04 +00:00
|
|
|
bool _closed = false;
|
2018-12-18 13:56:38 +00:00
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String _question;
|
|
|
|
Ui::Text::String _subtitle;
|
2018-12-18 13:56:38 +00:00
|
|
|
std::vector<Answer> _answers;
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String _totalVotesLabel;
|
2018-12-18 13:56:38 +00:00
|
|
|
|
2018-12-22 18:36:00 +00:00
|
|
|
mutable std::unique_ptr<AnswersAnimation> _answersAnimation;
|
2018-12-22 19:32:04 +00:00
|
|
|
mutable std::unique_ptr<SendingAnimation> _sendingAnimation;
|
2018-12-24 10:03:13 +00:00
|
|
|
mutable QPoint _lastLinkPoint;
|
2018-12-22 18:36:00 +00:00
|
|
|
|
2018-12-18 13:56:38 +00:00
|
|
|
};
|
2019-08-02 13:21:09 +00:00
|
|
|
|
|
|
|
} // namespace HistoryView
|