Suppress move/resize events if they are the result of call to move()/resize().
QWidget::resize() or QWidget::move() set the new size/position values and send events. The spontaneous events generated by the platform should be ignored in that case. Task-number: QTBUG-30744 Task-number: QTBUG-38768 Task-number: QTBUG-32590 Change-Id: I9c0ae38842ed76a8a88ca64fdc9bbe106b2766b7 Reviewed-by: Andy Shaw <andy.shaw@digia.com>
This commit is contained in:
parent
c3e416296a
commit
a1c5198387
@ -591,16 +591,24 @@ void QWidgetWindow::updateNormalGeometry()
|
||||
|
||||
void QWidgetWindow::handleMoveEvent(QMoveEvent *event)
|
||||
{
|
||||
// If the widget's position already matches that of the event, this is a
|
||||
// result of call to QWidget::move(), which already sends an event.
|
||||
const bool spontaneous = m_widget->geometry().topLeft() != event->pos();
|
||||
updateGeometry();
|
||||
QGuiApplication::sendSpontaneousEvent(m_widget, event);
|
||||
if (spontaneous)
|
||||
QGuiApplication::sendSpontaneousEvent(m_widget, event);
|
||||
}
|
||||
|
||||
void QWidgetWindow::handleResizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QSize oldSize = m_widget->data->crect.size();
|
||||
// If the widget's size already matches that of the event, this is a
|
||||
// result of call to QWidget::resize(), which already sends an event.
|
||||
const bool spontaneous = oldSize != event->size();
|
||||
|
||||
updateGeometry();
|
||||
QGuiApplication::sendSpontaneousEvent(m_widget, event);
|
||||
if (spontaneous)
|
||||
QGuiApplication::sendSpontaneousEvent(m_widget, event);
|
||||
|
||||
if (m_widget->d_func()->paintOnScreen()) {
|
||||
QRegion updateRegion(geometry());
|
||||
|
@ -262,6 +262,7 @@ private slots:
|
||||
void optimizedResizeMove();
|
||||
void optimizedResize_topLevel();
|
||||
void resizeEvent();
|
||||
void moveEvent();
|
||||
void task110173();
|
||||
|
||||
void testDeletionInEventHandlers();
|
||||
@ -2108,41 +2109,53 @@ void tst_QWidget::showFullScreen()
|
||||
|
||||
class ResizeWidget : public QWidget {
|
||||
public:
|
||||
ResizeWidget(QWidget *p = 0) : QWidget(p)
|
||||
ResizeWidget(QWidget *p = 0)
|
||||
: QWidget(p)
|
||||
, m_spontaneousResizeEventCount(0)
|
||||
, m_synthesizedResizeEventCount(0)
|
||||
, m_spontaneousMoveEventCount(0)
|
||||
, m_synthesizedMoveEventCount(0)
|
||||
{
|
||||
setObjectName(QLatin1String("ResizeWidget"));
|
||||
setWindowTitle(objectName());
|
||||
m_resizeEventCount = 0;
|
||||
}
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e){
|
||||
QCOMPARE(size(), e->size());
|
||||
++m_resizeEventCount;
|
||||
(e->spontaneous() ? m_spontaneousResizeEventCount : m_synthesizedResizeEventCount)++;
|
||||
}
|
||||
void moveEvent(QMoveEvent *e)
|
||||
{
|
||||
(e->spontaneous() ? m_spontaneousMoveEventCount : m_synthesizedMoveEventCount)++;
|
||||
}
|
||||
|
||||
public:
|
||||
int m_resizeEventCount;
|
||||
int m_spontaneousResizeEventCount;
|
||||
int m_synthesizedResizeEventCount;
|
||||
int m_spontaneousMoveEventCount;
|
||||
int m_synthesizedMoveEventCount;
|
||||
};
|
||||
|
||||
void tst_QWidget::resizeEvent()
|
||||
{
|
||||
QSKIP("QTBUG-30744");
|
||||
|
||||
{
|
||||
QWidget wParent;
|
||||
wParent.resize(200, 200);
|
||||
ResizeWidget wChild(&wParent);
|
||||
wParent.show();
|
||||
QTest::qWaitForWindowExposed(&wParent);
|
||||
QCOMPARE (wChild.m_resizeEventCount, 1); // initial resize event before paint
|
||||
QCOMPARE (wChild.m_synthesizedResizeEventCount, 1); // initial resize event before paint
|
||||
QCOMPARE (wChild.m_spontaneousResizeEventCount, 0);
|
||||
wParent.hide();
|
||||
QSize safeSize(640,480);
|
||||
if (wChild.size() == safeSize)
|
||||
safeSize.setWidth(639);
|
||||
wChild.resize(safeSize);
|
||||
QCOMPARE (wChild.m_resizeEventCount, 1);
|
||||
QCOMPARE (wChild.m_synthesizedResizeEventCount, 1);
|
||||
QCOMPARE (wChild.m_spontaneousResizeEventCount, 0);
|
||||
wParent.show();
|
||||
QCOMPARE (wChild.m_resizeEventCount, 2);
|
||||
QCOMPARE (wChild.m_synthesizedResizeEventCount, 2);
|
||||
QCOMPARE (wChild.m_spontaneousResizeEventCount, 0);
|
||||
}
|
||||
|
||||
{
|
||||
@ -2150,19 +2163,39 @@ void tst_QWidget::resizeEvent()
|
||||
wTopLevel.resize(200, 200);
|
||||
wTopLevel.show();
|
||||
QTest::qWaitForWindowExposed(&wTopLevel);
|
||||
QCOMPARE (wTopLevel.m_resizeEventCount, 1); // initial resize event before paint for toplevels
|
||||
const int synthesizedResizeEventCountAfterShow = wTopLevel.m_synthesizedResizeEventCount;
|
||||
QCOMPARE (synthesizedResizeEventCountAfterShow, 1); // initial resize event before paint for toplevels
|
||||
QCOMPARE (wTopLevel.m_spontaneousResizeEventCount, 0);
|
||||
wTopLevel.hide();
|
||||
QSize safeSize(640,480);
|
||||
if (wTopLevel.size() == safeSize)
|
||||
safeSize.setWidth(639);
|
||||
wTopLevel.resize(safeSize);
|
||||
QCOMPARE (wTopLevel.m_resizeEventCount, 1);
|
||||
QCOMPARE (wTopLevel.m_synthesizedResizeEventCount, synthesizedResizeEventCountAfterShow);
|
||||
QCOMPARE (wTopLevel.m_spontaneousResizeEventCount, 0);
|
||||
wTopLevel.show();
|
||||
QTest::qWaitForWindowExposed(&wTopLevel);
|
||||
QCOMPARE (wTopLevel.m_resizeEventCount, 2);
|
||||
#ifdef Q_OS_OSX
|
||||
QEXPECT_FAIL("", "QTBUG-30744", Abort);
|
||||
#endif
|
||||
QCOMPARE (wTopLevel.m_synthesizedResizeEventCount, synthesizedResizeEventCountAfterShow + 1);
|
||||
QCOMPARE (wTopLevel.m_spontaneousResizeEventCount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QWidget::moveEvent()
|
||||
{
|
||||
ResizeWidget wTopLevel;
|
||||
wTopLevel.resize(200, 200);
|
||||
centerOnScreen(&wTopLevel);
|
||||
wTopLevel.show();
|
||||
QTest::qWaitForWindowExposed(&wTopLevel);
|
||||
const int synthesizedMoveEventCountAfterShow = wTopLevel.m_synthesizedMoveEventCount;
|
||||
wTopLevel.move(wTopLevel.pos() + QPoint(20, 20));
|
||||
QTRY_COMPARE (wTopLevel.m_synthesizedMoveEventCount, synthesizedMoveEventCountAfterShow + 1);
|
||||
QCOMPARE (wTopLevel.m_spontaneousMoveEventCount, 0);
|
||||
}
|
||||
|
||||
void tst_QWidget::showMinimized()
|
||||
{
|
||||
QWidget plain;
|
||||
|
Loading…
Reference in New Issue
Block a user