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"
22 #include "rs_patternlist.h"
24 #include "rs_system.h"
28 #include "ui/qg_arcoptions.h"
29 #include "ui/qg_arctangentialoptions.h"
30 #include "ui/qg_beveloptions.h"
31 #include "ui/qg_blockdialog.h"
32 #include "ui/qg_cadtoolbar.h"
33 #include "ui/qg_circleoptions.h"
34 #include "ui/qg_commandwidget.h"
35 #include "ui/qg_coordinatewidget.h"
36 #include "ui/qg_dimlinearoptions.h"
37 #include "ui/qg_dimoptions.h"
38 #include "ui/qg_dlgarc.h"
39 #include "ui/qg_dlgattributes.h"
40 #include "ui/qg_dlgcircle.h"
41 #include "ui/qg_dlgdimension.h"
42 #include "ui/qg_dlgdimlinear.h"
43 #include "ui/qg_dlgellipse.h"
44 #include "ui/qg_dlghatch.h"
45 #include "ui/qg_dlginsert.h"
46 #include "ui/qg_dlgline.h"
47 #include "ui/qg_dlgmirror.h"
48 #include "ui/qg_dlgmove.h"
49 #include "ui/qg_dlgmoverotate.h"
50 #include "ui/qg_dlgoptionsdrawing.h"
51 #include "ui/qg_dlgoptionsgeneral.h"
52 #include "ui/qg_dlgpoint.h"
53 #include "ui/qg_dlgrotate.h"
54 #include "ui/qg_dlgrotate2.h"
55 #include "ui/qg_dlgscale.h"
56 #include "ui/qg_dlgspline.h"
57 #include "ui/qg_dlgtext.h"
58 #include "ui/qg_imageoptions.h"
59 #include "ui/qg_insertoptions.h"
60 #include "ui/qg_layerdialog.h"
61 #include "ui/qg_libraryinsertoptions.h"
62 #include "ui/qg_lineangleoptions.h"
63 #include "ui/qg_linebisectoroptions.h"
64 #include "ui/qg_lineoptions.h"
65 #include "ui/qg_lineparalleloptions.h"
66 #include "ui/qg_lineparallelthroughoptions.h"
67 #include "ui/qg_linepolygon2options.h"
68 #include "ui/qg_linepolygonoptions.h"
69 #include "ui/qg_linerelangleoptions.h"
70 #include "ui/qg_mousewidget.h"
71 #include "ui/qg_moverotateoptions.h"
72 #include "ui/qg_printpreviewoptions.h"
73 #include "ui/qg_roundoptions.h"
74 #include "ui/qg_selectionwidget.h"
75 #include "ui/qg_snapdistoptions.h"
76 #include "ui/qg_splineoptions.h"
77 #include "ui/qg_textoptions.h"
78 #include "ui/qg_trimamountoptions.h"
80 #include "arcoptions.h"
81 #include "arctangentialoptions.h"
82 #include "beveloptions.h"
83 #include "blockdialog.h"
84 #include "cadtoolbar.h"
85 #include "circleoptions.h"
86 #include "commandwidget.h"
87 #include "coordinatewidget.h"
88 #include "dimlinearoptions.h"
89 #include "dimoptions.h"
90 #include "dlgattributes.h"
91 #include "dlgoptionsdrawing.h"
92 #include "dlgoptionsgeneral.h"
94 #include "imageoptions.h"
95 #include "layerdialog.h"
96 #include "lineoptions.h"
97 #include "mousewidget.h"
98 #include "printpreviewoptions.h"
99 #include "selectionwidget.h"
100 #include "splineoptions.h"
101 #include "textoptions.h"
102 #include "trimamountoptions.h"
105 #include "qg_polylineoptions.h"
109 #include "rs_camdialog.h"
112 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
117 * @param parent Pointer to parent widget which can host dialogs.
118 * @param ow Pointer to widget that can host option widgets.
120 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
121 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
122 RS_DialogFactoryInterface()
124 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
126 this->parent = parent;
129 coordinateWidget = NULL;
131 selectionWidget = NULL;
133 commandWidget = NULL;
135 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
141 QG_DialogFactory::~QG_DialogFactory()
143 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
144 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
148 * Links factory to a widget that can host tool options.
150 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
151 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
153 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
155 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
159 * Links this dialog factory to a coordinate widget.
161 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
163 coordinateWidget = cw;
167 * Links this dialog factory to a mouse widget.
169 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
175 * Links this dialog factory to a selection widget.
177 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
179 selectionWidget = sw;
183 * Links this dialog factory to the cad tool bar.
185 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
191 * @return cad tool bar or NULL.
193 CadToolBar * QG_DialogFactory::getCadToolBar()
199 * Links this dialog factory to a command widget.
201 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
207 * @return command widget or NULL.
209 CommandWidget * QG_DialogFactory::getCommandWidget()
211 return commandWidget;
215 * Links the dialog factory to a main app window.
217 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
223 * Shows a message dialog.
225 void QG_DialogFactory::requestWarningDialog(const QString & warning)
227 QMessageBox::information(parent, QMessageBox::tr("Warning"),
228 warning, QMessageBox::Ok);
232 * Requests a new document from the main window.
234 RS_GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
236 if (mainWindow != NULL)
238 mainWindow->createNewDocument(fileName, doc);
239 return mainWindow->getGraphicView();
246 * Requests the simulation controls.
248 void QG_DialogFactory::requestSimulationControls()
250 if (mainWindow != NULL)
252 mainWindow->showSimulationControls();
257 * Shows a dialog for adding a layer. Doesn't add the layer.
258 * This is up to the caller.
260 * @return a pointer to the newly created layer that
263 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
265 RS_Layer * layer = NULL;
266 QString layer_name = "noname";
269 if (layerList != NULL)
271 while (layerList->find(layer_name) > 0)
272 layer_name.sprintf("noname%d", i++);
275 // Layer for parameter livery
276 layer = new RS_Layer(layer_name);
278 // QG_LayerDialog dlg(parent, "Layer Dialog");
279 LayerDialog dlg(parent);
281 dlg.setLayerList(layerList);
295 * Shows a dialog that asks the user if the selected layer
296 * can be removed. Doesn't remove the layer. This is up to the caller.
298 * @return a pointer to the layer that should be removed.
300 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
302 RS_Layer * layer = NULL;
304 if (layerList == NULL)
306 RS_DEBUG->print(RS_Debug::D_WARNING,
307 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
312 if (layerList==NULL) {
313 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
314 layerList = (RS_LayerList*)container;
320 // Layer for parameter livery
321 layer = layerList->getActive();
325 if (layer->getName() != "0")
327 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
328 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
329 QMessageBox::Ok, QMessageBox::Cancel);
341 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
342 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
351 * Shows a dialog for editing a layer. A new layer is created and
352 * returned. Modifying the layer is up to the caller.
354 * @return A pointer to a new layer with the changed attributes
355 * or NULL if the dialog was cancelled.
357 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
359 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
360 RS_Layer * layer = NULL;
362 if (layerList==NULL) {
363 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
364 layerList = (RS_LayerList*)container;
371 if (layerList == NULL)
373 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
374 "layerList is NULL");
378 // Layer for parameter livery
379 if (layerList->getActive() != NULL)
381 layer = new RS_Layer(*layerList->getActive());
383 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
384 LayerDialog dlg(parent);
386 dlg.setLayerList(layerList);
387 dlg.setEditLayer(true);
402 * Shows a dialog for adding a block. Doesn't add the block.
403 * This is up to the caller.
405 * @return a pointer to the newly created block that
408 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
410 //RS_Block* block = NULL;
412 ret = RS_BlockData("", Vector(false), false);
414 if (blockList == NULL)
416 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
417 "blockList is NULL");
421 // Block for parameter livery
422 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
424 BlockDialog dlg(parent);
425 dlg.setBlockList(blockList);
428 ret = dlg.getBlockData();
434 * Shows a dialog for renaming the currently active block.
436 * @return a pointer to the modified block or NULL on cancellation.
438 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
440 //RS_Block* block = NULL;
442 ret = RS_BlockData("", Vector(false), false);
444 if (blockList == NULL)
446 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
447 "blockList is NULL");
451 if (blockList==NULL) {
452 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
453 blockList = (RS_BlockList*)container;
459 // Block for parameter livery
460 //block = blockList->getActive();
462 BlockDialog dlg(parent);//WAS:, "Rename Block");
463 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
464 dlg.setWindowTitle(QObject::tr("Rename Block"));
465 dlg.setBlockList(blockList);
471 ret = dlg.getBlockData();
474 // ret = RS_BlockData("", Vector(false));
480 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
484 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
489 * Shows a dialog that asks the user if the selected block
490 * can be removed. Doesn't remove the block. This is up to the caller.
492 * @return a pointer to the block that should be removed.
494 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
496 RS_Block * block = NULL;
498 if (blockList == NULL)
500 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
501 "blockList is NULL");
505 // Block for parameter livery
506 block = blockList->getActive();
510 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
511 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
512 QMessageBox::Ok, QMessageBox::Cancel);
527 * Shows a dialog for choosing a file name. Saving the file is up to
530 * @return File name with path and extension to determine the file type
531 * or an empty string if the dialog was cancelled.
534 QString QG_DialogFactory::requestFileSaveAsDialog() {
535 // read default settings:
536 RS_SETTINGS->beginGroup("/Paths");
537 QString defDir = RS_SETTINGS->readEntry("/Save",
538 RS_SYSTEM->getHomeDir());
539 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
540 "Drawing Exchange (*.dxf)");
541 RS_SETTINGS->endGroup();
543 // prepare file save as dialog:
544 QFileDialog fileDlg(this,0,true);
550 filters.append("Drawing Exchange (*.dxf)");
551 filters.append("Font (*.cxf)");
552 fileDlg.setFilters(filters);
553 fileDlg.setMode(QFileDialog::AnyFile);
554 fileDlg.setCaption(tr("Save Drawing As"));
555 fileDlg.setDir(defDir);
556 fileDlg.setSelectedFilter(defFilter);
561 if (fileDlg.exec()==QDialog::Accepted) {
562 fn = fileDlg.selectedFile();
565 // append default extension:
566 if (fn.find('.')==-1) {
567 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
574 // overwrite warning:
575 if(QFileInfo(fn).exists()) {
577 QMessageBox::warning(this, tr("Save Drawing As"),
578 tr("%1 already exists.\n"
579 "Do you want to replace it?")
582 tr("Cancel"), 0, 1 );
605 // store new default settings:
607 RS_SETTINGS->beginGroup("/Paths");
608 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
609 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
610 RS_SETTINGS->endGroup();
618 * Shows a dialog for choosing a file name. Opening the file is up to
621 * @return File name with path and extension to determine the file type
622 * or an empty string if the dialog was cancelled.
624 QString QG_DialogFactory::requestImageOpenDialog()
628 // read default settings:
629 settings.beginGroup("Paths");
630 QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
631 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
636 // Q3FileDialog fileDlg(NULL, "", true);
637 QFileDialog fileDlg(NULL, "");
640 // Q3StrList f = QImageIO::inputFormats();
641 // QStringList formats = QStringList::fromStrList(f);
642 QList<QByteArray> f = QImageReader::supportedImageFormats();
643 QStringList formats = ???
645 #warning "Needs porting to Qt4... !!! FIX !!!"
650 //filters = QStringList::fromStrList(formats);
653 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
661 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
665 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
675 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
679 all += QString("*.%1").arg(QString(*it).lower());
684 filters.append(QObject::tr("All Image Files (%1)").arg(all));
685 filters.append(QObject::tr("All Files (*.*)"));
687 //filters.append("Drawing Exchange (*.)");
688 //filters.append("Font (*.cxf)");
690 fileDlg.setFilters(filters);
691 // fileDlg.setMode(Q3FileDialog::ExistingFile);
692 fileDlg.setFileMode(QFileDialog::ExistingFile);
693 // fileDlg.setCaption(QObject::tr("Open Image"));
694 fileDlg.setWindowTitle(QObject::tr("Open Image"));
695 // fileDlg.setDir(defDir);
696 fileDlg.setDirectory(defDir);
697 // fileDlg.setSelectedFilter(defFilter);
698 fileDlg.selectFilter(defFilter);
702 if (fileDlg.exec() == QDialog::Accepted)
704 // fn = fileDlg.selectedFile();
705 QStringList files = fileDlg.selectedFiles();
707 if (!files.isEmpty())
713 // store new default settings:
716 QStringList files = fileDlg.selectedFiles();
717 QString selected = "";
719 if (!files.isEmpty())
722 settings.beginGroup("Paths");
723 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
724 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
725 settings.setValue("ImageFilter", selected);
732 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
734 RS_DEBUG->print("QG_DialogFactory::requestOptions");
738 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
742 switch (action->rtti())
744 case RS2::ActionPrintPreview:
745 requestPrintPreviewOptions(action, on, update);
748 case RS2::ActionDrawLine:
749 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
750 requestLineOptions(action, on);
751 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
754 case RS2::ActionDrawPolyline:
755 requestPolylineOptions(action, on, update);
758 case RS2::ActionDrawLineAngle:
759 requestLineAngleOptions(action, on, update);
762 case RS2::ActionDrawLineParallel:
763 requestLineParallelOptions(action, on, update);
766 case RS2::ActionDrawLineParallelThrough:
767 requestLineParallelThroughOptions(action, on, update);
770 case RS2::ActionDrawLineBisector:
771 requestLineBisectorOptions(action, on, update);
774 case RS2::ActionDrawLineRelAngle:
775 requestLineRelAngleOptions(action, on, update);
778 case RS2::ActionDrawLinePolygon:
779 requestLinePolygonOptions(action, on, update);
782 case RS2::ActionDrawLinePolygon2:
783 requestLinePolygon2Options(action, on, update);
786 case RS2::ActionDrawArc:
787 requestArcOptions(action, on, update);
790 case RS2::ActionDrawArcTangential:
791 requestArcTangentialOptions(action, on, update);
794 case RS2::ActionDrawCircleCR:
795 requestCircleOptions(action, on, update);
798 case RS2::ActionDrawSpline:
799 requestSplineOptions(action, on, update);
802 case RS2::ActionDrawText:
803 requestTextOptions(action, on, update);
806 case RS2::ActionBlocksInsert:
807 requestInsertOptions(action, on, update);
810 case RS2::ActionDrawImage:
811 requestImageOptions(action, on, update);
814 case RS2::ActionDimAligned:
815 requestDimensionOptions(action, on, update);
818 case RS2::ActionDimLinear:
819 requestDimensionOptions(action, on, update);
821 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
822 requestDimLinearOptions(action, on, update);
826 case RS2::ActionDimRadial:
827 requestDimensionOptions(action, on, update);
830 case RS2::ActionDimDiametric:
831 requestDimensionOptions(action, on, update);
834 case RS2::ActionDimAngular:
835 requestDimensionOptions(action, on, update);
838 case RS2::ActionModifyTrimAmount:
839 requestTrimAmountOptions(action, on, update);
842 case RS2::ActionModifyMoveRotate:
843 requestMoveRotateOptions(action, on, update);
846 case RS2::ActionModifyBevel:
847 requestBevelOptions(action, on, update);
850 case RS2::ActionModifyRound:
851 requestRoundOptions(action, on, update);
854 case RS2::ActionLibraryInsert:
855 requestLibraryInsertOptions(action, on, update);
862 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
866 * Shows a widget for options for the action: "print preview"
868 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
870 static PrintPreviewOptions * toolWidget = NULL;
883 toolWidget = new PrintPreviewOptions(optionWidget);
884 toolWidget->setAction(action, update);
889 * Shows a widget for options for the action: "draw line"
891 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
894 The way I see it, this is failure. We're constantly creating & deleting
895 these objects all the time when we could create them once, and then reuse
896 them over and over. May need to do some more refactoring based on this idea...
899 static LineOptions * toolWidget = NULL;
904 // Get rid of the LineOptions object if it exists...
911 // Create a new one for the passed in action
914 toolWidget = new LineOptions(optionWidget);
915 toolWidget->setAction(action);
918 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
922 * Shows a widget for options for the action: "draw polyline"
924 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
927 static QG_PolylineOptions * toolWidget = NULL;
929 if (optionWidget != NULL)
931 if (toolWidget != NULL)
936 if (on && toolWidget == NULL)
938 toolWidget = new QG_PolylineOptions(optionWidget);
939 toolWidget->setAction(action, update);
947 * Shows a widget for options for the action: "draw line parallel"
949 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
951 static QG_LineParallelOptions* toolWidget = NULL;
953 if (optionWidget!=NULL) {
954 if (toolWidget!=NULL) {
958 if (on==true && toolWidget==NULL) {
959 toolWidget = new QG_LineParallelOptions(optionWidget);
960 toolWidget->setAction(action, update);
966 * Shows a widget for options for the action: "draw line parallel through"
968 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action,
969 bool on, bool update)
971 static QG_LineParallelThroughOptions* toolWidget = NULL;
973 if (optionWidget!=NULL) {
974 if (toolWidget!=NULL) {
978 if (on==true && toolWidget==NULL) {
979 toolWidget = new QG_LineParallelThroughOptions(optionWidget);
980 toolWidget->setAction(action, update);
986 * Shows a widget for options for the action: "line angle"
988 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action,
989 bool on, bool update)
991 static QG_LineAngleOptions* toolWidget = NULL;
993 if (optionWidget!=NULL) {
994 if (toolWidget!=NULL) {
998 if (on==true && toolWidget==NULL) {
999 toolWidget = new QG_LineAngleOptions(optionWidget);
1000 toolWidget->setAction(action, update);
1001 //toolWidget->setData(&angle, &length, fixedAngle, update);
1007 * Shows a widget for options for the action: "line relative angle"
1009 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action,
1010 bool on, bool update)
1012 static QG_LineRelAngleOptions* toolWidget = NULL;
1014 if (optionWidget!=NULL) {
1015 if (toolWidget!=NULL) {
1019 if (on==true && toolWidget==NULL) {
1020 toolWidget = new QG_LineRelAngleOptions(optionWidget);
1021 toolWidget->setAction(action, update);
1022 //toolWidget->setData(&angle, &length, fixedAngle, update);
1028 * Shows a widget for options for the action: "line angle"
1030 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action,
1031 bool on, bool update)
1033 static QG_LineBisectorOptions* toolWidget = NULL;
1035 if (optionWidget!=NULL) {
1036 if (toolWidget!=NULL) {
1040 if (on==true && toolWidget==NULL) {
1041 toolWidget = new QG_LineBisectorOptions(optionWidget);
1042 toolWidget->setAction(action, update);
1048 * Shows a widget for options for the action: "draw polygon"
1050 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action,
1051 bool on, bool update)
1053 static QG_LinePolygonOptions* toolWidget = NULL;
1055 if (optionWidget!=NULL) {
1056 if (toolWidget!=NULL) {
1060 if (on==true && toolWidget==NULL) {
1061 toolWidget = new QG_LinePolygonOptions(optionWidget);
1062 toolWidget->setAction(action, update);
1068 * Shows a widget for options for the action: "draw polygon2"
1070 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action,
1071 bool on, bool update)
1073 static QG_LinePolygon2Options* toolWidget = NULL;
1075 if (optionWidget!=NULL) {
1076 if (toolWidget!=NULL) {
1080 if (on==true && toolWidget==NULL) {
1081 toolWidget = new QG_LinePolygon2Options(optionWidget);
1082 toolWidget->setAction(action, update);
1088 * Shows a widget for insert options.
1090 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action,
1091 bool on, bool update)
1093 static QG_InsertOptions* toolWidget = NULL;
1095 if (optionWidget!=NULL) {
1096 if (toolWidget!=NULL) {
1100 if (on==true && toolWidget==NULL) {
1101 toolWidget = new QG_InsertOptions(optionWidget);
1102 toolWidget->setAction(action, update);
1108 * Shows a widget for image options.
1110 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action,
1111 bool on, bool update)
1113 static QG_ImageOptions* toolWidget = NULL;
1115 if (optionWidget!=NULL) {
1116 if (toolWidget!=NULL) {
1120 if (on==true && toolWidget==NULL) {
1121 toolWidget = new QG_ImageOptions(optionWidget);
1122 toolWidget->setAction(action, update);
1128 * Shows a widget for 'snap to a point with a given distance' options.
1130 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1132 static QG_SnapDistOptions* toolWidget = NULL;
1134 if (optionWidget!=NULL) {
1135 if (toolWidget!=NULL) {
1139 if (on==true && toolWidget==NULL) {
1140 toolWidget = new QG_SnapDistOptions(optionWidget);
1141 toolWidget->setDist(&dist);
1147 * Shows a widget for 'snap to a point with a given distance' options.
1149 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action,
1150 bool on, bool update)
1152 static QG_MoveRotateOptions* toolWidget = NULL;
1154 if (optionWidget!=NULL) {
1155 if (toolWidget!=NULL) {
1159 if (on==true && toolWidget==NULL) {
1160 toolWidget = new QG_MoveRotateOptions(optionWidget);
1161 toolWidget->setAction(action, update);
1167 * Shows a widget for rounding options.
1169 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action,
1170 bool on, bool update)
1172 static QG_RoundOptions* toolWidget = NULL;
1174 if (optionWidget!=NULL) {
1175 if (toolWidget!=NULL) {
1179 if (on==true && toolWidget==NULL) {
1180 toolWidget = new QG_RoundOptions(optionWidget);
1181 toolWidget->setAction(action, update);
1187 * Shows a widget for library insert options.
1189 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action,
1190 bool on, bool update)
1192 static QG_LibraryInsertOptions* toolWidget = NULL;
1194 if (optionWidget!=NULL) {
1195 if (toolWidget!=NULL) {
1199 if (on==true && toolWidget==NULL) {
1200 toolWidget = new QG_LibraryInsertOptions(optionWidget);
1201 toolWidget->setAction(action, update);
1206 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
1210 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action, bool on, bool update)
1214 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action, bool on, bool update)
1218 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action, bool on, bool update)
1222 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action, bool on, bool update)
1226 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action, bool on, bool update)
1230 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action, bool on, bool update)
1235 * Shows a widget for arc options.
1237 void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
1239 static ArcOptions * toolWidget = NULL;
1241 if (optionWidget != NULL)
1243 if (toolWidget != NULL)
1249 if (on && toolWidget == NULL)
1251 toolWidget = new ArcOptions(optionWidget);
1252 toolWidget->setAction(action, update);
1253 //toolWidget->setData(&data);
1259 * Shows a widget for tangential arc options.
1261 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
1263 static ArcTangentialOptions * toolWidget = NULL;
1276 toolWidget = new ArcTangentialOptions(optionWidget);
1277 toolWidget->setAction(action, update);
1278 //toolWidget->setData(&data);
1283 * Shows a widget for circle options.
1285 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
1287 static CircleOptions * toolWidget = NULL;
1297 if (on && toolWidget == NULL)
1299 toolWidget = new CircleOptions(optionWidget);
1300 toolWidget->setAction(action, update);
1306 * Shows a widget for spline options.
1308 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface * action, bool on, bool update)
1310 static SplineOptions * toolWidget = NULL;
1312 if (optionWidget!=NULL) {
1313 if (toolWidget!=NULL) {
1317 if (on==true && toolWidget==NULL) {
1318 toolWidget = new SplineOptions(optionWidget);
1319 toolWidget->setAction(action, update);
1325 * Shows a widget for text options.
1327 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1329 static TextOptions * toolWidget = NULL;
1342 toolWidget = new TextOptions(optionWidget);
1343 toolWidget->setAction(action, update);
1347 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action, bool on, bool update)
1351 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action, bool on, bool update)
1356 * Shows a widget for dimension options.
1358 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface * action, bool on, bool update)
1360 static DimOptions * toolWidget = NULL;
1362 if (optionWidget!=NULL) {
1363 if (toolWidget!=NULL) {
1367 if (on==true && toolWidget==NULL) {
1368 toolWidget = new DimOptions(optionWidget);
1369 toolWidget->setAction(action, update);
1375 * Shows a widget for linear dimension options.
1377 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface * action, bool on, bool update)
1379 static DimLinearOptions * toolWidget = NULL;
1392 toolWidget = new DimLinearOptions(optionWidget);
1393 toolWidget->setAction(action, update);
1397 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1401 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action, bool on, bool update)
1406 * Shows a widget for 'trim amount' options.
1408 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface * action, bool on, bool update)
1410 static TrimAmountOptions * toolWidget = NULL;
1423 toolWidget = new TrimAmountOptions(optionWidget);
1424 toolWidget->setAction(action, update);
1429 * Shows a widget for beveling options.
1431 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1433 static BevelOptions * toolWidget = NULL;
1435 if (optionWidget != NULL)
1437 if (toolWidget != NULL)
1443 if (on && toolWidget == NULL)
1445 toolWidget = new BevelOptions(optionWidget);
1446 toolWidget->setAction(action, update);
1451 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action, bool on, bool update)
1455 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action, bool on, bool update)
1461 * Shows the given toolbar.
1463 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1465 if (cadToolBar != NULL)
1466 cadToolBar->showToolBar(id);
1470 * Shows the select toolbar with the given action to launch.
1472 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1473 RS2::ActionType nextAction)
1475 if (cadToolBar != NULL)
1476 cadToolBar->showToolBarSelect(selectAction, nextAction);
1481 * Shows move options dialog presenting the given data.
1483 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1485 QG_DlgMove dlg(parent);
1498 * Shows rotate options dialog presenting the given data.
1500 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1502 QG_DlgRotate dlg(parent);
1515 * Shows scale options dialog presenting the given data.
1517 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1519 QG_DlgScale dlg(parent);
1532 * Shows mirror options dialog presenting the given data.
1534 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1536 QG_DlgMirror dlg(parent);
1549 * Shows move/rotate options dialog presenting the given data.
1551 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1553 QG_DlgMoveRotate dlg(parent);
1566 * Shows rotate around two centers options dialog presenting the given data.
1568 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1570 QG_DlgRotate2 dlg(parent);
1583 * Shows a dialog to edit the given entity.
1585 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1592 switch (entity->rtti())
1594 case RS2::EntityPoint:
1596 QG_DlgPoint dlg(parent);
1597 dlg.setPoint(*((RS_Point *)entity));
1607 case RS2::EntityLine:
1609 QG_DlgLine dlg(parent);
1610 dlg.setLine(*((RS_Line *)entity));
1620 case RS2::EntityArc:
1622 QG_DlgArc dlg(parent);
1623 dlg.setArc(*((RS_Arc *)entity));
1633 case RS2::EntityCircle:
1635 QG_DlgCircle dlg(parent);
1636 dlg.setCircle(*((RS_Circle *)entity));
1646 case RS2::EntityEllipse:
1648 QG_DlgEllipse dlg(parent);
1649 dlg.setEllipse(*((RS_Ellipse *)entity));
1653 dlg.updateEllipse();
1659 case RS2::EntitySpline:
1661 QG_DlgSpline dlg(parent);
1662 dlg.setSpline(*((RS_Spline *)entity));
1672 case RS2::EntityInsert:
1674 QG_DlgInsert dlg(parent);
1675 dlg.setInsert(*((RS_Insert *)entity));
1686 case RS2::EntityDimAligned:
1687 case RS2::EntityDimAngular:
1688 case RS2::EntityDimDiametric:
1689 case RS2::EntityDimRadial:
1691 QG_DlgDimension dlg(parent);
1692 dlg.setDim(*((RS_Dimension *)entity));
1698 ((RS_Dimension *)entity)->update(true);
1703 case RS2::EntityDimLinear:
1705 QG_DlgDimLinear dlg(parent);
1706 dlg.setDim(*((RS_DimLinear *)entity));
1712 ((RS_DimLinear *)entity)->update(true);
1717 case RS2::EntityText:
1719 QG_DlgText dlg(parent);
1720 dlg.setText(*((RS_Text *)entity), false);
1726 ((RS_Text *)entity)->update();
1731 case RS2::EntityHatch:
1733 QG_DlgHatch dlg(parent);
1734 dlg.setHatch(*((RS_Hatch *)entity), false);
1740 ((RS_Hatch *)entity)->update();
1753 * Shows a dialog to edit the attributes of the given dimension entity.
1756 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1761 QG_DlgDimAligned dlg(parent);
1762 dlg.setDim(*dim, true);
1773 * Shows a dialog to edit the attributes of the given text entity.
1775 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1780 QG_DlgText dlg(parent);
1781 dlg.setText(*text, true);
1793 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1795 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1800 RS_PATTERNLIST->init();
1802 QG_DlgHatch dlg(parent);
1803 dlg.setHatch(*hatch, true);
1815 * Shows attributes options dialog presenting the given data.
1817 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1819 DlgAttributes dlg(parent);
1820 dlg.setData(&data, layerList);
1831 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1836 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1841 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1846 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1851 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1856 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1862 * Shows a dialog to edit the given entity.
1864 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1871 switch (entity->rtti())
1873 //NOTE: These #if 0's are put here until these missing dialogs can be ported to Qt4.
1875 case RS2::EntityPoint:
1877 QG_DlgPoint dlg(parent);
1878 dlg.setPoint(*((RS_Point *)entity));
1888 case RS2::EntityLine:
1890 QG_DlgLine dlg(parent);
1891 dlg.setLine(*((RS_Line *)entity));
1901 case RS2::EntityArc:
1903 QG_DlgArc dlg(parent);
1904 dlg.setArc(*((RS_Arc *)entity));
1914 case RS2::EntityCircle:
1916 QG_DlgCircle dlg(parent);
1917 dlg.setCircle(*((RS_Circle *)entity));
1927 case RS2::EntityEllipse:
1929 QG_DlgEllipse dlg(parent);
1930 dlg.setEllipse(*((RS_Ellipse *)entity));
1934 dlg.updateEllipse();
1940 case RS2::EntitySpline:
1942 QG_DlgSpline dlg(parent);
1943 dlg.setSpline(*((RS_Spline *)entity));
1953 case RS2::EntityInsert:
1955 QG_DlgInsert dlg(parent);
1956 dlg.setInsert(*((RS_Insert *)entity));
1967 case RS2::EntityDimAligned:
1968 case RS2::EntityDimAngular:
1969 case RS2::EntityDimDiametric:
1970 case RS2::EntityDimRadial:
1972 QG_DlgDimension dlg(parent);
1973 dlg.setDim(*((RS_Dimension *)entity));
1979 ((RS_Dimension *)entity)->update(true);
1984 case RS2::EntityDimLinear:
1986 QG_DlgDimLinear dlg(parent);
1987 dlg.setDim(*((RS_DimLinear *)entity));
1993 ((RS_DimLinear *)entity)->update(true);
1999 case RS2::EntityText:
2001 DlgText dlg(parent);
2002 dlg.setText(*((RS_Text *)entity), false);
2008 ((RS_Text *)entity)->update();
2014 case RS2::EntityHatch:
2016 QG_DlgHatch dlg(parent);
2017 dlg.setHatch(*((RS_Hatch *)entity), false);
2023 ((RS_Hatch *)entity)->update();
2037 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
2043 * Shows a dialog to edit the attributes of the given text entity.
2045 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
2050 DlgText dlg(parent);
2051 dlg.setText(*text, true);
2062 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
2070 * Shows a dialog for CAM options.
2072 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
2074 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
2075 RS_CamDialog dlg(graphic, parent);
2076 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
2080 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
2084 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
2090 * Shows dialog for general application options.
2092 void QG_DialogFactory::requestOptionsGeneralDialog()
2094 DlgOptionsGeneral dlg(parent);
2099 * Shows dialog for drawing options.
2101 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
2103 DlgOptionsDrawing dlg(parent);
2104 dlg.setGraphic(&graphic);
2109 * Back to last menu in cad toolbar.
2111 void QG_DialogFactory::requestPreviousMenu()
2113 if (cadToolBar != NULL)
2114 cadToolBar->showToolBarMain();
2118 * Called whenever the mouse position changed.
2120 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
2121 const Vector & rel, bool updateFormat)
2123 if (coordinateWidget != NULL)
2124 coordinateWidget->setCoordinates(abs, rel, updateFormat);
2128 * Called when an action has a mouse hint.
2130 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
2132 if (mouseWidget != NULL)
2133 mouseWidget->setHelp(left, right);
2135 if (commandWidget != NULL)
2136 commandWidget->setCommand(left);
2140 * Called whenever the selection changed.
2142 void QG_DialogFactory::updateSelectionWidget(int num)
2144 if (selectionWidget != NULL)
2145 selectionWidget->setNumber(num);
2149 * Called when an action needs to communicate 'message' to the user.
2151 void QG_DialogFactory::commandMessage(const QString& message)
2153 RS_DEBUG->print("QG_DialogFactory::commandMessage");
2155 if (commandWidget != NULL)
2156 commandWidget->appendHistory(message);
2158 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
2161 /*virtual*/ bool QG_DialogFactory::isAdapter()
2167 * Converts an extension to a format description.
2168 * e.g. "PNG" to "Portable Network Graphic"
2171 * @return Format description
2173 QString QG_DialogFactory::extToFormat(const QString & ext)
2175 QString e = ext.toLower();
2178 return QObject::tr("Windows Bitmap");
2179 else if (e == "jpeg" || e == "jpg")
2180 return QObject::tr("Joint Photographic Experts Group");
2181 else if (e == "gif")
2182 return QObject::tr("Graphics Interchange Format");
2183 else if (e == "mng")
2184 return QObject::tr("Multiple-image Network Graphics");
2185 else if (e == "pbm")
2186 return QObject::tr("Portable Bit Map");
2187 else if (e == "pgm")
2188 return QObject::tr("Portable Grey Map");
2189 else if (e == "png")
2190 return QObject::tr("Portable Network Graphic");
2191 else if (e == "ppm")
2192 return QObject::tr("Portable Pixel Map");
2193 else if (e == "xbm")
2194 return QObject::tr("X Bitmap Format");
2195 else if (e == "xpm")
2196 return QObject::tr("X Pixel Map");
2198 return ext.toUpper();