From 568f2634feaf6c8103561743d0490b443ddcfd36 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 4 Sep 2015 21:06:56 +0200 Subject: [PATCH 1/2] + fix switching to another mdi view when using the sketcher creation command from task panel --- src/Gui/TaskView/TaskView.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index 760e41351..95ce4f87a 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -28,6 +28,7 @@ # include # include # include +# include # include #endif @@ -586,6 +587,21 @@ void TaskView::removeDialog(void) void TaskView::updateWatcher(void) { + // In case a child of the TaskView has the focus and get hidden we have + // to make sure that set the focus on a widget that won't be hidden or + // deleted because otherwise Qt may forward the focus via focusNextPrevChild() + // to the mdi area which may switch to another mdi view which is not an + // acceptable behaviour. + QWidget *fw = QApplication::focusWidget(); + QPointer fwp = fw; + while (fw && !fw->isWindow()) { + if (fw == this) { + this->setFocus(); + break; + } + fw = fw->parentWidget(); + } + // add all widgets for all watcher to the task view for (std::vector::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) { bool match = (*it)->shouldShow(); @@ -597,6 +613,11 @@ void TaskView::updateWatcher(void) (*it2)->hide(); } } + + // In case the previous widget that had the focus is still visible + // give it the focus back. + if (fwp && fwp->isVisible()) + fwp->setFocus(); } void TaskView::addTaskWatcher(const std::vector &Watcher) @@ -639,6 +660,20 @@ void TaskView::addTaskWatcher(void) void TaskView::removeTaskWatcher(void) { + // In case a child of the TaskView has the focus and get hidden we have + // to make sure that set the focus on a widget that won't be hidden or + // deleted because otherwise Qt may forward the focus via focusNextPrevChild() + // to the mdi area which may switch to another mdi view which is not an + // acceptable behaviour. + QWidget *fw = QApplication::focusWidget(); + while (fw && !fw->isWindow()) { + if (fw == this) { + this->setFocus(); + break; + } + fw = fw->parentWidget(); + } + // remove all widgets for (std::vector::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) { std::vector &cont = (*it)->getWatcherContent(); From 134acba91633eb01c52f3215adf9f2ee9688f319 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 4 Sep 2015 21:34:26 +0200 Subject: [PATCH 2/2] + fix switching to another mdi view when using the sketcher creation command from task panel --- src/Gui/TaskView/TaskView.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index 95ce4f87a..e7496d9ff 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -593,6 +593,8 @@ void TaskView::updateWatcher(void) // to the mdi area which may switch to another mdi view which is not an // acceptable behaviour. QWidget *fw = QApplication::focusWidget(); + if (!fw) + this->setFocus(); QPointer fwp = fw; while (fw && !fw->isWindow()) { if (fw == this) { @@ -666,6 +668,8 @@ void TaskView::removeTaskWatcher(void) // to the mdi area which may switch to another mdi view which is not an // acceptable behaviour. QWidget *fw = QApplication::focusWidget(); + if (!fw) + this->setFocus(); while (fw && !fw->isWindow()) { if (fw == this) { this->setFocus();