[gegl-qt] Widgets: Add support for AutoScaleViewport option.



commit cb056fd515875fed37b775a35195c2215a9e0816
Author: Jon Nordby <jononor gmail com>
Date:   Mon Aug 1 23:59:26 2011 +0200

    Widgets: Add support for AutoScaleViewport option.
    
    Untested.

 gegl-qt/geglqtdeclarativeview.cpp    |   10 ++++++++++
 gegl-qt/geglqtdeclarativeview.h      |    1 +
 gegl-qt/geglqtgraphicswidgetview.cpp |    8 ++++++++
 gegl-qt/geglqtgraphicswidgetview.h   |    2 ++
 gegl-qt/geglqtview.cpp               |    8 ++++++++
 gegl-qt/geglqtview.h                 |    1 +
 gegl-qt/geglqtviewimplementation.cpp |   13 +++++++++----
 gegl-qt/geglqtviewimplementation.h   |    1 +
 8 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/gegl-qt/geglqtdeclarativeview.cpp b/gegl-qt/geglqtdeclarativeview.cpp
index 8b3fd50..c61bbae 100644
--- a/gegl-qt/geglqtdeclarativeview.cpp
+++ b/gegl-qt/geglqtdeclarativeview.cpp
@@ -9,6 +9,8 @@ GeglQtDeclarativeView::GeglQtDeclarativeView(QDeclarativeItem *parent)
 
     connect(priv, SIGNAL(viewAreaChanged(QRectF)),
             this, SLOT(invalidate(QRectF)));
+    connect(priv, SIGNAL(viewportSizeRequest(QSizeF)),
+            this, SLOT(viewportSizeChangeRequested(QSizeF)));
 }
 
 GeglQtDeclarativeView::~GeglQtDeclarativeView()
@@ -52,6 +54,14 @@ GeglQtDeclarativeView::invalidate(QRectF rect)
 }
 
 void
+GeglQtDeclarativeView::viewportSizeChangeRequested(QSizeF requestedSize)
+{
+    // XXX: Is this the correct way to do it?
+    setImplicitHeight(requestedSize.height());
+    setImplicitWidth(requestedSize.width());
+}
+
+void
 GeglQtDeclarativeView::paint(QPainter *painter,
                              const QStyleOptionGraphicsItem *option,
                              QWidget *widget)
diff --git a/gegl-qt/geglqtdeclarativeview.h b/gegl-qt/geglqtdeclarativeview.h
index 01d0001..38bffdd 100644
--- a/gegl-qt/geglqtdeclarativeview.h
+++ b/gegl-qt/geglqtdeclarativeview.h
@@ -32,6 +32,7 @@ Q_SIGNALS:
 
 private Q_SLOTS:
     void invalidate(QRectF rect);
+    void viewportSizeChangeRequested(QSizeF);
 
 private:
     GeglQtViewImplementation *priv;
diff --git a/gegl-qt/geglqtgraphicswidgetview.cpp b/gegl-qt/geglqtgraphicswidgetview.cpp
index ea81622..c30d736 100644
--- a/gegl-qt/geglqtgraphicswidgetview.cpp
+++ b/gegl-qt/geglqtgraphicswidgetview.cpp
@@ -25,6 +25,8 @@ GeglQtGraphicsWidgetView::GeglQtGraphicsWidgetView(QGraphicsItem * parent)
 {
     connect(priv, SIGNAL(viewAreaChanged(QRectF)),
             this, SLOT(invalidate(QRectF)));
+    connect(priv, SIGNAL(viewportSizeRequest(QSizeF)),
+            this, SLOT(viewportSizeChangeRequested(QSizeF)));
 
     connect(this, SIGNAL(geometryChanged()),
             this, SLOT(handleGeometryChange));
@@ -68,6 +70,12 @@ GeglQtGraphicsWidgetView::invalidate(QRectF rect)
 }
 
 void
+GeglQtGraphicsWidgetView::viewportSizeChangeRequested(QSizeF requestedSize)
+{
+    resize(requestedSize);
+}
+
+void
 GeglQtGraphicsWidgetView::paint(QPainter *painter,
                                 const QStyleOptionGraphicsItem *option,
                                 QWidget *widget)
