Debian Codegraph @

src/Gui/TaskView/TaskWatcher.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 <QObject>
26 #include <App/Application.h>
27 #include <App/Document.h>
28 #include <Gui/Application.h>
29 #include <Gui/BitmapFactory.h>
30 #include <Gui/Command.h>
31 #include <Gui/TaskView/TaskView.h>
32
33 #include "TaskWatcher.h"
34
35
36 using namespace Gui::TaskView;
37
38
39 //**************************************************************************
40 //**************************************************************************
41 // TaskWatcher
42 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43
44 TaskWatcher::TaskWatcher(const char* Filter)
45 : QObject(nullptr)
46 , SelectionFilter(Filter)
47 {}
48
49 TaskWatcher::~TaskWatcher()
50 {
51 for (auto it : Content) {
52 delete it;
53 it = nullptr;
54 }
55 }
56
57 //==== implementer ===========================================================================
58
59 QWidget* TaskWatcher::addTaskBox(QWidget* widget, bool expandable, QWidget* parent)
60 {
61 return addTaskBox(QPixmap(), widget, expandable, parent);
62 }
63
64 QWidget* TaskWatcher::addTaskBox(const QPixmap& icon, QWidget* widget, bool expandable, QWidget* parent)
65 {
66 auto taskbox = new Gui::TaskView::TaskBox(icon, widget->windowTitle(), expandable, parent);
67 taskbox->groupLayout()->addWidget(widget);
68 Content.push_back(taskbox);
69 return taskbox;
70 }
71
72 QWidget* TaskWatcher::addTaskBoxWithoutHeader(QWidget* widget)
73 {
74 auto taskbox = new Gui::TaskView::TaskBox();
75 taskbox->groupLayout()->addWidget(widget);
76 Content.push_back(taskbox);
77 return taskbox;
78 }
79
80 std::vector<QWidget*>& TaskWatcher::getWatcherContent()
81 {
82 return Content;
83 }
84
85 //==== calls from the TaskView ===============================================================
86
87 bool TaskWatcher::shouldShow()
88 {
89 return false;
90 }
91
92 //**************************************************************************
93 //**************************************************************************
94 // TaskWatcherCommands
95 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
96
97 TaskWatcherCommands::TaskWatcherCommands(
98 const char* Filter,
99 const char* commands[],
100 const char* name,
101 const char* pixmap
102 )
103 : TaskWatcher(Filter)
104 {
105 if (commands) {
106 CommandManager& mgr = Gui::Application::Instance->commandManager();
107 auto tb = new Gui::TaskView::TaskBox(BitmapFactory().pixmap(pixmap), tr(name), true, nullptr);
108
109 for (const char** i = commands; *i; i++) {
110 Command* c = mgr.getCommandByName(*i);
111 if (c) {
112 // handled in TaskBox::actionEvent()
113 c->addTo(tb);
114 }
115 }
116
117 Content.push_back(tb);
118 }
119 }
120
121
122 //==== implementer ===========================================================================
123
124
125 //==== calls from the TaskView ===============================================================
126
127 bool TaskWatcherCommands::shouldShow()
128 {
129 return match();
130 }
131
132 //**************************************************************************
133 //**************************************************************************
134 // TaskWatcherCommandsEmptyDoc
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136
137 TaskWatcherCommandsEmptyDoc::TaskWatcherCommandsEmptyDoc(
138 const char* commands[],
139 const char* name,
140 const char* pixmap
141 )
142 : TaskWatcherCommands(nullptr, commands, name, pixmap)
143 {}
144
145
146 //==== implementer ===========================================================================
147
148
149 //==== calls from the TaskView ===============================================================
150
151 bool TaskWatcherCommandsEmptyDoc::shouldShow()
152 {
153 App::Document* doc = App::GetApplication().getActiveDocument();
154 return doc && doc->countObjects() == 0;
155 }
156
157 //**************************************************************************
158 //**************************************************************************
159 // TaskWatcherCommandsEmptySelection
160 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
161
162 TaskWatcherCommandsEmptySelection::TaskWatcherCommandsEmptySelection(
163 const char* commands[],
164 const char* name,
165 const char* pixmap
166 )
167 : TaskWatcherCommands(nullptr, commands, name, pixmap)
168 {}
169
170 TaskWatcherCommandsEmptySelection::~TaskWatcherCommandsEmptySelection() = default;
171
172 //==== implementer ===========================================================================
173
174
175 //==== calls from the TaskView ===============================================================
176
177 bool TaskWatcherCommandsEmptySelection::shouldShow()
178 {
179 return (App::GetApplication().getActiveDocument() && Gui::Selection().size() == 0);
180 }
181
182
183 #include "moc_TaskWatcher.cpp"