Use menu items with checks for spoiler / quality.

This commit is contained in:
John Preston
2026-03-17 18:32:11 +04:00
parent 87ebd2720f
commit 8224e6ece1
18 changed files with 188 additions and 84 deletions
+18 -23
View File
@@ -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), [=] {
+13 -9
View File
@@ -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());
@@ -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<Ui::PopupMenu>(
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;
}