Fixed display of quiz solution in sections.

This commit is contained in:
23rd 2022-07-08 00:17:22 +03:00 committed by John Preston
parent 5fbbdd8a9e
commit 38322dc998
7 changed files with 110 additions and 41 deletions

View File

@ -0,0 +1,63 @@
/*
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 "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,
const TextWithEntities &text,
Fn<void()> hiddenCallback) {
hide(anim::type::normal);
_topToast = Ui::Toast::Show(parent, Ui::Toast::Config{
.text = text,
.st = &st::historyInfoToast,
.durationMs = CountToastDuration(text),
.multiline = true,
.dark = true,
.slideSide = RectPart::Top,
});
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

View File

@ -0,0 +1,33 @@
/*
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 "base/weak_ptr.h"
namespace Ui::Toast {
class Instance;
} // namespace Ui::Toast
namespace HistoryView {
class InfoTooltip final {
public:
InfoTooltip();
void show(
not_null<QWidget*> parent,
const TextWithEntities &text,
Fn<void()> hiddenCallback);
void hide(anim::type animated);
private:
base::weak_ptr<Ui::Toast::Instance> _topToast;
};
} // namespace HistoryView

View File

@ -198,13 +198,6 @@ base::options::toggle AutoScrollInactiveChat({
"even when the window is not in focus.",
});
[[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);
}
[[nodiscard]] rpl::producer<PeerData*> ActivePeerValue(
not_null<Window::SessionController*> controller) {
return controller->activeChatValue(
@ -2020,7 +2013,7 @@ void HistoryWidget::showHistory(
_highlighter.clear();
controller()->sendingAnimation().clear();
hideInfoTooltip(anim::type::instant);
_topToast.hide(anim::type::instant);
if (_history) {
if (_peer->id == peerId && !reload) {
updateForwarding();
@ -6723,32 +6716,7 @@ bool HistoryWidget::sendExistingPhoto(
void HistoryWidget::showInfoTooltip(
const TextWithEntities &text,
Fn<void()> hiddenCallback) {
hideInfoTooltip(anim::type::normal);
_topToast = Ui::Toast::Show(_scroll, Ui::Toast::Config{
.text = text,
.st = &st::historyInfoToast,
.durationMs = CountToastDuration(text),
.multiline = true,
.dark = true,
.slideSide = RectPart::Top,
});
if (const auto strong = _topToast.get()) {
if (hiddenCallback) {
connect(strong->widget(), &QObject::destroyed, hiddenCallback);
}
} else if (hiddenCallback) {
hiddenCallback();
}
}
void HistoryWidget::hideInfoTooltip(anim::type animated) {
if (const auto strong = _topToast.get()) {
if (animated == anim::type::normal) {
strong->hideAnimated();
} else {
strong->hide();
}
}
_topToast.show(_scroll.data(), text, std::move(hiddenCallback));
}
void HistoryWidget::showPremiumStickerTooltip(

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_drag_area.h"
#include "history/history_view_highlight_manager.h"
#include "history/history_view_top_toast.h"
#include "history/history.h"
#include "chat_helpers/bot_command.h"
#include "chat_helpers/field_autocomplete.h"
@ -74,9 +75,6 @@ struct PreparedList;
class SendFilesWay;
class SendAsButton;
enum class ReportReason;
namespace Toast {
class Instance;
} // namespace Toast
class ChooseThemeController;
class ContinuousScroll;
} // namespace Ui
@ -265,7 +263,6 @@ public:
void showInfoTooltip(
const TextWithEntities &text,
Fn<void()> hiddenCallback);
void hideInfoTooltip(anim::type animated);
void showPremiumStickerTooltip(
not_null<const HistoryView::Element*> view);
@ -779,7 +776,7 @@ private:
base::Timer _saveDraftTimer;
base::Timer _saveCloudDraftTimer;
base::weak_ptr<Ui::Toast::Instance> _topToast;
HistoryView::InfoTooltip _topToast;
std::unique_ptr<HistoryView::StickerToast> _stickerToast;
std::unique_ptr<ChooseMessagesForReport> _chooseForReport;

View File

@ -1447,8 +1447,10 @@ void ListWidget::elementCancelUpload(const FullMsgId &context) {
}
void ListWidget::elementShowTooltip(
const TextWithEntities &text,
Fn<void()> hiddenCallback) {
const TextWithEntities &text,
Fn<void()> hiddenCallback) {
// Under the parent is supposed to be a scroll widget.
_topToast.show(parentWidget(), text, hiddenCallback);
}
bool ListWidget::elementIsGifPaused() {

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_messages.h"
#include "history/view/history_view_element.h"
#include "history/history_view_highlight_manager.h"
#include "history/history_view_top_toast.h"
namespace Main {
class Session;
@ -641,6 +642,8 @@ private:
Ui::DraggingScrollManager _selectScroll;
InfoTooltip _topToast;
rpl::event_stream<FullMsgId> _requestedToEditMessage;
rpl::event_stream<FullMsgId> _requestedToReplyToMessage;
rpl::event_stream<FullMsgId> _requestedToReadMessage;

View File

@ -85,6 +85,9 @@ PRIVATE
editor/scene/scene_item_line.cpp
editor/scene/scene_item_line.h
history/history_view_top_toast.cpp
history/history_view_top_toast.h
layout/abstract_layout_item.cpp
layout/abstract_layout_item.h
layout/layout_mosaic.cpp