From 8224e6ece1b8fe1824060f9742bcbeca91bacbb8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 17 Mar 2026 18:32:11 +0400 Subject: [PATCH] Use menu items with checks for spoiler / quality. --- Telegram/Resources/icons/menu/quality_sd.svg | 6 -- Telegram/Resources/icons/menu/spoiler_off.png | Bin 797 -> 0 bytes .../Resources/icons/menu/spoiler_off@2x.png | Bin 1484 -> 0 bytes .../Resources/icons/menu/spoiler_off@3x.png | Bin 2198 -> 0 bytes Telegram/Resources/langs/lang.strings | 4 +- .../SourceFiles/boxes/edit_caption_box.cpp | 41 ++++----- Telegram/SourceFiles/boxes/send_files_box.cpp | 22 +++-- .../boxes/send_gif_with_caption_box.cpp | 13 ++- .../chat_helpers/chat_helpers.style | 4 - .../history_view_compose_controls.cpp | 11 +-- .../SourceFiles/media/view/media_view.style | 2 - .../SourceFiles/menu/menu_checked_action.cpp | 83 ++++++++++++++++++ .../SourceFiles/menu/menu_checked_action.h | 28 ++++++ Telegram/SourceFiles/menu/menu_send.cpp | 24 ++--- .../attach_abstract_single_media_preview.cpp | 16 ++-- .../ui/chat/attach/attach_album_preview.cpp | 14 +-- Telegram/SourceFiles/ui/menu_icons.style | 2 - Telegram/cmake/td_ui.cmake | 2 + 18 files changed, 188 insertions(+), 84 deletions(-) delete mode 100644 Telegram/Resources/icons/menu/quality_sd.svg delete mode 100644 Telegram/Resources/icons/menu/spoiler_off.png delete mode 100644 Telegram/Resources/icons/menu/spoiler_off@2x.png delete mode 100644 Telegram/Resources/icons/menu/spoiler_off@3x.png create mode 100644 Telegram/SourceFiles/menu/menu_checked_action.cpp create mode 100644 Telegram/SourceFiles/menu/menu_checked_action.h diff --git a/Telegram/Resources/icons/menu/quality_sd.svg b/Telegram/Resources/icons/menu/quality_sd.svg deleted file mode 100644 index e1ef219e0d..0000000000 --- a/Telegram/Resources/icons/menu/quality_sd.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Telegram/Resources/icons/menu/spoiler_off.png b/Telegram/Resources/icons/menu/spoiler_off.png deleted file mode 100644 index c694fd15da85df4d502d7302f666599a8f5a9c27..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 797 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1SIoCSFHz9jKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uv49!D1}S`GTDq2jfvMfo#WBP} z@NTfLcUGXtS`#CkPt2mu6BM|#6$=%VR&+c_Z~nz7sLIjQyzJ42%;q#Rp(Zw7maQUR zzb-Tp5@dC}&}pHuv1!4DOB(mPqK{Xv{r+HYV)cUR^?SeX{QYL@xeFKiO~rQ3y#HQa zR(9>xES8`C&mTN^@bl-*q>XFVuKl|x(r9ML>Z@F>N|R6e`1@PS@bw=*oVI!U_U$j@ zlO`u*XJ=<+Y02=dU$aI=R+h8XN$cwCuj|&YS65e`KW|=Ke0+RdoYh=Dhn6MNALiub z=;-Uq%gb-SojdvDkrRJ|1vpr~egA&^*s(_+D^_1MlImrCyFBQ!iNLpo4<9BT zk*F>${rc(CrzcNb)?c5@w)tjFY3bH2Tb_LW$;Z$C(e}y&ox=w$47eT@SgZ_r_3>li z^2>o7(@)37$Fr|Z+E`ImCZ-_cX3zP8ol!Y?euSo^ca zZlXtq$*i3_cYgj{yfP$fYt-F5^X{Xcs`f6C@cXY|;3ag$%5nbXmpWqI6NKiU*PrV3 z#q{!P&&Ru+*Rj1dmFmqf>DtRMf5wahaqr*1SM+vcHh$snvQbT_GihUl)!b>PpNfl% z|KMe7)|JPAftuZK{y9pBrno9itlG=hbinpX$l9=#jJamfOM@(JZRgIM zX(++7z+QyQF#T6gf$0hPs}bz23#*EYgOw%*D9Qzx&EC6rZ>ZMP`M&r6zJK@b-rc)_ z$@SCgk5|~l=}q6gb7y2s%%9-16Yl06f6czTBx_$-a$Lrun>l(qIyGnO6s)bSEAHRT z6IW7dyZn+(@XY!1;#{l-+!rTpzIR{zuERDTwdQ*-9yIiuKCD(q$v%464U{xJUHx3vIVCg!00UT3$N&HU diff --git a/Telegram/Resources/icons/menu/spoiler_off@2x.png b/Telegram/Resources/icons/menu/spoiler_off@2x.png deleted file mode 100644 index 9400628b8ddbe329020703b2a1bbd17c1a4963fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1484 zcmV;-1vC1IP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91FrWhf1ONa40RR91FaQ7m0NXcg3;+NHHc3Q5R9Fe^SXn5wT@*g%dCELb z$(T$b^N>hVh7`(hi$dISC5m$4(gmeZBFT^;g$tRJkRkIt&$E8~&;PIQd-I+1zMONM zgwL!-nO>3 ztgWp%M5GAI3+e_NfEE@OgM)*?!NFkW;^Gn=9W5xyAWu(EEiEnk`};slOiW5kOD`@i zii?XM9v*-=I5^nY*!1@HzP`SqtEQ&*`1ttp^1@92q@k~`KQ}iATKKK6ubZ2j%gV~u z*Vhxm_3Y~EBE1a_4J1=oSO`Q*OY83L4oG@>I=b50+Tc1mI?6?Y#X~12C*k4YaF3Id z6W-d;&=CBTk&yuvF)=Z$ir}G+jt&|^n;Os0&uIMf{|^m#1y48z{I0LBNk)XHp`qd8 z;v%heWo54kRxx5AxWQ=wfZGbJ;;ILXbwn-QM0Nd(+d?IyyRnDtvr= zu>Fzxm`st9k^;9OLz1w!w>R_%PUJ*BAcQ%#wzj*wyToZ~Y6_W`Q<0x}*s3>-m%rCfM8C9~>MIr?IgyO-)UHEfVYtLkQ*^9UTu34~f&r$cTo9 z264b z73Ty$@DOq|5;5OQS65eXBClZSNXl?SZf-7f+Dqk?L3?LsC#)hRB5U(;a&vP#J3Avz z0|NspDk^*eU+S`Yhze~oiI|61_-uH1c$}Y~lR$rezp}D2pMdyXK|-ju$kOEGB%K47 zmzT`(iERV{*z@x8LU~G(eSLirgtL(_4M>mTrHhYYF_ z@yid|q_{OiMn=B3M{QJX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jZ$Y!pD^;p=^XARC50^F_f{i-Ys#UA>L%+1KBN#RCK;VJE1Azwu4+I_vJmB=e Yzk$W)KWdpPT>t<807*qoM6N<$g8bJdApigX diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ee7750d1d3..c959d4b667 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5054,7 +5054,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_noforwards_info_mine" = "You disabled copying and forwarding in this chat."; "lng_context_spoiler_effect" = "Hide with Spoiler"; -"lng_context_disable_spoiler" = "Remove Spoiler"; "lng_context_make_paid" = "Make This Content Paid"; "lng_context_change_price" = "Change Price"; "lng_context_edit_cover" = "Edit Cover"; @@ -5171,10 +5170,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_send_grouped" = "Group items"; "lng_send_compressed_one" = "Compress the image"; "lng_send_compressed" = "Compress images"; -"lng_send_high_quality" = "Send in High Quality"; +"lng_send_high_quality" = "High Quality"; "lng_send_as_documents_one" = "Send as a document"; "lng_send_as_documents" = "Send as documents"; -"lng_send_standard_quality" = "Standard Quality"; "lng_send_media_invalid_files" = "Sorry, no valid files found."; "lng_send_image" = "Send an image"; "lng_send_file" = "Send as a file"; diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index d929632061..92243777ac 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history.h" #include "lang/lang_keys.h" +#include "menu/menu_checked_action.h" #include "main/main_session.h" #include "main/main_session_settings.h" #include "mainwidget.h" // controller->content() -> QWidget* @@ -760,36 +761,30 @@ void EditCaptionBox::setupEditEventHandler() { if (!_asFile && (_isPhoto || _isVideo)) { if (hasSendLargePhotosOption()) { const auto enabled = _sendLargePhotos; - (*menu)->addAction( - (enabled - ? tr::lng_send_standard_quality(tr::now) - : tr::lng_send_high_quality(tr::now)), + Menu::AddCheckedAction( + menu->get(), + tr::lng_send_high_quality(tr::now), [=] { _sendLargePhotos = !enabled; rebuildPreview(); }, - enabled - ? &st::menuIconQualityStandard - : &st::menuIconQualityHigh); + &st::menuIconQualityHigh, + enabled); } if (_preparedList.hasSpoilerMenu(!_asFile)) { const auto spoilered = hasSpoiler(); - auto text = spoilered - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now); - auto callback = [=] { - _mediaEditManager.apply({ .type = spoilered - ? SendMenu::ActionType::SpoilerOff - : SendMenu::ActionType::SpoilerOn - }); - rebuildPreview(); - }; - (*menu)->addAction( - std::move(text), - std::move(callback), - spoilered - ? &st::menuIconSpoilerOff - : &st::menuIconSpoiler); + Menu::AddCheckedAction( + menu->get(), + tr::lng_context_spoiler_effect(tr::now), + [=] { + _mediaEditManager.apply({ .type = spoilered + ? SendMenu::ActionType::SpoilerOff + : SendMenu::ActionType::SpoilerOn + }); + rebuildPreview(); + }, + &st::menuIconSpoiler, + spoilered); } if (_isVideo && !_preparedList.files.empty()) { (*menu)->addAction(tr::lng_context_edit_cover(tr::now), [=] { diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 145212de9b..767509869e 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "chat_helpers/message_field.h" +#include "menu/menu_checked_action.h" #include "menu/menu_send.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/field_autocomplete.h" @@ -1496,15 +1497,18 @@ void SendFilesBox::pushBlock(int from, int till) { if (canToggleSpoiler) { const auto spoilered = file.spoiler; const auto &icons = _st.tabbed.icons; - state->menu->addAction(spoilered - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now), [=] { - applyBlockChanges(); - refreshAllAfterChanges(from, [&] { - auto &entry = _list.files[fileIndex]; - entry.spoiler = !spoilered; - }); - }, spoilered ? &icons.menuSpoilerOff : &icons.menuSpoiler); + Menu::AddCheckedAction( + state->menu.get(), + tr::lng_context_spoiler_effect(tr::now), + [=] { + applyBlockChanges(); + refreshAllAfterChanges(from, [&] { + auto &entry = _list.files[fileIndex]; + entry.spoiler = !spoilered; + }); + }, + &icons.menuSpoiler, + spoilered); } const auto canEditCover = file.isVideoFile() && (_toPeer->isBroadcast() || _toPeer->isSelf()); diff --git a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp index 3c4a6ca823..a0492408ef 100644 --- a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp @@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "main/main_session.h" #include "media/clip/media_clip_reader.h" +#include "menu/menu_checked_action.h" #include "menu/menu_send.h" #include "ui/controls/emoji_button.h" #include "ui/controls/emoji_button_factory.h" @@ -257,10 +258,9 @@ struct State final { const auto menu = Ui::CreateChild( widget, st::popupMenuWithIcons); - menu->addAction( - state->hasSpoiler - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now), + ::Menu::AddCheckedAction( + menu, + tr::lng_context_spoiler_effect(tr::now), [=] { state->hasSpoiler = !state->hasSpoiler; if (!state->hasSpoiler) { @@ -273,9 +273,8 @@ struct State final { } widget->update(); }, - state->hasSpoiler - ? &st::menuIconSpoilerOff - : &st::menuIconSpoiler); + &st::menuIconSpoiler, + state->hasSpoiler); menu->popup(QCursor::pos()); return base::EventFilterResult::Cancel; } diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index a851b3ff84..48acb15505 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -69,11 +69,9 @@ ComposeIcons { menuSchedule: icon; menuWhenOnline: icon; menuSpoiler: icon; - menuSpoilerOff: icon; menuBelow: icon; menuAbove: icon; menuQualityHigh: icon; - menuQualityStandard: icon; menuPrice: icon; menuEditStars: icon; @@ -657,11 +655,9 @@ defaultComposeIcons: ComposeIcons { menuSchedule: menuIconSchedule; menuWhenOnline: menuIconWhenOnline; menuSpoiler: menuIconSpoiler; - menuSpoilerOff: menuIconSpoilerOff; menuBelow: menuIconBelow; menuAbove: menuIconAbove; menuQualityHigh: menuIconQualityHigh; - menuQualityStandard: menuIconQualityStandard; menuPrice: menuIconEarn; stripBubble: icon{ diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 94c62567c5..15edeeddc2 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -75,6 +75,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/session/send_as_peers.h" #include "media/audio/media_audio_capture.h" #include "media/audio/media_audio.h" +#include "menu/menu_checked_action.h" #include "menu/menu_send.h" #include "settings/sections/settings_premium.h" #include "ui/item_text_options.h" @@ -4367,12 +4368,12 @@ void ShowPhotoEditSpoilerMenu( const auto menu = Ui::CreateChild( parent, st::popupMenuWithIcons); - menu->addAction( - spoilered - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now), + Menu::AddCheckedAction( + menu, + tr::lng_context_spoiler_effect(tr::now), [=] { callback(!spoilered); }, - spoilered ? &st::menuIconSpoilerOff : &st::menuIconSpoiler); + &st::menuIconSpoiler, + spoilered); menu->popup(QCursor::pos()); } diff --git a/Telegram/SourceFiles/media/view/media_view.style b/Telegram/SourceFiles/media/view/media_view.style index cae366abd0..18afb14c84 100644 --- a/Telegram/SourceFiles/media/view/media_view.style +++ b/Telegram/SourceFiles/media/view/media_view.style @@ -656,11 +656,9 @@ storiesEmojiPan: EmojiPan(defaultEmojiPan) { menuSchedule: icon {{ "menu/calendar", storiesComposeWhiteText }}; menuWhenOnline: icon {{ "menu/send_when_online", storiesComposeWhiteText }}; menuSpoiler: icon {{ "menu/spoiler_on", storiesComposeWhiteText }}; - menuSpoilerOff: icon {{ "menu/spoiler_off", storiesComposeWhiteText }}; menuBelow: icon {{ "menu/link_below", storiesComposeWhiteText }}; menuAbove: icon {{ "menu/link_above", storiesComposeWhiteText }}; menuQualityHigh: icon {{ "menu/quality_hd", storiesComposeWhiteText }}; - menuQualityStandard: icon {{ "menu/quality_sd", storiesComposeWhiteText }}; menuPrice: icon {{ "menu/earn", storiesComposeWhiteText }}; menuEditStars: icon {{ "chat/input_paid", storiesComposeWhiteText, point(-8px, -8px) }}; diff --git a/Telegram/SourceFiles/menu/menu_checked_action.cpp b/Telegram/SourceFiles/menu/menu_checked_action.cpp new file mode 100644 index 0000000000..7285204ce6 --- /dev/null +++ b/Telegram/SourceFiles/menu/menu_checked_action.cpp @@ -0,0 +1,83 @@ +/* +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_checked_action.h" + +#include "base/unique_qptr.h" +#include "ui/widgets/menu/menu_action.h" +#include "ui/widgets/menu/menu_common.h" +#include "ui/widgets/popup_menu.h" +#include "ui/painter.h" + +#include "styles/style_media_player.h" + +namespace { + +class CheckedAction final : public Ui::Menu::Action { +public: + CheckedAction( + not_null parent, + const style::Menu &st, + not_null action, + const style::icon *icon, + bool checked); + +private: + void paintEvent(QPaintEvent *e) override; + + const bool _checked = false; + +}; + +CheckedAction::CheckedAction( + not_null parent, + const style::Menu &st, + not_null action, + const style::icon *icon, + bool checked) +: Ui::Menu::Action(parent, st, action, icon, icon) +, _checked(checked) { + setMinWidth(minWidth() + st.itemRightSkip + st::mediaPlayerMenuCheck.width()); +} + +void CheckedAction::paintEvent(QPaintEvent *e) { + Ui::Menu::Action::paintEvent(e); + + if (!_checked) { + return; + } + + Painter p(this); + const auto &icon = st::mediaPlayerMenuCheck; + const auto left = width() - st().itemRightSkip - icon.width(); + const auto top = (height() - icon.height()) / 2; + icon.paint(p, left, top, width()); +} + +} // namespace + +namespace Menu { + +not_null AddCheckedAction( + not_null menu, + const QString &text, + Fn callback, + const style::icon *icon, + bool checked) { + auto item = base::make_unique_q( + menu->menu(), + menu->st().menu, + Ui::Menu::CreateAction( + menu->menu().get(), + text, + std::move(callback)), + icon, + checked); + return menu->addAction(std::move(item)); +} + +} // namespace Menu diff --git a/Telegram/SourceFiles/menu/menu_checked_action.h b/Telegram/SourceFiles/menu/menu_checked_action.h new file mode 100644 index 0000000000..6426c1770a --- /dev/null +++ b/Telegram/SourceFiles/menu/menu_checked_action.h @@ -0,0 +1,28 @@ +/* +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 "base/basic_types.h" +#include "ui/style/style_core_types.h" + +class QAction; + +namespace Ui { +class PopupMenu; +} // namespace Ui + +namespace Menu { + +not_null AddCheckedAction( + not_null menu, + const QString &text, + Fn callback, + const style::icon *icon, + bool checked); + +} // namespace Menu diff --git a/Telegram/SourceFiles/menu/menu_send.cpp b/Telegram/SourceFiles/menu/menu_send.cpp index d2fc93e2fe..8f423fa3a7 100644 --- a/Telegram/SourceFiles/menu/menu_send.cpp +++ b/Telegram/SourceFiles/menu/menu_send.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "menu/menu_send.h" +#include "menu/menu_checked_action.h" + #include "api/api_common.h" #include "base/event_filter.h" #include "base/unixtime.h" @@ -771,29 +773,27 @@ FillMenuResult FillSendMenu( } if (details.photoQuality != PhotoQualityState::None) { const auto high = (details.photoQuality == PhotoQualityState::High); - menu->addAction( - (high - ? tr::lng_send_standard_quality(tr::now) - : tr::lng_send_high_quality(tr::now)), + Menu::AddCheckedAction( + menu, + tr::lng_send_high_quality(tr::now), [=] { action({ .type = high ? ActionType::PhotoQualityOff : ActionType::PhotoQualityOn }, details); }, - (high - ? &icons.menuQualityStandard - : &icons.menuQualityHigh)); + &icons.menuQualityHigh, + high); } if (details.spoiler != SpoilerState::None) { const auto spoilered = (details.spoiler == SpoilerState::Enabled); - menu->addAction( - (spoilered - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now)), + Menu::AddCheckedAction( + menu, + tr::lng_context_spoiler_effect(tr::now), [=] { action({ .type = spoilered ? ActionType::SpoilerOff : ActionType::SpoilerOn }, details); }, - spoilered ? &icons.menuSpoilerOff : &icons.menuSpoiler); + &icons.menuSpoiler, + spoilered); } if (details.caption != CaptionState::None) { const auto above = (details.caption == CaptionState::Above); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_abstract_single_media_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_abstract_single_media_preview.cpp index da2bc305fe..f46c551d18 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_abstract_single_media_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_abstract_single_media_preview.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "editor/photo_editor_common.h" #include "lang/lang_keys.h" +#include "menu/menu_checked_action.h" #include "ui/chat/attach/attach_controls.h" #include "ui/chat/attach/attach_prepare.h" #include "ui/effects/spoiler_mess.h" @@ -301,12 +302,15 @@ void AbstractSingleMediaPreview::showContextMenu(QPoint position) { && _sendWay.sendImagesAsPhotos() && supportsSpoilers()) { const auto spoilered = hasSpoiler(); - _menu->addAction(spoilered - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now), [=] { - setSpoiler(!spoilered); - _spoileredChanges.fire_copy(!spoilered); - }, spoilered ? &icons.menuSpoilerOff : &icons.menuSpoiler); + ::Menu::AddCheckedAction( + _menu.get(), + tr::lng_context_spoiler_effect(tr::now), + [=] { + setSpoiler(!spoilered); + _spoileredChanges.fire_copy(!spoilered); + }, + &icons.menuSpoiler, + spoilered); } if (_actionAllowed(AttachActionType::EditCover)) { _menu->addAction(tr::lng_context_edit_cover(tr::now), [=] { diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp index cd2dc1d616..58ef4b6476 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/chat/attach/attach_album_preview.h" +#include "menu/menu_checked_action.h" #include "ui/chat/attach/attach_album_thumbnail.h" #include "ui/chat/attach/attach_prepare.h" #include "ui/effects/spoiler_mess.h" @@ -643,11 +644,14 @@ void AlbumPreview::showContextMenu( if (_actionAllowed(index, AttachActionType::ToggleSpoiler) && _sendWay.sendImagesAsPhotos()) { const auto spoilered = thumb->hasSpoiler(); - _menu->addAction(spoilered - ? tr::lng_context_disable_spoiler(tr::now) - : tr::lng_context_spoiler_effect(tr::now), [=] { - thumb->setSpoiler(!spoilered); - }, spoilered ? &st::menuIconSpoilerOff : &st::menuIconSpoiler); + ::Menu::AddCheckedAction( + _menu.get(), + tr::lng_context_spoiler_effect(tr::now), + [=] { + thumb->setSpoiler(!spoilered); + }, + &st::menuIconSpoiler, + spoilered); } if (_actionAllowed(index, AttachActionType::EditCover)) { _menu->addAction(tr::lng_context_edit_cover(tr::now), [=] { diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index 55f0366f12..ed468953e7 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -106,9 +106,7 @@ menuIconVideoChat: icon {{ "menu/video_chat", menuIconColor }}; menuIconTranslate: icon {{ "menu/translate", menuIconColor }}; menuIconReportAntiSpam: icon {{ "menu/false_positive", menuIconColor }}; menuIconSpoiler: icon {{ "menu/spoiler_on", menuIconColor }}; -menuIconSpoilerOff: icon {{ "menu/spoiler_off", menuIconColor }}; menuIconQualityHigh: icon {{ "menu/quality_hd", menuIconColor }}; -menuIconQualityStandard: icon {{ "menu/quality_sd", menuIconColor }}; menuIconDisable: icon {{ "menu/disable", menuIconColor }}; menuIconPhotoSet: icon {{ "menu/photo_set", menuIconColor }}; menuIconPhotoSuggest: icon {{ "menu/photo_suggest", menuIconColor }}; diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 9ee7210042..a959ceb849 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -218,6 +218,8 @@ PRIVATE menu/gift_resale_filter.cpp menu/gift_resale_filter.h + menu/menu_checked_action.cpp + menu/menu_checked_action.h menu/menu_check_item.cpp menu/menu_check_item.h menu/menu_item_rate_transcribe.cpp