From 72f0fb6892cc7532d8d9a21f3be1f3286492385f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 28 Sep 2025 09:20:21 +0300 Subject: [PATCH] Added menu item to sub tabs for star gifts collections for reordering. --- Telegram/Resources/langs/lang.strings | 2 ++ .../peer_gifts/info_peer_gifts_widget.cpp | 9 +++++ Telegram/SourceFiles/ui/controls/sub_tabs.cpp | 36 +++++++++++++------ Telegram/SourceFiles/ui/controls/sub_tabs.h | 4 +++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index cd35e615f1..822f2ba065 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3900,6 +3900,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_gift_collection_delete_sure" = "Are you sure you want to delete this collection?"; "lng_gift_collection_delete_button" = "Delete"; "lng_gift_collection_add_to" = "Add to Collection"; +"lng_gift_collection_reorder" = "Reorder"; +"lng_gift_collection_reorder_exit" = "Apply Reorder"; "lng_gift_locked_title" = "Gift Locked"; "lng_accounts_limit_title" = "Limit Reached"; diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp index 934336e700..692873152a 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp @@ -830,6 +830,15 @@ void InnerWidget::showMenuForCollection(int id) { addAction(tr::lng_gift_collection_edit(tr::now), [=] { editCollectionName(id); }, &st::menuIconEdit); + if (_collectionsTabs) { + const auto reorderEnabled = _collectionsTabs->reorderEnabled(); + addAction( + reorderEnabled + ? tr::lng_gift_collection_reorder_exit(tr::now) + : tr::lng_gift_collection_reorder(tr::now), + [=] { _collectionsTabs->setReorderEnabled(!reorderEnabled); }, + &st::menuIconManage); + } addAction({ .text = tr::lng_gift_collection_delete(tr::now), .handler = [=] { confirmDeleteCollection(id); }, diff --git a/Telegram/SourceFiles/ui/controls/sub_tabs.cpp b/Telegram/SourceFiles/ui/controls/sub_tabs.cpp index 57ea4fa452..3c3de6c30d 100644 --- a/Telegram/SourceFiles/ui/controls/sub_tabs.cpp +++ b/Telegram/SourceFiles/ui/controls/sub_tabs.cpp @@ -102,6 +102,14 @@ rpl::producer SubTabs::contextMenuRequests() const { return _contextMenuRequests.events(); } +void SubTabs::setReorderEnabled(bool enabled) { + _reorderEnable = enabled; +} + +bool SubTabs::reorderEnabled() const { + return _reorderEnable; +} + void SubTabs::setSelected(int index) { const auto was = (_selected >= 0); const auto now = (index >= 0); @@ -170,17 +178,19 @@ bool SubTabs::eventHook(QEvent *e) { void SubTabs::mouseMoveEvent(QMouseEvent *e) { const auto mousex = e->pos().x(); const auto drag = QApplication::startDragDistance(); - if (_dragx > 0) { - _scrollAnimation.stop(); - _scroll = std::clamp( - _dragscroll + _dragx - mousex, - 0., - _scrollMax * 1.); - update(); - return; - } else if (_pressx > 0 && std::abs(_pressx - mousex) > drag) { - _dragx = _pressx; - _dragscroll = _scroll; + if (!_reorderEnable) { + if (_dragx > 0) { + _scrollAnimation.stop(); + _scroll = std::clamp( + _dragscroll + _dragx - mousex, + 0., + _scrollMax * 1.); + update(); + return; + } else if (_pressx > 0 && std::abs(_pressx - mousex) > drag) { + _dragx = _pressx; + _dragscroll = _scroll; + } } auto selected = -1; const auto position = e->pos() + scroll(); @@ -194,6 +204,10 @@ void SubTabs::mouseMoveEvent(QMouseEvent *e) { } void SubTabs::wheelEvent(QWheelEvent *e) { + if (_reorderEnable) { + e->ignore(); + return; + } const auto delta = ScrollDeltaF(e); const auto phase = e->phase(); diff --git a/Telegram/SourceFiles/ui/controls/sub_tabs.h b/Telegram/SourceFiles/ui/controls/sub_tabs.h index 18cfe7e09b..d217111c85 100644 --- a/Telegram/SourceFiles/ui/controls/sub_tabs.h +++ b/Telegram/SourceFiles/ui/controls/sub_tabs.h @@ -47,6 +47,9 @@ public: void setActiveTab(const QString &id); + void setReorderEnabled(bool enabled); + [[nodiscard]] bool reorderEnabled() const; + [[nodiscard]] rpl::producer activated() const; [[nodiscard]] rpl::producer contextMenuRequests() const; @@ -89,6 +92,7 @@ private: int _pressed = -1; int _active = -1; bool _centered = false; + bool _reorderEnable = false; };