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