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 "graphicview.h"
18 #include "qg_layerwidget.h"
19 #include "qg_mainwindowinterface.h"
20 #include "actiondimlinear.h"
21 #include "actioninterface.h"
22 #include "rs_blocklist.h"
23 #include "rs_document.h"
25 #include "rs_patternlist.h"
27 #include "rs_system.h"
30 #include "arcoptions.h"
31 #include "arctangentialoptions.h"
32 #include "beveloptions.h"
33 #include "blockdialog.h"
34 #include "cadtoolbar.h"
35 #include "circleoptions.h"
36 #include "commandwidget.h"
37 #include "coordinatewidget.h"
38 #include "dimlinearoptions.h"
39 #include "dimoptions.h"
41 #include "dlgattributes.h"
42 #include "dlgcircle.h"
43 #include "dlgdimension.h"
44 #include "dlgdimlinear.h"
45 #include "dlgellipse.h"
47 #include "dlginsert.h"
49 #include "dlgmirror.h"
51 #include "dlgmoverotate.h"
52 #include "dlgoptionsdrawing.h"
53 #include "dlgoptionsgeneral.h"
55 #include "dlgrotate.h"
56 #include "dlgrotate2.h"
58 #include "dlgspline.h"
60 #include "libraryinsertoptions.h"
61 #include "imageoptions.h"
62 #include "insertoptions.h"
63 #include "layerdialog.h"
64 #include "lineangleoptions.h"
65 #include "linebisectoroptions.h"
66 #include "lineoptions.h"
67 #include "lineparalleloptions.h"
68 #include "lineparallelthroughoptions.h"
69 #include "linepolygon2options.h"
70 #include "linepolygonoptions.h"
71 #include "linerelangleoptions.h"
72 #include "mousewidget.h"
73 #include "moverotateoptions.h"
74 #include "printpreviewoptions.h"
75 #include "roundoptions.h"
76 #include "selectionwidget.h"
77 #include "snapdistoptions.h"
78 #include "splineoptions.h"
79 #include "textoptions.h"
80 #include "trimamountoptions.h"
83 #include "qg_polylineoptions.h"
87 #include "rs_camdialog.h"
90 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
95 * @param parent Pointer to parent widget which can host dialogs.
96 * @param ow Pointer to widget that can host option widgets.
98 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
99 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
100 RS_DialogFactoryInterface()
102 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
104 this->parent = parent;
107 coordinateWidget = NULL;
109 selectionWidget = NULL;
111 commandWidget = NULL;
113 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
119 QG_DialogFactory::~QG_DialogFactory()
121 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
122 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
126 * Links factory to a widget that can host tool options.
128 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
129 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
131 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
133 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
137 * Links this dialog factory to a coordinate widget.
139 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
141 coordinateWidget = cw;
145 * Links this dialog factory to a mouse widget.
147 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
153 * Links this dialog factory to a selection widget.
155 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
157 selectionWidget = sw;
161 * Links this dialog factory to the cad tool bar.
163 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
169 * @return cad tool bar or NULL.
171 CadToolBar * QG_DialogFactory::getCadToolBar()
177 * Links this dialog factory to a command widget.
179 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
185 * @return command widget or NULL.
187 CommandWidget * QG_DialogFactory::getCommandWidget()
189 return commandWidget;
193 * Links the dialog factory to a main app window.
195 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
201 * Shows a message dialog.
203 void QG_DialogFactory::requestWarningDialog(const QString & warning)
205 QMessageBox::information(parent, QMessageBox::tr("Warning"),
206 warning, QMessageBox::Ok);
210 * Requests a new document from the main window.
212 GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
214 if (mainWindow != NULL)
216 mainWindow->createNewDocument(fileName, doc);
217 return mainWindow->getGraphicView();
224 * Requests the simulation controls.
226 void QG_DialogFactory::requestSimulationControls()
228 if (mainWindow != NULL)
230 mainWindow->showSimulationControls();
235 * Shows a dialog for adding a layer. Doesn't add the layer.
236 * This is up to the caller.
238 * @return a pointer to the newly created layer that
241 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
243 RS_Layer * layer = NULL;
244 QString layer_name = "noname";
247 if (layerList != NULL)
249 while (layerList->find(layer_name) > 0)
250 layer_name.sprintf("noname%d", i++);
253 // Layer for parameter livery
254 layer = new RS_Layer(layer_name);
256 // QG_LayerDialog dlg(parent, "Layer Dialog");
257 LayerDialog dlg(parent);
259 dlg.setLayerList(layerList);
273 * Shows a dialog that asks the user if the selected layer
274 * can be removed. Doesn't remove the layer. This is up to the caller.
276 * @return a pointer to the layer that should be removed.
278 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
280 RS_Layer * layer = NULL;
282 if (layerList == NULL)
284 RS_DEBUG->print(RS_Debug::D_WARNING,
285 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
290 if (layerList==NULL) {
291 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
292 layerList = (RS_LayerList*)container;
298 // Layer for parameter livery
299 layer = layerList->getActive();
303 if (layer->getName() != "0")
305 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
306 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
307 QMessageBox::Ok, QMessageBox::Cancel);
319 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
320 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
329 * Shows a dialog for editing a layer. A new layer is created and
330 * returned. Modifying the layer is up to the caller.
332 * @return A pointer to a new layer with the changed attributes
333 * or NULL if the dialog was cancelled.
335 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
337 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
338 RS_Layer * layer = NULL;
340 if (layerList==NULL) {
341 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
342 layerList = (RS_LayerList*)container;
349 if (layerList == NULL)
351 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
352 "layerList is NULL");
356 // Layer for parameter livery
357 if (layerList->getActive() != NULL)
359 layer = new RS_Layer(*layerList->getActive());
361 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
362 LayerDialog dlg(parent);
364 dlg.setLayerList(layerList);
365 dlg.setEditLayer(true);
380 * Shows a dialog for adding a block. Doesn't add the block.
381 * This is up to the caller.
383 * @return a pointer to the newly created block that
386 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
388 //RS_Block* block = NULL;
390 ret = RS_BlockData("", Vector(false), false);
392 if (blockList == NULL)
394 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
395 "blockList is NULL");
399 // Block for parameter livery
400 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
402 BlockDialog dlg(parent);
403 dlg.setBlockList(blockList);
406 ret = dlg.getBlockData();
412 * Shows a dialog for renaming the currently active block.
414 * @return a pointer to the modified block or NULL on cancellation.
416 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
418 //RS_Block* block = NULL;
420 ret = RS_BlockData("", Vector(false), false);
422 if (blockList == NULL)
424 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
425 "blockList is NULL");
429 if (blockList==NULL) {
430 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
431 blockList = (RS_BlockList*)container;
437 // Block for parameter livery
438 //block = blockList->getActive();
440 BlockDialog dlg(parent);//WAS:, "Rename Block");
441 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
442 dlg.setWindowTitle(QObject::tr("Rename Block"));
443 dlg.setBlockList(blockList);
449 ret = dlg.getBlockData();
452 // ret = RS_BlockData("", Vector(false));
458 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
462 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
467 * Shows a dialog that asks the user if the selected block
468 * can be removed. Doesn't remove the block. This is up to the caller.
470 * @return a pointer to the block that should be removed.
472 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
474 RS_Block * block = NULL;
476 if (blockList == NULL)
478 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
479 "blockList is NULL");
483 // Block for parameter livery
484 block = blockList->getActive();
488 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
489 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
490 QMessageBox::Ok, QMessageBox::Cancel);
505 * Shows a dialog for choosing a file name. Saving the file is up to
508 * @return File name with path and extension to determine the file type
509 * or an empty string if the dialog was cancelled.
512 QString QG_DialogFactory::requestFileSaveAsDialog() {
513 // read default settings:
514 RS_SETTINGS->beginGroup("/Paths");
515 QString defDir = RS_SETTINGS->readEntry("/Save",
516 RS_SYSTEM->getHomeDir());
517 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
518 "Drawing Exchange (*.dxf)");
519 RS_SETTINGS->endGroup();
521 // prepare file save as dialog:
522 QFileDialog fileDlg(this,0,true);
528 filters.append("Drawing Exchange (*.dxf)");
529 filters.append("Font (*.cxf)");
530 fileDlg.setFilters(filters);
531 fileDlg.setMode(QFileDialog::AnyFile);
532 fileDlg.setCaption(tr("Save Drawing As"));
533 fileDlg.setDir(defDir);
534 fileDlg.setSelectedFilter(defFilter);
539 if (fileDlg.exec()==QDialog::Accepted) {
540 fn = fileDlg.selectedFile();
543 // append default extension:
544 if (fn.find('.')==-1) {
545 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
552 // overwrite warning:
553 if(QFileInfo(fn).exists()) {
555 QMessageBox::warning(this, tr("Save Drawing As"),
556 tr("%1 already exists.\n"
557 "Do you want to replace it?")
560 tr("Cancel"), 0, 1 );
583 // store new default settings:
585 RS_SETTINGS->beginGroup("/Paths");
586 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
587 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
588 RS_SETTINGS->endGroup();
596 * Shows a dialog for choosing a file name. Opening the file is up to
599 * @return File name with path and extension to determine the file type
600 * or an empty string if the dialog was cancelled.
602 QString QG_DialogFactory::requestImageOpenDialog()
606 // read default settings:
607 settings.beginGroup("Paths");
608 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
609 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
614 // Q3FileDialog fileDlg(NULL, "", true);
615 QFileDialog fileDlg(NULL, "");
618 // Q3StrList f = QImageIO::inputFormats();
619 // QStringList formats = QStringList::fromStrList(f);
620 QList<QByteArray> f = QImageReader::supportedImageFormats();
621 QStringList formats = ???
623 #warning "Needs porting to Qt4... !!! FIX !!!"
628 //filters = QStringList::fromStrList(formats);
631 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
639 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
643 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
653 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
657 all += QString("*.%1").arg(QString(*it).lower());
662 filters.append(QObject::tr("All Image Files (%1)").arg(all));
663 filters.append(QObject::tr("All Files (*.*)"));
665 //filters.append("Drawing Exchange (*.)");
666 //filters.append("Font (*.cxf)");
668 fileDlg.setFilters(filters);
669 // fileDlg.setMode(Q3FileDialog::ExistingFile);
670 fileDlg.setFileMode(QFileDialog::ExistingFile);
671 // fileDlg.setCaption(QObject::tr("Open Image"));
672 fileDlg.setWindowTitle(QObject::tr("Open Image"));
673 // fileDlg.setDir(defDir);
674 fileDlg.setDirectory(defDir);
675 // fileDlg.setSelectedFilter(defFilter);
676 fileDlg.selectFilter(defFilter);
680 if (fileDlg.exec() == QDialog::Accepted)
682 // fn = fileDlg.selectedFile();
683 QStringList files = fileDlg.selectedFiles();
685 if (!files.isEmpty())
691 // store new default settings:
694 QStringList files = fileDlg.selectedFiles();
695 QString selected = "";
697 if (!files.isEmpty())
700 settings.beginGroup("Paths");
701 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
702 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
703 settings.setValue("ImageFilter", selected);
710 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
712 RS_DEBUG->print("QG_DialogFactory::requestOptions");
716 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
720 switch (action->rtti())
722 case RS2::ActionPrintPreview:
723 requestPrintPreviewOptions(action, on, update);
726 case RS2::ActionDrawLine:
727 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
728 requestLineOptions(action, on);
729 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
732 case RS2::ActionDrawPolyline:
733 requestPolylineOptions(action, on, update);
736 case RS2::ActionDrawLineAngle:
737 requestLineAngleOptions(action, on, update);
740 case RS2::ActionDrawLineParallel:
741 requestLineParallelOptions(action, on, update);
744 case RS2::ActionDrawLineParallelThrough:
745 requestLineParallelThroughOptions(action, on, update);
748 case RS2::ActionDrawLineBisector:
749 requestLineBisectorOptions(action, on, update);
752 case RS2::ActionDrawLineRelAngle:
753 requestLineRelAngleOptions(action, on, update);
756 case RS2::ActionDrawLinePolygon:
757 requestLinePolygonOptions(action, on, update);
760 case RS2::ActionDrawLinePolygon2:
761 requestLinePolygon2Options(action, on, update);
764 case RS2::ActionDrawArc:
765 requestArcOptions(action, on, update);
768 case RS2::ActionDrawArcTangential:
769 requestArcTangentialOptions(action, on, update);
772 case RS2::ActionDrawCircleCR:
773 requestCircleOptions(action, on, update);
776 case RS2::ActionDrawSpline:
777 requestSplineOptions(action, on, update);
780 case RS2::ActionDrawText:
781 requestTextOptions(action, on, update);
784 case RS2::ActionBlocksInsert:
785 requestInsertOptions(action, on, update);
788 case RS2::ActionDrawImage:
789 requestImageOptions(action, on, update);
792 case RS2::ActionDimAligned:
793 requestDimensionOptions(action, on, update);
796 case RS2::ActionDimLinear:
797 requestDimensionOptions(action, on, update);
799 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
800 requestDimLinearOptions(action, on, update);
804 case RS2::ActionDimRadial:
805 requestDimensionOptions(action, on, update);
808 case RS2::ActionDimDiametric:
809 requestDimensionOptions(action, on, update);
812 case RS2::ActionDimAngular:
813 requestDimensionOptions(action, on, update);
816 case RS2::ActionModifyTrimAmount:
817 requestTrimAmountOptions(action, on, update);
820 case RS2::ActionModifyMoveRotate:
821 requestMoveRotateOptions(action, on, update);
824 case RS2::ActionModifyBevel:
825 requestBevelOptions(action, on, update);
828 case RS2::ActionModifyRound:
829 requestRoundOptions(action, on, update);
832 case RS2::ActionLibraryInsert:
833 requestLibraryInsertOptions(action, on, update);
840 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
844 * Shows a widget for options for the action: "print preview"
846 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
848 static PrintPreviewOptions * toolWidget = NULL;
861 toolWidget = new PrintPreviewOptions(optionWidget);
862 toolWidget->setAction(action, update);
867 * Shows a widget for options for the action: "draw line"
869 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
872 The way I see it, this is failure. We're constantly creating & deleting
873 these objects all the time when we could create them once, and then reuse
874 them over and over. May need to do some more refactoring based on this idea...
877 static LineOptions * toolWidget = NULL;
882 // Get rid of the LineOptions object if it exists...
889 // Create a new one for the passed in action
892 toolWidget = new LineOptions(optionWidget);
893 toolWidget->setAction(action);
896 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
900 * Shows a widget for options for the action: "draw polyline"
902 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
905 static PolylineOptions * toolWidget = NULL;
918 toolWidget = new PolylineOptions(optionWidget);
919 toolWidget->setAction(action, update);
925 * Shows a widget for options for the action: "draw line parallel"
927 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
929 static LineParallelOptions * toolWidget = NULL;
931 if (optionWidget!=NULL)
933 if (toolWidget!=NULL)
938 if (on==true && toolWidget==NULL)
940 toolWidget = new LineParallelOptions(optionWidget);
941 toolWidget->setAction(action, update);
947 * Shows a widget for options for the action: "draw line parallel through"
949 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
951 static LineParallelThroughOptions * toolWidget = NULL;
953 if (optionWidget!=NULL) {
954 if (toolWidget!=NULL) {
958 if (on==true && toolWidget==NULL) {
959 toolWidget = new LineParallelThroughOptions(optionWidget);
960 toolWidget->setAction(action, update);
966 * Shows a widget for options for the action: "line angle"
968 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
970 static LineAngleOptions * toolWidget = NULL;
983 toolWidget = new LineAngleOptions(optionWidget);
984 toolWidget->setAction(action, update);
989 * Shows a widget for options for the action: "line relative angle"
991 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
993 static LineRelAngleOptions * toolWidget = NULL;
1006 toolWidget = new LineRelAngleOptions(optionWidget);
1007 toolWidget->setAction(action, update);
1012 * Shows a widget for options for the action: "line angle"
1014 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
1016 static LineBisectorOptions * toolWidget = NULL;
1018 if (optionWidget!=NULL) {
1019 if (toolWidget!=NULL) {
1023 if (on==true && toolWidget==NULL) {
1024 toolWidget = new LineBisectorOptions(optionWidget);
1025 toolWidget->setAction(action, update);
1031 * Shows a widget for options for the action: "draw polygon"
1033 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1035 static LinePolygonOptions * toolWidget = NULL;
1037 if (optionWidget!=NULL) {
1038 if (toolWidget!=NULL) {
1042 if (on==true && toolWidget==NULL) {
1043 toolWidget = new LinePolygonOptions(optionWidget);
1044 toolWidget->setAction(action, update);
1050 * Shows a widget for options for the action: "draw polygon2"
1052 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1054 static LinePolygon2Options * toolWidget = NULL;
1056 if (optionWidget!=NULL) {
1057 if (toolWidget!=NULL) {
1061 if (on==true && toolWidget==NULL) {
1062 toolWidget = new LinePolygon2Options(optionWidget);
1063 toolWidget->setAction(action, update);
1069 * Shows a widget for arc options.
1071 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1073 static ArcOptions * toolWidget = NULL;
1075 if (optionWidget != NULL)
1077 if (toolWidget != NULL)
1083 if (on && toolWidget == NULL)
1085 toolWidget = new ArcOptions(optionWidget);
1086 toolWidget->setAction(action, update);
1087 //toolWidget->setData(&data);
1093 * Shows a widget for tangential arc options.
1095 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1097 static ArcTangentialOptions * toolWidget = NULL;
1110 toolWidget = new ArcTangentialOptions(optionWidget);
1111 toolWidget->setAction(action, update);
1112 //toolWidget->setData(&data);
1117 * Shows a widget for circle options.
1119 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1121 static CircleOptions * toolWidget = NULL;
1131 if (on && toolWidget == NULL)
1133 toolWidget = new CircleOptions(optionWidget);
1134 toolWidget->setAction(action, update);
1140 * Shows a widget for spline options.
1142 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1144 static SplineOptions * toolWidget = NULL;
1157 toolWidget = new SplineOptions(optionWidget);
1158 toolWidget->setAction(action, update);
1163 * Shows a widget for text options.
1165 void QG_DialogFactory::requestTextOptions(ActionInterface * action, bool on, bool update)
1167 static TextOptions * toolWidget = NULL;
1180 toolWidget = new TextOptions(optionWidget);
1181 toolWidget->setAction(action, update);
1186 * Shows a widget for insert options.
1188 void QG_DialogFactory::requestInsertOptions(ActionInterface * action, bool on, bool update)
1190 static InsertOptions * toolWidget = NULL;
1192 if (optionWidget!=NULL) {
1193 if (toolWidget!=NULL) {
1197 if (on==true && toolWidget==NULL) {
1198 toolWidget = new InsertOptions(optionWidget);
1199 toolWidget->setAction(action, update);
1205 * Shows a widget for image options.
1207 void QG_DialogFactory::requestImageOptions(ActionInterface * action, bool on, bool update)
1209 static ImageOptions * toolWidget = NULL;
1211 if (optionWidget!=NULL) {
1212 if (toolWidget!=NULL) {
1216 if (on==true && toolWidget==NULL) {
1217 toolWidget = new ImageOptions(optionWidget);
1218 toolWidget->setAction(action, update);
1224 * Shows a widget for dimension options.
1226 void QG_DialogFactory::requestDimensionOptions(ActionInterface * action, bool on, bool update)
1228 static DimOptions * toolWidget = NULL;
1230 if (optionWidget!=NULL) {
1231 if (toolWidget!=NULL) {
1235 if (on==true && toolWidget==NULL) {
1236 toolWidget = new DimOptions(optionWidget);
1237 toolWidget->setAction(action, update);
1243 * Shows a widget for linear dimension options.
1245 void QG_DialogFactory::requestDimLinearOptions(ActionInterface * action, bool on, bool update)
1247 static DimLinearOptions * toolWidget = NULL;
1260 toolWidget = new DimLinearOptions(optionWidget);
1261 toolWidget->setAction(action, update);
1266 * Shows a widget for 'snap to a point with a given distance' options.
1268 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1270 static SnapDistOptions * toolWidget = NULL;
1283 toolWidget = new SnapDistOptions(optionWidget);
1284 toolWidget->setDist(&dist);
1289 * Shows a widget for 'snap to a point with a given distance' options.
1291 void QG_DialogFactory::requestMoveRotateOptions(ActionInterface * action, bool on, bool update)
1293 static MoveRotateOptions * toolWidget = NULL;
1306 toolWidget = new MoveRotateOptions(optionWidget);
1307 toolWidget->setAction(action, update);
1312 * Shows a widget for 'trim amount' options.
1314 void QG_DialogFactory::requestTrimAmountOptions(ActionInterface * action, bool on, bool update)
1316 static TrimAmountOptions * toolWidget = NULL;
1329 toolWidget = new TrimAmountOptions(optionWidget);
1330 toolWidget->setAction(action, update);
1335 * Shows a widget for beveling options.
1337 void QG_DialogFactory::requestBevelOptions(ActionInterface * action, bool on, bool update)
1339 static BevelOptions * toolWidget = NULL;
1341 if (optionWidget != NULL)
1343 if (toolWidget != NULL)
1349 if (on && toolWidget == NULL)
1351 toolWidget = new BevelOptions(optionWidget);
1352 toolWidget->setAction(action, update);
1358 * Shows a widget for rounding options.
1360 void QG_DialogFactory::requestRoundOptions(ActionInterface * action, bool on, bool update)
1362 static RoundOptions * toolWidget = NULL;
1375 toolWidget = new RoundOptions(optionWidget);
1376 toolWidget->setAction(action, update);
1381 * Shows a widget for library insert options.
1383 void QG_DialogFactory::requestLibraryInsertOptions(ActionInterface * action, bool on, bool update)
1385 static LibraryInsertOptions * toolWidget = NULL;
1398 toolWidget = new LibraryInsertOptions(optionWidget);
1399 toolWidget->setAction(action, update);
1404 * Shows the given toolbar.
1406 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1408 if (cadToolBar != NULL)
1409 cadToolBar->showToolBar(id);
1413 * Shows the select toolbar with the given action to launch.
1415 void QG_DialogFactory::requestToolBarSelect(ActionInterface * selectAction,
1416 RS2::ActionType nextAction)
1418 if (cadToolBar != NULL)
1419 cadToolBar->showToolBarSelect(selectAction, nextAction);
1423 * Shows a dialog to edit the attributes of the given dimension entity.
1426 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1431 QG_DlgDimAligned dlg(parent);
1432 dlg.setDim(*dim, true);
1443 * Shows attributes options dialog presenting the given data.
1445 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1447 DlgAttributes dlg(parent);
1448 dlg.setData(&data, layerList);
1460 * Shows move options dialog presenting the given data.
1462 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1464 DlgMove dlg(parent);
1477 * Shows rotate options dialog presenting the given data.
1479 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1481 DlgRotate dlg(parent);
1494 * Shows scale options dialog presenting the given data.
1496 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1498 DlgScale dlg(parent);
1511 * Shows mirror options dialog presenting the given data.
1513 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1515 DlgMirror dlg(parent);
1528 * Shows move/rotate options dialog presenting the given data.
1530 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1532 DlgMoveRotate dlg(parent);
1545 * Shows rotate around two centers options dialog presenting the given data.
1547 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1549 DlgRotate2 dlg(parent);
1562 * Shows a dialog to edit the given entity.
1564 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1571 switch (entity->rtti())
1573 case RS2::EntityPoint:
1575 DlgPoint dlg(parent);
1576 dlg.setPoint(*((RS_Point *)entity));
1586 case RS2::EntityLine:
1588 DlgLine dlg(parent);
1589 dlg.setLine(*((RS_Line *)entity));
1599 case RS2::EntityArc:
1602 dlg.setArc(*((RS_Arc *)entity));
1612 case RS2::EntityCircle:
1614 DlgCircle dlg(parent);
1615 dlg.setCircle(*((RS_Circle *)entity));
1625 case RS2::EntityEllipse:
1627 DlgEllipse dlg(parent);
1628 dlg.setEllipse(*((RS_Ellipse *)entity));
1632 dlg.updateEllipse();
1638 case RS2::EntitySpline:
1640 DlgSpline dlg(parent);
1641 dlg.setSpline(*((RS_Spline *)entity));
1651 case RS2::EntityInsert:
1653 DlgInsert dlg(parent);
1654 dlg.setInsert(*((RS_Insert *)entity));
1665 case RS2::EntityDimAligned:
1666 case RS2::EntityDimAngular:
1667 case RS2::EntityDimDiametric:
1668 case RS2::EntityDimRadial:
1670 DlgDimension dlg(parent);
1671 dlg.setDim(*((RS_Dimension *)entity));
1677 ((RS_Dimension *)entity)->update(true);
1682 case RS2::EntityDimLinear:
1684 DlgDimLinear dlg(parent);
1685 dlg.setDim(*((RS_DimLinear *)entity));
1691 ((RS_DimLinear *)entity)->update(true);
1696 case RS2::EntityText:
1698 DlgText dlg(parent);
1699 dlg.setText(*((RS_Text *)entity), false);
1705 ((RS_Text *)entity)->update();
1710 case RS2::EntityHatch:
1712 DlgHatch dlg(parent);
1713 dlg.setHatch(*((RS_Hatch *)entity), false);
1719 ((RS_Hatch *)entity)->update();
1732 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1738 * Shows a dialog to edit the attributes of the given text entity.
1740 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1745 DlgText dlg(parent);
1746 dlg.setText(*text, true);
1758 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1760 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1765 RS_PATTERNLIST->init();
1767 DlgHatch dlg(parent);
1768 dlg.setHatch(*hatch, true);
1781 * Shows a dialog for CAM options.
1783 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1785 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1786 RS_CamDialog dlg(graphic, parent);
1787 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1791 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1795 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1801 * Shows dialog for general application options.
1803 void QG_DialogFactory::requestOptionsGeneralDialog()
1805 DlgOptionsGeneral dlg(parent);
1810 * Shows dialog for drawing options.
1812 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1814 DlgOptionsDrawing dlg(parent);
1815 dlg.setGraphic(&graphic);
1820 * Back to last menu in cad toolbar.
1822 void QG_DialogFactory::requestPreviousMenu()
1824 if (cadToolBar != NULL)
1825 cadToolBar->showToolBarMain();
1829 * Called whenever the mouse position changed.
1831 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1832 const Vector & rel, bool updateFormat)
1834 if (coordinateWidget != NULL)
1835 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1839 * Called when an action has a mouse hint.
1841 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1844 mouseWidget->setHelp(left, right);
1847 commandWidget->setCommand(left);
1851 * Called whenever the selection changed.
1853 void QG_DialogFactory::updateSelectionWidget(int num)
1855 if (selectionWidget != NULL)
1856 selectionWidget->setNumber(num);
1860 * Called when an action needs to communicate 'message' to the user.
1862 void QG_DialogFactory::commandMessage(const QString& message)
1864 RS_DEBUG->print("QG_DialogFactory::commandMessage");
1866 if (commandWidget != NULL)
1867 commandWidget->appendHistory(message);
1869 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
1872 /*virtual*/ bool QG_DialogFactory::isAdapter()
1878 * Converts an extension to a format description.
1879 * e.g. "PNG" to "Portable Network Graphic"
1882 * @return Format description
1884 QString QG_DialogFactory::extToFormat(const QString & ext)
1886 QString e = ext.toLower();
1889 return QObject::tr("Windows Bitmap");
1890 else if (e == "jpeg" || e == "jpg")
1891 return QObject::tr("Joint Photographic Experts Group");
1892 else if (e == "gif")
1893 return QObject::tr("Graphics Interchange Format");
1894 else if (e == "mng")
1895 return QObject::tr("Multiple-image Network Graphics");
1896 else if (e == "pbm")
1897 return QObject::tr("Portable Bit Map");
1898 else if (e == "pgm")
1899 return QObject::tr("Portable Grey Map");
1900 else if (e == "png")
1901 return QObject::tr("Portable Network Graphic");
1902 else if (e == "ppm")
1903 return QObject::tr("Portable Pixel Map");
1904 else if (e == "xbm")
1905 return QObject::tr("X Bitmap Format");
1906 else if (e == "xpm")
1907 return QObject::tr("X Pixel Map");
1909 return ext.toUpper();