feat: Prevent Tab key from moving focus outside active viewport tools
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user