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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/10/2010 Added this text. :-)
17 #include "qg_dialogfactory.h"
19 #include "graphicview.h"
20 #include "layerwidget.h"
21 #include "qg_mainwindowinterface.h"
22 #include "actiondimlinear.h"
23 #include "actioninterface.h"
24 #include "rs_blocklist.h"
25 #include "rs_document.h"
27 #include "rs_layerlist.h"
28 #include "rs_patternlist.h"
30 #include "rs_system.h"
33 #include "arcoptions.h"
34 #include "arctangentialoptions.h"
35 #include "beveloptions.h"
36 #include "blockdialog.h"
37 #include "cadtoolbar.h"
38 #include "circleoptions.h"
39 #include "commandwidget.h"
40 #include "coordinatewidget.h"
41 #include "dimlinearoptions.h"
42 #include "dimoptions.h"
44 #include "dlgattributes.h"
45 #include "dlgcircle.h"
46 #include "dlgdimension.h"
47 #include "dlgdimlinear.h"
48 #include "dlgellipse.h"
50 #include "dlginsert.h"
52 #include "dlgmirror.h"
54 #include "dlgmoverotate.h"
55 #include "dlgoptionsdrawing.h"
56 #include "dlgoptionsgeneral.h"
58 #include "dlgrotate.h"
59 #include "dlgrotate2.h"
61 #include "dlgspline.h"
63 #include "libraryinsertoptions.h"
64 #include "imageoptions.h"
65 #include "insertoptions.h"
66 #include "layerdialog.h"
67 #include "lineangleoptions.h"
68 #include "linebisectoroptions.h"
69 #include "lineoptions.h"
70 #include "lineparalleloptions.h"
71 #include "lineparallelthroughoptions.h"
72 #include "linepolygon2options.h"
73 #include "linepolygonoptions.h"
74 #include "linerelangleoptions.h"
75 #include "mousewidget.h"
76 #include "moverotateoptions.h"
77 #include "printpreviewoptions.h"
78 #include "roundoptions.h"
79 #include "selectionwidget.h"
80 #include "snapdistoptions.h"
81 #include "splineoptions.h"
82 #include "textoptions.h"
83 #include "trimamountoptions.h"
86 #include "qg_polylineoptions.h"
90 #include "rs_camdialog.h"
93 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
98 * @param parent Pointer to parent widget which can host dialogs.
99 * @param ow Pointer to widget that can host option widgets.
101 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
102 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
103 RS_DialogFactoryInterface()
105 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
107 this->parent = parent;
110 coordinateWidget = NULL;
112 selectionWidget = NULL;
114 commandWidget = NULL;
116 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
122 QG_DialogFactory::~QG_DialogFactory()
124 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
125 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
129 * Links factory to a widget that can host tool options.
131 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
132 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
134 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
136 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
140 * Links this dialog factory to a coordinate widget.
142 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
144 coordinateWidget = cw;
148 * Links this dialog factory to a mouse widget.
150 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
156 * Links this dialog factory to a selection widget.
158 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
160 selectionWidget = sw;
164 * Links this dialog factory to the cad tool bar.
166 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
172 * @return cad tool bar or NULL.
174 CadToolBar * QG_DialogFactory::getCadToolBar()
180 * Links this dialog factory to a command widget.
182 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
188 * @return command widget or NULL.
190 CommandWidget * QG_DialogFactory::getCommandWidget()
192 return commandWidget;
196 * Links the dialog factory to a main app window.
198 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
204 * Shows a message dialog.
206 void QG_DialogFactory::requestWarningDialog(const QString & warning)
208 QMessageBox::information(parent, QMessageBox::tr("Warning"),
209 warning, QMessageBox::Ok);
213 * Requests a new document from the main window.
215 GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
217 if (mainWindow != NULL)
219 mainWindow->createNewDocument(fileName, doc);
220 return mainWindow->getGraphicView();
227 * Requests the simulation controls.
229 void QG_DialogFactory::requestSimulationControls()
231 if (mainWindow != NULL)
233 mainWindow->showSimulationControls();
238 * Shows a dialog for adding a layer. Doesn't add the layer.
239 * This is up to the caller.
241 * @return a pointer to the newly created layer that
244 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
246 RS_Layer * layer = NULL;
247 QString layer_name = "noname";
250 if (layerList != NULL)
252 while (layerList->find(layer_name) > 0)
253 layer_name.sprintf("noname%d", i++);
256 // Layer for parameter livery
257 layer = new RS_Layer(layer_name);
259 // QG_LayerDialog dlg(parent, "Layer Dialog");
260 LayerDialog dlg(parent);
262 dlg.setLayerList(layerList);
276 * Shows a dialog that asks the user if the selected layer
277 * can be removed. Doesn't remove the layer. This is up to the caller.
279 * @return a pointer to the layer that should be removed.
281 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
283 RS_Layer * layer = NULL;
285 if (layerList == NULL)
287 RS_DEBUG->print(RS_Debug::D_WARNING,
288 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
293 if (layerList==NULL) {
294 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
295 layerList = (RS_LayerList*)container;
301 // Layer for parameter livery
302 layer = layerList->getActive();
306 if (layer->getName() != "0")
308 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
309 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
310 QMessageBox::Ok, QMessageBox::Cancel);
322 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
323 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
332 * Shows a dialog for editing a layer. A new layer is created and
333 * returned. Modifying the layer is up to the caller.
335 * @return A pointer to a new layer with the changed attributes
336 * or NULL if the dialog was cancelled.
338 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
340 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
341 RS_Layer * layer = NULL;
343 if (layerList==NULL) {
344 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
345 layerList = (RS_LayerList*)container;
352 if (layerList == NULL)
354 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
355 "layerList is NULL");
359 // Layer for parameter livery
360 if (layerList->getActive() != NULL)
362 layer = new RS_Layer(*layerList->getActive());
364 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
365 LayerDialog dlg(parent);
367 dlg.setLayerList(layerList);
368 dlg.setEditLayer(true);
383 * Shows a dialog for adding a block. Doesn't add the block.
384 * This is up to the caller.
386 * @return a pointer to the newly created block that
389 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
391 //RS_Block* block = NULL;
393 ret = RS_BlockData("", Vector(false), false);
395 if (blockList == NULL)
397 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
398 "blockList is NULL");
402 // Block for parameter livery
403 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
405 BlockDialog dlg(parent);
406 dlg.setBlockList(blockList);
409 ret = dlg.getBlockData();
415 * Shows a dialog for renaming the currently active block.
417 * @return a pointer to the modified block or NULL on cancellation.
419 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
421 //RS_Block* block = NULL;
423 ret = RS_BlockData("", Vector(false), false);
425 if (blockList == NULL)
427 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
428 "blockList is NULL");
432 if (blockList==NULL) {
433 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
434 blockList = (RS_BlockList*)container;
440 // Block for parameter livery
441 //block = blockList->getActive();
443 BlockDialog dlg(parent);//WAS:, "Rename Block");
444 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
445 dlg.setWindowTitle(QObject::tr("Rename Block"));
446 dlg.setBlockList(blockList);
452 ret = dlg.getBlockData();
455 // ret = RS_BlockData("", Vector(false));
461 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
465 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
470 * Shows a dialog that asks the user if the selected block
471 * can be removed. Doesn't remove the block. This is up to the caller.
473 * @return a pointer to the block that should be removed.
475 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
477 RS_Block * block = NULL;
479 if (blockList == NULL)
481 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
482 "blockList is NULL");
486 // Block for parameter livery
487 block = blockList->getActive();
491 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
492 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
493 QMessageBox::Ok, QMessageBox::Cancel);
508 * Shows a dialog for choosing a file name. Saving the file is up to
511 * @return File name with path and extension to determine the file type
512 * or an empty string if the dialog was cancelled.
515 QString QG_DialogFactory::requestFileSaveAsDialog() {
516 // read default settings:
517 RS_SETTINGS->beginGroup("/Paths");
518 QString defDir = RS_SETTINGS->readEntry("/Save",
519 RS_SYSTEM->getHomeDir());
520 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
521 "Drawing Exchange (*.dxf)");
522 RS_SETTINGS->endGroup();
524 // prepare file save as dialog:
525 QFileDialog fileDlg(this,0,true);
531 filters.append("Drawing Exchange (*.dxf)");
532 filters.append("Font (*.cxf)");
533 fileDlg.setFilters(filters);
534 fileDlg.setMode(QFileDialog::AnyFile);
535 fileDlg.setCaption(tr("Save Drawing As"));
536 fileDlg.setDir(defDir);
537 fileDlg.setSelectedFilter(defFilter);
542 if (fileDlg.exec()==QDialog::Accepted) {
543 fn = fileDlg.selectedFile();
546 // append default extension:
547 if (fn.find('.')==-1) {
548 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
555 // overwrite warning:
556 if(QFileInfo(fn).exists()) {
558 QMessageBox::warning(this, tr("Save Drawing As"),
559 tr("%1 already exists.\n"
560 "Do you want to replace it?")
563 tr("Cancel"), 0, 1 );
586 // store new default settings:
588 RS_SETTINGS->beginGroup("/Paths");
589 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
590 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
591 RS_SETTINGS->endGroup();
599 * Shows a dialog for choosing a file name. Opening the file is up to
602 * @return File name with path and extension to determine the file type
603 * or an empty string if the dialog was cancelled.
605 QString QG_DialogFactory::requestImageOpenDialog()
609 // read default settings:
610 settings.beginGroup("Paths");
611 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
612 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
617 // Q3FileDialog fileDlg(NULL, "", true);
618 QFileDialog fileDlg(NULL, "");
621 // Q3StrList f = QImageIO::inputFormats();
622 // QStringList formats = QStringList::fromStrList(f);
623 QList<QByteArray> f = QImageReader::supportedImageFormats();
624 QStringList formats = ???
626 #warning "Needs porting to Qt4... !!! FIX !!!"
631 //filters = QStringList::fromStrList(formats);
634 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
642 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
646 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
656 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
660 all += QString("*.%1").arg(QString(*it).lower());
665 filters.append(QObject::tr("All Image Files (%1)").arg(all));
666 filters.append(QObject::tr("All Files (*.*)"));
668 //filters.append("Drawing Exchange (*.)");
669 //filters.append("Font (*.cxf)");
671 fileDlg.setFilters(filters);
672 // fileDlg.setMode(Q3FileDialog::ExistingFile);
673 fileDlg.setFileMode(QFileDialog::ExistingFile);
674 // fileDlg.setCaption(QObject::tr("Open Image"));
675 fileDlg.setWindowTitle(QObject::tr("Open Image"));
676 // fileDlg.setDir(defDir);
677 fileDlg.setDirectory(defDir);
678 // fileDlg.setSelectedFilter(defFilter);
679 fileDlg.selectFilter(defFilter);
683 if (fileDlg.exec() == QDialog::Accepted)
685 // fn = fileDlg.selectedFile();
686 QStringList files = fileDlg.selectedFiles();
688 if (!files.isEmpty())
694 // store new default settings:
697 QStringList files = fileDlg.selectedFiles();
698 QString selected = "";
700 if (!files.isEmpty())
703 settings.beginGroup("Paths");
704 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
705 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
706 settings.setValue("ImageFilter", selected);
713 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
715 RS_DEBUG->print("QG_DialogFactory::requestOptions");
719 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
723 switch (action->rtti())
725 case RS2::ActionPrintPreview:
726 requestPrintPreviewOptions(action, on, update);
729 case RS2::ActionDrawLine:
730 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
731 requestLineOptions(action, on);
732 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
735 case RS2::ActionDrawPolyline:
736 requestPolylineOptions(action, on, update);
739 case RS2::ActionDrawLineAngle:
740 requestLineAngleOptions(action, on, update);
743 case RS2::ActionDrawLineParallel:
744 requestLineParallelOptions(action, on, update);
747 case RS2::ActionDrawLineParallelThrough:
748 requestLineParallelThroughOptions(action, on, update);
751 case RS2::ActionDrawLineBisector:
752 requestLineBisectorOptions(action, on, update);
755 case RS2::ActionDrawLineRelAngle:
756 requestLineRelAngleOptions(action, on, update);
759 case RS2::ActionDrawLinePolygon:
760 requestLinePolygonOptions(action, on, update);
763 case RS2::ActionDrawLinePolygon2:
764 requestLinePolygon2Options(action, on, update);
767 case RS2::ActionDrawArc:
768 requestArcOptions(action, on, update);
771 case RS2::ActionDrawArcTangential:
772 requestArcTangentialOptions(action, on, update);
775 case RS2::ActionDrawCircleCR:
776 requestCircleOptions(action, on, update);
779 case RS2::ActionDrawSpline:
780 requestSplineOptions(action, on, update);
783 case RS2::ActionDrawText:
784 requestTextOptions(action, on, update);
787 case RS2::ActionBlocksInsert:
788 requestInsertOptions(action, on, update);
791 case RS2::ActionDrawImage:
792 requestImageOptions(action, on, update);
795 case RS2::ActionDimAligned:
796 requestDimensionOptions(action, on, update);
799 case RS2::ActionDimLinear:
800 requestDimensionOptions(action, on, update);
802 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
803 requestDimLinearOptions(action, on, update);
807 case RS2::ActionDimRadial:
808 requestDimensionOptions(action, on, update);
811 case RS2::ActionDimDiametric:
812 requestDimensionOptions(action, on, update);
815 case RS2::ActionDimAngular:
816 requestDimensionOptions(action, on, update);
819 case RS2::ActionModifyTrimAmount:
820 requestTrimAmountOptions(action, on, update);
823 case RS2::ActionModifyMoveRotate:
824 requestMoveRotateOptions(action, on, update);
827 case RS2::ActionModifyBevel:
828 requestBevelOptions(action, on, update);
831 case RS2::ActionModifyRound:
832 requestRoundOptions(action, on, update);
835 case RS2::ActionLibraryInsert:
836 requestLibraryInsertOptions(action, on, update);
843 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
847 * Shows a widget for options for the action: "print preview"
849 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
851 static PrintPreviewOptions * toolWidget = NULL;
864 toolWidget = new PrintPreviewOptions(optionWidget);
865 toolWidget->setAction(action, update);
870 * Shows a widget for options for the action: "draw line"
872 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
875 The way I see it, this is failure. We're constantly creating & deleting
876 these objects all the time when we could create them once, and then reuse
877 them over and over. May need to do some more refactoring based on this idea...
880 static LineOptions * toolWidget = NULL;
885 // Get rid of the LineOptions object if it exists...
892 // Create a new one for the passed in action
895 toolWidget = new LineOptions(optionWidget);
896 toolWidget->setAction(action);
899 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
903 * Shows a widget for options for the action: "draw polyline"
905 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
908 static PolylineOptions * toolWidget = NULL;
921 toolWidget = new PolylineOptions(optionWidget);
922 toolWidget->setAction(action, update);
928 * Shows a widget for options for the action: "draw line parallel"
930 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
932 static LineParallelOptions * toolWidget = NULL;
934 if (optionWidget!=NULL)
936 if (toolWidget!=NULL)
941 if (on==true && toolWidget==NULL)
943 toolWidget = new LineParallelOptions(optionWidget);
944 toolWidget->setAction(action, update);
950 * Shows a widget for options for the action: "draw line parallel through"
952 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
954 static LineParallelThroughOptions * toolWidget = NULL;
956 if (optionWidget!=NULL) {
957 if (toolWidget!=NULL) {
961 if (on==true && toolWidget==NULL) {
962 toolWidget = new LineParallelThroughOptions(optionWidget);
963 toolWidget->setAction(action, update);
969 * Shows a widget for options for the action: "line angle"
971 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
973 static LineAngleOptions * toolWidget = NULL;
986 toolWidget = new LineAngleOptions(optionWidget);
987 toolWidget->setAction(action, update);
992 * Shows a widget for options for the action: "line relative angle"
994 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
996 static LineRelAngleOptions * toolWidget = NULL;
1009 toolWidget = new LineRelAngleOptions(optionWidget);
1010 toolWidget->setAction(action, update);
1015 * Shows a widget for options for the action: "line angle"
1017 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
1019 static LineBisectorOptions * toolWidget = NULL;
1021 if (optionWidget!=NULL) {
1022 if (toolWidget!=NULL) {
1026 if (on==true && toolWidget==NULL) {
1027 toolWidget = new LineBisectorOptions(optionWidget);
1028 toolWidget->setAction(action, update);
1034 * Shows a widget for options for the action: "draw polygon"
1036 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1038 static LinePolygonOptions * toolWidget = NULL;
1040 if (optionWidget!=NULL) {
1041 if (toolWidget!=NULL) {
1045 if (on==true && toolWidget==NULL) {
1046 toolWidget = new LinePolygonOptions(optionWidget);
1047 toolWidget->setAction(action, update);
1053 * Shows a widget for options for the action: "draw polygon2"
1055 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1057 static LinePolygon2Options * toolWidget = NULL;
1059 if (optionWidget!=NULL) {
1060 if (toolWidget!=NULL) {
1064 if (on==true && toolWidget==NULL) {
1065 toolWidget = new LinePolygon2Options(optionWidget);
1066 toolWidget->setAction(action, update);
1072 * Shows a widget for arc options.
1074 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1076 static ArcOptions * toolWidget = NULL;
1078 if (optionWidget != NULL)
1080 if (toolWidget != NULL)
1086 if (on && toolWidget == NULL)
1088 toolWidget = new ArcOptions(optionWidget);
1089 toolWidget->setAction(action, update);
1090 //toolWidget->setData(&data);
1096 * Shows a widget for tangential arc options.
1098 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1100 static ArcTangentialOptions * toolWidget = NULL;
1113 toolWidget = new ArcTangentialOptions(optionWidget);
1114 toolWidget->setAction(action, update);
1115 //toolWidget->setData(&data);
1120 * Shows a widget for circle options.
1122 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1124 static CircleOptions * toolWidget = NULL;
1134 if (on && toolWidget == NULL)
1136 toolWidget = new CircleOptions(optionWidget);
1137 toolWidget->setAction(action, update);
1143 * Shows a widget for spline options.
1145 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1147 static SplineOptions * toolWidget = NULL;
1160 toolWidget = new SplineOptions(optionWidget);
1161 toolWidget->setAction(action, update);
1166 * Shows a widget for text options.
1168 void QG_DialogFactory::requestTextOptions(ActionInterface * action, bool on, bool update)
1170 static TextOptions * toolWidget = NULL;
1183 toolWidget = new TextOptions(optionWidget);
1184 toolWidget->setAction(action, update);
1189 * Shows a widget for insert options.
1191 void QG_DialogFactory::requestInsertOptions(ActionInterface * action, bool on, bool update)
1193 static InsertOptions * toolWidget = NULL;
1195 if (optionWidget!=NULL) {
1196 if (toolWidget!=NULL) {
1200 if (on==true && toolWidget==NULL) {
1201 toolWidget = new InsertOptions(optionWidget);
1202 toolWidget->setAction(action, update);
1208 * Shows a widget for image options.
1210 void QG_DialogFactory::requestImageOptions(ActionInterface * action, bool on, bool update)
1212 static ImageOptions * toolWidget = NULL;
1214 if (optionWidget!=NULL) {
1215 if (toolWidget!=NULL) {
1219 if (on==true && toolWidget==NULL) {
1220 toolWidget = new ImageOptions(optionWidget);
1221 toolWidget->setAction(action, update);
1227 * Shows a widget for dimension options.
1229 void QG_DialogFactory::requestDimensionOptions(ActionInterface * action, bool on, bool update)
1231 static DimOptions * toolWidget = NULL;
1233 if (optionWidget!=NULL) {
1234 if (toolWidget!=NULL) {
1238 if (on==true && toolWidget==NULL) {
1239 toolWidget = new DimOptions(optionWidget);
1240 toolWidget->setAction(action, update);
1246 * Shows a widget for linear dimension options.
1248 void QG_DialogFactory::requestDimLinearOptions(ActionInterface * action, bool on, bool update)
1250 static DimLinearOptions * toolWidget = NULL;
1263 toolWidget = new DimLinearOptions(optionWidget);
1264 toolWidget->setAction(action, update);
1269 * Shows a widget for 'snap to a point with a given distance' options.
1271 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1273 static SnapDistOptions * toolWidget = NULL;
1286 toolWidget = new SnapDistOptions(optionWidget);
1287 toolWidget->setDist(&dist);
1292 * Shows a widget for 'snap to a point with a given distance' options.
1294 void QG_DialogFactory::requestMoveRotateOptions(ActionInterface * action, bool on, bool update)
1296 static MoveRotateOptions * toolWidget = NULL;
1309 toolWidget = new MoveRotateOptions(optionWidget);
1310 toolWidget->setAction(action, update);
1315 * Shows a widget for 'trim amount' options.
1317 void QG_DialogFactory::requestTrimAmountOptions(ActionInterface * action, bool on, bool update)
1319 static TrimAmountOptions * toolWidget = NULL;
1332 toolWidget = new TrimAmountOptions(optionWidget);
1333 toolWidget->setAction(action, update);
1338 * Shows a widget for beveling options.
1340 void QG_DialogFactory::requestBevelOptions(ActionInterface * action, bool on, bool update)
1342 static BevelOptions * toolWidget = NULL;
1344 if (optionWidget != NULL)
1346 if (toolWidget != NULL)
1352 if (on && toolWidget == NULL)
1354 toolWidget = new BevelOptions(optionWidget);
1355 toolWidget->setAction(action, update);
1361 * Shows a widget for rounding options.
1363 void QG_DialogFactory::requestRoundOptions(ActionInterface * action, bool on, bool update)
1365 static RoundOptions * toolWidget = NULL;
1378 toolWidget = new RoundOptions(optionWidget);
1379 toolWidget->setAction(action, update);
1384 * Shows a widget for library insert options.
1386 void QG_DialogFactory::requestLibraryInsertOptions(ActionInterface * action, bool on, bool update)
1388 static LibraryInsertOptions * toolWidget = NULL;
1401 toolWidget = new LibraryInsertOptions(optionWidget);
1402 toolWidget->setAction(action, update);
1407 * Shows the given toolbar.
1409 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1411 if (cadToolBar != NULL)
1412 cadToolBar->showToolBar(id);
1416 * Shows the select toolbar with the given action to launch.
1418 void QG_DialogFactory::requestToolBarSelect(ActionInterface * selectAction,
1419 RS2::ActionType nextAction)
1421 if (cadToolBar != NULL)
1422 cadToolBar->showToolBarSelect(selectAction, nextAction);
1426 * Shows a dialog to edit the attributes of the given dimension entity.
1429 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1434 QG_DlgDimAligned dlg(parent);
1435 dlg.setDim(*dim, true);
1446 * Shows attributes options dialog presenting the given data.
1448 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1450 DlgAttributes dlg(parent);
1451 dlg.setData(&data, layerList);
1463 * Shows move options dialog presenting the given data.
1465 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1467 DlgMove dlg(parent);
1480 * Shows rotate options dialog presenting the given data.
1482 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1484 DlgRotate dlg(parent);
1497 * Shows scale options dialog presenting the given data.
1499 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1501 DlgScale dlg(parent);
1514 * Shows mirror options dialog presenting the given data.
1516 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1518 DlgMirror dlg(parent);
1531 * Shows move/rotate options dialog presenting the given data.
1533 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1535 DlgMoveRotate dlg(parent);
1548 * Shows rotate around two centers options dialog presenting the given data.
1550 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1552 DlgRotate2 dlg(parent);
1565 * Shows a dialog to edit the given entity.
1567 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1574 switch (entity->rtti())
1576 case RS2::EntityPoint:
1578 DlgPoint dlg(parent);
1579 dlg.setPoint(*((RS_Point *)entity));
1589 case RS2::EntityLine:
1591 DlgLine dlg(parent);
1592 dlg.setLine(*((RS_Line *)entity));
1602 case RS2::EntityArc:
1605 dlg.setArc(*((RS_Arc *)entity));
1615 case RS2::EntityCircle:
1617 DlgCircle dlg(parent);
1618 dlg.setCircle(*((RS_Circle *)entity));
1628 case RS2::EntityEllipse:
1630 DlgEllipse dlg(parent);
1631 dlg.setEllipse(*((RS_Ellipse *)entity));
1635 dlg.updateEllipse();
1641 case RS2::EntitySpline:
1643 DlgSpline dlg(parent);
1644 dlg.setSpline(*((RS_Spline *)entity));
1654 case RS2::EntityInsert:
1656 DlgInsert dlg(parent);
1657 dlg.setInsert(*((RS_Insert *)entity));
1668 case RS2::EntityDimAligned:
1669 case RS2::EntityDimAngular:
1670 case RS2::EntityDimDiametric:
1671 case RS2::EntityDimRadial:
1673 DlgDimension dlg(parent);
1674 dlg.setDim(*((RS_Dimension *)entity));
1680 ((RS_Dimension *)entity)->update(true);
1685 case RS2::EntityDimLinear:
1687 DlgDimLinear dlg(parent);
1688 dlg.setDim(*((RS_DimLinear *)entity));
1694 ((RS_DimLinear *)entity)->update(true);
1699 case RS2::EntityText:
1701 DlgText dlg(parent);
1702 dlg.setText(*((RS_Text *)entity), false);
1708 ((RS_Text *)entity)->update();
1713 case RS2::EntityHatch:
1715 DlgHatch dlg(parent);
1716 dlg.setHatch(*((RS_Hatch *)entity), false);
1722 ((RS_Hatch *)entity)->update();
1735 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1741 * Shows a dialog to edit the attributes of the given text entity.
1743 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1748 DlgText dlg(parent);
1749 dlg.setText(*text, true);
1761 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1763 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1768 RS_PATTERNLIST->init();
1770 DlgHatch dlg(parent);
1771 dlg.setHatch(*hatch, true);
1784 * Shows a dialog for CAM options.
1786 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1788 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1789 RS_CamDialog dlg(graphic, parent);
1790 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1794 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1798 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1804 * Shows dialog for general application options.
1806 void QG_DialogFactory::requestOptionsGeneralDialog()
1808 DlgOptionsGeneral dlg(parent);
1813 * Shows dialog for drawing options.
1815 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1817 DlgOptionsDrawing dlg(parent);
1818 dlg.setGraphic(&graphic);
1823 * Back to last menu in cad toolbar.
1825 void QG_DialogFactory::requestPreviousMenu()
1827 if (cadToolBar != NULL)
1828 cadToolBar->showToolBarMain();
1832 * Called whenever the mouse position changed.
1834 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1835 const Vector & rel, bool updateFormat)
1837 if (coordinateWidget != NULL)
1838 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1842 * Called when an action has a mouse hint.
1844 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1847 mouseWidget->setHelp(left, right);
1850 commandWidget->setCommand(left);
1854 * Called whenever the selection changed.
1856 void QG_DialogFactory::updateSelectionWidget(int num)
1858 if (selectionWidget != NULL)
1859 selectionWidget->setNumber(num);
1863 * Called when an action needs to communicate 'message' to the user.
1865 void QG_DialogFactory::commandMessage(const QString& message)
1867 RS_DEBUG->print("QG_DialogFactory::commandMessage");
1869 if (commandWidget != NULL)
1870 commandWidget->appendHistory(message);
1872 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
1875 /*virtual*/ bool QG_DialogFactory::isAdapter()
1881 * Converts an extension to a format description.
1882 * e.g. "PNG" to "Portable Network Graphic"
1885 * @return Format description
1887 QString QG_DialogFactory::extToFormat(const QString & ext)
1889 QString e = ext.toLower();
1892 return QObject::tr("Windows Bitmap");
1893 else if (e == "jpeg" || e == "jpg")
1894 return QObject::tr("Joint Photographic Experts Group");
1895 else if (e == "gif")
1896 return QObject::tr("Graphics Interchange Format");
1897 else if (e == "mng")
1898 return QObject::tr("Multiple-image Network Graphics");
1899 else if (e == "pbm")
1900 return QObject::tr("Portable Bit Map");
1901 else if (e == "pgm")
1902 return QObject::tr("Portable Grey Map");
1903 else if (e == "png")
1904 return QObject::tr("Portable Network Graphic");
1905 else if (e == "ppm")
1906 return QObject::tr("Portable Pixel Map");
1907 else if (e == "xbm")
1908 return QObject::tr("X Bitmap Format");
1909 else if (e == "xpm")
1910 return QObject::tr("X Pixel Map");
1912 return ext.toUpper();