Replaced raw PopupMenu pointer with unique_qptr in FlatLabel.
This commit is contained in:
parent
8c381e6bd4
commit
92fe8b138b
2 changed files with 4 additions and 17 deletions
|
|
@ -614,11 +614,6 @@ void FlatLabel::touchEvent(QTouchEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) {
|
void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) {
|
||||||
if (_contextMenu) {
|
|
||||||
_contextMenu->deleteLater();
|
|
||||||
_contextMenu = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e->reason() == QContextMenuEvent::Mouse) {
|
if (e->reason() == QContextMenuEvent::Mouse) {
|
||||||
_lastMousePos = e->globalPos();
|
_lastMousePos = e->globalPos();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -635,7 +630,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
|
||||||
const auto fullSelection = _selectable
|
const auto fullSelection = _selectable
|
||||||
&& _text.isFullSelection(_selection);
|
&& _text.isFullSelection(_selection);
|
||||||
|
|
||||||
_contextMenu = new PopupMenu(this);
|
_contextMenu = base::make_unique_q<PopupMenu>(this);
|
||||||
|
|
||||||
if (fullSelection && !_contextCopyText.isEmpty()) {
|
if (fullSelection && !_contextCopyText.isEmpty()) {
|
||||||
_contextMenu->addAction(
|
_contextMenu->addAction(
|
||||||
|
|
@ -662,11 +657,9 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_contextMenu->actions().empty()) {
|
if (_contextMenu->empty()) {
|
||||||
delete _contextMenu;
|
|
||||||
_contextMenu = nullptr;
|
_contextMenu = nullptr;
|
||||||
} else {
|
} else {
|
||||||
connect(_contextMenu, SIGNAL(destroyed(QObject*)), this, SLOT(onContextMenuDestroy(QObject*)));
|
|
||||||
_contextMenu->popup(e->globalPos());
|
_contextMenu->popup(e->globalPos());
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
|
|
@ -688,12 +681,6 @@ void FlatLabel::onTouchSelect() {
|
||||||
dragActionStart(_touchPos, Qt::LeftButton);
|
dragActionStart(_touchPos, Qt::LeftButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatLabel::onContextMenuDestroy(QObject *obj) {
|
|
||||||
if (obj == _contextMenu) {
|
|
||||||
_contextMenu = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlatLabel::onExecuteDrag() {
|
void FlatLabel::onExecuteDrag() {
|
||||||
if (_dragAction != Dragging) return;
|
if (_dragAction != Dragging) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/unique_qptr.h"
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
#include "ui/wrap/padding_wrap.h"
|
#include "ui/wrap/padding_wrap.h"
|
||||||
#include "ui/text/text.h"
|
#include "ui/text/text.h"
|
||||||
|
|
@ -171,7 +172,6 @@ private Q_SLOTS:
|
||||||
void onCopyContextText();
|
void onCopyContextText();
|
||||||
|
|
||||||
void onTouchSelect();
|
void onTouchSelect();
|
||||||
void onContextMenuDestroy(QObject *obj);
|
|
||||||
|
|
||||||
void onExecuteDrag();
|
void onExecuteDrag();
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ private:
|
||||||
QPoint _trippleClickPoint;
|
QPoint _trippleClickPoint;
|
||||||
QTimer _trippleClickTimer;
|
QTimer _trippleClickTimer;
|
||||||
|
|
||||||
PopupMenu *_contextMenu = nullptr;
|
base::unique_qptr<PopupMenu> _contextMenu;
|
||||||
QString _contextCopyText;
|
QString _contextCopyText;
|
||||||
|
|
||||||
ClickHandlerFilter _clickHandlerFilter;
|
ClickHandlerFilter _clickHandlerFilter;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue