Files
AyuGramDesktop/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion_test.cpp
T

150 lines
4.1 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 "dialogs/dialogs_widget.h"
#ifdef _DEBUG
#include "base/call_delayed.h"
#include "data/data_authorization.h"
#include "dialogs/dialogs_inner_widget.h"
#include "dialogs/ui/dialogs_top_bar_suggestion_content.h"
#include "ui/painter.h"
#include "ui/widgets/elastic_scroll.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "styles/style_dialogs.h"
#include <QtGui/QShortcut>
namespace Dialogs {
void Widget::setupTopBarSuggestionTestHotkeys() {
const auto install = [this](Ui::SlideWrap<Ui::RpWidget> *wrap) {
_topBarSuggestionPlaceholder = nullptr;
_topBarSuggestion = nullptr;
if (!wrap) {
_scroll->setBarTopInset(0);
_topBarSuggestionHeightChanged.fire(0);
return;
}
_topBarSuggestionPlaceholder.reset(_innerList->insert(
0,
object_ptr<Ui::RpWidget>(_innerList)));
_topBarSuggestionPlaceholder->paintOn([
ph = _topBarSuggestionPlaceholder.get()
](QPainter &p) {
p.fillRect(ph->rect(), st::dialogsBg);
});
_topBarSuggestion.reset(wrap);
_topBarSuggestion->setParent(_scroll);
_topBarSuggestion->raise();
_topBarSuggestion->toggle(false, anim::type::instant);
_topBarSuggestion->heightValue(
) | rpl::on_next([=, this](int h) {
if (_topBarSuggestionPlaceholder) {
_topBarSuggestionPlaceholder->resize(
_topBarSuggestionPlaceholder->width(),
h);
}
_scroll->setBarTopInset(h);
_topBarSuggestionHeightChanged.fire_copy(h);
}, _topBarSuggestion->entity()->lifetime());
const auto pinToScroll = [this] {
if (_topBarSuggestion) {
_topBarSuggestion->resizeToWidth(_scroll->width());
_topBarSuggestion->moveToLeft(0, 0);
}
};
_scroll->sizeValue(
) | rpl::to_empty | rpl::on_next(
pinToScroll,
_topBarSuggestion->entity()->lifetime());
pinToScroll();
_topBarSuggestion->toggle(true, anim::type::normal);
};
const auto hideAndCleanup = [this] {
if (!_topBarSuggestion) {
return;
}
_topBarSuggestion->toggle(false, anim::type::normal);
const auto wrap = _topBarSuggestion.get();
base::call_delayed(st::slideWrapDuration * 2, wrap, [=, this] {
_topBarSuggestionPlaceholder = nullptr;
_topBarSuggestion = nullptr;
_scroll->setBarTopInset(0);
_topBarSuggestionHeightChanged.fire(0);
});
};
const auto regularShortcut = new QShortcut(
QKeySequence(u"Ctrl+Shift+T"_q),
this);
QObject::connect(
regularShortcut,
&QShortcut::activated,
this,
[=, this] {
using RightIcon = TopBarSuggestionContent::RightIcon;
const auto content = Ui::CreateChild<TopBarSuggestionContent>(
this);
content->setRightIcon(RightIcon::Close);
content->setContent(
TextWithEntities{ u"Test regular suggestion"_q },
TextWithEntities{
u"Press the X to dismiss, then Ctrl+Shift+T again."_q
});
content->setHideCallback(hideAndCleanup);
content->setCollapseProgress(_childListShown.value());
_prepareTopBarSnapshot.events(
) | rpl::on_next([content] {
content->prepareCollapseSnapshot();
}, content->lifetime());
const auto wrap = Ui::CreateChild<
Ui::SlideWrap<Ui::RpWidget>>(
this,
object_ptr<Ui::RpWidget>::fromRaw(content));
install(wrap);
});
const auto authShortcut = new QShortcut(
QKeySequence(u"Ctrl+Shift+A"_q),
this);
QObject::connect(
authShortcut,
&QShortcut::activated,
this,
[=, this] {
auto fake = std::vector<Data::UnreviewedAuth>();
fake.push_back({
.hash = 0,
.unconfirmed = true,
.device = u"Test Device"_q,
.location = u"Test Location"_q,
});
const auto auth = CreateUnconfirmedAuthContent(
this,
fake,
[=](bool) { hideAndCleanup(); },
_childListShown.value());
_prepareTopBarSnapshot.events(
) | rpl::on_next([auth] {
auth->prepareCollapseSnapshot();
}, auth->lifetime());
const auto wrap = Ui::CreateChild<
Ui::SlideWrap<Ui::RpWidget>>(
this,
object_ptr<Ui::RpWidget>::fromRaw(auth));
install(wrap);
});
}
} // namespace Dialogs
#endif // _DEBUG