Debian Codegraph @

src/Gui/TaskView/TaskDialog.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /***************************************************************************
3 * Copyright (c) 2009 Jürgen Riegel <[email protected]> *
4 * *
5 * This file is part of the FreeCAD CAx development system. *
6 * *
7 * This library is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Library General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 2 of the License, or (at your option) any later version. *
11 * *
12 * This library is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with this library; see the file COPYING.LIB. If not, *
19 * write to the Free Software Foundation, Inc., 59 Temple Place, *
20 * Suite 330, Boston, MA 02111-1307, USA *
21 * *
22 ***************************************************************************/
23
24
25 #include <QMessageBox>
26
27
28 #include <App/Document.h>
29 #include <Gui/Application.h>
30 #include <Gui/Document.h>
31 #include <Gui/MainWindow.h>
32 #include <Gui/View3DInventor.h>
33 #include <Gui/ViewProviderDocumentObject.h>
34
35
36 #include "TaskDialog.h"
37 #include "TaskView.h"
38
39 using namespace Gui::TaskView;
40
41
42 //**************************************************************************
43 //**************************************************************************
44 // TaskDialog
45 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46
47 TaskDialog::TaskDialog()
48 : QObject(nullptr)
49 , pos(North)
50 , escapeButton(true)
51 , autoCloseTransaction(false)
52 , autoCloseDeletedDocument(false)
53 , autoCloseClosedView(false)
54 {}
55
56 TaskDialog::~TaskDialog()
57 {
58 for (auto it : Content) {
59 delete it;
60 it = nullptr;
61 }
62 }
63
64 //==== Slots ===============================================================
65
66 QWidget* TaskDialog::addTaskBox(QWidget* widget, bool expandable, QWidget* parent)
67 {
68 return addTaskBox(QPixmap(), widget, expandable, parent);
69 }
70
71 QWidget* TaskDialog::addTaskBox(const QPixmap& icon, QWidget* widget, bool expandable, QWidget* parent)
72 {
73 auto taskbox = new Gui::TaskView::TaskBox(icon, widget->windowTitle(), expandable, parent);
74 taskbox->groupLayout()->addWidget(widget);
75 Content.push_back(taskbox);
76 return taskbox;
77 }
78
79 QWidget* TaskDialog::addTaskBoxWithoutHeader(QWidget* widget)
80 {
81 auto taskbox = new Gui::TaskView::TaskBox();
82 taskbox->groupLayout()->addWidget(widget);
83 Content.push_back(taskbox);
84 return taskbox;
85 }
86
87 const std::vector<QWidget*>& TaskDialog::getDialogContent() const
88 {
89 return Content;
90 }
91
92 bool TaskDialog::canClose() const
93 {
94 QMessageBox msgBox(Gui::getMainWindow());
95 msgBox.setText(tr("A dialog is already open in the task panel"));
96 msgBox.setInformativeText(QObject::tr("Close this dialog?"));
97 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
98 msgBox.setDefaultButton(QMessageBox::Yes);
99 int ret = msgBox.exec();
100 return (ret == QMessageBox::Yes);
101 }
102
103 void TaskDialog::associateToObject3dView(App::DocumentObject* obj)
104 {
105 if (!obj) {
106 return;
107 }
108
109 Gui::Document* guiDoc = Gui::Application::Instance->getDocument(obj->getDocument());
110 auto* vp = Gui::Application::Instance->getViewProvider(obj);
111 auto* vpdo = static_cast<Gui::ViewProviderDocumentObject*>(vp);
112 auto* view = guiDoc->openEditingView3D(vpdo);
113
114 if (!view) {
115 return;
116 }
117
118 setAssociatedView(view);
119 setAutoCloseOnClosedView(true);
120 }
121
122 //==== calls from the TaskView ===============================================================
123
124 void TaskDialog::open()
125 {}
126
127 void TaskDialog::closed()
128 {}
129
130 void TaskDialog::autoClosedOnTransactionChange()
131 {}
132
133 void TaskDialog::autoClosedOnDeletedDocument()
134 {}
135
136 void TaskDialog::autoClosedOnClosedView()
137 {}
138
139 void TaskDialog::clicked(int)
140 {}
141
142 bool TaskDialog::accept()
143 {
144 return true;
145 }
146
147 bool TaskDialog::reject()
148 {
149 return true;
150 }
151
152 void TaskDialog::helpRequested()
153 {}
154
155 void TaskDialog::onUndo()
156 {}
157
158 void TaskDialog::onRedo()
159 {}
160
161
162 #include "moc_TaskDialog.cpp"