From dc631ef631a4e8e52632d8cc06ec7b3afb7b3f16 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 22 Jan 2021 02:36:22 +0300 Subject: [PATCH] Added ability to see url of inline button in tooltip. Fixed #5457. --- .../history/history_item_components.cpp | 42 ++++++++++++------- .../history/history_item_components.h | 6 +-- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index a1292c6bb..59ccf1ca5 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -413,23 +413,13 @@ ReplyMarkupClickHandler::ReplyMarkupClickHandler( // Copy to clipboard support. QString ReplyMarkupClickHandler::copyToClipboardText() const { - if (const auto button = getButton()) { - using Type = HistoryMessageMarkupButton::Type; - if (button->type == Type::Url || button->type == Type::Auth) { - return QString::fromUtf8(button->data); - } - } - return QString(); + const auto button = getUrlButton(); + return button ? QString::fromUtf8(button->data) : QString(); } QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const { - if (const auto button = getButton()) { - using Type = HistoryMessageMarkupButton::Type; - if (button->type == Type::Url || button->type == Type::Auth) { - return tr::lng_context_copy_link(tr::now); - } - } - return QString(); + const auto button = getUrlButton(); + return button ? tr::lng_context_copy_link(tr::now) : QString(); } // Finds the corresponding button in the items markup struct. @@ -440,6 +430,17 @@ const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const { return HistoryMessageMarkupButton::Get(_owner, _itemId, _row, _column); } +auto ReplyMarkupClickHandler::getUrlButton() const +-> const HistoryMessageMarkupButton* { + if (const auto button = getButton()) { + using Type = HistoryMessageMarkupButton::Type; + if (button->type == Type::Url || button->type == Type::Auth) { + return button; + } + } + return nullptr; +} + void ReplyMarkupClickHandler::onClickImpl() const { if (const auto item = _owner->message(_itemId)) { App::activateBotCommand(item, _row, _column); @@ -454,6 +455,19 @@ QString ReplyMarkupClickHandler::buttonText() const { return QString(); } +QString ReplyMarkupClickHandler::tooltip() const { + const auto button = getUrlButton(); + const auto url = button ? QString::fromUtf8(button->data) : QString(); + const auto text = _fullDisplayed ? QString() : buttonText(); + if (!url.isEmpty() && !text.isEmpty()) { + return QString("%1\n\n%2").arg(text).arg(url); + } else if (url.isEmpty() != text.isEmpty()) { + return text + url; + } else { + return QString(); + } +} + ReplyKeyboard::Button::Button() = default; ReplyKeyboard::Button::Button(Button &&other) = default; ReplyKeyboard::Button &ReplyKeyboard::Button::operator=( diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 5e720fb20..36a7fc4cf 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -251,9 +251,7 @@ public: int column, FullMsgId context); - QString tooltip() const override { - return _fullDisplayed ? QString() : buttonText(); - } + QString tooltip() const override; void setFullDisplayed(bool full) { _fullDisplayed = full; @@ -269,6 +267,8 @@ public: // than the one was used when constructing the handler, but not a big deal. const HistoryMessageMarkupButton *getButton() const; + const HistoryMessageMarkupButton *getUrlButton() const; + // We hold only FullMsgId, not HistoryItem*, because all click handlers // are activated async and the item may be already destroyed. void setMessageId(const FullMsgId &msgId) {