diff panner.cpp @ 113:5fc7b4fc77a8

* Better error handling/reporting; some futile changes to termios handling; avoid weirdly stretching panned view in panner
author Chris Cannam
date Fri, 26 Nov 2010 21:04:40 +0000
parents b0a90ac84b8b
children 2550aaa09240
line wrap: on
line diff
--- a/panner.cpp	Fri Nov 26 17:02:55 2010 +0000
+++ b/panner.cpp	Fri Nov 26 21:04:40 2010 +0000
@@ -17,6 +17,7 @@
 
 #include "panner.h"
 #include "panned.h"
+#include "debug.h"
 
 #include <QPolygon>
 #include <QMouseEvent>
@@ -42,6 +43,26 @@
 }
 
 void
+Panner::fit(QRectF r)
+{
+    Qt::AspectRatioMode m = Qt::IgnoreAspectRatio;
+    if (height() > width()) {
+        // Our panner is vertical; if the source is not tall,
+        // don't stretch it to fit in the height, it'd look weird
+        if (r.height() < height() * 2) {
+            m = Qt::KeepAspectRatio;
+        }
+    } else {
+        // Similarly, but horizontal
+        if (r.width() < width() * 2) {
+            m = Qt::KeepAspectRatio;
+        }
+    }
+    DEBUG << "Panner: fit mode " << m << endl;
+    fitInView(r, m);
+}
+
+void
 Panner::setScene(QGraphicsScene *s)
 {
     if (scene()) {
@@ -49,7 +70,11 @@
                    this, SLOT(slotSceneRectChanged(const QRectF &)));
     }
     QGraphicsView::setScene(s);
-    if (scene()) fitInView(sceneRect(), Qt::IgnoreAspectRatio);
+    if (scene()) {
+        QRectF r = sceneRect();
+        DEBUG << "scene rect: " << r << ", my rect " << rect() << endl;
+        fit(r);
+    }
     m_cache = QPixmap();
     connect(scene(), SIGNAL(sceneRectChanged(const QRectF &)),
             this, SLOT(slotSceneRectChanged(const QRectF &)));
@@ -81,7 +106,7 @@
 void
 Panner::resizeEvent(QResizeEvent *)
 {
-    if (scene()) fitInView(sceneRect(), Qt::IgnoreAspectRatio);
+    if (scene()) fit(sceneRect());
     m_cache = QPixmap();
 }
 
@@ -89,7 +114,7 @@
 Panner::slotSceneRectChanged(const QRectF &newRect)
 {
     if (!scene()) return; // spurious
-    fitInView(newRect, Qt::IgnoreAspectRatio);
+    fit(newRect);
     m_cache = QPixmap();
     viewport()->update();
 }
@@ -137,7 +162,7 @@
 {
     if (m_cache.size() != viewport()->size()) {
 
-    std::cerr << "Panner: recreating cache" << std::endl;
+        DEBUG << "Panner: recreating cache" << endl;
 
         QGraphicsScene *s = scene();
         if (!s) return;