QWidgetTextControl: Suppress drag selection for OS-synthesized mouse events.
Add a convenience function to QApplicationPrivate returning the source of mouse events to be able to detect synthesized mouse events. Change-Id: I09f82ed917586cd3de8b4146fc6638d19d428163 Task-number: QTBUG-40461 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>bb10
parent
6bded1695b
commit
cf0d96f4c8
|
|
@ -53,6 +53,7 @@
|
|||
#include "qtranslator.h"
|
||||
#include "qvariant.h"
|
||||
#include "qwidget.h"
|
||||
#include "qgraphicssceneevent.h"
|
||||
#include "private/qdnd_p.h"
|
||||
#include "private/qguiapplication_p.h"
|
||||
#include "qcolormap.h"
|
||||
|
|
@ -2286,6 +2287,31 @@ QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool
|
|||
return w;
|
||||
}
|
||||
|
||||
Qt::MouseEventSource QApplicationPrivate::mouseEventSource(const QEvent *e)
|
||||
{
|
||||
switch (e->type()) {
|
||||
case QEvent::NonClientAreaMouseButtonDblClick:
|
||||
case QEvent::NonClientAreaMouseButtonPress:
|
||||
case QEvent::NonClientAreaMouseButtonRelease:
|
||||
case QEvent::NonClientAreaMouseMove:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseMove:
|
||||
return static_cast<const QMouseEvent *>(e)->source();
|
||||
#ifndef QT_NO_GRAPHICSVIEW
|
||||
case QEvent::GraphicsSceneMouseDoubleClick:
|
||||
case QEvent::GraphicsSceneMousePress:
|
||||
case QEvent::GraphicsSceneMouseRelease:
|
||||
case QEvent::GraphicsSceneMouseMove:
|
||||
return static_cast<const QGraphicsSceneMouseEvent *>(e)->source();
|
||||
#endif // !QT_NO_GRAPHICSVIEW
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Qt::MouseEventNotSynthesized;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF)
|
||||
\internal
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ public:
|
|||
static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
|
||||
static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
|
||||
bool *wrappingOccurred = 0);
|
||||
static Qt::MouseEventSource mouseEventSource(const QEvent *e);
|
||||
|
||||
#ifndef QT_NO_GRAPHICSVIEW
|
||||
// Maintain a list of all scenes to ensure font and palette propagation to
|
||||
|
|
|
|||
|
|
@ -1580,8 +1580,10 @@ void QWidgetTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton butto
|
|||
cursor.clearSelection();
|
||||
}
|
||||
}
|
||||
// Do not start selection on a mouse event synthesized from a touch event.
|
||||
if (!(button & Qt::LeftButton) ||
|
||||
!((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) {
|
||||
!((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))
|
||||
|| QApplicationPrivate::mouseEventSource(e) != Qt::MouseEventNotSynthesized) {
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
|
|
@ -1752,6 +1754,11 @@ void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton but
|
|||
{
|
||||
Q_Q(QWidgetTextControl);
|
||||
|
||||
if (QApplicationPrivate::mouseEventSource(e) != Qt::MouseEventNotSynthesized) {
|
||||
setCursorPosition(pos); // Emulate Tap to set cursor for events synthesized from touch.
|
||||
return;
|
||||
}
|
||||
|
||||
const QTextCursor oldSelection = cursor;
|
||||
if (sendMouseEventToInputContext(
|
||||
e, QEvent::MouseButtonRelease, button, pos, modifiers, buttons, globalPos)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue