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);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QEvent;
|
||||
class ViewportWidget;
|
||||
class Document;
|
||||
class Feature;
|
||||
@@ -29,6 +30,9 @@ private slots:
|
||||
void exitSketchMode();
|
||||
void updateWindowTitle(const QString& filePath);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
ApplicationController* m_appController;
|
||||
ViewportWidget *m_viewport;
|
||||
|
||||
@@ -1054,6 +1054,14 @@ void ViewportWidget::keyPressEvent(QKeyEvent *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)
|
||||
{
|
||||
m_currentPlane = plane;
|
||||
|
||||
@@ -58,6 +58,7 @@ protected:
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
bool focusNextPrevChild(bool next) override;
|
||||
|
||||
private:
|
||||
void initShaders();
|
||||
|
||||
Reference in New Issue
Block a user