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"
23 #include "rs_patternlist.h"
25 #include "rs_system.h"
28 #include "arcoptions.h"
29 #include "arctangentialoptions.h"
30 #include "beveloptions.h"
31 #include "blockdialog.h"
32 #include "cadtoolbar.h"
33 #include "circleoptions.h"
34 #include "commandwidget.h"
35 #include "coordinatewidget.h"
36 #include "dimlinearoptions.h"
37 #include "dimoptions.h"
39 #include "dlgattributes.h"
40 #include "dlgcircle.h"
41 #include "dlgdimension.h"
42 #include "dlgdimlinear.h"
43 #include "dlgellipse.h"
45 #include "dlginsert.h"
47 #include "dlgmirror.h"
49 #include "dlgmoverotate.h"
50 #include "dlgoptionsdrawing.h"
51 #include "dlgoptionsgeneral.h"
53 #include "dlgrotate.h"
54 #include "dlgrotate2.h"
56 #include "dlgspline.h"
58 #include "libraryinsertoptions.h"
59 #include "imageoptions.h"
60 #include "insertoptions.h"
61 #include "layerdialog.h"
62 #include "lineangleoptions.h"
63 #include "linebisectoroptions.h"
64 #include "lineoptions.h"
65 #include "lineparalleloptions.h"
66 #include "lineparallelthroughoptions.h"
67 #include "linepolygon2options.h"
68 #include "linepolygonoptions.h"
69 #include "linerelangleoptions.h"
70 #include "mousewidget.h"
71 #include "moverotateoptions.h"
72 #include "printpreviewoptions.h"
73 #include "roundoptions.h"
74 #include "selectionwidget.h"
75 #include "snapdistoptions.h"
76 #include "splineoptions.h"
77 #include "textoptions.h"
78 #include "trimamountoptions.h"
81 #include "qg_polylineoptions.h"
85 #include "rs_camdialog.h"
88 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
93 * @param parent Pointer to parent widget which can host dialogs.
94 * @param ow Pointer to widget that can host option widgets.
96 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
97 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
98 RS_DialogFactoryInterface()
100 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
102 this->parent = parent;
105 coordinateWidget = NULL;
107 selectionWidget = NULL;
109 commandWidget = NULL;
111 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
117 QG_DialogFactory::~QG_DialogFactory()
119 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
120 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
124 * Links factory to a widget that can host tool options.
126 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
127 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
129 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
131 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
135 * Links this dialog factory to a coordinate widget.
137 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
139 coordinateWidget = cw;
143 * Links this dialog factory to a mouse widget.
145 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
151 * Links this dialog factory to a selection widget.
153 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
155 selectionWidget = sw;
159 * Links this dialog factory to the cad tool bar.
161 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
167 * @return cad tool bar or NULL.
169 CadToolBar * QG_DialogFactory::getCadToolBar()
175 * Links this dialog factory to a command widget.
177 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
183 * @return command widget or NULL.
185 CommandWidget * QG_DialogFactory::getCommandWidget()
187 return commandWidget;
191 * Links the dialog factory to a main app window.
193 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
199 * Shows a message dialog.
201 void QG_DialogFactory::requestWarningDialog(const QString & warning)
203 QMessageBox::information(parent, QMessageBox::tr("Warning"),
204 warning, QMessageBox::Ok);
208 * Requests a new document from the main window.
210 RS_GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
212 if (mainWindow != NULL)
214 mainWindow->createNewDocument(fileName, doc);
215 return mainWindow->getGraphicView();
222 * Requests the simulation controls.
224 void QG_DialogFactory::requestSimulationControls()
226 if (mainWindow != NULL)
228 mainWindow->showSimulationControls();
233 * Shows a dialog for adding a layer. Doesn't add the layer.
234 * This is up to the caller.
236 * @return a pointer to the newly created layer that
239 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
241 RS_Layer * layer = NULL;
242 QString layer_name = "noname";
245 if (layerList != NULL)
247 while (layerList->find(layer_name) > 0)
248 layer_name.sprintf("noname%d", i++);
251 // Layer for parameter livery
252 layer = new RS_Layer(layer_name);
254 // QG_LayerDialog dlg(parent, "Layer Dialog");
255 LayerDialog dlg(parent);
257 dlg.setLayerList(layerList);
271 * Shows a dialog that asks the user if the selected layer
272 * can be removed. Doesn't remove the layer. This is up to the caller.
274 * @return a pointer to the layer that should be removed.
276 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
278 RS_Layer * layer = NULL;
280 if (layerList == NULL)
282 RS_DEBUG->print(RS_Debug::D_WARNING,
283 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
288 if (layerList==NULL) {
289 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
290 layerList = (RS_LayerList*)container;
296 // Layer for parameter livery
297 layer = layerList->getActive();
301 if (layer->getName() != "0")
303 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
304 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
305 QMessageBox::Ok, QMessageBox::Cancel);
317 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
318 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
327 * Shows a dialog for editing a layer. A new layer is created and
328 * returned. Modifying the layer is up to the caller.
330 * @return A pointer to a new layer with the changed attributes
331 * or NULL if the dialog was cancelled.
333 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
335 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
336 RS_Layer * layer = NULL;
338 if (layerList==NULL) {
339 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
340 layerList = (RS_LayerList*)container;
347 if (layerList == NULL)
349 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
350 "layerList is NULL");
354 // Layer for parameter livery
355 if (layerList->getActive() != NULL)
357 layer = new RS_Layer(*layerList->getActive());
359 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
360 LayerDialog dlg(parent);
362 dlg.setLayerList(layerList);
363 dlg.setEditLayer(true);
378 * Shows a dialog for adding a block. Doesn't add the block.
379 * This is up to the caller.
381 * @return a pointer to the newly created block that
384 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
386 //RS_Block* block = NULL;
388 ret = RS_BlockData("", Vector(false), false);
390 if (blockList == NULL)
392 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
393 "blockList is NULL");
397 // Block for parameter livery
398 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
400 BlockDialog dlg(parent);
401 dlg.setBlockList(blockList);
404 ret = dlg.getBlockData();
410 * Shows a dialog for renaming the currently active block.
412 * @return a pointer to the modified block or NULL on cancellation.
414 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
416 //RS_Block* block = NULL;
418 ret = RS_BlockData("", Vector(false), false);
420 if (blockList == NULL)
422 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
423 "blockList is NULL");
427 if (blockList==NULL) {
428 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
429 blockList = (RS_BlockList*)container;
435 // Block for parameter livery
436 //block = blockList->getActive();
438 BlockDialog dlg(parent);//WAS:, "Rename Block");
439 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
440 dlg.setWindowTitle(QObject::tr("Rename Block"));
441 dlg.setBlockList(blockList);
447 ret = dlg.getBlockData();
450 // ret = RS_BlockData("", Vector(false));
456 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
460 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
465 * Shows a dialog that asks the user if the selected block
466 * can be removed. Doesn't remove the block. This is up to the caller.
468 * @return a pointer to the block that should be removed.
470 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
472 RS_Block * block = NULL;
474 if (blockList == NULL)
476 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
477 "blockList is NULL");
481 // Block for parameter livery
482 block = blockList->getActive();
486 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
487 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
488 QMessageBox::Ok, QMessageBox::Cancel);
503 * Shows a dialog for choosing a file name. Saving the file is up to
506 * @return File name with path and extension to determine the file type
507 * or an empty string if the dialog was cancelled.
510 QString QG_DialogFactory::requestFileSaveAsDialog() {
511 // read default settings:
512 RS_SETTINGS->beginGroup("/Paths");
513 QString defDir = RS_SETTINGS->readEntry("/Save",
514 RS_SYSTEM->getHomeDir());
515 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
516 "Drawing Exchange (*.dxf)");
517 RS_SETTINGS->endGroup();
519 // prepare file save as dialog:
520 QFileDialog fileDlg(this,0,true);
526 filters.append("Drawing Exchange (*.dxf)");
527 filters.append("Font (*.cxf)");
528 fileDlg.setFilters(filters);
529 fileDlg.setMode(QFileDialog::AnyFile);
530 fileDlg.setCaption(tr("Save Drawing As"));
531 fileDlg.setDir(defDir);
532 fileDlg.setSelectedFilter(defFilter);
537 if (fileDlg.exec()==QDialog::Accepted) {
538 fn = fileDlg.selectedFile();
541 // append default extension:
542 if (fn.find('.')==-1) {
543 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
550 // overwrite warning:
551 if(QFileInfo(fn).exists()) {
553 QMessageBox::warning(this, tr("Save Drawing As"),
554 tr("%1 already exists.\n"
555 "Do you want to replace it?")
558 tr("Cancel"), 0, 1 );
581 // store new default settings:
583 RS_SETTINGS->beginGroup("/Paths");
584 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
585 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
586 RS_SETTINGS->endGroup();
594 * Shows a dialog for choosing a file name. Opening the file is up to
597 * @return File name with path and extension to determine the file type
598 * or an empty string if the dialog was cancelled.
600 QString QG_DialogFactory::requestImageOpenDialog()
604 // read default settings:
605 settings.beginGroup("Paths");
606 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
607 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
612 // Q3FileDialog fileDlg(NULL, "", true);
613 QFileDialog fileDlg(NULL, "");
616 // Q3StrList f = QImageIO::inputFormats();
617 // QStringList formats = QStringList::fromStrList(f);
618 QList<QByteArray> f = QImageReader::supportedImageFormats();
619 QStringList formats = ???
621 #warning "Needs porting to Qt4... !!! FIX !!!"
626 //filters = QStringList::fromStrList(formats);
629 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
637 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
641 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
651 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
655 all += QString("*.%1").arg(QString(*it).lower());
660 filters.append(QObject::tr("All Image Files (%1)").arg(all));
661 filters.append(QObject::tr("All Files (*.*)"));
663 //filters.append("Drawing Exchange (*.)");
664 //filters.append("Font (*.cxf)");
666 fileDlg.setFilters(filters);
667 // fileDlg.setMode(Q3FileDialog::ExistingFile);
668 fileDlg.setFileMode(QFileDialog::ExistingFile);
669 // fileDlg.setCaption(QObject::tr("Open Image"));
670 fileDlg.setWindowTitle(QObject::tr("Open Image"));
671 // fileDlg.setDir(defDir);
672 fileDlg.setDirectory(defDir);
673 // fileDlg.setSelectedFilter(defFilter);
674 fileDlg.selectFilter(defFilter);
678 if (fileDlg.exec() == QDialog::Accepted)
680 // fn = fileDlg.selectedFile();
681 QStringList files = fileDlg.selectedFiles();
683 if (!files.isEmpty())
689 // store new default settings:
692 QStringList files = fileDlg.selectedFiles();
693 QString selected = "";
695 if (!files.isEmpty())
698 settings.beginGroup("Paths");
699 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
700 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
701 settings.setValue("ImageFilter", selected);
708 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
710 RS_DEBUG->print("QG_DialogFactory::requestOptions");
714 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
718 switch (action->rtti())
720 case RS2::ActionPrintPreview:
721 requestPrintPreviewOptions(action, on, update);
724 case RS2::ActionDrawLine:
725 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
726 requestLineOptions(action, on);
727 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
730 case RS2::ActionDrawPolyline:
731 requestPolylineOptions(action, on, update);
734 case RS2::ActionDrawLineAngle:
735 requestLineAngleOptions(action, on, update);
738 case RS2::ActionDrawLineParallel:
739 requestLineParallelOptions(action, on, update);
742 case RS2::ActionDrawLineParallelThrough:
743 requestLineParallelThroughOptions(action, on, update);
746 case RS2::ActionDrawLineBisector:
747 requestLineBisectorOptions(action, on, update);
750 case RS2::ActionDrawLineRelAngle:
751 requestLineRelAngleOptions(action, on, update);
754 case RS2::ActionDrawLinePolygon:
755 requestLinePolygonOptions(action, on, update);
758 case RS2::ActionDrawLinePolygon2:
759 requestLinePolygon2Options(action, on, update);
762 case RS2::ActionDrawArc:
763 requestArcOptions(action, on, update);
766 case RS2::ActionDrawArcTangential:
767 requestArcTangentialOptions(action, on, update);
770 case RS2::ActionDrawCircleCR:
771 requestCircleOptions(action, on, update);
774 case RS2::ActionDrawSpline:
775 requestSplineOptions(action, on, update);
778 case RS2::ActionDrawText:
779 requestTextOptions(action, on, update);
782 case RS2::ActionBlocksInsert:
783 requestInsertOptions(action, on, update);
786 case RS2::ActionDrawImage:
787 requestImageOptions(action, on, update);
790 case RS2::ActionDimAligned:
791 requestDimensionOptions(action, on, update);
794 case RS2::ActionDimLinear:
795 requestDimensionOptions(action, on, update);
797 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
798 requestDimLinearOptions(action, on, update);
802 case RS2::ActionDimRadial:
803 requestDimensionOptions(action, on, update);
806 case RS2::ActionDimDiametric:
807 requestDimensionOptions(action, on, update);
810 case RS2::ActionDimAngular:
811 requestDimensionOptions(action, on, update);
814 case RS2::ActionModifyTrimAmount:
815 requestTrimAmountOptions(action, on, update);
818 case RS2::ActionModifyMoveRotate:
819 requestMoveRotateOptions(action, on, update);
822 case RS2::ActionModifyBevel:
823 requestBevelOptions(action, on, update);
826 case RS2::ActionModifyRound:
827 requestRoundOptions(action, on, update);
830 case RS2::ActionLibraryInsert:
831 requestLibraryInsertOptions(action, on, update);
838 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
842 * Shows a widget for options for the action: "print preview"
844 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
846 static PrintPreviewOptions * toolWidget = NULL;
859 toolWidget = new PrintPreviewOptions(optionWidget);
860 toolWidget->setAction(action, update);
865 * Shows a widget for options for the action: "draw line"
867 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
870 The way I see it, this is failure. We're constantly creating & deleting
871 these objects all the time when we could create them once, and then reuse
872 them over and over. May need to do some more refactoring based on this idea...
875 static LineOptions * toolWidget = NULL;
880 // Get rid of the LineOptions object if it exists...
887 // Create a new one for the passed in action
890 toolWidget = new LineOptions(optionWidget);
891 toolWidget->setAction(action);
894 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
898 * Shows a widget for options for the action: "draw polyline"
900 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
903 static PolylineOptions * toolWidget = NULL;
916 toolWidget = new PolylineOptions(optionWidget);
917 toolWidget->setAction(action, update);
923 * Shows a widget for options for the action: "draw line parallel"
925 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
927 static LineParallelOptions * toolWidget = NULL;
929 if (optionWidget!=NULL)
931 if (toolWidget!=NULL)
936 if (on==true && toolWidget==NULL)
938 toolWidget = new LineParallelOptions(optionWidget);
939 toolWidget->setAction(action, update);
945 * Shows a widget for options for the action: "draw line parallel through"
947 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface * action, bool on, bool update)
949 static LineParallelThroughOptions * toolWidget = NULL;
951 if (optionWidget!=NULL) {
952 if (toolWidget!=NULL) {
956 if (on==true && toolWidget==NULL) {
957 toolWidget = new LineParallelThroughOptions(optionWidget);
958 toolWidget->setAction(action, update);
964 * Shows a widget for options for the action: "line angle"
966 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface * action, bool on, bool update)
968 static LineAngleOptions * toolWidget = NULL;
981 toolWidget = new LineAngleOptions(optionWidget);
982 toolWidget->setAction(action, update);
987 * Shows a widget for options for the action: "line relative angle"
989 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface * action, bool on, bool update)
991 static LineRelAngleOptions * toolWidget = NULL;
1004 toolWidget = new LineRelAngleOptions(optionWidget);
1005 toolWidget->setAction(action, update);
1010 * Shows a widget for options for the action: "line angle"
1012 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface * action, bool on, bool update)
1014 static LineBisectorOptions * toolWidget = NULL;
1016 if (optionWidget!=NULL) {
1017 if (toolWidget!=NULL) {
1021 if (on==true && toolWidget==NULL) {
1022 toolWidget = new LineBisectorOptions(optionWidget);
1023 toolWidget->setAction(action, update);
1029 * Shows a widget for options for the action: "draw polygon"
1031 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface * action, bool on, bool update)
1033 static LinePolygonOptions * toolWidget = NULL;
1035 if (optionWidget!=NULL) {
1036 if (toolWidget!=NULL) {
1040 if (on==true && toolWidget==NULL) {
1041 toolWidget = new LinePolygonOptions(optionWidget);
1042 toolWidget->setAction(action, update);
1048 * Shows a widget for options for the action: "draw polygon2"
1050 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface * action, bool on, bool update)
1052 static LinePolygon2Options * toolWidget = NULL;
1054 if (optionWidget!=NULL) {
1055 if (toolWidget!=NULL) {
1059 if (on==true && toolWidget==NULL) {
1060 toolWidget = new LinePolygon2Options(optionWidget);
1061 toolWidget->setAction(action, update);
1067 * Shows a widget for arc options.
1069 void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
1071 static ArcOptions * toolWidget = NULL;
1073 if (optionWidget != NULL)
1075 if (toolWidget != NULL)
1081 if (on && toolWidget == NULL)
1083 toolWidget = new ArcOptions(optionWidget);
1084 toolWidget->setAction(action, update);
1085 //toolWidget->setData(&data);
1091 * Shows a widget for tangential arc options.
1093 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
1095 static ArcTangentialOptions * toolWidget = NULL;
1108 toolWidget = new ArcTangentialOptions(optionWidget);
1109 toolWidget->setAction(action, update);
1110 //toolWidget->setData(&data);
1115 * Shows a widget for circle options.
1117 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
1119 static CircleOptions * toolWidget = NULL;
1129 if (on && toolWidget == NULL)
1131 toolWidget = new CircleOptions(optionWidget);
1132 toolWidget->setAction(action, update);
1138 * Shows a widget for spline options.
1140 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface * action, bool on, bool update)
1142 static SplineOptions * toolWidget = NULL;
1144 if (optionWidget!=NULL) {
1145 if (toolWidget!=NULL) {
1149 if (on==true && toolWidget==NULL) {
1150 toolWidget = new SplineOptions(optionWidget);
1151 toolWidget->setAction(action, update);
1157 * Shows a widget for text options.
1159 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1161 static TextOptions * toolWidget = NULL;
1174 toolWidget = new TextOptions(optionWidget);
1175 toolWidget->setAction(action, update);
1180 * Shows a widget for insert options.
1182 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface * action, bool on, bool update)
1184 static InsertOptions * toolWidget = NULL;
1186 if (optionWidget!=NULL) {
1187 if (toolWidget!=NULL) {
1191 if (on==true && toolWidget==NULL) {
1192 toolWidget = new InsertOptions(optionWidget);
1193 toolWidget->setAction(action, update);
1199 * Shows a widget for image options.
1201 void QG_DialogFactory::requestImageOptions(RS_ActionInterface * action, bool on, bool update)
1203 static ImageOptions * toolWidget = NULL;
1205 if (optionWidget!=NULL) {
1206 if (toolWidget!=NULL) {
1210 if (on==true && toolWidget==NULL) {
1211 toolWidget = new ImageOptions(optionWidget);
1212 toolWidget->setAction(action, update);
1218 * Shows a widget for dimension options.
1220 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface * action, bool on, bool update)
1222 static DimOptions * toolWidget = NULL;
1224 if (optionWidget!=NULL) {
1225 if (toolWidget!=NULL) {
1229 if (on==true && toolWidget==NULL) {
1230 toolWidget = new DimOptions(optionWidget);
1231 toolWidget->setAction(action, update);
1237 * Shows a widget for linear dimension options.
1239 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface * action, bool on, bool update)
1241 static DimLinearOptions * toolWidget = NULL;
1254 toolWidget = new DimLinearOptions(optionWidget);
1255 toolWidget->setAction(action, update);
1260 * Shows a widget for 'snap to a point with a given distance' options.
1262 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1264 static SnapDistOptions * toolWidget = NULL;
1277 toolWidget = new SnapDistOptions(optionWidget);
1278 toolWidget->setDist(&dist);
1283 * Shows a widget for 'snap to a point with a given distance' options.
1285 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface * action, bool on, bool update)
1287 static MoveRotateOptions * toolWidget = NULL;
1300 toolWidget = new MoveRotateOptions(optionWidget);
1301 toolWidget->setAction(action, update);
1306 * Shows a widget for 'trim amount' options.
1308 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface * action, bool on, bool update)
1310 static TrimAmountOptions * toolWidget = NULL;
1323 toolWidget = new TrimAmountOptions(optionWidget);
1324 toolWidget->setAction(action, update);
1329 * Shows a widget for beveling options.
1331 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1333 static BevelOptions * toolWidget = NULL;
1335 if (optionWidget != NULL)
1337 if (toolWidget != NULL)
1343 if (on && toolWidget == NULL)
1345 toolWidget = new BevelOptions(optionWidget);
1346 toolWidget->setAction(action, update);
1352 * Shows a widget for rounding options.
1354 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface * action, bool on, bool update)
1356 static RoundOptions * toolWidget = NULL;
1369 toolWidget = new RoundOptions(optionWidget);
1370 toolWidget->setAction(action, update);
1375 * Shows a widget for library insert options.
1377 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface * action, bool on, bool update)
1379 static LibraryInsertOptions * toolWidget = NULL;
1392 toolWidget = new LibraryInsertOptions(optionWidget);
1393 toolWidget->setAction(action, update);
1398 * Shows the given toolbar.
1400 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1402 if (cadToolBar != NULL)
1403 cadToolBar->showToolBar(id);
1407 * Shows the select toolbar with the given action to launch.
1409 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1410 RS2::ActionType nextAction)
1412 if (cadToolBar != NULL)
1413 cadToolBar->showToolBarSelect(selectAction, nextAction);
1417 * Shows a dialog to edit the attributes of the given dimension entity.
1420 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1425 QG_DlgDimAligned dlg(parent);
1426 dlg.setDim(*dim, true);
1437 * Shows attributes options dialog presenting the given data.
1439 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1441 DlgAttributes dlg(parent);
1442 dlg.setData(&data, layerList);
1454 * Shows move options dialog presenting the given data.
1456 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1458 DlgMove dlg(parent);
1471 * Shows rotate options dialog presenting the given data.
1473 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1475 DlgRotate dlg(parent);
1488 * Shows scale options dialog presenting the given data.
1490 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1492 DlgScale dlg(parent);
1505 * Shows mirror options dialog presenting the given data.
1507 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1509 DlgMirror dlg(parent);
1522 * Shows move/rotate options dialog presenting the given data.
1524 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1526 DlgMoveRotate dlg(parent);
1539 * Shows rotate around two centers options dialog presenting the given data.
1541 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1543 DlgRotate2 dlg(parent);
1556 * Shows a dialog to edit the given entity.
1558 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1565 switch (entity->rtti())
1567 case RS2::EntityPoint:
1569 DlgPoint dlg(parent);
1570 dlg.setPoint(*((RS_Point *)entity));
1580 case RS2::EntityLine:
1582 DlgLine dlg(parent);
1583 dlg.setLine(*((RS_Line *)entity));
1593 case RS2::EntityArc:
1596 dlg.setArc(*((RS_Arc *)entity));
1606 case RS2::EntityCircle:
1608 DlgCircle dlg(parent);
1609 dlg.setCircle(*((RS_Circle *)entity));
1619 case RS2::EntityEllipse:
1621 DlgEllipse dlg(parent);
1622 dlg.setEllipse(*((RS_Ellipse *)entity));
1626 dlg.updateEllipse();
1632 case RS2::EntitySpline:
1634 DlgSpline dlg(parent);
1635 dlg.setSpline(*((RS_Spline *)entity));
1645 case RS2::EntityInsert:
1647 DlgInsert dlg(parent);
1648 dlg.setInsert(*((RS_Insert *)entity));
1659 case RS2::EntityDimAligned:
1660 case RS2::EntityDimAngular:
1661 case RS2::EntityDimDiametric:
1662 case RS2::EntityDimRadial:
1664 DlgDimension dlg(parent);
1665 dlg.setDim(*((RS_Dimension *)entity));
1671 ((RS_Dimension *)entity)->update(true);
1676 case RS2::EntityDimLinear:
1678 DlgDimLinear dlg(parent);
1679 dlg.setDim(*((RS_DimLinear *)entity));
1685 ((RS_DimLinear *)entity)->update(true);
1690 case RS2::EntityText:
1692 DlgText dlg(parent);
1693 dlg.setText(*((RS_Text *)entity), false);
1699 ((RS_Text *)entity)->update();
1704 case RS2::EntityHatch:
1706 DlgHatch dlg(parent);
1707 dlg.setHatch(*((RS_Hatch *)entity), false);
1713 ((RS_Hatch *)entity)->update();
1726 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1732 * Shows a dialog to edit the attributes of the given text entity.
1734 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1739 DlgText dlg(parent);
1740 dlg.setText(*text, true);
1752 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1754 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1759 RS_PATTERNLIST->init();
1761 DlgHatch dlg(parent);
1762 dlg.setHatch(*hatch, true);
1775 * Shows a dialog for CAM options.
1777 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1779 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1780 RS_CamDialog dlg(graphic, parent);
1781 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1785 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1789 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1795 * Shows dialog for general application options.
1797 void QG_DialogFactory::requestOptionsGeneralDialog()
1799 DlgOptionsGeneral dlg(parent);
1804 * Shows dialog for drawing options.
1806 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1808 DlgOptionsDrawing dlg(parent);
1809 dlg.setGraphic(&graphic);
1814 * Back to last menu in cad toolbar.
1816 void QG_DialogFactory::requestPreviousMenu()
1818 if (cadToolBar != NULL)
1819 cadToolBar->showToolBarMain();
1823 * Called whenever the mouse position changed.
1825 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1826 const Vector & rel, bool updateFormat)
1828 if (coordinateWidget != NULL)
1829 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1833 * Called when an action has a mouse hint.
1835 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1837 if (mouseWidget != NULL)
1838 mouseWidget->setHelp(left, right);
1840 if (commandWidget != NULL)
1841 commandWidget->setCommand(left);
1845 * Called whenever the selection changed.
1847 void QG_DialogFactory::updateSelectionWidget(int num)
1849 if (selectionWidget != NULL)
1850 selectionWidget->setNumber(num);
1854 * Called when an action needs to communicate 'message' to the user.
1856 void QG_DialogFactory::commandMessage(const QString& message)
1858 RS_DEBUG->print("QG_DialogFactory::commandMessage");
1860 if (commandWidget != NULL)
1861 commandWidget->appendHistory(message);
1863 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
1866 /*virtual*/ bool QG_DialogFactory::isAdapter()
1872 * Converts an extension to a format description.
1873 * e.g. "PNG" to "Portable Network Graphic"
1876 * @return Format description
1878 QString QG_DialogFactory::extToFormat(const QString & ext)
1880 QString e = ext.toLower();
1883 return QObject::tr("Windows Bitmap");
1884 else if (e == "jpeg" || e == "jpg")
1885 return QObject::tr("Joint Photographic Experts Group");
1886 else if (e == "gif")
1887 return QObject::tr("Graphics Interchange Format");
1888 else if (e == "mng")
1889 return QObject::tr("Multiple-image Network Graphics");
1890 else if (e == "pbm")
1891 return QObject::tr("Portable Bit Map");
1892 else if (e == "pgm")
1893 return QObject::tr("Portable Grey Map");
1894 else if (e == "png")
1895 return QObject::tr("Portable Network Graphic");
1896 else if (e == "ppm")
1897 return QObject::tr("Portable Pixel Map");
1898 else if (e == "xbm")
1899 return QObject::tr("X Bitmap Format");
1900 else if (e == "xpm")
1901 return QObject::tr("X Pixel Map");
1903 return ext.toUpper();