From f9881584a9d3af1566ecf05ea2df53941635f6be Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Tue, 12 Jan 2021 21:24:23 -0600 Subject: [PATCH] Add option to auto-show selection view The SelectionView dock window was already an observer of the current selection when it was showing. This changes it to continuously monitor the selection even when invisible. If the user sets the parameter BaseApp/Preferences/Selection/AutoShowSelectionView to true, when there is an item selected, the view will show itself if it was hidden, and will re-hide itself when the selection is cleared. The option has no effect if the user had chosen to manually show the selection view prior to beginning a selection. --- src/Gui/SelectionView.cpp | 23 ++++++++++++++++++----- src/Gui/SelectionView.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Gui/SelectionView.cpp b/src/Gui/SelectionView.cpp index 4459b02d60..f89d8d1526 100644 --- a/src/Gui/SelectionView.cpp +++ b/src/Gui/SelectionView.cpp @@ -55,8 +55,9 @@ using namespace Gui::DockWnd; SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent) : DockWindow(pcDocument,parent) - , SelectionObserver(false,0) + , SelectionObserver(true,0) , x(0.0f), y(0.0f), z(0.0f) + , openedAutomatically(false) { setWindowTitle(tr("Selection View")); @@ -128,6 +129,22 @@ void SelectionView::leaveEvent(QEvent *) /// @cond DOXERR void SelectionView::onSelectionChanged(const SelectionChanges &Reason) { + ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") + ->GetGroup("Preferences")->GetGroup("Selection"); + bool autoShow = hGrp->GetBool("AutoShowSelectionView", false); + hGrp->SetBool("AutoShowSelectionView", autoShow); // Remove this line once the preferences window item is implemented + + if (autoShow) { + if (!parentWidget()->isVisible() && Selection().hasSelection()) { + parentWidget()->show(); + openedAutomatically = true; + } + else if (openedAutomatically && !Selection().hasSelection()) { + parentWidget()->hide(); + openedAutomatically = false; + } + } + QString selObject; QTextStream str(&selObject); if (Reason.Type == SelectionChanges::AddSelection) { @@ -608,14 +625,10 @@ bool SelectionView::onMsg(const char* /*pMsg*/,const char** /*ppReturn*/) } void SelectionView::hideEvent(QHideEvent *ev) { - FC_TRACE(this << " detaching selection observer"); - this->detachSelection(); DockWindow::hideEvent(ev); } void SelectionView::showEvent(QShowEvent *ev) { - FC_TRACE(this << " attaching selection observer"); - this->attachSelection(); enablePickList->setChecked(Selection().needPickedList()); Gui::DockWindow::showEvent(ev); } diff --git a/src/Gui/SelectionView.h b/src/Gui/SelectionView.h index ecb9a1dad5..da72d37298 100644 --- a/src/Gui/SelectionView.h +++ b/src/Gui/SelectionView.h @@ -110,6 +110,7 @@ private: private: float x,y,z; std::vector searchList; + bool openedAutomatically; }; } // namespace DockWnd