]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_dialogfactory.cpp
Refactoring: Moved RS_GraphicView to GraphicView.
[architektonas] / src / widgets / qg_dialogfactory.cpp
1 // qg_dialogfactory.cpp
2 //
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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Added this text. :-)
13 //
14
15 #include "qg_dialogfactory.h"
16
17 #include "graphicview.h"
18 #include "qg_layerwidget.h"
19 #include "qg_mainwindowinterface.h"
20 #include "rs_actiondimlinear.h"
21 #include "rs_actioninterface.h"
22 #include "rs_blocklist.h"
23 #include "rs_document.h"
24 #include "rs_hatch.h"
25 #include "rs_patternlist.h"
26 #include "settings.h"
27 #include "rs_system.h"
28 #include "rs_text.h"
29
30 #include "arcoptions.h"
31 #include "arctangentialoptions.h"
32 #include "beveloptions.h"
33 #include "blockdialog.h"
34 #include "cadtoolbar.h"
35 #include "circleoptions.h"
36 #include "commandwidget.h"
37 #include "coordinatewidget.h"
38 #include "dimlinearoptions.h"
39 #include "dimoptions.h"
40 #include "dlgarc.h"
41 #include "dlgattributes.h"
42 #include "dlgcircle.h"
43 #include "dlgdimension.h"
44 #include "dlgdimlinear.h"
45 #include "dlgellipse.h"
46 #include "dlghatch.h"
47 #include "dlginsert.h"
48 #include "dlgline.h"
49 #include "dlgmirror.h"
50 #include "dlgmove.h"
51 #include "dlgmoverotate.h"
52 #include "dlgoptionsdrawing.h"
53 #include "dlgoptionsgeneral.h"
54 #include "dlgpoint.h"
55 #include "dlgrotate.h"
56 #include "dlgrotate2.h"
57 #include "dlgscale.h"
58 #include "dlgspline.h"
59 #include "dlgtext.h"
60 #include "libraryinsertoptions.h"
61 #include "imageoptions.h"
62 #include "insertoptions.h"
63 #include "layerdialog.h"
64 #include "lineangleoptions.h"
65 #include "linebisectoroptions.h"
66 #include "lineoptions.h"
67 #include "lineparalleloptions.h"
68 #include "lineparallelthroughoptions.h"
69 #include "linepolygon2options.h"
70 #include "linepolygonoptions.h"
71 #include "linerelangleoptions.h"
72 #include "mousewidget.h"
73 #include "moverotateoptions.h"
74 #include "printpreviewoptions.h"
75 #include "roundoptions.h"
76 #include "selectionwidget.h"
77 #include "snapdistoptions.h"
78 #include "splineoptions.h"
79 #include "textoptions.h"
80 #include "trimamountoptions.h"
81
82 #ifdef RS_PROF
83 #include "qg_polylineoptions.h"
84 #endif
85
86 #ifdef RS_CAM
87 #include "rs_camdialog.h"
88 #endif
89
90 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
91
92 /**
93  * Constructor.
94  *
95  * @param parent Pointer to parent widget which can host dialogs.
96  * @param ow Pointer to widget that can host option widgets.
97  */
98 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
99 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
100         RS_DialogFactoryInterface()
101 {
102         RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
103
104         this->parent = parent;
105         setOptionWidget(ow);
106
107         coordinateWidget = NULL;
108         mouseWidget = NULL;
109         selectionWidget = NULL;
110         cadToolBar = NULL;
111         commandWidget = NULL;
112         mainWindow = NULL;
113         RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
114 }
115
116 /**
117  * Destructor
118  */
119 QG_DialogFactory::~QG_DialogFactory()
120 {
121         RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
122         RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
123 }
124
125 /**
126  * Links factory to a widget that can host tool options.
127  */
128 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
129 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
130 {
131         RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
132         optionWidget = ow;
133         RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
134 }
135
136 /**
137  * Links this dialog factory to a coordinate widget.
138  */
139 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
140 {
141         coordinateWidget = cw;
142 }
143
144 /**
145  * Links this dialog factory to a mouse widget.
146  */
147 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
148 {
149         mouseWidget = mw;
150 }
151
152 /**
153  * Links this dialog factory to a selection widget.
154  */
155 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
156 {
157         selectionWidget = sw;
158 }
159
160 /**
161  * Links this dialog factory to the cad tool bar.
162  */
163 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
164 {
165         cadToolBar = ctb;
166 }
167
168 /**
169  * @return cad tool bar or NULL.
170  */
171 CadToolBar * QG_DialogFactory::getCadToolBar()
172 {
173         return cadToolBar;
174 }
175
176 /**
177  * Links this dialog factory to a command widget.
178  */
179 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
180 {
181         commandWidget = cw;
182 }
183
184 /**
185  * @return command widget or NULL.
186  */
187 CommandWidget * QG_DialogFactory::getCommandWidget()
188 {
189         return commandWidget;
190 }
191
192 /**
193  * Links the dialog factory to a main app window.
194  */
195 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
196 {
197         mainWindow = mw;
198 }
199
200 /**
201  * Shows a message dialog.
202  */
203 void QG_DialogFactory::requestWarningDialog(const QString & warning)
204 {
205         QMessageBox::information(parent, QMessageBox::tr("Warning"),
206                 warning, QMessageBox::Ok);
207 }
208
209 /**
210  * Requests a new document from the main window.
211  */
212 GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
213 {
214         if (mainWindow != NULL)
215         {
216                 mainWindow->createNewDocument(fileName, doc);
217                 return mainWindow->getGraphicView();
218         }
219
220         return NULL;
221 }
222
223 /**
224  * Requests the simulation controls.
225  */
226 void QG_DialogFactory::requestSimulationControls()
227 {
228         if (mainWindow != NULL)
229         {
230                 mainWindow->showSimulationControls();
231         }
232 }
233
234 /**
235  * Shows a dialog for adding a layer. Doesn't add the layer.
236  * This is up to the caller.
237  *
238  * @return a pointer to the newly created layer that
239  * should be added.
240  */
241 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
242 {
243         RS_Layer * layer = NULL;
244         QString layer_name = "noname";
245         int i = 2;
246
247         if (layerList != NULL)
248         {
249                 while (layerList->find(layer_name) > 0)
250                         layer_name.sprintf("noname%d", i++);
251         }
252
253         // Layer for parameter livery
254         layer = new RS_Layer(layer_name);
255
256 //      QG_LayerDialog dlg(parent, "Layer Dialog");
257         LayerDialog dlg(parent);
258         dlg.setLayer(layer);
259         dlg.setLayerList(layerList);
260
261         if (dlg.exec())
262                 dlg.updateLayer();
263         else
264         {
265                 delete layer;
266                 layer = NULL;
267         }
268
269         return layer;
270 }
271
272 /**
273  * Shows a dialog that asks the user if the selected layer
274  * can be removed. Doesn't remove the layer. This is up to the caller.
275  *
276  * @return a pointer to the layer that should be removed.
277  */
278 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
279 {
280     RS_Layer * layer = NULL;
281
282         if (layerList == NULL)
283         {
284         RS_DEBUG->print(RS_Debug::D_WARNING,
285                 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
286
287         return NULL;
288     }
289     /*
290        if (layerList==NULL) {
291            if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
292                layerList = (RS_LayerList*)container;
293            } else {
294                return NULL;
295            }
296        }*/
297
298         // Layer for parameter livery
299         layer = layerList->getActive();
300
301         if (layer != NULL)
302         {
303                 if (layer->getName() != "0")
304                 {
305                         int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
306                                 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
307                                 QMessageBox::Ok, QMessageBox::Cancel);
308
309                         if (remove == 1)
310                         {
311                         }
312                         else
313                         {
314                                 layer = NULL;
315                         }
316                 }
317                 else
318                 {
319                         QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
320                                 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
321                                 QMessageBox::Ok);
322                 }
323         }
324
325         return layer;
326 }
327
328 /**
329  * Shows a dialog for editing a layer. A new layer is created and
330  * returned. Modifying the layer is up to the caller.
331  *
332  * @return A pointer to a new layer with the changed attributes
333  *         or NULL if the dialog was cancelled.
334  */
335 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
336 {
337         RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
338         RS_Layer * layer = NULL;
339         /*
340         if (layerList==NULL) {
341                 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
342                         layerList = (RS_LayerList*)container;
343                 } else {
344                         return NULL;
345                 }
346         }
347         */
348
349         if (layerList == NULL)
350         {
351                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
352                         "layerList is NULL");
353                 return NULL;
354         }
355
356         // Layer for parameter livery
357         if (layerList->getActive() != NULL)
358         {
359                 layer = new RS_Layer(*layerList->getActive());
360
361 //        QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
362                 LayerDialog dlg(parent);
363                 dlg.setLayer(layer);
364                 dlg.setLayerList(layerList);
365                 dlg.setEditLayer(true);
366
367                 if (dlg.exec())
368                         dlg.updateLayer();
369                 else
370                 {
371                         delete layer;
372                         layer = NULL;
373                 }
374         }
375
376         return layer;
377 }
378
379 /**
380  * Shows a dialog for adding a block. Doesn't add the block.
381  * This is up to the caller.
382  *
383  * @return a pointer to the newly created block that
384  * should be added.
385  */
386 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
387 {
388         //RS_Block* block = NULL;
389         RS_BlockData ret;
390         ret = RS_BlockData("", Vector(false), false);
391
392         if (blockList == NULL)
393         {
394                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
395                         "blockList is NULL");
396                 return ret;
397         }
398
399         // Block for parameter livery
400         //block = new RS_Block(container, "noname", Vector(0.0,0.0));
401
402         BlockDialog dlg(parent);
403         dlg.setBlockList(blockList);
404
405         if (dlg.exec())
406                 ret = dlg.getBlockData();
407
408         return ret;
409 }
410
411 /**
412  * Shows a dialog for renaming the currently active block.
413  *
414  * @return a pointer to the modified block or NULL on cancellation.
415  */
416 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
417 {
418         //RS_Block* block = NULL;
419         RS_BlockData ret;
420         ret = RS_BlockData("", Vector(false), false);
421
422         if (blockList == NULL)
423         {
424                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
425                         "blockList is NULL");
426                 return ret;
427         }
428         /*
429                 if (blockList==NULL) {
430                         if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
431                                 blockList = (RS_BlockList*)container;
432                         } else {
433                                 return NULL;
434                         }
435                 }*/
436
437         // Block for parameter livery
438         //block = blockList->getActive();
439
440         BlockDialog dlg(parent);//WAS:, "Rename Block");
441 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
442         dlg.setWindowTitle(QObject::tr("Rename Block"));
443         dlg.setBlockList(blockList);
444
445         if (dlg.exec())
446         {
447                 //dlg.updateBlock();
448                 //block->setData();
449                 ret = dlg.getBlockData();
450         }
451         //else {
452         //      ret = RS_BlockData("", Vector(false));
453         //}
454
455         return ret;
456 }
457
458 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
459 {
460 }
461
462 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
463 {
464 }
465
466 /**
467  * Shows a dialog that asks the user if the selected block
468  * can be removed. Doesn't remove the block. This is up to the caller.
469  *
470  * @return a pointer to the block that should be removed.
471  */
472 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
473 {
474         RS_Block * block = NULL;
475
476         if (blockList == NULL)
477         {
478                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
479                         "blockList is NULL");
480                 return NULL;
481         }
482
483         // Block for parameter livery
484         block = blockList->getActive();
485
486         if (block != NULL)
487         {
488                 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
489                         QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
490                         QMessageBox::Ok, QMessageBox::Cancel);
491
492                 if (remove == 1)
493                 {
494                 }
495                 else
496                 {
497                         block = NULL;
498                 }
499         }
500
501         return block;
502 }
503
504 /**
505  * Shows a dialog for choosing a file name. Saving the file is up to
506  * the caller.
507  *
508  * @return File name with path and extension to determine the file type
509  *         or an empty string if the dialog was cancelled.
510  */
511 /*
512 QString QG_DialogFactory::requestFileSaveAsDialog() {
513     // read default settings:
514     RS_SETTINGS->beginGroup("/Paths");
515     QString defDir = RS_SETTINGS->readEntry("/Save",
516                        RS_SYSTEM->getHomeDir());
517     QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
518                           "Drawing Exchange (*.dxf)");
519     RS_SETTINGS->endGroup();
520
521     // prepare file save as dialog:
522     QFileDialog fileDlg(this,0,true);
523     QStringList filters;
524     bool done = false;
525     bool cancel = false;
526     QString fn = "";
527
528     filters.append("Drawing Exchange (*.dxf)");
529     filters.append("Font (*.cxf)");
530     fileDlg.setFilters(filters);
531     fileDlg.setMode(QFileDialog::AnyFile);
532     fileDlg.setCaption(tr("Save Drawing As"));
533     fileDlg.setDir(defDir);
534     fileDlg.setSelectedFilter(defFilter);
535
536     // run dialog:
537     do {
538         // accepted:
539         if (fileDlg.exec()==QDialog::Accepted) {
540                 fn = fileDlg.selectedFile();
541                         cancel = false;
542
543             // append default extension:
544             if (fn.find('.')==-1) {
545                 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
546                     fn+=".cxf";
547                 } else {
548                     fn+=".dxf";
549                 }
550             }
551
552             // overwrite warning:
553             if(QFileInfo(fn).exists()) {
554                 int choice =
555                     QMessageBox::warning(this, tr("Save Drawing As"),
556                                          tr("%1 already exists.\n"
557                                             "Do you want to replace it?")
558                                          .arg(fn),
559                                          tr("Yes"), tr("No"),
560                                          tr("Cancel"), 0, 1 );
561
562                 switch (choice) {
563                 case 0:
564                     done = true;
565                     break;
566                 case 1:
567                 case 2:
568                 default:
569                     done = false;
570                     break;
571                 }
572             } else {
573                 done = true;
574             }
575         }
576                 else {
577             done = true;
578             cancel = true;
579                         fn = "";
580         }
581     } while(!done);
582
583     // store new default settings:
584     if (!cancel) {
585         RS_SETTINGS->beginGroup("/Paths");
586         RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
587         RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
588         RS_SETTINGS->endGroup();
589     }
590
591     return fn;
592 }
593 */
594
595 /**
596  * Shows a dialog for choosing a file name. Opening the file is up to
597  * the caller.
598  *
599  * @return File name with path and extension to determine the file type
600  *         or an empty string if the dialog was cancelled.
601  */
602 QString QG_DialogFactory::requestImageOpenDialog()
603 {
604         QString fn = "";
605
606         // read default settings:
607         settings.beginGroup("Paths");
608         QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
609         QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
610         settings.endGroup();
611
612         bool cancel = false;
613
614 //      Q3FileDialog fileDlg(NULL, "", true);
615         QFileDialog fileDlg(NULL, "");
616
617 #if 0
618 //      Q3StrList f = QImageIO::inputFormats();
619 //      QStringList formats = QStringList::fromStrList(f);
620         QList<QByteArray> f = QImageReader::supportedImageFormats();
621         QStringList formats = ???
622 #else
623 #warning "Needs porting to Qt4... !!! FIX !!!"
624 #endif
625
626         QStringList filters;
627         QString all = "";
628         //filters = QStringList::fromStrList(formats);
629
630 #if 0
631         for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
632         {
633                 QString ext = (*it);
634
635                 QString st;
636
637                 if (ext == "JPEG")
638                 {
639                         st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
640                 }
641                 else
642                 {
643                         st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
644                 }
645
646                 filters.append(st);
647
648                 if (!all.isEmpty())
649                         all += " ";
650
651                 if (ext == "JPEG")
652                 {
653                         all += QString("*.%1 *.jpg").arg(QString(*it).lower());
654                 }
655                 else
656                 {
657                         all += QString("*.%1").arg(QString(*it).lower());
658                 }
659         }
660 #endif
661
662         filters.append(QObject::tr("All Image Files (%1)").arg(all));
663         filters.append(QObject::tr("All Files (*.*)"));
664
665         //filters.append("Drawing Exchange (*.)");
666         //filters.append("Font (*.cxf)");
667
668         fileDlg.setFilters(filters);
669 //      fileDlg.setMode(Q3FileDialog::ExistingFile);
670         fileDlg.setFileMode(QFileDialog::ExistingFile);
671 //      fileDlg.setCaption(QObject::tr("Open Image"));
672         fileDlg.setWindowTitle(QObject::tr("Open Image"));
673 //      fileDlg.setDir(defDir);
674         fileDlg.setDirectory(defDir);
675 //      fileDlg.setSelectedFilter(defFilter);
676         fileDlg.selectFilter(defFilter);
677
678         cancel = true;
679
680         if (fileDlg.exec() == QDialog::Accepted)
681         {
682 //              fn = fileDlg.selectedFile();
683                 QStringList files = fileDlg.selectedFiles();
684
685                 if (!files.isEmpty())
686                         fn = files[0];
687
688                 cancel = false;
689         }
690
691         // store new default settings:
692         if (!cancel)
693         {
694                 QStringList files = fileDlg.selectedFiles();
695                 QString selected = "";
696
697                 if (!files.isEmpty())
698                         selected = files[0];
699
700                 settings.beginGroup("Paths");
701 //              RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
702                 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
703                 settings.setValue("ImageFilter", selected);
704                 settings.endGroup();
705         }
706
707         return fn;
708 }
709
710 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
711 {
712         RS_DEBUG->print("QG_DialogFactory::requestOptions");
713
714     if (action == NULL)
715         {
716         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
717         return;
718     }
719
720     switch (action->rtti())
721         {
722     case RS2::ActionPrintPreview:
723         requestPrintPreviewOptions(action, on, update);
724         break;
725
726     case RS2::ActionDrawLine:
727                 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
728         requestLineOptions(action, on);
729                 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
730         break;
731
732     case RS2::ActionDrawPolyline:
733         requestPolylineOptions(action, on, update);
734         break;
735
736     case RS2::ActionDrawLineAngle:
737         requestLineAngleOptions(action, on, update);
738         break;
739
740     case RS2::ActionDrawLineParallel:
741         requestLineParallelOptions(action, on, update);
742         break;
743
744     case RS2::ActionDrawLineParallelThrough:
745         requestLineParallelThroughOptions(action, on, update);
746         break;
747
748     case RS2::ActionDrawLineBisector:
749         requestLineBisectorOptions(action, on, update);
750         break;
751
752     case RS2::ActionDrawLineRelAngle:
753         requestLineRelAngleOptions(action, on, update);
754         break;
755
756     case RS2::ActionDrawLinePolygon:
757         requestLinePolygonOptions(action, on, update);
758         break;
759
760     case RS2::ActionDrawLinePolygon2:
761         requestLinePolygon2Options(action, on, update);
762         break;
763
764     case RS2::ActionDrawArc:
765         requestArcOptions(action, on, update);
766         break;
767
768         case RS2::ActionDrawArcTangential:
769         requestArcTangentialOptions(action, on, update);
770         break;
771
772     case RS2::ActionDrawCircleCR:
773         requestCircleOptions(action, on, update);
774         break;
775
776     case RS2::ActionDrawSpline:
777         requestSplineOptions(action, on, update);
778         break;
779
780     case RS2::ActionDrawText:
781         requestTextOptions(action, on, update);
782         break;
783
784     case RS2::ActionBlocksInsert:
785         requestInsertOptions(action, on, update);
786         break;
787
788     case RS2::ActionDrawImage:
789         requestImageOptions(action, on, update);
790         break;
791
792     case RS2::ActionDimAligned:
793         requestDimensionOptions(action, on, update);
794         break;
795
796     case RS2::ActionDimLinear:
797         requestDimensionOptions(action, on, update);
798
799                 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
800             requestDimLinearOptions(action, on, update);
801
802                 break;
803
804     case RS2::ActionDimRadial:
805         requestDimensionOptions(action, on, update);
806         break;
807
808     case RS2::ActionDimDiametric:
809         requestDimensionOptions(action, on, update);
810         break;
811
812     case RS2::ActionDimAngular:
813         requestDimensionOptions(action, on, update);
814         break;
815
816     case RS2::ActionModifyTrimAmount:
817         requestTrimAmountOptions(action, on, update);
818         break;
819
820     case RS2::ActionModifyMoveRotate:
821         requestMoveRotateOptions(action, on, update);
822         break;
823
824     case RS2::ActionModifyBevel:
825         requestBevelOptions(action, on, update);
826         break;
827
828     case RS2::ActionModifyRound:
829         requestRoundOptions(action, on, update);
830         break;
831
832     case RS2::ActionLibraryInsert:
833         requestLibraryInsertOptions(action, on, update);
834         break;
835
836     default:
837         break;
838     }
839
840         RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
841 }
842
843 /**
844  * Shows a widget for options for the action: "print preview"
845  */
846 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
847 {
848         static PrintPreviewOptions * toolWidget = NULL;
849
850         if (!optionWidget)
851                 return;
852
853         if (toolWidget)
854         {
855                 delete toolWidget;
856                 toolWidget = NULL;
857         }
858
859         if (on)
860         {
861                 toolWidget = new PrintPreviewOptions(optionWidget);
862                 toolWidget->setAction(action, update);
863         }
864 }
865
866 /**
867  * Shows a widget for options for the action: "draw line"
868  */
869 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
870 {
871 /*
872 The way I see it, this is failure. We're constantly creating & deleting
873 these objects all the time when we could create them once, and then reuse
874 them over and over. May need to do some more refactoring based on this idea...
875 */
876         //ugh.
877         static LineOptions * toolWidget = NULL;
878
879         if (!optionWidget)
880                 return;
881
882         // Get rid of the LineOptions object if it exists...
883         if (toolWidget)
884         {
885                 delete toolWidget;
886                 toolWidget = NULL;
887         }
888
889         // Create a new one for the passed in action
890         if (on)
891         {
892                 toolWidget = new LineOptions(optionWidget);
893                 toolWidget->setAction(action);
894         }
895
896         RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
897 }
898
899 /**
900  * Shows a widget for options for the action: "draw polyline"
901  */
902 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
903 {
904 #ifdef RS_PROF
905         static PolylineOptions * toolWidget = NULL;
906
907         if (!optionWidget)
908                 return;
909
910         if (toolWidget)
911         {
912                 delete toolWidget;
913                 toolWidget = NULL;
914         }
915
916         if (on)
917         {
918                 toolWidget = new PolylineOptions(optionWidget);
919                 toolWidget->setAction(action, update);
920         }
921 #endif
922 }
923
924 /**
925  * Shows a widget for options for the action: "draw line parallel"
926  */
927 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
928 {
929     static LineParallelOptions * toolWidget = NULL;
930
931     if (optionWidget!=NULL)
932         {
933         if (toolWidget!=NULL)
934                 {
935             delete toolWidget;
936             toolWidget = NULL;
937         }
938         if (on==true && toolWidget==NULL)
939                 {
940             toolWidget = new LineParallelOptions(optionWidget);
941             toolWidget->setAction(action, update);
942         }
943     }
944 }
945
946 /**
947  * Shows a widget for options for the action: "draw line parallel through"
948  */
949 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface * action, bool on, bool update)
950 {
951     static LineParallelThroughOptions * toolWidget = NULL;
952
953     if (optionWidget!=NULL) {
954         if (toolWidget!=NULL) {
955             delete toolWidget;
956             toolWidget = NULL;
957         }
958         if (on==true && toolWidget==NULL) {
959             toolWidget = new LineParallelThroughOptions(optionWidget);
960             toolWidget->setAction(action, update);
961         }
962     }
963 }
964
965 /**
966  * Shows a widget for options for the action: "line angle"
967  */
968 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface * action, bool on, bool update)
969 {
970         static LineAngleOptions * toolWidget = NULL;
971
972         if (!optionWidget)
973                 return;
974
975         if (toolWidget)
976         {
977                 delete toolWidget;
978                 toolWidget = NULL;
979         }
980
981         if (on)
982         {
983                 toolWidget = new LineAngleOptions(optionWidget);
984                 toolWidget->setAction(action, update);
985         }
986 }
987
988 /**
989  * Shows a widget for options for the action: "line relative angle"
990  */
991 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface * action, bool on, bool update)
992 {
993         static LineRelAngleOptions * toolWidget = NULL;
994
995         if (!optionWidget)
996                 return;
997
998         if (toolWidget)
999         {
1000                 delete toolWidget;
1001                 toolWidget = NULL;
1002         }
1003
1004         if (on)
1005         {
1006                 toolWidget = new LineRelAngleOptions(optionWidget);
1007                 toolWidget->setAction(action, update);
1008         }
1009 }
1010
1011 /**
1012  * Shows a widget for options for the action: "line angle"
1013  */
1014 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface * action, bool on, bool update)
1015 {
1016     static LineBisectorOptions * toolWidget = NULL;
1017
1018     if (optionWidget!=NULL) {
1019         if (toolWidget!=NULL) {
1020             delete toolWidget;
1021             toolWidget = NULL;
1022         }
1023         if (on==true && toolWidget==NULL) {
1024             toolWidget = new LineBisectorOptions(optionWidget);
1025             toolWidget->setAction(action, update);
1026         }
1027     }
1028 }
1029
1030 /**
1031  * Shows a widget for options for the action: "draw polygon"
1032  */
1033 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface * action, bool on, bool update)
1034 {
1035     static LinePolygonOptions * toolWidget = NULL;
1036
1037     if (optionWidget!=NULL) {
1038         if (toolWidget!=NULL) {
1039             delete toolWidget;
1040             toolWidget = NULL;
1041         }
1042         if (on==true && toolWidget==NULL) {
1043             toolWidget = new LinePolygonOptions(optionWidget);
1044             toolWidget->setAction(action, update);
1045         }
1046     }
1047 }
1048
1049 /**
1050  * Shows a widget for options for the action: "draw polygon2"
1051  */
1052 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface * action, bool on, bool update)
1053 {
1054     static LinePolygon2Options * toolWidget = NULL;
1055
1056     if (optionWidget!=NULL) {
1057         if (toolWidget!=NULL) {
1058             delete toolWidget;
1059             toolWidget = NULL;
1060         }
1061         if (on==true && toolWidget==NULL) {
1062             toolWidget = new LinePolygon2Options(optionWidget);
1063             toolWidget->setAction(action, update);
1064         }
1065     }
1066 }
1067
1068 /**
1069  * Shows a widget for arc options.
1070  */
1071 void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
1072 {
1073         static ArcOptions * toolWidget = NULL;
1074
1075         if (optionWidget != NULL)
1076         {
1077                 if (toolWidget != NULL)
1078                 {
1079                         delete toolWidget;
1080                         toolWidget = NULL;
1081                 }
1082
1083                 if (on && toolWidget == NULL)
1084                 {
1085                         toolWidget = new ArcOptions(optionWidget);
1086                         toolWidget->setAction(action, update);
1087                         //toolWidget->setData(&data);
1088                 }
1089         }
1090 }
1091
1092 /**
1093  * Shows a widget for tangential arc options.
1094  */
1095 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
1096 {
1097         static ArcTangentialOptions * toolWidget = NULL;
1098
1099         if (!optionWidget)
1100                 return;
1101
1102         if (toolWidget)
1103         {
1104                 delete toolWidget;
1105                 toolWidget = NULL;
1106         }
1107
1108         if (on)
1109         {
1110                 toolWidget = new ArcTangentialOptions(optionWidget);
1111                 toolWidget->setAction(action, update);
1112                 //toolWidget->setData(&data);
1113         }
1114 }
1115
1116 /**
1117  * Shows a widget for circle options.
1118  */
1119 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
1120 {
1121     static CircleOptions * toolWidget = NULL;
1122
1123     if (optionWidget)
1124         {
1125         if (toolWidget)
1126                 {
1127             delete toolWidget;
1128             toolWidget = NULL;
1129         }
1130
1131         if (on && toolWidget == NULL)
1132                 {
1133             toolWidget = new CircleOptions(optionWidget);
1134             toolWidget->setAction(action, update);
1135         }
1136     }
1137 }
1138
1139 /**
1140  * Shows a widget for spline options.
1141  */
1142 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface * action, bool on, bool update)
1143 {
1144         static SplineOptions * toolWidget = NULL;
1145
1146         if (optionWidget!=NULL) {
1147                 if (toolWidget!=NULL) {
1148                         delete toolWidget;
1149                         toolWidget = NULL;
1150                 }
1151                 if (on==true && toolWidget==NULL) {
1152                         toolWidget = new SplineOptions(optionWidget);
1153                         toolWidget->setAction(action, update);
1154                 }
1155         }
1156 }
1157
1158 /**
1159  * Shows a widget for text options.
1160  */
1161 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1162 {
1163         static TextOptions * toolWidget = NULL;
1164
1165         if (!optionWidget)
1166                 return;
1167
1168         if (toolWidget)
1169         {
1170                 delete toolWidget;
1171                 toolWidget = NULL;
1172         }
1173
1174         if (on)
1175         {
1176                 toolWidget = new TextOptions(optionWidget);
1177                 toolWidget->setAction(action, update);
1178         }
1179 }
1180
1181 /**
1182  * Shows a widget for insert options.
1183  */
1184 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface * action, bool on, bool update)
1185 {
1186     static InsertOptions * toolWidget = NULL;
1187
1188     if (optionWidget!=NULL) {
1189         if (toolWidget!=NULL) {
1190             delete toolWidget;
1191             toolWidget = NULL;
1192         }
1193         if (on==true && toolWidget==NULL) {
1194             toolWidget = new InsertOptions(optionWidget);
1195             toolWidget->setAction(action, update);
1196         }
1197     }
1198 }
1199
1200 /**
1201  * Shows a widget for image options.
1202  */
1203 void QG_DialogFactory::requestImageOptions(RS_ActionInterface * action, bool on, bool update)
1204 {
1205     static ImageOptions * toolWidget = NULL;
1206
1207     if (optionWidget!=NULL) {
1208         if (toolWidget!=NULL) {
1209             delete toolWidget;
1210             toolWidget = NULL;
1211         }
1212         if (on==true && toolWidget==NULL) {
1213             toolWidget = new ImageOptions(optionWidget);
1214             toolWidget->setAction(action, update);
1215         }
1216     }
1217 }
1218
1219 /**
1220  * Shows a widget for dimension options.
1221  */
1222 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface * action, bool on, bool update)
1223 {
1224     static DimOptions * toolWidget = NULL;
1225
1226     if (optionWidget!=NULL) {
1227         if (toolWidget!=NULL) {
1228             delete toolWidget;
1229             toolWidget = NULL;
1230         }
1231         if (on==true && toolWidget==NULL) {
1232             toolWidget = new DimOptions(optionWidget);
1233             toolWidget->setAction(action, update);
1234         }
1235     }
1236 }
1237
1238 /**
1239  * Shows a widget for linear dimension options.
1240  */
1241 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface * action, bool on, bool update)
1242 {
1243         static DimLinearOptions * toolWidget = NULL;
1244
1245         if (!optionWidget)
1246                 return;
1247
1248         if (toolWidget)
1249         {
1250                 delete toolWidget;
1251                 toolWidget = NULL;
1252         }
1253
1254         if (on)
1255         {
1256                 toolWidget = new DimLinearOptions(optionWidget);
1257                 toolWidget->setAction(action, update);
1258         }
1259 }
1260
1261 /**
1262  * Shows a widget for 'snap to a point with a given distance' options.
1263  */
1264 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1265 {
1266         static SnapDistOptions * toolWidget = NULL;
1267
1268         if (!optionWidget)
1269                 return;
1270
1271         if (toolWidget)
1272         {
1273                 delete toolWidget;
1274                 toolWidget = NULL;
1275         }
1276
1277         if (on)
1278         {
1279                 toolWidget = new SnapDistOptions(optionWidget);
1280                 toolWidget->setDist(&dist);
1281         }
1282 }
1283
1284 /**
1285  * Shows a widget for 'snap to a point with a given distance' options.
1286  */
1287 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface * action, bool on, bool update)
1288 {
1289         static MoveRotateOptions * toolWidget = NULL;
1290
1291         if (!optionWidget)
1292                 return;
1293
1294         if (toolWidget)
1295         {
1296                 delete toolWidget;
1297                 toolWidget = NULL;
1298         }
1299
1300         if (on)
1301         {
1302                 toolWidget = new MoveRotateOptions(optionWidget);
1303                 toolWidget->setAction(action, update);
1304         }
1305 }
1306
1307 /**
1308  * Shows a widget for 'trim amount' options.
1309  */
1310 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface * action, bool on, bool update)
1311 {
1312         static TrimAmountOptions * toolWidget = NULL;
1313
1314         if (!optionWidget)
1315                 return;
1316
1317         if (toolWidget)
1318         {
1319                 delete toolWidget;
1320                 toolWidget = NULL;
1321         }
1322
1323         if (on)
1324         {
1325                 toolWidget = new TrimAmountOptions(optionWidget);
1326                 toolWidget->setAction(action, update);
1327         }
1328 }
1329
1330 /**
1331  * Shows a widget for beveling options.
1332  */
1333 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1334 {
1335     static BevelOptions * toolWidget = NULL;
1336
1337     if (optionWidget != NULL)
1338         {
1339         if (toolWidget != NULL)
1340                 {
1341             delete toolWidget;
1342             toolWidget = NULL;
1343         }
1344
1345                 if (on && toolWidget == NULL)
1346                 {
1347             toolWidget = new BevelOptions(optionWidget);
1348             toolWidget->setAction(action, update);
1349         }
1350     }
1351 }
1352
1353 /**
1354  * Shows a widget for rounding options.
1355  */
1356 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface * action, bool on, bool update)
1357 {
1358         static RoundOptions * toolWidget = NULL;
1359
1360         if (!optionWidget)
1361                 return;
1362
1363         if (toolWidget)
1364         {
1365                 delete toolWidget;
1366                 toolWidget = NULL;
1367         }
1368
1369         if (on)
1370         {
1371                 toolWidget = new RoundOptions(optionWidget);
1372                 toolWidget->setAction(action, update);
1373         }
1374 }
1375
1376 /**
1377  * Shows a widget for library insert options.
1378  */
1379 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface * action, bool on, bool update)
1380 {
1381         static LibraryInsertOptions * toolWidget = NULL;
1382
1383         if (!optionWidget)
1384                 return;
1385
1386         if (toolWidget)
1387         {
1388                 delete toolWidget;
1389                 toolWidget = NULL;
1390         }
1391
1392         if (on)
1393         {
1394                 toolWidget = new LibraryInsertOptions(optionWidget);
1395                 toolWidget->setAction(action, update);
1396         }
1397 }
1398
1399 /**
1400  * Shows the given toolbar.
1401  */
1402 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1403 {
1404         if (cadToolBar != NULL)
1405                 cadToolBar->showToolBar(id);
1406 }
1407
1408 /**
1409  * Shows the select toolbar with the given action to launch.
1410  */
1411 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1412         RS2::ActionType nextAction)
1413 {
1414         if (cadToolBar != NULL)
1415                 cadToolBar->showToolBarSelect(selectAction, nextAction);
1416 }
1417
1418 /**
1419  * Shows a dialog to edit the attributes of the given dimension entity.
1420  */
1421  /*
1422 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1423     if (dim==NULL) {
1424         return false;
1425     }
1426
1427     QG_DlgDimAligned dlg(parent);
1428     dlg.setDim(*dim, true);
1429     if (dlg.exec()) {
1430         dlg.updateDim();
1431         return true;
1432     }
1433
1434     return false;
1435 }
1436 */
1437
1438 /**
1439  * Shows attributes options dialog presenting the given data.
1440  */
1441 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1442 {
1443         DlgAttributes dlg(parent);
1444         dlg.setData(&data, layerList);
1445
1446         if (dlg.exec())
1447         {
1448                 dlg.updateData();
1449                 return true;
1450         }
1451
1452         return false;
1453 }
1454
1455 /**
1456  * Shows move options dialog presenting the given data.
1457  */
1458 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1459 {
1460         DlgMove dlg(parent);
1461         dlg.setData(&data);
1462
1463         if (dlg.exec())
1464         {
1465                 dlg.updateData();
1466                 return true;
1467         }
1468
1469         return false;
1470 }
1471
1472 /**
1473  * Shows rotate options dialog presenting the given data.
1474  */
1475 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1476 {
1477         DlgRotate dlg(parent);
1478         dlg.setData(&data);
1479
1480         if (dlg.exec())
1481         {
1482                 dlg.updateData();
1483                 return true;
1484         }
1485
1486         return false;
1487 }
1488
1489 /**
1490  * Shows scale options dialog presenting the given data.
1491  */
1492 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1493 {
1494         DlgScale dlg(parent);
1495         dlg.setData(&data);
1496
1497         if (dlg.exec())
1498         {
1499                 dlg.updateData();
1500                 return true;
1501         }
1502
1503         return false;
1504 }
1505
1506 /**
1507  * Shows mirror options dialog presenting the given data.
1508  */
1509 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1510 {
1511         DlgMirror dlg(parent);
1512         dlg.setData(&data);
1513
1514         if (dlg.exec())
1515         {
1516                 dlg.updateData();
1517                 return true;
1518         }
1519
1520         return false;
1521 }
1522
1523 /**
1524  * Shows move/rotate options dialog presenting the given data.
1525  */
1526 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1527 {
1528         DlgMoveRotate dlg(parent);
1529         dlg.setData(&data);
1530
1531         if (dlg.exec())
1532         {
1533                 dlg.updateData();
1534                 return true;
1535         }
1536
1537         return false;
1538 }
1539
1540 /**
1541  * Shows rotate around two centers options dialog presenting the given data.
1542  */
1543 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1544 {
1545         DlgRotate2 dlg(parent);
1546         dlg.setData(&data);
1547
1548         if (dlg.exec())
1549         {
1550                 dlg.updateData();
1551                 return true;
1552         }
1553
1554         return false;
1555 }
1556
1557 /**
1558  * Shows a dialog to edit the given entity.
1559  */
1560 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1561 {
1562         if (entity == NULL)
1563                 return false;
1564
1565         bool ret = false;
1566
1567         switch (entity->rtti())
1568         {
1569         case RS2::EntityPoint:
1570         {
1571                 DlgPoint dlg(parent);
1572                 dlg.setPoint(*((RS_Point *)entity));
1573
1574                 if (dlg.exec())
1575                 {
1576                         dlg.updatePoint();
1577                         ret = true;
1578                 }
1579         }
1580                 break;
1581
1582         case RS2::EntityLine:
1583         {
1584                 DlgLine dlg(parent);
1585                 dlg.setLine(*((RS_Line *)entity));
1586
1587                 if (dlg.exec())
1588                 {
1589                         dlg.updateLine();
1590                         ret = true;
1591                 }
1592         }
1593                 break;
1594
1595         case RS2::EntityArc:
1596         {
1597                 DlgArc dlg(parent);
1598                 dlg.setArc(*((RS_Arc *)entity));
1599
1600                 if (dlg.exec())
1601                 {
1602                         dlg.updateArc();
1603                         ret = true;
1604                 }
1605         }
1606                 break;
1607
1608         case RS2::EntityCircle:
1609         {
1610                 DlgCircle dlg(parent);
1611                 dlg.setCircle(*((RS_Circle *)entity));
1612
1613                 if (dlg.exec())
1614                 {
1615                         dlg.updateCircle();
1616                         ret = true;
1617                 }
1618         }
1619                 break;
1620
1621         case RS2::EntityEllipse:
1622         {
1623                 DlgEllipse dlg(parent);
1624                 dlg.setEllipse(*((RS_Ellipse *)entity));
1625
1626                 if (dlg.exec())
1627                 {
1628                         dlg.updateEllipse();
1629                         ret = true;
1630                 }
1631         }
1632                 break;
1633
1634         case RS2::EntitySpline:
1635         {
1636                 DlgSpline dlg(parent);
1637                 dlg.setSpline(*((RS_Spline *)entity));
1638
1639                 if (dlg.exec())
1640                 {
1641                         dlg.updateSpline();
1642                         ret = true;
1643                 }
1644         }
1645                 break;
1646
1647         case RS2::EntityInsert:
1648         {
1649                 DlgInsert dlg(parent);
1650                 dlg.setInsert(*((RS_Insert *)entity));
1651
1652                 if (dlg.exec())
1653                 {
1654                         dlg.updateInsert();
1655                         ret = true;
1656                         entity->update();
1657                 }
1658         }
1659                 break;
1660
1661         case RS2::EntityDimAligned:
1662         case RS2::EntityDimAngular:
1663         case RS2::EntityDimDiametric:
1664         case RS2::EntityDimRadial:
1665         {
1666                 DlgDimension dlg(parent);
1667                 dlg.setDim(*((RS_Dimension *)entity));
1668
1669                 if (dlg.exec())
1670                 {
1671                         dlg.updateDim();
1672                         ret = true;
1673                         ((RS_Dimension *)entity)->update(true);
1674                 }
1675         }
1676                 break;
1677
1678         case RS2::EntityDimLinear:
1679         {
1680                 DlgDimLinear dlg(parent);
1681                 dlg.setDim(*((RS_DimLinear *)entity));
1682
1683                 if (dlg.exec())
1684                 {
1685                         dlg.updateDim();
1686                         ret = true;
1687                         ((RS_DimLinear *)entity)->update(true);
1688                 }
1689         }
1690                 break;
1691
1692         case RS2::EntityText:
1693         {
1694                 DlgText dlg(parent);
1695                 dlg.setText(*((RS_Text *)entity), false);
1696
1697                 if (dlg.exec())
1698                 {
1699                         dlg.updateText();
1700                         ret = true;
1701                         ((RS_Text *)entity)->update();
1702                 }
1703         }
1704                 break;
1705
1706         case RS2::EntityHatch:
1707         {
1708                 DlgHatch dlg(parent);
1709                 dlg.setHatch(*((RS_Hatch *)entity), false);
1710
1711                 if (dlg.exec())
1712                 {
1713                         dlg.updateHatch();
1714                         ret = true;
1715                         ((RS_Hatch *)entity)->update();
1716                 }
1717         }
1718                 break;
1719
1720         default:
1721                 break;
1722         }
1723
1724         return ret;
1725 }
1726
1727  /*
1728 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1729     return false;
1730 }
1731 */
1732
1733 /**
1734  * Shows a dialog to edit the attributes of the given text entity.
1735  */
1736 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1737 {
1738         if (text == NULL)
1739                 return false;
1740
1741         DlgText dlg(parent);
1742         dlg.setText(*text, true);
1743
1744         if (dlg.exec())
1745         {
1746                 dlg.updateText();
1747                 return true;
1748         }
1749
1750         return false;
1751 }
1752
1753 /**
1754  * Shows a dialog to edit pattern / hatch attributes of the given entity.
1755  */
1756 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1757 {
1758         if (hatch == NULL)
1759                 return false;
1760
1761         RS_PATTERNLIST->init();
1762
1763         DlgHatch dlg(parent);
1764         dlg.setHatch(*hatch, true);
1765
1766         if (dlg.exec())
1767         {
1768                 dlg.updateHatch();
1769                 return true;
1770         }
1771
1772         return false;
1773 }
1774
1775 #ifdef RS_CAM
1776 /**
1777  * Shows a dialog for CAM options.
1778  */
1779 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1780 {
1781         RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1782         RS_CamDialog dlg(graphic, parent);
1783         RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1784
1785         if (dlg.exec())
1786         {
1787                 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1788                 return true;
1789         }
1790
1791         RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1792         return false;
1793 }
1794 #endif
1795
1796 /**
1797  * Shows dialog for general application options.
1798  */
1799 void QG_DialogFactory::requestOptionsGeneralDialog()
1800 {
1801         DlgOptionsGeneral dlg(parent);
1802         dlg.exec();
1803 }
1804
1805 /**
1806  * Shows dialog for drawing options.
1807  */
1808 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1809 {
1810         DlgOptionsDrawing dlg(parent);
1811         dlg.setGraphic(&graphic);
1812         dlg.exec();
1813 }
1814
1815 /**
1816  * Back to last menu in cad toolbar.
1817  */
1818 void QG_DialogFactory::requestPreviousMenu()
1819 {
1820         if (cadToolBar != NULL)
1821                 cadToolBar->showToolBarMain();
1822 }
1823
1824 /**
1825  * Called whenever the mouse position changed.
1826  */
1827 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1828         const Vector & rel, bool updateFormat)
1829 {
1830         if (coordinateWidget != NULL)
1831                 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1832 }
1833
1834 /**
1835  * Called when an action has a mouse hint.
1836  */
1837 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1838 {
1839         if (mouseWidget != NULL)
1840                 mouseWidget->setHelp(left, right);
1841
1842         if (commandWidget != NULL)
1843                 commandWidget->setCommand(left);
1844 }
1845
1846 /**
1847  * Called whenever the selection changed.
1848  */
1849 void QG_DialogFactory::updateSelectionWidget(int num)
1850 {
1851         if (selectionWidget != NULL)
1852                 selectionWidget->setNumber(num);
1853 }
1854
1855 /**
1856  * Called when an action needs to communicate 'message' to the user.
1857  */
1858 void QG_DialogFactory::commandMessage(const QString& message)
1859 {
1860         RS_DEBUG->print("QG_DialogFactory::commandMessage");
1861
1862         if (commandWidget != NULL)
1863                 commandWidget->appendHistory(message);
1864
1865         RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
1866 }
1867
1868 /*virtual*/ bool QG_DialogFactory::isAdapter()
1869 {
1870         return false;
1871 }
1872
1873 /**
1874  * Converts an extension to a format description.
1875  * e.g. "PNG" to "Portable Network Graphic"
1876  *
1877  * @param Extension
1878  * @return Format description
1879  */
1880 QString QG_DialogFactory::extToFormat(const QString & ext)
1881 {
1882         QString e = ext.toLower();
1883
1884         if (e == "bmp")
1885                 return QObject::tr("Windows Bitmap");
1886         else if (e == "jpeg" || e == "jpg")
1887                 return QObject::tr("Joint Photographic Experts Group");
1888         else if (e == "gif")
1889                 return QObject::tr("Graphics Interchange Format");
1890         else if (e == "mng")
1891                 return QObject::tr("Multiple-image Network Graphics");
1892         else if (e == "pbm")
1893                 return QObject::tr("Portable Bit Map");
1894         else if (e == "pgm")
1895                 return QObject::tr("Portable Grey Map");
1896         else if (e == "png")
1897                 return QObject::tr("Portable Network Graphic");
1898         else if (e == "ppm")
1899                 return QObject::tr("Portable Pixel Map");
1900         else if (e == "xbm")
1901                 return QObject::tr("X Bitmap Format");
1902         else if (e == "xpm")
1903                 return QObject::tr("X Pixel Map");
1904         else
1905                 return ext.toUpper();
1906 }