Handle stream tile coordinates with Qt 5 and Qt 6 APIs

This commit is contained in:
evgeny committed 2026-10-20 20:46:08 +02:00
1 parent 03e8caf849
commit 8673673fcb
1 file changed
+13 -7
+13 -7
View File
@@ -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<QMouseEvent*>(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<QMouseEvent*>(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<QMouseEvent*>(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<QMouseEvent*>(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<QWidget*>(watched))) {
(position - m_pressPosition).manhattanLength() < QApplication::startDragDistance()) {
for (const auto& tile : m_tiles) if (tile.video && (tile.video == watched || tile.video->isAncestorOf(qobject_cast<QWidget*>(watched)))) {
QMetaObject::invokeMethod(this, [this, source = tile.source] { activateTile(source); }, Qt::QueuedConnection); break;
}
}