1 // qg_dialogfactory.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/10/2010 Added this text. :-)
17 #include "qg_dialogfactory.h"
19 #include "graphicview.h"
20 #include "qg_layerwidget.h"
21 #include "qg_mainwindowinterface.h"
22 #include "actiondimlinear.h"
23 #include "actioninterface.h"
24 #include "rs_blocklist.h"
25 #include "rs_document.h"
27 #include "rs_patternlist.h"
29 #include "rs_system.h"
32 #include "arcoptions.h"
33 #include "arctangentialoptions.h"
34 #include "beveloptions.h"
35 #include "blockdialog.h"
36 #include "cadtoolbar.h"
37 #include "circleoptions.h"
38 #include "commandwidget.h"
39 #include "coordinatewidget.h"
40 #include "dimlinearoptions.h"
41 #include "dimoptions.h"
43 #include "dlgattributes.h"
44 #include "dlgcircle.h"
45 #include "dlgdimension.h"
46 #include "dlgdimlinear.h"
47 #include "dlgellipse.h"
49 #include "dlginsert.h"
51 #include "dlgmirror.h"
53 #include "dlgmoverotate.h"
54 #include "dlgoptionsdrawing.h"
55 #include "dlgoptionsgeneral.h"
57 #include "dlgrotate.h"
58 #include "dlgrotate2.h"
60 #include "dlgspline.h"
62 #include "libraryinsertoptions.h"
63 #include "imageoptions.h"
64 #include "insertoptions.h"
65 #include "layerdialog.h"
66 #include "lineangleoptions.h"
67 #include "linebisectoroptions.h"
68 #include "lineoptions.h"
69 #include "lineparalleloptions.h"
70 #include "lineparallelthroughoptions.h"
71 #include "linepolygon2options.h"
72 #include "linepolygonoptions.h"
73 #include "linerelangleoptions.h"
74 #include "mousewidget.h"
75 #include "moverotateoptions.h"
76 #include "printpreviewoptions.h"
77 #include "roundoptions.h"
78 #include "selectionwidget.h"
79 #include "snapdistoptions.h"
80 #include "splineoptions.h"
81 #include "textoptions.h"
82 #include "trimamountoptions.h"
85 #include "qg_polylineoptions.h"
89 #include "rs_camdialog.h"
92 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
97 * @param parent Pointer to parent widget which can host dialogs.
98 * @param ow Pointer to widget that can host option widgets.
100 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
101 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
102 RS_DialogFactoryInterface()
104 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
106 this->parent = parent;
109 coordinateWidget = NULL;
111 selectionWidget = NULL;
113 commandWidget = NULL;
115 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
121 QG_DialogFactory::~QG_DialogFactory()
123 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
124 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
128 * Links factory to a widget that can host tool options.
130 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
131 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
133 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
135 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
139 * Links this dialog factory to a coordinate widget.
141 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
143 coordinateWidget = cw;
147 * Links this dialog factory to a mouse widget.
149 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
155 * Links this dialog factory to a selection widget.
157 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
159 selectionWidget = sw;
163 * Links this dialog factory to the cad tool bar.
165 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
171 * @return cad tool bar or NULL.
173 CadToolBar * QG_DialogFactory::getCadToolBar()
179 * Links this dialog factory to a command widget.
181 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
187 * @return command widget or NULL.
189 CommandWidget * QG_DialogFactory::getCommandWidget()
191 return commandWidget;
195 * Links the dialog factory to a main app window.
197 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
203 * Shows a message dialog.
205 void QG_DialogFactory::requestWarningDialog(const QString & warning)
207 QMessageBox::information(parent, QMessageBox::tr("Warning"),
208 warning, QMessageBox::Ok);
212 * Requests a new document from the main window.
214 GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
216 if (mainWindow != NULL)
218 mainWindow->createNewDocument(fileName, doc);
219 return mainWindow->getGraphicView();
226 * Requests the simulation controls.
228 void QG_DialogFactory::requestSimulationControls()
230 if (mainWindow != NULL)
232 mainWindow->showSimulationControls();
237 * Shows a dialog for adding a layer. Doesn't add the layer.
238 * This is up to the caller.
240 * @return a pointer to the newly created layer that
243 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
245 RS_Layer * layer = NULL;
246 QString layer_name = "noname";
249 if (layerList != NULL)
251 while (layerList->find(layer_name) > 0)
252 layer_name.sprintf("noname%d", i++);
255 // Layer for parameter livery
256 layer = new RS_Layer(layer_name);
258 // QG_LayerDialog dlg(parent, "Layer Dialog");
259 LayerDialog dlg(parent);
261 dlg.setLayerList(layerList);
275 * Shows a dialog that asks the user if the selected layer
276 * can be removed. Doesn't remove the layer. This is up to the caller.
278 * @return a pointer to the layer that should be removed.
280 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
282 RS_Layer * layer = NULL;
284 if (layerList == NULL)
286 RS_DEBUG->print(RS_Debug::D_WARNING,
287 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
292 if (layerList==NULL) {
293 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
294 layerList = (RS_LayerList*)container;
300 // Layer for parameter livery
301 layer = layerList->getActive();
305 if (layer->getName() != "0")
307 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
308 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
309 QMessageBox::Ok, QMessageBox::Cancel);
321 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
322 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
331 * Shows a dialog for editing a layer. A new layer is created and
332 * returned. Modifying the layer is up to the caller.
334 * @return A pointer to a new layer with the changed attributes
335 * or NULL if the dialog was cancelled.
337 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
339 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
340 RS_Layer * layer = NULL;
342 if (layerList==NULL) {
343 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
344 layerList = (RS_LayerList*)container;
351 if (layerList == NULL)
353 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
354 "layerList is NULL");
358 // Layer for parameter livery
359 if (layerList->getActive() != NULL)
361 layer = new RS_Layer(*layerList->getActive());
363 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
364 LayerDialog dlg(parent);
366 dlg.setLayerList(layerList);
367 dlg.setEditLayer(true);
382 * Shows a dialog for adding a block. Doesn't add the block.
383 * This is up to the caller.
385 * @return a pointer to the newly created block that
388 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
390 //RS_Block* block = NULL;
392 ret = RS_BlockData("", Vector(false), false);
394 if (blockList == NULL)
396 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
397 "blockList is NULL");
401 // Block for parameter livery
402 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
404 BlockDialog dlg(parent);
405 dlg.setBlockList(blockList);
408 ret = dlg.getBlockData();
414 * Shows a dialog for renaming the currently active block.
416 * @return a pointer to the modified block or NULL on cancellation.
418 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
420 //RS_Block* block = NULL;
422 ret = RS_BlockData("", Vector(false), false);
424 if (blockList == NULL)
426 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
427 "blockList is NULL");
431 if (blockList==NULL) {
432 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
433 blockList = (RS_BlockList*)container;
439 // Block for parameter livery
440 //block = blockList->getActive();
442 BlockDialog dlg(parent);//WAS:, "Rename Block");
443 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
444 dlg.setWindowTitle(QObject::tr("Rename Block"));
445 dlg.setBlockList(blockList);
451 ret = dlg.getBlockData();
454 // ret = RS_BlockData("", Vector(false));
460 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
464 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
469 * Shows a dialog that asks the user if the selected block
470 * can be removed. Doesn't remove the block. This is up to the caller.
472 * @return a pointer to the block that should be removed.
474 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
476 RS_Block * block = NULL;
478 if (blockList == NULL)
480 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
481 "blockList is NULL");
485 // Block for parameter livery
486 block = blockList->getActive();
490 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
491 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
492 QMessageBox::Ok, QMessageBox::Cancel);
507 * Shows a dialog for choosing a file name. Saving the file is up to
510 * @return File name with path and extension to determine the file type
511 * or an empty string if the dialog was cancelled.
514 QString QG_DialogFactory::requestFileSaveAsDialog() {
515 // read default settings:
516 RS_SETTINGS->beginGroup("/Paths");
517 QString defDir = RS_SETTINGS->readEntry("/Save",
518 RS_SYSTEM->getHomeDir());
519 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
520 "Drawing Exchange (*.dxf)");
521 RS_SETTINGS->endGroup();
523 // prepare file save as dialog:
524 QFileDialog fileDlg(this,0,true);
530 filters.append("Drawing Exchange (*.dxf)");
531 filters.append("Font (*.cxf)");
532 fileDlg.setFilters(filters);
533 fileDlg.setMode(QFileDialog::AnyFile);
534 fileDlg.setCaption(tr("Save Drawing As"));
535 fileDlg.setDir(defDir);
536 fileDlg.setSelectedFilter(defFilter);
541 if (fileDlg.exec()==QDialog::Accepted) {
542 fn = fileDlg.selectedFile();
545 // append default extension:
546 if (fn.find('.')==-1) {
547 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
554 // overwrite warning:
555 if(QFileInfo(fn).exists()) {
557 QMessageBox::warning(this, tr("Save Drawing As"),
558 tr("%1 already exists.\n"
559 "Do you want to replace it?")
562 tr("Cancel"), 0, 1 );
585 // store new default settings:
587 RS_SETTINGS->beginGroup("/Paths");
588 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
589 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
590 RS_SETTINGS->endGroup();
598 * Shows a dialog for choosing a file name. Opening the file is up to
601 * @return File name with path and extension to determine the file type
602 * or an empty string if the dialog was cancelled.
604 QString QG_DialogFactory::requestImageOpenDialog()
608 // read default settings:
609 settings.beginGroup("Paths");
610 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
611 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
616 // Q3FileDialog fileDlg(NULL, "", true);
617 QFileDialog fileDlg(NULL, "");
620 // Q3StrList f = QImageIO::inputFormats();
621 // QStringList formats = QStringList::fromStrList(f);
622 QList<QByteArray> f = QImageReader::supportedImageFormats();
623 QStringList formats = ???
625 #warning "Needs porting to Qt4... !!! FIX !!!"
630 //filters = QStringList::fromStrList(formats);
633 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
641 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
645 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
655 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
659 all += QString("*.%1").arg(QString(*it).lower());
664 filters.append(QObject::tr("All Image Files (%1)").arg(all));
665 filters.append(QObject::tr("All Files (*.*)"));
667 //filters.append("Drawing Exchange (*.)");
668 //filters.append("Font (*.cxf)");
670 fileDlg.setFilters(filters);
671 // fileDlg.setMode(Q3FileDialog::ExistingFile);
672 fileDlg.setFileMode(QFileDialog::ExistingFile);
673 // fileDlg.setCaption(QObject::tr("Open Image"));
674 fileDlg.setWindowTitle(QObject::tr("Open Image"));
675 // fileDlg.setDir(defDir);
676 fileDlg.setDirectory(defDir);
677 // fileDlg.setSelectedFilter(defFilter);
678 fileDlg.selectFilter(defFilter);
682 if (fileDlg.exec() == QDialog::Accepted)
684 // fn = fileDlg.selectedFile();
685 QStringList files = fileDlg.selectedFiles();
687 if (!files.isEmpty())
693 // store new default settings:
696 QStringList files = fileDlg.selectedFiles();
697 QString selected = "";
699 if (!files.isEmpty())
702 settings.beginGroup("Paths");
703 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
704 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
705 settings.setValue("ImageFilter", selected);
712 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
714 RS_DEBUG->print("QG_DialogFactory::requestOptions");
718 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
722 switch (action->rtti())
724 case RS2::ActionPrintPreview:
725 requestPrintPreviewOptions(action, on, update);
728 case RS2::ActionDrawLine:
729 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
730 requestLineOptions(action, on);
731 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
734 case RS2::ActionDrawPolyline:
735 requestPolylineOptions(action, on, update);
738 case RS2::ActionDrawLineAngle:
739 requestLineAngleOptions(action, on, update);
742 case RS2::ActionDrawLineParallel:
743 requestLineParallelOptions(action, on, update);
746 case RS2::ActionDrawLineParallelThrough:
747 requestLineParallelThroughOptions(action, on, update);
750 case RS2::ActionDrawLineBisector:
751 requestLineBisectorOptions(action, on, update);
754 case RS2::ActionDrawLineRelAngle:
755 requestLineRelAngleOptions(action, on, update);
758 case RS2::ActionDrawLinePolygon:
759 requestLinePolygonOptions(action, on, update);
762 case RS2::ActionDrawLinePolygon2:
763 requestLinePolygon2Options(action, on, update);
766 case RS2::ActionDrawArc:
767 requestArcOptions(action, on, update);
770 case RS2::ActionDrawArcTangential:
771 requestArcTangentialOptions(action, on, update);
774 case RS2::ActionDrawCircleCR:
775 requestCircleOptions(action, on, update);
778 case RS2::ActionDrawSpline:
779 requestSplineOptions(action, on, update);
782 case RS2::ActionDrawText:
783 requestTextOptions(action, on, update);
786 case RS2::ActionBlocksInsert:
787 requestInsertOptions(action, on, update);
790 case RS2::ActionDrawImage:
791 requestImageOptions(action, on, update);
794 case RS2::ActionDimAligned:
795 requestDimensionOptions(action, on, update);
798 case RS2::ActionDimLinear:
799 requestDimensionOptions(action, on, update);
801 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
802 requestDimLinearOptions(action, on, update);
806 case RS2::ActionDimRadial:
807 requestDimensionOptions(action, on, update);
810 case RS2::ActionDimDiametric:
811 requestDimensionOptions(action, on, update);
814 case RS2::ActionDimAngular:
815 requestDimensionOptions(action, on, update);
818 case RS2::ActionModifyTrimAmount:
819 requestTrimAmountOptions(action, on, update);
822 case RS2::ActionModifyMoveRotate:
823 requestMoveRotateOptions(action, on, update);
826 case RS2::ActionModifyBevel:
827 requestBevelOptions(action, on, update);
830 case RS2::ActionModifyRound:
831 requestRoundOptions(action, on, update);
834 case RS2::ActionLibraryInsert:
835 requestLibraryInsertOptions(action, on, update);
842 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
846 * Shows a widget for options for the action: "print preview"
848 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
850 static PrintPreviewOptions * toolWidget = NULL;
863 toolWidget = new PrintPreviewOptions(optionWidget);
864 toolWidget->setAction(action, update);
869 * Shows a widget for options for the action: "draw line"
871 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
874 The way I see it, this is failure. We're constantly creating & deleting
875 these objects all the time when we could create them once, and then reuse
876 them over and over. May need to do some more refactoring based on this idea...
879 static LineOptions * toolWidget = NULL;
884 // Get rid of the LineOptions object if it exists...
891 // Create a new one for the passed in action
894 toolWidget = new LineOptions(optionWidget);
895 toolWidget->setAction(action);
898 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
902 * Shows a widget for options for the action: "draw polyline"
904 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
907 static PolylineOptions * toolWidget = NULL;
920 toolWidget = new PolylineOptions(optionWidget);
921 toolWidget->setAction(action, update);
927 * Shows a widget for options for the action: "draw line parallel"
929 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
931 static LineParallelOptions * toolWidget = NULL;
933 if (optionWidget!=NULL)
935 if (toolWidget!=NULL)
940 if (on==true && toolWidget==NULL)
942 toolWidget = new LineParallelOptions(optionWidget);
943 toolWidget->setAction(action, update);
949 * Shows a widget for options for the action: "draw line parallel through"
951 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
953 static LineParallelThroughOptions * toolWidget = NULL;
955 if (optionWidget!=NULL) {
956 if (toolWidget!=NULL) {
960 if (on==true && toolWidget==NULL) {
961 toolWidget = new LineParallelThroughOptions(optionWidget);
962 toolWidget->setAction(action, update);
968 * Shows a widget for options for the action: "line angle"
970 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
972 static LineAngleOptions * toolWidget = NULL;
985 toolWidget = new LineAngleOptions(optionWidget);
986 toolWidget->setAction(action, update);
991 * Shows a widget for options for the action: "line relative angle"
993 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
995 static LineRelAngleOptions * toolWidget = NULL;
1008 toolWidget = new LineRelAngleOptions(optionWidget);
1009 toolWidget->setAction(action, update);
1014 * Shows a widget for options for the action: "line angle"
1016 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
1018 static LineBisectorOptions * toolWidget = NULL;
1020 if (optionWidget!=NULL) {
1021 if (toolWidget!=NULL) {
1025 if (on==true && toolWidget==NULL) {
1026 toolWidget = new LineBisectorOptions(optionWidget);
1027 toolWidget->setAction(action, update);
1033 * Shows a widget for options for the action: "draw polygon"
1035 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1037 static LinePolygonOptions * toolWidget = NULL;
1039 if (optionWidget!=NULL) {
1040 if (toolWidget!=NULL) {
1044 if (on==true && toolWidget==NULL) {
1045 toolWidget = new LinePolygonOptions(optionWidget);
1046 toolWidget->setAction(action, update);
1052 * Shows a widget for options for the action: "draw polygon2"
1054 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1056 static LinePolygon2Options * toolWidget = NULL;
1058 if (optionWidget!=NULL) {
1059 if (toolWidget!=NULL) {
1063 if (on==true && toolWidget==NULL) {
1064 toolWidget = new LinePolygon2Options(optionWidget);
1065 toolWidget->setAction(action, update);
1071 * Shows a widget for arc options.
1073 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1075 static ArcOptions * toolWidget = NULL;
1077 if (optionWidget != NULL)
1079 if (toolWidget != NULL)
1085 if (on && toolWidget == NULL)
1087 toolWidget = new ArcOptions(optionWidget);
1088 toolWidget->setAction(action, update);
1089 //toolWidget->setData(&data);
1095 * Shows a widget for tangential arc options.
1097 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1099 static ArcTangentialOptions * toolWidget = NULL;
1112 toolWidget = new ArcTangentialOptions(optionWidget);
1113 toolWidget->setAction(action, update);
1114 //toolWidget->setData(&data);
1119 * Shows a widget for circle options.
1121 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1123 static CircleOptions * toolWidget = NULL;
1133 if (on && toolWidget == NULL)
1135 toolWidget = new CircleOptions(optionWidget);
1136 toolWidget->setAction(action, update);
1142 * Shows a widget for spline options.
1144 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1146 static SplineOptions * toolWidget = NULL;
1159 toolWidget = new SplineOptions(optionWidget);
1160 toolWidget->setAction(action, update);
1165 * Shows a widget for text options.
1167 void QG_DialogFactory::requestTextOptions(ActionInterface * action, bool on, bool update)
1169 static TextOptions * toolWidget = NULL;
1182 toolWidget = new TextOptions(optionWidget);
1183 toolWidget->setAction(action, update);
1188 * Shows a widget for insert options.
1190 void QG_DialogFactory::requestInsertOptions(ActionInterface * action, bool on, bool update)
1192 static InsertOptions * toolWidget = NULL;
1194 if (optionWidget!=NULL) {
1195 if (toolWidget!=NULL) {
1199 if (on==true && toolWidget==NULL) {
1200 toolWidget = new InsertOptions(optionWidget);
1201 toolWidget->setAction(action, update);
1207 * Shows a widget for image options.
1209 void QG_DialogFactory::requestImageOptions(ActionInterface * action, bool on, bool update)
1211 static ImageOptions * toolWidget = NULL;
1213 if (optionWidget!=NULL) {
1214 if (toolWidget!=NULL) {
1218 if (on==true && toolWidget==NULL) {
1219 toolWidget = new ImageOptions(optionWidget);
1220 toolWidget->setAction(action, update);
1226 * Shows a widget for dimension options.
1228 void QG_DialogFactory::requestDimensionOptions(ActionInterface * action, bool on, bool update)
1230 static DimOptions * toolWidget = NULL;
1232 if (optionWidget!=NULL) {
1233 if (toolWidget!=NULL) {
1237 if (on==true && toolWidget==NULL) {
1238 toolWidget = new DimOptions(optionWidget);
1239 toolWidget->setAction(action, update);
1245 * Shows a widget for linear dimension options.
1247 void QG_DialogFactory::requestDimLinearOptions(ActionInterface * action, bool on, bool update)
1249 static DimLinearOptions * toolWidget = NULL;
1262 toolWidget = new DimLinearOptions(optionWidget);
1263 toolWidget->setAction(action, update);
1268 * Shows a widget for 'snap to a point with a given distance' options.
1270 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1272 static SnapDistOptions * toolWidget = NULL;
1285 toolWidget = new SnapDistOptions(optionWidget);
1286 toolWidget->setDist(&dist);
1291 * Shows a widget for 'snap to a point with a given distance' options.
1293 void QG_DialogFactory::requestMoveRotateOptions(ActionInterface * action, bool on, bool update)
1295 static MoveRotateOptions * toolWidget = NULL;
1308 toolWidget = new MoveRotateOptions(optionWidget);
1309 toolWidget->setAction(action, update);
1314 * Shows a widget for 'trim amount' options.
1316 void QG_DialogFactory::requestTrimAmountOptions(ActionInterface * action, bool on, bool update)
1318 static TrimAmountOptions * toolWidget = NULL;
1331 toolWidget = new TrimAmountOptions(optionWidget);
1332 toolWidget->setAction(action, update);
1337 * Shows a widget for beveling options.
1339 void QG_DialogFactory::requestBevelOptions(ActionInterface * action, bool on, bool update)
1341 static BevelOptions * toolWidget = NULL;
1343 if (optionWidget != NULL)
1345 if (toolWidget != NULL)
1351 if (on && toolWidget == NULL)
1353 toolWidget = new BevelOptions(optionWidget);
1354 toolWidget->setAction(action, update);
1360 * Shows a widget for rounding options.
1362 void QG_DialogFactory::requestRoundOptions(ActionInterface * action, bool on, bool update)
1364 static RoundOptions * toolWidget = NULL;
1377 toolWidget = new RoundOptions(optionWidget);
1378 toolWidget->setAction(action, update);
1383 * Shows a widget for library insert options.
1385 void QG_DialogFactory::requestLibraryInsertOptions(ActionInterface * action, bool on, bool update)
1387 static LibraryInsertOptions * toolWidget = NULL;
1400 toolWidget = new LibraryInsertOptions(optionWidget);
1401 toolWidget->setAction(action, update);
1406 * Shows the given toolbar.
1408 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1410 if (cadToolBar != NULL)
1411 cadToolBar->showToolBar(id);
1415 * Shows the select toolbar with the given action to launch.
1417 void QG_DialogFactory::requestToolBarSelect(ActionInterface * selectAction,
1418 RS2::ActionType nextAction)
1420 if (cadToolBar != NULL)
1421 cadToolBar->showToolBarSelect(selectAction, nextAction);
1425 * Shows a dialog to edit the attributes of the given dimension entity.
1428 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1433 QG_DlgDimAligned dlg(parent);
1434 dlg.setDim(*dim, true);
1445 * Shows attributes options dialog presenting the given data.
1447 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1449 DlgAttributes dlg(parent);
1450 dlg.setData(&data, layerList);
1462 * Shows move options dialog presenting the given data.
1464 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1466 DlgMove dlg(parent);
1479 * Shows rotate options dialog presenting the given data.
1481 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1483 DlgRotate dlg(parent);
1496 * Shows scale options dialog presenting the given data.
1498 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1500 DlgScale dlg(parent);
1513 * Shows mirror options dialog presenting the given data.
1515 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1517 DlgMirror dlg(parent);
1530 * Shows move/rotate options dialog presenting the given data.
1532 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1534 DlgMoveRotate dlg(parent);
1547 * Shows rotate around two centers options dialog presenting the given data.
1549 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1551 DlgRotate2 dlg(parent);
1564 * Shows a dialog to edit the given entity.
1566 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1573 switch (entity->rtti())
1575 case RS2::EntityPoint:
1577 DlgPoint dlg(parent);
1578 dlg.setPoint(*((RS_Point *)entity));
1588 case RS2::EntityLine:
1590 DlgLine dlg(parent);
1591 dlg.setLine(*((RS_Line *)entity));
1601 case RS2::EntityArc:
1604 dlg.setArc(*((RS_Arc *)entity));
1614 case RS2::EntityCircle:
1616 DlgCircle dlg(parent);
1617 dlg.setCircle(*((RS_Circle *)entity));
1627 case RS2::EntityEllipse:
1629 DlgEllipse dlg(parent);
1630 dlg.setEllipse(*((RS_Ellipse *)entity));
1634 dlg.updateEllipse();
1640 case RS2::EntitySpline:
1642 DlgSpline dlg(parent);
1643 dlg.setSpline(*((RS_Spline *)entity));
1653 case RS2::EntityInsert:
1655 DlgInsert dlg(parent);
1656 dlg.setInsert(*((RS_Insert *)entity));
1667 case RS2::EntityDimAligned:
1668 case RS2::EntityDimAngular:
1669 case RS2::EntityDimDiametric:
1670 case RS2::EntityDimRadial:
1672 DlgDimension dlg(parent);
1673 dlg.setDim(*((RS_Dimension *)entity));
1679 ((RS_Dimension *)entity)->update(true);
1684 case RS2::EntityDimLinear:
1686 DlgDimLinear dlg(parent);
1687 dlg.setDim(*((RS_DimLinear *)entity));
1693 ((RS_DimLinear *)entity)->update(true);
1698 case RS2::EntityText:
1700 DlgText dlg(parent);
1701 dlg.setText(*((RS_Text *)entity), false);
1707 ((RS_Text *)entity)->update();
1712 case RS2::EntityHatch:
1714 DlgHatch dlg(parent);
1715 dlg.setHatch(*((RS_Hatch *)entity), false);
1721 ((RS_Hatch *)entity)->update();
1734 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1740 * Shows a dialog to edit the attributes of the given text entity.
1742 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1747 DlgText dlg(parent);
1748 dlg.setText(*text, true);
1760 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1762 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1767 RS_PATTERNLIST->init();
1769 DlgHatch dlg(parent);
1770 dlg.setHatch(*hatch, true);
1783 * Shows a dialog for CAM options.
1785 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1787 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1788 RS_CamDialog dlg(graphic, parent);
1789 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1793 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1797 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1803 * Shows dialog for general application options.
1805 void QG_DialogFactory::requestOptionsGeneralDialog()
1807 DlgOptionsGeneral dlg(parent);
1812 * Shows dialog for drawing options.
1814 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1816 DlgOptionsDrawing dlg(parent);
1817 dlg.setGraphic(&graphic);
1822 * Back to last menu in cad toolbar.
1824 void QG_DialogFactory::requestPreviousMenu()
1826 if (cadToolBar != NULL)
1827 cadToolBar->showToolBarMain();
1831 * Called whenever the mouse position changed.
1833 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1834 const Vector & rel, bool updateFormat)
1836 if (coordinateWidget != NULL)
1837 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1841 * Called when an action has a mouse hint.
1843 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1846 mouseWidget->setHelp(left, right);
1849 commandWidget->setCommand(left);
1853 * Called whenever the selection changed.
1855 void QG_DialogFactory::updateSelectionWidget(int num)
1857 if (selectionWidget != NULL)
1858 selectionWidget->setNumber(num);
1862 * Called when an action needs to communicate 'message' to the user.
1864 void QG_DialogFactory::commandMessage(const QString& message)
1866 RS_DEBUG->print("QG_DialogFactory::commandMessage");
1868 if (commandWidget != NULL)
1869 commandWidget->appendHistory(message);
1871 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
1874 /*virtual*/ bool QG_DialogFactory::isAdapter()
1880 * Converts an extension to a format description.
1881 * e.g. "PNG" to "Portable Network Graphic"
1884 * @return Format description
1886 QString QG_DialogFactory::extToFormat(const QString & ext)
1888 QString e = ext.toLower();
1891 return QObject::tr("Windows Bitmap");
1892 else if (e == "jpeg" || e == "jpg")
1893 return QObject::tr("Joint Photographic Experts Group");
1894 else if (e == "gif")
1895 return QObject::tr("Graphics Interchange Format");
1896 else if (e == "mng")
1897 return QObject::tr("Multiple-image Network Graphics");
1898 else if (e == "pbm")
1899 return QObject::tr("Portable Bit Map");
1900 else if (e == "pgm")
1901 return QObject::tr("Portable Grey Map");
1902 else if (e == "png")
1903 return QObject::tr("Portable Network Graphic");
1904 else if (e == "ppm")
1905 return QObject::tr("Portable Pixel Map");
1906 else if (e == "xbm")
1907 return QObject::tr("X Bitmap Format");
1908 else if (e == "xpm")
1909 return QObject::tr("X Pixel Map");
1911 return ext.toUpper();