From 9669a8a44adc2276d08ec8af5d5ab980f30d8837 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 27 May 2021 03:44:12 +0300 Subject: [PATCH] Moved Core::Settings:chatWide to Window::Adaptive. --- Telegram/SourceFiles/core/core_settings.cpp | 9 ++----- Telegram/SourceFiles/core/core_settings.h | 8 +++--- .../admin_log/history_admin_log_inner.cpp | 11 ++++++-- .../admin_log/history_admin_log_inner.h | 1 + .../history/history_inner_widget.cpp | 27 ++++++++++++++----- .../history/history_inner_widget.h | 3 +++ .../history/view/history_view_element.cpp | 12 ++++++--- .../history/view/history_view_element.h | 6 +++-- .../history/view/history_view_list_widget.cpp | 17 +++++++++--- .../history/view/history_view_list_widget.h | 3 +++ .../history/view/history_view_message.cpp | 12 ++++----- .../view/history_view_service_message.cpp | 24 +++++++++-------- .../view/history_view_service_message.h | 3 +++ .../media/history_view_media_unwrapped.cpp | 22 ++++++++------- .../info/media/info_media_list_widget.cpp | 1 + .../SourceFiles/window/window_adaptive.cpp | 16 +++++++++++ Telegram/SourceFiles/window/window_adaptive.h | 3 +++ 17 files changed, 123 insertions(+), 55 deletions(-) diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index ccf1fd6d9..38b254c5c 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -117,7 +117,7 @@ QByteArray Settings::serialize() const { stream.setVersion(QDataStream::Qt_5_1); stream << themesAccentColors - << qint32(_adaptiveForWide ? 1 : 0) + << qint32(_adaptiveForWide.current() ? 1 : 0) << qint32(_moderateModeEnabled ? 1 : 0) << qint32(qRound(_songVolume.current() * 1e6)) << qint32(qRound(_videoVolume.current() * 1e6)) @@ -211,7 +211,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { stream.setVersion(QDataStream::Qt_5_1); QByteArray themesAccentColors; - qint32 adaptiveForWide = _adaptiveForWide ? 1 : 0; + qint32 adaptiveForWide = _adaptiveForWide.current() ? 1 : 0; qint32 moderateModeEnabled = _moderateModeEnabled ? 1 : 0; qint32 songVolume = qint32(qRound(_songVolume.current() * 1e6)); qint32 videoVolume = qint32(qRound(_videoVolume.current() * 1e6)); @@ -522,11 +522,6 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _groupCallNoiseSuppression = (groupCallNoiseSuppression == 1); } -bool Settings::chatWide() const { - return _adaptiveForWide - && (Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide); -} - QString Settings::getSoundPath(const QString &key) const { auto it = _soundOverrides.find(key); if (it != _soundOverrides.end()) { diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index a4ebd35cf..d70c79709 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -69,9 +69,11 @@ public: [[nodiscard]] QByteArray serialize() const; void addFromSerialized(const QByteArray &serialized); - [[nodiscard]] bool chatWide() const; [[nodiscard]] bool adaptiveForWide() const { - return _adaptiveForWide; + return _adaptiveForWide.current(); + } + [[nodiscard]] rpl::producer adaptiveForWideValue() const { + return _adaptiveForWide.value(); } void setAdaptiveForWide(bool value) { _adaptiveForWide = value; @@ -573,7 +575,7 @@ private: ushort rating = 0; }; - bool _adaptiveForWide = true; + rpl::variable _adaptiveForWide = true; bool _moderateModeEnabled = false; rpl::variable _songVolume = kDefaultVolume; rpl::variable _videoVolume = kDefaultVolume; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index bbf58c9d7..4a95caee1 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -626,6 +626,10 @@ void InnerWidget::elementSendBotCommand( void InnerWidget::elementHandleViaClick(not_null bot) { } +bool InnerWidget::elementIsChatWide() { + return _controller->adaptive().isChatWide(); +} + void InnerWidget::saveState(not_null memento) { memento->setFilter(std::move(_filter)); memento->setAdmins(std::move(_admins)); @@ -941,14 +945,17 @@ void InnerWidget::paintEvent(QPaintEvent *e) { p.setOpacity(opacity); const auto dateY = /*noFloatingDate ? itemtop :*/ (dateTop - st::msgServiceMargin.top()); const auto width = view->width(); + const auto chatWide = + _controller->adaptive().isChatWide(); if (const auto date = view->Get()) { - date->paint(p, dateY, width); + date->paint(p, dateY, width, chatWide); } else { HistoryView::ServiceMessagePainter::paintDate( p, view->dateTime(), dateY, - width); + width, + chatWide); } } } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index b3af9bb0b..bc7b0d3f0 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -120,6 +120,7 @@ public: const QString &command, const FullMsgId &context) override; void elementHandleViaClick(not_null bot) override; + bool elementIsChatWide() override; ~InnerWidget(); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 080da909d..f8b69a155 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -209,6 +209,11 @@ HistoryInner::HistoryInner( ) | rpl::start_with_next([=] { update(); }, lifetime()); + + controller->adaptive().chatWideValue( + ) | rpl::start_with_next([=](bool wide) { + _isChatWide = wide; + }, lifetime()); } Main::Session &HistoryInner::session() const { @@ -358,7 +363,7 @@ bool HistoryInner::canHaveFromUserpics() const { if (_peer->isUser() && !_peer->isSelf() && !_peer->isRepliesChat() - && !Core::App().settings().chatWide()) { + && !_isChatWide) { return false; } else if (_peer->isChannel() && !_peer->isMegagroup()) { return false; @@ -772,13 +777,14 @@ void HistoryInner::paintEvent(QPaintEvent *e) { ? itemtop : (dateTop - st::msgServiceMargin.top()); if (const auto date = view->Get()) { - date->paint(p, dateY, _contentWidth); + date->paint(p, dateY, _contentWidth, _isChatWide); } else { HistoryView::ServiceMessagePainter::paintDate( p, view->dateTime(), dateY, - _contentWidth); + _contentWidth, + _isChatWide); } } } @@ -2163,7 +2169,7 @@ void HistoryInner::recountHistoryGeometry() { : (st::msgNameFont->height + st::botDescSkip); int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom(); int32 descMaxWidth = _scroll->width(); - if (Core::App().settings().chatWide()) { + if (_isChatWide) { descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left(); @@ -2370,7 +2376,7 @@ void HistoryInner::updateSize() { : (st::msgNameFont->height + st::botDescSkip); int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom(); int32 descMaxWidth = _scroll->width(); - if (Core::App().settings().chatWide()) { + if (_isChatWide) { descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left(); @@ -2593,6 +2599,10 @@ void HistoryInner::elementHandleViaClick(not_null bot) { App::insertBotCommand('@' + bot->username); } +bool HistoryInner::elementIsChatWide() { + return _isChatWide; +} + auto HistoryInner::getSelectionState() const -> HistoryView::TopBarWidget::SelectedState { auto result = HistoryView::TopBarWidget::SelectedState {}; @@ -2749,7 +2759,7 @@ void HistoryInner::mouseActionUpdate() { dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right(); auto dateLeft = st::msgServiceMargin.left(); auto maxwidth = _contentWidth; - if (Core::App().settings().chatWide()) { + if (_isChatWide) { maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); @@ -3463,6 +3473,11 @@ not_null HistoryInner::ElementDelegate() { Instance->elementHandleViaClick(bot); } } + bool elementIsChatWide() override { + return Instance + ? Instance->elementIsChatWide() + : false; + } }; static Result result; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index ffc30c164..f60b284ee 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -96,6 +96,7 @@ public: const QString &command, const FullMsgId &context); void elementHandleViaClick(not_null bot); + bool elementIsChatWide(); void updateBotInfo(bool recount = true); @@ -356,6 +357,8 @@ private: SelectedItems _selected; std::optional _chooseForReportReason; + bool _isChatWide = false; + base::flat_set> _animatedStickersPlayed; base::flat_map< not_null, diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index c84818a53..fe27ee04f 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -133,6 +133,10 @@ void SimpleElementDelegate::elementSendBotCommand( void SimpleElementDelegate::elementHandleViaClick(not_null bot) { } +bool SimpleElementDelegate::elementIsChatWide() { + return false; +} + TextSelection UnshiftItemSelection( TextSelection selection, uint16 byLength) { @@ -220,7 +224,7 @@ int UnreadBar::marginTop() { return st::lineWidth + st::historyUnreadBarMargin; } -void UnreadBar::paint(Painter &p, int y, int w) const { +void UnreadBar::paint(Painter &p, int y, int w, bool chatWide) const { const auto bottom = y + height(); y += marginTop(); p.fillRect( @@ -240,7 +244,7 @@ void UnreadBar::paint(Painter &p, int y, int w) const { int left = st::msgServiceMargin.left(); int maxwidth = w; - if (Core::App().settings().chatWide()) { + if (chatWide) { maxwidth = qMin( maxwidth, st::msgMaxWidth @@ -272,8 +276,8 @@ int DateBadge::height() const { + st::msgServiceMargin.bottom(); } -void DateBadge::paint(Painter &p, int y, int w) const { - ServiceMessagePainter::paintDate(p, text, width, y, w); +void DateBadge::paint(Painter &p, int y, int w, bool chatWide) const { + ServiceMessagePainter::paintDate(p, text, width, y, w, chatWide); } Element::Element( diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 6da4dd7a3..cf7103c92 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -70,6 +70,7 @@ public: const QString &command, const FullMsgId &context) = 0; virtual void elementHandleViaClick(not_null bot) = 0; + virtual bool elementIsChatWide() = 0; }; @@ -106,6 +107,7 @@ public: const QString &command, const FullMsgId &context) override; void elementHandleViaClick(not_null bot) override; + bool elementIsChatWide() override; private: const not_null _controller; @@ -135,7 +137,7 @@ struct UnreadBar : public RuntimeComponent { static int height(); static int marginTop(); - void paint(Painter &p, int y, int w) const; + void paint(Painter &p, int y, int w, bool chatWide) const; QString text; int width = 0; @@ -149,7 +151,7 @@ struct DateBadge : public RuntimeComponent { void init(const QString &date); int height() const; - void paint(Painter &p, int y, int w) const; + void paint(Painter &p, int y, int w, bool chatWide) const; QString text; int width = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index dafab327e..1bca5aee5 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/message_field.h" #include "mainwindow.h" #include "mainwidget.h" -#include "core/application.h" #include "core/click_handler_types.h" #include "apiwrap.h" #include "layout.h" @@ -312,6 +311,11 @@ ListWidget::ListWidget( } } }); + + controller->adaptive().chatWideValue( + ) | rpl::start_with_next([=](bool wide) { + _isChatWide = wide; + }, lifetime()); } Main::Session &ListWidget::session() const { @@ -1323,6 +1327,10 @@ void ListWidget::elementHandleViaClick(not_null bot) { _delegate->listHandleViaClick(bot); } +bool ListWidget::elementIsChatWide() { + return _isChatWide; +} + void ListWidget::saveState(not_null memento) { memento->setAroundPosition(_aroundPosition); auto state = countScrollState(); @@ -1558,13 +1566,14 @@ void ListWidget::paintEvent(QPaintEvent *e) { int dateY = /*noFloatingDate ? itemtop :*/ (dateTop - st::msgServiceMargin.top()); int width = view->width(); if (const auto date = view->Get()) { - date->paint(p, dateY, width); + date->paint(p, dateY, width, _isChatWide); } else { ServiceMessagePainter::paintDate( p, ItemDateText(view->data(), IsItemScheduledUntilOnline(view->data())), dateY, - width); + width, + _isChatWide); } } } @@ -2348,7 +2357,7 @@ void ListWidget::mouseActionUpdate() { dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right(); auto dateLeft = st::msgServiceMargin.left(); auto maxwidth = view->width(); - if (Core::App().settings().chatWide()) { + if (_isChatWide) { maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 8d6cf9169..debb2099c 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -244,6 +244,7 @@ public: const QString &command, const FullMsgId &context) override; void elementHandleViaClick(not_null bot) override; + bool elementIsChatWide() override; ~ListWidget(); @@ -546,6 +547,8 @@ private: bool _wasSelectedText = false; Qt::CursorShape _cursor = style::cur_default; + bool _isChatWide = false; + base::unique_qptr _menu; QPoint _trippleClickPoint; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 1b943d13d..d334ea25f 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -16,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "ui/effects/ripple_animation.h" #include "base/unixtime.h" -#include "core/application.h" -#include "core/core_settings.h" #include "ui/toast/toast.h" #include "ui/text/text_utilities.h" #include "ui/text/text_entity.h" @@ -564,7 +562,7 @@ void Message::draw( auto unreadbarh = bar->height(); if (clip.intersects(QRect(0, dateh, width(), unreadbarh))) { p.translate(0, dateh); - bar->paint(p, 0, width()); + bar->paint(p, 0, width(), delegate()->elementIsChatWide()); p.translate(0, -dateh); } } @@ -644,7 +642,7 @@ void Message::draw( || (context() == Context::Replies && data()->isDiscussionPost()); auto displayTail = skipTail ? RectPart::None - : (outbg && !Core::App().settings().chatWide()) + : (outbg && !delegate()->elementIsChatWide()) ? RectPart::Right : RectPart::Left; PaintBubble( @@ -1207,7 +1205,7 @@ bool Message::hasFromPhoto() const { || item->isEmpty() || (context() == Context::Replies && item->isDiscussionPost())) { return false; - } else if (Core::App().settings().chatWide()) { + } else if (delegate()->elementIsChatWide()) { return true; } else if (const auto forwarded = item->Get()) { const auto peer = item->history()->peer; @@ -2517,7 +2515,7 @@ QRect Message::countGeometry() const { const auto availableWidth = width() - st::msgMargin.left() - (commentsRoot ? st::msgMargin.left() : st::msgMargin.right()); - auto contentLeft = (outbg && !Core::App().settings().chatWide()) + auto contentLeft = (outbg && !delegate()->elementIsChatWide()) ? st::msgMargin.right() : st::msgMargin.left(); auto contentWidth = availableWidth; @@ -2540,7 +2538,7 @@ QRect Message::countGeometry() const { contentWidth = mediaWidth; } } - if (contentWidth < availableWidth && !Core::App().settings().chatWide()) { + if (contentWidth < availableWidth && !delegate()->elementIsChatWide()) { if (outbg) { contentLeft += availableWidth - contentWidth; } else if (commentsRoot) { diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index b9fce0e04..e26930b14 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -16,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat.h" #include "data/data_channel.h" #include "ui/text/text_options.h" -#include "core/core_settings.h" -#include "core/application.h" #include "mainwidget.h" #include "layout.h" #include "lang/lang_keys.h" @@ -216,13 +214,13 @@ void paintPreparedDate( int dateTextWidth, int y, int w, + bool chatWide, const style::color &bg, const style::color &fg) { int left = st::msgServiceMargin.left(); - int maxwidth = w; - if (Core::App().settings().chatWide()) { - maxwidth = qMin(maxwidth, WideChatWidth()); - } + const auto maxwidth = chatWide + ? std::min(w, WideChatWidth()) + : w; w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); left += (w - dateTextWidth - st::msgServicePadding.left() - st::msgServicePadding.right()) / 2; @@ -262,11 +260,12 @@ void ServiceMessagePainter::paintDate( const QDateTime &date, int y, int w, + bool chatWide, const style::color &bg, const style::color &fg) { const auto dateText = langDayOfMonthFull(date.date()); const auto dateTextWidth = st::msgServiceFont->width(dateText); - paintPreparedDate(p, dateText, dateTextWidth, y, w, bg, fg); + paintPreparedDate(p, dateText, dateTextWidth, y, w, chatWide, bg, fg); } void ServiceMessagePainter::paintDate( @@ -274,6 +273,7 @@ void ServiceMessagePainter::paintDate( const QString &dateText, int y, int w, + bool chatWide, const style::color &bg, const style::color &fg) { paintPreparedDate( @@ -282,6 +282,7 @@ void ServiceMessagePainter::paintDate( st::msgServiceFont->width(dateText), y, w, + chatWide, bg, fg); } @@ -292,9 +293,10 @@ void ServiceMessagePainter::paintDate( int dateTextWidth, int y, int w, + bool chatWide, const style::color &bg, const style::color &fg) { - paintPreparedDate(p, dateText, dateTextWidth, y, w, bg, fg); + paintPreparedDate(p, dateText, dateTextWidth, y, w, chatWide, bg, fg); } void ServiceMessagePainter::paintBubble( @@ -439,7 +441,7 @@ not_null Service::message() const { QRect Service::countGeometry() const { auto result = QRect(0, 0, width(), height()); - if (Core::App().settings().chatWide()) { + if (delegate()->elementIsChatWide()) { result.setWidth(qMin(result.width(), st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } return result.marginsRemoved(st::msgServiceMargin); @@ -462,7 +464,7 @@ QSize Service::performCountCurrentSize(int newWidth) { item->_textHeight = 0; } else { auto contentWidth = newWidth; - if (Core::App().settings().chatWide()) { + if (delegate()->elementIsChatWide()) { accumulate_min(contentWidth, st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()); } contentWidth -= st::msgServiceMargin.left() + st::msgServiceMargin.left(); // two small margins @@ -536,7 +538,7 @@ void Service::draw( if (const auto bar = Get()) { unreadbarh = bar->height(); if (clip.intersects(QRect(0, 0, width(), unreadbarh))) { - bar->paint(p, 0, width()); + bar->paint(p, 0, width(), delegate()->elementIsChatWide()); } p.translate(0, unreadbarh); clip.translate(0, -unreadbarh); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.h b/Telegram/SourceFiles/history/view/history_view_service_message.h index 17b76a0c7..1295ae4e5 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.h +++ b/Telegram/SourceFiles/history/view/history_view_service_message.h @@ -68,6 +68,7 @@ public: const QDateTime &date, int y, int w, + bool chatWide, const style::color &bg = st::msgServiceBg, const style::color &fg = st::msgServiceFg); static void paintDate( @@ -75,6 +76,7 @@ public: const QString &dateText, int y, int w, + bool chatWide, const style::color &bg = st::msgServiceBg, const style::color &fg = st::msgServiceFg); static void paintDate( @@ -83,6 +85,7 @@ public: int dateTextWidth, int y, int w, + bool chatWide, const style::color &bg = st::msgServiceBg, const style::color &fg = st::msgServiceFg); diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index 8b2b63b97..34767914d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -13,8 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history_item_components.h" #include "lottie/lottie_single_player.h" -#include "core/application.h" -#include "core/core_settings.h" #include "ui/cached_round_corners.h" #include "layout.h" #include "styles/style_chat.h" @@ -95,7 +93,8 @@ QSize UnwrappedMedia::countCurrentSize(int newWidth) { } } auto newHeight = minHeight(); - if (_parent->hasOutLayout() && !Core::App().settings().chatWide()) { + if (_parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide()) { // Add some height to isolated emoji for the timestamp info. const auto infoHeight = st::msgDateImgPadding.y() * 2 + st::msgDateFont->height; @@ -117,7 +116,8 @@ void UnwrappedMedia::draw( } bool selected = (selection == FullSelection); - const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); + const auto rightAligned = _parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); @@ -185,7 +185,8 @@ void UnwrappedMedia::drawSurrounding( const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const { - const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); + const auto rightAligned = _parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide(); const auto rightActionSize = _parent->rightActionSize(); const auto fullRight = calculateFullRight(inner); auto fullBottom = height(); @@ -245,7 +246,8 @@ PointState UnwrappedMedia::pointState(QPoint point) const { return PointState::Outside; } - const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); + const auto rightAligned = _parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); @@ -285,7 +287,8 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { return result; } - const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); + const auto rightAligned = _parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); @@ -398,7 +401,8 @@ std::unique_ptr UnwrappedMedia::stickerTakeLottie( } int UnwrappedMedia::calculateFullRight(const QRect &inner) const { - const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); + const auto rightAligned = _parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide(); const auto infoWidth = _parent->infoWidth() + st::msgDateImgPadding.x() * 2 + st::msgReplyPadding.left(); @@ -444,7 +448,7 @@ bool UnwrappedMedia::needInfoDisplay() const { || (_parent->rightActionSize()) || (_parent->isLastAndSelfMessage()) || (_parent->hasOutLayout() - && !Core::App().settings().chatWide() + && !_parent->delegate()->elementIsChatWide() && _content->alwaysShowOutTimestamp()); } diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 831742855..7b022a4cb 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1338,6 +1338,7 @@ void ListWidget::paintEvent(QPaintEvent *e) { _dateBadge.text, _visibleTop, outerWidth, + false, st::roundedBg, st::roundedFg); } diff --git a/Telegram/SourceFiles/window/window_adaptive.cpp b/Telegram/SourceFiles/window/window_adaptive.cpp index c3932066e..2285a7bdb 100644 --- a/Telegram/SourceFiles/window/window_adaptive.cpp +++ b/Telegram/SourceFiles/window/window_adaptive.cpp @@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "data/data_media_types.h" #include "data/data_session.h" +#include "core/application.h" +#include "core/core_settings.h" namespace Window { @@ -25,6 +27,7 @@ void AdaptiveModern::setChatLayout(ChatLayout value) { rpl::producer<> AdaptiveModern::changed() const { return rpl::merge( + Core::App().settings().adaptiveForWideValue() | rpl::to_empty, _chatLayout.changes() | rpl::to_empty, _layout.changes() | rpl::to_empty); } @@ -52,4 +55,17 @@ bool AdaptiveModern::isThreeColumn() const { return _layout.current() == WindowLayout::ThreeColumn; } +rpl::producer AdaptiveModern::chatWideValue() const { + return rpl::combine( + _chatLayout.value( + ) | rpl::map(rpl::mappers::_1 == AdaptiveModern::ChatLayout::Wide), + Core::App().settings().adaptiveForWideValue() + ) | rpl::map(rpl::mappers::_1 && rpl::mappers::_2); +} + +bool AdaptiveModern::isChatWide() const { + return Core::App().settings().adaptiveForWide() + && (_chatLayout.current() == AdaptiveModern::ChatLayout::Wide); +} + } // namespace Window diff --git a/Telegram/SourceFiles/window/window_adaptive.h b/Telegram/SourceFiles/window/window_adaptive.h index d27980e8f..d6c7c3a20 100644 --- a/Telegram/SourceFiles/window/window_adaptive.h +++ b/Telegram/SourceFiles/window/window_adaptive.h @@ -35,6 +35,9 @@ public: [[nodiscard]] bool isNormal() const; [[nodiscard]] bool isThreeColumn() const; + [[nodiscard]] rpl::producer chatWideValue() const; + [[nodiscard]] bool isChatWide() const; + private: rpl::variable _chatLayout; rpl::variable _layout;