Gui: rework ComboView
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <Gui/MainWindow.h>
|
||||
|
||||
#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<Gui::TaskView::TaskView> _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::DockWnd::ComboView*>
|
||||
(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::TaskView::TaskView*>
|
||||
(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<QTabBar*> bars = getMainWindow()->findChildren<QTabBar*>();
|
||||
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::DockWnd::ComboView*>
|
||||
(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::DockWnd::ComboView*>
|
||||
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
|
||||
if (pcComboView)
|
||||
pcComboView->showTreeView();
|
||||
else if (_taskPanel)
|
||||
_taskPanel->raise();
|
||||
auto treeView = qobject_cast<Gui::TreeDockWidget*>
|
||||
(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::DockWnd::ComboView*>
|
||||
(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<QDockWidget*>(pcComboView->parentWidget());
|
||||
auto dw = qobject_cast<QDockWidget*>(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<QDockWidget*>(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::DockWnd::ComboView*>
|
||||
(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::DockWnd::ComboView*>
|
||||
(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::DockWnd::ComboView*>
|
||||
(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::DockWnd::ComboView*>
|
||||
(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<QDockWidget*>(pcComboView->parentWidget());
|
||||
if (dw)
|
||||
auto dw = qobject_cast<QDockWidget*>(taskView->parentWidget());
|
||||
if (dw) {
|
||||
aboutToHideDialog(dw);
|
||||
dw->setFeatures(QDockWidget::DockWidgetClosable
|
||||
| QDockWidget::DockWidgetMovable
|
||||
| QDockWidget::DockWidgetFloatable);
|
||||
}
|
||||
}
|
||||
|
||||
bool ControlSingleton::isAllowedAlterDocument() const
|
||||
|
||||
Reference in New Issue
Block a user