Simplified installing of tooltip to some labels.

This commit is contained in:
23rd
2026-02-05 13:03:41 +03:00
committed by John Preston
parent 36e312193f
commit 2015a1c69f
3 changed files with 23 additions and 88 deletions
@@ -26,48 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace UrlAuthBox {
namespace {
class TextWithTooltip final
: public Ui::FlatLabel
, public Ui::AbstractTooltipShower {
public:
using Ui::FlatLabel::FlatLabel;
void setTooltip(QString text) {
_tooltip = std::move(text);
}
QString tooltipText() const override {
return _tooltip;
}
QPoint tooltipPos() const override {
return QCursor::pos();
}
bool tooltipWindowActive() const override {
return Ui::AppInFocus()
&& Ui::InFocusChain(window())
&& textMaxWidth() > width();
}
private:
void mouseMoveEvent(QMouseEvent *e) override {
Ui::Tooltip::Show(1000, this);
Ui::FlatLabel::mouseMoveEvent(e);
}
void enterEventHook(QEnterEvent *e) override {
Ui::Tooltip::Show(1000, this);
Ui::FlatLabel::enterEventHook(e);
}
void leaveEventHook(QEvent *e) override {
Ui::Tooltip::Hide();
Ui::FlatLabel::leaveEventHook(e);
}
QString _tooltip;
};
} // namespace
SwitchableUserpicButton::SwitchableUserpicButton(
@@ -144,18 +102,26 @@ void AddAuthInfoRow(
object_ptr<Ui::RpWidget>(container),
st::boxRowPadding);
const auto topLabel = Ui::CreateChild<TextWithTooltip>(
const auto topLabel = Ui::CreateChild<Ui::FlatLabel>(
row,
topText,
st::urlAuthBoxRowTopLabel);
topLabel->setSelectable(true);
topLabel->setTooltip(topText);
const auto bottomLabel = Ui::CreateChild<TextWithTooltip>(
Ui::InstallTooltip(topLabel, [=] {
return (topLabel->textMaxWidth() > topLabel->width())
? topText
: QString();
});
const auto bottomLabel = Ui::CreateChild<Ui::FlatLabel>(
row,
bottomText,
st::urlAuthBoxRowBottomLabel);
bottomLabel->setSelectable(true);
bottomLabel->setTooltip(bottomText);
Ui::InstallTooltip(bottomLabel, [=] {
return (bottomLabel->textMaxWidth() > bottomLabel->width())
? bottomText
: QString();
});
const auto leftLabel = Ui::CreateChild<Ui::FlatLabel>(
row,
leftText,
@@ -37,50 +37,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_window.h"
namespace Window {
namespace {
class VersionLabel final
: public Ui::FlatLabel
, public Ui::AbstractTooltipShower {
public:
using Ui::FlatLabel::FlatLabel;
void clickHandlerActiveChanged(
const ClickHandlerPtr &action,
bool active) override {
update();
if (active && action && !action->dragText().isEmpty()) {
Ui::Tooltip::Show(1000, this);
} else {
Ui::Tooltip::Hide();
}
}
QString tooltipText() const override {
return u"Build date: %1."_q.arg(__DATE__);
}
QPoint tooltipPos() const override {
return QCursor::pos();
}
bool tooltipWindowActive() const override {
return Ui::AppInFocus() && Ui::InFocusChain(window());
}
};
} // namespace
[[nodiscard]] not_null<Ui::FlatLabel*> AddVersionLabel(
not_null<Ui::RpWidget*> parent) {
return (Platform::IsMacStoreBuild() || Platform::IsWindowsStoreBuild())
? Ui::CreateChild<Ui::FlatLabel>(
parent.get(),
st::mainMenuVersionLabel)
: Ui::CreateChild<VersionLabel>(
parent.get(),
st::mainMenuVersionLabel);
const auto label = Ui::CreateChild<Ui::FlatLabel>(
parent.get(),
st::mainMenuVersionLabel);
if constexpr (Platform::IsMacStoreBuild()
|| Platform::IsWindowsStoreBuild()) {
Ui::InstallTooltip(label, [] {
return u"Build date: %1."_q.arg(__DATE__);
});
}
return label;
}
not_null<Ui::SettingsButton*> AddMyChannelsBox(