diff --git a/ui/widgets/labels.cpp b/ui/widgets/labels.cpp index 26ac073..ace7162 100644 --- a/ui/widgets/labels.cpp +++ b/ui/widgets/labels.cpp @@ -614,11 +614,6 @@ void FlatLabel::touchEvent(QTouchEvent *e) { } void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) { - if (_contextMenu) { - _contextMenu->deleteLater(); - _contextMenu = nullptr; - } - if (e->reason() == QContextMenuEvent::Mouse) { _lastMousePos = e->globalPos(); } else { @@ -635,7 +630,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) const auto fullSelection = _selectable && _text.isFullSelection(_selection); - _contextMenu = new PopupMenu(this); + _contextMenu = base::make_unique_q(this); if (fullSelection && !_contextCopyText.isEmpty()) { _contextMenu->addAction( @@ -662,11 +657,9 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) } } - if (_contextMenu->actions().empty()) { - delete _contextMenu; + if (_contextMenu->empty()) { _contextMenu = nullptr; } else { - connect(_contextMenu, SIGNAL(destroyed(QObject*)), this, SLOT(onContextMenuDestroy(QObject*))); _contextMenu->popup(e->globalPos()); e->accept(); } @@ -688,12 +681,6 @@ void FlatLabel::onTouchSelect() { dragActionStart(_touchPos, Qt::LeftButton); } -void FlatLabel::onContextMenuDestroy(QObject *obj) { - if (obj == _contextMenu) { - _contextMenu = nullptr; - } -} - void FlatLabel::onExecuteDrag() { if (_dragAction != Dragging) return; diff --git a/ui/widgets/labels.h b/ui/widgets/labels.h index c43bf0f..076a39e 100644 --- a/ui/widgets/labels.h +++ b/ui/widgets/labels.h @@ -6,6 +6,7 @@ // #pragma once +#include "base/unique_qptr.h" #include "ui/rp_widget.h" #include "ui/wrap/padding_wrap.h" #include "ui/text/text.h" @@ -171,7 +172,6 @@ private Q_SLOTS: void onCopyContextText(); void onTouchSelect(); - void onContextMenuDestroy(QObject *obj); void onExecuteDrag(); @@ -229,7 +229,7 @@ private: QPoint _trippleClickPoint; QTimer _trippleClickTimer; - PopupMenu *_contextMenu = nullptr; + base::unique_qptr _contextMenu; QString _contextCopyText; ClickHandlerFilter _clickHandlerFilter;