[gegl-qt] Widgets: Add AutoScale/AutoCenter view options.



commit 2932bd2778f431a6b20ea8b70df867a32a019447
Author: Jon Nordby <jononor gmail com>
Date:   Sun Jul 31 21:57:33 2011 +0200

    Widgets: Add AutoScale/AutoCenter view options.
    
    Currently does not do anything.

 gegl-qt/geglqtviewoptions.cpp |   68 ++++++++++++++++++++++++++++++++---------
 gegl-qt/geglqtviewoptions.h   |   20 ++++++++++++
 2 files changed, 73 insertions(+), 15 deletions(-)
---
diff --git a/gegl-qt/geglqtviewoptions.cpp b/gegl-qt/geglqtviewoptions.cpp
index f4d7c5d..7aad52d 100644
--- a/gegl-qt/geglqtviewoptions.cpp
+++ b/gegl-qt/geglqtviewoptions.cpp
@@ -24,31 +24,38 @@ struct GeglQtViewOptionsPrivate {
     double translationX;
     double translationY;
     double scale;
+    GeglQtViewOptions::AutoCenter autoCenter;
+    GeglQtViewOptions::AutoScale autoScale;
 };
 
 /*
   TODO: support more options
 
   double rotation;
-  GeglQtViewOptions::AutoCenter autoCenter;
-  GeglQtViewOptions::AutoScale autoScale;
-
-enum AutoCenter {
-    AutoCenterDisabled,
-    AutoCenterEnabled
-};
-
-enum AutoScale {
-    AutoScaleDisabled,
-    AutoScaleToView,
-    AutoScaleToViewIgnoreAspectRatio,
-    AutoScaleView
-};
 */
 
 
 /* FIXME: find a better name? */
-
+/* TODO: evaluate what is the best behavior when the Auto options are enabled,
+ * and trying to use the manual setters as well.
+ *
+ * Currently enabling autoCenter/autoScaling means that
+ * - The view implementation will change the scale/translation values
+ * - Using the manual setters will set the value, but it will be overwritten as soon
+ * the auto value update is triggered (by viewport/model changes, et.c)
+ *
+ * A challenge is that GeglQtViewImplementation should still be able to set the values
+ * when autocenter/autoscale is enabled.
+ *
+ * Possible behaviors include
+ * 0. Ignoring values from explicit setters
+ * Suprising that when toggling auto enable/disable, the previously manually set values will be gone?
+ * 1. Setting scale/translation manually will quit auto mode.
+ * Could be suprising if one accidentically calls it?
+ * 2. Allowing one to set scale/translation manually, but they are overridden when auto mode is on
+ * Suprising that calling setSomething(), and then something() would not return the same value;
+ * or that scale() returns a different value from the current transformation (and that transformation() indicates)
+ */
 GeglQtViewOptions::GeglQtViewOptions(QObject *parent)
     : QObject(parent)
     , priv(new GeglQtViewOptionsPrivate())
@@ -117,3 +124,34 @@ GeglQtViewOptions::transformation()
     transform.scale(scale(), scale());
     return transform;
 }
+
+
+void
+GeglQtViewOptions::setAutoCenterPolicy(AutoCenter newAutoCenter)
+{
+    if (priv->autoCenter == newAutoCenter) {
+        return;
+    }
+    priv->autoCenter = newAutoCenter;
+}
+
+void
+GeglQtViewOptions::setAutoScalePolicy(AutoScale newAutoScale)
+{
+    if (priv->autoScale == newAutoScale) {
+        return;
+    }
+    priv->autoScale = newAutoScale;
+}
+
+GeglQtViewOptions::AutoCenter
+GeglQtViewOptions::autoCenterPolicy()
+{
+    return priv->autoCenter;
+}
+
+GeglQtViewOptions::AutoScale
+GeglQtViewOptions::autoScalePolicy()
+{
+    return priv->autoScale;
+}
diff --git a/gegl-qt/geglqtviewoptions.h b/gegl-qt/geglqtviewoptions.h
index 8a20676..bb27bce 100644
--- a/gegl-qt/geglqtviewoptions.h
+++ b/gegl-qt/geglqtviewoptions.h
@@ -26,20 +26,40 @@ class GeglQtViewOptionsPrivate;
 class GeglQtViewOptions : public QObject
 {
     Q_OBJECT
+
 public:
     explicit GeglQtViewOptions(QObject *parent = 0);
 
+public:
+    enum AutoCenter {
+      AutoCenterDisabled,
+      AutoCenterEnabled
+    };
+
+    enum AutoScale {
+      AutoScaleDisabled,
+      AutoScaleToView,
+      AutoScaleToViewIgnoreAspectRatio,
+      AutoScaleViewport
+    };
+
 public Q_SLOTS:
     void setScale(double newScale);
     void setTranslationX(double newTranslationX);
     void setTranslationY(double newTranslationY);
 
+    void setAutoCenterPolicy(AutoCenter newAutoCenter);
+    void setAutoScalePolicy(AutoScale newAutoScale);
+
 public:
     double scale();
     double translationX();
     double translationY();
     QTransform transformation();
 
+    AutoCenter autoCenterPolicy();
+    AutoScale autoScalePolicy();
+
 public:
     Q_PROPERTY(double scale
                READ scale WRITE setScale NOTIFY scaleChanged)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]