feat: Prevent Tab key from moving focus outside active viewport tools

This commit is contained in:
2026-02-16 18:51:57 -07:00
committed by Tanner Collin (aider)
parent d89b7e42bc
commit b2d5cd19d4
4 changed files with 32 additions and 0 deletions

View File

@@ -17,11 +17,14 @@
#include <QIcon>
#include <QInputDialog>
#include <QStringList>
#include <QKeyEvent>
#include <QApplication>
MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
: QMainWindow(parent)
, m_appController(appController)
{
qApp->installEventFilter(this);
setWindowTitle("OpenCAD");
resize(1920, 1080);
@@ -204,3 +207,19 @@ void MainWindow::updateWindowTitle(const QString& filePath)
shownName = "Untitled";
setWindowTitle(tr("%1[*] - %2").arg(QFileInfo(shownName).fileName(), tr("OpenCAD")));
}
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
if (m_appController->activeTool() != ApplicationController::ToolType::None && event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) {
if (watched == m_viewport) {
return false; // Let the viewport handle its own event
}
// Forward event to viewport and consume it
QApplication::sendEvent(m_viewport, keyEvent);
return true;
}
}
return QMainWindow::eventFilter(watched, event);
}