diff --git a/ui/ui_utility.cpp b/ui/ui_utility.cpp index ee6173d..283b340 100644 --- a/ui/ui_utility.cpp +++ b/ui/ui_utility.cpp @@ -222,4 +222,20 @@ int WheelDirection(not_null e) { return (delta / absDelta); } +QPoint MapFrom( + not_null to, + not_null from, + QPoint point) { + return (to->window() != from->window()) + ? to->mapFromGlobal(from->mapToGlobal(point)) + : to->mapFrom(to->window(), from->mapTo(from->window(), point)); +} + +[[nodiscard]] QRect MapFrom( + not_null to, + not_null from, + QRect rect) { + return { MapFrom(to, from, rect.topLeft()), rect.size() }; +} + } // namespace Ui diff --git a/ui/ui_utility.h b/ui/ui_utility.h index 420f0ff..3242ed5 100644 --- a/ui/ui_utility.h +++ b/ui/ui_utility.h @@ -196,4 +196,14 @@ QPointer MakeWeak(not_null object) { int WheelDirection(not_null e); +[[nodiscard]] QPoint MapFrom( + not_null to, + not_null from, + QPoint point); + +[[nodiscard]] QRect MapFrom( + not_null to, + not_null from, + QRect rect); + } // namespace Ui