1 // qg_dialogfactory.cpp
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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/10/2010 Added this text. :-)
15 #include "qg_dialogfactory.h"
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"
24 #include "rs_system.h"
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"
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 "dimlinearoptions.h"
89 #include "dimoptions.h"
90 #include "dlgattributes.h"
91 #include "dlgoptionsdrawing.h"
92 #include "dlgoptionsgeneral.h"
94 #include "imageoptions.h"
95 #include "layerdialog.h"
96 #include "lineangleoptions.h"
97 #include "linebisectoroptions.h"
98 #include "lineoptions.h"
99 #include "lineparalleloptions.h"
100 #include "lineparallelthroughoptions.h"
101 #include "linepolygon2options.h"
102 #include "linepolygonoptions.h"
103 #include "linerelangleoptions.h"
104 #include "mousewidget.h"
105 #include "moverotateoptions.h"
106 #include "printpreviewoptions.h"
107 #include "roundoptions.h"
108 #include "selectionwidget.h"
109 #include "snapdistoptions.h"
110 #include "splineoptions.h"
111 #include "textoptions.h"
112 #include "trimamountoptions.h"
115 #include "qg_polylineoptions.h"
119 #include "rs_camdialog.h"
122 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
127 * @param parent Pointer to parent widget which can host dialogs.
128 * @param ow Pointer to widget that can host option widgets.
130 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
131 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
132 RS_DialogFactoryInterface()
134 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
136 this->parent = parent;
139 coordinateWidget = NULL;
141 selectionWidget = NULL;
143 commandWidget = NULL;
145 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
151 QG_DialogFactory::~QG_DialogFactory()
153 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
154 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
158 * Links factory to a widget that can host tool options.
160 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
161 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
163 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
165 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
169 * Links this dialog factory to a coordinate widget.
171 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
173 coordinateWidget = cw;
177 * Links this dialog factory to a mouse widget.
179 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
185 * Links this dialog factory to a selection widget.
187 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
189 selectionWidget = sw;
193 * Links this dialog factory to the cad tool bar.
195 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
201 * @return cad tool bar or NULL.
203 CadToolBar * QG_DialogFactory::getCadToolBar()
209 * Links this dialog factory to a command widget.
211 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
217 * @return command widget or NULL.
219 CommandWidget * QG_DialogFactory::getCommandWidget()
221 return commandWidget;
225 * Links the dialog factory to a main app window.
227 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
233 * Shows a message dialog.
235 void QG_DialogFactory::requestWarningDialog(const QString & warning)
237 QMessageBox::information(parent, QMessageBox::tr("Warning"),
238 warning, QMessageBox::Ok);
242 * Requests a new document from the main window.
244 RS_GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
246 if (mainWindow != NULL)
248 mainWindow->createNewDocument(fileName, doc);
249 return mainWindow->getGraphicView();
256 * Requests the simulation controls.
258 void QG_DialogFactory::requestSimulationControls()
260 if (mainWindow != NULL)
262 mainWindow->showSimulationControls();
267 * Shows a dialog for adding a layer. Doesn't add the layer.
268 * This is up to the caller.
270 * @return a pointer to the newly created layer that
273 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
275 RS_Layer * layer = NULL;
276 QString layer_name = "noname";
279 if (layerList != NULL)
281 while (layerList->find(layer_name) > 0)
282 layer_name.sprintf("noname%d", i++);
285 // Layer for parameter livery
286 layer = new RS_Layer(layer_name);
288 // QG_LayerDialog dlg(parent, "Layer Dialog");
289 LayerDialog dlg(parent);
291 dlg.setLayerList(layerList);
305 * Shows a dialog that asks the user if the selected layer
306 * can be removed. Doesn't remove the layer. This is up to the caller.
308 * @return a pointer to the layer that should be removed.
310 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
312 RS_Layer * layer = NULL;
314 if (layerList == NULL)
316 RS_DEBUG->print(RS_Debug::D_WARNING,
317 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
322 if (layerList==NULL) {
323 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
324 layerList = (RS_LayerList*)container;
330 // Layer for parameter livery
331 layer = layerList->getActive();
335 if (layer->getName() != "0")
337 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
338 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
339 QMessageBox::Ok, QMessageBox::Cancel);
351 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
352 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
361 * Shows a dialog for editing a layer. A new layer is created and
362 * returned. Modifying the layer is up to the caller.
364 * @return A pointer to a new layer with the changed attributes
365 * or NULL if the dialog was cancelled.
367 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
369 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
370 RS_Layer * layer = NULL;
372 if (layerList==NULL) {
373 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
374 layerList = (RS_LayerList*)container;
381 if (layerList == NULL)
383 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
384 "layerList is NULL");
388 // Layer for parameter livery
389 if (layerList->getActive() != NULL)
391 layer = new RS_Layer(*layerList->getActive());
393 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
394 LayerDialog dlg(parent);
396 dlg.setLayerList(layerList);
397 dlg.setEditLayer(true);
412 * Shows a dialog for adding a block. Doesn't add the block.
413 * This is up to the caller.
415 * @return a pointer to the newly created block that
418 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
420 //RS_Block* block = NULL;
422 ret = RS_BlockData("", Vector(false), false);
424 if (blockList == NULL)
426 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
427 "blockList is NULL");
431 // Block for parameter livery
432 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
434 BlockDialog dlg(parent);
435 dlg.setBlockList(blockList);
438 ret = dlg.getBlockData();
444 * Shows a dialog for renaming the currently active block.
446 * @return a pointer to the modified block or NULL on cancellation.
448 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
450 //RS_Block* block = NULL;
452 ret = RS_BlockData("", Vector(false), false);
454 if (blockList == NULL)
456 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
457 "blockList is NULL");
461 if (blockList==NULL) {
462 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
463 blockList = (RS_BlockList*)container;
469 // Block for parameter livery
470 //block = blockList->getActive();
472 BlockDialog dlg(parent);//WAS:, "Rename Block");
473 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
474 dlg.setWindowTitle(QObject::tr("Rename Block"));
475 dlg.setBlockList(blockList);
481 ret = dlg.getBlockData();
484 // ret = RS_BlockData("", Vector(false));
490 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
494 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
499 * Shows a dialog that asks the user if the selected block
500 * can be removed. Doesn't remove the block. This is up to the caller.
502 * @return a pointer to the block that should be removed.
504 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
506 RS_Block * block = NULL;
508 if (blockList == NULL)
510 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
511 "blockList is NULL");
515 // Block for parameter livery
516 block = blockList->getActive();
520 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
521 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
522 QMessageBox::Ok, QMessageBox::Cancel);
537 * Shows a dialog for choosing a file name. Saving the file is up to
540 * @return File name with path and extension to determine the file type
541 * or an empty string if the dialog was cancelled.
544 QString QG_DialogFactory::requestFileSaveAsDialog() {
545 // read default settings:
546 RS_SETTINGS->beginGroup("/Paths");
547 QString defDir = RS_SETTINGS->readEntry("/Save",
548 RS_SYSTEM->getHomeDir());
549 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
550 "Drawing Exchange (*.dxf)");
551 RS_SETTINGS->endGroup();
553 // prepare file save as dialog:
554 QFileDialog fileDlg(this,0,true);
560 filters.append("Drawing Exchange (*.dxf)");
561 filters.append("Font (*.cxf)");
562 fileDlg.setFilters(filters);
563 fileDlg.setMode(QFileDialog::AnyFile);
564 fileDlg.setCaption(tr("Save Drawing As"));
565 fileDlg.setDir(defDir);
566 fileDlg.setSelectedFilter(defFilter);
571 if (fileDlg.exec()==QDialog::Accepted) {
572 fn = fileDlg.selectedFile();
575 // append default extension:
576 if (fn.find('.')==-1) {
577 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
584 // overwrite warning:
585 if(QFileInfo(fn).exists()) {
587 QMessageBox::warning(this, tr("Save Drawing As"),
588 tr("%1 already exists.\n"
589 "Do you want to replace it?")
592 tr("Cancel"), 0, 1 );
615 // store new default settings:
617 RS_SETTINGS->beginGroup("/Paths");
618 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
619 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
620 RS_SETTINGS->endGroup();
628 * Shows a dialog for choosing a file name. Opening the file is up to
631 * @return File name with path and extension to determine the file type
632 * or an empty string if the dialog was cancelled.
634 QString QG_DialogFactory::requestImageOpenDialog()
638 // read default settings:
639 settings.beginGroup("Paths");
640 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
641 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
646 // Q3FileDialog fileDlg(NULL, "", true);
647 QFileDialog fileDlg(NULL, "");
650 // Q3StrList f = QImageIO::inputFormats();
651 // QStringList formats = QStringList::fromStrList(f);
652 QList<QByteArray> f = QImageReader::supportedImageFormats();
653 QStringList formats = ???
655 #warning "Needs porting to Qt4... !!! FIX !!!"
660 //filters = QStringList::fromStrList(formats);
663 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
671 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
675 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
685 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
689 all += QString("*.%1").arg(QString(*it).lower());
694 filters.append(QObject::tr("All Image Files (%1)").arg(all));
695 filters.append(QObject::tr("All Files (*.*)"));
697 //filters.append("Drawing Exchange (*.)");
698 //filters.append("Font (*.cxf)");
700 fileDlg.setFilters(filters);
701 // fileDlg.setMode(Q3FileDialog::ExistingFile);
702 fileDlg.setFileMode(QFileDialog::ExistingFile);
703 // fileDlg.setCaption(QObject::tr("Open Image"));
704 fileDlg.setWindowTitle(QObject::tr("Open Image"));
705 // fileDlg.setDir(defDir);
706 fileDlg.setDirectory(defDir);
707 // fileDlg.setSelectedFilter(defFilter);
708 fileDlg.selectFilter(defFilter);
712 if (fileDlg.exec() == QDialog::Accepted)
714 // fn = fileDlg.selectedFile();
715 QStringList files = fileDlg.selectedFiles();
717 if (!files.isEmpty())
723 // store new default settings:
726 QStringList files = fileDlg.selectedFiles();
727 QString selected = "";
729 if (!files.isEmpty())
732 settings.beginGroup("Paths");
733 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
734 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
735 settings.setValue("ImageFilter", selected);
742 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
744 RS_DEBUG->print("QG_DialogFactory::requestOptions");
748 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
752 switch (action->rtti())
754 case RS2::ActionPrintPreview:
755 requestPrintPreviewOptions(action, on, update);
758 case RS2::ActionDrawLine:
759 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
760 requestLineOptions(action, on);
761 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
764 case RS2::ActionDrawPolyline:
765 requestPolylineOptions(action, on, update);
768 case RS2::ActionDrawLineAngle:
769 requestLineAngleOptions(action, on, update);
772 case RS2::ActionDrawLineParallel:
773 requestLineParallelOptions(action, on, update);
776 case RS2::ActionDrawLineParallelThrough:
777 requestLineParallelThroughOptions(action, on, update);
780 case RS2::ActionDrawLineBisector:
781 requestLineBisectorOptions(action, on, update);
784 case RS2::ActionDrawLineRelAngle:
785 requestLineRelAngleOptions(action, on, update);
788 case RS2::ActionDrawLinePolygon:
789 requestLinePolygonOptions(action, on, update);
792 case RS2::ActionDrawLinePolygon2:
793 requestLinePolygon2Options(action, on, update);
796 case RS2::ActionDrawArc:
797 requestArcOptions(action, on, update);
800 case RS2::ActionDrawArcTangential:
801 requestArcTangentialOptions(action, on, update);
804 case RS2::ActionDrawCircleCR:
805 requestCircleOptions(action, on, update);
808 case RS2::ActionDrawSpline:
809 requestSplineOptions(action, on, update);
812 case RS2::ActionDrawText:
813 requestTextOptions(action, on, update);
816 case RS2::ActionBlocksInsert:
817 requestInsertOptions(action, on, update);
820 case RS2::ActionDrawImage:
821 requestImageOptions(action, on, update);
824 case RS2::ActionDimAligned:
825 requestDimensionOptions(action, on, update);
828 case RS2::ActionDimLinear:
829 requestDimensionOptions(action, on, update);
831 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
832 requestDimLinearOptions(action, on, update);
836 case RS2::ActionDimRadial:
837 requestDimensionOptions(action, on, update);
840 case RS2::ActionDimDiametric:
841 requestDimensionOptions(action, on, update);
844 case RS2::ActionDimAngular:
845 requestDimensionOptions(action, on, update);
848 case RS2::ActionModifyTrimAmount:
849 requestTrimAmountOptions(action, on, update);
852 case RS2::ActionModifyMoveRotate:
853 requestMoveRotateOptions(action, on, update);
856 case RS2::ActionModifyBevel:
857 requestBevelOptions(action, on, update);
860 case RS2::ActionModifyRound:
861 requestRoundOptions(action, on, update);
864 case RS2::ActionLibraryInsert:
865 requestLibraryInsertOptions(action, on, update);
872 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
876 * Shows a widget for options for the action: "print preview"
878 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
880 static PrintPreviewOptions * toolWidget = NULL;
893 toolWidget = new PrintPreviewOptions(optionWidget);
894 toolWidget->setAction(action, update);
899 * Shows a widget for options for the action: "draw line"
901 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
904 The way I see it, this is failure. We're constantly creating & deleting
905 these objects all the time when we could create them once, and then reuse
906 them over and over. May need to do some more refactoring based on this idea...
909 static LineOptions * toolWidget = NULL;
914 // Get rid of the LineOptions object if it exists...
921 // Create a new one for the passed in action
924 toolWidget = new LineOptions(optionWidget);
925 toolWidget->setAction(action);
928 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
932 * Shows a widget for options for the action: "draw polyline"
934 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
937 static PolylineOptions * toolWidget = NULL;
939 if (optionWidget != NULL)
941 if (toolWidget != NULL)
946 if (on && toolWidget == NULL)
948 toolWidget = new PolylineOptions(optionWidget);
949 toolWidget->setAction(action, update);
957 * Shows a widget for insert options.
959 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action,
960 bool on, bool update)
962 static QG_InsertOptions* toolWidget = NULL;
964 if (optionWidget!=NULL) {
965 if (toolWidget!=NULL) {
969 if (on==true && toolWidget==NULL) {
970 toolWidget = new QG_InsertOptions(optionWidget);
971 toolWidget->setAction(action, update);
977 * Shows a widget for image options.
979 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action,
980 bool on, bool update)
982 static QG_ImageOptions* toolWidget = NULL;
984 if (optionWidget!=NULL) {
985 if (toolWidget!=NULL) {
989 if (on==true && toolWidget==NULL) {
990 toolWidget = new QG_ImageOptions(optionWidget);
991 toolWidget->setAction(action, update);
997 * Shows a widget for library insert options.
999 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action,
1000 bool on, bool update)
1002 static QG_LibraryInsertOptions* toolWidget = NULL;
1004 if (optionWidget!=NULL) {
1005 if (toolWidget!=NULL) {
1009 if (on==true && toolWidget==NULL) {
1010 toolWidget = new QG_LibraryInsertOptions(optionWidget);
1011 toolWidget->setAction(action, update);
1017 * Shows a widget for options for the action: "draw line parallel"
1019 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
1021 static LineParallelOptions * toolWidget = NULL;
1023 if (optionWidget!=NULL)
1025 if (toolWidget!=NULL)
1030 if (on==true && toolWidget==NULL)
1032 toolWidget = new LineParallelOptions(optionWidget);
1033 toolWidget->setAction(action, update);
1039 * Shows a widget for options for the action: "draw line parallel through"
1041 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface * action, bool on, bool update)
1043 static LineParallelThroughOptions * toolWidget = NULL;
1045 if (optionWidget!=NULL) {
1046 if (toolWidget!=NULL) {
1050 if (on==true && toolWidget==NULL) {
1051 toolWidget = new LineParallelThroughOptions(optionWidget);
1052 toolWidget->setAction(action, update);
1058 * Shows a widget for options for the action: "line angle"
1060 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface * action, bool on, bool update)
1062 static LineAngleOptions * toolWidget = NULL;
1075 toolWidget = new LineAngleOptions(optionWidget);
1076 toolWidget->setAction(action, update);
1081 * Shows a widget for options for the action: "line relative angle"
1083 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface * action, bool on, bool update)
1085 static LineRelAngleOptions * toolWidget = NULL;
1098 toolWidget = new LineRelAngleOptions(optionWidget);
1099 toolWidget->setAction(action, update);
1104 * Shows a widget for options for the action: "line angle"
1106 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface * action, bool on, bool update)
1108 static LineBisectorOptions * toolWidget = NULL;
1110 if (optionWidget!=NULL) {
1111 if (toolWidget!=NULL) {
1115 if (on==true && toolWidget==NULL) {
1116 toolWidget = new LineBisectorOptions(optionWidget);
1117 toolWidget->setAction(action, update);
1123 * Shows a widget for options for the action: "draw polygon"
1125 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface * action, bool on, bool update)
1127 static LinePolygonOptions * toolWidget = NULL;
1129 if (optionWidget!=NULL) {
1130 if (toolWidget!=NULL) {
1134 if (on==true && toolWidget==NULL) {
1135 toolWidget = new LinePolygonOptions(optionWidget);
1136 toolWidget->setAction(action, update);
1142 * Shows a widget for options for the action: "draw polygon2"
1144 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface * action, bool on, bool update)
1146 static LinePolygon2Options * toolWidget = NULL;
1148 if (optionWidget!=NULL) {
1149 if (toolWidget!=NULL) {
1153 if (on==true && toolWidget==NULL) {
1154 toolWidget = new LinePolygon2Options(optionWidget);
1155 toolWidget->setAction(action, update);
1161 * Shows a widget for arc options.
1163 void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
1165 static ArcOptions * toolWidget = NULL;
1167 if (optionWidget != NULL)
1169 if (toolWidget != NULL)
1175 if (on && toolWidget == NULL)
1177 toolWidget = new ArcOptions(optionWidget);
1178 toolWidget->setAction(action, update);
1179 //toolWidget->setData(&data);
1185 * Shows a widget for tangential arc options.
1187 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
1189 static ArcTangentialOptions * toolWidget = NULL;
1202 toolWidget = new ArcTangentialOptions(optionWidget);
1203 toolWidget->setAction(action, update);
1204 //toolWidget->setData(&data);
1209 * Shows a widget for circle options.
1211 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
1213 static CircleOptions * toolWidget = NULL;
1223 if (on && toolWidget == NULL)
1225 toolWidget = new CircleOptions(optionWidget);
1226 toolWidget->setAction(action, update);
1232 * Shows a widget for spline options.
1234 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface * action, bool on, bool update)
1236 static SplineOptions * toolWidget = NULL;
1238 if (optionWidget!=NULL) {
1239 if (toolWidget!=NULL) {
1243 if (on==true && toolWidget==NULL) {
1244 toolWidget = new SplineOptions(optionWidget);
1245 toolWidget->setAction(action, update);
1251 * Shows a widget for text options.
1253 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1255 static TextOptions * toolWidget = NULL;
1268 toolWidget = new TextOptions(optionWidget);
1269 toolWidget->setAction(action, update);
1273 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action, bool on, bool update)
1277 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action, bool on, bool update)
1282 * Shows a widget for dimension options.
1284 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface * action, bool on, bool update)
1286 static DimOptions * toolWidget = NULL;
1288 if (optionWidget!=NULL) {
1289 if (toolWidget!=NULL) {
1293 if (on==true && toolWidget==NULL) {
1294 toolWidget = new DimOptions(optionWidget);
1295 toolWidget->setAction(action, update);
1301 * Shows a widget for linear dimension options.
1303 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface * action, bool on, bool update)
1305 static DimLinearOptions * toolWidget = NULL;
1318 toolWidget = new DimLinearOptions(optionWidget);
1319 toolWidget->setAction(action, update);
1324 * Shows a widget for 'snap to a point with a given distance' options.
1326 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1328 static SnapDistOptions * toolWidget = NULL;
1341 toolWidget = new SnapDistOptions(optionWidget);
1342 toolWidget->setDist(&dist);
1347 * Shows a widget for 'snap to a point with a given distance' options.
1349 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface * action, bool on, bool update)
1351 static MoveRotateOptions * toolWidget = NULL;
1364 toolWidget = new MoveRotateOptions(optionWidget);
1365 toolWidget->setAction(action, update);
1370 * Shows a widget for 'trim amount' options.
1372 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface * action, bool on, bool update)
1374 static TrimAmountOptions * toolWidget = NULL;
1387 toolWidget = new TrimAmountOptions(optionWidget);
1388 toolWidget->setAction(action, update);
1393 * Shows a widget for beveling options.
1395 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1397 static BevelOptions * toolWidget = NULL;
1399 if (optionWidget != NULL)
1401 if (toolWidget != NULL)
1407 if (on && toolWidget == NULL)
1409 toolWidget = new BevelOptions(optionWidget);
1410 toolWidget->setAction(action, update);
1416 * Shows a widget for rounding options.
1418 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface * action, bool on, bool update)
1420 static RoundOptions * toolWidget = NULL;
1433 toolWidget = new RoundOptions(optionWidget);
1434 toolWidget->setAction(action, update);
1438 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action, bool on, bool update)
1444 * Shows the given toolbar.
1446 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1448 if (cadToolBar != NULL)
1449 cadToolBar->showToolBar(id);
1453 * Shows the select toolbar with the given action to launch.
1455 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1456 RS2::ActionType nextAction)
1458 if (cadToolBar != NULL)
1459 cadToolBar->showToolBarSelect(selectAction, nextAction);
1464 * Shows move options dialog presenting the given data.
1466 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1468 QG_DlgMove dlg(parent);
1481 * Shows rotate options dialog presenting the given data.
1483 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1485 QG_DlgRotate dlg(parent);
1498 * Shows scale options dialog presenting the given data.
1500 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1502 QG_DlgScale dlg(parent);
1515 * Shows mirror options dialog presenting the given data.
1517 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1519 QG_DlgMirror dlg(parent);
1532 * Shows move/rotate options dialog presenting the given data.
1534 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1536 QG_DlgMoveRotate dlg(parent);
1549 * Shows rotate around two centers options dialog presenting the given data.
1551 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1553 QG_DlgRotate2 dlg(parent);
1566 * Shows a dialog to edit the given entity.
1568 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1575 switch (entity->rtti())
1577 case RS2::EntityPoint:
1579 QG_DlgPoint dlg(parent);
1580 dlg.setPoint(*((RS_Point *)entity));
1590 case RS2::EntityLine:
1592 QG_DlgLine dlg(parent);
1593 dlg.setLine(*((RS_Line *)entity));
1603 case RS2::EntityArc:
1605 QG_DlgArc dlg(parent);
1606 dlg.setArc(*((RS_Arc *)entity));
1616 case RS2::EntityCircle:
1618 QG_DlgCircle dlg(parent);
1619 dlg.setCircle(*((RS_Circle *)entity));
1629 case RS2::EntityEllipse:
1631 QG_DlgEllipse dlg(parent);
1632 dlg.setEllipse(*((RS_Ellipse *)entity));
1636 dlg.updateEllipse();
1642 case RS2::EntitySpline:
1644 QG_DlgSpline dlg(parent);
1645 dlg.setSpline(*((RS_Spline *)entity));
1655 case RS2::EntityInsert:
1657 QG_DlgInsert dlg(parent);
1658 dlg.setInsert(*((RS_Insert *)entity));
1669 case RS2::EntityDimAligned:
1670 case RS2::EntityDimAngular:
1671 case RS2::EntityDimDiametric:
1672 case RS2::EntityDimRadial:
1674 QG_DlgDimension dlg(parent);
1675 dlg.setDim(*((RS_Dimension *)entity));
1681 ((RS_Dimension *)entity)->update(true);
1686 case RS2::EntityDimLinear:
1688 QG_DlgDimLinear dlg(parent);
1689 dlg.setDim(*((RS_DimLinear *)entity));
1695 ((RS_DimLinear *)entity)->update(true);
1700 case RS2::EntityText:
1702 QG_DlgText dlg(parent);
1703 dlg.setText(*((RS_Text *)entity), false);
1709 ((RS_Text *)entity)->update();
1714 case RS2::EntityHatch:
1716 QG_DlgHatch dlg(parent);
1717 dlg.setHatch(*((RS_Hatch *)entity), false);
1723 ((RS_Hatch *)entity)->update();
1736 * Shows a dialog to edit the attributes of the given dimension entity.
1739 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1744 QG_DlgDimAligned dlg(parent);
1745 dlg.setDim(*dim, true);
1756 * Shows a dialog to edit the attributes of the given text entity.
1758 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1763 QG_DlgText dlg(parent);
1764 dlg.setText(*text, true);
1776 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1778 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1783 RS_PATTERNLIST->init();
1785 QG_DlgHatch dlg(parent);
1786 dlg.setHatch(*hatch, true);
1798 * Shows attributes options dialog presenting the given data.
1800 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1802 DlgAttributes dlg(parent);
1803 dlg.setData(&data, layerList);
1814 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1819 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1824 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1829 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1834 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1839 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1845 * Shows a dialog to edit the given entity.
1847 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1854 switch (entity->rtti())
1856 //NOTE: These #if 0's are put here until these missing dialogs can be ported to Qt4.
1858 case RS2::EntityPoint:
1860 QG_DlgPoint dlg(parent);
1861 dlg.setPoint(*((RS_Point *)entity));
1871 case RS2::EntityLine:
1873 QG_DlgLine dlg(parent);
1874 dlg.setLine(*((RS_Line *)entity));
1884 case RS2::EntityArc:
1886 QG_DlgArc dlg(parent);
1887 dlg.setArc(*((RS_Arc *)entity));
1897 case RS2::EntityCircle:
1899 QG_DlgCircle dlg(parent);
1900 dlg.setCircle(*((RS_Circle *)entity));
1910 case RS2::EntityEllipse:
1912 QG_DlgEllipse dlg(parent);
1913 dlg.setEllipse(*((RS_Ellipse *)entity));
1917 dlg.updateEllipse();
1923 case RS2::EntitySpline:
1925 QG_DlgSpline dlg(parent);
1926 dlg.setSpline(*((RS_Spline *)entity));
1936 case RS2::EntityInsert:
1938 QG_DlgInsert dlg(parent);
1939 dlg.setInsert(*((RS_Insert *)entity));
1950 case RS2::EntityDimAligned:
1951 case RS2::EntityDimAngular:
1952 case RS2::EntityDimDiametric:
1953 case RS2::EntityDimRadial:
1955 QG_DlgDimension dlg(parent);
1956 dlg.setDim(*((RS_Dimension *)entity));
1962 ((RS_Dimension *)entity)->update(true);
1967 case RS2::EntityDimLinear:
1969 QG_DlgDimLinear dlg(parent);
1970 dlg.setDim(*((RS_DimLinear *)entity));
1976 ((RS_DimLinear *)entity)->update(true);
1982 case RS2::EntityText:
1984 DlgText dlg(parent);
1985 dlg.setText(*((RS_Text *)entity), false);
1991 ((RS_Text *)entity)->update();
1997 case RS2::EntityHatch:
1999 QG_DlgHatch dlg(parent);
2000 dlg.setHatch(*((RS_Hatch *)entity), false);
2006 ((RS_Hatch *)entity)->update();
2020 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
2026 * Shows a dialog to edit the attributes of the given text entity.
2028 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
2033 DlgText dlg(parent);
2034 dlg.setText(*text, true);
2045 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
2053 * Shows a dialog for CAM options.
2055 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
2057 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
2058 RS_CamDialog dlg(graphic, parent);
2059 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
2063 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
2067 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
2073 * Shows dialog for general application options.
2075 void QG_DialogFactory::requestOptionsGeneralDialog()
2077 DlgOptionsGeneral dlg(parent);
2082 * Shows dialog for drawing options.
2084 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
2086 DlgOptionsDrawing dlg(parent);
2087 dlg.setGraphic(&graphic);
2092 * Back to last menu in cad toolbar.
2094 void QG_DialogFactory::requestPreviousMenu()
2096 if (cadToolBar != NULL)
2097 cadToolBar->showToolBarMain();
2101 * Called whenever the mouse position changed.
2103 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
2104 const Vector & rel, bool updateFormat)
2106 if (coordinateWidget != NULL)
2107 coordinateWidget->setCoordinates(abs, rel, updateFormat);
2111 * Called when an action has a mouse hint.
2113 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
2115 if (mouseWidget != NULL)
2116 mouseWidget->setHelp(left, right);
2118 if (commandWidget != NULL)
2119 commandWidget->setCommand(left);
2123 * Called whenever the selection changed.
2125 void QG_DialogFactory::updateSelectionWidget(int num)
2127 if (selectionWidget != NULL)
2128 selectionWidget->setNumber(num);
2132 * Called when an action needs to communicate 'message' to the user.
2134 void QG_DialogFactory::commandMessage(const QString& message)
2136 RS_DEBUG->print("QG_DialogFactory::commandMessage");
2138 if (commandWidget != NULL)
2139 commandWidget->appendHistory(message);
2141 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
2144 /*virtual*/ bool QG_DialogFactory::isAdapter()
2150 * Converts an extension to a format description.
2151 * e.g. "PNG" to "Portable Network Graphic"
2154 * @return Format description
2156 QString QG_DialogFactory::extToFormat(const QString & ext)
2158 QString e = ext.toLower();
2161 return QObject::tr("Windows Bitmap");
2162 else if (e == "jpeg" || e == "jpg")
2163 return QObject::tr("Joint Photographic Experts Group");
2164 else if (e == "gif")
2165 return QObject::tr("Graphics Interchange Format");
2166 else if (e == "mng")
2167 return QObject::tr("Multiple-image Network Graphics");
2168 else if (e == "pbm")
2169 return QObject::tr("Portable Bit Map");
2170 else if (e == "pgm")
2171 return QObject::tr("Portable Grey Map");
2172 else if (e == "png")
2173 return QObject::tr("Portable Network Graphic");
2174 else if (e == "ppm")
2175 return QObject::tr("Portable Pixel Map");
2176 else if (e == "xbm")
2177 return QObject::tr("X Bitmap Format");
2178 else if (e == "xpm")
2179 return QObject::tr("X Pixel Map");
2181 return ext.toUpper();