summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-07-03 13:28:58 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-07-12 15:13:01 +0200
commit7d29807296cb7ccc7f3459e106d74f93a321c493 (patch)
tree04844d21a3d09b4bfe5749033537831efdd077cc /src/widgets
parent0a724ac74c5aa22a65ff0b81b762433b5d1e2002 (diff)
Finish deprecating obsolete members of QWheelEvent
In Qt 5.0, delta() and orientation() were already marked obsolete, but Widgets and tests have kept on depending on them all this time. We now start using alternative API so they can really be deprecated. All constructors except the newest one are also deprecated. The plan is for all events from pointing devices to have QPointF position() and globalPosition(), so we deprecate the other position accessors. [ChangeLog][QtGui] Obsolete constructors and accessors in QWheelEvent now have proper deprecation macros. What is left is intended to be compatible with planned changes in Qt 6. Change-Id: I26250dc90922b60a6ed20d7f65f38019da3e139e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp11
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp9
-rw-r--r--src/widgets/itemviews/qlistview.cpp10
-rw-r--r--src/widgets/kernel/qapplication.cpp14
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp9
-rw-r--r--src/widgets/widgets/qabstractscrollarea.cpp2
-rw-r--r--src/widgets/widgets/qabstractslider.cpp5
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp2
-rw-r--r--src/widgets/widgets/qcombobox.cpp5
-rw-r--r--src/widgets/widgets/qmenu.cpp4
-rw-r--r--src/widgets/widgets/qscrollbar.cpp10
-rw-r--r--src/widgets/widgets/qtabbar.cpp4
12 files changed, 55 insertions, 30 deletions
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index f1b01fbb4d..dec9e7a268 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
@@ -1293,8 +1293,15 @@ void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
pos = d->mapToReceiver(pos, receiver);
// Send mouse event.
- QWheelEvent wheelEvent(pos.toPoint(), event->screenPos(), event->delta(),
- event->buttons(), event->modifiers(), event->orientation());
+ QPoint angleDelta;
+ if (event->orientation() == Qt::Horizontal)
+ angleDelta.setX(event->delta());
+ else
+ angleDelta.setY(event->delta());
+ // pixelDelta, inverted, scrollPhase and source from the original QWheelEvent
+ // were not preserved in the QGraphicsSceneWheelEvent unfortunately
+ QWheelEvent wheelEvent(pos, event->screenPos(), QPoint(), angleDelta,
+ event->buttons(), event->modifiers(), Qt::NoScrollPhase, false);
QPointer<QWidget> focusWidget = d->widget->focusWidget();
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
qt_sendSpontaneousEvent(receiver, &wheelEvent);
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 3ec9668cde..d5919eb55f 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -3426,12 +3426,13 @@ void QGraphicsView::wheelEvent(QWheelEvent *event)
QGraphicsSceneWheelEvent wheelEvent(QEvent::GraphicsSceneWheel);
wheelEvent.setWidget(viewport());
- wheelEvent.setScenePos(mapToScene(event->pos()));
- wheelEvent.setScreenPos(event->globalPos());
+ wheelEvent.setScenePos(mapToScene(event->position().toPoint()));
+ wheelEvent.setScreenPos(event->globalPosition().toPoint());
wheelEvent.setButtons(event->buttons());
wheelEvent.setModifiers(event->modifiers());
- wheelEvent.setDelta(event->delta());
- wheelEvent.setOrientation(event->orientation());
+ const bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
+ wheelEvent.setDelta(horizontal ? event->angleDelta().x() : event->angleDelta().y());
+ wheelEvent.setOrientation(horizontal ? Qt::Horizontal : Qt::Vertical);
wheelEvent.setAccepted(false);
QCoreApplication::sendEvent(d->scene, &wheelEvent);
event->setAccepted(wheelEvent.isAccepted());
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 25facd1484..0415dc4e56 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -810,14 +810,14 @@ void QListView::mouseReleaseEvent(QMouseEvent *e)
void QListView::wheelEvent(QWheelEvent *e)
{
Q_D(QListView);
- if (e->orientation() == Qt::Vertical) {
+ if (qAbs(e->angleDelta().y()) > qAbs(e->angleDelta().x())) {
if (e->angleDelta().x() == 0
- && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap))
- && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) {
+ && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap))
+ && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) {
QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x());
QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x());
- QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(),
- Qt::Horizontal, e->buttons(), e->modifiers(), e->phase(), e->source(), e->inverted());
+ QWheelEvent hwe(e->position(), e->globalPosition(), pixelDelta, angleDelta,
+ e->buttons(), e->modifiers(), e->phase(), e->inverted(), e->source());
if (e->spontaneous())
qt_sendSpontaneousEvent(d->hbar, &hwe);
else
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index c922aecceb..7feb18e839 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -3240,13 +3240,18 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
if (spontaneous && phase == Qt::ScrollBegin)
QApplicationPrivate::wheel_widget = nullptr;
- const QPoint &relpos = wheel->pos();
+ QPoint relpos = wheel->position().toPoint();
if (spontaneous && (phase == Qt::NoScrollPhase || phase == Qt::ScrollUpdate))
QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
+#if QT_DEPRECATED_SINCE(5, 14)
QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(),
wheel->modifiers(), phase, wheel->source(), wheel->inverted());
+#else
+ QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
+ wheel->modifiers(), phase, wheel->inverted(), wheel->source());
+#endif
we.setTimestamp(wheel->timestamp());
bool eventAccepted;
do {
@@ -3281,9 +3286,14 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
// is set. Since it accepted the wheel event previously, we continue
// sending those events until we get a ScrollEnd, which signifies
// the end of the natural scrolling sequence.
- const QPoint &relpos = QApplicationPrivate::wheel_widget->mapFromGlobal(wheel->globalPos());
+ const QPoint &relpos = QApplicationPrivate::wheel_widget->mapFromGlobal(wheel->globalPosition().toPoint());
+#if QT_DEPRECATED_SINCE(5, 0)
QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(),
wheel->modifiers(), wheel->phase(), wheel->source());
+#else
+ QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
+ wheel->modifiers(), wheel->phase(), wheel->inverted(), wheel->source());
+#endif
we.setTimestamp(wheel->timestamp());
we.spont = true;
we.ignore();
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index ba10083829..5537ff497a 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -828,14 +828,14 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
return;
QWidget *rootWidget = m_widget;
- QPoint pos = event->pos();
+ QPoint pos = event->position().toPoint();
// Use proper popup window for wheel event. Some QPA sends the wheel
// event to the root menu, so redirect it to the proper popup window.
QWidget *activePopupWidget = QApplication::activePopupWidget();
if (activePopupWidget && activePopupWidget != m_widget) {
rootWidget = activePopupWidget;
- pos = rootWidget->mapFromGlobal(event->globalPos());
+ pos = rootWidget->mapFromGlobal(event->globalPosition().toPoint());
}
// which child should have it?
@@ -846,7 +846,12 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
QPoint mapped = widget->mapFrom(rootWidget, pos);
+#if QT_DEPRECATED_SINCE(5, 0)
QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted());
+#else
+ QWheelEvent translated(QPointF(mapped), event->globalPosition(), event->pixelDelta(), event->angleDelta(),
+ event->buttons(), event->modifiers(), event->phase(), event->inverted(), event->source());
+#endif
translated.setTimestamp(event->timestamp());
QGuiApplication::forwardEvent(widget, &translated, event);
}
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp
index b9e0d3280f..8f50ec1584 100644
--- a/src/widgets/widgets/qabstractscrollarea.cpp
+++ b/src/widgets/widgets/qabstractscrollarea.cpp
@@ -1324,7 +1324,7 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e)
void QAbstractScrollArea::wheelEvent(QWheelEvent *e)
{
Q_D(QAbstractScrollArea);
- if (e->orientation() == Qt::Horizontal)
+ if (qAbs(e->angleDelta().x()) > qAbs(e->angleDelta().y()))
QCoreApplication::sendEvent(d->hbar, e);
else
QCoreApplication::sendEvent(d->vbar, e);
diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp
index 2172ebc99c..1c1aec6035 100644
--- a/src/widgets/widgets/qabstractslider.cpp
+++ b/src/widgets/widgets/qabstractslider.cpp
@@ -764,10 +764,11 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e)
{
Q_D(QAbstractSlider);
e->ignore();
- int delta = e->delta();
+ bool vertical = bool(e->angleDelta().y());
+ int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
if (e->inverted())
delta = -delta;
- if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
+ if (d->scrollByDelta(vertical ? Qt::Vertical : Qt::Horizontal, e->modifiers(), delta))
e->accept();
}
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 510b34cb18..f07b42c181 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -1418,7 +1418,7 @@ void QCalendarView::keyPressEvent(QKeyEvent *event)
#if QT_CONFIG(wheelevent)
void QCalendarView::wheelEvent(QWheelEvent *event)
{
- const int numDegrees = event->delta() / 8;
+ const int numDegrees = event->angleDelta().y() / 8;
const int numSteps = numDegrees / 15;
const QModelIndex index = currentIndex();
QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column());
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 90d55f9688..83c472b51a 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -3378,12 +3378,13 @@ void QComboBox::wheelEvent(QWheelEvent *e)
!d->viewContainer()->isVisible()) {
const int rowCount = count();
int newIndex = currentIndex();
+ int delta = e->angleDelta().y();
- if (e->delta() > 0) {
+ if (delta > 0) {
newIndex--;
while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
newIndex--;
- } else if (e->delta() < 0) {
+ } else if (delta < 0) {
newIndex++;
while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
newIndex++;
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 72653b377d..7ec33acbbf 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -2847,8 +2847,8 @@ void QMenu::paintEvent(QPaintEvent *e)
void QMenu::wheelEvent(QWheelEvent *e)
{
Q_D(QMenu);
- if (d->scroll && rect().contains(e->pos()))
- d->scrollMenu(e->delta() > 0 ?
+ if (d->scroll && rect().contains(e->position().toPoint()))
+ d->scrollMenu(e->angleDelta().y() > 0 ?
QMenuPrivate::QMenuScroller::ScrollUp : QMenuPrivate::QMenuScroller::ScrollDown);
}
#endif
diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp
index b4168268a0..08d771a27a 100644
--- a/src/widgets/widgets/qscrollbar.cpp
+++ b/src/widgets/widgets/qscrollbar.cpp
@@ -497,16 +497,14 @@ bool QScrollBar::event(QEvent *event)
void QScrollBar::wheelEvent(QWheelEvent *event)
{
event->ignore();
- int delta = event->delta();
// scrollbar is a special case - in vertical mode it reaches minimum
// value in the upper position, however QSlider's minimum value is on
- // the bottom. So we need to invert a value, but since the scrollbar is
- // inverted by default, we need to inverse the delta value for the
+ // the bottom. So we need to invert the value, but since the scrollbar is
+ // inverted by default, we need to invert the delta value only for the
// horizontal orientation.
- if (event->orientation() == Qt::Horizontal)
- delta = -delta;
+ int delta = (orientation() == Qt::Horizontal ? -event->angleDelta().x() : event->angleDelta().y());
Q_D(QScrollBar);
- if (d->scrollByDelta(event->orientation(), event->modifiers(), delta))
+ if (d->scrollByDelta(orientation(), event->modifiers(), delta))
event->accept();
if (event->phase() == Qt::ScrollBegin)
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index f6f56c12d1..1be1729684 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -2210,7 +2210,9 @@ void QTabBar::wheelEvent(QWheelEvent *event)
{
#ifndef Q_OS_MAC
Q_D(QTabBar);
- int offset = event->delta() > 0 ? -1 : 1;
+ int delta = (qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y()) ?
+ event->angleDelta().x() : event->angleDelta().y());
+ int offset = delta > 0 ? -1 : 1;
d->setCurrentNextEnabledIndex(offset);
QWidget::wheelEvent(event);
#else