[gegl-qt] Examples: Add QWidget view transformation example
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-qt] Examples: Add QWidget view transformation example
- Date: Sun, 31 Jul 2011 17:43:56 +0000 (UTC)
commit e3530139cc28bec3263fd2251e8a556c8f22dd95
Author: Jon Nordby <jononor gmail com>
Date: Sun Jul 31 14:34:40 2011 +0200
Examples: Add QWidget view transformation example
examples/examples.pro | 7 ++-
examples/qwidget-transformations/.gitignore | 1 +
.../qwidget-transformations.cpp | 65 ++++++++++++++++++++
.../qwidget-transformations.pro | 8 +++
.../transformation-controls.cpp | 48 ++++++++++++++
.../transformation-controls.h | 25 ++++++++
6 files changed, 153 insertions(+), 1 deletions(-)
---
diff --git a/examples/examples.pro b/examples/examples.pro
index ae0315e..140b669 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -2,5 +2,10 @@
# TODO: install examples
TEMPLATE = subdirs
-SUBDIRS = qwidget-basic qgv-basic qml-basic qml-paint
+SUBDIRS = \
+ qwidget-basic \
+ qgv-basic \
+ qml-basic \
+ qml-paint \
+ qwidget-transformations \
diff --git a/examples/qwidget-transformations/.gitignore b/examples/qwidget-transformations/.gitignore
new file mode 100644
index 0000000..f93bad8
--- /dev/null
+++ b/examples/qwidget-transformations/.gitignore
@@ -0,0 +1 @@
+qwidget-transformations
diff --git a/examples/qwidget-transformations/qwidget-transformations.cpp b/examples/qwidget-transformations/qwidget-transformations.cpp
new file mode 100644
index 0000000..50f8564
--- /dev/null
+++ b/examples/qwidget-transformations/qwidget-transformations.cpp
@@ -0,0 +1,65 @@
+/* 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-qt.h>
+
+#include "transformation-controls.h"
+
+#include <QtGui/QApplication>
+#include <QtCore>
+
+int main(int argc, char *argv[])
+{
+ GeglNode *graph, *node;
+
+ 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 ();
+ node = gegl_node_new_child (graph,
+ "operation", "gegl:load",
+ "path", argv[argc-1], NULL);
+ gegl_node_process(node);
+
+ QWidget toplevelWidget;
+ QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom);
+ toplevelWidget.setLayout(layout);
+
+ GeglQtView *view = new GeglQtView();
+ view->setInputNode(node);
+ layout->addWidget(view, 1);
+
+ TransformationControls *controls = new TransformationControls();
+ GeglQtViewOptions *options = view->options();
+ controls->setViewOptionsInstance(options);
+ layout->addWidget(controls);
+
+ toplevelWidget.resize(600, 600);
+ toplevelWidget.show();
+
+ int retval = a.exec();
+ g_object_unref(graph);
+ gegl_exit();
+ return retval;
+}
diff --git a/examples/qwidget-transformations/qwidget-transformations.pro b/examples/qwidget-transformations/qwidget-transformations.pro
new file mode 100644
index 0000000..371e05e
--- /dev/null
+++ b/examples/qwidget-transformations/qwidget-transformations.pro
@@ -0,0 +1,8 @@
+include(../examples-common.pri)
+
+SOURCES += \
+ qwidget-transformations.cpp \
+ transformation-controls.cpp
+
+HEADERS += \
+ transformation-controls.h
diff --git a/examples/qwidget-transformations/transformation-controls.cpp b/examples/qwidget-transformations/transformation-controls.cpp
new file mode 100644
index 0000000..53b6ebe
--- /dev/null
+++ b/examples/qwidget-transformations/transformation-controls.cpp
@@ -0,0 +1,48 @@
+#include "transformation-controls.h"
+
+TransformationControls::TransformationControls(QWidget *parent) :
+ QWidget(parent)
+{
+ mViewOptions = 0;
+ buildUi();
+}
+
+/* */
+void
+TransformationControls::buildUi()
+{
+ QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom);
+ layout->addStretch(1);
+
+ // X translation
+ m_xSpinBox = new QDoubleSpinBox(this);
+ layout->addWidget(m_xSpinBox);
+
+ // Y translation
+ m_ySpinBox = new QDoubleSpinBox(this);
+ layout->addWidget(m_ySpinBox);
+
+ // Scale
+ m_scaleSpinBox = new QDoubleSpinBox(this);
+ layout->addWidget(m_scaleSpinBox);
+
+ this->setLayout(layout);
+}
+
+void
+TransformationControls::setViewOptionsInstance(GeglQtViewOptions *options)
+{
+ mViewOptions = options;
+
+ connect(m_xSpinBox, SIGNAL(valueChanged(double)),
+ mViewOptions, SLOT(setTranslationX(double)));
+ m_xSpinBox->setValue(10.0);
+
+ connect(m_ySpinBox, SIGNAL(valueChanged(double)),
+ mViewOptions, SLOT(setTranslationY(double)));
+ m_ySpinBox->setValue(10.0);
+
+ connect(m_scaleSpinBox, SIGNAL(valueChanged(double)),
+ mViewOptions, SLOT(setScale(double)));
+ m_scaleSpinBox->setValue(1.0);
+}
diff --git a/examples/qwidget-transformations/transformation-controls.h b/examples/qwidget-transformations/transformation-controls.h
new file mode 100644
index 0000000..6e353b5
--- /dev/null
+++ b/examples/qwidget-transformations/transformation-controls.h
@@ -0,0 +1,25 @@
+#ifndef TRANSFORMATIONCONTROLS_H
+#define TRANSFORMATIONCONTROLS_H
+
+#include <QtGui>
+
+#include "geglqtviewoptions.h"
+
+class TransformationControls : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit TransformationControls(QWidget *parent = 0);
+
+ void setViewOptionsInstance(GeglQtViewOptions *options);
+
+private:
+ void buildUi();
+private:
+ GeglQtViewOptions *mViewOptions;
+ QDoubleSpinBox *m_xSpinBox;
+ QDoubleSpinBox *m_ySpinBox;
+ QDoubleSpinBox *m_scaleSpinBox;
+};
+
+#endif // TRANSFORMATIONCONTROLS_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]