mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Replaced slots with lambdas to fill context menu in OverlayWidget.
This commit is contained in:
parent
2d906bddb2
commit
03a7131a1a
2 changed files with 34 additions and 32 deletions
|
@ -793,33 +793,37 @@ void OverlayWidget::refreshCaptionGeometry() {
|
||||||
captionHeight);
|
captionHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::updateActions() {
|
void OverlayWidget::fillContextMenuActions(const MenuCallback &addAction) {
|
||||||
_actions.clear();
|
|
||||||
|
|
||||||
if (_document && _document->loading()) {
|
if (_document && _document->loading()) {
|
||||||
_actions.push_back({ tr::lng_cancel(tr::now), SLOT(onSaveCancel()) });
|
addAction(tr::lng_cancel(tr::now), [=] { onSaveCancel(); });
|
||||||
}
|
}
|
||||||
if (IsServerMsgId(_msgid.msg)) {
|
if (IsServerMsgId(_msgid.msg)) {
|
||||||
_actions.push_back({ tr::lng_context_to_msg(tr::now), SLOT(onToMessage()) });
|
addAction(tr::lng_context_to_msg(tr::now), [=] { onToMessage(); });
|
||||||
}
|
}
|
||||||
if (_document && !_document->filepath(true).isEmpty()) {
|
if (_document && !_document->filepath(true).isEmpty()) {
|
||||||
_actions.push_back({ Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), SLOT(onShowInFolder()) });
|
const auto text = Platform::IsMac()
|
||||||
|
? tr::lng_context_show_in_finder(tr::now)
|
||||||
|
: tr::lng_context_show_in_folder(tr::now);
|
||||||
|
addAction(text, [=] { onShowInFolder(); });
|
||||||
}
|
}
|
||||||
if ((_document && documentContentShown()) || (_photo && _photoMedia->loaded())) {
|
if ((_document && documentContentShown()) || (_photo && _photoMedia->loaded())) {
|
||||||
_actions.push_back({ tr::lng_mediaview_copy(tr::now), SLOT(onCopy()) });
|
addAction(tr::lng_mediaview_copy(tr::now), [=] { onCopy(); });
|
||||||
}
|
}
|
||||||
if ((_photo && _photo->hasAttachedStickers())
|
if ((_photo && _photo->hasAttachedStickers())
|
||||||
|| (_document && _document->hasAttachedStickers())) {
|
|| (_document && _document->hasAttachedStickers())) {
|
||||||
auto member = _photo
|
auto callback = [=] {
|
||||||
? SLOT(onPhotoAttachedStickers())
|
if (_photo) {
|
||||||
: SLOT(onDocumentAttachedStickers());
|
onPhotoAttachedStickers();
|
||||||
_actions.push_back({
|
} else if (_document) {
|
||||||
|
onDocumentAttachedStickers();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
addAction(
|
||||||
tr::lng_context_attached_stickers(tr::now),
|
tr::lng_context_attached_stickers(tr::now),
|
||||||
std::move(member)
|
std::move(callback));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (_canForwardItem) {
|
if (_canForwardItem) {
|
||||||
_actions.push_back({ tr::lng_mediaview_forward(tr::now), SLOT(onForward()) });
|
addAction(tr::lng_mediaview_forward(tr::now), [=] { onForward(); });
|
||||||
}
|
}
|
||||||
const auto canDelete = [&] {
|
const auto canDelete = [&] {
|
||||||
if (_canDeleteItem) {
|
if (_canDeleteItem) {
|
||||||
|
@ -839,12 +843,15 @@ void OverlayWidget::updateActions() {
|
||||||
return false;
|
return false;
|
||||||
}();
|
}();
|
||||||
if (canDelete) {
|
if (canDelete) {
|
||||||
_actions.push_back({ tr::lng_mediaview_delete(tr::now), SLOT(onDelete()) });
|
addAction(tr::lng_mediaview_delete(tr::now), [=] { onDelete(); });
|
||||||
}
|
}
|
||||||
_actions.push_back({ tr::lng_mediaview_save_as(tr::now), SLOT(onSaveAs()) });
|
addAction(tr::lng_mediaview_save_as(tr::now), [=] { onSaveAs(); });
|
||||||
|
|
||||||
if (const auto overviewType = computeOverviewType()) {
|
if (const auto overviewType = computeOverviewType()) {
|
||||||
_actions.push_back({ _document ? tr::lng_mediaview_files_all(tr::now) : tr::lng_mediaview_photos_all(tr::now), SLOT(onOverview()) });
|
const auto text = _document
|
||||||
|
? tr::lng_mediaview_files_all(tr::now)
|
||||||
|
: tr::lng_mediaview_photos_all(tr::now);
|
||||||
|
addAction(text, [=] { onOverview(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4143,10 +4150,9 @@ void OverlayWidget::contextMenuEvent(QContextMenuEvent *e) {
|
||||||
_menu = base::make_unique_q<Ui::PopupMenu>(
|
_menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
this,
|
this,
|
||||||
st::mediaviewPopupMenu);
|
st::mediaviewPopupMenu);
|
||||||
updateActions();
|
fillContextMenuActions([&] (const QString &text, Fn<void()> handler) {
|
||||||
for_const (auto &action, _actions) {
|
_menu->addAction(text, std::move(handler));
|
||||||
_menu->addAction(action.text, this, action.member);
|
});
|
||||||
}
|
|
||||||
_menu->setDestroyedCallback(crl::guard(this, [=] {
|
_menu->setDestroyedCallback(crl::guard(this, [=] {
|
||||||
activateControls();
|
activateControls();
|
||||||
_receiveMouse = false;
|
_receiveMouse = false;
|
||||||
|
@ -4344,11 +4350,10 @@ void OverlayWidget::receiveMouse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::onDropdown() {
|
void OverlayWidget::onDropdown() {
|
||||||
updateActions();
|
|
||||||
_dropdown->clearActions();
|
_dropdown->clearActions();
|
||||||
for_const (auto &action, _actions) {
|
fillContextMenuActions([&] (const QString &text, Fn<void()> handler) {
|
||||||
_dropdown->addAction(action.text, this, action.member);
|
_dropdown->addAction(text, std::move(handler));
|
||||||
}
|
});
|
||||||
_dropdown->moveToRight(0, height() - _dropdown->height());
|
_dropdown->moveToRight(0, height() - _dropdown->height());
|
||||||
_dropdown->showAnimated(Ui::PanelAnimation::Origin::BottomRight);
|
_dropdown->showAnimated(Ui::PanelAnimation::Origin::BottomRight);
|
||||||
_dropdown->setFocus();
|
_dropdown->setFocus();
|
||||||
|
|
|
@ -274,8 +274,11 @@ private:
|
||||||
void dropdownHidden();
|
void dropdownHidden();
|
||||||
void updateDocSize();
|
void updateDocSize();
|
||||||
void updateControls();
|
void updateControls();
|
||||||
void updateActions();
|
|
||||||
void updateControlsGeometry();
|
void updateControlsGeometry();
|
||||||
|
|
||||||
|
using MenuCallback = Fn<void(const QString &, Fn<void()>)>;
|
||||||
|
void fillContextMenuActions(const MenuCallback &addAction);
|
||||||
|
|
||||||
void resizeCenteredControls();
|
void resizeCenteredControls();
|
||||||
void resizeContentByScreenSize();
|
void resizeContentByScreenSize();
|
||||||
|
|
||||||
|
@ -501,12 +504,6 @@ private:
|
||||||
object_ptr<Ui::DropdownMenu> _dropdown;
|
object_ptr<Ui::DropdownMenu> _dropdown;
|
||||||
base::Timer _dropdownShowTimer;
|
base::Timer _dropdownShowTimer;
|
||||||
|
|
||||||
struct ActionData {
|
|
||||||
QString text;
|
|
||||||
const char *member;
|
|
||||||
};
|
|
||||||
QList<ActionData> _actions;
|
|
||||||
|
|
||||||
bool _receiveMouse = true;
|
bool _receiveMouse = true;
|
||||||
|
|
||||||
bool _touchPress = false;
|
bool _touchPress = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue