]> Shamusworld >> Repos - architektonas/blobdiff - src/widgets/qg_dialogfactory.cpp
Start of bringing back missing forms/dialogs
[architektonas] / src / widgets / qg_dialogfactory.cpp
index e267e6a3417678f75267381a025012d3b491d47c..632ce8dc174b21c78bfe7e92a1b79b77c58db9ea 100644 (file)
 
 #include "qg_dialogfactory.h"
 
+#include "qg_layerwidget.h"
+#include "qg_mainwindowinterface.h"
+#include "rs_actiondimlinear.h"
+#include "rs_actioninterface.h"
+#include "rs_document.h"
 #include "rs_patternlist.h"
 #include "settings.h"
 #include "rs_system.h"
-#include "rs_actioninterface.h"
-#include "rs_document.h"
-#include "rs_actiondimlinear.h"
+#include "rs_text.h"
 
 #if 0
-#include "ui/qg_arcoptions.h"
-#include "ui/qg_arctangentialoptions.h"
-#include "ui/qg_beveloptions.h"
+       #include "ui/qg_arcoptions.h"
+       #include "ui/qg_arctangentialoptions.h"
+       #include "ui/qg_beveloptions.h"
        #include "ui/qg_blockdialog.h"
        #include "ui/qg_cadtoolbar.h"
-#include "ui/qg_circleoptions.h"
+       #include "ui/qg_circleoptions.h"
        #include "ui/qg_commandwidget.h"
        #include "ui/qg_coordinatewidget.h"
 #include "ui/qg_dimlinearoptions.h"
        #include "ui/qg_textoptions.h"
 #include "ui/qg_trimamountoptions.h"
 #endif
+#include "arcoptions.h"
+#include "arctangentialoptions.h"
+#include "beveloptions.h"
 #include "blockdialog.h"
 #include "cadtoolbar.h"
+#include "circleoptions.h"
 #include "commandwidget.h"
 #include "coordinatewidget.h"
 #include "dlgattributes.h"
 #include "rs_camdialog.h"
 #endif
 
-#include "qg_layerwidget.h"
-#include "qg_mainwindowinterface.h"
-
 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
 
 /**
  * @param parent Pointer to parent widget which can host dialogs.
  * @param ow Pointer to widget that can host option widgets.
  */
-QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
+//QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
+QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
        RS_DialogFactoryInterface()
 {
        RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
@@ -138,7 +143,8 @@ QG_DialogFactory::~QG_DialogFactory()
 /**
  * Links factory to a widget that can host tool options.
  */
-/*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
+///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
+/*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
 {
        RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
        optionWidget = ow;
@@ -859,18 +865,19 @@ void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, b
 {
        static PrintPreviewOptions * toolWidget = NULL;
 
-       if (optionWidget != NULL)
+       if (!optionWidget)
+               return;
+
+       if (toolWidget)
        {
-               if (toolWidget != NULL)
-               {
-                       delete toolWidget;
-                       toolWidget = NULL;
-               }
-               if (on && toolWidget == NULL)
-               {
-                       toolWidget = new PrintPreviewOptions(optionWidget);
-                       toolWidget->setAction(action, update);
-               }
+               delete toolWidget;
+               toolWidget = NULL;
+       }
+
+       if (on)
+       {
+               toolWidget = new PrintPreviewOptions(optionWidget);
+               toolWidget->setAction(action, update);
        }
 }
 
@@ -879,21 +886,29 @@ void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, b
  */
 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
 {
+/*
+The way I see it, this is failure. We're constantly creating & deleting
+these objects all the time when we could create them once, and then reuse
+them over and over. May need to do some more refactoring based on this idea...
+*/
+       //ugh.
        static LineOptions * toolWidget = NULL;
 
-       if (optionWidget != NULL)
+       if (!optionWidget)
+               return;
+
+       // Get rid of the LineOptions object if it exists...
+       if (toolWidget)
        {
-               if (toolWidget != NULL)
-               {
-                       delete toolWidget;
-                       toolWidget = NULL;
-               }
+               delete toolWidget;
+               toolWidget = NULL;
+       }
 
-               if (on == true && toolWidget == NULL)
-               {
-                       toolWidget = new LineOptions(optionWidget);
-                       toolWidget->setAction(action);
-               }
+       // Create a new one for the passed in action
+       if (on)
+       {
+               toolWidget = new LineOptions(optionWidget);
+               toolWidget->setAction(action);
        }
 
        RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
@@ -1065,68 +1080,6 @@ void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action,
     }
 }
 
