Show exact option votes count in a tooltip.

Fixes #5505.
This commit is contained in:
John Preston 2018-12-24 14:12:45 +04:00
parent 76c06923d5
commit 57f2ae098f
5 changed files with 38 additions and 12 deletions

View file

@ -955,7 +955,7 @@ void HistoryInner::touchScrollUpdated(const QPoint &screenPos) {
touchUpdateSpeed();
}
QPoint HistoryInner::mapPointToItem(QPoint p, const Element *view) {
QPoint HistoryInner::mapPointToItem(QPoint p, const Element *view) const {
if (view) {
const auto top = itemTop(view);
p.setY(p.y() - top);
@ -964,7 +964,9 @@ QPoint HistoryInner::mapPointToItem(QPoint p, const Element *view) {
return QPoint();
}
QPoint HistoryInner::mapPointToItem(QPoint p, const HistoryItem *item) {
QPoint HistoryInner::mapPointToItem(
QPoint p,
const HistoryItem *item) const {
return item ? mapPointToItem(p, item->mainView()) : QPoint();
}
@ -2524,7 +2526,8 @@ void HistoryInner::mouseActionUpdate() {
}
if (dragState.link
|| dragState.cursor == CursorState::Date
|| dragState.cursor == CursorState::Forwarded) {
|| dragState.cursor == CursorState::Forwarded
|| dragState.customTooltip) {
Ui::Tooltip::Show(1000, this);
}
@ -3037,8 +3040,17 @@ QString HistoryInner::tooltipText() const {
return forwarded->text.originalText(AllTextSelection, ExpandLinksNone);
}
}
} else if (auto lnk = ClickHandler::getActive()) {
} else if (const auto lnk = ClickHandler::getActive()) {
return lnk->tooltip();
} else if (const auto view = App::mousedItem()) {
StateRequest request;
const auto local = mapFromGlobal(_mousePosition);
const auto point = _widget->clampMousePosition(local);
request.flags |= Text::StateRequest::Flag::LookupCustomTooltip;
const auto state = view->textState(
mapPointToItem(point, view),
request);
return state.customTooltipText;
}
return QString();
}

View file

@ -199,8 +199,8 @@ private:
std::unique_ptr<QMimeData> prepareDrag();
void performDrag();
QPoint mapPointToItem(QPoint p, const Element *view);
QPoint mapPointToItem(QPoint p, const HistoryItem *item);
QPoint mapPointToItem(QPoint p, const Element *view) const;
QPoint mapPointToItem(QPoint p, const HistoryItem *item) const;
void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
void cancelContextDownload(not_null<DocumentData*> document);

View file

@ -730,10 +730,11 @@ void HistoryPoll::startAnswersAnimation() const {
TextState HistoryPoll::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent);
if (!canVote() || !_poll->sendingVote.isEmpty()) {
if (!_poll->sendingVote.isEmpty()) {
return result;
}
const auto can = canVote();
const auto padding = st::msgPadding;
auto paintw = width();
auto tshift = st::historyPollQuestionTop;
@ -750,8 +751,18 @@ TextState HistoryPoll::textState(QPoint point, StateRequest request) const {
for (const auto &answer : _answers) {
const auto height = countAnswerHeight(answer, paintw);
if (point.y() >= tshift && point.y() < tshift + height) {
_lastLinkPoint = point;
result.link = answer.handler;
if (can) {
_lastLinkPoint = point;
result.link = answer.handler;
} else {
result.customTooltip = true;
using Flag = Text::StateRequest::Flag;
if (request.flags & Flag::LookupCustomTooltip) {
result.customTooltipText = answer.votes
? lng_polls_votes_count(lt_count, answer.votes)
: lang(lng_polls_votes_none);
}
}
return result;
}
tshift += height;

View file

@ -50,7 +50,9 @@ struct TextState {
CursorState cursor = CursorState::None;
ClickHandlerPtr link;
bool afterSymbol = false;
bool customTooltip = false;
uint16 symbol = 0;
QString customTooltipText;
};

View file

@ -115,9 +115,10 @@ public:
struct StateRequest {
enum class Flag {
BreakEverywhere = (1 << 0),
LookupSymbol = (1 << 1),
LookupLink = (1 << 2),
BreakEverywhere = (1 << 0),
LookupSymbol = (1 << 1),
LookupLink = (1 << 2),
LookupCustomTooltip = (1 << 3),
};
using Flags = base::flags<Flag>;
friend inline constexpr auto is_flag_type(Flag) { return true; };