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