From 51cb234b37656fde504010b5c97c763b73e6dc0c Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 27 Mar 2022 15:46:27 +0300 Subject: [PATCH] Moved menu item with check to td_ui. --- Telegram/SourceFiles/boxes/share_box.cpp | 41 +------------------ Telegram/SourceFiles/menu/menu_check_item.cpp | 39 ++++++++++++++++++ Telegram/SourceFiles/menu/menu_check_item.h | 30 ++++++++++++++ Telegram/cmake/td_ui.cmake | 3 ++ Telegram/lib_ui | 2 +- 5 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 Telegram/SourceFiles/menu/menu_check_item.cpp create mode 100644 Telegram/SourceFiles/menu/menu_check_item.h diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index cb18f722d8..5fe89e692c 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -21,12 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/input_fields.h" -#include "ui/widgets/menu/menu_action.h" #include "ui/widgets/popup_menu.h" #include "ui/wrap/slide_wrap.h" #include "ui/text/text_options.h" #include "ui/text/text_utilities.h" #include "chat_helpers/message_field.h" +#include "menu/menu_check_item.h" #include "menu/menu_send.h" #include "history/history.h" #include "history/history_message.h" @@ -49,47 +49,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" #include "styles/style_chat.h" #include "styles/style_menu_icons.h" -#include "styles/style_media_player.h" #include #include -namespace { - -class ForwardOptionItem final : public Ui::Menu::Action { -public: - using Ui::Menu::Action::Action; - - void init(bool checked) { - enableMouseSelecting(); - - AbstractButton::setDisabled(true); - - _checkView = std::make_unique(st::defaultCheck, false); - _checkView->checkedChanges( - ) | rpl::start_with_next([=](bool checked) { - setIcon(checked ? &st::mediaPlayerMenuCheck : nullptr); - }, lifetime()); - - _checkView->setChecked(checked, anim::type::normal); - AbstractButton::clicks( - ) | rpl::start_with_next([=] { - _checkView->setChecked( - !_checkView->checked(), - anim::type::normal); - }, lifetime()); - } - - not_null checkView() const { - return _checkView.get(); - } - -private: - std::unique_ptr _checkView; -}; - -} // namespace - class ShareBox::Inner final : public Ui::RpWidget { public: Inner(QWidget *parent, const Descriptor &descriptor); @@ -503,7 +466,7 @@ void ShareBox::showMenu(not_null parent) { if (_descriptor.forwardOptions.show) { auto createView = [&](rpl::producer &&text, bool checked) { - auto item = base::make_unique_q( + auto item = base::make_unique_q( _menu->menu(), st::popupMenuWithIcons.menu, new QAction(QString(), _menu->menu()), diff --git a/Telegram/SourceFiles/menu/menu_check_item.cpp b/Telegram/SourceFiles/menu/menu_check_item.cpp new file mode 100644 index 0000000000..f76e5d3b9b --- /dev/null +++ b/Telegram/SourceFiles/menu/menu_check_item.cpp @@ -0,0 +1,39 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "menu/menu_check_item.h" + +#include "ui/widgets/checkbox.h" +#include "styles/style_media_player.h" + +namespace Menu { + +void ItemWithCheck::init(bool checked) { + enableMouseSelecting(); + + AbstractButton::setDisabled(true); + + _checkView = std::make_unique(st::defaultCheck, false); + _checkView->checkedChanges( + ) | rpl::start_with_next([=](bool checked) { + setIcon(checked ? &st::mediaPlayerMenuCheck : nullptr); + }, lifetime()); + + _checkView->setChecked(checked, anim::type::normal); + AbstractButton::clicks( + ) | rpl::start_with_next([=] { + _checkView->setChecked( + !_checkView->checked(), + anim::type::normal); + }, lifetime()); +} + +not_null ItemWithCheck::checkView() const { + return _checkView.get(); +} + +} // namespace Menu diff --git a/Telegram/SourceFiles/menu/menu_check_item.h b/Telegram/SourceFiles/menu/menu_check_item.h new file mode 100644 index 0000000000..181b446953 --- /dev/null +++ b/Telegram/SourceFiles/menu/menu_check_item.h @@ -0,0 +1,30 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "ui/widgets/menu/menu_action.h" + +namespace Ui { +class CheckView; +} // namespace Ui + +namespace Menu { + +class ItemWithCheck final : public Ui::Menu::Action { +public: + using Ui::Menu::Action::Action; + + void init(bool checked); + + not_null checkView() const; + +private: + std::unique_ptr _checkView; +}; + +} // namespace Menu diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index e31ccd77d4..bd62b61c4d 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -102,6 +102,9 @@ PRIVATE media/player/media_player_dropdown.cpp media/player/media_player_dropdown.h + menu/menu_check_item.cpp + menu/menu_check_item.h + passport/ui/passport_details_row.cpp passport/ui/passport_details_row.h passport/ui/passport_form_row.cpp diff --git a/Telegram/lib_ui b/Telegram/lib_ui index a0b04da1d9..62002f034b 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit a0b04da1d95a67d1ba431b7652026bd72d86962e +Subproject commit 62002f034bbfd3e5f78a71317f37c685a8846b1f