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 <QIcon>
#include <QInputDialog> #include <QInputDialog>
#include <QStringList> #include <QStringList>
#include <QKeyEvent>
#include <QApplication>
MainWindow::MainWindow(ApplicationController* appController, QWidget *parent) MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, m_appController(appController) , m_appController(appController)
{ {
qApp->installEventFilter(this);
setWindowTitle("OpenCAD"); setWindowTitle("OpenCAD");
resize(1920, 1080); resize(1920, 1080);
@@ -204,3 +207,19 @@ void MainWindow::updateWindowTitle(const QString& filePath)
shownName = "Untitled"; shownName = "Untitled";
setWindowTitle(tr("%1[*] - %2").arg(QFileInfo(shownName).fileName(), tr("OpenCAD"))); 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);
}

View File

@@ -3,6 +3,7 @@
#include <QMainWindow> #include <QMainWindow>
class QEvent;
class ViewportWidget; class ViewportWidget;
class Document; class Document;
class Feature; class Feature;
@@ -29,6 +30,9 @@ private slots:
void exitSketchMode(); void exitSketchMode();
void updateWindowTitle(const QString& filePath); void updateWindowTitle(const QString& filePath);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private: private:
ApplicationController* m_appController; ApplicationController* m_appController;
ViewportWidget *m_viewport; ViewportWidget *m_viewport;

View File

@@ -1054,6 +1054,14 @@ void ViewportWidget::keyPressEvent(QKeyEvent *event)
QOpenGLWidget::keyPressEvent(event); QOpenGLWidget::keyPressEvent(event);
} }
bool ViewportWidget::focusNextPrevChild(bool next)
{
if (m_activeTool != static_cast<int>(ApplicationController::ToolType::None)) {
return false;
}
return QOpenGLWidget::focusNextPrevChild(next);
}
void ViewportWidget::onSketchModeStarted(SketchPlane plane) void ViewportWidget::onSketchModeStarted(SketchPlane plane)
{ {
m_currentPlane = plane; m_currentPlane = plane;

View File

@@ -58,6 +58,7 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
bool focusNextPrevChild(bool next) override;
private: private:
void initShaders(); void initShaders();