| 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_TASKDIALOG_H |
| 26 |
#define GUI_TASKVIEW_TASKDIALOG_H |
| 27 |
|
| 28 |
#include <string> |
| 29 |
#include <vector> |
| 30 |
|
| 31 |
#include <QDialogButtonBox> |
| 32 |
#include <QPointer> |
| 33 |
#include <FCGlobal.h> |
| 34 |
|
| 35 |
|
| 36 |
namespace App |
| 37 |
{ |
| 38 |
class DocumentObject; |
| 39 |
} |
| 40 |
|
| 41 |
namespace Gui |
| 42 |
{ |
| 43 |
class MDIView; |
| 44 |
namespace TaskView |
| 45 |
{ |
| 46 |
|
| 47 |
class TaskContent; |
| 48 |
class TaskDialogAttorney; |
| 49 |
class TaskDialogPy; |
| 50 |
class TaskView; |
| 51 |
|
| 52 |
/// Father class of content with header and Icon |
| 53 |
class GuiExport TaskDialog: public QObject |
| 54 |
{ |
| 55 |
Q_OBJECT |
| 56 |
|
| 57 |
public: |
| 58 |
enum ButtonPosition |
| 59 |
{ |
| 60 |
North, |
| 61 |
South |
| 62 |
}; |
| 63 |
|
| 64 |
TaskDialog(); |
| 65 |
~TaskDialog() override; |
| 66 |
|
| 67 |
QWidget* addTaskBox(QWidget* widget, bool expandable = true, QWidget* parent = nullptr); |
| 68 |
QWidget* addTaskBox( |
| 69 |
const QPixmap& icon, |
| 70 |
QWidget* widget, |
| 71 |
bool expandable = true, |
| 72 |
QWidget* parent = nullptr |
| 73 |
); |
| 74 |
QWidget* addTaskBoxWithoutHeader(QWidget* widget); |
| 75 |
|
| 76 |
void setButtonPosition(ButtonPosition p) |
| 77 |
{ |
| 78 |
pos = p; |
| 79 |
} |
| 80 |
ButtonPosition buttonPosition() const |
| 81 |
{ |
| 82 |
return pos; |
| 83 |
} |
| 84 |
const std::vector<QWidget*>& getDialogContent() const; |
| 85 |
bool canClose() const; |
| 86 |
|
| 87 |
/// tells the framework which buttons are wished for the dialog |
| 88 |
virtual QDialogButtonBox::StandardButtons getStandardButtons() const |
| 89 |
{ |
| 90 |
return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; |
| 91 |
} |
| 92 |
virtual void modifyStandardButtons(QDialogButtonBox*) |
| 93 |
{} |
| 94 |
|
| 95 |
/// Defines whether a task dialog can be rejected by pressing Esc |
| 96 |
void setEscapeButtonEnabled(bool on) |
| 97 |
{ |
| 98 |
escapeButton = on; |
| 99 |
} |
| 100 |
bool isEscapeButtonEnabled() const |
| 101 |
{ |
| 102 |
return escapeButton; |
| 103 |
} |
| 104 |
|
| 105 |
/// Defines whether a task dialog must be closed if the document changed the |
| 106 |
/// active transaction. |
| 107 |
void setAutoCloseOnTransactionChange(bool on) |
| 108 |
{ |
| 109 |
autoCloseTransaction = on; |
| 110 |
} |
| 111 |
bool isAutoCloseOnTransactionChange() const |
| 112 |
{ |
| 113 |
return autoCloseTransaction; |
| 114 |
} |
| 115 |
|
| 116 |
/// Defines whether a task dialog must be closed if the document is |
| 117 |
/// deleted. |
| 118 |
void setAutoCloseOnDeletedDocument(bool on) |
| 119 |
{ |
| 120 |
autoCloseDeletedDocument = on; |
| 121 |
} |
| 122 |
bool isAutoCloseOnDeletedDocument() const |
| 123 |
{ |
| 124 |
return autoCloseDeletedDocument; |
| 125 |
} |
| 126 |
|
| 127 |
const std::string& getDocumentName() const |
| 128 |
{ |
| 129 |
return documentName; |
| 130 |
} |
| 131 |
void setDocumentName(const std::string& doc) |
| 132 |
{ |
| 133 |
documentName = doc; |
| 134 |
} |
| 135 |
|
| 136 |
/// Defines whether a task dialog must be closed if the associated view |
| 137 |
/// is deleted. |
| 138 |
void setAutoCloseOnClosedView(bool on) |
| 139 |
{ |
| 140 |
autoCloseClosedView = on; |
| 141 |
} |
| 142 |
bool isAutoCloseOnClosedView() const |
| 143 |
{ |
| 144 |
return autoCloseClosedView; |
| 145 |
} |
| 146 |
void associateToObject3dView(App::DocumentObject* obj); |
| 147 |
|
| 148 |
const Gui::MDIView* getAssociatedView() const |
| 149 |
{ |
| 150 |
return associatedView; |
| 151 |
} |
| 152 |
void setAssociatedView(const Gui::MDIView* view) |
| 153 |
{ |
| 154 |
associatedView = view; |
| 155 |
} |
| 156 |
|
| 157 |
/*! |
| 158 |
Indicates whether this task dialog allows other commands to modify |
| 159 |
the document while it is open. |
| 160 |
*/ |
| 161 |
virtual bool isAllowedAlterDocument() const |
| 162 |
{ |
| 163 |
return false; |
| 164 |
} |
| 165 |
/*! |
| 166 |
Indicates whether this task dialog allows other commands to modify |
| 167 |
the 3d view while it is open. |
| 168 |
*/ |
| 169 |
virtual bool isAllowedAlterView() const |
| 170 |
{ |
| 171 |
return true; |
| 172 |
} |
| 173 |
/*! |
| 174 |
Indicates whether this task dialog allows other commands to modify |
| 175 |
the selection while it is open. |
| 176 |
*/ |
| 177 |
virtual bool isAllowedAlterSelection() const |
| 178 |
{ |
| 179 |
return true; |
| 180 |
} |
| 181 |
virtual bool needsFullSpace() const |
| 182 |
{ |
| 183 |
return false; |
| 184 |
} |
| 185 |
|
| 186 |
public: |
| 187 |
/// is called by the framework when the dialog is opened |
| 188 |
virtual void open(); |
| 189 |
/// is called by the framework when the dialog is closed |
| 190 |
virtual void closed(); |
| 191 |
/// is called by the framework when the dialog is automatically closed due to |
| 192 |
/// changing the active transaction |
| 193 |
virtual void autoClosedOnTransactionChange(); |
| 194 |
/// is called by the framework when the dialog is automatically closed due to |
| 195 |
/// deleting the document |
| 196 |
virtual void autoClosedOnDeletedDocument(); |
| 197 |
/// is called by the framework when the dialog is automatically closed due to |
| 198 |
/// closing of associated view |
| 199 |
virtual void autoClosedOnClosedView(); |
| 200 |
/// is called by the framework if a button is clicked which has no accept or reject role |
| 201 |
virtual void clicked(int); |
| 202 |
/// is called by the framework if the dialog is accepted (Ok) |
| 203 |
virtual bool accept(); |
| 204 |
/// is called by the framework if the dialog is rejected (Cancel) |
| 205 |
virtual bool reject(); |
| 206 |
/// is called by the framework if the user press the help button |
| 207 |
virtual void helpRequested(); |
| 208 |
/// is called by the framework if the user press the undo button |
| 209 |
virtual void onUndo(); |
| 210 |
/// is called by the framework if the user press the redo button |
| 211 |
virtual void onRedo(); |
| 212 |
|
| 213 |
void emitDestructionSignal() |
| 214 |
{ |
| 215 |
Q_EMIT aboutToBeDestroyed(); |
| 216 |
} |
| 217 |
|
| 218 |
Q_SIGNALS: |
| 219 |
void aboutToBeDestroyed(); |
| 220 |
|
| 221 |
protected: |
| 222 |
QPointer<QDialogButtonBox> buttonBox; |
| 223 |
/// List of TaskBoxes of that dialog |
| 224 |
std::vector<QWidget*> Content; |
| 225 |
ButtonPosition pos; |
| 226 |
|
| 227 |
private: |
| 228 |
std::string documentName; |
| 229 |
const Gui::MDIView* associatedView; |
| 230 |
bool escapeButton; |
| 231 |
bool autoCloseTransaction; |
| 232 |
bool autoCloseDeletedDocument; |
| 233 |
bool autoCloseClosedView; |
| 234 |
|
| 235 |
friend class TaskDialogAttorney; |
| 236 |
}; |
| 237 |
|
| 238 |
class TaskDialogAttorney |
| 239 |
{ |
| 240 |
private: |
| 241 |
static void setButtonBox(TaskDialog* dlg, QDialogButtonBox* box) |
| 242 |
{ |
| 243 |
dlg->buttonBox = box; |
| 244 |
} |
| 245 |
static QDialogButtonBox* getButtonBox(TaskDialog* dlg) |
| 246 |
{ |
| 247 |
return dlg->buttonBox; |
| 248 |
} |
| 249 |
|
| 250 |
friend class TaskDialogPy; |
| 251 |
friend class TaskView; |
| 252 |
}; |
| 253 |
|
| 254 |
} // namespace TaskView |
| 255 |
} // namespace Gui |
| 256 |
|
| 257 |
#endif // GUI_TASKVIEW_TASKDIALOG_H |