From 1ff53eb5857ac1ddd4400c0fa3b00476425cb31a Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 1 Dec 2022 18:59:03 +0400 Subject: [PATCH] Fix opening _childList from archive. --- .../SourceFiles/dialogs/dialogs_widget.cpp | 53 +++++++++++++------ .../view/history_view_top_bar_widget.cpp | 39 ++++++++++---- .../view/history_view_top_bar_widget.h | 9 +++- 3 files changed, 76 insertions(+), 25 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 4770b476b..7333b0b75 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -354,10 +354,10 @@ Widget::Widget( setupShortcuts(); _searchForNarrowFilters->setClickedCallback([=] { + _filter->setFocusFast(); if (_childList) { controller->closeForum(); } - _filter->setFocus(); }); setAcceptDrops(true); @@ -738,9 +738,8 @@ void Widget::updateControlsVisibility(bool fast) { _forumReportBar->show(); } } else { - if (hasFocus()) { - _filter->setFocus(); - _filter->finishAnimating(); + if (hasFocus() && !_childList) { + _filter->setFocusFast(); } updateLockUnlockVisibility(); updateJumpToDateVisibility(fast); @@ -754,6 +753,9 @@ void Widget::updateControlsVisibility(bool fast) { if (_hideChildListCanvas) { _hideChildListCanvas->show(); } + if (_childList && _filter->hasFocus()) { + setInnerFocus(); + } } void Widget::changeOpenedSubsection( @@ -1967,12 +1969,17 @@ void Widget::openChildList( auto copy = params; copy.childColumn = false; copy.animated = anim::type::instant; - _childList = std::make_unique( - this, - controller(), - Layout::Child); - _childList->showForum(forum, copy); - _childListPeerId = forum->channel()->id; + { + if (_childList && InFocusChain(_childList.get())) { + setFocus(); + } + _childList = std::make_unique( + this, + controller(), + Layout::Child); + _childList->showForum(forum, copy); + _childListPeerId = forum->channel()->id; + } _childListShadow = std::make_unique(this); const auto shadow = _childListShadow.get(); @@ -2006,6 +2013,9 @@ void Widget::openChildList( } else { _childListShown = 1.; } + if (hasFocus()) { + setInnerFocus(); + } } void Widget::closeChildList(anim::type animated) { @@ -2029,8 +2039,15 @@ void Widget::closeChildList(anim::type animated) { animation->paintContents(p); }, _hideChildListCanvas->lifetime()); } + if (InFocusChain(_childList.get())) { + setFocus(); + } _childList = nullptr; _childListShown = 0.; + if (hasFocus()) { + setInnerFocus(); + _filter->finishAnimating(); + } if (animated == anim::type::normal) { _hideChildListCanvas->hide(); auto newContentCache = Ui::GrabWidget(this, geometry); @@ -2060,6 +2077,9 @@ void Widget::searchInChat(Key chat) { controller()->closeForum(); } if (_openedFolder) { + if (_childList && _childList->setSearchInChat(chat)) { + return; + } controller()->closeFolder(); } cancelSearch(); @@ -2298,7 +2318,7 @@ void Widget::updateControlsGeometry() { _narrowWidth, _childListShown.current()); const auto smallw = st::columnMinimalWidthLeft - _narrowWidth; - const auto smallLayoutRatio = (ratiow < smallw) + const auto narrowRatio = (ratiow < smallw) ? ((smallw - ratiow) / float64(smallw - _narrowWidth)) : 0.; @@ -2313,21 +2333,24 @@ void Widget::updateControlsGeometry() { auto filterAreaHeight = st::topBarHeight; _searchControls->setGeometry(0, filterAreaTop, ratiow, filterAreaHeight); if (_subsectionTopBar) { - _subsectionTopBar->setGeometry(_searchControls->geometry()); + _subsectionTopBar->setGeometryWithNarrowRatio( + _searchControls->geometry(), + _narrowWidth, + narrowRatio); } auto filterTop = (filterAreaHeight - _filter->height()) / 2; - filterLeft = anim::interpolate(filterLeft, _narrowWidth, smallLayoutRatio); + filterLeft = anim::interpolate(filterLeft, _narrowWidth, narrowRatio); _filter->setGeometryToLeft(filterLeft, filterTop, filterWidth, _filter->height()); auto mainMenuLeft = anim::interpolate( st::dialogsFilterPadding.x(), (_narrowWidth - _mainMenuToggle->width()) / 2, - smallLayoutRatio); + narrowRatio); _mainMenuToggle->moveToLeft(mainMenuLeft, st::dialogsFilterPadding.y()); const auto searchLeft = anim::interpolate( -_searchForNarrowFilters->width(), (_narrowWidth - _searchForNarrowFilters->width()) / 2, - smallLayoutRatio); + narrowRatio); _searchForNarrowFilters->moveToLeft(searchLeft, st::dialogsFilterPadding.y()); auto right = filterLeft + filterWidth; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index f6017327e..50df41975 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -421,7 +421,7 @@ void TopBarWidget::paintEvent(QPaintEvent *e) { } void TopBarWidget::paintTopBar(Painter &p) { - if (!_activeChat.key || _narrowMode) { + if (!_activeChat.key || _narrowRatio == 1.) { return; } auto nameleft = _leftTaken; @@ -846,12 +846,6 @@ void TopBarWidget::refreshInfoButton() { } void TopBarWidget::resizeEvent(QResizeEvent *e) { - const auto narrowMode = (_activeChat.section == Section::ChatsList) - && (width() < _back->width() + _search->width()); - if (_narrowMode != narrowMode) { - _narrowMode = narrowMode; - updateControlsVisibility(); - } updateSearchVisibility(); updateControlsGeometry(); } @@ -922,7 +916,10 @@ void TopBarWidget::updateControlsGeometry() { } else if (_back->isHidden()) { _leftTaken = st::topBarArrowPadding.right(); } else { - _leftTaken = _narrowMode ? (width() - _back->width()) / 2 : 0; + _leftTaken = anim::interpolate( + 0, + (_narrowWidth - _back->width()) / 2, + _narrowRatio); _back->moveToLeft(_leftTaken, backButtonTop); _leftTaken += _back->width(); } @@ -1078,7 +1075,7 @@ void TopBarWidget::updateControlsVisibility() { } _menuToggle->setVisible(hasMenu && !_chooseForReportReason - && !_narrowMode); + && (_narrowRatio < 1.)); _infoToggle->setVisible(hasInfo && !isOneColumn && _controller->canShowThirdSection() @@ -1349,6 +1346,30 @@ void TopBarWidget::toggleSelectedControls(bool shown) { anim::easeOutCirc); } +void TopBarWidget::setGeometryWithNarrowRatio( + QRect geometry, + int narrowWidth, + float64 narrowRatio) { + if (_activeChat.section != Section::ChatsList) { + narrowRatio = 0.; + narrowWidth = 0; + } + const auto changed = (_narrowRatio != narrowRatio); + const auto started = (_narrowRatio == 0.) != (narrowRatio == 0.); + const auto finished = (_narrowRatio == 1.) != (narrowRatio == 1.); + const auto resized = (size() != geometry.size()); + _narrowRatio = narrowRatio; + _narrowWidth = narrowWidth; + if (started || finished) { + updateControlsVisibility(); + } + setGeometry(geometry); + if (changed && !resized) { + updateSearchVisibility(); + updateControlsGeometry(); + } +} + bool TopBarWidget::showSelectedActions() const { return showSelectedState() && !_chooseForReportReason; } diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index d283aab2a..614d7ade0 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -112,6 +112,11 @@ public: } [[nodiscard]] rpl::producer<> searchRequest() const; + void setGeometryWithNarrowRatio( + QRect geometry, + int narrowWidth, + float64 narrowRatio); + protected: void paintEvent(QPaintEvent *e) override; void mousePressEvent(QMouseEvent *e) override; @@ -226,12 +231,14 @@ private: object_ptr _membersShowArea = { nullptr }; rpl::event_stream _membersShowAreaActive; + float64 _narrowRatio = 0.; + int _narrowWidth = 0; + Ui::Text::String _titlePeerText; bool _titlePeerTextOnline = false; int _leftTaken = 0; int _rightTaken = 0; bool _animatingMode = false; - bool _narrowMode = false; std::unique_ptr _connecting; SendActionPainter *_sendAction = nullptr;