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;
345 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
346 "layerList is NULL");
350 // Layer for parameter livery
351 if (layerList->getActive())
353 layer = new RS_Layer(*layerList->getActive());
355 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
356 LayerDialog dlg(parent);
358 dlg.setLayerList(layerList);
359 dlg.setEditLayer(true);
374 * Shows a dialog for adding a block. Doesn't add the block.
375 * This is up to the caller.
377 * @return a pointer to the newly created block that
380 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
382 //RS_Block* block = NULL;
384 ret = RS_BlockData("", Vector(false), false);
386 if (blockList == NULL)
388 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
389 "blockList is NULL");
393 // Block for parameter livery
394 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
396 BlockDialog dlg(parent);
397 dlg.setBlockList(blockList);
400 ret = dlg.getBlockData();
406 * Shows a dialog for renaming the currently active block.
408 * @return a pointer to the modified block or NULL on cancellation.
410 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
412 //RS_Block* block = NULL;
414 ret = RS_BlockData("", Vector(false), false);
416 if (blockList == NULL)
418 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
419 "blockList is NULL");
423 if (blockList==NULL) {
424 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
425 blockList = (RS_BlockList*)container;
431 // Block for parameter livery
432 //block = blockList->getActive();
434 BlockDialog dlg(parent);//WAS:, "Rename Block");
435 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
436 dlg.setWindowTitle(QObject::tr("Rename Block"));
437 dlg.setBlockList(blockList);
443 ret = dlg.getBlockData();
446 // ret = RS_BlockData("", Vector(false));
452 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
456 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
461 * Shows a dialog that asks the user if the selected block
462 * can be removed. Doesn't remove the block. This is up to the caller.
464 * @return a pointer to the block that should be removed.
466 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
468 RS_Block * block = NULL;
470 if (blockList == NULL)
472 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
473 "blockList is NULL");
477 // Block for parameter livery
478 block = blockList->getActive();
482 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
483 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
484 QMessageBox::Ok, QMessageBox::Cancel);
499 * Shows a dialog for choosing a file name. Saving the file is up to
502 * @return File name with path and extension to determine the file type
503 * or an empty string if the dialog was cancelled.
506 QString QG_DialogFactory::requestFileSaveAsDialog() {
507 // read default settings:
508 RS_SETTINGS->beginGroup("/Paths");
509 QString defDir = RS_SETTINGS->readEntry("/Save",
510 RS_SYSTEM->getHomeDir());
511 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
512 "Drawing Exchange (*.dxf)");
513 RS_SETTINGS->endGroup();
515 // prepare file save as dialog:
516 QFileDialog fileDlg(this,0,true);
522 filters.append("Drawing Exchange (*.dxf)");
523 filters.append("Font (*.cxf)");
524 fileDlg.setFilters(filters);
525 fileDlg.setMode(QFileDialog::AnyFile);
526 fileDlg.setCaption(tr("Save Drawing As"));
527 fileDlg.setDir(defDir);
528 fileDlg.setSelectedFilter(defFilter);
533 if (fileDlg.exec()==QDialog::Accepted) {
534 fn = fileDlg.selectedFile();
537 // append default extension:
538 if (fn.find('.')==-1) {
539 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
546 // overwrite warning:
547 if(QFileInfo(fn).exists()) {
549 QMessageBox::warning(this, tr("Save Drawing As"),
550 tr("%1 already exists.\n"
551 "Do you want to replace it?")
554 tr("Cancel"), 0, 1 );
577 // store new default settings:
579 RS_SETTINGS->beginGroup("/Paths");
580 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
581 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
582 RS_SETTINGS->endGroup();
590 * Shows a dialog for choosing a file name. Opening the file is up to
593 * @return File name with path and extension to determine the file type
594 * or an empty string if the dialog was cancelled.
596 QString QG_DialogFactory::requestImageOpenDialog()
600 // read default settings:
601 settings.beginGroup("Paths");
602 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
603 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
608 // Q3FileDialog fileDlg(NULL, "", true);
609 QFileDialog fileDlg(NULL, "");
612 // Q3StrList f = QImageIO::inputFormats();
613 // QStringList formats = QStringList::fromStrList(f);
614 QList<QByteArray> f = QImageReader::supportedImageFormats();
615 QStringList formats = ???
617 #warning "Needs porting to Qt4... !!! FIX !!!"
622 //filters = QStringList::fromStrList(formats);
625 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
633 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
637 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
647 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
651 all += QString("*.%1").arg(QString(*it).lower());
656 filters.append(QObject::tr("All Image Files (%1)").arg(all));
657 filters.append(QObject::tr("All Files (*.*)"));
659 //filters.append("Drawing Exchange (*.)");
660 //filters.append("Font (*.cxf)");
662 fileDlg.setFilters(filters);
663 // fileDlg.setMode(Q3FileDialog::ExistingFile);
664 fileDlg.setFileMode(QFileDialog::ExistingFile);
665 // fileDlg.setCaption(QObject::tr("Open Image"));
666 fileDlg.setWindowTitle(QObject::tr("Open Image"));
667 // fileDlg.setDir(defDir);
668 fileDlg.setDirectory(defDir);
669 // fileDlg.setSelectedFilter(defFilter);
670 fileDlg.selectFilter(defFilter);
674 if (fileDlg.exec() == QDialog::Accepted)
676 // fn = fileDlg.selectedFile();
677 QStringList files = fileDlg.selectedFiles();
679 if (!files.isEmpty())
685 // store new default settings:
688 QStringList files = fileDlg.selectedFiles();
689 QString selected = "";
691 if (!files.isEmpty())
694 settings.beginGroup("Paths");
695 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
696 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
697 settings.setValue("ImageFilter", selected);
704 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
706 RS_DEBUG->print("QG_DialogFactory::requestOptions");
710 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
714 switch (action->rtti())
716 case RS2::ActionPrintPreview:
717 requestPrintPreviewOptions(action, on, update);
720 case RS2::ActionDrawLine:
721 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
722 requestLineOptions(action, on);
723 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
726 case RS2::ActionDrawPolyline:
727 requestPolylineOptions(action, on, update);
730 case RS2::ActionDrawLineAngle:
731 requestLineAngleOptions(action, on, update);
734 case RS2::ActionDrawLineParallel:
735 requestLineParallelOptions(action, on, update);
738 case RS2::ActionDrawLineParallelThrough:
739 requestLineParallelThroughOptions(action, on, update);
742 case RS2::ActionDrawLineBisector:
743 requestLineBisectorOptions(action, on, update);
746 case RS2::ActionDrawLineRelAngle:
747 requestLineRelAngleOptions(action, on, update);
750 case RS2::ActionDrawLinePolygon:
751 requestLinePolygonOptions(action, on, update);
754 case RS2::ActionDrawLinePolygon2:
755 requestLinePolygon2Options(action, on, update);
758 case RS2::ActionDrawArc:
759 requestArcOptions(action, on, update);
762 case RS2::ActionDrawArcTangential:
763 requestArcTangentialOptions(action, on, update);
766 case RS2::ActionDrawCircleCR:
767 requestCircleOptions(action, on, update);
770 case RS2::ActionDrawSpline:
771 requestSplineOptions(action, on, update);
774 case RS2::ActionDrawText:
775 requestTextOptions(action, on, update);
778 case RS2::ActionBlocksInsert:
779 requestInsertOptions(action, on, update);
782 case RS2::ActionDrawImage:
783 requestImageOptions(action, on, update);
786 case RS2::ActionDimAligned:
787 requestDimensionOptions(action, on, update);
790 case RS2::ActionDimLinear:
791 requestDimensionOptions(action, on, update);
793 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
794 requestDimLinearOptions(action, on, update);
798 case RS2::ActionDimRadial:
799 requestDimensionOptions(action, on, update);
802 case RS2::ActionDimDiametric:
803 requestDimensionOptions(action, on, update);
806 case RS2::ActionDimAngular:
807 requestDimensionOptions(action, on, update);
810 case RS2::ActionModifyTrimAmount:
811 requestTrimAmountOptions(action, on, update);
814 case RS2::ActionModifyMoveRotate:
815 requestMoveRotateOptions(action, on, update);
818 case RS2::ActionModifyBevel:
819 requestBevelOptions(action, on, update);
822 case RS2::ActionModifyRound:
823 requestRoundOptions(action, on, update);
826 case RS2::ActionLibraryInsert:
827 requestLibraryInsertOptions(action, on, update);
834 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
838 * Shows a widget for options for the action: "print preview"
840 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
842 static PrintPreviewOptions * toolWidget = NULL;
855 toolWidget = new PrintPreviewOptions(optionWidget);
856 toolWidget->setAction(action, update);
861 * Shows a widget for options for the action: "draw line"
863 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
866 The way I see it, this is failure. We're constantly creating & deleting
867 these objects all the time when we could create them once, and then reuse
868 them over and over. May need to do some more refactoring based on this idea...
871 static LineOptions * toolWidget = NULL;
876 // Get rid of the LineOptions object if it exists...
883 // Create a new one for the passed in action
886 toolWidget = new LineOptions(optionWidget);
887 toolWidget->setAction(action);
890 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
894 * Shows a widget for options for the action: "draw polyline"
896 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
899 static PolylineOptions * toolWidget = NULL;
912 toolWidget = new PolylineOptions(optionWidget);
913 toolWidget->setAction(action, update);
919 * Shows a widget for options for the action: "draw line parallel"
921 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
923 static LineParallelOptions * toolWidget = NULL;
925 if (optionWidget!=NULL)
927 if (toolWidget!=NULL)
932 if (on==true && toolWidget==NULL)
934 toolWidget = new LineParallelOptions(optionWidget);
935 toolWidget->setAction(action, update);
941 * Shows a widget for options for the action: "draw line parallel through"
943 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
945 static LineParallelThroughOptions * toolWidget = NULL;
947 if (optionWidget!=NULL) {
948 if (toolWidget!=NULL) {
952 if (on==true && toolWidget==NULL) {
953 toolWidget = new LineParallelThroughOptions(optionWidget);
954 toolWidget->setAction(action, update);
960 * Shows a widget for options for the action: "line angle"
962 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
964 static LineAngleOptions * toolWidget = NULL;
977 toolWidget = new LineAngleOptions(optionWidget);
978 toolWidget->setAction(action, update);
983 * Shows a widget for options for the action: "line relative angle"
985 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
987 static LineRelAngleOptions * toolWidget = NULL;
1000 toolWidget = new LineRelAngleOptions(optionWidget);
1001 toolWidget->setAction(action, update);
1006 * Shows a widget for options for the action: "line angle"
1008 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
1010 static LineBisectorOptions * toolWidget = NULL;
1012 if (optionWidget!=NULL) {
1013 if (toolWidget!=NULL) {
1017 if (on==true && toolWidget==NULL) {
1018 toolWidget = new LineBisectorOptions(optionWidget);
1019 toolWidget->setAction(action, update);
1025 * Shows a widget for options for the action: "draw polygon"
1027 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1029 static LinePolygonOptions * toolWidget = NULL;
1031 if (optionWidget!=NULL) {
1032 if (toolWidget!=NULL) {
1036 if (on==true && toolWidget==NULL) {
1037 toolWidget = new LinePolygonOptions(optionWidget);
1038 toolWidget->setAction(action, update);
1044 * Shows a widget for options for the action: "draw polygon2"
1046 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1048 static LinePolygon2Options * toolWidget = NULL;
1050 if (optionWidget!=NULL) {
1051 if (toolWidget!=NULL) {
1055 if (on==true && toolWidget==NULL) {
1056 toolWidget = new LinePolygon2Options(optionWidget);
1057 toolWidget->setAction(action, update);
1063 * Shows a widget for arc options.
1065 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1067 static ArcOptions * toolWidget = NULL;
1069 if (optionWidget != NULL)
1071 if (toolWidget != NULL)
1077 if (on && toolWidget == NULL)
1079 toolWidget = new ArcOptions(optionWidget);
1080 toolWidget->setAction(action, update);
1081 //toolWidget->setData(&data);
1087 * Shows a widget for tangential arc options.
1089 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1091 static ArcTangentialOptions * toolWidget = NULL;
1104 toolWidget = new ArcTangentialOptions(optionWidget);
1105 toolWidget->setAction(action, update);
1106 //toolWidget->setData(&data);
1111 * Shows a widget for circle options.
1113 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1115 static CircleOptions * toolWidget = NULL;
1125 if (on && toolWidget == NULL)
1127 toolWidget = new CircleOptions(optionWidget);
1128 toolWidget->setAction(action, update);
1134 * Shows a widget for spline options.
1136 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1138 static SplineOptions * toolWidget = NULL;
1151 toolWidget = new SplineOptions(optionWidget);
1152 toolWidget->setAction(action, update);
1157 * Shows a widget for text options.
1159 void QG_DialogFactory::requestTextOptions(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(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(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(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(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(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(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(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(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(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)
1403 cadToolBar->showToolBar(id);
1407 * Shows the select toolbar with the given action to launch.
1409 void QG_DialogFactory::requestToolBarSelect(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)
1838 mouseWidget->setHelp(left, right);
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();