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 "dlgattributes.h"
89 #include "dlgoptionsdrawing.h"
90 #include "dlgoptionsgeneral.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"
101 #include "qg_polylineoptions.h"
105 #include "rs_camdialog.h"
108 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
113 * @param parent Pointer to parent widget which can host dialogs.
114 * @param ow Pointer to widget that can host option widgets.
116 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
117 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
118 RS_DialogFactoryInterface()
120 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
122 this->parent = parent;
125 coordinateWidget = NULL;
127 selectionWidget = NULL;
129 commandWidget = NULL;
131 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
137 QG_DialogFactory::~QG_DialogFactory()
139 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
140 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
144 * Links factory to a widget that can host tool options.
146 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
147 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
149 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
151 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
155 * Links this dialog factory to a coordinate widget.
157 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
159 coordinateWidget = cw;
163 * Links this dialog factory to a mouse widget.
165 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
171 * Links this dialog factory to a selection widget.
173 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
175 selectionWidget = sw;
179 * Links this dialog factory to the cad tool bar.
181 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
187 * @return cad tool bar or NULL.
189 CadToolBar * QG_DialogFactory::getCadToolBar()
195 * Links this dialog factory to a command widget.
197 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
203 * @return command widget or NULL.
205 CommandWidget * QG_DialogFactory::getCommandWidget()
207 return commandWidget;
211 * Links the dialog factory to a main app window.
213 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
219 * Shows a message dialog.
221 void QG_DialogFactory::requestWarningDialog(const QString & warning)
223 QMessageBox::information(parent, QMessageBox::tr("Warning"),
224 warning, QMessageBox::Ok);
228 * Requests a new document from the main window.
230 RS_GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
232 if (mainWindow != NULL)
234 mainWindow->createNewDocument(fileName, doc);
235 return mainWindow->getGraphicView();
242 * Requests the simulation controls.
244 void QG_DialogFactory::requestSimulationControls()
246 if (mainWindow != NULL)
248 mainWindow->showSimulationControls();
253 * Shows a dialog for adding a layer. Doesn't add the layer.
254 * This is up to the caller.
256 * @return a pointer to the newly created layer that
259 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
261 RS_Layer * layer = NULL;
262 QString layer_name = "noname";
265 if (layerList != NULL)
267 while (layerList->find(layer_name) > 0)
268 layer_name.sprintf("noname%d", i++);
271 // Layer for parameter livery
272 layer = new RS_Layer(layer_name);
274 // QG_LayerDialog dlg(parent, "Layer Dialog");
275 LayerDialog dlg(parent);
277 dlg.setLayerList(layerList);
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.
294 * @return a pointer to the layer that should be removed.
296 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
298 RS_Layer * layer = NULL;
300 if (layerList == NULL)
302 RS_DEBUG->print(RS_Debug::D_WARNING,
303 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
308 if (layerList==NULL) {
309 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
310 layerList = (RS_LayerList*)container;
316 // Layer for parameter livery
317 layer = layerList->getActive();
321 if (layer->getName() != "0")
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);
337 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
338 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
347 * Shows a dialog for editing a layer. A new layer is created and
348 * returned. Modifying the layer is up to the caller.
350 * @return A pointer to a new layer with the changed attributes
351 * or NULL if the dialog was cancelled.
353 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
355 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
356 RS_Layer * layer = NULL;
358 if (layerList==NULL) {
359 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
360 layerList = (RS_LayerList*)container;
367 if (layerList == NULL)
369 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
370 "layerList is NULL");
374 // Layer for parameter livery
375 if (layerList->getActive() != NULL)
377 layer = new RS_Layer(*layerList->getActive());
379 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
380 LayerDialog dlg(parent);
382 dlg.setLayerList(layerList);
383 dlg.setEditLayer(true);
398 * Shows a dialog for adding a block. Doesn't add the block.
399 * This is up to the caller.
401 * @return a pointer to the newly created block that
404 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
406 //RS_Block* block = NULL;
408 ret = RS_BlockData("", Vector(false), false);
410 if (blockList == NULL)
412 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
413 "blockList is NULL");
417 // Block for parameter livery
418 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
420 BlockDialog dlg(parent);
421 dlg.setBlockList(blockList);
424 ret = dlg.getBlockData();
430 * Shows a dialog for renaming the currently active block.
432 * @return a pointer to the modified block or NULL on cancellation.
434 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
436 //RS_Block* block = NULL;
438 ret = RS_BlockData("", Vector(false), false);
440 if (blockList == NULL)
442 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
443 "blockList is NULL");
447 if (blockList==NULL) {
448 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
449 blockList = (RS_BlockList*)container;
455 // Block for parameter livery
456 //block = blockList->getActive();
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);
467 ret = dlg.getBlockData();
470 // ret = RS_BlockData("", Vector(false));
476 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
480 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
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.
488 * @return a pointer to the block that should be removed.
490 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
492 RS_Block * block = NULL;
494 if (blockList == NULL)
496 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
497 "blockList is NULL");
501 // Block for parameter livery
502 block = blockList->getActive();
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);
523 * Shows a dialog for choosing a file name. Saving the file is up to
526 * @return File name with path and extension to determine the file type
527 * or an empty string if the dialog was cancelled.
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();
539 // prepare file save as dialog:
540 QFileDialog fileDlg(this,0,true);
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);
557 if (fileDlg.exec()==QDialog::Accepted) {
558 fn = fileDlg.selectedFile();
561 // append default extension:
562 if (fn.find('.')==-1) {
563 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
570 // overwrite warning:
571 if(QFileInfo(fn).exists()) {
573 QMessageBox::warning(this, tr("Save Drawing As"),
574 tr("%1 already exists.\n"
575 "Do you want to replace it?")
578 tr("Cancel"), 0, 1 );
601 // store new default settings:
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();
614 * Shows a dialog for choosing a file name. Opening the file is up to
617 * @return File name with path and extension to determine the file type
618 * or an empty string if the dialog was cancelled.
620 QString QG_DialogFactory::requestImageOpenDialog()
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();
632 // Q3FileDialog fileDlg(NULL, "", true);
633 QFileDialog fileDlg(NULL, "");
636 // Q3StrList f = QImageIO::inputFormats();
637 // QStringList formats = QStringList::fromStrList(f);
638 QList<QByteArray> f = QImageReader::supportedImageFormats();
639 QStringList formats = ???
641 #warning "Needs porting to Qt4... !!! FIX !!!"
646 //filters = QStringList::fromStrList(formats);
649 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
657 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
661 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
671 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
675 all += QString("*.%1").arg(QString(*it).lower());
680 filters.append(QObject::tr("All Image Files (%1)").arg(all));
681 filters.append(QObject::tr("All Files (*.*)"));
683 //filters.append("Drawing Exchange (*.)");
684 //filters.append("Font (*.cxf)");
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);
698 if (fileDlg.exec() == QDialog::Accepted)
700 // fn = fileDlg.selectedFile();
701 QStringList files = fileDlg.selectedFiles();
703 if (!files.isEmpty())
709 // store new default settings:
712 QStringList files = fileDlg.selectedFiles();
713 QString selected = "";
715 if (!files.isEmpty())
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);
728 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
730 RS_DEBUG->print("QG_DialogFactory::requestOptions");
734 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
738 switch (action->rtti())
740 case RS2::ActionPrintPreview:
741 requestPrintPreviewOptions(action, on, update);
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");
750 case RS2::ActionDrawPolyline:
751 requestPolylineOptions(action, on, update);
754 case RS2::ActionDrawLineAngle:
755 requestLineAngleOptions(action, on, update);
758 case RS2::ActionDrawLineParallel:
759 requestLineParallelOptions(action, on, update);
762 case RS2::ActionDrawLineParallelThrough:
763 requestLineParallelThroughOptions(action, on, update);
766 case RS2::ActionDrawLineBisector:
767 requestLineBisectorOptions(action, on, update);
770 case RS2::ActionDrawLineRelAngle:
771 requestLineRelAngleOptions(action, on, update);
774 case RS2::ActionDrawLinePolygon:
775 requestLinePolygonOptions(action, on, update);
778 case RS2::ActionDrawLinePolygon2:
779 requestLinePolygon2Options(action, on, update);
782 case RS2::ActionDrawArc:
783 requestArcOptions(action, on, update);
786 case RS2::ActionDrawArcTangential:
787 requestArcTangentialOptions(action, on, update);
790 case RS2::ActionDrawCircleCR:
791 requestCircleOptions(action, on, update);
794 case RS2::ActionDrawSpline:
795 requestSplineOptions(action, on, update);
798 case RS2::ActionDrawText:
799 requestTextOptions(action, on, update);
802 case RS2::ActionBlocksInsert:
803 requestInsertOptions(action, on, update);
806 case RS2::ActionDrawImage:
807 requestImageOptions(action, on, update);
810 case RS2::ActionDimAligned:
811 requestDimensionOptions(action, on, update);
814 case RS2::ActionDimLinear:
815 requestDimensionOptions(action, on, update);
817 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
818 requestDimLinearOptions(action, on, update);
822 case RS2::ActionDimRadial:
823 requestDimensionOptions(action, on, update);
826 case RS2::ActionDimDiametric:
827 requestDimensionOptions(action, on, update);
830 case RS2::ActionDimAngular:
831 requestDimensionOptions(action, on, update);
834 case RS2::ActionModifyTrimAmount:
835 requestTrimAmountOptions(action, on, update);
838 case RS2::ActionModifyMoveRotate:
839 requestMoveRotateOptions(action, on, update);
842 case RS2::ActionModifyBevel:
843 requestBevelOptions(action, on, update);
846 case RS2::ActionModifyRound:
847 requestRoundOptions(action, on, update);
850 case RS2::ActionLibraryInsert:
851 requestLibraryInsertOptions(action, on, update);
858 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
862 * Shows a widget for options for the action: "print preview"
864 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
866 static PrintPreviewOptions * toolWidget = NULL;
879 toolWidget = new PrintPreviewOptions(optionWidget);
880 toolWidget->setAction(action, update);
885 * Shows a widget for options for the action: "draw line"
887 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
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...
895 static LineOptions * toolWidget = NULL;
900 // Get rid of the LineOptions object if it exists...
907 // Create a new one for the passed in action
910 toolWidget = new LineOptions(optionWidget);
911 toolWidget->setAction(action);
914 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
918 * Shows a widget for options for the action: "draw polyline"
920 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
923 static QG_PolylineOptions * toolWidget = NULL;
925 if (optionWidget != NULL)
927 if (toolWidget != NULL)
932 if (on && toolWidget == NULL)
934 toolWidget = new QG_PolylineOptions(optionWidget);
935 toolWidget->setAction(action, update);
943 * Shows a widget for options for the action: "draw line parallel"
945 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
947 static QG_LineParallelOptions* toolWidget = NULL;
949 if (optionWidget!=NULL) {
950 if (toolWidget!=NULL) {
954 if (on==true && toolWidget==NULL) {
955 toolWidget = new QG_LineParallelOptions(optionWidget);
956 toolWidget->setAction(action, update);
962 * Shows a widget for options for the action: "draw line parallel through"
964 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action,
965 bool on, bool update)
967 static QG_LineParallelThroughOptions* toolWidget = NULL;
969 if (optionWidget!=NULL) {
970 if (toolWidget!=NULL) {
974 if (on==true && toolWidget==NULL) {
975 toolWidget = new QG_LineParallelThroughOptions(optionWidget);
976 toolWidget->setAction(action, update);
982 * Shows a widget for options for the action: "line angle"
984 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action,
985 bool on, bool update)
987 static QG_LineAngleOptions* toolWidget = NULL;
989 if (optionWidget!=NULL) {
990 if (toolWidget!=NULL) {
994 if (on==true && toolWidget==NULL) {
995 toolWidget = new QG_LineAngleOptions(optionWidget);
996 toolWidget->setAction(action, update);
997 //toolWidget->setData(&angle, &length, fixedAngle, update);
1003 * Shows a widget for options for the action: "line relative angle"
1005 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action,
1006 bool on, bool update)
1008 static QG_LineRelAngleOptions* toolWidget = NULL;
1010 if (optionWidget!=NULL) {
1011 if (toolWidget!=NULL) {
1015 if (on==true && toolWidget==NULL) {
1016 toolWidget = new QG_LineRelAngleOptions(optionWidget);
1017 toolWidget->setAction(action, update);
1018 //toolWidget->setData(&angle, &length, fixedAngle, update);
1024 * Shows a widget for options for the action: "line angle"
1026 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action,
1027 bool on, bool update)
1029 static QG_LineBisectorOptions* toolWidget = NULL;
1031 if (optionWidget!=NULL) {
1032 if (toolWidget!=NULL) {
1036 if (on==true && toolWidget==NULL) {
1037 toolWidget = new QG_LineBisectorOptions(optionWidget);
1038 toolWidget->setAction(action, update);
1044 * Shows a widget for options for the action: "draw polygon"
1046 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action,
1047 bool on, bool update)
1049 static QG_LinePolygonOptions* toolWidget = NULL;
1051 if (optionWidget!=NULL) {
1052 if (toolWidget!=NULL) {
1056 if (on==true && toolWidget==NULL) {
1057 toolWidget = new QG_LinePolygonOptions(optionWidget);
1058 toolWidget->setAction(action, update);
1064 * Shows a widget for options for the action: "draw polygon2"
1066 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action,
1067 bool on, bool update)
1069 static QG_LinePolygon2Options* toolWidget = NULL;
1071 if (optionWidget!=NULL) {
1072 if (toolWidget!=NULL) {
1076 if (on==true && toolWidget==NULL) {
1077 toolWidget = new QG_LinePolygon2Options(optionWidget);
1078 toolWidget->setAction(action, update);
1084 * Shows a widget for spline options.
1086 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action,
1087 bool on, bool update)
1089 static QG_SplineOptions* toolWidget = NULL;
1091 if (optionWidget!=NULL) {
1092 if (toolWidget!=NULL) {
1096 if (on==true && toolWidget==NULL) {
1097 toolWidget = new QG_SplineOptions(optionWidget);
1098 toolWidget->setAction(action, update);
1104 * Shows a widget for insert options.
1106 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action,
1107 bool on, bool update)
1109 static QG_InsertOptions* toolWidget = NULL;
1111 if (optionWidget!=NULL) {
1112 if (toolWidget!=NULL) {
1116 if (on==true && toolWidget==NULL) {
1117 toolWidget = new QG_InsertOptions(optionWidget);
1118 toolWidget->setAction(action, update);
1124 * Shows a widget for image options.
1126 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action,
1127 bool on, bool update)
1129 static QG_ImageOptions* toolWidget = NULL;
1131 if (optionWidget!=NULL) {
1132 if (toolWidget!=NULL) {
1136 if (on==true && toolWidget==NULL) {
1137 toolWidget = new QG_ImageOptions(optionWidget);
1138 toolWidget->setAction(action, update);
1144 * Shows a widget for dimension options.
1146 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface* action,
1147 bool on, bool update)
1149 //static QLabel* l = NULL;
1150 static QG_DimOptions* toolWidget = NULL;
1152 if (optionWidget!=NULL) {
1153 if (toolWidget!=NULL) {
1157 if (on==true && toolWidget==NULL) {
1158 toolWidget = new QG_DimOptions(optionWidget);
1159 toolWidget->setAction(action, update);
1165 * Shows a widget for linear dimension options.
1167 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface* action,
1168 bool on, bool update)
1170 //static QLabel* l = NULL;
1171 static QG_DimLinearOptions* toolWidget = NULL;
1173 if (optionWidget!=NULL) {
1174 if (toolWidget!=NULL) {
1178 if (on==true && toolWidget==NULL) {
1179 toolWidget = new QG_DimLinearOptions(optionWidget);
1180 toolWidget->setAction(action, update);
1186 * Shows a widget for 'snap to a point with a given distance' options.
1188 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1190 static QG_SnapDistOptions* toolWidget = NULL;
1192 if (optionWidget!=NULL) {
1193 if (toolWidget!=NULL) {
1197 if (on==true && toolWidget==NULL) {
1198 toolWidget = new QG_SnapDistOptions(optionWidget);
1199 toolWidget->setDist(&dist);
1205 * Shows a widget for 'snap to a point with a given distance' options.
1207 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action,
1208 bool on, bool update)
1210 static QG_MoveRotateOptions* toolWidget = NULL;
1212 if (optionWidget!=NULL) {
1213 if (toolWidget!=NULL) {
1217 if (on==true && toolWidget==NULL) {
1218 toolWidget = new QG_MoveRotateOptions(optionWidget);
1219 toolWidget->setAction(action, update);
1225 * Shows a widget for 'trim amount' options.
1227 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action,
1228 bool on, bool update)
1230 static QG_TrimAmountOptions* toolWidget = NULL;
1232 if (optionWidget!=NULL) {
1233 if (toolWidget!=NULL) {
1237 if (on==true && toolWidget==NULL) {
1238 toolWidget = new QG_TrimAmountOptions(optionWidget);
1239 toolWidget->setAction(action, update);
1245 * Shows a widget for rounding options.
1247 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action,
1248 bool on, bool update)
1250 static QG_RoundOptions* toolWidget = NULL;
1252 if (optionWidget!=NULL) {
1253 if (toolWidget!=NULL) {
1257 if (on==true && toolWidget==NULL) {
1258 toolWidget = new QG_RoundOptions(optionWidget);
1259 toolWidget->setAction(action, update);
1265 * Shows a widget for library insert options.
1267 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action,
1268 bool on, bool update)
1270 static QG_LibraryInsertOptions* toolWidget = NULL;
1272 if (optionWidget!=NULL) {
1273 if (toolWidget!=NULL) {
1277 if (on==true && toolWidget==NULL) {
1278 toolWidget = new QG_LibraryInsertOptions(optionWidget);
1279 toolWidget->setAction(action, update);
1284 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
1288 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action, bool on, bool update)
1292 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action, bool on, bool update)
1296 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action, bool on, bool update)
1300 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action, bool on, bool update)
1304 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action, bool on, bool update)
1308 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action, bool on, bool update)
1313 * Shows a widget for arc options.
1315 void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
1317 static ArcOptions * toolWidget = NULL;
1319 if (optionWidget != NULL)
1321 if (toolWidget != NULL)
1327 if (on && toolWidget == NULL)
1329 toolWidget = new ArcOptions(optionWidget);
1330 toolWidget->setAction(action, update);
1331 //toolWidget->setData(&data);
1337 * Shows a widget for tangential arc options.
1339 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
1341 static ArcTangentialOptions * toolWidget = NULL;
1354 toolWidget = new ArcTangentialOptions(optionWidget);
1355 toolWidget->setAction(action, update);
1356 //toolWidget->setData(&data);
1361 * Shows a widget for circle options.
1363 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
1365 static CircleOptions * toolWidget = NULL;
1375 if (on && toolWidget == NULL)
1377 toolWidget = new CircleOptions(optionWidget);
1378 toolWidget->setAction(action, update);
1383 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action, bool on, bool update)
1388 * Shows a widget for text options.
1390 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1392 static TextOptions * toolWidget = NULL;
1405 toolWidget = new TextOptions(optionWidget);
1406 toolWidget->setAction(action, update);
1410 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action, bool on, bool update)
1414 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action, bool on, bool update)
1418 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface* action, bool on, bool update)
1422 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface* action, bool on, bool update)
1426 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1430 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action, bool on, bool update)
1434 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action, bool on, bool update)
1439 * Shows a widget for beveling options.
1441 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1443 static BevelOptions * toolWidget = NULL;
1445 if (optionWidget != NULL)
1447 if (toolWidget != NULL)
1453 if (on && toolWidget == NULL)
1455 toolWidget = new BevelOptions(optionWidget);
1456 toolWidget->setAction(action, update);
1461 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action, bool on, bool update)
1465 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action, bool on, bool update)
1471 * Shows the given toolbar.
1473 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1475 if (cadToolBar != NULL)
1476 cadToolBar->showToolBar(id);
1480 * Shows the select toolbar with the given action to launch.
1482 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1483 RS2::ActionType nextAction)
1485 if (cadToolBar != NULL)
1486 cadToolBar->showToolBarSelect(selectAction, nextAction);
1491 * Shows move options dialog presenting the given data.
1493 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1495 QG_DlgMove dlg(parent);
1508 * Shows rotate options dialog presenting the given data.
1510 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1512 QG_DlgRotate dlg(parent);
1525 * Shows scale options dialog presenting the given data.
1527 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1529 QG_DlgScale dlg(parent);
1542 * Shows mirror options dialog presenting the given data.
1544 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1546 QG_DlgMirror dlg(parent);
1559 * Shows move/rotate options dialog presenting the given data.
1561 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1563 QG_DlgMoveRotate dlg(parent);
1576 * Shows rotate around two centers options dialog presenting the given data.
1578 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1580 QG_DlgRotate2 dlg(parent);
1593 * Shows a dialog to edit the given entity.
1595 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1602 switch (entity->rtti())
1604 case RS2::EntityPoint:
1606 QG_DlgPoint dlg(parent);
1607 dlg.setPoint(*((RS_Point *)entity));
1617 case RS2::EntityLine:
1619 QG_DlgLine dlg(parent);
1620 dlg.setLine(*((RS_Line *)entity));
1630 case RS2::EntityArc:
1632 QG_DlgArc dlg(parent);
1633 dlg.setArc(*((RS_Arc *)entity));
1643 case RS2::EntityCircle:
1645 QG_DlgCircle dlg(parent);
1646 dlg.setCircle(*((RS_Circle *)entity));
1656 case RS2::EntityEllipse:
1658 QG_DlgEllipse dlg(parent);
1659 dlg.setEllipse(*((RS_Ellipse *)entity));
1663 dlg.updateEllipse();
1669 case RS2::EntitySpline:
1671 QG_DlgSpline dlg(parent);
1672 dlg.setSpline(*((RS_Spline *)entity));
1682 case RS2::EntityInsert:
1684 QG_DlgInsert dlg(parent);
1685 dlg.setInsert(*((RS_Insert *)entity));
1696 case RS2::EntityDimAligned:
1697 case RS2::EntityDimAngular:
1698 case RS2::EntityDimDiametric:
1699 case RS2::EntityDimRadial:
1701 QG_DlgDimension dlg(parent);
1702 dlg.setDim(*((RS_Dimension *)entity));
1708 ((RS_Dimension *)entity)->update(true);
1713 case RS2::EntityDimLinear:
1715 QG_DlgDimLinear dlg(parent);
1716 dlg.setDim(*((RS_DimLinear *)entity));
1722 ((RS_DimLinear *)entity)->update(true);
1727 case RS2::EntityText:
1729 QG_DlgText dlg(parent);
1730 dlg.setText(*((RS_Text *)entity), false);
1736 ((RS_Text *)entity)->update();
1741 case RS2::EntityHatch:
1743 QG_DlgHatch dlg(parent);
1744 dlg.setHatch(*((RS_Hatch *)entity), false);
1750 ((RS_Hatch *)entity)->update();
1763 * Shows a dialog to edit the attributes of the given dimension entity.
1766 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1771 QG_DlgDimAligned dlg(parent);
1772 dlg.setDim(*dim, true);
1783 * Shows a dialog to edit the attributes of the given text entity.
1785 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1790 QG_DlgText dlg(parent);
1791 dlg.setText(*text, true);
1803 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1805 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1810 RS_PATTERNLIST->init();
1812 QG_DlgHatch dlg(parent);
1813 dlg.setHatch(*hatch, true);
1825 * Shows attributes options dialog presenting the given data.
1827 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1829 DlgAttributes dlg(parent);
1830 dlg.setData(&data, layerList);
1841 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1846 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1851 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1856 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1861 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1866 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1872 * Shows a dialog to edit the given entity.
1874 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1881 switch (entity->rtti())
1883 //NOTE: These #if 0's are put here until these missing dialogs can be ported to Qt4.
1885 case RS2::EntityPoint:
1887 QG_DlgPoint dlg(parent);
1888 dlg.setPoint(*((RS_Point *)entity));
1898 case RS2::EntityLine:
1900 QG_DlgLine dlg(parent);
1901 dlg.setLine(*((RS_Line *)entity));
1911 case RS2::EntityArc:
1913 QG_DlgArc dlg(parent);
1914 dlg.setArc(*((RS_Arc *)entity));
1924 case RS2::EntityCircle:
1926 QG_DlgCircle dlg(parent);
1927 dlg.setCircle(*((RS_Circle *)entity));
1937 case RS2::EntityEllipse:
1939 QG_DlgEllipse dlg(parent);
1940 dlg.setEllipse(*((RS_Ellipse *)entity));
1944 dlg.updateEllipse();
1950 case RS2::EntitySpline:
1952 QG_DlgSpline dlg(parent);
1953 dlg.setSpline(*((RS_Spline *)entity));
1963 case RS2::EntityInsert:
1965 QG_DlgInsert dlg(parent);
1966 dlg.setInsert(*((RS_Insert *)entity));
1977 case RS2::EntityDimAligned:
1978 case RS2::EntityDimAngular:
1979 case RS2::EntityDimDiametric:
1980 case RS2::EntityDimRadial:
1982 QG_DlgDimension dlg(parent);
1983 dlg.setDim(*((RS_Dimension *)entity));
1989 ((RS_Dimension *)entity)->update(true);
1994 case RS2::EntityDimLinear:
1996 QG_DlgDimLinear dlg(parent);
1997 dlg.setDim(*((RS_DimLinear *)entity));
2003 ((RS_DimLinear *)entity)->update(true);
2009 case RS2::EntityText:
2011 DlgText dlg(parent);
2012 dlg.setText(*((RS_Text *)entity), false);
2018 ((RS_Text *)entity)->update();
2024 case RS2::EntityHatch:
2026 QG_DlgHatch dlg(parent);
2027 dlg.setHatch(*((RS_Hatch *)entity), false);
2033 ((RS_Hatch *)entity)->update();
2047 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
2053 * Shows a dialog to edit the attributes of the given text entity.
2055 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
2060 DlgText dlg(parent);
2061 dlg.setText(*text, true);
2072 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
2080 * Shows a dialog for CAM options.
2082 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
2084 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
2085 RS_CamDialog dlg(graphic, parent);
2086 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
2090 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
2094 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
2100 * Shows dialog for general application options.
2102 void QG_DialogFactory::requestOptionsGeneralDialog()
2104 DlgOptionsGeneral dlg(parent);
2109 * Shows dialog for drawing options.
2111 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
2113 DlgOptionsDrawing dlg(parent);
2114 dlg.setGraphic(&graphic);
2119 * Back to last menu in cad toolbar.
2121 void QG_DialogFactory::requestPreviousMenu()
2123 if (cadToolBar != NULL)
2124 cadToolBar->showToolBarMain();
2128 * Called whenever the mouse position changed.
2130 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
2131 const Vector & rel, bool updateFormat)
2133 if (coordinateWidget != NULL)
2134 coordinateWidget->setCoordinates(abs, rel, updateFormat);
2138 * Called when an action has a mouse hint.
2140 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
2142 if (mouseWidget != NULL)
2143 mouseWidget->setHelp(left, right);
2145 if (commandWidget != NULL)
2146 commandWidget->setCommand(left);
2150 * Called whenever the selection changed.
2152 void QG_DialogFactory::updateSelectionWidget(int num)
2154 if (selectionWidget != NULL)
2155 selectionWidget->setNumber(num);
2159 * Called when an action needs to communicate 'message' to the user.
2161 void QG_DialogFactory::commandMessage(const QString& message)
2163 RS_DEBUG->print("QG_DialogFactory::commandMessage");
2165 if (commandWidget != NULL)
2166 commandWidget->appendHistory(message);
2168 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
2171 /*virtual*/ bool QG_DialogFactory::isAdapter()
2177 * Converts an extension to a format description.
2178 * e.g. "PNG" to "Portable Network Graphic"
2181 * @return Format description
2183 QString QG_DialogFactory::extToFormat(const QString & ext)
2185 QString e = ext.toLower();
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");
2208 return ext.toUpper();