Add Ui::MapFrom for optimized mapFromGlobal(mapToGlobal(..)).

This commit is contained in:
John Preston 2022-09-07 12:50:59 +04:00
parent d7c2185f5c
commit 12b8b3804c
2 changed files with 26 additions and 0 deletions

View file

@ -222,4 +222,20 @@ int WheelDirection(not_null<QWheelEvent*> e) {
return (delta / absDelta); return (delta / absDelta);
} }
QPoint MapFrom(
not_null<QWidget*> to,
not_null<QWidget*> 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<QWidget*> to,
not_null<QWidget*> from,
QRect rect) {
return { MapFrom(to, from, rect.topLeft()), rect.size() };
}
} // namespace Ui } // namespace Ui

View file

@ -196,4 +196,14 @@ QPointer<const Widget> MakeWeak(not_null<const Widget*> object) {
int WheelDirection(not_null<QWheelEvent*> e); int WheelDirection(not_null<QWheelEvent*> e);
[[nodiscard]] QPoint MapFrom(
not_null<QWidget*> to,
not_null<QWidget*> from,
QPoint point);
[[nodiscard]] QRect MapFrom(
not_null<QWidget*> to,
not_null<QWidget*> from,
QRect rect);
} // namespace Ui } // namespace Ui