[gegl-qt] Widgets: Add a options class for the view widgets



commit 5d360a6f137611c2ee0b9f0a7175301b687f0a85
Author: Jon Nordby <jononor gmail com>
Date:   Sun Jul 31 16:48:51 2011 +0200

    Widgets: Add a options class for the view widgets
    
    Will allow consumers to get access to the the view transformation et.c.
    A separate class was chosen because it allows to have the same interface
    for the different view widgets, and reuse the implementation.

 gegl-qt/gegl-qt.pro                  |    8 ++-
 gegl-qt/geglqtviewimplementation.cpp |   21 ++++++
 gegl-qt/geglqtviewimplementation.h   |    7 ++
 gegl-qt/geglqtviewoptions.cpp        |  119 ++++++++++++++++++++++++++++++++++
 gegl-qt/geglqtviewoptions.h          |   61 +++++++++++++++++
 5 files changed, 213 insertions(+), 3 deletions(-)
---
diff --git a/gegl-qt/gegl-qt.pro b/gegl-qt/gegl-qt.pro
index 071013e..05724c5 100644
--- a/gegl-qt/gegl-qt.pro
+++ b/gegl-qt/gegl-qt.pro
@@ -20,15 +20,17 @@ SOURCES += \
     geglqtview.cpp \
     geglqtviewimplementation.cpp \
     geglqtgraphicswidgetview.cpp \
-    geglqtdeclarativeview.cpp
+    geglqtdeclarativeview.cpp \
+    geglqtviewoptions.cpp
 
 PUBLIC_HEADERS = gegl-qt.h \
     geglqtview.h \
     geglqtgraphicswidgetview.h \
-    geglqtdeclarativeview.h
+    geglqtdeclarativeview.h \
+    geglqtviewoptions.h
 
 HEADERS += $$PUBLIC_HEADERS \
-    geglqtviewimplementation.h
+    geglqtviewimplementation.h \
 
 headers.path = $$GEGLQT_INSTALL_HEADERS/$$GEGLQT_LIBNAME
 headers.files = $$PUBLIC_HEADERS
diff --git a/gegl-qt/geglqtviewimplementation.cpp b/gegl-qt/geglqtviewimplementation.cpp
index ff26965..942e942 100644
--- a/gegl-qt/geglqtviewimplementation.cpp
+++ b/gegl-qt/geglqtviewimplementation.cpp
@@ -51,6 +51,7 @@ GeglQtViewImplementation::GeglQtViewImplementation(QObject *parent)
     , mInputNode(0)
     , processor(0)
     , timer(new QTimer())
+    , mOptions(new GeglQtViewOptions())
 {
     connect(timer, SIGNAL(timeout()), this, SLOT(processNode()));
 }
@@ -61,6 +62,7 @@ GeglQtViewImplementation::~GeglQtViewImplementation()
     if (processor) {
         gegl_processor_destroy(processor);
     }
+    delete mOptions;
 }
 
 void
@@ -89,6 +91,25 @@ GeglQtViewImplementation::inputNode() const
     return mInputNode;
 }
 
+GeglQtViewOptions *
+GeglQtViewImplementation::options() const
+{
+    return mOptions;
+}
+
+void
+GeglQtViewImplementation::setOptions(GeglQtViewOptions *newOptions)
+{
+    if (mOptions == newOptions) {
+        return;
+    }
+
+    /* FIXME: Don't take complete ownership of the options instance.
+     * Use refcounting instead? */
+    delete mOptions;
+    mOptions = newOptions ? newOptions : new GeglQtViewOptions();
+}
+
 /* An area in the GeglNode has been invalidated,
  * process it to compute the contents. */
 void
diff --git a/gegl-qt/geglqtviewimplementation.h b/gegl-qt/geglqtviewimplementation.h
index aaf47d2..439d952 100644
--- a/gegl-qt/geglqtviewimplementation.h
+++ b/gegl-qt/geglqtviewimplementation.h
@@ -21,6 +21,9 @@
 
 #include <Qt/QtGui>
 #include <gegl.h>
+#include "geglqtviewoptions.h"
+
+class GeglQtViewOptions;
 
 class GeglQtViewImplementation : public QObject
 {
@@ -32,6 +35,9 @@ public:
     void setInputNode(GeglNode *node);
     GeglNode *inputNode() const;
 
+    GeglQtViewOptions *options() const;
+    void setOptions(GeglQtViewOptions *newOptions);
+
     void paint(QPainter *painter, const QRect & viewRect);
 
 public: // Only public because invalidate_event and computed_event needs them.
@@ -48,6 +54,7 @@ private:
     GeglNode *mInputNode; // The node the widget displays.
     GeglProcessor *processor; // Used to process the GeglNode when invalidated.
     QTimer *timer; // Used to defer operations to the mainloop.
+    GeglQtViewOptions *mOptions;
 };
 
 #endif // GEGLQTVIEWIMPLEMENTATION_H
