Cancel member actions when a click becomes a drag
This commit is contained in:
1 parent
1820128f5b
commit
a7a7e4b5a1
3 files changed
+58
-6
No files matched your search
@@ -158,6 +158,16 @@ void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
|
||||
bool AccountDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) {
|
||||
Q_UNUSED(model);
|
||||
if (event->type() == QEvent::MouseMove) {
|
||||
const auto* mouse = static_cast<QMouseEvent*>(event);
|
||||
if (m_pressedIndex.isValid() && (!(mouse->buttons() & Qt::LeftButton) ||
|
||||
(mouse->pos() - m_pressedPosition).manhattanLength() >= ClickDistance)) {
|
||||
GUI_DEBUG("AccountDelegate: action cancelled row=%d action=%d distance=%d left_down=%d", m_pressedIndex.row(),
|
||||
int(m_pressedAction), (mouse->pos() - m_pressedPosition).manhattanLength(), bool(mouse->buttons() & Qt::LeftButton));
|
||||
m_pressedIndex = QPersistentModelIndex(); m_pressedAction = Action::None;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseButtonRelease &&
|
||||
event->type() != QEvent::MouseButtonDblClick) return false;
|
||||
auto* mouse = static_cast<QMouseEvent*>(event);
|
||||
@@ -172,9 +182,10 @@ bool AccountDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, cons
|
||||
if (event->type() == QEvent::MouseButtonDblClick) return action != Action::None;
|
||||
const bool handled = action != Action::None || m_pressedIndex.isValid();
|
||||
const bool activate = enabled && action != Action::None && action == m_pressedAction && m_pressedIndex == index &&
|
||||
(mouse->pos() - m_pressedPosition).manhattanLength() < 5;
|
||||
(mouse->pos() - m_pressedPosition).manhattanLength() < ClickDistance;
|
||||
m_pressedIndex = QPersistentModelIndex(); m_pressedAction = Action::None;
|
||||
if (activate) {
|
||||
GUI_DEBUG("AccountDelegate: action activated row=%d action=%d", index.row(), int(action));
|
||||
if (action == Action::Avatar) emit avatarRequested(index);
|
||||
else if (action == Action::RadioMute) emit radioMuteRequested(index);
|
||||
else if (action == Action::RadioCall) emit radioCallRequested(index);
|
||||
|
||||
Reference in new issue
Block a user