From 570cd9bdfa8b0b7c7fabf1e856d1dc6427befa85 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 7 Apr 2017 21:10:49 +0300 Subject: [PATCH] Move GIF pausing methods to Window::Controller. --- Telegram/SourceFiles/boxes/abstract_box.cpp | 3 +- Telegram/SourceFiles/boxes/abstract_box.h | 20 +++++++++--- Telegram/SourceFiles/boxes/send_files_box.cpp | 10 +++--- .../chat_helpers/emoji_list_widget.cpp | 2 +- .../chat_helpers/emoji_list_widget.h | 6 +++- .../SourceFiles/chat_helpers/emoji_panel.cpp | 11 ++++--- .../SourceFiles/chat_helpers/emoji_panel.h | 14 +++++++-- .../chat_helpers/gifs_list_widget.cpp | 13 ++++---- .../chat_helpers/gifs_list_widget.h | 6 +++- .../chat_helpers/stickers_list_widget.cpp | 2 +- .../chat_helpers/stickers_list_widget.h | 6 +++- .../history/history_media_types.cpp | 3 +- Telegram/SourceFiles/historywidget.cpp | 13 ++++---- Telegram/SourceFiles/historywidget.h | 4 ++- .../inline_bots/inline_results_widget.cpp | 19 +++++++----- .../inline_bots/inline_results_widget.h | 12 +++++-- Telegram/SourceFiles/layerwidget.cpp | 18 ++++++----- Telegram/SourceFiles/layerwidget.h | 15 ++++++--- Telegram/SourceFiles/mainwidget.cpp | 16 +++++----- Telegram/SourceFiles/mainwidget.h | 5 +-- Telegram/SourceFiles/mainwindow.cpp | 28 +++++++++-------- Telegram/SourceFiles/mainwindow.h | 7 ++++- Telegram/SourceFiles/window/main_window.cpp | 26 ---------------- Telegram/SourceFiles/window/main_window.h | 20 ------------ .../SourceFiles/window/window_controller.cpp | 31 +++++++++++++++++++ .../SourceFiles/window/window_controller.h | 29 ++++++++++++++++- Telegram/gyp/telegram_sources.txt | 2 ++ 27 files changed, 214 insertions(+), 127 deletions(-) diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index 05a3ef959..ea40f1571 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -194,7 +194,8 @@ void BoxContent::paintEvent(QPaintEvent *e) { } } -AbstractBox::AbstractBox(QWidget *parent, object_ptr content) : LayerWidget(parent) +AbstractBox::AbstractBox(QWidget *parent, Window::Controller *controller, object_ptr content) : LayerWidget(parent) +, _controller(controller) , _content(std::move(content)) { _content->setParent(this); _content->setDelegate(this); diff --git a/Telegram/SourceFiles/boxes/abstract_box.h b/Telegram/SourceFiles/boxes/abstract_box.h index 867b50fc6..234a50857 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.h +++ b/Telegram/SourceFiles/boxes/abstract_box.h @@ -31,6 +31,10 @@ template class WidgetFadeWrap; } // namespace Ui +namespace Window { +class Controller; +} // namespace Window + class BoxLayerTitleShadow : public Ui::PlainShadow { public: BoxLayerTitleShadow(QWidget *parent); @@ -39,6 +43,8 @@ public: class BoxContentDelegate { public: + virtual Window::Controller *controller() const = 0; + virtual void setLayerType(bool layerType) = 0; virtual void setTitle(const QString &title, const QString &additional) = 0; @@ -61,8 +67,6 @@ public: BoxContent() { setAttribute(Qt::WA_OpaquePaintEvent); } - BoxContent(QWidget*) : BoxContent() { - } bool isBoxShown() const { return getDelegate()->isBoxShown(); @@ -107,6 +111,10 @@ public slots: protected: virtual void prepare() = 0; + Window::Controller *controller() { + return getDelegate()->controller(); + } + void setLayerType(bool layerType) { getDelegate()->setLayerType(layerType); } @@ -165,7 +173,7 @@ private: object_ptr doTakeInnerWidget(); BoxContentDelegate *getDelegate() const { - t_assert(_delegate != nullptr); + Expects(_delegate != nullptr); return _delegate; } BoxContentDelegate *_delegate = nullptr; @@ -183,8 +191,11 @@ private: class AbstractBox : public LayerWidget, public BoxContentDelegate, protected base::Subscriber { public: - AbstractBox(QWidget *parent, object_ptr content); + AbstractBox(QWidget *parent, Window::Controller *controller, object_ptr content); + Window::Controller *controller() const override { + return _controller; + } void parentResized() override; void setLayerType(bool layerType) override; @@ -235,6 +246,7 @@ private: int countRealHeight() const; void updateSize(); + Window::Controller *_controller = nullptr; int _fullHeight = 0; bool _noContentMargin = false; diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 3b6f213ec..f18d428fc 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -31,7 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_history.h" #include "styles/style_boxes.h" #include "media/media_clip_reader.h" -#include "mainwindow.h" +#include "window/window_controller.h" namespace { @@ -61,7 +61,7 @@ SendFilesBox::SendFilesBox(QWidget*, const QStringList &files, CompressConfirm c } void SendFilesBox::prepareSingleFileLayout() { - t_assert(_files.size() == 1); + Expects(_files.size() == 1); if (!_files.front().isEmpty()) { tryToReadSingleFile(); } @@ -231,6 +231,8 @@ SendFilesBox::SendFilesBox(QWidget*, const QString &phone, const QString &firstn } void SendFilesBox::prepare() { + Expects(controller() != nullptr); + if (_files.size() > 1) { updateTitleText(); } @@ -331,7 +333,7 @@ void SendFilesBox::paintEvent(QPaintEvent *e) { } if (_gifPreview && _gifPreview->started()) { auto s = QSize(_previewWidth, _previewHeight); - auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer); + auto paused = controller()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer); auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms()); p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), frame); } else { @@ -673,7 +675,7 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) { } if (_gifPreview && _gifPreview->started()) { auto s = QSize(_thumbw, _thumbh); - auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer); + auto paused = controller()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer); auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms()); p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), frame); } else { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 9e386b7dd..e20b0a7c0 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -302,7 +302,7 @@ void EmojiColorPicker::drawVariant(Painter &p, int variant) { p.drawPixmapLeft(w.x() + (st::emojiPanSize.width() - (esize / cIntRetinaFactor())) / 2, w.y() + (st::emojiPanSize.height() - (esize / cIntRetinaFactor())) / 2, width(), App::emojiLarge(), QRect(_variants[variant]->x() * esize, _variants[variant]->y() * esize, esize, esize)); } -EmojiListWidget::EmojiListWidget(QWidget *parent) : Inner(parent) +EmojiListWidget::EmojiListWidget(QWidget *parent, gsl::not_null controller) : Inner(parent, controller) , _picker(this) { resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight()); diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h index 7565534f5..1ab76510a 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h @@ -22,6 +22,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "chat_helpers/emoji_panel.h" +namespace Window { +class Controller; +} // namespace Window + namespace ChatHelpers { constexpr auto kEmojiSectionCount = 8; @@ -84,7 +88,7 @@ class EmojiListWidget : public EmojiPanel::Inner { Q_OBJECT public: - EmojiListWidget(QWidget *parent); + EmojiListWidget(QWidget *parent, gsl::not_null controller); using Section = Ui::Emoji::Section; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_panel.cpp b/Telegram/SourceFiles/chat_helpers/emoji_panel.cpp index 678d6f7f7..0ada17fe4 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_panel.cpp @@ -279,15 +279,15 @@ void EmojiPanel::Tab::saveScrollTop() { _scrollTop = widget()->getVisibleTop(); } -EmojiPanel::EmojiPanel(QWidget *parent) : TWidget(parent) +EmojiPanel::EmojiPanel(QWidget *parent, gsl::not_null controller) : TWidget(parent) , _tabsSlider(this, st::emojiTabs) , _topShadow(this, st::shadowFg) , _bottomShadow(this, st::shadowFg) , _scroll(this, st::emojiScroll) , _tabs { { - Tab { TabType::Emoji, object_ptr(this) }, - Tab { TabType::Stickers, object_ptr(this) }, - Tab { TabType::Gifs, object_ptr(this) }, + Tab { TabType::Emoji, object_ptr(this, controller) }, + Tab { TabType::Stickers, object_ptr(this, controller) }, + Tab { TabType::Gifs, object_ptr(this, controller) }, } } , _currentTabType(AuthSession::Current().data().emojiPanelTab()) { resize(QRect(0, 0, st::emojiPanWidth, st::emojiPanMaxHeight).marginsAdded(innerPadding()).size()); @@ -879,7 +879,8 @@ void EmojiPanel::scrollToY(int y) { _topShadow->update(); } -EmojiPanel::Inner::Inner(QWidget *parent) : TWidget(parent) { +EmojiPanel::Inner::Inner(QWidget *parent, gsl::not_null controller) : TWidget(parent) +, _controller(controller) { } void EmojiPanel::Inner::setVisibleTopBottom(int visibleTop, int visibleBottom) { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_panel.h b/Telegram/SourceFiles/chat_helpers/emoji_panel.h index 579cc84fe..2e7e59ac4 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_panel.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_panel.h @@ -36,6 +36,10 @@ class RippleAnimation; class SettingsSlider; } // namesapce Ui +namespace Window { +class Controller; +} // namespace Window + namespace ChatHelpers { class EmojiListWidget; @@ -46,7 +50,7 @@ class EmojiPanel : public TWidget { Q_OBJECT public: - EmojiPanel(QWidget *parent); + EmojiPanel(QWidget *parent, gsl::not_null controller); void moveBottom(int bottom); @@ -234,7 +238,7 @@ class EmojiPanel::Inner : public TWidget { Q_OBJECT public: - Inner(QWidget *parent); + Inner(QWidget *parent, gsl::not_null controller); void setVisibleTopBottom(int visibleTop, int visibleBottom) override; @@ -265,6 +269,10 @@ signals: void saveConfigDelayed(int delay); protected: + gsl::not_null controller() const { + return _controller; + } + virtual int countHeight() = 0; virtual InnerFooter *getFooter() const = 0; virtual void processHideFinished() { @@ -273,6 +281,8 @@ protected: } private: + gsl::not_null _controller; + int _visibleTop = 0; int _visibleBottom = 0; diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index b74c479a5..26021a6fd 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -30,6 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "storage/localstorage.h" #include "lang.h" #include "mainwindow.h" +#include "window/window_controller.h" namespace ChatHelpers { namespace { @@ -115,7 +116,7 @@ void GifsListWidget::Footer::processPanelHideFinished() { _field->setText(QString()); } -GifsListWidget::GifsListWidget(QWidget *parent) : Inner(parent) +GifsListWidget::GifsListWidget(QWidget *parent, gsl::not_null controller) : Inner(parent, controller) , _section(Section::Gifs) { resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight()); @@ -137,8 +138,8 @@ GifsListWidget::GifsListWidget(QWidget *parent) : Inner(parent) subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); - subscribe(App::wnd()->gifPauseLevelChanged(), [this] { - if (!App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs)) { + subscribe(controller->gifPauseLevelChanged(), [this] { + if (!this->controller()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs)) { update(); } }); @@ -253,7 +254,7 @@ void GifsListWidget::paintInlineItems(Painter &p, QRect clip) { p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center); return; } - auto gifPaused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs); + auto gifPaused = controller()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs); InlineBots::Layout::PaintContext context(getms(), false, gifPaused, false); auto top = st::stickerPanPadding; @@ -388,7 +389,7 @@ EmojiPanel::InnerFooter *GifsListWidget::getFooter() const { void GifsListWidget::processHideFinished() { clearSelection(); - App::wnd()->disableGifPauseReason(Window::GifPauseReason::SavedGifs); + controller()->disableGifPauseReason(Window::GifPauseReason::SavedGifs); } void GifsListWidget::processPanelHideFinished() { @@ -749,7 +750,7 @@ void GifsListWidget::afterShown() { if (_footer) { _footer->stealFocus(); } - App::wnd()->enableGifPauseReason(Window::GifPauseReason::SavedGifs); + controller()->enableGifPauseReason(Window::GifPauseReason::SavedGifs); } void GifsListWidget::beforeHiding() { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index 2921cf833..8e7c7f29c 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -34,13 +34,17 @@ namespace Ui { class RoundButton; } // namespace Ui +namespace Window { +class Controller; +} // namespace Window + namespace ChatHelpers { class GifsListWidget : public EmojiPanel::Inner, public InlineBots::Layout::Context, private base::Subscriber, private MTP::Sender { Q_OBJECT public: - GifsListWidget(QWidget *parent); + GifsListWidget(QWidget *parent, gsl::not_null controller); void refreshRecent() override; void preloadImages() override; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index d7131b53a..f24889ffb 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -412,7 +412,7 @@ void StickersListWidget::Footer::step_icons(TimeMs ms, bool timer) { } } -StickersListWidget::StickersListWidget(QWidget *parent) : Inner(parent) +StickersListWidget::StickersListWidget(QWidget *parent, gsl::not_null controller) : Inner(parent, controller) , _section(Section::Stickers) , _addText(lang(lng_stickers_featured_add).toUpper()) , _addWidth(st::stickersTrendingAdd.font->width(_addText)) diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 7ab30a346..8f4ebec98 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -23,6 +23,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "chat_helpers/emoji_panel.h" #include "base/variant.h" +namespace Window { +class Controller; +} // namespace Window + namespace Ui { class LinkButton; } // namespace Ui @@ -35,7 +39,7 @@ class StickersListWidget : public EmojiPanel::Inner, private base::Subscriber, p Q_OBJECT public: - StickersListWidget(QWidget *parent); + StickersListWidget(QWidget *parent, gsl::not_null controller); void refreshRecent() override; void preloadImages() override; diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index ffb1a64d0..35ab7f127 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "boxes/add_contact_box.h" #include "core/click_handler_types.h" #include "history/history_location_manager.h" +#include "window/window_controller.h" #include "styles/style_history.h" namespace { @@ -1844,7 +1845,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM auto roundCorners = inWebPage ? ImageRoundCorner::All : ((isBubbleTop() ? (ImageRoundCorner::TopLeft | ImageRoundCorner::TopRight) : ImageRoundCorner::None) | ((isBubbleBottom() && _caption.isEmpty()) ? (ImageRoundCorner::BottomLeft | ImageRoundCorner::BottomRight) : ImageRoundCorner::None)); if (animating) { - auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Any); + auto paused = App::wnd()->controller()->isGifPausedAtLeastFor(Window::GifPauseReason::Any); p.drawPixmap(rthumb.topLeft(), _gif->current(_thumbw, _thumbh, width, height, roundRadius, roundCorners, paused ? 0 : ms)); } else { p.drawPixmap(rthumb.topLeft(), _data->thumb->pixBlurredSingle(_thumbw, _thumbh, width, height, roundRadius, roundCorners)); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index a7f9ba1e3..d8f2d46ba 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -147,7 +147,8 @@ private: // flick scroll taken from http://qt-project.org/doc/qt-4.8/demos-embedded-anomaly-src-flickcharm-cpp.html -HistoryInner::HistoryInner(HistoryWidget *historyWidget, Ui::ScrollArea *scroll, History *history) : TWidget(nullptr) +HistoryInner::HistoryInner(HistoryWidget *historyWidget, gsl::not_null controller, Ui::ScrollArea *scroll, History *history) : TWidget(nullptr) +, _controller(controller) , _peer(history->peer) , _migrated(history->peer->migrateFrom() ? App::history(history->peer->migrateFrom()->id) : nullptr) , _history(history) @@ -170,8 +171,8 @@ HistoryInner::HistoryInner(HistoryWidget *historyWidget, Ui::ScrollArea *scroll, subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) { itemRemoved(item); }); - subscribe(App::wnd()->gifPauseLevelChanged(), [this] { - if (!App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Any)) { + subscribe(_controller->gifPauseLevelChanged(), [this] { + if (!_controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any)) { update(); } }); @@ -3224,7 +3225,7 @@ HistoryWidget::HistoryWidget(QWidget *parent, gsl::not_null , _recordCancelWidth(st::historyRecordFont->width(lang(lng_record_cancel))) , _a_recording(animation(this, &HistoryWidget::step_recording)) , _kbScroll(this, st::botKbScroll) -, _emojiPanel(this) +, _emojiPanel(this, controller) , _attachDragDocument(this) , _attachDragPhoto(this) , _fileLoader(this, FileLoaderQueueStopTimeout) @@ -3438,7 +3439,7 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) { inlineBotChanged(); } if (!_inlineResults) { - _inlineResults.create(this); + _inlineResults.create(this, _controller); _inlineResults->setResultSelectedCallback([this](InlineBots::Result *result, UserData *bot) { onInlineResultSend(result, bot); }); @@ -4489,7 +4490,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re } _scroll->hide(); - _list = _scroll->setOwnedWidget(object_ptr(this, _scroll, _history)); + _list = _scroll->setOwnedWidget(object_ptr(this, _controller, _scroll, _history)); _list->show(); _updateHistoryItems.stop(); diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 5ce0ca6d0..964ea7a1b 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -70,7 +70,7 @@ class HistoryInner : public TWidget, public Ui::AbstractTooltipShower, private b Q_OBJECT public: - HistoryInner(HistoryWidget *historyWidget, Ui::ScrollArea *scroll, History *history); + HistoryInner(HistoryWidget *historyWidget, gsl::not_null controller, Ui::ScrollArea *scroll, History *history); void messagesReceived(PeerData *peer, const QVector &messages); void messagesReceivedDown(PeerData *peer, const QVector &messages); @@ -187,6 +187,8 @@ private: void scrollDateHide(); void keepScrollDateForNow(); + gsl::not_null _controller; + PeerData *_peer = nullptr; History *_migrated = nullptr; History *_history = nullptr; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index d4dd45757..5a95797a9 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -35,6 +35,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "mainwidget.h" #include "auth_session.h" +#include "window/window_controller.h" namespace InlineBots { namespace Layout { @@ -45,7 +46,8 @@ constexpr auto kInlineBotRequestDelay = 400; } // namespace -Inner::Inner(QWidget *parent) : TWidget(parent) { +Inner::Inner(QWidget *parent, gsl::not_null controller) : TWidget(parent) +, _controller(controller) { resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, st::emojiPanMinHeight); setMouseTracking(true); @@ -60,8 +62,8 @@ Inner::Inner(QWidget *parent) : TWidget(parent) { subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); - subscribe(App::wnd()->gifPauseLevelChanged(), [this] { - if (!App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults)) { + subscribe(controller->gifPauseLevelChanged(), [this] { + if (!_controller->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults)) { update(); } }); @@ -106,7 +108,7 @@ void Inner::paintInlineItems(Painter &p, const QRect &r) { p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center); return; } - auto gifPaused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults); + auto gifPaused = _controller->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults); InlineBots::Layout::PaintContext context(getms(), false, gifPaused, false); auto top = st::stickerPanPadding; @@ -658,7 +660,8 @@ void Inner::onSwitchPm() { } // namespace internal -Widget::Widget(QWidget *parent) : TWidget(parent) +Widget::Widget(QWidget *parent, gsl::not_null controller) : TWidget(parent) +, _controller(controller) , _contentMaxHeight(st::emojiPanMaxHeight) , _contentHeight(_contentMaxHeight) , _scroll(this, st::inlineBotsScroll) { @@ -669,7 +672,7 @@ Widget::Widget(QWidget *parent) : TWidget(parent) _scroll->resize(st::emojiPanWidth - st::buttonRadius, _contentHeight); _scroll->move(verticalRect().topLeft()); - _inner = _scroll->setOwnedWidget(object_ptr(this)); + _inner = _scroll->setOwnedWidget(object_ptr(this, controller)); _inner->moveToLeft(0, 0, _scroll->width()); @@ -872,7 +875,7 @@ Widget::~Widget() = default; void Widget::hideFinished() { hide(); - App::wnd()->disableGifPauseReason(Window::GifPauseReason::InlineResults); + _controller->disableGifPauseReason(Window::GifPauseReason::InlineResults); _inner->hideFinish(true); _a_show.finish(); @@ -893,7 +896,7 @@ void Widget::showStarted() { recountContentMaxHeight(); _inner->preloadImages(); show(); - App::wnd()->enableGifPauseReason(Window::GifPauseReason::InlineResults); + _controller->enableGifPauseReason(Window::GifPauseReason::InlineResults); startShowAnimation(); } else if (_hiding) { startOpacityAnimation(false); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index 80e1a1e64..921b10251 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -34,6 +34,10 @@ class RoundButton; class RippleAnimation; } // namesapce Ui +namespace Window { +class Controller; +} // namespace Window + namespace InlineBots { class Result; @@ -58,7 +62,7 @@ class Inner : public TWidget, public Context, private base::Subscriber { Q_OBJECT public: - Inner(QWidget *parent); + Inner(QWidget *parent, gsl::not_null controller); void hideFinish(bool completely); @@ -111,6 +115,8 @@ private: void refreshSwitchPmButton(const CacheEntry *entry); + gsl::not_null _controller; + int _visibleTop = 0; int _visibleBottom = 0; @@ -158,7 +164,7 @@ class Widget : public TWidget, private MTP::Sender { Q_OBJECT public: - Widget(QWidget *parent); + Widget(QWidget *parent, gsl::not_null controller); void moveBottom(int bottom); @@ -228,6 +234,8 @@ private: bool refreshInlineRows(int *added = nullptr); void inlineResultsDone(const MTPmessages_BotResults &result); + gsl::not_null _controller; + int _contentMaxHeight = 0; int _contentHeight = 0; bool _horizontal = false; diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index 2b566451e..331dbc9ba 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/shadow.h" #include "window/window_main_menu.h" #include "auth_session.h" +#include "window/window_controller.h" namespace { @@ -311,7 +312,8 @@ void LayerStackWidget::BackgroundWidget::animationCallback() { checkIfDone(); } -LayerStackWidget::LayerStackWidget(QWidget *parent) : TWidget(parent) +LayerStackWidget::LayerStackWidget(QWidget *parent, Window::Controller *controller) : TWidget(parent) +, _controller(controller) , _background(this) { setGeometry(parentWidget()->rect()); hide(); @@ -565,7 +567,6 @@ void LayerStackWidget::animationDone() { } if (hidden) { App::wnd()->layerFinishedHide(this); - App::wnd()->disableGifPauseReason(Window::GifPauseReason::Layer); } else { showFinished(); } @@ -622,7 +623,7 @@ LayerWidget *LayerStackWidget::pushBox(object_ptr box) { if (oldLayer->inFocusChain()) setFocus(); oldLayer->hide(); } - auto layer = object_ptr(this, std::move(box)); + auto layer = object_ptr(this, _controller, std::move(box)); _layers.push_back(layer); initChildLayer(layer); @@ -644,7 +645,7 @@ void LayerStackWidget::prependBox(object_ptr box) { if (_layers.empty()) { return showBox(std::move(box)); } - auto layer = object_ptr(this, std::move(box)); + auto layer = object_ptr(this, _controller, std::move(box)); layer->hide(); _layers.push_front(layer); initChildLayer(layer); @@ -719,7 +720,8 @@ LayerStackWidget::~LayerStackWidget() { if (App::wnd()) App::wnd()->noLayerStack(this); } -MediaPreviewWidget::MediaPreviewWidget(QWidget *parent) : TWidget(parent) +MediaPreviewWidget::MediaPreviewWidget(QWidget *parent, gsl::not_null controller) : TWidget(parent) +, _controller(controller) , _emojiSize(Ui::Emoji::Size(Ui::Emoji::Index() + 1) / cIntRetinaFactor()) { setAttribute(Qt::WA_TransparentForMouseEvents); subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); @@ -735,7 +737,7 @@ void MediaPreviewWidget::paintEvent(QPaintEvent *e) { if (!_a_shown.animating()) { if (_hiding) { hide(); - App::wnd()->disableGifPauseReason(Window::GifPauseReason::MediaPreview); + _controller->disableGifPauseReason(Window::GifPauseReason::MediaPreview); return; } } else { @@ -792,7 +794,7 @@ void MediaPreviewWidget::startShow() { if (isHidden() || _a_shown.animating()) { if (isHidden()) { show(); - App::wnd()->enableGifPauseReason(Window::GifPauseReason::MediaPreview); + _controller->enableGifPauseReason(Window::GifPauseReason::MediaPreview); } _hiding = false; _a_shown.start([this] { update(); }, 0., 1., st::stickerPreviewDuration); @@ -926,7 +928,7 @@ QPixmap MediaPreviewWidget::currentImage() const { } if (_gif && _gif->started()) { auto s = currentDimensions(); - auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::MediaPreview); + auto paused = _controller->isGifPausedAtLeastFor(Window::GifPauseReason::MediaPreview); return _gif->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms()); } if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) { diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index c0d44259a..72cb94862 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Window { class MainMenu; +class Controller; } // namespace Window class LayerWidget : public TWidget { @@ -83,8 +84,11 @@ class LayerStackWidget : public TWidget { Q_OBJECT public: - LayerStackWidget(QWidget *parent); + LayerStackWidget(QWidget *parent, Window::Controller *controller); + Window::Controller *controller() const { + return _controller; + } void finishAnimation(); void showBox(object_ptr box); @@ -149,8 +153,9 @@ private: return const_cast(this)->currentLayer(); } - using Layers = QList; - Layers _layers; + Window::Controller *_controller = nullptr; + + QList _layers; object_ptr _specialLayer = { nullptr }; object_ptr _mainMenu = { nullptr }; @@ -164,7 +169,7 @@ class MediaPreviewWidget : public TWidget, private base::Subscriber { Q_OBJECT public: - MediaPreviewWidget(QWidget *parent); + MediaPreviewWidget(QWidget *parent, gsl::not_null controller); void showPreview(DocumentData *document); void showPreview(PhotoData *photo); @@ -183,6 +188,8 @@ private: void fillEmojiString(); void resetGifAndCache(); + gsl::not_null _controller; + Animation _a_shown; bool _hiding = false; DocumentData *_document = nullptr; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index ceaddd975..a6c310f4b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -74,13 +74,13 @@ StackItemSection::StackItemSection(std::unique_ptr &&mem StackItemSection::~StackItemSection() { } -MainWidget::MainWidget(QWidget *parent, std::unique_ptr controller) : TWidget(parent) -, _controller(std::move(controller)) +MainWidget::MainWidget(QWidget *parent, gsl::not_null controller) : TWidget(parent) +, _controller(controller) , _dialogsWidth(st::dialogsWidthMin) , _sideShadow(this, st::shadowFg) , _sideResizeArea(this) -, _dialogs(this, _controller.get()) -, _history(this, _controller.get()) +, _dialogs(this, _controller) +, _history(this, _controller) , _playerPlaylist(this, Media::Player::Panel::Layout::OnlyPlaylist) , _playerPanel(this, Media::Player::Panel::Layout::Full) { Messenger::Instance().mtp()->setUpdatesHandler(rpcDone(&MainWidget::updateReceived)); @@ -1872,6 +1872,8 @@ void MainWidget::setInnerFocus() { _overview->activate(); } else if (!_hider && _wideSection) { _wideSection->setInnerFocus(); + } else if (!_hider && _thirdSection) { + _thirdSection->setInnerFocus(); } else { dialogsActivate(); } @@ -1879,6 +1881,8 @@ void MainWidget::setInnerFocus() { _overview->activate(); } else if (_wideSection) { _wideSection->setInnerFocus(); + } else if (_thirdSection) { + _thirdSection->setInnerFocus(); } else { _history->setInnerFocus(); } @@ -2372,7 +2376,7 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool _wideSection->deleteLater(); _wideSection = nullptr; } - _overview.create(this, _controller.get(), peer, type); + _overview.create(this, _controller, peer, type); updateControlsGeometry(); // Send a fake update. @@ -4198,8 +4202,6 @@ MainWidget::~MainWidget() { delete hider; } Messenger::Instance().mtp()->clearGlobalHandlers(); - - if (App::wnd()) App::wnd()->noMain(this); } void MainWidget::updateOnline(bool gotOtherOffline) { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 7e208cc51..4e4c2a32e 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -142,7 +142,7 @@ class MainWidget : public TWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: - MainWidget(QWidget *parent, std::unique_ptr controller); + MainWidget(QWidget *parent, gsl::not_null controller); bool needBackButton(); @@ -495,7 +495,7 @@ private: void saveSectionInStack(); - std::unique_ptr _controller; + gsl::not_null _controller; bool _started = false; SelectedItemSet _toForward; @@ -570,6 +570,7 @@ private: object_ptr _dialogs; object_ptr _history; object_ptr _wideSection = { nullptr }; + object_ptr _thirdSection = { nullptr }; object_ptr _overview = { nullptr }; object_ptr _player = { nullptr }; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 0b154b050..a236784d2 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -200,6 +200,7 @@ void MainWindow::clearWidgetsHook() { auto wasMain = (_main != nullptr); _passcode.destroyDelayed(); _main.destroy(); + _controller.reset(); _intro.destroy(); if (wasMain) { App::clearHistories(); @@ -351,7 +352,8 @@ void MainWindow::setupMain(const MTPUser *self) { t_assert(AuthSession::Exists()); - _main.create(bodyWidget(), std::make_unique(this)); + _controller = std::make_unique(this); + _main.create(bodyWidget(), controller()); _main->show(); updateControlsGeometry(); @@ -391,15 +393,19 @@ void MainWindow::showMainMenu() { void MainWindow::ensureLayerCreated() { if (!_layerBg) { - _layerBg.create(bodyWidget()); - enableGifPauseReason(Window::GifPauseReason::Layer); + _layerBg.create(bodyWidget(), _controller.get()); + if (_controller) { + _controller->enableGifPauseReason(Window::GifPauseReason::Layer); + } } } void MainWindow::destroyLayerDelayed() { if (_layerBg) { _layerBg.destroyDelayed(); - disableGifPauseReason(Window::GifPauseReason::Layer); + if (_controller) { + _controller->disableGifPauseReason(Window::GifPauseReason::Layer); + } } } @@ -474,7 +480,7 @@ bool MainWindow::ui_isLayerShown() { void MainWindow::ui_showMediaPreview(DocumentData *document) { if (!document || ((!document->isAnimation() || !document->loaded()) && !document->sticker())) return; if (!_mediaPreview) { - _mediaPreview.create(bodyWidget()); + _mediaPreview.create(bodyWidget(), controller()); updateControlsGeometry(); } if (_mediaPreview->isHidden()) { @@ -486,7 +492,7 @@ void MainWindow::ui_showMediaPreview(DocumentData *document) { void MainWindow::ui_showMediaPreview(PhotoData *photo) { if (!photo) return; if (!_mediaPreview) { - _mediaPreview.create(bodyWidget()); + _mediaPreview.create(bodyWidget(), controller()); updateControlsGeometry(); } if (_mediaPreview->isHidden()) { @@ -761,16 +767,12 @@ void MainWindow::noIntro(Intro::Widget *was) { } } -void MainWindow::noMain(MainWidget *was) { - if (was == _main) { - _main = nullptr; - } -} - void MainWindow::noLayerStack(LayerStackWidget *was) { if (was == _layerBg) { _layerBg = nullptr; - disableGifPauseReason(Window::GifPauseReason::Layer); + if (_controller) { + _controller->disableGifPauseReason(Window::GifPauseReason::Layer); + } } } diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index ec66a52d9..a9f5b19f1 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -43,6 +43,7 @@ namespace Theme { struct BackgroundUpdate; class WarningWidget; } // namespace Theme +class Controller; } // namespace Window namespace Ui { @@ -78,6 +79,10 @@ public: MainWindow(); ~MainWindow(); + Window::Controller *controller() const { + return _controller.get(); + } + void firstShow(); void inactivePress(bool inactive); @@ -103,7 +108,6 @@ public: void activate(); void noIntro(Intro::Widget *was); - void noMain(MainWidget *was); void noLayerStack(LayerStackWidget *was); void layerFinishedHide(LayerStackWidget *was); @@ -218,6 +222,7 @@ private: QList _delayedServiceMsgs; mtpRequestId _serviceHistoryRequest = 0; + std::unique_ptr _controller; object_ptr _passcode = { nullptr }; object_ptr _intro = { nullptr }; object_ptr _main = { nullptr }; diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 4a9759516..2f03e1c6b 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -372,32 +372,6 @@ PeerData *MainWindow::ui_getPeerForMouseAction() { return nullptr; } -void MainWindow::enableGifPauseReason(GifPauseReason reason) { - if (!(_gifPauseReasons & reason)) { - auto notify = (static_cast(_gifPauseReasons) < static_cast(reason)); - _gifPauseReasons |= reason; - if (notify) { - _gifPauseLevelChanged.notify(); - } - } -} - -void MainWindow::disableGifPauseReason(GifPauseReason reason) { - if (_gifPauseReasons & reason) { - _gifPauseReasons &= ~qFlags(reason); - if (static_cast(_gifPauseReasons) < static_cast(reason)) { - _gifPauseLevelChanged.notify(); - } - } -} - -bool MainWindow::isGifPausedAtLeastFor(GifPauseReason reason) const { - if (reason == GifPauseReason::Any) { - return (_gifPauseReasons != 0) || !isActive(); - } - return (static_cast(_gifPauseReasons) >= 2 * static_cast(reason)) || !isActive(); -} - MainWindow::~MainWindow() = default; } // namespace Window diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index cb3cf4d5c..e2e77560d 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -26,16 +26,6 @@ class MediaView; namespace Window { -enum class GifPauseReason { - Any = 0, - InlineResults = (1 << 0), - SavedGifs = (1 << 1), - Layer = (1 << 2), - MediaPreview = (1 << 3), -}; -Q_DECLARE_FLAGS(GifPauseReasons, GifPauseReason); -Q_DECLARE_OPERATORS_FOR_FLAGS(GifPauseReasons); - class TitleWidget; class MainWindow : public QWidget, protected base::Subscriber { @@ -94,13 +84,6 @@ public: } virtual PeerData *ui_getPeerForMouseAction(); - void enableGifPauseReason(GifPauseReason reason); - void disableGifPauseReason(GifPauseReason reason); - base::Observable &gifPauseLevelChanged() { - return _gifPauseLevelChanged; - } - bool isGifPausedAtLeastFor(GifPauseReason reason) const; - public slots: bool minimizeToTray(); void updateGlobalMenu() { @@ -186,9 +169,6 @@ private: object_ptr _mediaView = { nullptr }; - GifPauseReasons _gifPauseReasons = { 0 }; - base::Observable _gifPauseLevelChanged; - }; } // namespace Window diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 23282d841..a241efbd1 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -20,3 +20,34 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #include "window/window_controller.h" +#include "window/main_window.h" + +namespace Window { + +void Controller::enableGifPauseReason(GifPauseReason reason) { + if (!(_gifPauseReasons & reason)) { + auto notify = (static_cast(_gifPauseReasons) < static_cast(reason)); + _gifPauseReasons |= reason; + if (notify) { + _gifPauseLevelChanged.notify(); + } + } +} + +void Controller::disableGifPauseReason(GifPauseReason reason) { + if (_gifPauseReasons & reason) { + _gifPauseReasons &= ~qFlags(reason); + if (static_cast(_gifPauseReasons) < static_cast(reason)) { + _gifPauseLevelChanged.notify(); + } + } +} + +bool Controller::isGifPausedAtLeastFor(GifPauseReason reason) const { + if (reason == GifPauseReason::Any) { + return (_gifPauseReasons != 0) || !window()->isActive(); + } + return (static_cast(_gifPauseReasons) >= 2 * static_cast(reason)) || !window()->isActive(); +} + +} // namespace Window diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index f033054cb..a2a66d3bf 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -22,9 +22,25 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Window { +enum class GifPauseReason { + Any = 0, + InlineResults = (1 << 0), + SavedGifs = (1 << 1), + Layer = (1 << 2), + MediaPreview = (1 << 3), +}; +Q_DECLARE_FLAGS(GifPauseReasons, GifPauseReason); +Q_DECLARE_OPERATORS_FOR_FLAGS(GifPauseReasons); + +class MainWindow; + class Controller { public: - Controller(MainWindow *window) : _window(window) { + Controller(gsl::not_null window) : _window(window) { + } + + gsl::not_null window() const { + return _window; } // This is needed for History TopBar updating when searchInPeer @@ -40,11 +56,22 @@ public: return _historyPeerChanged; } + void enableGifPauseReason(GifPauseReason reason); + void disableGifPauseReason(GifPauseReason reason); + base::Observable &gifPauseLevelChanged() { + return _gifPauseLevelChanged; + } + bool isGifPausedAtLeastFor(GifPauseReason reason) const; + private: gsl::not_null _window; + base::Observable _searchInPeerChanged; base::Observable _historyPeerChanged; + GifPauseReasons _gifPauseReasons = { 0 }; + base::Observable _gifPauseLevelChanged; + }; } // namespace Window diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 421f61a24..2df4431f7 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -83,6 +83,8 @@ <(src_loc)/chat_helpers/emoji_panel.h <(src_loc)/chat_helpers/emoji_list_widget.cpp <(src_loc)/chat_helpers/emoji_list_widget.h +<(src_loc)/chat_helpers/emoji_section.cpp +<(src_loc)/chat_helpers/emoji_section.h <(src_loc)/chat_helpers/field_autocomplete.cpp <(src_loc)/chat_helpers/field_autocomplete.h <(src_loc)/chat_helpers/gifs_list_widget.cpp