From 4f952aaea13adfc2d271ed98f111fc8f6d9614ef Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 7 Jul 2020 22:11:14 +0200 Subject: Move method only used in keypad navigation to a better place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QDesktopWidget in particular doesn't use that code anymore. Change-Id: I8eed752175c5478663b25872c7ffe78c814245d7 Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 39 ++++++++++++++------------------------- src/widgets/kernel/qwidget_p.h | 2 -- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 5a75900f84..7c20657a85 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -6872,30 +6872,6 @@ void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw) } -/*!\internal - - Measures the shortest distance from a point to a rect. - - This function is called from QDesktopwidget::screen(QPoint) to find the - closest screen for a point. - In directional KeypadNavigation, it is called to find the closest - widget to the current focus widget center. -*/ -int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r) -{ - int dx = 0; - int dy = 0; - if (p.x() < r.left()) - dx = r.left() - p.x(); - else if (p.x() > r.right()) - dx = p.x() - r.right(); - if (p.y() < r.top()) - dy = r.top() - p.y(); - else if (p.y() > r.bottom()) - dy = p.y() - r.bottom(); - return dx + dy; -} - /*! \property QWidget::frameSize \brief the size of the widget including any window frame @@ -11780,7 +11756,20 @@ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) && targetCandidate->isVisible() // ...is in the same window, && targetCandidate->window() == sourceWindow) { - const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect); + const int targetCandidateDistance = [](const QPoint &sourcePoint, + const QRect &targetCandidateRect) { + int dx = 0; + int dy = 0; + if (p.x() < r.left()) + dx = r.left() - p.x(); + else if (p.x() > r.right()) + dx = p.x() - r.right(); + if (p.y() < r.top()) + dy = r.top() - p.y(); + else if (p.y() > r.bottom()) + dy = p.y() - r.bottom(); + return dx + dy; + }(); if (targetCandidateDistance < shortestDistance) { shortestDistance = targetCandidateDistance; targetWidget = targetCandidate; diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 08954cc778..f6a1ee539d 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -398,8 +398,6 @@ public: void reparentFocusWidgets(QWidget *oldtlw); - static int pointToRect(const QPoint &p, const QRect &r); - void setWinId(WId); void showChildren(bool spontaneous); void hideChildren(bool spontaneous); -- cgit v1.2.3