From 3ac4eefe1dcd7142d328c2cff76187f7b913cf89 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 2 Jan 2026 09:45:02 +0300 Subject: [PATCH] Slightly improved style of top bar in admin log section. --- .../admin_log/history_admin_log_section.cpp | 13 +++ .../profile/profile_back_button.cpp | 99 +++++++++++++++++-- .../SourceFiles/profile/profile_back_button.h | 16 +++ Telegram/SourceFiles/ui/chat/chat.style | 2 + 4 files changed, 124 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index 7da0862dda..0acb4a8477 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -11,12 +11,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/admin_log/history_admin_log_filter.h" #include "profile/profile_back_button.h" #include "core/shortcuts.h" +#include "info/profile/info_profile_values.h" #include "ui/chat/chat_style.h" #include "ui/controls/swipe_handler.h" #include "ui/effects/animations.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" +#include "ui/controls/userpic_button.h" #include "ui/widgets/fields/input_field.h" #include "ui/ui_utility.h" #include "apiwrap.h" @@ -132,6 +134,15 @@ FixedBar::FixedBar( _searchTimer.setCallback([=] { applySearch(); }); _cancel->hide(anim::type::instant); + + _backButton->setSubtext(tr::lng_admin_log_title_all(tr::now)); + Info::Profile::NameValue(channel) | rpl::on_next([=](QString name) { + _backButton->setText(name); + }, _backButton->lifetime()); + _backButton->setWidget(Ui::CreateChild( + _backButton.get(), + channel, + st::topBarInfoButton)); } void FixedBar::applyFilter(const FilterValue &value) { @@ -178,6 +189,7 @@ void FixedBar::searchAnimationCallback() { _searchShown ? &st::topBarBg : nullptr); _search->setCursor( _searchShown ? style::cur_default : style::cur_pointer); + _backButton->setOpacity(1.); } resizeToWidth(width()); } @@ -218,6 +230,7 @@ int FixedBar::resizeGetHeight(int newWidth) { searchShownLeft, searchShown); _search->moveToLeft(searchCurrentLeft, 0); + _backButton->setOpacity(1. - searchShown); _backButton->resizeToWidth(searchCurrentLeft); _backButton->moveToLeft(0, 0); diff --git a/Telegram/SourceFiles/profile/profile_back_button.cpp b/Telegram/SourceFiles/profile/profile_back_button.cpp index 5de124d152..c0dd41128f 100644 --- a/Telegram/SourceFiles/profile/profile_back_button.cpp +++ b/Telegram/SourceFiles/profile/profile_back_button.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "profile/profile_back_button.h" -//#include "history/view/history_view_top_bar_widget.h" #include "main/main_session.h" #include "data/data_session.h" #include "ui/painter.h" @@ -15,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_window.h" #include "styles/style_profile.h" #include "styles/style_info.h" +#include "styles/style_chat.h" +#include "styles/style_dialogs.h" + +#include namespace Profile { @@ -48,22 +51,106 @@ BackButton::BackButton( void BackButton::setText(const QString &text) { _text = text; + _cachedWidth = -1; + update(); +} + +void BackButton::setSubtext(const QString &subtext) { + _subtext = subtext; + _cachedWidth = -1; + update(); +} + +void BackButton::setWidget(not_null widget) { + _widget = widget; + _widget->setParent(this); + _widget->show(); + _widget->move( + st::historyAdminLogTopBarLeft + st::historyAdminLogTopBarUserpicSkip, + (st::profileTopBarHeight - _widget->height()) / 2); + _cachedWidth = -1; + update(); +} + +void BackButton::setOpacity(float64 opacity) { + _opacity = opacity; + if (_widget) { + if (opacity < 1.) { + if (!_opacityEffect) { + _opacityEffect = Ui::CreateChild( + _widget); + _widget->setGraphicsEffect(_opacityEffect); + } + _opacityEffect->setOpacity(opacity); + } else { + _widget->setGraphicsEffect(nullptr); + _opacityEffect = nullptr; + } + } update(); } int BackButton::resizeGetHeight(int newWidth) { + _cachedWidth = -1; return st::profileTopBarHeight; } +void BackButton::updateCache() { + if (_cachedWidth == width()) { + return; + } + _cachedWidth = width(); + const auto widgetWidth = _widget + ? _widget->width() + st::historyAdminLogTopBarUserpicSkip + : 0; + const auto availableWidth = width() + - st::historyAdminLogTopBarLeft + - widgetWidth; + _cachedElidedText = st::semiboldFont->elided( + _text, + availableWidth); + _cachedElidedSubtext = st::dialogsTextFont->elided( + _subtext, + availableWidth); +} + void BackButton::paintEvent(QPaintEvent *e) { - Painter p(this); + updateCache(); + + auto p = Painter(this); + p.setOpacity(_opacity); p.fillRect(e->rect(), st::profileBg); - st::topBarBack.paint(p, (st::topBarArrowPadding.left() - st::topBarBack.width()) / 2, (st::topBarHeight - st::topBarBack.height()) / 2, width()); + st::topBarBack.paint( + p, + st::historyAdminLogTopBarLeft, + (st::topBarHeight - st::topBarBack.height()) / 2, + width()); - p.setFont(st::topBarButton.style.font); - p.setPen(st::topBarButton.textFg); - p.drawTextLeft(st::topBarArrowPadding.left(), st::topBarButton.padding.top() + st::topBarButton.textTop, width(), _text); + const auto textHeight = st::semiboldFont->height; + const auto subtextHeight = st::dialogsTextFont->height; + const auto totalHeight = _subtext.isEmpty() + ? textHeight + : textHeight + subtextHeight; + const auto startY = (height() - totalHeight) / 2 - st::lineWidth; + const auto widgetWidth = _widget + ? _widget->width() + st::historyAdminLogTopBarUserpicSkip + : 0; + const auto textX = st::historyAdminLogTopBarLeft + widgetWidth; + + p.setFont(st::semiboldFont); + p.setPen(st::dialogsNameFg); + p.drawTextLeft(textX, startY, width(), _cachedElidedText); + + if (!_subtext.isEmpty()) { + p.setFont(st::dialogsTextFont); + p.setPen(st::historyStatusFg); + p.drawTextLeft( + textX, + startY + textHeight + st::lineWidth * 2, + width(), + _cachedElidedSubtext); + } } void BackButton::onStateChanged(State was, StateChangeSource source) { diff --git a/Telegram/SourceFiles/profile/profile_back_button.h b/Telegram/SourceFiles/profile/profile_back_button.h index 4c3ca7ceab..7b6d557107 100644 --- a/Telegram/SourceFiles/profile/profile_back_button.h +++ b/Telegram/SourceFiles/profile/profile_back_button.h @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/abstract_button.h" +class QGraphicsOpacityEffect; + namespace Main { class Session; } // namespace Main @@ -24,6 +26,9 @@ public: rpl::producer oneColumnValue); void setText(const QString &text); + void setSubtext(const QString &subtext); + void setWidget(not_null widget); + void setOpacity(float64 opacity); protected: void paintEvent(QPaintEvent *e) override; @@ -32,10 +37,21 @@ protected: void onStateChanged(State was, StateChangeSource source) override; private: + void updateCache(); + const not_null _session; rpl::lifetime _unreadBadgeLifetime; QString _text; + QString _subtext; + Ui::RpWidget *_widget = nullptr; + + int _cachedWidth = -1; + QString _cachedElidedText; + QString _cachedElidedSubtext; + + float64 _opacity = 1.0; + QGraphicsOpacityEffect *_opacityEffect = nullptr; }; diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 17bec8158c..8a9f7a48cd 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -582,6 +582,8 @@ historyAdminLogCancelSearch: CrossButton { } historyAdminLogSearchTop: 11px; historyAdminLogSearchSlideDuration: 150; +historyAdminLogTopBarLeft: 17px; +historyAdminLogTopBarUserpicSkip: 35px; historyAdminLogWhatIsThis: IconButton(historyAttach) { icon: icon {{ "menu/faq", windowActiveTextFg }}; iconOver: icon {{ "menu/faq", windowActiveTextFg }};