tdesktop/Telegram/SourceFiles/history/media/history_media_poll.h

90 lines
2.0 KiB
C
Raw Normal View History

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
#include "history/media/history_media.h"
2018-12-19 11:20:04 +00:00
struct PollAnswer;
2018-12-18 13:56:38 +00:00
class HistoryPoll : public HistoryMedia {
public:
HistoryPoll(
not_null<Element*> parent,
not_null<PollData*> poll);
void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const override;
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-19 11:20:04 +00:00
~HistoryPoll();
2018-12-18 13:56:38 +00:00
private:
struct Answer {
Answer();
Text text;
QByteArray option;
mutable int votes = 0;
2018-12-19 11:20:04 +00:00
mutable int votesPercentWidth = 0;
mutable float64 filling = 0.;
mutable QString votesPercent;
2018-12-18 13:56:38 +00:00
mutable bool chosen = false;
2018-12-19 11:20:04 +00:00
ClickHandlerPtr handler;
2018-12-18 13:56:38 +00:00
};
QSize countOptimalSize() override;
QSize countCurrentSize(int newWidth) override;
2018-12-19 11:20:04 +00:00
int countAnswerHeight(const Answer &answer, int innerWidth) const;
[[nodiscard]] ClickHandlerPtr createAnswerClickHandler(
const Answer &answer) const;
2018-12-18 13:56:38 +00:00
void updateTexts();
void updateVotes() const;
void updateTotalVotes() const;
2018-12-19 11:20:04 +00:00
void updateAnswerVotes() const;
void updateAnswerVotesFromOriginal(
const Answer &answer,
const PollAnswer &original,
int totalVotes,
int maxVotes) const;
int paintAnswer(
Painter &p,
const Answer &answer,
int left,
int top,
int width,
int outerWidth,
TextSelection selection,
TimeMs ms) const;
2018-12-18 13:56:38 +00:00
not_null<PollData*> _poll;
int _pollVersion = 0;
mutable int _totalVotes = 0;
mutable bool _voted = false;
2018-12-19 11:20:04 +00:00
bool _closed = false;
2018-12-18 13:56:38 +00:00
Text _question;
Text _subtitle;
std::vector<Answer> _answers;
mutable Text _totalVotesLabel;
};