From 8673673fcb3527c46d1f80ca5a9d6ea28ddee2c1 Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 20 Oct 2026 20:46:08 +0200 Subject: [PATCH] Handle stream tile coordinates with Qt 5 and Qt 6 APIs --- tools/chatgui/src/streamgrid_window.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/chatgui/src/streamgrid_window.cpp b/tools/chatgui/src/streamgrid_window.cpp index 1c503860..b8d3d071 100644 --- a/tools/chatgui/src/streamgrid_window.cpp +++ b/tools/chatgui/src/streamgrid_window.cpp @@ -131,17 +131,23 @@ void StreamGridWindow::restoreGrid() { /* Не перехватываем drag/колесо zoom. Активация после release даёт VideoRenderWidget завершить drag. */ bool StreamGridWindow::eventFilter(QObject* watched, QEvent* event) { + if (event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseMove && event->type() != QEvent::MouseButtonRelease) + return QWidget::eventFilter(watched, event); + auto* mouse = static_cast(event); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const auto position = mouse->globalPosition().toPoint(); +#else + const auto position = mouse->globalPos(); +#endif if (event->type() == QEvent::MouseButtonPress) { - auto* mouse = static_cast(event); - if (mouse->button() == Qt::LeftButton) { m_pressed = watched; m_pressPosition = mouse->globalPos(); m_dragged = false; } + if (mouse->button() == Qt::LeftButton) { m_pressed = watched; m_pressPosition = position; m_dragged = false; } } else if (event->type() == QEvent::MouseMove && m_pressed == watched) { - auto* mouse = static_cast(event); - if ((mouse->globalPos() - m_pressPosition).manhattanLength() >= QApplication::startDragDistance()) m_dragged = true; + if ((position - m_pressPosition).manhattanLength() >= QApplication::startDragDistance()) m_dragged = true; } else if (event->type() == QEvent::MouseButtonRelease && m_pressed == watched) { - auto* mouse = static_cast(event); m_pressed = nullptr; + m_pressed = nullptr; if (mouse->button() == Qt::LeftButton && !m_dragged && - (mouse->globalPos() - m_pressPosition).manhattanLength() < QApplication::startDragDistance()) { - for (const auto& tile : m_tiles) if (tile.video == watched || tile.video->isAncestorOf(qobject_cast(watched))) { + (position - m_pressPosition).manhattanLength() < QApplication::startDragDistance()) { + for (const auto& tile : m_tiles) if (tile.video && (tile.video == watched || tile.video->isAncestorOf(qobject_cast(watched)))) { QMetaObject::invokeMethod(this, [this, source = tile.source] { activateTile(source); }, Qt::QueuedConnection); break; } }