diff --git a/src/Gui/ComboView.cpp b/src/Gui/ComboView.cpp index f142d7672f..a3a1c89ab6 100644 --- a/src/Gui/ComboView.cpp +++ b/src/Gui/ComboView.cpp @@ -23,15 +23,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include # include #endif #include "ComboView.h" -#include "BitmapFactory.h" -#include "Document.h" #include "PropertyView.h" #include "Tree.h" -#include "TaskView/TaskView.h" using namespace Gui; @@ -40,11 +38,8 @@ using namespace Gui::DockWnd; /* TRANSLATOR Gui::DockWnd::ComboView */ -ComboView::ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent) - : DockWindow(pcDocument,parent) - , oldTabIndex(0) - , modelIndex(-1) - , taskIndex(-1) +ComboView::ComboView(Gui::Document* pcDocument, QWidget *parent) + : DockWindow(pcDocument, parent) { setWindowTitle(tr("Combo View")); @@ -53,102 +48,20 @@ ComboView::ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent) pLayout->setContentsMargins ( 0, 0, 0, 0 ); // tabs to switch between Tree/Properties and TaskPanel - tabs = new QTabWidget (); - tabs->setObjectName(QString::fromUtf8("combiTab")); - tabs->setTabPosition(QTabWidget::North); - pLayout->addWidget( tabs, 0, 0 ); + auto splitter = new QSplitter(); + pLayout->addWidget( splitter, 0, 0 ); - connect(tabs, qOverload(&QTabWidget::currentChanged), - this, &ComboView::onCurrentTabChanged); - if (showModel) { - // splitter between tree and property view - auto splitter = new QSplitter(); - splitter->setOrientation(Qt::Vertical); + // splitter between tree and property view + splitter->setOrientation(Qt::Vertical); - tree = new TreePanel("ComboView", this); - splitter->addWidget(tree); + tree = new TreePanel("ComboView", this); + splitter->addWidget(tree); - // property view - prop = new PropertyView(this); - splitter->addWidget(prop); - modelIndex = tabs->addTab(splitter,tr("Model")); - } - else { - tree = nullptr; - prop = nullptr; - } - - // task panel - taskPanel = new Gui::TaskView::TaskView(this); - taskIndex = tabs->addTab(taskPanel, tr("Tasks")); - - // task panel - //projectView = new Gui::ProjectWidget(this); - //tabs->addTab(projectView, tr("Project")); + // property view + prop = new PropertyView(this); + splitter->addWidget(prop); } ComboView::~ComboView() = default; -void ComboView::showDialog(Gui::TaskView::TaskDialog *dlg) -{ - static QIcon icon = Gui::BitmapFactory().pixmap("edit-edit.svg"); - - // switch to the TaskView tab - oldTabIndex = tabs->currentIndex(); - tabs->setCurrentIndex(taskIndex); - tabs->setTabIcon(taskIndex, icon); - // set the dialog - taskPanel->showDialog(dlg); - - // force to show the combo view - if (modelIndex < 0) { - if (parentWidget()) - parentWidget()->raise(); - } -} - -void ComboView::closeDialog() -{ - // close the dialog - taskPanel->removeDialog(); -} - -void ComboView::closedDialog() -{ - static QIcon icon = QIcon(); - - // dialog has been closed - tabs->setCurrentIndex(oldTabIndex); - tabs->setTabIcon(taskIndex, icon); -} - -void ComboView::showTreeView() -{ - // switch to the tree view - tabs->setCurrentIndex(modelIndex); -} - -void ComboView::showTaskView() -{ - // switch to the task view - tabs->setCurrentIndex(taskIndex); -} - -void ComboView::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::LanguageChange) { - tabs->setTabText(modelIndex, tr("Model")); - tabs->setTabText(taskIndex, tr("Tasks")); - //tabs->setTabText(2, tr("Project")); - } - - DockWindow::changeEvent(e); -} - -void ComboView::onCurrentTabChanged(int index) -{ - if (index != taskIndex) - oldTabIndex = index; -} - #include "moc_ComboView.cpp" diff --git a/src/Gui/ComboView.h b/src/Gui/ComboView.h index 195790314d..0aac485b05 100644 --- a/src/Gui/ComboView.h +++ b/src/Gui/ComboView.h @@ -56,7 +56,7 @@ namespace Gui { namespace DockWnd { /** Combo View - * is a combination of a tree, property and TaskPanel for + * is a combination of a tree and property view for * integrated user action. */ class GuiExport ComboView : public Gui::DockWindow @@ -68,7 +68,7 @@ public: * A constructor. * A more elaborate description of the constructor. */ - ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent=nullptr); + ComboView(Gui::Document* pcDocument, QWidget *parent=nullptr); /** * A destructor. @@ -76,33 +76,11 @@ public: */ ~ComboView() override; - Gui::TaskView::TaskView *getTaskPanel(){return taskPanel;} - QTabWidget* getTabPanel() const { return tabs;} - - friend class Gui::ControlSingleton; - void showTreeView(); - void showTaskView(); - -private Q_SLOTS: - void onCurrentTabChanged(int index); - -protected: - void showDialog(Gui::TaskView::TaskDialog *dlg); - void closeDialog(); - void closedDialog(); - void changeEvent(QEvent *e) override; - private: - int oldTabIndex; - int modelIndex; - int taskIndex; - QTabWidget * tabs; Gui::PropertyView * prop; Gui::TreePanel * tree; - Gui::TaskView::TaskView * taskPanel; - //Gui::ProjectWidget * projectView; }; } // namespace DockWnd diff --git a/src/Gui/Control.cpp b/src/Gui/Control.cpp index 47e21cd17b..a617edfde5 100644 --- a/src/Gui/Control.cpp +++ b/src/Gui/Control.cpp @@ -37,6 +37,8 @@ #include #include "Control.h" +#include "BitmapFactory.h" +#include "Tree.h" #include "TaskView/TaskView.h" @@ -46,10 +48,10 @@ using namespace std; /* TRANSLATOR Gui::ControlSingleton */ ControlSingleton* ControlSingleton::_pcSingleton = nullptr; -static QPointer _taskPanel = nullptr; ControlSingleton::ControlSingleton() : ActiveDialog(nullptr) + , oldTabIndex(-1) { } @@ -58,37 +60,86 @@ ControlSingleton::~ControlSingleton() = default; Gui::TaskView::TaskView* ControlSingleton::taskPanel() const { - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - // should return the pointer to combo view - if (pcComboView) - return pcComboView->getTaskPanel(); - // not all workbenches have the combo view enabled - else if (_taskPanel) - return _taskPanel; - // no task panel available - else - return nullptr; + auto taskView = qobject_cast + (Gui::DockWindowManager::instance()->getDockWindow("Tasks")); + return taskView; +} + +void ControlSingleton::showDockWidget(QWidget* widget) +{ + QWidget* parent = widget->parentWidget(); + if (parent) { + parent->show(); + parent->raise(); + } +} + +QTabBar* ControlSingleton::findTabBar(QDockWidget* widget) const +{ + int count = getMainWindow()->tabifiedDockWidgets(widget).size() + 1; + if (count > 1) { + QList bars = getMainWindow()->findChildren(); + for (auto it : bars) { + if (it->count() == count) { + for (int i = 0; i < count; i++) { + if (it->tabText(i) == widget->windowTitle()) { + return it; + } + } + } + } + } + + return nullptr; +} + +void ControlSingleton::aboutToShowDialog(QDockWidget* widget) +{ + static QIcon icon = Gui::BitmapFactory().pixmap("edit-edit.svg"); + QTabBar* bar = findTabBar(widget); + if (bar) { + oldTabIndex = bar->currentIndex(); + for (int i = 0; i < bar->count(); i++) { + if (bar->tabText(i) == widget->windowTitle()) { + bar->setTabIcon(i, icon); + break; + } + } + } + + widget->show(); + widget->raise(); +} + +void ControlSingleton::aboutToHideDialog(QDockWidget* widget) +{ + QTabBar* bar = findTabBar(widget); + if (bar) { + bar->setCurrentIndex(oldTabIndex); + for (int i = 0; i < bar->count(); i++) { + if (bar->tabText(i) == widget->windowTitle()) { + bar->setTabIcon(i, QIcon()); + break; + } + } + } } void ControlSingleton::showTaskView() { - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - if (pcComboView) - pcComboView->showTaskView(); - else if (_taskPanel) - _taskPanel->raise(); + Gui::TaskView::TaskView* taskView = taskPanel(); + if (taskView) { + showDockWidget(taskView); + } } void ControlSingleton::showModelView() { - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - if (pcComboView) - pcComboView->showTreeView(); - else if (_taskPanel) - _taskPanel->raise(); + auto treeView = qobject_cast + (Gui::DockWindowManager::instance()->getDockWindow("Tree view")); + if (treeView) { + showDockWidget(treeView); + } } void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg) @@ -113,14 +164,15 @@ void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg) // which may open a transaction but fails when auto transaction is still active. App::AutoTransaction::setEnable(false); - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); + Gui::TaskView::TaskView* taskView = taskPanel(); // should return the pointer to combo view - if (pcComboView) { - pcComboView->showDialog(dlg); + if (taskView) { + taskView->showDialog(dlg); + // make sure that the combo view is shown - auto dw = qobject_cast(pcComboView->parentWidget()); + auto dw = qobject_cast(taskView->parentWidget()); if (dw) { + aboutToShowDialog(dw); dw->setVisible(true); dw->toggleViewAction()->setVisible(true); dw->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); @@ -132,37 +184,6 @@ void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg) connect(dlg, &TaskView::TaskDialog::aboutToBeDestroyed, this, &ControlSingleton::closedDialog); } - // not all workbenches have the combo view enabled - else if (!_taskPanel) { - auto dw = new QDockWidget(); - dw->setWindowTitle(tr("Task panel")); - dw->setFeatures(QDockWidget::DockWidgetMovable); - _taskPanel = new Gui::TaskView::TaskView(dw); - dw->setWidget(_taskPanel); - _taskPanel->showDialog(dlg); - getMainWindow()->addDockWidget(Qt::LeftDockWidgetArea, dw); - connect(dlg, &TaskView::TaskDialog::destroyed, dw, &ControlSingleton::deleteLater); - - // if we have the normal tree view available then just tabify with it - QWidget* treeView = Gui::DockWindowManager::instance()->getDockWindow("Tree view"); - QDockWidget* par = treeView ? qobject_cast(treeView->parent()) : 0; - if (par && par->isVisible()) { - getMainWindow()->tabifyDockWidget(par, dw); - qApp->processEvents(); // make sure that the task panel is tabified now - dw->show(); - dw->raise(); - } - } -} - -QTabWidget* ControlSingleton::tabPanel() const -{ - Gui::DockWnd::ComboView* pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - // should return the pointer to combo view - if (pcComboView) - return pcComboView->getTabPanel(); - return nullptr; } Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const @@ -170,22 +191,11 @@ Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const return ActiveDialog; } -Gui::TaskView::TaskView* ControlSingleton::getTaskPanel() -{ - // should return the pointer to combo view - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - if (pcComboView) - return pcComboView->getTaskPanel(); - else - return _taskPanel; -} - void ControlSingleton::accept() { - Gui::TaskView::TaskView* taskPanel = getTaskPanel(); - if (taskPanel) { - taskPanel->accept(); + Gui::TaskView::TaskView* taskView = taskPanel(); + if (taskView) { + taskView->accept(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); } @@ -193,9 +203,9 @@ void ControlSingleton::accept() void ControlSingleton::reject() { - Gui::TaskView::TaskView* taskPanel = getTaskPanel(); - if (taskPanel) { - taskPanel->reject(); + Gui::TaskView::TaskView* taskView = taskPanel(); + if (taskView) { + taskView->reject(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); } @@ -203,29 +213,25 @@ void ControlSingleton::reject() void ControlSingleton::closeDialog() { - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - // should return the pointer to combo view - if (pcComboView) - pcComboView->closeDialog(); - else if (_taskPanel) - _taskPanel->removeDialog(); + Gui::TaskView::TaskView* taskView = taskPanel(); + if (taskView) + taskView->removeDialog(); } void ControlSingleton::closedDialog() { ActiveDialog = nullptr; - auto pcComboView = qobject_cast - (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); - // should return the pointer to combo view - assert(pcComboView); - pcComboView->closedDialog(); + Gui::TaskView::TaskView* taskView = taskPanel(); + assert(taskView); + // make sure that the combo view is shown - auto dw = qobject_cast(pcComboView->parentWidget()); - if (dw) + auto dw = qobject_cast(taskView->parentWidget()); + if (dw) { + aboutToHideDialog(dw); dw->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); + } } bool ControlSingleton::isAllowedAlterDocument() const diff --git a/src/Gui/Control.h b/src/Gui/Control.h index 7da5098ce3..fd4d3ed838 100644 --- a/src/Gui/Control.h +++ b/src/Gui/Control.h @@ -32,7 +32,8 @@ #include -class QTabWidget; +class QDockWidget; +class QTabBar; namespace App { @@ -75,8 +76,6 @@ public: Gui::TaskView::TaskView* taskPanel() const; /// raising the model view void showModelView(); - /// get the tab panel - QTabWidget* tabPanel() const; //@} /*! @@ -106,9 +105,6 @@ private Q_SLOTS: /// This get called by the TaskView when the Dialog is finished void closedDialog(); -private: - Gui::TaskView::TaskView *getTaskPanel(); - private: struct status { std::bitset<32> StatusBits; @@ -117,12 +113,17 @@ private: std::stack StatusStack; Gui::TaskView::TaskDialog *ActiveDialog; + int oldTabIndex; private: /// Construction ControlSingleton(); /// Destruction ~ControlSingleton() override; + void showDockWidget(QWidget*); + QTabBar* findTabBar(QDockWidget*) const; + void aboutToShowDialog(QDockWidget* widget); + void aboutToHideDialog(QDockWidget* widget); static ControlSingleton* _pcSingleton; }; diff --git a/src/Gui/DockWindowManager.cpp b/src/Gui/DockWindowManager.cpp index e7864e0da1..9a9f2292d6 100644 --- a/src/Gui/DockWindowManager.cpp +++ b/src/Gui/DockWindowManager.cpp @@ -175,6 +175,20 @@ QWidget* DockWindowManager::getDockWindow(const char* name) const return nullptr; } +/** + * Returns the dock widget by name. + * If it does not exist 0 is returned. + */ +QDockWidget* DockWindowManager::getDockContainer(const char* name) const +{ + for (QList::Iterator it = d->_dockedWindows.begin(); it != d->_dockedWindows.end(); ++it) { + if ((*it)->objectName() == QLatin1String(name)) + return (*it); + } + + return nullptr; +} + /** * Returns a list of all widgets inside the dock windows. */ diff --git a/src/Gui/DockWindowManager.h b/src/Gui/DockWindowManager.h index de314b6af7..366cd96738 100644 --- a/src/Gui/DockWindowManager.h +++ b/src/Gui/DockWindowManager.h @@ -86,6 +86,8 @@ public: /// returned from @ref addDockWindow. If you want to access the QDockWidget /// you get it with parentWidget() of the returned widget. QWidget* getDockWindow(const char* name) const; + /// Returns the QDockWidget container + QDockWidget* getDockContainer(const char* name) const; /// Returns a list of all widgets which set to a QDockWidget. QList getDockWindows() const; /// If the corresponding dock widget isn't visible then activate it diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index ff566c1308..20f3d75fe4 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -479,6 +479,8 @@ void MainWindow::setupDockWindows() setupReportView(hiddenDockWindows); setupPythonConsole(hiddenDockWindows); setupDAGView(hiddenDockWindows); + + this->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); } bool MainWindow::setupTreeView(const std::string& hiddenDockWindows) @@ -580,8 +582,8 @@ bool MainWindow::setupComboView(const std::string& hiddenDockWindows, bool enabl enable = group->GetBool("Enabled", true); } - auto pcComboView = new ComboView(enable, nullptr, this); - pcComboView->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Combo View"))); + auto pcComboView = new ComboView(nullptr, this); + pcComboView->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget", "Model"))); pcComboView->setMinimumWidth(150); DockWindowManager* pDockMgr = DockWindowManager::instance();