Deprecate QContextMenuEvent and QMouseEvent ctors without globalPos
As with QHoverEvent, it's better to require globalPos rather than "initialized to QCursor::pos(), which may not be appropriate" as the docs have pointed out for many years now. This removes the remaining calls to QCursor::pos() in event constructors. Task-number: QTBUG-52430 Task-number: QTBUG-69433 Task-number: QTBUG-100324 Change-Id: I076dae56f37abaad7085cc95dddee453a80a45f3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
a300c3810c
commit
6b2c9b81af
@ -691,7 +691,10 @@ bool QSinglePointEvent::isEndEvent() const
|
||||
QCursor::pos()
|
||||
*/
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 4)
|
||||
/*!
|
||||
\deprecated [6.4] Use another constructor instead (global position is required).
|
||||
|
||||
Constructs a mouse event object originating from \a device.
|
||||
|
||||
The \a type parameter must be one of QEvent::MouseButtonPress,
|
||||
@ -722,6 +725,7 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton but
|
||||
button, buttons, modifiers)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
Constructs a mouse event object originating from \a device.
|
||||
@ -2014,7 +2018,11 @@ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPo
|
||||
QContextMenuEvent::~QContextMenuEvent()
|
||||
{
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 4)
|
||||
/*!
|
||||
\deprecated [6.4] Use the other constructor instead (global position is required).
|
||||
|
||||
Constructs a context menu event object with the accept parameter
|
||||
flag set to false.
|
||||
|
||||
@ -2035,6 +2043,7 @@ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
|
||||
m_globalPos = QCursor::pos();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\fn const QPoint &QContextMenuEvent::pos() const
|
||||
|
@ -231,9 +231,12 @@ class Q_GUI_EXPORT QMouseEvent : public QSinglePointEvent
|
||||
{
|
||||
Q_EVENT_DISABLE_COPY(QMouseEvent);
|
||||
public:
|
||||
#if QT_DEPRECATED_SINCE(6, 4)
|
||||
QT_DEPRECATED_VERSION_X_6_4("Use another constructor")
|
||||
QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
|
||||
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
|
||||
const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
|
||||
#endif
|
||||
QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
|
||||
Qt::MouseButton button, Qt::MouseButtons buttons,
|
||||
Qt::KeyboardModifiers modifiers,
|
||||
@ -669,7 +672,10 @@ public:
|
||||
|
||||
QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
|
||||
Qt::KeyboardModifiers modifiers = Qt::NoModifier);
|
||||
#if QT_DEPRECATED_SINCE(6, 4)
|
||||
QT_DEPRECATED_VERSION_X_6_4("Use the other constructor")
|
||||
QContextMenuEvent(Reason reason, const QPoint &pos);
|
||||
#endif
|
||||
~QContextMenuEvent();
|
||||
|
||||
QContextMenuEvent *clone() const override { return new QContextMenuEvent(*this); }
|
||||
|
@ -333,7 +333,7 @@ static bool openContextMenu(QFileDialog &fd)
|
||||
MenuCloser closer(&fd);
|
||||
QObject::connect(&timer, &QTimer::timeout, &closer, &MenuCloser::close);
|
||||
timer.start();
|
||||
QContextMenuEvent cme(QContextMenuEvent::Mouse, QPoint(10, 10));
|
||||
QContextMenuEvent cme(QContextMenuEvent::Mouse, QPoint(10, 10), list->viewport()->mapToGlobal(QPoint(10, 10)));
|
||||
qApp->sendEvent(list->viewport(), &cme); // blocks until menu is closed again.
|
||||
return true;
|
||||
}
|
||||
|
@ -5362,8 +5362,9 @@ void tst_QGraphicsItem::deleteItemInEventHandlers()
|
||||
|
||||
#ifndef QT_NO_CONTEXTMENU
|
||||
if (!HarakiriItem::dead) {
|
||||
QContextMenuEvent event(QContextMenuEvent::Other,
|
||||
view.mapFromScene(item->scenePos()));
|
||||
auto viewPos = view.mapFromScene(item->scenePos());
|
||||
QContextMenuEvent event(QContextMenuEvent::Other, viewPos,
|
||||
view.mapToGlobal(viewPos));
|
||||
QCoreApplication::sendEvent(view.viewport(), &event);
|
||||
}
|
||||
#endif // QT_NO_CONTEXTMENU
|
||||
|
@ -4960,6 +4960,7 @@ void tst_QGraphicsScene::taskQTBUG_85088_previewTextfailWhenLostFocus()
|
||||
|
||||
// focusItem will lose focus
|
||||
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPointF(0, 0),
|
||||
view.viewport()->mapToGlobal(QPointF()),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(view.viewport(), &pressEvent);
|
||||
|
||||
|
@ -743,8 +743,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
|
||||
int verticalScrollBarValue = view.verticalScrollBar()->value();
|
||||
{
|
||||
// Press
|
||||
QMouseEvent event(QEvent::MouseButtonPress,
|
||||
view.viewport()->rect().center(),
|
||||
auto pos = view.viewport()->rect().center();
|
||||
QMouseEvent event(QEvent::MouseButtonPress, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -760,8 +761,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
|
||||
#endif
|
||||
{
|
||||
// Move
|
||||
QMouseEvent event(QEvent::MouseMove,
|
||||
view.viewport()->rect().center() + QPoint(10, 0),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(10, 0);
|
||||
QMouseEvent event(QEvent::MouseMove, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -772,8 +774,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
|
||||
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue);
|
||||
{
|
||||
// Move
|
||||
QMouseEvent event(QEvent::MouseMove,
|
||||
view.viewport()->rect().center() + QPoint(10, 10),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(10, 10);
|
||||
QMouseEvent event(QEvent::MouseMove, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -786,8 +789,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
|
||||
|
||||
{
|
||||
// Release
|
||||
QMouseEvent event(QEvent::MouseButtonRelease,
|
||||
view.viewport()->rect().center() + QPoint(10, 10),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(10, 10);
|
||||
QMouseEvent event(QEvent::MouseButtonRelease, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -808,15 +812,17 @@ void tst_QGraphicsView::dragMode_scrollHand()
|
||||
// Check that a click will still unselect the item.
|
||||
{
|
||||
// Press
|
||||
QMouseEvent event(QEvent::MouseButtonPress,
|
||||
view.viewport()->rect().center() + QPoint(10, 10),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(10, 10);
|
||||
QMouseEvent event(QEvent::MouseButtonPress, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
}
|
||||
{
|
||||
// Release
|
||||
QMouseEvent event(QEvent::MouseButtonRelease,
|
||||
view.viewport()->rect().center() + QPoint(10, 10),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(10, 10);
|
||||
QMouseEvent event(QEvent::MouseButtonRelease, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
}
|
||||
@ -865,8 +871,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
|
||||
int verticalScrollBarValue = view.verticalScrollBar()->value();
|
||||
{
|
||||
// Press
|
||||
QMouseEvent event(QEvent::MouseButtonPress,
|
||||
view.viewport()->rect().center(),
|
||||
auto pos = view.viewport()->rect().center();
|
||||
QMouseEvent event(QEvent::MouseButtonPress, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -880,8 +887,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
|
||||
|
||||
{
|
||||
// Move
|
||||
QMouseEvent event(QEvent::MouseMove,
|
||||
view.viewport()->rect().center() + QPoint(100, 0),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(100, 0);
|
||||
QMouseEvent event(QEvent::MouseMove, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -895,8 +903,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
|
||||
|
||||
{
|
||||
// Move
|
||||
QMouseEvent event(QEvent::MouseMove,
|
||||
view.viewport()->rect().center() + QPoint(100, 100),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(100, 100);
|
||||
QMouseEvent event(QEvent::MouseMove, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -907,8 +916,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
|
||||
|
||||
{
|
||||
// Release
|
||||
QMouseEvent event(QEvent::MouseButtonRelease,
|
||||
view.viewport()->rect().center() + QPoint(100, 100),
|
||||
auto pos = view.viewport()->rect().center() + QPoint(100, 100);
|
||||
QMouseEvent event(QEvent::MouseButtonRelease, pos,
|
||||
view.viewport()->mapToGlobal(pos),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
event.setAccepted(true);
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
@ -3295,7 +3305,8 @@ void tst_QGraphicsView::task186827_deleteReplayedItem()
|
||||
|
||||
QCOMPARE(view.mouseMoves, 0);
|
||||
{
|
||||
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, {}, {});
|
||||
auto pos = view.mapFromScene(25, 25);
|
||||
QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), Qt::NoButton, {}, {});
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
}
|
||||
QCOMPARE(view.mouseMoves, 1);
|
||||
@ -3303,7 +3314,8 @@ void tst_QGraphicsView::task186827_deleteReplayedItem()
|
||||
QTRY_COMPARE(view.mouseMoves, 1);
|
||||
QTest::qWait(25);
|
||||
{
|
||||
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, {}, {});
|
||||
auto pos = view.mapFromScene(25, 25);
|
||||
QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), Qt::NoButton, {}, {});
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
}
|
||||
QCOMPARE(view.mouseMoves, 2);
|
||||
@ -3349,8 +3361,10 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging()
|
||||
// Enable and do a drag
|
||||
{
|
||||
view.setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
QMouseEvent press(QEvent::MouseButtonPress, origPos, Qt::LeftButton, {}, {});
|
||||
QMouseEvent move(QEvent::MouseMove, step1Pos, Qt::LeftButton, {}, {});
|
||||
QMouseEvent press(QEvent::MouseButtonPress, origPos,
|
||||
view.viewport()->mapToGlobal(origPos), Qt::LeftButton, {}, {});
|
||||
QMouseEvent move(QEvent::MouseMove, step1Pos,
|
||||
view.viewport()->mapToGlobal(step1Pos), Qt::LeftButton, {}, {});
|
||||
QApplication::sendEvent(view.viewport(), &press);
|
||||
QApplication::sendEvent(view.viewport(), &move);
|
||||
}
|
||||
@ -3358,7 +3372,8 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging()
|
||||
// unset drag and release mouse, inverse order
|
||||
{
|
||||
view.setDragMode(QGraphicsView::NoDrag);
|
||||
QMouseEvent release(QEvent::MouseButtonRelease, step1Pos, Qt::LeftButton, {}, {});
|
||||
QMouseEvent release(QEvent::MouseButtonRelease, step1Pos,
|
||||
view.viewport()->mapToGlobal(step1Pos), Qt::LeftButton, {}, {});
|
||||
QApplication::sendEvent(view.viewport(), &release);
|
||||
}
|
||||
|
||||
@ -3367,7 +3382,8 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging()
|
||||
// reset drag, and move mouse without holding button down.
|
||||
{
|
||||
view.setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
QMouseEvent move(QEvent::MouseMove, step2Pos, Qt::LeftButton, {}, {});
|
||||
QMouseEvent move(QEvent::MouseMove, step2Pos,
|
||||
view.viewport()->mapToGlobal(step2Pos), Qt::LeftButton, {}, {});
|
||||
QApplication::sendEvent(view.viewport(), &move);
|
||||
}
|
||||
|
||||
@ -3871,8 +3887,9 @@ void tst_QGraphicsView::mouseTracking2()
|
||||
|
||||
EventSpy spy(&scene, QEvent::GraphicsSceneMouseMove);
|
||||
QCOMPARE(spy.count(), 0);
|
||||
QMouseEvent event(QEvent::MouseMove,view.viewport()->rect().center(), Qt::NoButton,
|
||||
Qt::MouseButtons(Qt::NoButton), {});
|
||||
auto pos = view.viewport()->rect().center();
|
||||
QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos),
|
||||
Qt::NoButton, Qt::MouseButtons(Qt::NoButton), {});
|
||||
QApplication::sendEvent(view.viewport(), &event);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
@ -2962,11 +2962,9 @@ void tst_QGraphicsWidget::respectHFW()
|
||||
view->grabMouse();
|
||||
// move both mouse cursor and set correct event in order to emulate resize
|
||||
QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200);
|
||||
QMouseEvent e = QMouseEvent(QEvent::MouseMove,
|
||||
view->mapFromScene(60, 20),
|
||||
Qt::NoButton,
|
||||
Qt::LeftButton,
|
||||
Qt::NoModifier);
|
||||
auto pos = view->mapFromScene(60, 20);
|
||||
QMouseEvent e(QEvent::MouseMove, pos, view->mapToGlobal(pos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(view->viewport(), &e);
|
||||
view->releaseMouse();
|
||||
}
|
||||
|
@ -730,8 +730,8 @@ void tst_QAbstractItemView::persistentEditorFocus()
|
||||
const QPoint p(5, 5);
|
||||
for (QSpinBox *sb : list) {
|
||||
QTRY_VERIFY(sb->isVisible());
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonPress, p, Qt::LeftButton,
|
||||
Qt::LeftButton, Qt::NoModifier);
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonPress, p, sb->mapToGlobal(p),
|
||||
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QCoreApplication::sendEvent(sb, &mouseEvent);
|
||||
if (!QApplication::focusWidget())
|
||||
QSKIP("Some window managers don't handle focus that well");
|
||||
@ -1480,7 +1480,8 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
|
||||
// The mouse move event has to be created manually because the QTest framework does not
|
||||
// contain a function for mouse moves with buttons pressed
|
||||
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, pressPos);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, releasePos, view.viewport()->mapToGlobal(releasePos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent);
|
||||
QVERIFY(moveEventReceived);
|
||||
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, releasePos);
|
||||
@ -1503,7 +1504,8 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
|
||||
|
||||
// Repeat the same steps as above, but with a Shift-Arrow selection
|
||||
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, pressPos);
|
||||
QMouseEvent moveEvent2(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QMouseEvent moveEvent2(QEvent::MouseMove, releasePos, view.viewport()->mapToGlobal(releasePos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
moveEventReceived = qApp->notify(view.viewport(), &moveEvent2);
|
||||
QVERIFY(moveEventReceived);
|
||||
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, releasePos);
|
||||
@ -1553,7 +1555,8 @@ void tst_QAbstractItemView::ctrlRubberbandSelection()
|
||||
QPoint pressPos = view.visualRect(index1).topLeft() - QPoint(1, 1);
|
||||
QPoint releasePos = view.visualRect(index2).bottomRight() + QPoint(1, 1);
|
||||
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pressPos);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, releasePos, view.viewport()->mapToGlobal(releasePos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent);
|
||||
QVERIFY(moveEventReceived);
|
||||
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, releasePos);
|
||||
@ -2658,8 +2661,8 @@ void tst_QAbstractItemView::dragSelectAfterNewPress()
|
||||
const QPoint releasePos = view.visualRect(index5).center();
|
||||
// The mouse move event has to be created manually because the QTest framework does not
|
||||
// contain a function for mouse moves with buttons pressed
|
||||
QMouseEvent moveEvent2(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton,
|
||||
Qt::ShiftModifier);
|
||||
QMouseEvent moveEvent2(QEvent::MouseMove, releasePos, view.viewport()->mapToGlobal(releasePos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::ShiftModifier);
|
||||
const bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent2);
|
||||
QVERIFY(moveEventReceived);
|
||||
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, releasePos);
|
||||
@ -2755,7 +2758,7 @@ void tst_QAbstractItemView::dragWithSecondClick()
|
||||
const QPoint dragTo = view->visualRect(index1).center()
|
||||
+ QPoint(2 * QApplication::startDragDistance(),
|
||||
2 * QApplication::startDragDistance());
|
||||
QMouseEvent mouseMoveEvent(QEvent::MouseMove, dragTo,
|
||||
QMouseEvent mouseMoveEvent(QEvent::MouseMove, dragTo, view->viewport()->mapToGlobal(dragTo),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QVERIFY(QApplication::sendEvent(view->viewport(), &mouseMoveEvent));
|
||||
// twice since the view will first enter dragging state, then start the drag
|
||||
@ -3066,7 +3069,8 @@ void tst_QAbstractItemView::mouseSelection()
|
||||
break;
|
||||
case SelectionEvent::Move: {
|
||||
QMouseEvent mouseMoveEvent(QEvent::MouseMove, targetPoint,
|
||||
Qt::NoButton, buttonDown, event.keyboardModifiers);
|
||||
view->viewport()->mapToGlobal(targetPoint),
|
||||
Qt::NoButton, buttonDown, event.keyboardModifiers);
|
||||
QApplication::sendEvent(view->viewport(), &mouseMoveEvent);
|
||||
}
|
||||
break;
|
||||
@ -3315,7 +3319,8 @@ void tst_QAbstractItemView::selectionAutoScrolling()
|
||||
}
|
||||
|
||||
QTest::mousePress(listview.viewport(), Qt::LeftButton, Qt::NoModifier, pressPoint);
|
||||
QMouseEvent mmEvent(QEvent::MouseMove, dragPoint, Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QMouseEvent mmEvent(QEvent::MouseMove, dragPoint, listview.viewport()->mapToGlobal(dragPoint),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(listview.viewport(), &mmEvent); // QTest::mouseMove is useless
|
||||
|
||||
// check that we scrolled to the end
|
||||
|
@ -1245,7 +1245,7 @@ void tst_QItemDelegate::editorEvent()
|
||||
QPoint pos = inCheck ? qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0) : QPoint(200,200);
|
||||
|
||||
QEvent *event = new QMouseEvent((QEvent::Type)type,
|
||||
pos,
|
||||
pos, pos,
|
||||
(Qt::MouseButton)button,
|
||||
(Qt::MouseButton)button,
|
||||
Qt::NoModifier);
|
||||
|
@ -4355,15 +4355,18 @@ void tst_QTableView::task191545_dragSelectRows()
|
||||
QHeaderView *vHeader = table.verticalHeader();
|
||||
QWidget *vHeaderVp = vHeader->viewport();
|
||||
QPoint rowPos(cellRect.center());
|
||||
QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, rowPos, vHeaderVp->mapToGlobal(rowPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(vHeaderVp, &rowPressEvent);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
rowPos.setY(rowPos.y() + cellRect.height());
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, rowPos, rowPos, vHeaderVp->mapToGlobal(rowPos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(vHeaderVp, &moveEvent);
|
||||
}
|
||||
QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, vHeaderVp->mapToGlobal(rowPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(vHeaderVp, &rowReleaseEvent);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
@ -4377,15 +4380,18 @@ void tst_QTableView::task191545_dragSelectRows()
|
||||
QHeaderView *hHeader = table.horizontalHeader();
|
||||
QWidget *hHeaderVp = hHeader->viewport();
|
||||
QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5);
|
||||
QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, hHeaderVp->mapToGlobal(colPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(hHeaderVp, &colPressEvent);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
colPos.setX(colPos.x() + cellRect.width());
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, colPos, hHeaderVp->mapToGlobal(colPos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(hHeaderVp, &moveEvent);
|
||||
}
|
||||
QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, hHeaderVp->mapToGlobal(colPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(hHeaderVp, &colReleaseEvent);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
@ -4398,16 +4404,19 @@ void tst_QTableView::task191545_dragSelectRows()
|
||||
QRect cellRect = table.visualRect(model.index(2, 2));
|
||||
QWidget *tableVp = table.viewport();
|
||||
QPoint cellPos = cellRect.center();
|
||||
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, tableVp->mapToGlobal(cellPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(tableVp, &cellPressEvent);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
cellPos.setX(cellPos.x() + cellRect.width());
|
||||
cellPos.setY(cellPos.y() + cellRect.height());
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, tableVp->mapToGlobal(cellPos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(tableVp, &moveEvent);
|
||||
}
|
||||
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, tableVp->mapToGlobal(cellPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
@ -4422,16 +4431,19 @@ void tst_QTableView::task191545_dragSelectRows()
|
||||
QRect cellRect = table.visualRect(model.index(3, 3));
|
||||
QWidget *tableVp = table.viewport();
|
||||
QPoint cellPos = cellRect.center();
|
||||
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, tableVp->mapToGlobal(cellPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(tableVp, &cellPressEvent);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
cellPos.setX(cellPos.x() + cellRect.width());
|
||||
cellPos.setY(cellPos.y() + cellRect.height());
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, tableVp->mapToGlobal(cellPos),
|
||||
Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(tableVp, &moveEvent);
|
||||
}
|
||||
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, tableVp->mapToGlobal(cellPos),
|
||||
Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
|
||||
QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
|
||||
|
||||
QTest::qWait(200);
|
||||
@ -4795,7 +4807,8 @@ public:
|
||||
{
|
||||
return QTableView::selectionCommand(index, shiftPressed ? &mouseEvent : nullptr);
|
||||
}
|
||||
QMouseEvent mouseEvent = QMouseEvent(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::ShiftModifier);
|
||||
QMouseEvent mouseEvent = QMouseEvent(QEvent::MouseButtonPress, QPointF(), QPointF(),
|
||||
Qt::LeftButton, Qt::LeftButton, Qt::ShiftModifier);
|
||||
bool shiftPressed = false;
|
||||
};
|
||||
|
||||
|
@ -1865,7 +1865,7 @@ void tst_QApplication::focusMouseClick()
|
||||
// front most widget has Qt::TabFocus, parent widget accepts clicks as well
|
||||
// now send a mouse button press event and check what happens with the focus
|
||||
// it should be given to the parent widget
|
||||
QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), w.mapToGlobal(QPointF()), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QSpontaneKeyEvent::setSpontaneous(&ev);
|
||||
QVERIFY(ev.spontaneous());
|
||||
qApp->notify(&w2, &ev);
|
||||
|
@ -4231,7 +4231,8 @@ void tst_QWidget::testDeletionInEventHandlers()
|
||||
w = new Widget;
|
||||
w->show();
|
||||
w->deleteThis = true;
|
||||
QMouseEvent me(QEvent::MouseButtonRelease, QPoint(1, 1), Qt::LeftButton, Qt::LeftButton, Qt::KeyboardModifiers());
|
||||
QMouseEvent me(QEvent::MouseButtonRelease, QPoint(1, 1), w->mapToGlobal(QPoint(1, 1)),
|
||||
Qt::LeftButton, Qt::LeftButton, Qt::KeyboardModifiers());
|
||||
qApp->notify(w, &me);
|
||||
QVERIFY(w.isNull());
|
||||
delete w;
|
||||
@ -4270,7 +4271,8 @@ void tst_QWidget::testDeletionInEventHandlers()
|
||||
w->setMouseTracking(true);
|
||||
w->show();
|
||||
w->deleteThis = true;
|
||||
QMouseEvent me2 = QMouseEvent(QEvent::MouseMove, QPoint(0, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QMouseEvent me2 = QMouseEvent(QEvent::MouseMove, QPoint(0, 0), w->mapToGlobal(QPoint(0, 0)),
|
||||
Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(w, &me2);
|
||||
QVERIFY(w.isNull());
|
||||
delete w;
|
||||
|
@ -619,9 +619,9 @@ void tst_QAbstractButton::mouseReleased() // QTBUG-53244
|
||||
|
||||
QPointF posOutOfWidget = QPointF(30, 30);
|
||||
QMouseEvent me(QEvent::MouseMove,
|
||||
posOutOfWidget, Qt::NoButton,
|
||||
Qt::MouseButtons(Qt::LeftButton),
|
||||
Qt::NoModifier); // mouse press and move
|
||||
posOutOfWidget, button.mapToGlobal(posOutOfWidget),
|
||||
Qt::NoButton, Qt::MouseButtons(Qt::LeftButton),
|
||||
Qt::NoModifier); // mouse press and move
|
||||
|
||||
qApp->sendEvent(&button, &me);
|
||||
// should emit released signal once mouse is dragging out of boundary
|
||||
|
@ -100,7 +100,7 @@ void tst_QDial::sliderMoved()
|
||||
|
||||
QPoint init(dial.width()/4, dial.height()/2);
|
||||
|
||||
QMouseEvent pressevent(QEvent::MouseButtonPress, init,
|
||||
QMouseEvent pressevent(QEvent::MouseButtonPress, init, dial.mapToGlobal(init),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
qApp->sendEvent(&dial, &pressevent);
|
||||
|
||||
@ -110,7 +110,7 @@ void tst_QDial::sliderMoved()
|
||||
|
||||
{ //move on top of the slider
|
||||
init = QPoint(dial.width()/2, dial.height()/4);
|
||||
QMouseEvent moveevent(QEvent::MouseMove, init,
|
||||
QMouseEvent moveevent(QEvent::MouseMove, init, dial.mapToGlobal(init),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
qApp->sendEvent(&dial, &moveevent);
|
||||
QCOMPARE( sliderspy.count(), 1);
|
||||
@ -120,14 +120,14 @@ void tst_QDial::sliderMoved()
|
||||
|
||||
{ //move on the right of the slider
|
||||
init = QPoint(dial.width()*3/4, dial.height()/2);
|
||||
QMouseEvent moveevent(QEvent::MouseMove, init,
|
||||
QMouseEvent moveevent(QEvent::MouseMove, init, dial.mapToGlobal(init),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
qApp->sendEvent(&dial, &moveevent);
|
||||
QCOMPARE( sliderspy.count(), 2);
|
||||
QCOMPARE( valuespy.count(), 0);
|
||||
}
|
||||
|
||||
QMouseEvent releaseevent(QEvent::MouseButtonRelease, init,
|
||||
QMouseEvent releaseevent(QEvent::MouseButtonRelease, init, dial.mapToGlobal(init),
|
||||
Qt::LeftButton, Qt::LeftButton, {});
|
||||
qApp->sendEvent(&dial, &releaseevent);
|
||||
QCOMPARE( valuespy.count(), 1); // valuechanged signal should be called at this point
|
||||
|
@ -614,7 +614,8 @@ void tst_QGroupBox::task_QTBUG_15519_propagateMouseEvents()
|
||||
void tst_QGroupBox::sendMouseMoveEvent(QWidget *widget, const QPoint &localPos)
|
||||
{
|
||||
// Send a MouseMove event without actually moving the pointer
|
||||
QMouseEvent event(QEvent::MouseMove, localPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QMouseEvent event(QEvent::MouseMove, localPos, widget->mapToGlobal(localPos),
|
||||
Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(widget, &event);
|
||||
}
|
||||
|
||||
|
@ -575,7 +575,8 @@ void tst_QLabel::taskQTBUG_7902_contextMenuCrash()
|
||||
w->connect(&ti, SIGNAL(timeout()), w, SLOT(deleteLater()));
|
||||
ti.start(300);
|
||||
|
||||
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center());
|
||||
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center(),
|
||||
w->mapToGlobal(w->rect().center()));
|
||||
qApp->postEvent(w, cme);
|
||||
|
||||
QTest::qWait(350);
|
||||
|
@ -4047,7 +4047,8 @@ void tst_QLineEdit::taskQTBUG_7902_contextMenuCrash()
|
||||
w->connect(&ti, SIGNAL(timeout()), w, SLOT(deleteLater()));
|
||||
ti.start(200);
|
||||
|
||||
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center());
|
||||
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center(),
|
||||
w->mapToGlobal(w->rect().center()));
|
||||
qApp->postEvent(w, cme);
|
||||
|
||||
QTest::qWait(300);
|
||||
|
@ -68,13 +68,13 @@ public:
|
||||
}
|
||||
void timerEvent(QTimerEvent*) override
|
||||
{
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseButtonPress, QPoint(6, 7), Qt::LeftButton, {}, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(7, 8), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(27, 23), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(30, 27), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(162, 109), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(10, 4), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseButtonRelease, QPoint(9, 4), Qt::LeftButton, {}, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseButtonPress, QPoint(6, 7), m_tb->mapToGlobal(QPoint(6, 7)), Qt::LeftButton, {}, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(7, 8), m_tb->mapToGlobal(QPoint(7, 8)), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(27, 23), m_tb->mapToGlobal(QPoint(27, 23)), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(30, 27), m_tb->mapToGlobal(QPoint(30, 27)), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(162, 109), m_tb->mapToGlobal(QPoint(162, 109)), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseMove, QPoint(10, 4), m_tb->mapToGlobal(QPoint(10, 4)), Qt::LeftButton, Qt::LeftButton, {}));
|
||||
QCoreApplication::postEvent(m_tb, new QMouseEvent(QEvent::MouseButtonRelease, QPoint(9, 4), m_tb->mapToGlobal(QPoint(6, 7)), Qt::LeftButton, {}, {}));
|
||||
}
|
||||
};
|
||||
|
||||
@ -92,8 +92,8 @@ public:
|
||||
|
||||
void timerEvent(QTimerEvent*) override
|
||||
{
|
||||
QCoreApplication::postEvent(m_w, new QMouseEvent(QEvent::MouseButtonPress, QPoint(230, 370), Qt::LeftButton, {}, {}));
|
||||
QCoreApplication::postEvent(m_w, new QMouseEvent(QEvent::MouseButtonRelease, QPoint(230, 370), Qt::LeftButton, {}, {}));
|
||||
QCoreApplication::postEvent(m_w, new QMouseEvent(QEvent::MouseButtonPress, QPoint(230, 370), m_w->mapToGlobal(QPoint(230, 370)), Qt::LeftButton, {}, {}));
|
||||
QCoreApplication::postEvent(m_w, new QMouseEvent(QEvent::MouseButtonRelease, QPoint(230, 370), m_w->mapToGlobal(QPoint(230, 370)), Qt::LeftButton, {}, {}));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2297,7 +2297,8 @@ void tst_QTextEdit::taskQTBUG_7902_contextMenuCrash()
|
||||
w->connect(&ti, SIGNAL(timeout()), w, SLOT(deleteLater()));
|
||||
ti.start(200);
|
||||
|
||||
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center());
|
||||
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center(),
|
||||
w->viewport()->mapToGlobal(w->rect().center()));
|
||||
qApp->postEvent(w->viewport(), cme);
|
||||
|
||||
QTest::qWait(300);
|
||||
|
Loading…
Reference in New Issue
Block a user