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