/
Control.cpp
277 lines (237 loc) · 9.47 KB
/
Control.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/***************************************************************************
* Copyright 2011 (c) Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QAction>
# include <QApplication>
# include <QDebug>
# include <QDockWidget>
# include <QPointer>
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include "Control.h"
#include "TaskView/TaskView.h"
#include <App/AutoTransaction.h>
#include <Gui/MainWindow.h>
#include <Gui/ComboView.h>
#include <Gui/DockWindowManager.h>
using namespace Gui;
using namespace std;
/* TRANSLATOR Gui::ControlSingleton */
ControlSingleton* ControlSingleton::_pcSingleton = 0;
static QPointer<Gui::TaskView::TaskView> _taskPanel = 0;
ControlSingleton::ControlSingleton()
: ActiveDialog(0)
{
}
ControlSingleton::~ControlSingleton()
{
}
Gui::TaskView::TaskView* ControlSingleton::taskPanel() 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->getTaskPanel();
// not all workbenches have the combo view enabled
else if (_taskPanel)
return _taskPanel;
// no task panel available
else
return 0;
}
void ControlSingleton::showTaskView()
{
Gui::DockWnd::ComboView* pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
if (pcComboView)
pcComboView->showTaskView();
else if (_taskPanel)
_taskPanel->raise();
}
void ControlSingleton::showModelView()
{
Gui::DockWnd::ComboView* pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
if (pcComboView)
pcComboView->showTreeView();
else if (_taskPanel)
_taskPanel->raise();
}
void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg)
{
// only one dialog at a time, print a warning instead of raising an assert
if (ActiveDialog && ActiveDialog != dlg) {
if (dlg) {
qWarning() << "ControlSingleton::showDialog: Can't show "
<< dlg->metaObject()->className()
<< " since there is already an active task dialog";
}
else {
qWarning() << "ControlSingleton::showDialog: Task dialog is null";
}
return;
}
// Since the caller sets up a modeless task panel, it indicates intention
// for prolonged editing. So disable auto transaction in the current call
// stack.
// Do this before showing the dialog because its open() function is called
// which may open a transaction but fails when auto transaction is still active.
App::AutoTransaction::setEnable(false);
Gui::DockWnd::ComboView* pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
// should return the pointer to combo view
if (pcComboView) {
pcComboView->showDialog(dlg);
// make sure that the combo view is shown
QDockWidget* dw = qobject_cast<QDockWidget*>(pcComboView->parentWidget());
if (dw) {
dw->setVisible(true);
dw->toggleViewAction()->setVisible(true);
dw->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
if (ActiveDialog == dlg)
return; // dialog is already defined
ActiveDialog = dlg;
connect(dlg, SIGNAL(aboutToBeDestroyed()), this, SLOT(closedDialog()));
}
// not all workbenches have the combo view enabled
else if (!_taskPanel) {
QDockWidget* 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, SIGNAL(destroyed()), dw, SLOT(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 0;
}
Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const
{
return ActiveDialog;
}
Gui::TaskView::TaskView* ControlSingleton::getTaskPanel()
{
// should return the pointer to combo view
Gui::DockWnd::ComboView* 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();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
QEventLoop::ExcludeSocketNotifiers);
}
}
void ControlSingleton::reject()
{
Gui::TaskView::TaskView* taskPanel = getTaskPanel();
if (taskPanel) {
taskPanel->reject();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
QEventLoop::ExcludeSocketNotifiers);
}
}
void ControlSingleton::closeDialog()
{
Gui::DockWnd::ComboView* 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();
}
void ControlSingleton::closedDialog()
{
ActiveDialog = 0;
Gui::DockWnd::ComboView* pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
// should return the pointer to combo view
assert(pcComboView);
pcComboView->closedDialog();
// make sure that the combo view is shown
QDockWidget* dw = qobject_cast<QDockWidget*>(pcComboView->parentWidget());
if (dw)
dw->setFeatures(QDockWidget::DockWidgetClosable
| QDockWidget::DockWidgetMovable
| QDockWidget::DockWidgetFloatable);
}
bool ControlSingleton::isAllowedAlterDocument(void) const
{
if (ActiveDialog)
return ActiveDialog->isAllowedAlterDocument();
return true;
}
bool ControlSingleton::isAllowedAlterView(void) const
{
if (ActiveDialog)
return ActiveDialog->isAllowedAlterView();
return true;
}
bool ControlSingleton::isAllowedAlterSelection(void) const
{
if (ActiveDialog)
return ActiveDialog->isAllowedAlterSelection();
return true;
}
// -------------------------------------------
ControlSingleton& ControlSingleton::instance(void)
{
if (_pcSingleton == NULL)
_pcSingleton = new ControlSingleton;
return *_pcSingleton;
}
void ControlSingleton::destruct (void)
{
if (_pcSingleton != NULL)
delete _pcSingleton;
_pcSingleton = 0;
}
// -------------------------------------------
#include "moc_Control.cpp"