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