2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-03 08:05:12 +00:00

Detach ComposeControls from SessionController.

This commit is contained in:
John Preston
2023-05-02 13:33:19 +04:00
parent 665467b02d
commit 65afa2c402
178 changed files with 2080 additions and 1869 deletions

View File

@@ -51,11 +51,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication>
namespace {
[[nodiscard]] QString PrimaryUsername(not_null<UserData*> user) {
const auto &usernames = user->usernames();
return usernames.empty() ? user->username() : usernames.front();
}
} // namespace
class FieldAutocomplete::Inner final : public Ui::RpWidget {
public:
struct ScrollTo {
@@ -64,7 +68,7 @@ public:
};
Inner(
not_null<Window::SessionController*> controller,
std::shared_ptr<ChatHelpers::Show> show,
not_null<FieldAutocomplete*> parent,
not_null<MentionRows*> mrows,
not_null<HashtagRows*> hrows,
@@ -120,7 +124,8 @@ private:
Media::Clip::Notification notification,
not_null<DocumentData*> document);
const not_null<Window::SessionController*> _controller;
const std::shared_ptr<ChatHelpers::Show> _show;
const not_null<Main::Session*> _session;
const not_null<FieldAutocomplete*> _parent;
const not_null<MentionRows*> _mrows;
const not_null<HashtagRows*> _hrows;
@@ -140,7 +145,7 @@ private:
bool _previewShown = false;
bool _isOneColumn = false;
bool _adjustShadowLeft = false;
const std::unique_ptr<Ui::PathShiftGradient> _pathGradient;
StickerPremiumMark _premiumMark;
@@ -182,8 +187,15 @@ struct FieldAutocomplete::BotCommandRow {
FieldAutocomplete::FieldAutocomplete(
QWidget *parent,
not_null<Window::SessionController*> controller)
: FieldAutocomplete(parent, controller->uiShow()) {
}
FieldAutocomplete::FieldAutocomplete(
QWidget *parent,
std::shared_ptr<ChatHelpers::Show> show)
: RpWidget(parent)
, _controller(controller)
, _show(std::move(show))
, _session(&_show->session())
, _scroll(this) {
hide();
@@ -191,7 +203,7 @@ FieldAutocomplete::FieldAutocomplete(
_inner = _scroll->setOwnedWidget(
object_ptr<Inner>(
_controller,
_show,
this,
&_mrows,
&_hrows,
@@ -215,8 +227,8 @@ FieldAutocomplete::FieldAutocomplete(
}), lifetime());
}
not_null<Window::SessionController*> FieldAutocomplete::controller() const {
return _controller;
std::shared_ptr<ChatHelpers::Show> FieldAutocomplete::uiShow() const {
return _show;
}
auto FieldAutocomplete::mentionChosen() const
@@ -365,7 +377,7 @@ inline int indexOfInFirstN(const T &v, const U &elem, int last) {
}
FieldAutocomplete::StickerRows FieldAutocomplete::getStickerSuggestions() {
const auto data = &_controller->session().data().stickers();
const auto data = &_session->data().stickers();
const auto list = data->getListByEmoji({ _emoji }, _stickersSeed);
auto result = ranges::views::all(
list
@@ -804,13 +816,14 @@ bool FieldAutocomplete::eventFilter(QObject *obj, QEvent *e) {
}
FieldAutocomplete::Inner::Inner(
not_null<Window::SessionController*> controller,
std::shared_ptr<ChatHelpers::Show> show,
not_null<FieldAutocomplete*> parent,
not_null<MentionRows*> mrows,
not_null<HashtagRows*> hrows,
not_null<BotCommandRows*> brows,
not_null<StickerRows*> srows)
: _controller(controller)
: _show(std::move(show))
, _session(&_show->session())
, _parent(parent)
, _mrows(mrows)
, _hrows(hrows)
@@ -820,16 +833,16 @@ FieldAutocomplete::Inner::Inner(
st::windowBgRipple,
st::windowBgOver,
[=] { update(); }))
, _premiumMark(&controller->session())
, _premiumMark(_session)
, _previewTimer([=] { showPreview(); }) {
controller->session().downloaderTaskFinished(
_session->downloaderTaskFinished(
) | rpl::start_with_next([=] {
update();
}, lifetime());
controller->adaptive().value(
) | rpl::start_with_next([=] {
_isOneColumn = controller->adaptive().isOneColumn();
_show->adjustShadowLeft(
) | rpl::start_with_next([=](bool adjust) {
_adjustShadowLeft = adjust;
update();
}, lifetime());
}
@@ -891,8 +904,8 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) {
}
media->checkStickerSmall();
const auto paused = _controller->isGifPausedAtLeastFor(
Window::GifPauseReason::TabbedPanel);
const auto paused = _show->paused(
ChatHelpers::PauseReason::TabbedPanel);
const auto size = ChatHelpers::ComputeStickerSize(
document,
stickerBoundingBox());
@@ -1062,9 +1075,19 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) {
}
}
}
p.fillRect(_isOneColumn ? 0 : st::lineWidth, _parent->innerBottom() - st::lineWidth, width() - (_isOneColumn ? 0 : st::lineWidth), st::lineWidth, st::shadowFg);
p.fillRect(
_adjustShadowLeft ? st::lineWidth : 0,
_parent->innerBottom() - st::lineWidth,
width() - (_adjustShadowLeft ? st::lineWidth : 0),
st::lineWidth,
st::shadowFg);
}
p.fillRect(_isOneColumn ? 0 : st::lineWidth, _parent->innerTop(), width() - (_isOneColumn ? 0 : st::lineWidth), st::lineWidth, st::shadowFg);
p.fillRect(
_adjustShadowLeft ? st::lineWidth : 0,
_parent->innerTop(),
width() - (_adjustShadowLeft ? st::lineWidth : 0),
st::lineWidth,
st::shadowFg);
}
void FieldAutocomplete::Inner::resizeEvent(QResizeEvent *e) {
@@ -1158,7 +1181,7 @@ bool FieldAutocomplete::Inner::chooseAtIndex(
contentRect.moveCenter(bounding.center());
return {
Ui::MessageSendingAnimationFrom::Type::Sticker,
_controller->session().data().nextLocalMessageId(),
_show->session().data().nextLocalMessageId(),
mapToGlobal(std::move(contentRect)),
};
};
@@ -1231,7 +1254,7 @@ void FieldAutocomplete::Inner::mousePressEvent(QMouseEvent *e) {
}
}
if (removed) {
_controller->session().local().writeRecentHashtagsAndBots();
_show->session().local().writeRecentHashtagsAndBots();
}
_parent->updateFiltered();
@@ -1483,11 +1506,7 @@ void FieldAutocomplete::Inner::selectByMouse(QPoint globalPosition) {
setSel(sel);
if (_down >= 0 && _sel >= 0 && _down != _sel) {
_down = _sel;
if (_down >= 0 && _down < _srows->size()) {
_controller->widget()->showMediaPreview(
(*_srows)[_down].document->stickerSetOrigin(),
(*_srows)[_down].document);
}
showPreview();
}
}
}
@@ -1504,9 +1523,8 @@ void FieldAutocomplete::Inner::onParentGeometryChanged() {
void FieldAutocomplete::Inner::showPreview() {
if (_down >= 0 && _down < _srows->size()) {
_controller->widget()->showMediaPreview(
(*_srows)[_down].document->stickerSetOrigin(),
(*_srows)[_down].document);
const auto document = (*_srows)[_down].document;
_show->showMediaPreview(document->stickerSetOrigin(), document);
_previewShown = true;
}
}