diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 3501df9638..ee574be6fa 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1162,8 +1162,6 @@ void OverlayWidget::clearSession() { _animationOpacities.clear(); } clearStreaming(); - delete _menu; - _menu = nullptr; setContext(v::null); _from = nullptr; _fromName = QString(); @@ -1620,7 +1618,9 @@ void OverlayWidget::onDelete() { } void OverlayWidget::onOverview() { - if (_menu) _menu->hideMenu(true); + if (_menu) { + _menu->hideMenu(true); + } update(); if (const auto overviewType = computeOverviewType()) { close(); @@ -3858,7 +3858,9 @@ void OverlayWidget::preloadData(int delta) { void OverlayWidget::mousePressEvent(QMouseEvent *e) { updateOver(e->pos()); - if (_menu || !_receiveMouse) return; + if (_menu || !_receiveMouse) { + return; + } ClickHandler::pressed(); @@ -4138,16 +4140,18 @@ void OverlayWidget::mouseReleaseEvent(QMouseEvent *e) { void OverlayWidget::contextMenuEvent(QContextMenuEvent *e) { if (e->reason() != QContextMenuEvent::Mouse || QRect(_x, _y, _w, _h).contains(e->pos())) { - if (_menu) { - _menu->deleteLater(); - _menu = nullptr; - } - _menu = new Ui::PopupMenu(this, st::mediaviewPopupMenu); + _menu = base::make_unique_q( + this, + st::mediaviewPopupMenu); updateActions(); for_const (auto &action, _actions) { _menu->addAction(action.text, this, action.member); } - connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroy(QObject*))); + _menu->setDestroyedCallback(crl::guard(this, [=] { + activateControls(); + _receiveMouse = false; + InvokeQueued(this, [=] { receiveMouse(); }); + })); _menu->popup(e->globalPos()); e->accept(); activateControls(); @@ -4309,7 +4313,9 @@ void OverlayWidget::setVisibleHook(bool visible) { assignMediaPointer(nullptr); _preloadPhotos.clear(); _preloadDocuments.clear(); - if (_menu) _menu->hideMenu(true); + if (_menu) { + _menu->hideMenu(true); + } _controlsHideTimer.cancel(); _controlsState = ControlsShown; _controlsOpacity = anim::value(1, 1); @@ -4333,15 +4339,6 @@ void OverlayWidget::setVisibleHook(bool visible) { } } -void OverlayWidget::onMenuDestroy(QObject *obj) { - if (_menu == obj) { - _menu = nullptr; - activateControls(); - } - _receiveMouse = false; - InvokeQueued(this, [=] { receiveMouse(); }); -} - void OverlayWidget::receiveMouse() { _receiveMouse = true; } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 8f9733c93b..152669a2e7 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -128,7 +128,6 @@ private slots: void onDelete(); void onOverview(); void onCopy(); - void onMenuDestroy(QObject *obj); void receiveMouse(); void onPhotoAttachedStickers(); void onDocumentAttachedStickers(); @@ -498,7 +497,7 @@ private: anim::value _controlsOpacity; bool _mousePressed = false; - Ui::PopupMenu *_menu = nullptr; + base::unique_qptr _menu; object_ptr _dropdown; base::Timer _dropdownShowTimer;