diff --git a/gegl-qt/geglqtviewoptions.cpp b/gegl-qt/geglqtviewoptions.cpp
new file mode 100644
index 0000000..f4d7c5d
--- /dev/null
+++ b/gegl-qt/geglqtviewoptions.cpp
@@ -0,0 +1,119 @@
+#include "geglqtviewoptions.h"
+
+/* This file is part of GEGL-QT
+ *
+ * GEGL-QT is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL-QT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL-QT; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Jon Nordby <jononor gmail com>
+ */
+
+#include <QtGui>
+
+struct GeglQtViewOptionsPrivate {
+    double translationX;
+    double translationY;
+    double scale;
+};
+
+/*
+  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? */
+
+GeglQtViewOptions::GeglQtViewOptions(QObject *parent)
+    : QObject(parent)
+    , priv(new GeglQtViewOptionsPrivate())
+{
+    setScale(1.0);
+    setTranslationX(0.0);
+    setTranslationY(0.0);
+}
+
+void
+GeglQtViewOptions::setScale(double newScale)
+{
+    if (priv->scale == newScale) {
+        return;
+    }
+    priv->scale = newScale;
+    Q_EMIT scaleChanged();
+    Q_EMIT transformationChanged();
+}
+
+double
+GeglQtViewOptions::scale()
+{
+    return priv->scale;
+}
+
+void
+GeglQtViewOptions::setTranslationX(double newTranslationX)
+{
+    if (priv->translationX == newTranslationX) {
+        return;
+    }
+    priv->translationX = newTranslationX;
+    Q_EMIT translationChanged();
+    Q_EMIT transformationChanged();
+}
+
+double
+GeglQtViewOptions::translationX()
+{
+    return priv->translationX;
+}
+
+void
+GeglQtViewOptions::setTranslationY(double newTranslationY)
+{
+    if (priv->translationY == newTranslationY) {
+        return;
+    }
+    priv->translationY = newTranslationY;
+    Q_EMIT translationChanged();
+    Q_EMIT transformationChanged();
+}
+
+double
+GeglQtViewOptions::translationY()
+{
+    return priv->translationY;
+}
+
+QTransform
+GeglQtViewOptions::transformation()
+{
+    QTransform transform;
+    transform.translate(translationX(), translationY());
+    transform.scale(scale(), scale());
+    return transform;
+}
diff --git a/gegl-qt/geglqtviewoptions.h b/gegl-qt/geglqtviewoptions.h
new file mode 100644
index 0000000..8a20676
--- /dev/null
+++ b/gegl-qt/geglqtviewoptions.h
@@ -0,0 +1,61 @@
+#ifndef GEGLVIEWOPTIONS_H
+#define GEGLVIEWOPTIONS_H
+
+/* This file is part of GEGL-QT
+ *
+ * GEGL-QT is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL-QT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL-QT; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Jon Nordby <jononor gmail com>
+ */
+
+#include <QtCore>
+
+class GeglQtViewOptionsPrivate;
+
+class GeglQtViewOptions : public QObject
+{
+    Q_OBJECT
+public:
+    explicit GeglQtViewOptions(QObject *parent = 0);
+
+public Q_SLOTS:
+    void setScale(double newScale);
+    void setTranslationX(double newTranslationX);
+    void setTranslationY(double newTranslationY);
+
+public:
+    double scale();
+    double translationX();
+    double translationY();
+    QTransform transformation();
+
+public:
+    Q_PROPERTY(double scale
+               READ scale WRITE setScale NOTIFY scaleChanged)
+    Q_PROPERTY(double translationX
+               READ translationX WRITE setTranslationX NOTIFY translationChanged)
+    Q_PROPERTY(double translationY
+               READ translationY WRITE setTranslationY NOTIFY translationChanged)
+
+Q_SIGNALS:
+    void translationChanged();
+    void scaleChanged();
+    void transformationChanged();
+
+private:
+    Q_DISABLE_COPY(GeglQtViewOptions)
+    GeglQtViewOptionsPrivate *priv;
+};
+
+#endif // GEGLVIEWOPTIONS_H



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