From 99037d3d46ef140faadca291ffa90cda280bf88a Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 9 Aug 2019 13:15:57 +0100 Subject: [PATCH] Improve scheduled messages top bar. --- Telegram/Resources/langs/lang.strings | 2 + .../SourceFiles/dialogs/dialogs_widget.cpp | 4 +- .../SourceFiles/history/history_widget.cpp | 8 +++- .../view/history_view_scheduled_section.cpp | 7 ++- .../view/history_view_top_bar_widget.cpp | 43 +++++++++---------- .../view/history_view_top_bar_widget.h | 9 +++- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 55a039769..3ec8e441e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1259,6 +1259,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_saved_short" = "Save"; "lng_saved_forward_here" = "Forward messages here for quick access"; +"lng_scheduled_messages" = "Scheduled Messages"; + "lng_archived_name" = "Archived chats"; "lng_archived_add" = "Archive"; "lng_archived_remove" = "Unarchive"; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 68797353e..b456f7ac5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -444,7 +444,9 @@ void Widget::refreshFolderTopBar() { _folderTopBar.create(this, controller()); updateControlsGeometry(); } - _folderTopBar->setActiveChat(_openedFolder); + _folderTopBar->setActiveChat( + _openedFolder, + HistoryView::TopBarWidget::Section::History); } else { _folderTopBar.destroy(); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 25b9e45e7..912e1d5a0 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1761,7 +1761,9 @@ void HistoryWidget::showHistory( _migrated->clear(History::ClearType::Unload); } - _topBar->setActiveChat(_history); + _topBar->setActiveChat( + _history, + HistoryView::TopBarWidget::Section::History); updateTopBarSelection(); if (_channel) { @@ -1837,7 +1839,9 @@ void HistoryWidget::showHistory( } unreadCountUpdated(); // set _historyDown badge. } else { - _topBar->setActiveChat(Dialogs::Key()); + _topBar->setActiveChat( + Dialogs::Key(), + HistoryView::TopBarWidget::Section::History); updateTopBarSelection(); clearFieldText(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index f60a89e7d..db3d0ad82 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -50,7 +50,7 @@ ScheduledWidget::ScheduledWidget( , _topBar(this, controller) , _topBarShadow(this) , _scrollDown(_scroll, st::historyToDown) { - _topBar->setActiveChat(_history); + _topBar->setActiveChat(_history, TopBarWidget::Section::Scheduled); _topBar->move(0, 0); _topBar->resizeToWidth(width()); @@ -200,6 +200,7 @@ Dialogs::RowDescriptor ScheduledWidget::activeChat() const { } QPixmap ScheduledWidget::grabForShowAnimation(const Window::SectionSlideParams ¶ms) { + _topBar->updateControlsVisibility(); if (params.withTopBarShadow) _topBarShadow->hide(); auto result = Ui::GrabWidget(this); if (params.withTopBarShadow) _topBarShadow->show(); @@ -315,7 +316,9 @@ void ScheduledWidget::updateInnerVisibleArea() { void ScheduledWidget::showAnimatedHook( const Window::SectionSlideParams ¶ms) { _topBar->setAnimatingMode(true); - if (params.withTopBarShadow) _topBarShadow->show(); + if (params.withTopBarShadow) { + _topBarShadow->show(); + } } void ScheduledWidget::showFinishedHook() { 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 8f3d4e12f..5af79e2ec 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -313,23 +313,17 @@ void TopBarWidget::paintTopBar(Painter &p) { auto statustop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height; auto availableWidth = width() - _rightTaken - nameleft; - auto history = _activeChat.history(); - - if (const auto folder = _activeChat.folder()) { - auto text = folder->chatListName(); // TODO feed name emoji - const auto textWidth = st::historySavedFont->width(text); - if (availableWidth < textWidth) { - text = st::historySavedFont->elided(text, availableWidth); - } - p.setPen(st::dialogsNameFg); - p.setFont(st::historySavedFont); - p.drawTextLeft( - nameleft, - (height() - st::historySavedFont->height) / 2, - width(), - text); - } else if (_activeChat.peer()->isSelf()) { - auto text = tr::lng_saved_messages(tr::now); + const auto history = _activeChat.history(); + const auto folder = _activeChat.folder(); + if (folder + || history->peer->isSelf() + || (_section == Section::Scheduled)) { + // #TODO feed name emoji. + auto text = (_section == Section::Scheduled) + ? tr::lng_scheduled_messages(tr::now) + : folder + ? folder->chatListName() + : tr::lng_saved_messages(tr::now); const auto textWidth = st::historySavedFont->width(text); if (availableWidth < textWidth) { text = st::historySavedFont->elided(text, availableWidth); @@ -468,11 +462,12 @@ void TopBarWidget::backClicked() { } } -void TopBarWidget::setActiveChat(Dialogs::Key chat) { - if (_activeChat == chat) { +void TopBarWidget::setActiveChat(Dialogs::Key chat, Section section) { + if (_activeChat == chat && _section == section) { return; } _activeChat = chat; + _section = section; _back->clearState(); update(); @@ -611,11 +606,13 @@ void TopBarWidget::updateControlsVisibility() { if (_unreadBadge) { _unreadBadge->show(); } + const auto historyMode = (_section == Section::History); const auto smallDialogsColumn = _activeChat.folder() && (width() < _back->width() + _search->width()); - _search->setVisible(!smallDialogsColumn); - _menuToggle->setVisible(!_activeChat.folder()); - _infoToggle->setVisible(!_activeChat.folder() + _search->setVisible(historyMode && !smallDialogsColumn); + _menuToggle->setVisible(historyMode && !_activeChat.folder()); + _infoToggle->setVisible(historyMode + && !_activeChat.folder() && !Adaptive::OneColumn() && _controller->canShowThirdSection()); const auto callsEnabled = [&] { @@ -626,7 +623,7 @@ void TopBarWidget::updateControlsVisibility() { } return false; }(); - _call->setVisible(callsEnabled); + _call->setVisible(historyMode && callsEnabled); if (_membersShowArea) { _membersShowArea->show(); 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 bc1ced310..0614e69e5 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -39,6 +39,10 @@ public: int canDeleteCount = 0; int canForwardCount = 0; }; + enum class Section { + History, + Scheduled, + }; TopBarWidget( QWidget *parent, @@ -55,7 +59,7 @@ public: } void setAnimatingMode(bool enabled); - void setActiveChat(Dialogs::Key chat); + void setActiveChat(Dialogs::Key chat, Section section); rpl::producer<> forwardSelectionRequest() const { return _forwardSelection.events(); @@ -112,8 +116,9 @@ private: void refreshUnreadBadge(); void updateUnreadBadge(); - not_null _controller; + const not_null _controller; Dialogs::Key _activeChat; + Section _section = Section::History; int _selectedCount = 0; bool _canDelete = false;