1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 #ifndef QG_DIALOGFACTORY_H
28 #define QG_DIALOGFACTORY_H
29 
30 #include "rs_dialogfactoryinterface.h"
31 
32 class QG_PolylineEquidistantOptions;
33 class QG_SnapMiddleOptions;
34 class QG_SnapDistOptions;
35 class QG_ModifyOffsetOptions;
36 class QWidget;
37 
38 class QToolBar;
39 class QG_CoordinateWidget;
40 class QG_SelectionWidget;
41 class QG_MouseWidget;
42 class QG_ArcTangentialOptions;
43 class QG_PrintPreviewOptions;
44 //class PrintPreviewOptions;
45 class QG_CommandWidget;
46 class RS_Document;
47 class QG_LineAngleOptions;
48 class RS_Vector;
49 
50 #define QG_DIALOGFACTORY (RS_DialogFactory::instance()->getFactoryObject())
51 
52 /**
53  * This is the Qt implementation of a widget which can create and
54  * show dialogs.
55  */
56 class QG_DialogFactory: public RS_DialogFactoryInterface {
57 public:
58 	QG_DialogFactory(QWidget* parent, QToolBar* ow);
59 	~QG_DialogFactory() override;
60 
61 protected:
62 	/**
63 	 * Links factory to a widget that can host tool options.
64 	 */
65 	void setOptionWidget(QToolBar* ow);
66 public:
67 	/**
68 	 * Links this dialog factory to a coordinate widget.
69 	 */
setCoordinateWidget(QG_CoordinateWidget * cw)70 	void setCoordinateWidget(QG_CoordinateWidget* cw) override{
71 		coordinateWidget = cw;
72 	}
73 
74 	/**
75 	 * Links this dialog factory to a mouse widget.
76 	 */
setMouseWidget(QG_MouseWidget * mw)77 	void setMouseWidget(QG_MouseWidget* mw) override{
78 		mouseWidget = mw;
79 	}
80 
81 	/**
82 	 * Links this dialog factory to a selection widget.
83 	 */
setSelectionWidget(QG_SelectionWidget * sw)84 	void setSelectionWidget(QG_SelectionWidget* sw) override{
85 		selectionWidget = sw;
86 	}
87 
88 	/**
89 	 * Links this dialog factory to a command widget.
90 	 */
setCommandWidget(QG_CommandWidget * cw)91 	void setCommandWidget(QG_CommandWidget* cw) override{
92 		commandWidget = cw;
93 	}
94 
95 	/**
96 	 * @return command widget or nullptr.
97 	 */
getCommandWidget()98 	QG_CommandWidget* getCommandWidget() const{
99 		return commandWidget;
100 	}
101 
102 	/**
103 	 * Links the dialog factory to a main app window.
104 	 */
105 
106 	void requestWarningDialog(const QString& warning) override;
107 
108 	RS_Layer* requestNewLayerDialog(
109 			RS_LayerList* layerList = nullptr) override;
110 	RS_Layer* requestLayerRemovalDialog(
111 			RS_LayerList* layerList = nullptr) override;
112 	QStringList requestSelectedLayersRemovalDialog(
113 			RS_LayerList* layerList = nullptr) override;
114 	RS_Layer* requestEditLayerDialog(
115 			RS_LayerList* layerList = nullptr) override;
116 
117 	RS_BlockData requestNewBlockDialog(RS_BlockList* blockList) override;
118 	RS_Block* requestBlockRemovalDialog(
119 			RS_BlockList* blockList) override;
120 	QList<RS_Block*> requestSelectedBlocksRemovalDialog(
121 			RS_BlockList* blockList = nullptr) override;
122 	RS_BlockData requestBlockAttributesDialog(
123 			RS_BlockList* blockList) override;
requestEditBlockWindow(RS_BlockList *)124 	void requestEditBlockWindow(RS_BlockList* /*blockList*/) override{}
closeEditBlockWindow(RS_Block *)125 	void closeEditBlockWindow(RS_Block* /*blockList*/) override{}
126 	//QString requestFileSaveAsDialog() override;
127 	//QString requestFileOpenDialog() override;
128 
129 	QString requestImageOpenDialog() override;
130 
131 
132 	void requestOptions(RS_ActionInterface* action,
133 								bool on, bool update = false) override;
134 
135 protected:
136 	void requestPrintPreviewOptions(RS_ActionInterface* action,
137 											bool on, bool update);
138 	void requestLineOptions(RS_ActionInterface* action,
139 									bool on);
140 	void requestPolylineOptions(RS_ActionInterface* action,
141 										bool on, bool update);
142 	void requestPolylineEquidistantOptions(RS_ActionInterface* action, bool on, bool update=false);
143 	void requestLineAngleOptions(RS_ActionInterface* action,
144 										 bool on, bool update);
145 	void requestLineRelAngleOptions(RS_ActionInterface* action,
146 											bool on, bool update);
147 	void requestLineParallelOptions(RS_ActionInterface* action,
148 											bool on, bool update);
149 	void requestLineParallelThroughOptions(RS_ActionInterface* action,
150 												   bool on, bool update);
151 	void requestLineBisectorOptions(RS_ActionInterface* action,
152 											bool on, bool update);
153 	void requestLinePolygonOptions(RS_ActionInterface* action,
154 										   bool on, bool update);
155 	void requestLinePolygon2Options(RS_ActionInterface* action,
156 											bool on, bool update);
157 
158 	void requestArcOptions(RS_ActionInterface* action,
159 								   bool on, bool update);
160 
161 	void requestArcTangentialOptions(RS_ActionInterface* action,
162 											 bool on, bool update);
163 
164 	void requestCircleOptions(RS_ActionInterface* action,
165 									  bool on, bool update);
166 
167 	void requestCircleTan2Options(RS_ActionInterface* action,
168 										  bool on, bool update);
169 
170 	void requestSplineOptions(RS_ActionInterface* action,
171 									  bool on, bool update);
172 
173 	void requestMTextOptions(RS_ActionInterface* action,
174 									 bool on, bool update);
175 
176 	void requestTextOptions(RS_ActionInterface* action,
177 									bool on, bool update);
178 
179 	void requestDimensionOptions(RS_ActionInterface* action,
180 										 bool on, bool update);
181 	void requestDimLinearOptions(RS_ActionInterface* action,
182 										 bool on, bool update);
183 
184 	void requestInsertOptions(RS_ActionInterface* action,
185 									  bool on, bool update);
186 	void requestImageOptions(RS_ActionInterface* action,
187 									 bool on, bool update);
188 
189 	void requestTrimAmountOptions(RS_ActionInterface* action,
190 										  bool on, bool update);
191 	void requestMoveRotateOptions(RS_ActionInterface* action,
192 										  bool on, bool update);
193 	void requestBevelOptions(RS_ActionInterface* action,
194 									 bool on, bool update);
195 	void requestRoundOptions(RS_ActionInterface* action,
196 									 bool on, bool update);
197 	void requestLibraryInsertOptions(RS_ActionInterface* action,
198 											 bool on, bool update);
199 
200 public:
201 	void requestSnapDistOptions(double& dist, bool on) override;
202 	void requestSnapMiddleOptions(int& middlePoints, bool on) override;
203 
204 public:
205 
206 	bool requestAttributesDialog(RS_AttributesData& data,
207 										 RS_LayerList& layerList) override;
208 	bool requestMoveDialog(RS_MoveData& data) override;
209 	bool requestRotateDialog(RS_RotateData& data) override;
210 	bool requestScaleDialog(RS_ScaleData& data) override;
211 	bool requestMirrorDialog(RS_MirrorData& data) override;
212 	bool requestMoveRotateDialog(RS_MoveRotateData& data) override;
213 	bool requestRotate2Dialog(RS_Rotate2Data& data) override;
214 
215 	bool requestModifyEntityDialog(RS_Entity* entity) override;
216 	void requestModifyOffsetOptions(double& dist, bool on) override;
217 	bool requestMTextDialog(RS_MText* text) override;
218 	bool requestTextDialog(RS_Text* text) override;
219 	bool requestHatchDialog(RS_Hatch* hatch) override;
220 	void requestOptionsGeneralDialog() override;
221 	void requestOptionsDrawingDialog(RS_Graphic& graphic) override;
222 	bool requestOptionsMakerCamDialog() override;
223 
224 	QString requestFileSaveAsDialog(const QString& caption = QString(),
225 											const QString& dir = QString(),
226 											const QString& filter = QString(),
227 											QString* selectedFilter = 0) override;
228 
229 	void updateCoordinateWidget(const RS_Vector& abs, const RS_Vector& rel, bool updateFormat=false) override;
230 	/**
231 	 * \brief updateMouseWidget Called when an action has a mouse hint.
232 	 * \param left mouse hint for left button
233 	 * \param right mouse hint for right button
234 	 */
235 	void updateMouseWidget(const QString& left=QString(),
236 								   const QString& right=QString()) override;
237 	void updateSelectionWidget(int num, double length) override;//updated for total number of selected, and total length of selected
238 	void commandMessage(const QString& message) override;
239 
240 	static QString extToFormat(const QString& ext);
241 	void updateArcTangentialOptions(const double& d, bool byRadius) override;
242 
243 
244 
245 protected:
246 	//! Pointer to the widget which can host dialogs
247 	QWidget* parent;
248 	//! Pointer to the widget which can host individual tool options
249 	QToolBar* optionWidget;
250 	//! Pointer to the coordinate widget.
251 	QG_CoordinateWidget* coordinateWidget;
252 	//! Pointer to the mouse widget.
253 	QG_MouseWidget* mouseWidget;
254 	//! Pointer to the selection widget.
255 	QG_SelectionWidget* selectionWidget;
256 	//! Pointer to the command line widget
257 	QG_CommandWidget* commandWidget;
258 	//! Pointer to arcTangential Option widge
259 	QG_ArcTangentialOptions* arcTangentialOptions;
260 	QG_PolylineEquidistantOptions* polylineEquidistantOptions;
261 private:
262 	// pointers to snap option widgets
263 	QG_SnapMiddleOptions* snapMiddleOptions;
264 	QG_SnapDistOptions* snapDistOptions;
265 	QG_ModifyOffsetOptions* modifyOffsetOptions;
266 	QG_PrintPreviewOptions* printPreviewOptions;
267 	QG_LineAngleOptions* m_pLineAngleOptions;
268 };
269 
270 #endif
271