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