[gegl-qt] Examples: Example showing the AutoScale/AutoCenter view options



commit 3cdbe0c53dbc7a902e374c89d6deeaf418834b41
Author: Jon Nordby <jononor gmail com>
Date:   Mon Aug 1 00:56:29 2011 +0200

    Examples: Example showing the AutoScale/AutoCenter view options

 examples/examples.pro                              |    1 +
 examples/qwidget-autotransform/.gitignore          |    1 +
 .../autotransform-controls.cpp                     |   69 ++++++++++++++++++++
 .../qwidget-autotransform/autotransform-controls.h |   31 +++++++++
 .../qwidget-autotransform.cpp                      |   63 ++++++++++++++++++
 .../qwidget-autotransform.pro                      |    8 ++
 6 files changed, 173 insertions(+), 0 deletions(-)
---
diff --git a/examples/examples.pro b/examples/examples.pro
index 140b669..a38e2c9 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -8,4 +8,5 @@ SUBDIRS = \
     qml-basic \
     qml-paint \
     qwidget-transformations \
+    qwidget-autotransform \
 
diff --git a/examples/qwidget-autotransform/.gitignore b/examples/qwidget-autotransform/.gitignore
new file mode 100644
index 0000000..ecbcb47
--- /dev/null
+++ b/examples/qwidget-autotransform/.gitignore
@@ -0,0 +1 @@
+qwidget-autotransform
diff --git a/examples/qwidget-autotransform/autotransform-controls.cpp b/examples/qwidget-autotransform/autotransform-controls.cpp
new file mode 100644
index 0000000..30566b6
--- /dev/null
+++ b/examples/qwidget-autotransform/autotransform-controls.cpp
@@ -0,0 +1,69 @@
+#include "autotransform-controls.h"
+
+
+AutoTransformControls::AutoTransformControls(QWidget *parent) :
+    QWidget(parent)
+{
+    mViewOptions = 0;
+    buildUi();
+}
+
+/* */
+void
+AutoTransformControls::buildUi()
+{
+    QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom);
+    layout->addStretch(1);
+
+    m_autoCenterCheckBox = new QCheckBox("AutoCenter");
+    layout->addWidget(m_autoCenterCheckBox);
+
+    m_autoScaleCheckBox = new QCheckBox("AutoScale");
+    layout->addWidget(m_autoScaleCheckBox);
+
+    this->setLayout(layout);
+}
+
+void
+AutoTransformControls::setViewOptionsInstance(GeglQtViewOptions *options)
+{
+    mViewOptions = options;
+
+    connect(m_autoScaleCheckBox, SIGNAL(toggled(bool)),
+            this, SLOT(autoScaleChanged(bool)));
+    m_autoScaleCheckBox->setChecked(true);
+
+    connect(m_autoCenterCheckBox, SIGNAL(toggled(bool)),
+            this, SLOT(autoCenterChanged(bool)));
+    m_autoCenterCheckBox->setChecked(true);
+}
+
+void
+AutoTransformControls::autoCenterChanged(bool newValue)
+{
+    GeglQtViewOptions::AutoCenter autoCenter = newValue ?
+                GeglQtViewOptions::AutoCenterEnabled : GeglQtViewOptions::AutoCenterDisabled;
+
+    mViewOptions->setAutoCenterPolicy(autoCenter);
+
+    if (autoCenter == GeglQtViewOptions::AutoCenterDisabled) {
+        // To get a nice toggling effect, reset translation
+        // Otherwise the view would just have stayed where it is when autocentering is disabled.
+        mViewOptions->setTranslationX(0.0);
+        mViewOptions->setTranslationY(0.0);
+    }
+}
+
+void
+AutoTransformControls::autoScaleChanged(bool newValue)
+{
+    GeglQtViewOptions::AutoScale autoScale = newValue ?
+                GeglQtViewOptions::AutoScaleToView : GeglQtViewOptions::AutoScaleDisabled;
+    mViewOptions->setAutoScalePolicy(autoScale);
+
+    if (autoScale == GeglQtViewOptions::AutoScaleDisabled) {
+        // To get a nice toggling effect, reset scale
+        // Otherwise the view would just have stayed where it os when autoscale is disabled.
+        mViewOptions->setScale(1.0);
+    }
+}
diff --git a/examples/qwidget-autotransform/autotransform-controls.h b/examples/qwidget-autotransform/autotransform-controls.h
new file mode 100644
index 0000000..6b769d0
--- /dev/null
+++ b/examples/qwidget-autotransform/autotransform-controls.h
@@ -0,0 +1,31 @@
+#ifndef AUTOTRANSFORMCONTROLS_H
+#define AUTOTRANSFORMCONTROLS_H
+
+#include <QtGui>
+#include "geglqtviewoptions.h"
+
+class AutoTransformControls : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit AutoTransformControls(QWidget *parent = 0);
+
+    void setViewOptionsInstance(GeglQtViewOptions*);
+
+private Q_SLOTS:
+    void autoCenterChanged(bool newValue);
+    void autoScaleChanged(bool newValue);
+
+private:
+    void buildUi();
+
+private:
+    QCheckBox *m_autoCenterCheckBox;
+    QCheckBox *m_autoScaleCheckBox;
+    GeglQtViewOptions *mViewOptions;
+};
+
+
+
+
+#endif // AUTOTRANSFORMCONTROLS_H
diff --git a/examples/qwidget-autotransform/qwidget-autotransform.cpp b/examples/qwidget-autotransform/qwidget-autotransform.cpp
new file mode 100644
index 0000000..8a607a0
--- /dev/null
+++ b/examples/qwidget-autotransform/qwidget-autotransform.cpp
@@ -0,0 +1,63 @@
+/* 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 "autotransform-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);
+
+    AutoTransformControls *controls = new AutoTransformControls();
+    controls->setViewOptionsInstance(view->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-autotransform/qwidget-autotransform.pro b/examples/qwidget-autotransform/qwidget-autotransform.pro
new file mode 100644
index 0000000..1c328bf
--- /dev/null
+++ b/examples/qwidget-autotransform/qwidget-autotransform.pro
@@ -0,0 +1,8 @@
+include(../examples-common.pri)
+
+SOURCES += \
+    qwidget-autotransform.cpp \
+    autotransform-controls.cpp
+
+HEADERS += \
+    autotransform-controls.h



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