1
/***************************************************************************
2
* Copyright 2011 (c) Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
28
# include <QApplication>
30
# include <QDockWidget>
34
#include <App/AutoTransaction.h>
35
#include <Gui/ComboView.h>
36
#include <Gui/DockWindowManager.h>
37
#include <Gui/MainWindow.h>
40
#include "BitmapFactory.h"
42
#include "TaskView/TaskView.h"
48
/* TRANSLATOR Gui::ControlSingleton */
50
ControlSingleton* ControlSingleton::_pcSingleton = nullptr;
52
ControlSingleton::ControlSingleton()
53
: ActiveDialog(nullptr)
59
ControlSingleton::~ControlSingleton() = default;
61
Gui::TaskView::TaskView* ControlSingleton::taskPanel() const
63
auto taskView = qobject_cast<Gui::TaskView::TaskView*>
64
(Gui::DockWindowManager::instance()->getDockWindow("Tasks"));
68
void ControlSingleton::showDockWidget(QWidget* widget)
70
QWidget* parent = widget->parentWidget();
77
QTabBar* ControlSingleton::findTabBar(QDockWidget* widget) const
79
int count = getMainWindow()->tabifiedDockWidgets(widget).size() + 1;
81
QList<QTabBar*> bars = getMainWindow()->findChildren<QTabBar*>();
82
for (auto it : bars) {
83
if (it->count() <= count) {
84
for (int i = 0; i < count; i++) {
85
if (it->tabText(i) == widget->windowTitle()) {
96
void ControlSingleton::aboutToShowDialog(QDockWidget* widget)
98
static QIcon icon = Gui::BitmapFactory().pixmap("edit-edit.svg");
99
QTabBar* bar = findTabBar(widget);
101
oldTabIndex = bar->currentIndex();
102
for (int i = 0; i < bar->count(); i++) {
103
if (bar->tabText(i) == widget->windowTitle()) {
104
bar->setTabIcon(i, icon);
114
void ControlSingleton::aboutToHideDialog(QDockWidget* widget)
116
QTabBar* bar = findTabBar(widget);
118
bar->setCurrentIndex(oldTabIndex);
119
for (int i = 0; i < bar->count(); i++) {
120
if (bar->tabText(i) == widget->windowTitle()) {
121
bar->setTabIcon(i, QIcon());
128
void ControlSingleton::showTaskView()
130
Gui::TaskView::TaskView* taskView = taskPanel();
132
showDockWidget(taskView);
136
void ControlSingleton::showModelView()
138
auto treeView = qobject_cast<Gui::TreeDockWidget*>
139
(Gui::DockWindowManager::instance()->getDockWindow("Tree view"));
141
showDockWidget(treeView);
144
auto comboView = qobject_cast<Gui::DockWnd::ComboView*>
145
(Gui::DockWindowManager::instance()->getDockWindow("Model"));
147
showDockWidget(comboView);
152
void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg)
154
// only one dialog at a time, print a warning instead of raising an assert
155
if (ActiveDialog && ActiveDialog != dlg) {
157
qWarning() << "ControlSingleton::showDialog: Can't show "
158
<< dlg->metaObject()->className()
159
<< " since there is already an active task dialog";
162
qWarning() << "ControlSingleton::showDialog: Task dialog is null";
167
// Since the caller sets up a modeless task panel, it indicates intention
168
// for prolonged editing. So disable auto transaction in the current call
170
// Do this before showing the dialog because its open() function is called
171
// which may open a transaction but fails when auto transaction is still active.
172
App::AutoTransaction::setEnable(false);
174
Gui::TaskView::TaskView* taskView = taskPanel();
175
// should return the pointer to combo view
177
taskView->showDialog(dlg);
179
// make sure that the combo view is shown
180
auto dw = qobject_cast<QDockWidget*>(taskView->parentWidget());
182
aboutToShowDialog(dw);
183
dw->setVisible(true);
184
dw->toggleViewAction()->setVisible(true);
185
dw->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
188
if (ActiveDialog == dlg)
189
return; // dialog is already defined
191
connect(dlg, &TaskView::TaskDialog::aboutToBeDestroyed,
192
this, &ControlSingleton::closedDialog);
196
Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const
201
void ControlSingleton::accept()
203
Gui::TaskView::TaskView* taskView = taskPanel();
206
qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
207
QEventLoop::ExcludeSocketNotifiers);
211
void ControlSingleton::reject()
213
Gui::TaskView::TaskView* taskView = taskPanel();
216
qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
217
QEventLoop::ExcludeSocketNotifiers);
221
void ControlSingleton::closeDialog()
223
Gui::TaskView::TaskView* taskView = taskPanel();
225
taskView->removeDialog();
228
void ControlSingleton::closedDialog()
230
ActiveDialog = nullptr;
231
Gui::TaskView::TaskView* taskView = taskPanel();
234
// make sure that the combo view is shown
235
auto dw = qobject_cast<QDockWidget*>(taskView->parentWidget());
237
aboutToHideDialog(dw);
238
dw->setFeatures(QDockWidget::DockWidgetClosable
239
| QDockWidget::DockWidgetMovable
240
| QDockWidget::DockWidgetFloatable);
244
bool ControlSingleton::isAllowedAlterDocument() const
247
return ActiveDialog->isAllowedAlterDocument();
252
bool ControlSingleton::isAllowedAlterView() const
255
return ActiveDialog->isAllowedAlterView();
259
bool ControlSingleton::isAllowedAlterSelection() const
262
return ActiveDialog->isAllowedAlterSelection();
266
// -------------------------------------------
268
ControlSingleton& ControlSingleton::instance()
271
_pcSingleton = new ControlSingleton;
272
return *_pcSingleton;
275
void ControlSingleton::destruct ()
279
_pcSingleton = nullptr;
283
// -------------------------------------------
286
#include "moc_Control.cpp"