comparison widgets/Panner.cpp @ 27:38fe0ea9e46e

* Some fixes to waveform layer greyscaling * Tidying in panner class
author Chris Cannam
date Fri, 03 Feb 2006 17:30:47 +0000
parents 37b110168acf
children 01ab51f72e84
comparison
equal deleted inserted replaced
26:94381052a6c9 27:38fe0ea9e46e
41 } 41 }
42 42
43 void 43 void
44 Panner::registerView(View *widget) 44 Panner::registerView(View *widget)
45 { 45 {
46 m_widgets[widget] = WidgetRec(0, -1); 46 m_widgets.insert(widget);
47 update(); 47 update();
48 } 48 }
49 49
50 void 50 void
51 Panner::unregisterView(View *widget) 51 Panner::unregisterView(View *widget)
60 // std::cerr << "Panner[" << this << "]::viewManagerCentreFrameChanged(" 60 // std::cerr << "Panner[" << this << "]::viewManagerCentreFrameChanged("
61 // << p << ", " << f << ")" << std::endl; 61 // << p << ", " << f << ")" << std::endl;
62 62
63 if (p == this) return; 63 if (p == this) return;
64 if (m_widgets.find(p) != m_widgets.end()) { 64 if (m_widgets.find(p) != m_widgets.end()) {
65 m_widgets[p].first = f;
66 update(); 65 update();
67 } 66 }
68 } 67 }
69 68
70 void 69 void
71 Panner::viewManagerZoomLevelChanged(void *p, unsigned long z, bool) 70 Panner::viewManagerZoomLevelChanged(void *p, unsigned long z, bool)
72 { 71 {
73 if (p == this) return; 72 if (p == this) return;
74 if (m_widgets.find(p) != m_widgets.end()) { 73 if (m_widgets.find(p) != m_widgets.end()) {
75 m_widgets[p].second = z;
76 update(); 74 update();
77 } 75 }
78 } 76 }
79 77
80 void 78 void
81 Panner::viewManagerPlaybackFrameChanged(unsigned long f) 79 Panner::viewManagerPlaybackFrameChanged(unsigned long f)
82 { 80 {
83 bool changed = false; 81 bool changed = false;
84 82
85 if (m_playPointerFrame / m_zoomLevel != f / m_zoomLevel) changed = true; 83 if (getXForFrame(m_playPointerFrame) != getXForFrame(f)) changed = true;
86 m_playPointerFrame = f; 84 m_playPointerFrame = f;
87 85
88 for (WidgetMap::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
89 unsigned long of = i->second.first;
90 i->second.first = f;
91 if (of / m_zoomLevel != f / m_zoomLevel) changed = true;
92 }
93
94 if (changed) update(); 86 if (changed) update();
95 } 87 }
96 88
97 void 89 void
98 Panner::paintEvent(QPaintEvent *e) 90 Panner::paintEvent(QPaintEvent *e)
99 { 91 {
100 /*!!!
101 // Force View to recalculate zoom in case the size of the
102 // widget has changed. (We need a better name/mechanism for this)
103 m_newModel = true;
104 */
105
106 // Recalculate zoom in case the size of the widget has changed. 92 // Recalculate zoom in case the size of the widget has changed.
107 93
108 size_t startFrame = getModelsStartFrame(); 94 size_t startFrame = getModelsStartFrame();
109 size_t frameCount = getModelsEndFrame() - getModelsStartFrame(); 95 size_t frameCount = getModelsEndFrame() - getModelsStartFrame();
110 int zoomLevel = frameCount / width(); 96 int zoomLevel = frameCount / width();
137 } 123 }
138 124
139 paint.setPen(Qt::black); 125 paint.setPen(Qt::black);
140 126
141 int y = 0; 127 int y = 0;
142 long prevCentre = 0; 128
143 long prevZoom = -1; 129 int prevx0 = -10;
144 130 int prevx1 = -10;
145 for (WidgetMap::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) { 131
146 if (!i->first) continue; 132 for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
147 133 if (!*i) continue;
148 View *w = (View *)i->first; 134
149 if (i->second.second < 0) i->second.second = w->getZoomLevel(); 135 View *w = (View *)*i;
150 if (i->second.second < 0) continue; 136
151 137 long f0 = w->getFrameForX(0);
152 long c = (long)i->second.first; 138 long f1 = w->getFrameForX(w->width());
153 long z = (long)i->second.second; 139
154 140 int x0 = getXForFrame(f0);
155 long f0 = c - (w->width() / 2) * z; 141 int x1 = getXForFrame(f1);
156 long f1 = c + (w->width() / 2) * z; 142
157 143 if (x0 != prevx0 || x1 != prevx1) {
158 int x0 = (f0 - long(getCentreFrame())) / getZoomLevel() + width()/2;
159 int x1 = (f1 - long(getCentreFrame())) / getZoomLevel() + width()/2 - 1;
160
161 if (c != prevCentre || z != prevZoom) {
162 y += height() / 10 + 1; 144 y += height() / 10 + 1;
163 prevCentre = c; 145 prevx0 = x0;
164 prevZoom = z; 146 prevx1 = x1;
165 } 147 }
148
149 if (x1 <= x0) x1 = x0 + 1;
166 150
167 paint.drawRect(x0, y, x1 - x0, height() - 2 * y); 151 paint.drawRect(x0, y, x1 - x0, height() - 2 * y);
168 } 152 }
169 153
170 paint.end(); 154 paint.end();
172 156
173 void 157 void
174 Panner::mousePressEvent(QMouseEvent *e) 158 Panner::mousePressEvent(QMouseEvent *e)
175 { 159 {
176 m_clickPos = e->pos(); 160 m_clickPos = e->pos();
177 for (WidgetMap::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) { 161 for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
178 if (i->first && i->second.second >= 0) { 162 if (*i) {
179 m_clickedInRange = true; 163 m_clickedInRange = true;
180 m_dragCentreFrame = i->second.first; 164 m_dragCentreFrame = ((View *)*i)->getCentreFrame();
165 break;
181 } 166 }
182 } 167 }
183 } 168 }
184 169
185 void 170 void
193 178
194 void 179 void
195 Panner::mouseMoveEvent(QMouseEvent *e) 180 Panner::mouseMoveEvent(QMouseEvent *e)
196 { 181 {
197 if (!m_clickedInRange) return; 182 if (!m_clickedInRange) return;
198
199 /*!!!
200 long newFrame = getStartFrame() + e->x() * m_zoomLevel;
201
202 if (newFrame < 0) newFrame = 0;
203 if (newFrame >= getModelsEndFrame()) {
204 newFrame = getModelsEndFrame();
205 if (newFrame > 0) --newFrame;
206 }
207 emit centreFrameChanged(this, newFrame, true);
208 */
209 183
210 long xoff = int(e->x()) - int(m_clickPos.x()); 184 long xoff = int(e->x()) - int(m_clickPos.x());
211 long frameOff = xoff * m_zoomLevel; 185 long frameOff = xoff * m_zoomLevel;
212 186
213 size_t newCentreFrame = m_dragCentreFrame; 187 size_t newCentreFrame = m_dragCentreFrame;