Files
tdesktop/Telegram/SourceFiles/history/history_view_top_toast.cpp
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

65 lines
1.5 KiB
C++

/*
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
*/
#include "history/history_view_top_toast.h"
#include "ui/toast/toast.h"
#include "core/ui_integration.h"
#include "styles/style_chat.h"
namespace HistoryView {
namespace {
[[nodiscard]] crl::time CountToastDuration(const TextWithEntities &text) {
return std::clamp(
crl::time(1000) * int(text.text.size()) / 14,
crl::time(1000) * 5,
crl::time(1000) * 8);
}
} // namespace
InfoTooltip::InfoTooltip() = default;
void InfoTooltip::show(
not_null<QWidget*> parent,
not_null<Main::Session*> session,
const TextWithEntities &text,
Fn<void()> hiddenCallback) {
hide(anim::type::normal);
_topToast = Ui::Toast::Show(parent, Ui::Toast::Config{
.text = text,
.textContext = Core::TextContext({ .session = session }),
.st = &st::historyInfoToast,
.attach = RectPart::Top,
.duration = CountToastDuration(text),
});
if (const auto strong = _topToast.get()) {
if (hiddenCallback) {
QObject::connect(
strong->widget(),
&QObject::destroyed,
hiddenCallback);
}
} else if (hiddenCallback) {
hiddenCallback();
}
}
void InfoTooltip::hide(anim::type animated) {
if (const auto strong = _topToast.get()) {
if (animated == anim::type::normal) {
strong->hideAnimated();
} else {
strong->hide();
}
}
}
} // namespace HistoryView