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 "rs_actiondimlinear.h"
21 #include "rs_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(RS_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 (((RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_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(RS_ActionInterface * action, bool on, bool update)
1144 static SplineOptions * toolWidget = NULL;
1146 if (optionWidget!=NULL) {
1147 if (toolWidget!=NULL) {
1151 if (on==true && toolWidget==NULL) {
1152 toolWidget = new SplineOptions(optionWidget);
1153 toolWidget->setAction(action, update);
1159 * Shows a widget for text options.
1161 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1163 static TextOptions * toolWidget = NULL;
1176 toolWidget = new TextOptions(optionWidget);
1177 toolWidget->setAction(action, update);
1182 * Shows a widget for insert options.
1184 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface * action, bool on, bool update)
1186 static InsertOptions * toolWidget = NULL;
1188 if (optionWidget!=NULL) {
1189 if (toolWidget!=NULL) {
1193 if (on==true && toolWidget==NULL) {
1194 toolWidget = new InsertOptions(optionWidget);
1195 toolWidget->setAction(action, update);
1201 * Shows a widget for image options.
1203 void QG_DialogFactory::requestImageOptions(RS_ActionInterface * action, bool on, bool update)
1205 static ImageOptions * toolWidget = NULL;
1207 if (optionWidget!=NULL) {
1208 if (toolWidget!=NULL) {
1212 if (on==true && toolWidget==NULL) {
1213 toolWidget = new ImageOptions(optionWidget);
1214 toolWidget->setAction(action, update);
1220 * Shows a widget for dimension options.
1222 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface * action, bool on, bool update)
1224 static DimOptions * toolWidget = NULL;
1226 if (optionWidget!=NULL) {
1227 if (toolWidget!=NULL) {
1231 if (on==true && toolWidget==NULL) {
1232 toolWidget = new DimOptions(optionWidget);
1233 toolWidget->setAction(action, update);
1239 * Shows a widget for linear dimension options.
1241 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface * action, bool on, bool update)
1243 static DimLinearOptions * toolWidget = NULL;
1256 toolWidget = new DimLinearOptions(optionWidget);
1257 toolWidget->setAction(action, update);
1262 * Shows a widget for 'snap to a point with a given distance' options.
1264 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1266 static SnapDistOptions * toolWidget = NULL;
1279 toolWidget = new SnapDistOptions(optionWidget);
1280 toolWidget->setDist(&dist);
1285 * Shows a widget for 'snap to a point with a given distance' options.
1287 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface * action, bool on, bool update)
1289 static MoveRotateOptions * toolWidget = NULL;
1302 toolWidget = new MoveRotateOptions(optionWidget);
1303 toolWidget->setAction(action, update);
1308 * Shows a widget for 'trim amount' options.
1310 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface * action, bool on, bool update)
1312 static TrimAmountOptions * toolWidget = NULL;
1325 toolWidget = new TrimAmountOptions(optionWidget);
1326 toolWidget->setAction(action, update);
1331 * Shows a widget for beveling options.
1333 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1335 static BevelOptions * toolWidget = NULL;
1337 if (optionWidget != NULL)
1339 if (toolWidget != NULL)
1345 if (on && toolWidget == NULL)
1347 toolWidget = new BevelOptions(optionWidget);
1348 toolWidget->setAction(action, update);
1354 * Shows a widget for rounding options.
1356 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface * action, bool on, bool update)
1358 static RoundOptions * toolWidget = NULL;
1371 toolWidget = new RoundOptions(optionWidget);
1372 toolWidget->setAction(action, update);
1377 * Shows a widget for library insert options.
1379 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface * action, bool on, bool update)
1381 static LibraryInsertOptions * toolWidget = NULL;
1394 toolWidget = new LibraryInsertOptions(optionWidget);
1395 toolWidget->setAction(action, update);
1400 * Shows the given toolbar.
1402 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1404 if (cadToolBar != NULL)
1405 cadToolBar->showToolBar(id);
1409 * Shows the select toolbar with the given action to launch.
1411 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1412 RS2::ActionType nextAction)
1414 if (cadToolBar != NULL)
1415 cadToolBar->showToolBarSelect(selectAction, nextAction);
1419 * Shows a dialog to edit the attributes of the given dimension entity.
1422 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1427 QG_DlgDimAligned dlg(parent);
1428 dlg.setDim(*dim, true);
1439 * Shows attributes options dialog presenting the given data.
1441 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1443 DlgAttributes dlg(parent);
1444 dlg.setData(&data, layerList);
1456 * Shows move options dialog presenting the given data.
1458 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1460 DlgMove dlg(parent);
1473 * Shows rotate options dialog presenting the given data.
1475 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1477 DlgRotate dlg(parent);
1490 * Shows scale options dialog presenting the given data.
1492 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1494 DlgScale dlg(parent);
1507 * Shows mirror options dialog presenting the given data.
1509 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1511 DlgMirror dlg(parent);
1524 * Shows move/rotate options dialog presenting the given data.
1526 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1528 DlgMoveRotate dlg(parent);
1541 * Shows rotate around two centers options dialog presenting the given data.
1543 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1545 DlgRotate2 dlg(parent);
1558 * Shows a dialog to edit the given entity.
1560 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1567 switch (entity->rtti())
1569 case RS2::EntityPoint:
1571 DlgPoint dlg(parent);
1572 dlg.setPoint(*((RS_Point *)entity));
1582 case RS2::EntityLine:
1584 DlgLine dlg(parent);
1585 dlg.setLine(*((RS_Line *)entity));
1595 case RS2::EntityArc:
1598 dlg.setArc(*((RS_Arc *)entity));
1608 case RS2::EntityCircle:
1610 DlgCircle dlg(parent);
1611 dlg.setCircle(*((RS_Circle *)entity));
1621 case RS2::EntityEllipse:
1623 DlgEllipse dlg(parent);
1624 dlg.setEllipse(*((RS_Ellipse *)entity));
1628 dlg.updateEllipse();
1634 case RS2::EntitySpline:
1636 DlgSpline dlg(parent);
1637 dlg.setSpline(*((RS_Spline *)entity));
1647 case RS2::EntityInsert:
1649 DlgInsert dlg(parent);
1650 dlg.setInsert(*((RS_Insert *)entity));
1661 case RS2::EntityDimAligned:
1662 case RS2::EntityDimAngular:
1663 case RS2::EntityDimDiametric:
1664 case RS2::EntityDimRadial:
1666 DlgDimension dlg(parent);
1667 dlg.setDim(*((RS_Dimension *)entity));
1673 ((RS_Dimension *)entity)->update(true);
1678 case RS2::EntityDimLinear:
1680 DlgDimLinear dlg(parent);
1681 dlg.setDim(*((RS_DimLinear *)entity));
1687 ((RS_DimLinear *)entity)->update(true);
1692 case RS2::EntityText:
1694 DlgText dlg(parent);
1695 dlg.setText(*((RS_Text *)entity), false);
1701 ((RS_Text *)entity)->update();
1706 case RS2::EntityHatch:
1708 DlgHatch dlg(parent);
1709 dlg.setHatch(*((RS_Hatch *)entity), false);
1715 ((RS_Hatch *)entity)->update();
1728 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1734 * Shows a dialog to edit the attributes of the given text entity.
1736 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1741 DlgText dlg(parent);
1742 dlg.setText(*text, true);
1754 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1756 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1761 RS_PATTERNLIST->init();
1763 DlgHatch dlg(parent);
1764 dlg.setHatch(*hatch, true);
1777 * Shows a dialog for CAM options.
1779 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1781 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1782 RS_CamDialog dlg(graphic, parent);
1783 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1787 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1791 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1797 * Shows dialog for general application options.
1799 void QG_DialogFactory::requestOptionsGeneralDialog()
1801 DlgOptionsGeneral dlg(parent);
1806 * Shows dialog for drawing options.
1808 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1810 DlgOptionsDrawing dlg(parent);
1811 dlg.setGraphic(&graphic);
1816 * Back to last menu in cad toolbar.
1818 void QG_DialogFactory::requestPreviousMenu()
1820 if (cadToolBar != NULL)
1821 cadToolBar->showToolBarMain();
1825 * Called whenever the mouse position changed.
1827 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1828 const Vector & rel, bool updateFormat)
1830 if (coordinateWidget != NULL)
1831 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1835 * Called when an action has a mouse hint.
1837 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1839 if (mouseWidget != NULL)
1840 mouseWidget->setHelp(left, right);
1842 if (commandWidget != NULL)
1843 commandWidget->setCommand(left);
1847 * Called whenever the selection changed.
1849 void QG_DialogFactory::updateSelectionWidget(int num)
1851 if (selectionWidget != NULL)
1852 selectionWidget->setNumber(num);
1856 * Called when an action needs to communicate 'message' to the user.
1858 void QG_DialogFactory::commandMessage(const QString& message)
1860 RS_DEBUG->print("QG_DialogFactory::commandMessage");
1862 if (commandWidget != NULL)
1863 commandWidget->appendHistory(message);
1865 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
1868 /*virtual*/ bool QG_DialogFactory::isAdapter()
1874 * Converts an extension to a format description.
1875 * e.g. "PNG" to "Portable Network Graphic"
1878 * @return Format description
1880 QString QG_DialogFactory::extToFormat(const QString & ext)
1882 QString e = ext.toLower();
1885 return QObject::tr("Windows Bitmap");
1886 else if (e == "jpeg" || e == "jpg")
1887 return QObject::tr("Joint Photographic Experts Group");
1888 else if (e == "gif")
1889 return QObject::tr("Graphics Interchange Format");
1890 else if (e == "mng")
1891 return QObject::tr("Multiple-image Network Graphics");
1892 else if (e == "pbm")
1893 return QObject::tr("Portable Bit Map");
1894 else if (e == "pgm")
1895 return QObject::tr("Portable Grey Map");
1896 else if (e == "png")
1897 return QObject::tr("Portable Network Graphic");
1898 else if (e == "ppm")
1899 return QObject::tr("Portable Pixel Map");
1900 else if (e == "xbm")
1901 return QObject::tr("X Bitmap Format");
1902 else if (e == "xpm")
1903 return QObject::tr("X Pixel Map");
1905 return ext.toUpper();