Debian Codegraph @

src/Gui/TaskView/TaskView.h

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 #ifndef GUI_TASKVIEW_TASKVIEW_H
26 #define GUI_TASKVIEW_TASKVIEW_H
27
28 #include <vector>
29 #include <QScrollArea>
30
31 #include <Base/Parameter.h>
32 #include <Gui/QSint/include/QSint>
33 #include <Gui/Selection/Selection.h>
34 #include "TaskWatcher.h"
35
36
37 namespace App
38 {
39 class Property;
40 }
41
42 namespace Gui
43 {
44 class MDIView;
45 class ControlSingleton;
46 class ViewProviderDocumentObject;
47 namespace DockWnd
48 {
49 class ComboView;
50 }
51 namespace TaskView
52 {
53
54 using Connection = boost::signals2::connection;
55 class TaskEditControl;
56 class TaskDialog;
57
58 /// Father class of all content in TaskView
59 class GuiExport TaskContent {
60
61 public :
62 // TaskContent();
63 //~TaskContent();
64 };
65
66 class GuiExport TaskGroup: public QSint::ActionBox, public TaskContent
67 {
68 Q_OBJECT
69
70 public:
71 explicit TaskGroup(QWidget* parent = nullptr);
72 explicit TaskGroup(const QString& headerText, QWidget* parent = nullptr);
73 explicit TaskGroup(const QPixmap& icon, const QString& headerText, QWidget* parent = nullptr);
74 ~TaskGroup() override;
75
76 protected:
77 void actionEvent(QActionEvent*) override;
78 };
79
80 /// Father class of content with header and Icon
81 class GuiExport TaskBox: public QSint::ActionGroup, public TaskContent
82 {
83 Q_OBJECT
84
85 public:
86 /** Constructor. Creates TaskBox without header.
87 */
88 explicit TaskBox(QWidget* parent = nullptr);
89
90 /** Constructor. Creates TaskBox with header's
91 text set to \a title, but with no icon.
92
93 If \a expandable set to \a true (default), the group can be expanded/collapsed by the user.
94 */
95 explicit TaskBox(const QString& title, bool expandable = true, QWidget* parent = nullptr);
96
97 /** Constructor. Creates TaskBox with header's
98 text set to \a title and icon set to \a icon.
99
100 If \a expandable set to \a true (default), the group can be expanded/collapsed by the user.
101 */
102 explicit TaskBox(
103 const QPixmap& icon,
104 const QString& title,
105 bool expandable = true,
106 QWidget* parent = nullptr
107 );
108 QSize minimumSizeHint() const override;
109
110 ~TaskBox() override;
111 void hideGroupBox();
112 bool isGroupVisible() const;
113
114 protected:
115 void showEvent(QShowEvent*) override;
116 void actionEvent(QActionEvent*) override;
117
118 private:
119 bool wasShown;
120 };
121
122 class GuiExport TaskPanel: public QSint::ActionPanel
123 {
124 Q_OBJECT
125
126 public:
127 explicit TaskPanel(QWidget* parent = nullptr);
128 ~TaskPanel() override;
129 QSize minimumSizeHint() const override;
130 };
131
132 /// Father class of content of a Free widget (without header and Icon), shut be an exception!
133 class GuiExport TaskWidget: public QWidget, public TaskContent
134 {
135 Q_OBJECT
136
137 public:
138 explicit TaskWidget(QWidget* parent = nullptr);
139 ~TaskWidget() override;
140 };
141
142 /** TaskView class
143 * handles the FreeCAD task view panel. Keeps track of the inserted content elements.
144 * This elements get injected mostly by the ViewProvider classes of the selected
145 * DocumentObjects.
146 */
147 class GuiExport TaskView: public QWidget, public Gui::SelectionSingleton::ObserverType
148 {
149 Q_OBJECT
150
151 public:
152 explicit TaskView(QWidget* parent = nullptr);
153 ~TaskView() override;
154
155 /// Observer message from the Selection
156 void OnChange(
157 Gui::SelectionSingleton::SubjectType& rCaller,
158 Gui::SelectionSingleton::MessageType Reason
159 ) override;
160
161 friend class Gui::DockWnd::ComboView;
162 friend class Gui::ControlSingleton;
163
164 void addTaskWatcher(const std::vector<TaskWatcher*>& Watcher);
165 void clearTaskWatcher();
166 void takeTaskWatcher(TaskView* other);
167
168 bool isEmpty(bool includeWatcher = true) const;
169
170 void clearActionStyle();
171 void restoreActionStyle();
172
173 /// Add a persistent panel at the top of the task view, independent of the active dialog.
174 void addContextualPanel(QWidget* panel);
175 void removeContextualPanel(QWidget* panel);
176
177 QSize minimumSizeHint() const override;
178
179 // Restore width before opening a task panel
180 void setRestoreWidth(bool on);
181 bool shouldRestoreWidth() const;
182
183 Q_SIGNALS:
184 void taskUpdate();
185
186 protected Q_SLOTS:
187 void accept();
188 void reject();
189 void helpRequested();
190 void clicked(QAbstractButton* button);
191
192 private:
193 void triggerMinimumSizeHint();
194 void adjustMinimumSizeHint();
195 void saveCurrentWidth();
196 void tryRestoreWidth();
197 void slotActiveDocument(const App::Document&);
198 void slotInEdit(const Gui::ViewProviderDocumentObject&);
199 void slotDeletedDocument(const App::Document&);
200 void slotViewClosed(const Gui::MDIView*);
201 void slotUndoDocument(const App::Document&);
202 void slotRedoDocument(const App::Document&);
203 void transactionChangeOnDocument(const App::Document&, bool undo);
204 QVBoxLayout* mainLayout;
205 QScrollArea* scrollArea;
206 QVBoxLayout* contextualPanelsLayout;
207 QVBoxLayout* dialogLayout;
208 QList<QWidget*> contextualPanels;
209
210 protected:
211 void keyPressEvent(QKeyEvent* event) override;
212 bool event(QEvent* event) override;
213
214 void addTaskWatcher();
215 void removeTaskWatcher();
216 /// update the visibility of the TaskWatcher accordant to the selection
217 void updateWatcher();
218 /// used by Gui::Control to register Dialogs
219 void showDialog(TaskDialog* dlg);
220 // removes the running dialog after accept() or reject() from the TaskView
221 void removeDialog();
222
223 void setShowTaskWatcher(bool show);
224
225 std::vector<TaskWatcher*> ActiveWatcher;
226
227 QSint::ActionPanel* taskPanel;
228 TaskDialog* ActiveDialog;
229 TaskEditControl* ActiveCtrl;
230 bool restoreWidth = false;
231 int currentWidth = 0;
232 ParameterGrp::handle hGrp;
233 bool showTaskWatcher;
234
235 Connection connectApplicationActiveDocument;
236 Connection connectApplicationDeleteDocument;
237 Connection connectApplicationClosedView;
238 Connection connectApplicationUndoDocument;
239 Connection connectApplicationRedoDocument;
240 Connection connectApplicationInEdit;
241 Connection connectShowTaskWatcherSetting;
242 };
243
244 } // namespace TaskView
245 } // namespace Gui
246
247 #endif // GUI_TASKVIEW_TASKVIEW_H