-/**
- * Shows a widget for arc options.
- */
-void QG_DialogFactory::requestArcOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_ArcOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_ArcOptions(optionWidget);
-            toolWidget->setAction(action, update);
-            //toolWidget->setData(&data);
-        }
-    }
-}
-
-/**
- * Shows a widget for tangential arc options.
- */
-void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_ArcTangentialOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_ArcTangentialOptions(optionWidget);
-            toolWidget->setAction(action, update);
-            //toolWidget->setData(&data);
-        }
-    }
-}
-
-/**
- * Shows a widget for arc options.
- */
-void QG_DialogFactory::requestCircleOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_CircleOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_CircleOptions(optionWidget);
-            toolWidget->setAction(action, update);
-        }
-    }
-}
-
 /**
  * Shows a widget for spline options.
  */
@@ -1147,26 +1100,6 @@ void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action,
     }
 }
 
-/**
- * Shows a widget for text options.
- */
-void QG_DialogFactory::requestTextOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_TextOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_TextOptions(optionWidget);
-            toolWidget->setAction(action, update);
-        }
-    }
-}
-
 /**
  * Shows a widget for insert options.
  */
@@ -1308,26 +1241,6 @@ void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action,
     }
 }
 
-/**
- * Shows a widget for beveling options.
- */
-void QG_DialogFactory::requestBevelOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_BevelOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_BevelOptions(optionWidget);
-            toolWidget->setAction(action, update);
-        }
-    }
-}
-
 /**
  * Shows a widget for rounding options.
  */
@@ -1396,16 +1309,75 @@ void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action, bo
 {
 }
 
-void QG_DialogFactory::requestArcOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for arc options.
+ */
+void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
 {
+       static ArcOptions * toolWidget = NULL;
+
+       if (optionWidget != NULL)
+       {
+               if (toolWidget != NULL)
+               {
+                       delete toolWidget;
+                       toolWidget = NULL;
+               }
+
+               if (on && toolWidget == NULL)
+               {
+                       toolWidget = new ArcOptions(optionWidget);
+                       toolWidget->setAction(action, update);
+                       //toolWidget->setData(&data);
+               }
+       }
 }
 
-void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for tangential arc options.
+ */
+void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
 {
+       static ArcTangentialOptions * toolWidget = NULL;
+
+       if (!optionWidget)
+               return;
+
+       if (toolWidget)
+       {
+               delete toolWidget;
+               toolWidget = NULL;
+       }
+
+       if (on)
+       {
+               toolWidget = new ArcTangentialOptions(optionWidget);
+               toolWidget->setAction(action, update);
+               //toolWidget->setData(&data);
+       }
 }
 
-void QG_DialogFactory::requestCircleOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for circle options.
+ */
+void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
 {
+    static CircleOptions * toolWidget = NULL;
+
+    if (optionWidget)
+       {
+        if (toolWidget)
+               {
+            delete toolWidget;
+            toolWidget = NULL;
+        }
+
+        if (on && toolWidget == NULL)
+               {
+            toolWidget = new CircleOptions(optionWidget);
+            toolWidget->setAction(action, update);
+        }
+    }
 }
 
 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action, bool on, bool update)
@@ -1419,19 +1391,19 @@ void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on,
 {
        static TextOptions * toolWidget = NULL;
 
-       if (optionWidget != NULL)
+       if (!optionWidget)
+               return;
+
+       if (toolWidget)
        {
-               if (toolWidget != NULL)
-               {
-                       delete toolWidget;
-                       toolWidget = NULL;
-               }
+               delete toolWidget;
+               toolWidget = NULL;
+       }
 
-               if (on == true && toolWidget == NULL)
-               {
-                       toolWidget = new TextOptions(optionWidget);
-                       toolWidget->setAction(action, update);
-               }
+       if (on)
+       {
+               toolWidget = new TextOptions(optionWidget);
+               toolWidget->setAction(action, update);
        }
 }
 
@@ -1463,8 +1435,27 @@ void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action, bool
 {
 }
 
-void QG_DialogFactory::requestBevelOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for beveling options.
+ */
+void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
 {
+    static BevelOptions * toolWidget = NULL;
+
+    if (optionWidget != NULL)
+       {
+        if (toolWidget != NULL)
+               {
+            delete toolWidget;
+            toolWidget = NULL;
+        }
+
+               if (on && toolWidget == NULL)
+               {
+            toolWidget = new BevelOptions(optionWidget);
+            toolWidget->setAction(action, update);
+        }
+    }
 }
 
 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action, bool on, bool update)
