From 3ce3baee61c17a733d84dc06abb3fac6de5530ff Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 30 Jan 2023 01:45:05 +0300 Subject: [PATCH] Added button to expand list of chat restrictions for sending media. --- .../boxes/peers/edit_peer_permissions_box.cpp | 208 +++++++++++++++++- 1 file changed, 202 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index b65d014adf..ef3fab48ac 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -10,8 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "data/data_channel.h" #include "data/data_chat.h" +#include "ui/effects/toggle_arrow.h" +#include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "ui/layers/generic_box.h" +#include "ui/painter.h" #include "ui/widgets/labels.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" @@ -31,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_info.h" +#include "styles/style_window.h" namespace { @@ -114,6 +118,23 @@ ChatRestrictions NegateRestrictions(ChatRestrictions value) { | Flag::SendOther); } +[[nodiscard]] std::vector MediaRestrictions() { + return std::vector{ + ChatRestriction::SendPhotos, + ChatRestriction::SendVideos, + ChatRestriction::SendVideoMessages, + ChatRestriction::SendMusic, + ChatRestriction::SendVoiceMessages, + ChatRestriction::SendFiles, + ChatRestriction::SendStickers + | ChatRestriction::SendGifs + | ChatRestriction::SendGames + | ChatRestriction::SendInline, + ChatRestriction::EmbedLinks, + ChatRestriction::SendPolls, + }; +} + auto Dependencies(ChatAdminRights) -> std::vector> { return {}; @@ -154,6 +175,117 @@ ChatRestrictions DisabledByAdminRights(not_null peer) { : Flag::ChangeInfo); } +not_null SendMediaToggle( + not_null container, + rpl::producer checkedValue, + int total, + not_null*> wrap, + Fn toggleMedia) { + class Button final : public Ui::SettingsButton { + public: + using Ui::SettingsButton::SettingsButton; + + [[nodiscard]] QRect innerToggleRect() const { + return Ui::SettingsButton::maybeToggleRect(); + } + [[nodiscard]] bool toggleClicked() const { + return _togglePressed && _toggleReleased; + } + + protected: + void mousePressEvent(QMouseEvent *event) override { + _togglePressed = Ui::SettingsButton::maybeToggleRect().contains( + event->pos()); + Ui::SettingsButton::mousePressEvent(event); + } + void mouseReleaseEvent(QMouseEvent *event) override { + _toggleReleased = Ui::SettingsButton::maybeToggleRect().contains( + event->pos()); + Ui::SettingsButton::mouseReleaseEvent(event); + } + + private: + bool _togglePressed = false; + bool _toggleReleased = false; + + }; + const auto button = container->add(object_ptr