From ac243136b98b1e34df7092c313d028f7b52d1dda Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 29 Jun 2025 23:37:43 +0300 Subject: [PATCH] Replaced AboutBox with generic box. --- Telegram/SourceFiles/boxes/about_box.cpp | 139 +++++++++--------- Telegram/SourceFiles/boxes/about_box.h | 27 +--- Telegram/SourceFiles/boxes/boxes.style | 2 +- .../platform/mac/main_window_mac.mm | 2 +- .../SourceFiles/window/window_main_menu.cpp | 2 +- 5 files changed, 71 insertions(+), 101 deletions(-) diff --git a/Telegram/SourceFiles/boxes/about_box.cpp b/Telegram/SourceFiles/boxes/about_box.cpp index 75674299f8..3fe076b512 100644 --- a/Telegram/SourceFiles/boxes/about_box.cpp +++ b/Telegram/SourceFiles/boxes/about_box.cpp @@ -7,18 +7,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/about_box.h" -#include "lang/lang_keys.h" -#include "mainwidget.h" -#include "mainwindow.h" -#include "ui/boxes/confirm_box.h" -#include "ui/widgets/buttons.h" -#include "ui/widgets/labels.h" -#include "ui/text/text_utilities.h" #include "base/platform/base_platform_info.h" -#include "core/file_utilities.h" -#include "core/click_handler_types.h" -#include "core/update_checker.h" #include "core/application.h" +#include "core/file_utilities.h" +#include "core/update_checker.h" +#include "lang/lang_keys.h" +#include "ui/boxes/confirm_box.h" +#include "ui/text/text_utilities.h" +#include "ui/vertical_list.h" +#include "ui/widgets/buttons.h" +#include "ui/wrap/vertical_layout.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -57,78 +55,73 @@ rpl::producer Text3() { } // namespace -AboutBox::AboutBox(QWidget *parent) -: _version(this, tr::lng_about_version(tr::now, lt_version, currentVersionText()), st::aboutVersionLink) -, _text1(this, Text1(), st::aboutLabel) -, _text2(this, Text2(), st::aboutLabel) -, _text3(this, Text3(), st::aboutLabel) { -} +void AboutBox(not_null box) { + box->setTitle(rpl::single(u"Telegram Desktop"_q)); -void AboutBox::prepare() { - setTitle(rpl::single(u"Telegram Desktop"_q)); + auto layout = box->verticalLayout(); - addButton(tr::lng_close(), [this] { closeBox(); }); + const auto version = layout->add( + object_ptr( + box, + tr::lng_about_version( + tr::now, + lt_version, + currentVersionText()), + st::aboutVersionLink), + QMargins( + st::boxRowPadding.left(), + -st::lineWidth * 3, + st::boxRowPadding.right(), + st::boxRowPadding.bottom())); + version->setClickedCallback([=] { + if (cRealAlphaVersion()) { + auto url = u"https://tdesktop.com/"_q; + if (Platform::IsWindows32Bit()) { + url += u"win/%1.zip"_q; + } else if (Platform::IsWindows64Bit()) { + url += u"win64/%1.zip"_q; + } else if (Platform::IsWindowsARM64()) { + url += u"winarm/%1.zip"_q; + } else if (Platform::IsMac()) { + url += u"mac/%1.zip"_q; + } else if (Platform::IsLinux()) { + url += u"linux/%1.tar.xz"_q; + } else { + Unexpected("Platform value."); + } + url = url.arg(u"talpha%1_%2"_q + .arg(cRealAlphaVersion()) + .arg(Core::countAlphaVersionSignature(cRealAlphaVersion()))); - _text1->setLinksTrusted(); - _text2->setLinksTrusted(); - _text3->setLinksTrusted(); + QGuiApplication::clipboard()->setText(url); - _version->setClickedCallback([this] { showVersionHistory(); }); - - setDimensions(st::aboutWidth, st::aboutTextTop + _text1->height() + st::aboutSkip + _text2->height() + st::aboutSkip + _text3->height()); -} - -void AboutBox::resizeEvent(QResizeEvent *e) { - BoxContent::resizeEvent(e); - - const auto available = width() - - st::boxPadding.left() - - st::boxPadding.right(); - _version->moveToLeft(st::boxPadding.left(), st::aboutVersionTop); - _text1->resizeToWidth(available); - _text1->moveToLeft(st::boxPadding.left(), st::aboutTextTop); - _text2->resizeToWidth(available); - _text2->moveToLeft(st::boxPadding.left(), _text1->y() + _text1->height() + st::aboutSkip); - _text3->resizeToWidth(available); - _text3->moveToLeft(st::boxPadding.left(), _text2->y() + _text2->height() + st::aboutSkip); -} - -void AboutBox::showVersionHistory() { - if (cRealAlphaVersion()) { - auto url = u"https://tdesktop.com/"_q; - if (Platform::IsWindows32Bit()) { - url += u"win/%1.zip"_q; - } else if (Platform::IsWindows64Bit()) { - url += u"win64/%1.zip"_q; - } else if (Platform::IsWindowsARM64()) { - url += u"winarm/%1.zip"_q; - } else if (Platform::IsMac()) { - url += u"mac/%1.zip"_q; - } else if (Platform::IsLinux()) { - url += u"linux/%1.tar.xz"_q; + box->getDelegate()->show( + Ui::MakeInformBox( + "The link to the current private alpha " + "version of Telegram Desktop was copied " + "to the clipboard.")); } else { - Unexpected("Platform value."); + File::OpenUrl(Core::App().changelogLink()); } - url = url.arg(u"talpha%1_%2"_q.arg(cRealAlphaVersion()).arg(Core::countAlphaVersionSignature(cRealAlphaVersion()))); + }); - QGuiApplication::clipboard()->setText(url); + Ui::AddSkip(layout, st::aboutTopSkip); - getDelegate()->show( - Ui::MakeInformBox( - "The link to the current private alpha " - "version of Telegram Desktop was copied to the clipboard."), - Ui::LayerOption::CloseOther); - } else { - File::OpenUrl(Core::App().changelogLink()); - } -} + const auto addText = [&](rpl::producer text) { + const auto label = layout->add( + object_ptr(box, std::move(text), st::aboutLabel), + st::boxRowPadding); + label->setLinksTrusted(); + Ui::AddSkip(layout, st::aboutSkip); + }; -void AboutBox::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { - closeBox(); - } else { - BoxContent::keyPressEvent(e); - } + addText(Text1()); + addText(Text2()); + addText(Text3()); + + box->addButton(tr::lng_close(), [=] { box->closeBox(); }); + + box->setWidth(st::aboutWidth); } QString telegramFaqLink() { diff --git a/Telegram/SourceFiles/boxes/about_box.h b/Telegram/SourceFiles/boxes/about_box.h index e03b9970ec..61cb3fe83f 100644 --- a/Telegram/SourceFiles/boxes/about_box.h +++ b/Telegram/SourceFiles/boxes/about_box.h @@ -7,32 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "ui/layers/box_content.h" +#include "ui/layers/generic_box.h" -namespace Ui { -class LinkButton; -class FlatLabel; -} // namespace Ui - -class AboutBox : public Ui::BoxContent { -public: - AboutBox(QWidget*); - -protected: - void prepare() override; - - void resizeEvent(QResizeEvent *e) override; - void keyPressEvent(QKeyEvent *e) override; - -private: - void showVersionHistory(); - - object_ptr _version; - object_ptr _text1; - object_ptr _text2; - object_ptr _text3; - -}; +void AboutBox(not_null box); QString telegramFaqLink(); QString currentVersionText(); diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 33184a2fe9..25d6aca2fc 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -349,7 +349,7 @@ aboutVersionLink: LinkButton(defaultLinkButton) { color: windowSubTextFg; overColor: windowSubTextFg; } -aboutTextTop: 34px; +aboutTopSkip: 19px; aboutSkip: 14px; aboutLabel: FlatLabel(defaultFlatLabel) { minWidth: 300px; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 0bded2736c..5b26fefb9d 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -369,7 +369,7 @@ void MainWindow::createGlobalMenu() { { auto callback = [=] { ensureWindowShown(); - controller().show(Box()); + controller().show(Box(AboutBox)); }; main->addAction( tr::lng_mac_menu_about_telegram( diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 7e7f796831..7c0deede45 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -403,7 +403,7 @@ MainMenu::MainMenu( _version->setLink( 2, std::make_shared([=] { - controller->show(Box()); + controller->show(Box(AboutBox)); })); rpl::combine(