diff --git a/Telegram/SourceFiles/boxes/polls.style b/Telegram/SourceFiles/boxes/polls.style index 5c1bc1d1a6..134dba97f5 100644 --- a/Telegram/SourceFiles/boxes/polls.style +++ b/Telegram/SourceFiles/boxes/polls.style @@ -120,7 +120,9 @@ historyPollAddOptionAttach: IconButton(defaultIconButton) { height: 26px; icon: icon {{ "poll/general/outline_poll_attach-22x22", historyComposeIconFg }}; iconOver: icon {{ "poll/general/outline_poll_attach-22x22", historyComposeIconFgOver }}; - rippleAreaSize: 0px; + rippleAreaPosition: point(0px, 0px); + rippleAreaSize: 26px; + ripple: defaultRippleAnimationBgOver; } pollBoxOutlinePollEmojiIcon: icon{{ "poll/general/outline_poll_emoji", activeButtonFg }}; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 303f5ceaee..29b3d81263 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -4301,41 +4301,13 @@ void HistoryInner::elementShowAddPollOption( not_null poll, FullMsgId context, QRect optionRect) { - auto widget = base::make_unique_q< - HistoryView::AddPollOptionWidget>( - this, - poll, - context, - _controller); - const auto raw = widget.get(); - _overlayHost->show( + HistoryView::ShowAddPollOptionOverlay( + *_overlayHost, + this, view, + poll, context, - std::move(widget), - rpl::merge(raw->submitted(), raw->cancelled()), - [raw](not_null v, int top) { - const auto media = v->media(); - if (!media) { - return false; - } - const auto mediaPos = v->mediaTopLeft(); - const auto innerWidth = v->innerGeometry().width() - - st::msgPadding.left() - - st::msgPadding.right(); - const auto rect = media->addOptionRect(innerWidth); - raw->updatePosition( - QPoint( - mediaPos.x() + rect.x(), - top + mediaPos.y() + rect.y()), - rect.width()); - return true; - }, - [](not_null v, bool active) { - if (const auto media = v->media()) { - media->setAddOptionActive(active); - } - }, - [raw] { raw->triggerSubmit(); }); + _controller); } void HistoryInner::elementSubmitAddPollOption(FullMsgId context) { diff --git a/Telegram/SourceFiles/history/view/history_view_add_poll_option.cpp b/Telegram/SourceFiles/history/view/history_view_add_poll_option.cpp index 4df757ccae..043bb1094c 100644 --- a/Telegram/SourceFiles/history/view/history_view_add_poll_option.cpp +++ b/Telegram/SourceFiles/history/view/history_view_add_poll_option.cpp @@ -7,6 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_add_poll_option.h" +#include "history/view/history_view_element.h" +#include "history/view/history_view_element_overlay.h" +#include "history/view/media/history_view_media.h" #include "api/api_polls.h" #include "apiwrap.h" #include "base/event_filter.h" @@ -74,9 +77,10 @@ void AddPollOptionWidget::setupField() { this, st::historyPollAddOptionEmoji); - _attach = Ui::CreateChild( + _attach = Ui::CreateChild( this, - st::historyPollAddOptionAttach); + st::historyPollAddOptionAttach, + _mediaState); _field->setMaxLength(100); @@ -170,7 +174,13 @@ void AddPollOptionWidget::setupAttach() { return; } _attach->addClickHandler([=] { - _uploader->choosePhotoOrVideo(this, _mediaState); + if (_mediaState->uploading) { + _uploader->clearMedia(_mediaState); + } else if (_mediaState->media) { + _uploader->clearMedia(_mediaState); + } else { + _uploader->choosePhotoOrVideo(this, _mediaState); + } }); _uploader->installDropToField(_field, _mediaState, false); } @@ -251,4 +261,47 @@ rpl::producer<> AddPollOptionWidget::cancelled() const { return _cancelledEvents.events(); } +void ShowAddPollOptionOverlay( + ElementOverlayHost &host, + not_null parent, + not_null view, + not_null poll, + FullMsgId context, + not_null controller) { + auto widget = base::make_unique_q( + parent, + poll, + context, + controller); + const auto raw = widget.get(); + host.show( + view, + context, + std::move(widget), + rpl::merge(raw->submitted(), raw->cancelled()), + [raw](not_null v, int top) { + const auto media = v->media(); + if (!media) { + return false; + } + const auto mediaPos = v->mediaTopLeft(); + const auto innerWidth = v->innerGeometry().width() + - st::msgPadding.left() + - st::msgPadding.right(); + const auto rect = media->addOptionRect(innerWidth); + raw->updatePosition( + QPoint( + mediaPos.x() + rect.x(), + top + mediaPos.y() + rect.y()), + rect.width()); + return true; + }, + [](not_null v, bool active) { + if (const auto media = v->media()) { + media->setAddOptionActive(active); + } + }, + [raw] { raw->triggerSubmit(); }); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_add_poll_option.h b/Telegram/SourceFiles/history/view/history_view_add_poll_option.h index 15f36f5fe2..0760dbb399 100644 --- a/Telegram/SourceFiles/history/view/history_view_add_poll_option.h +++ b/Telegram/SourceFiles/history/view/history_view_add_poll_option.h @@ -16,6 +16,7 @@ class TabbedPanel; } // namespace ChatHelpers namespace PollMediaUpload { +class PollMediaButton; struct PollMediaState; class PollMediaUploader; } // namespace PollMediaUpload @@ -35,6 +36,9 @@ class SessionController; namespace HistoryView { +class Element; +class ElementOverlayHost; + class AddPollOptionWidget final : public Ui::RpWidget { public: AddPollOptionWidget( @@ -63,7 +67,7 @@ private: Ui::InputField *_field = nullptr; Ui::IconButton *_emoji = nullptr; - Ui::IconButton *_attach = nullptr; + PollMediaUpload::PollMediaButton *_attach = nullptr; base::unique_qptr _emojiPanel; std::unique_ptr _uploader; std::shared_ptr _mediaState; @@ -73,4 +77,12 @@ private: }; +void ShowAddPollOptionOverlay( + ElementOverlayHost &host, + not_null parent, + not_null view, + not_null poll, + FullMsgId context, + not_null controller); + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_element_overlay.cpp b/Telegram/SourceFiles/history/view/history_view_element_overlay.cpp index b98248a0b6..794b5123c9 100644 --- a/Telegram/SourceFiles/history/view/history_view_element_overlay.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element_overlay.cpp @@ -59,25 +59,20 @@ void ElementOverlayHost::hide() { if (!_widget) { return; } - if (_view && _mediaStateFn) { - _mediaStateFn(_view, false); - } - _widget = nullptr; - _view = nullptr; - _context = FullMsgId(); - _positionFn = nullptr; - _mediaStateFn = nullptr; - _submitFn = nullptr; - _closeLifetime.destroy(); - if (const auto callback = _hiddenCallback) { - callback(); - } + cleanup(true); } void ElementOverlayHost::viewGone(not_null view) { if (_view != view.get()) { return; } + cleanup(false); +} + +void ElementOverlayHost::cleanup(bool notifyMedia) { + if (notifyMedia && _view && _mediaStateFn) { + _mediaStateFn(_view, false); + } _widget = nullptr; _view = nullptr; _context = FullMsgId(); @@ -103,9 +98,9 @@ void ElementOverlayHost::updatePosition() { } } -bool ElementOverlayHost::handleClickOutside(QPoint clickPos) { +void ElementOverlayHost::handleClickOutside(QPoint clickPos) { if (!_widget || !_view) { - return false; + return; } const auto top = _itemTopFn(_view); const auto viewRect = (top >= 0) @@ -113,9 +108,7 @@ bool ElementOverlayHost::handleClickOutside(QPoint clickPos) { : QRect(); if (!viewRect.contains(clickPos)) { hide(); - return true; } - return false; } void ElementOverlayHost::triggerSubmit(FullMsgId context) { diff --git a/Telegram/SourceFiles/history/view/history_view_element_overlay.h b/Telegram/SourceFiles/history/view/history_view_element_overlay.h index 4cd1252812..45555d48df 100644 --- a/Telegram/SourceFiles/history/view/history_view_element_overlay.h +++ b/Telegram/SourceFiles/history/view/history_view_element_overlay.h @@ -40,7 +40,7 @@ public: void hide(); void viewGone(not_null view); void updatePosition(); - bool handleClickOutside(QPoint clickPos); + void handleClickOutside(QPoint clickPos); void triggerSubmit(FullMsgId context); void setHiddenCallback(Fn callback); @@ -48,6 +48,8 @@ public: [[nodiscard]] FullMsgId context() const; private: + void cleanup(bool notifyMedia); + const not_null _container; const ItemTopFn _itemTopFn; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 7981e221b4..12a73d0bd0 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1904,40 +1904,13 @@ void ListWidget::elementShowAddPollOption( not_null poll, FullMsgId context, QRect optionRect) { - auto widget = base::make_unique_q( + ShowAddPollOptionOverlay( + *_overlayHost, this, + view, poll, context, controller()); - const auto raw = widget.get(); - _overlayHost->show( - view, - context, - std::move(widget), - rpl::merge(raw->submitted(), raw->cancelled()), - [raw](not_null v, int top) { - const auto media = v->media(); - if (!media) { - return false; - } - const auto mediaPos = v->mediaTopLeft(); - const auto innerWidth = v->innerGeometry().width() - - st::msgPadding.left() - - st::msgPadding.right(); - const auto rect = media->addOptionRect(innerWidth); - raw->updatePosition( - QPoint( - mediaPos.x() + rect.x(), - top + mediaPos.y() + rect.y()), - rect.width()); - return true; - }, - [](not_null v, bool active) { - if (const auto media = v->media()) { - media->setAddOptionActive(active); - } - }, - [raw] { raw->triggerSubmit(); }); } void ListWidget::elementSubmitAddPollOption(FullMsgId context) {