[gegl-qt] Add gegl-qt4:display: gegl operation that displays node output in a window



commit df9d8730727b13057190256214d860ea4c252929
Author: Jon Nordby <jononor gmail com>
Date:   Tue Aug 2 00:01:06 2011 +0200

    Add gegl-qt4:display: gegl operation that displays node output in a window

 config.pri                                       |   12 ++-
 examples/display-operation/.gitignore            |    1 +
 examples/display-operation/display-operation.cpp |   52 ++++++++++
 examples/display-operation/display-operation.pro |   12 +++
 examples/examples.pro                            |    2 +-
 gegl-qt.pro                                      |    2 +-
 operations/geglqtdisplay.cpp                     |  111 ++++++++++++++++++++++
 operations/operations.pro                        |   23 +++++
 8 files changed, 212 insertions(+), 3 deletions(-)
---
diff --git a/config.pri b/config.pri
index 026c320..c37c55e 100644
--- a/config.pri
+++ b/config.pri
@@ -1,7 +1,11 @@
 
 GEGLQT_API_VERSION = 0.1
 GEGLQT_VERSION = 0.0.1
-GEGLQT_LIBNAME = gegl-qt4-$$GEGLQT_API_VERSION
+GEGLQT_BASELIBNAME = gegl-qt4
+GEGLQT_LIBNAME = $$GEGLQT_BASELIBNAME-$$GEGLQT_API_VERSION
+
+OBJECTS_DIR = .obj
+MOC_DIR = .moc
 
 # Can be used to specify custom install prefix
 isEmpty(GEGLQT_INSTALL_PREFIX) {
@@ -9,6 +13,12 @@ isEmpty(GEGLQT_INSTALL_PREFIX) {
 }
 
 # Paths for installing files
+GEGL_LIBDIR = $$system(pkg-config --variable libdir gegl)
+GEGL_INSTALL_OPERATIONS = $$system(pkg-config --variable pluginsdir gegl)
+isEmpty(GEGL_INSTALL_OPERATIONS) {
+    GEGL_INSTALL_OPERATIONS = $$GEGL_LIBDIR/gegl-0.1/
+}
+
 GEGLQT_INSTALL_BIN = $$GEGLQT_INSTALL_PREFIX/bin
 GEGLQT_INSTALL_HEADERS = $$GEGLQT_INSTALL_PREFIX/include
 GEGLQT_INSTALL_LIBS = $$GEGLQT_INSTALL_PREFIX/lib
diff --git a/examples/display-operation/.gitignore b/examples/display-operation/.gitignore
new file mode 100644
index 0000000..af833c2
--- /dev/null
+++ b/examples/display-operation/.gitignore
@@ -0,0 +1 @@
+display-operation
diff --git a/examples/display-operation/display-operation.cpp b/examples/display-operation/display-operation.cpp
new file mode 100644
index 0000000..40cc91c
--- /dev/null
+++ b/examples/display-operation/display-operation.cpp
@@ -0,0 +1,52 @@
+/* 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 <jononor gmail com>
+ */
+
+#include <gegl.h>
+
+#include <QtGui/QApplication>
+#include <QtCore>
+
+int main(int argc, char *argv[])
+{
+    GeglNode *graph, *load, *display;
+
+    QApplication a(argc, argv);
+    gegl_init(&argc, &argv);
+
+    if (argc < 2) {
+        QTextStream(stdout) << "Usage: " << argv[0] << " [options] FILE\n";
+        exit(1);
+    }
+
+    // Build a Gegl graph that loads a file
+    graph = gegl_node_new ();
+    load = gegl_node_new_child (graph,
+      "operation", "gegl:load",
+      "path", argv[argc-1], NULL);
+    display = gegl_node_new_child (graph,
+      "operation", "gegl-qt4:display", NULL);
+    gegl_node_link_many (load, display, NULL);
+
+    gegl_node_process(display);
+
+    const int retval = a.exec();
+
+    g_object_unref(graph);
+    gegl_exit();
+    return retval;
+}
diff --git a/examples/display-operation/display-operation.pro b/examples/display-operation/display-operation.pro
new file mode 100644
index 0000000..81b62de
--- /dev/null
+++ b/examples/display-operation/display-operation.pro
@@ -0,0 +1,12 @@
+SOURCES += display-operation.cpp
+
+QT += core gui declarative
+
+CONFIG += qt
+
+OBJECTS_DIR = .obj
+MOC_DIR = .moc
+
+# Does not link against gegl-qt as it is not used directly
+CONFIG += link_pkgconfig
+PKGCONFIG += gegl
diff --git a/examples/examples.pro b/examples/examples.pro
index a38e2c9..c6c68c3 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -9,4 +9,4 @@ SUBDIRS = \
     qml-paint \
     qwidget-transformations \
     qwidget-autotransform \
-
+    display-operation \
diff --git a/gegl-qt.pro b/gegl-qt.pro
index d6f9c3b..c68ecb9 100644
--- a/gegl-qt.pro
+++ b/gegl-qt.pro
@@ -1,6 +1,6 @@
 
 TEMPLATE = subdirs
 CONFIG += ordered
-SUBDIRS = gegl-qt examples tests
+SUBDIRS = gegl-qt operations examples tests
 
 !system(pkg-config --exists gegl):error("Could not find gegl")
diff --git a/operations/geglqtdisplay.cpp b/operations/geglqtdisplay.cpp
new file mode 100644
index 0000000..cbe9c01
--- /dev/null
+++ b/operations/geglqtdisplay.cpp
@@ -0,0 +1,111 @@
+/* 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>
+ */
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_string  (window_title, "Window Title", "", "Title to give window.")
+
+#else
+
+#define GEGL_CHANT_TYPE_SINK
+#define GEGL_CHANT_C_FILE   "geglqtdisplay.cpp"
+
+#include <gegl.h>
+#include <gegl-chant.h>
+
+#include <QtGui>
+#include <gegl-qt.h>
+
+typedef struct
+{
+  GeglQtView *viewWidget;
+  GeglNode *node;
+} Priv;
+
+
+static Priv *
+init_priv (GeglOperation *operation)
+{
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+
+  if (!o->chant_data)
+    {
+      Priv *priv = g_new0 (Priv, 1);
+      o->chant_data = (void*) priv;
+
+      priv->viewWidget = new GeglQtView();
+      priv->viewWidget->options()->setAutoScalePolicy(GeglQtViewOptions::AutoScaleViewport);
+      priv->viewWidget->show();
+    }
+  return (Priv*)(o->chant_data);
+}
+
+
+static void
+attach (GeglOperation *operation)
+{
+  Priv       *priv = init_priv (operation);
+
+  GeglNode *input = gegl_node_get_input_proxy (operation->node, "input");
+  priv->node = gegl_node_new_child (operation->node,
+                                    "operation", "gegl:nop",
+                                    NULL);
+
+  gegl_node_link (input, priv->node);
+  priv->viewWidget->setInputNode(priv->node);
+}
+
+static void
+dispose (GObject *object)
+{
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (object);
+  Priv       *priv = (Priv*)o->chant_data;
+
+  if (priv)
+    {
+      // Destroy priv
+      delete priv->viewWidget;
+      priv->viewWidget = 0;
+
+      g_object_unref(priv->node);
+
+      o->chant_data = NULL;
+    }
+
+  G_OBJECT_CLASS (g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)))->dispose (object);
+}
+
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+  GeglOperationClass     *operation_class;
+  GeglOperationSinkClass *sink_class;
+
+  operation_class = GEGL_OPERATION_CLASS (klass);
+  sink_class      = GEGL_OPERATION_SINK_CLASS (klass);
+
+  operation_class->attach = attach;
+  G_OBJECT_CLASS (klass)->dispose = dispose;
+
+  operation_class->name        = "gegl-qt4:display";
+  operation_class->categories  = "output";
+  operation_class->description = "Displays the input buffer in a Qt window.";
+}
+
+#endif
diff --git a/operations/operations.pro b/operations/operations.pro
new file mode 100644
index 0000000..a30f429
--- /dev/null
+++ b/operations/operations.pro
@@ -0,0 +1,23 @@
+
+include(../config.pri)
+
+TARGET = $$GEGLQT_BASELIBNAME-display
+target.path = $$GEGL_INSTALL_OPERATIONS
+TEMPLATE = lib
+CONFIG += qt no_keywords plugin
+
+VERSION = $$GEGLQT_VERSION
+
+QT += core gui declarative
+
+CONFIG += link_pkgconfig
+PKGCONFIG += gegl
+
+INCLUDEPATH += ../gegl-qt
+LIBS += -L../gegl-qt -l$$GEGLQT_LIBNAME
+
+SOURCES += \
+    geglqtdisplay.cpp \
+
+INSTALLS += target
+



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