comparison 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
comparison
equal deleted inserted replaced
112:4bd17f36d059 113:5fc7b4fc77a8
15 COPYING included with this distribution for more information. 15 COPYING included with this distribution for more information.
16 */ 16 */
17 17
18 #include "panner.h" 18 #include "panner.h"
19 #include "panned.h" 19 #include "panned.h"
20 #include "debug.h"
20 21
21 #include <QPolygon> 22 #include <QPolygon>
22 #include <QMouseEvent> 23 #include <QMouseEvent>
23 #include <QColor> 24 #include <QColor>
24 25
40 setMouseTracking(true); 41 setMouseTracking(true);
41 setInteractive(false); 42 setInteractive(false);
42 } 43 }
43 44
44 void 45 void
46 Panner::fit(QRectF r)
47 {
48 Qt::AspectRatioMode m = Qt::IgnoreAspectRatio;
49 if (height() > width()) {
50 // Our panner is vertical; if the source is not tall,
51 // don't stretch it to fit in the height, it'd look weird
52 if (r.height() < height() * 2) {
53 m = Qt::KeepAspectRatio;
54 }
55 } else {
56 // Similarly, but horizontal
57 if (r.width() < width() * 2) {
58 m = Qt::KeepAspectRatio;
59 }
60 }
61 DEBUG << "Panner: fit mode " << m << endl;
62 fitInView(r, m);
63 }
64
65 void
45 Panner::setScene(QGraphicsScene *s) 66 Panner::setScene(QGraphicsScene *s)
46 { 67 {
47 if (scene()) { 68 if (scene()) {
48 disconnect(scene(), SIGNAL(sceneRectChanged(const QRectF &)), 69 disconnect(scene(), SIGNAL(sceneRectChanged(const QRectF &)),
49 this, SLOT(slotSceneRectChanged(const QRectF &))); 70 this, SLOT(slotSceneRectChanged(const QRectF &)));
50 } 71 }
51 QGraphicsView::setScene(s); 72 QGraphicsView::setScene(s);
52 if (scene()) fitInView(sceneRect(), Qt::IgnoreAspectRatio); 73 if (scene()) {
74 QRectF r = sceneRect();
75 DEBUG << "scene rect: " << r << ", my rect " << rect() << endl;
76 fit(r);
77 }
53 m_cache = QPixmap(); 78 m_cache = QPixmap();
54 connect(scene(), SIGNAL(sceneRectChanged(const QRectF &)), 79 connect(scene(), SIGNAL(sceneRectChanged(const QRectF &)),
55 this, SLOT(slotSceneRectChanged(const QRectF &))); 80 this, SLOT(slotSceneRectChanged(const QRectF &)));
56 } 81 }
57 82
79 } 104 }
80 105
81 void 106 void
82 Panner::resizeEvent(QResizeEvent *) 107 Panner::resizeEvent(QResizeEvent *)
83 { 108 {
84 if (scene()) fitInView(sceneRect(), Qt::IgnoreAspectRatio); 109 if (scene()) fit(sceneRect());
85 m_cache = QPixmap(); 110 m_cache = QPixmap();
86 } 111 }
87 112
88 void 113 void
89 Panner::slotSceneRectChanged(const QRectF &newRect) 114 Panner::slotSceneRectChanged(const QRectF &newRect)
90 { 115 {
91 if (!scene()) return; // spurious 116 if (!scene()) return; // spurious
92 fitInView(newRect, Qt::IgnoreAspectRatio); 117 fit(newRect);
93 m_cache = QPixmap(); 118 m_cache = QPixmap();
94 viewport()->update(); 119 viewport()->update();
95 } 120 }
96 121
97 void 122 void
135 QGraphicsItem *items[], 160 QGraphicsItem *items[],
136 const QStyleOptionGraphicsItem options[]) 161 const QStyleOptionGraphicsItem options[])
137 { 162 {
138 if (m_cache.size() != viewport()->size()) { 163 if (m_cache.size() != viewport()->size()) {
139 164
140 std::cerr << "Panner: recreating cache" << std::endl; 165 DEBUG << "Panner: recreating cache" << endl;
141 166
142 QGraphicsScene *s = scene(); 167 QGraphicsScene *s = scene();
143 if (!s) return; 168 if (!s) return;
144 PannerScene *ps = static_cast<PannerScene *>(s); 169 PannerScene *ps = static_cast<PannerScene *>(s);
145 170