diff --git a/gegl-qt/geglqtgraphicswidgetview.h b/gegl-qt/geglqtgraphicswidgetview.h
index 11e63a5..a03329d 100644
--- a/gegl-qt/geglqtgraphicswidgetview.h
+++ b/gegl-qt/geglqtgraphicswidgetview.h
@@ -43,6 +43,8 @@ public:
 
 private Q_SLOTS:
     void invalidate(QRectF rect);
+    void viewportSizeChangeRequested(QSizeF);
+
     void handleGeometryChange();
 
 private:
diff --git a/gegl-qt/geglqtview.cpp b/gegl-qt/geglqtview.cpp
index 5087f28..1fbbadc 100644
--- a/gegl-qt/geglqtview.cpp
+++ b/gegl-qt/geglqtview.cpp
@@ -39,6 +39,8 @@ GeglQtView::GeglQtView(QWidget *parent)
 {
     connect(priv, SIGNAL(viewAreaChanged(QRectF)),
             this, SLOT(invalidate(QRectF)));
+    connect(priv, SIGNAL(viewportSizeRequest(QSizeF)),
+            this, SLOT(viewportSizeChangeRequested(QSizeF)));
 }
 
 GeglQtView::~GeglQtView()
@@ -76,6 +78,12 @@ GeglQtView::invalidate(QRectF rect)
     }
 }
 
+void
+GeglQtView::viewportSizeChangeRequested(QSizeF requestedSize)
+{
+    resize(requestedSize.toSize());
+}
+
 //! \brief Draw the view of GeglNode onto the widget
 void
 GeglQtView::paintEvent(QPaintEvent *event)
diff --git a/gegl-qt/geglqtview.h b/gegl-qt/geglqtview.h
index 09fd536..c5ead41 100644
--- a/gegl-qt/geglqtview.h
+++ b/gegl-qt/geglqtview.h
@@ -47,6 +47,7 @@ public:
 
 private Q_SLOTS:
     void invalidate(QRectF rect);
+    void viewportSizeChangeRequested(QSizeF);
 
 private:
     Q_DISABLE_COPY(GeglQtView)
diff --git a/gegl-qt/geglqtviewimplementation.cpp b/gegl-qt/geglqtviewimplementation.cpp
index f6eda1e..7dc6dde 100644
--- a/gegl-qt/geglqtviewimplementation.cpp
+++ b/gegl-qt/geglqtviewimplementation.cpp
@@ -189,12 +189,17 @@ GeglQtViewImplementation::updateAutoCenterScale()
         options()->setScale(options()->scale()*(1.0/maxRatio));
 
     } else if (options()->autoScalePolicy() == GeglQtViewOptions::AutoScaleViewport) {
-        // TODO: emit a viewportChangeRequest(QSize) signal that widgets catch
-        // and then resize themselves after.
-        qDebug() << __PRETTY_FUNCTION__ << "GeglQtViewOptions::AutoScaleViewport is currently not supported.";
+        // Reset transformation, and request that the widget changes its viewport size to fit the model
+        options()->setScale(1.0);
+        options()->setTranslationX(0.0);
+        options()->setTranslationY(0.0);
+
+        GeglRectangle bbox = gegl_node_get_bounding_box(inputNode());
+        Q_EMIT viewportSizeRequest(QSizeF(bbox.width, bbox.height));
     }
 
-    if (options()->autoCenterPolicy() == GeglQtViewOptions::AutoCenterEnabled) {
+    if (options()->autoCenterPolicy() == GeglQtViewOptions::AutoCenterEnabled
+        && options()->autoScalePolicy() != GeglQtViewOptions::AutoScaleViewport) {
         // Set translation such that the center of the model is center of the viewport
         GeglRectangle bbox = gegl_node_get_bounding_box(inputNode());
         QPointF modelCenter(bbox.width/2.0, bbox.height/2.0);
diff --git a/gegl-qt/geglqtviewimplementation.h b/gegl-qt/geglqtviewimplementation.h
index 9efbdd8..2bde222 100644
--- a/gegl-qt/geglqtviewimplementation.h
+++ b/gegl-qt/geglqtviewimplementation.h
@@ -49,6 +49,7 @@ public: // Only public because invalidate_event and computed_event needs them.
 
 Q_SIGNALS:
     void viewAreaChanged(QRectF area);
+    void viewportSizeRequest(QSizeF requestedSize);
 
 private Q_SLOTS:
     void processNode();



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