@@ -1877,9 +1868,179 @@ bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
        return false;
 }
 
+/**
+ * Shows a dialog to edit the given entity.
+ */
 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
 {
-       return false;
+       if (entity == NULL)
+               return false;
+
+       bool ret = false;
+
+       switch (entity->rtti())
+       {
+//NOTE: These #if 0's are put here until these missing dialogs can be ported to Qt4.
+#if 0
+       case RS2::EntityPoint:
+       {
+               QG_DlgPoint dlg(parent);
+               dlg.setPoint(*((RS_Point *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updatePoint();
+                       ret = true;
+               }
+       }
+               break;
+
+       case RS2::EntityLine:
+       {
+               QG_DlgLine dlg(parent);
+               dlg.setLine(*((RS_Line *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateLine();
+                       ret = true;
+               }
+       }
+               break;
+
+       case RS2::EntityArc:
+       {
+               QG_DlgArc dlg(parent);
+               dlg.setArc(*((RS_Arc *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateArc();
+                       ret = true;
+               }
+       }
+               break;
+
+       case RS2::EntityCircle:
+       {
+               QG_DlgCircle dlg(parent);
+               dlg.setCircle(*((RS_Circle *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateCircle();
+                       ret = true;
+               }
+       }
+               break;
+
+       case RS2::EntityEllipse:
+       {
+               QG_DlgEllipse dlg(parent);
+               dlg.setEllipse(*((RS_Ellipse *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateEllipse();
+                       ret = true;
+               }
+       }
+               break;
+
+       case RS2::EntitySpline:
+       {
+               QG_DlgSpline dlg(parent);
+               dlg.setSpline(*((RS_Spline *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateSpline();
+                       ret = true;
+               }
+       }
+               break;
+
+       case RS2::EntityInsert:
+       {
+               QG_DlgInsert dlg(parent);
+               dlg.setInsert(*((RS_Insert *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateInsert();
+                       ret = true;
+                       entity->update();
+               }
+       }
+               break;
+
+       case RS2::EntityDimAligned:
+       case RS2::EntityDimAngular:
+       case RS2::EntityDimDiametric:
+       case RS2::EntityDimRadial:
+       {
+               QG_DlgDimension dlg(parent);
+               dlg.setDim(*((RS_Dimension *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateDim();
+                       ret = true;
+                       ((RS_Dimension *)entity)->update(true);
+               }
+       }
+               break;
+
+       case RS2::EntityDimLinear:
+       {
+               QG_DlgDimLinear dlg(parent);
+               dlg.setDim(*((RS_DimLinear *)entity));
+
+               if (dlg.exec())
+               {
+                       dlg.updateDim();
+                       ret = true;
+                       ((RS_DimLinear *)entity)->update(true);
+               }
+       }
+               break;
+#endif
+
+       case RS2::EntityText:
+       {
+               DlgText dlg(parent);
+               dlg.setText(*((RS_Text *)entity), false);
+
+               if (dlg.exec())
+               {
+                       dlg.updateText();
+                       ret = true;
+                       ((RS_Text *)entity)->update();
+               }
+       }
+               break;
+
+#if 0
+       case RS2::EntityHatch:
+       {
+               QG_DlgHatch dlg(parent);
+               dlg.setHatch(*((RS_Hatch *)entity), false);
+
+               if (dlg.exec())
+               {
+                       dlg.updateHatch();
+                       ret = true;
+                       ((RS_Hatch *)entity)->update();
+               }
+       }
+               break;
+#endif
+
+       default:
+               break;
+       }
+
+       return ret;
 }
 
  /*
@@ -1918,7 +2079,7 @@ bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
 /**
  * Shows a dialog for CAM options.
  */
-bool QG_DialogFactory::requestCamOptionsDialog(RS_Graphic& graphic)
+bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
 {
        RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
        RS_CamDialog dlg(graphic, parent);
@@ -1947,7 +2108,7 @@ void QG_DialogFactory::requestOptionsGeneralDialog()
 /**
  * Shows dialog for drawing options.
  */
-void QG_DialogFactory::requestOptionsDrawingDialog(RS_Graphic & graphic)
+void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
 {
        DlgOptionsDrawing dlg(parent);
        dlg.setGraphic(&graphic);