From c2d1b5ce7c18a5a1b7ce588df04a4e81afc175ae Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Tue, 15 Dec 2020 18:27:54 -0800 Subject: [PATCH] Use events for view focus changes. --- common/lc_glwidget.cpp | 4 ++++ common/lc_glwidget.h | 1 + common/lc_mainwindow.cpp | 6 ++++++ common/lc_mainwindow.h | 3 ++- common/view.cpp | 7 ------- common/view.h | 2 -- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/common/lc_glwidget.cpp b/common/lc_glwidget.cpp index 93d67452..cc4805f0 100644 --- a/common/lc_glwidget.cpp +++ b/common/lc_glwidget.cpp @@ -55,7 +55,11 @@ lcModel* lcGLWidget::GetActiveModel() const void lcGLWidget::SetFocus(bool Focus) { if (Focus) + { mLastFocusedView = this; + + emit FocusReceived(); + } } void lcGLWidget::SetMousePosition(int MouseX, int MouseY) diff --git a/common/lc_glwidget.h b/common/lc_glwidget.h index be3eeab4..44daf3e6 100644 --- a/common/lc_glwidget.h +++ b/common/lc_glwidget.h @@ -196,6 +196,7 @@ public: lcContext* mContext = nullptr; signals: + void FocusReceived(); void CameraChanged(); protected: diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 33f483e0..c9f613b4 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -773,6 +773,7 @@ View* lcMainWindow::CreateView(lcModel* Model) View* NewView = new View(Model); connect(NewView, SIGNAL(CameraChanged()), this, SLOT(ViewCameraChanged())); + connect(NewView, SIGNAL(FocusReceived()), this, SLOT(ViewFocusReceived())); return NewView; } @@ -2146,6 +2147,11 @@ void lcMainWindow::UpdateUndoRedo(const QString& UndoText, const QString& RedoTe } } +void lcMainWindow::ViewFocusReceived() +{ + SetActiveView(dynamic_cast(sender())); +} + void lcMainWindow::ViewCameraChanged() { lcGLWidget* View = dynamic_cast(sender()); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index b4cffaef..d4d9acd1 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -285,7 +285,6 @@ public: void ResetCameras(); void AddView(View* View); void RemoveView(View* View); - void SetActiveView(View* ActiveView); void SetTool(lcTool Tool); void SetTransformType(lcTransformType TransformType); @@ -360,6 +359,7 @@ public slots: void TogglePreviewWidget(bool); protected slots: + void ViewFocusReceived(); void ViewCameraChanged(); void UpdateDockWidgetActions(); void UpdateGamepads(); @@ -384,6 +384,7 @@ protected: void CreateToolBars(); void CreateStatusBar(); View* CreateView(lcModel* Model); + void SetActiveView(View* ActiveView); void ToggleDockWidget(QWidget* DockWidget); void SplitView(Qt::Orientation Orientation); void ShowSearchDialog(); diff --git a/common/view.cpp b/common/view.cpp index 1da9d080..a565d24a 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -2425,8 +2425,6 @@ void View::OnLeftButtonDown() return; } - gMainWindow->SetActiveView(this); - if (mViewSphere.OnLeftButtonDown()) return; @@ -2451,8 +2449,6 @@ void View::OnLeftButtonUp() void View::OnLeftButtonDoubleClick() { - gMainWindow->SetActiveView(this); - lcObjectSection ObjectSection = FindObjectUnderPointer(false, false); lcModel* ActiveModel = GetActiveModel(); @@ -2472,7 +2468,6 @@ void View::OnMiddleButtonDown() return; } - gMainWindow->SetActiveView(this); #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) lcTrackTool OverrideTool = GetOverrideTrackTool(Qt::MiddleButton); @@ -2498,8 +2493,6 @@ void View::OnRightButtonDown() return; } - gMainWindow->SetActiveView(this); - lcTrackTool OverrideTool = GetOverrideTrackTool(Qt::RightButton); if (OverrideTool != lcTrackTool::None) diff --git a/common/view.h b/common/view.h index a155a9e6..f7c54cf9 100644 --- a/common/view.h +++ b/common/view.h @@ -13,9 +13,7 @@ public: ~View(); View(const View&) = delete; - View(View&&) = delete; View& operator=(const View&) = delete; - View& operator=(View&&) = delete; void Clear() {