00001 /*************************************************************************** 00002 * Copyright (c) Juergen Riegel <juergen.riegel@web.de> * 00003 * * 00004 * This file is part of the FreeCAD CAx development system. * 00005 * * 00006 * This library is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Library General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Library General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Library General Public * 00017 * License along with this library; see the file COPYING.LIB. If not, * 00018 * write to the Free Software Foundation, Inc., 59 Temple Place, * 00019 * Suite 330, Boston, MA 02111-1307, USA * 00020 * * 00021 ***************************************************************************/ 00022 00023 00024 #include "PreCompiled.h" 00025 00026 #ifndef _PreComp_ 00027 # include <QDockWidget> 00028 # include <QPointer> 00029 #endif 00030 00032 #include "Control.h" 00033 #include "TaskView/TaskView.h" 00034 00035 #include <Gui/MainWindow.h> 00036 #include <Gui/CombiView.h> 00037 #include <Gui/DockWindowManager.h> 00038 00039 00040 using namespace Gui; 00041 using namespace std; 00042 00043 /* TRANSLATOR Gui::ControlSingleton */ 00044 00045 ControlSingleton* ControlSingleton::_pcSingleton = 0; 00046 static QPointer<Gui::TaskView::TaskView> _taskPanel = 0; 00047 00048 ControlSingleton::ControlSingleton() 00049 : ActiveDialog(0) 00050 { 00051 00052 } 00053 00054 ControlSingleton::~ControlSingleton() 00055 { 00056 00057 } 00058 00059 Gui::TaskView::TaskView* ControlSingleton::taskPanel() const 00060 { 00061 Gui::DockWnd::CombiView* pcCombiView = qobject_cast<Gui::DockWnd::CombiView*> 00062 (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); 00063 // should return the pointer to combo view 00064 if (pcCombiView) 00065 return pcCombiView->getTaskPanel(); 00066 // not all workbenches have the combo view enabled 00067 else if (_taskPanel) 00068 return _taskPanel; 00069 // no task panel available 00070 else 00071 return 0; 00072 } 00073 00074 void ControlSingleton::showTaskView() 00075 { 00076 Gui::DockWnd::CombiView* pcCombiView = qobject_cast<Gui::DockWnd::CombiView*> 00077 (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); 00078 if (pcCombiView) 00079 pcCombiView->showTaskView(); 00080 else if (_taskPanel) 00081 _taskPanel->raise(); 00082 } 00083 00084 void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg) 00085 { 00086 // only one dialog at a time 00087 assert(!ActiveDialog || ActiveDialog==dlg); 00088 Gui::DockWnd::CombiView* pcCombiView = qobject_cast<Gui::DockWnd::CombiView*> 00089 (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); 00090 // should return the pointer to combo view 00091 if (pcCombiView) { 00092 pcCombiView->showDialog(dlg); 00093 // make sure that the combo view is shown 00094 QDockWidget* dw = qobject_cast<QDockWidget*>(pcCombiView->parentWidget()); 00095 if (dw) { 00096 dw->setVisible(true); 00097 dw->toggleViewAction()->setVisible(true); 00098 } 00099 00100 if (ActiveDialog == dlg) 00101 return; // dialog is already defined 00102 ActiveDialog = dlg; 00103 connect(dlg, SIGNAL(destroyed()), this, SLOT(closedDialog())); 00104 } 00105 // not all workbenches have the combo view enabled 00106 else if (!_taskPanel) { 00107 QDockWidget* dw = new QDockWidget(); 00108 dw->setWindowTitle(tr("Task panel")); 00109 dw->setFeatures(QDockWidget::DockWidgetMovable); 00110 _taskPanel = new Gui::TaskView::TaskView(dw); 00111 dw->setWidget(_taskPanel); 00112 _taskPanel->showDialog(dlg); 00113 getMainWindow()->addDockWidget(Qt::LeftDockWidgetArea, dw); 00114 connect(dlg, SIGNAL(destroyed()), dw, SLOT(deleteLater())); 00115 00116 // if we have the normal tree view available then just tabify with it 00117 QWidget* treeView = Gui::DockWindowManager::instance()->getDockWindow("Tree view"); 00118 QDockWidget* par = treeView ? qobject_cast<QDockWidget*>(treeView->parent()) : 0; 00119 if (par && par->isVisible()) { 00120 getMainWindow()->tabifyDockWidget(par, dw); 00121 qApp->processEvents(); // make sure that the task panel is tabified now 00122 dw->show(); 00123 dw->raise(); 00124 } 00125 } 00126 } 00127 00128 Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const 00129 { 00130 return ActiveDialog; 00131 } 00132 00133 void ControlSingleton::closeDialog() 00134 { 00135 Gui::DockWnd::CombiView* pcCombiView = qobject_cast<Gui::DockWnd::CombiView*> 00136 (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); 00137 // should return the pointer to combo view 00138 if (pcCombiView) 00139 pcCombiView->closeDialog(); 00140 else if (_taskPanel) 00141 _taskPanel->removeDialog(); 00142 } 00143 00144 void ControlSingleton::closedDialog() 00145 { 00146 ActiveDialog = 0; 00147 Gui::DockWnd::CombiView* pcCombiView = qobject_cast<Gui::DockWnd::CombiView*> 00148 (Gui::DockWindowManager::instance()->getDockWindow("Combo View")); 00149 // should return the pointer to combo view 00150 assert(pcCombiView); 00151 pcCombiView->closedDialog(); 00152 } 00153 00154 bool ControlSingleton::isAllowedAlterDocument(void) const 00155 { 00156 if (ActiveDialog) 00157 return ActiveDialog->isAllowedAlterDocument(); 00158 return true; 00159 } 00160 00161 00162 bool ControlSingleton::isAllowedAlterView(void) const 00163 { 00164 if (ActiveDialog) 00165 return ActiveDialog->isAllowedAlterView(); 00166 return true; 00167 } 00168 00169 bool ControlSingleton::isAllowedAlterSelection(void) const 00170 { 00171 if (ActiveDialog) 00172 return ActiveDialog->isAllowedAlterSelection(); 00173 return true; 00174 } 00175 00176 // ------------------------------------------- 00177 00178 ControlSingleton& ControlSingleton::instance(void) 00179 { 00180 if (_pcSingleton == NULL) 00181 _pcSingleton = new ControlSingleton; 00182 return *_pcSingleton; 00183 } 00184 00185 void ControlSingleton::destruct (void) 00186 { 00187 if (_pcSingleton != NULL) 00188 delete _pcSingleton; 00189 _pcSingleton = 0; 00190 } 00191 00192 00193 // ------------------------------------------- 00194 00195 00196 #include "moc_Control.cpp" 00197