Remove usages of deprecated APIs of QWheelEvent
- Replaced the usages of deprecated QWheelEvent::delta() and QWheelEvent::orientation() with QWheelEvent::angleDelta(). In most of the examples it is acceptable to use only the vertical component of angle delta. - Made the docs APIs to build conditionally, based on the deprecation version. Task-number: QTBUG-76491 Task-number: QTBUG-76540 Change-Id: Id4230d483f724af49e4b6349b44881c3944de2a2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
5d94aac2ba
commit
1b7ce85a60
@ -304,8 +304,8 @@
|
|||||||
\snippet threads/mandelbrot/mandelbrotwidget.cpp 12
|
\snippet threads/mandelbrot/mandelbrotwidget.cpp 12
|
||||||
|
|
||||||
The wheel event handler is reimplemented to make the mouse wheel
|
The wheel event handler is reimplemented to make the mouse wheel
|
||||||
control the zoom level. QWheelEvent::delta() returns the angle of
|
control the zoom level. QWheelEvent::angleDelta() returns the angle
|
||||||
the wheel mouse movement, in eights of a degree. For most mice,
|
of the wheel mouse movement, in eighths of a degree. For most mice,
|
||||||
one wheel step corresponds to 15 degrees. We find out how many
|
one wheel step corresponds to 15 degrees. We find out how many
|
||||||
mouse steps we have and determine the resulting zoom factor.
|
mouse steps we have and determine the resulting zoom factor.
|
||||||
For example, if we have two wheel steps in the positive direction
|
For example, if we have two wheel steps in the positive direction
|
||||||
|
@ -176,7 +176,7 @@ void MandelbrotWidget::keyPressEvent(QKeyEvent *event)
|
|||||||
//! [12]
|
//! [12]
|
||||||
void MandelbrotWidget::wheelEvent(QWheelEvent *event)
|
void MandelbrotWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
int numDegrees = event->delta() / 8;
|
int numDegrees = event->angleDelta().y() / 8;
|
||||||
double numSteps = numDegrees / 15.0f;
|
double numSteps = numDegrees / 15.0f;
|
||||||
zoom(pow(ZoomInFactor, numSteps));
|
zoom(pow(ZoomInFactor, numSteps));
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
void GraphicsView::wheelEvent(QWheelEvent *e)
|
void GraphicsView::wheelEvent(QWheelEvent *e)
|
||||||
{
|
{
|
||||||
if (e->modifiers() & Qt::ControlModifier) {
|
if (e->modifiers() & Qt::ControlModifier) {
|
||||||
if (e->delta() > 0)
|
if (e->angleDelta().y() > 0)
|
||||||
view->zoomIn(6);
|
view->zoomIn(6);
|
||||||
else
|
else
|
||||||
view->zoomOut(6);
|
view->zoomOut(6);
|
||||||
|
@ -190,7 +190,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
|
|||||||
//! [5]
|
//! [5]
|
||||||
void GraphWidget::wheelEvent(QWheelEvent *event)
|
void GraphWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
scaleView(pow((double)2, -event->delta() / 240.0));
|
scaleView(pow((double)2, -event->angleDelta().y() / 240.0));
|
||||||
}
|
}
|
||||||
//! [5]
|
//! [5]
|
||||||
#endif
|
#endif
|
||||||
|
@ -260,7 +260,7 @@ void XFormView::timerEvent(QTimerEvent *e)
|
|||||||
#if QT_CONFIG(wheelevent)
|
#if QT_CONFIG(wheelevent)
|
||||||
void XFormView::wheelEvent(QWheelEvent *e)
|
void XFormView::wheelEvent(QWheelEvent *e)
|
||||||
{
|
{
|
||||||
m_scale += e->delta() / qreal(600);
|
m_scale += e->angleDelta().y() / qreal(600);
|
||||||
m_scale = qMax(qreal(0.1), qMin(qreal(4), m_scale));
|
m_scale = qMax(qreal(0.1), qMin(qreal(4), m_scale));
|
||||||
emit scaleChanged(int(m_scale*1000));
|
emit scaleChanged(int(m_scale*1000));
|
||||||
}
|
}
|
||||||
|
@ -93,15 +93,16 @@ void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e)
|
|||||||
void ButtonTester::wheelEvent (QWheelEvent *e)
|
void ButtonTester::wheelEvent (QWheelEvent *e)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
if (e->delta() > 0) {
|
const bool vertical = qAbs(e->angleDelta().y()) >= qAbs(e->angleDelta().x());
|
||||||
|
const int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
|
||||||
if (e->orientation() == Qt::Vertical) {
|
if (delta > 0) {
|
||||||
|
if (vertical) {
|
||||||
result = "Mouse Wheel Event: UP";
|
result = "Mouse Wheel Event: UP";
|
||||||
} else {
|
} else {
|
||||||
result = "Mouse Wheel Event: LEFT";
|
result = "Mouse Wheel Event: LEFT";
|
||||||
}
|
}
|
||||||
} else if (e->delta() < 0) {
|
} else if (delta < 0) {
|
||||||
if (e->orientation() == Qt::Vertical) {
|
if (vertical) {
|
||||||
result = "Mouse Wheel Event: DOWN";
|
result = "Mouse Wheel Event: DOWN";
|
||||||
} else {
|
} else {
|
||||||
result = "Mouse Wheel Event: RIGHT";
|
result = "Mouse Wheel Event: RIGHT";
|
||||||
|
@ -743,12 +743,14 @@ QHoverEvent::~QHoverEvent()
|
|||||||
\l inverted always returns false.
|
\l inverted always returns false.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
/*!
|
/*!
|
||||||
\fn Qt::Orientation QWheelEvent::orientation() const
|
\fn Qt::Orientation QWheelEvent::orientation() const
|
||||||
\obsolete
|
\obsolete
|
||||||
|
|
||||||
Use angleDelta() instead.
|
Use angleDelta() instead.
|
||||||
*/
|
*/
|
||||||
|
#endif
|
||||||
|
|
||||||
#if QT_CONFIG(wheelevent)
|
#if QT_CONFIG(wheelevent)
|
||||||
#if QT_DEPRECATED_SINCE(5, 15)
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
@ -929,6 +931,7 @@ QWheelEvent::~QWheelEvent()
|
|||||||
\endlist
|
\endlist
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
/*!
|
/*!
|
||||||
\fn int QWheelEvent::delta() const
|
\fn int QWheelEvent::delta() const
|
||||||
\obsolete
|
\obsolete
|
||||||
@ -992,6 +995,7 @@ QWheelEvent::~QWheelEvent()
|
|||||||
|
|
||||||
This function has been deprecated, use globalPosition() instead.
|
This function has been deprecated, use globalPosition() instead.
|
||||||
*/
|
*/
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn Qt::ScrollPhase QWheelEvent::phase() const
|
\fn Qt::ScrollPhase QWheelEvent::phase() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user