Mercurial > hg > svgui
comparison layer/TimeRulerLayer.cpp @ 1216:dc2af6616c83
Merge from branch 3.0-integration
author | Chris Cannam |
---|---|
date | Fri, 13 Jan 2017 10:29:50 +0000 |
parents | ee01a4062747 |
children | a34a2a25907c |
comparison
equal
deleted
inserted
replaced
1048:e8102ff5573b | 1216:dc2af6616c83 |
---|---|
17 | 17 |
18 #include "LayerFactory.h" | 18 #include "LayerFactory.h" |
19 | 19 |
20 #include "data/model/Model.h" | 20 #include "data/model/Model.h" |
21 #include "base/RealTime.h" | 21 #include "base/RealTime.h" |
22 #include "view/View.h" | |
23 | |
22 #include "ColourDatabase.h" | 24 #include "ColourDatabase.h" |
23 #include "view/View.h" | 25 #include "PaintAssistant.h" |
24 | 26 |
25 #include <QPainter> | 27 #include <QPainter> |
26 | 28 |
27 #include <iostream> | 29 #include <iostream> |
28 #include <cmath> | 30 #include <cmath> |
31 #include <stdexcept> | |
29 | 32 |
30 //#define DEBUG_TIME_RULER_LAYER 1 | 33 //#define DEBUG_TIME_RULER_LAYER 1 |
31 | |
32 | |
33 | 34 |
34 | 35 |
35 TimeRulerLayer::TimeRulerLayer() : | 36 TimeRulerLayer::TimeRulerLayer() : |
36 SingleColourLayer(), | 37 SingleColourLayer(), |
37 m_model(0), | 38 m_model(0), |
47 m_model = model; | 48 m_model = model; |
48 emit modelReplaced(); | 49 emit modelReplaced(); |
49 } | 50 } |
50 | 51 |
51 bool | 52 bool |
52 TimeRulerLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 53 TimeRulerLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
53 int &resolution, SnapType snap) const | 54 int &resolution, SnapType snap) const |
54 { | 55 { |
55 if (!m_model) { | 56 if (!m_model) { |
56 resolution = 1; | 57 resolution = 1; |
57 return false; | 58 return false; |
139 | 140 |
140 return true; | 141 return true; |
141 } | 142 } |
142 | 143 |
143 int | 144 int |
144 TimeRulerLayer::getMajorTickSpacing(View *v, bool &quarterTicks) const | 145 TimeRulerLayer::getMajorTickSpacing(LayerGeometryProvider *v, bool &quarterTicks) const |
145 { | 146 { |
146 // return value is in milliseconds | 147 // return value is in milliseconds |
147 | 148 |
148 if (!m_model || !v) return 1000; | 149 if (!m_model || !v) return 1000; |
149 | 150 |
156 int minPixelSpacing = 50; | 157 int minPixelSpacing = 50; |
157 | 158 |
158 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); | 159 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); |
159 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate); | 160 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate); |
160 | 161 |
161 int count = v->width() / minPixelSpacing; | 162 int count = v->getPaintWidth() / minPixelSpacing; |
162 if (count < 1) count = 1; | 163 if (count < 1) count = 1; |
163 RealTime rtGap = (rtEnd - rtStart) / count; | 164 RealTime rtGap = (rtEnd - rtStart) / count; |
164 | 165 |
165 int incms; | 166 int incms; |
166 quarterTicks = false; | 167 quarterTicks = false; |
180 quarterTicks = false; | 181 quarterTicks = false; |
181 } | 182 } |
182 } else { | 183 } else { |
183 incms = 1; | 184 incms = 1; |
184 int ms = rtGap.msec(); | 185 int ms = rtGap.msec(); |
186 // cerr << "rtGap.msec = " << ms << ", rtGap = " << rtGap << ", count = " << count << endl; | |
187 // cerr << "startFrame = " << startFrame << ", endFrame = " << endFrame << " rtStart = " << rtStart << ", rtEnd = " << rtEnd << endl; | |
185 if (ms > 0) { incms *= 10; ms /= 10; } | 188 if (ms > 0) { incms *= 10; ms /= 10; } |
186 if (ms > 0) { incms *= 10; ms /= 10; } | 189 if (ms > 0) { incms *= 10; ms /= 10; } |
187 if (ms > 0) { incms *= 5; ms /= 5; } | 190 if (ms > 0) { incms *= 5; ms /= 5; } |
188 if (ms > 0) { incms *= 2; ms /= 2; } | 191 if (ms > 0) { incms *= 2; ms /= 2; } |
189 } | 192 } |
190 | 193 |
191 return incms; | 194 return incms; |
192 } | 195 } |
193 | 196 |
194 void | 197 void |
195 TimeRulerLayer::paint(View *v, QPainter &paint, QRect rect) const | 198 TimeRulerLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
196 { | 199 { |
197 #ifdef DEBUG_TIME_RULER_LAYER | 200 #ifdef DEBUG_TIME_RULER_LAYER |
198 SVDEBUG << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y() | 201 SVDEBUG << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y() |
199 << ") [" << rect.width() << "x" << rect.height() << "]" << endl; | 202 << ") [" << rect.width() << "x" << rect.height() << "]" << endl; |
200 #endif | 203 #endif |
239 | 242 |
240 // Do not label time zero - we now overlay an opaque area over | 243 // Do not label time zero - we now overlay an opaque area over |
241 // time < 0 which would cut it in half | 244 // time < 0 which would cut it in half |
242 int minlabel = 1; // ms | 245 int minlabel = 1; // ms |
243 | 246 |
247 // used for a sanity check | |
248 sv_frame_t prevframe = 0; | |
249 | |
244 while (1) { | 250 while (1) { |
245 | 251 |
246 // frame is used to determine where to draw the lines, so it | 252 // frame is used to determine where to draw the lines, so it |
247 // needs to correspond to an exact pixel (so that we don't get | 253 // needs to correspond to an exact pixel (so that we don't get |
248 // a different pixel when scrolling a small amount and | 254 // a different pixel when scrolling a small amount and |
251 double dms = ms; | 257 double dms = ms; |
252 sv_frame_t frame = lrint((dms * sampleRate) / 1000.0); | 258 sv_frame_t frame = lrint((dms * sampleRate) / 1000.0); |
253 frame /= v->getZoomLevel(); | 259 frame /= v->getZoomLevel(); |
254 frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel | 260 frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel |
255 | 261 |
262 if (frame == prevframe && prevframe != 0) { | |
263 cerr << "ERROR: frame == prevframe (== " << frame | |
264 << ") in TimeRulerLayer::paint" << endl; | |
265 throw std::logic_error("frame == prevframe in TimeRulerLayer::paint"); | |
266 } | |
267 prevframe = frame; | |
268 | |
256 int x = v->getXForFrame(frame); | 269 int x = v->getXForFrame(frame); |
257 | 270 |
258 #ifdef DEBUG_TIME_RULER_LAYER | 271 #ifdef DEBUG_TIME_RULER_LAYER |
259 SVDEBUG << "Considering frame = " << frame << ", x = " << x << endl; | 272 cerr << "Considering frame = " << frame << ", x = " << x << endl; |
260 #endif | 273 #endif |
261 | 274 |
262 if (x >= rect.x() + rect.width() + 50) { | 275 if (x >= rect.x() + rect.width() + 50) { |
263 #ifdef DEBUG_TIME_RULER_LAYER | 276 #ifdef DEBUG_TIME_RULER_LAYER |
264 cerr << "X well out of range, ending here" << endl; | 277 cerr << "X well out of range, ending here" << endl; |
285 cerr << "hm, maybe X isn't in range after all (x = " << x << ", tw = " << tw << ", rect.x() = " << rect.x() << ", rect.width() = " << rect.width() << ")" << endl; | 298 cerr << "hm, maybe X isn't in range after all (x = " << x << ", tw = " << tw << ", rect.x() = " << rect.x() << ", rect.width() = " << rect.width() << ")" << endl; |
286 #endif | 299 #endif |
287 } | 300 } |
288 | 301 |
289 paint.setPen(greyColour); | 302 paint.setPen(greyColour); |
290 paint.drawLine(x, 0, x, v->height()); | 303 paint.drawLine(x, 0, x, v->getPaintHeight()); |
291 | 304 |
292 paint.setPen(getBaseQColor()); | 305 paint.setPen(getBaseQColor()); |
293 paint.drawLine(x, 0, x, 5); | 306 paint.drawLine(x, 0, x, 5); |
294 paint.drawLine(x, v->height() - 6, x, v->height() - 1); | 307 paint.drawLine(x, v->getPaintHeight() - 6, x, v->getPaintHeight() - 1); |
295 | 308 |
296 int y; | 309 int y; |
297 switch (m_labelHeight) { | 310 switch (m_labelHeight) { |
298 default: | 311 default: |
299 case LabelTop: | 312 case LabelTop: |
300 y = 6 + metrics.ascent(); | 313 y = 6 + metrics.ascent(); |
301 break; | 314 break; |
302 case LabelMiddle: | 315 case LabelMiddle: |
303 y = v->height() / 2 - metrics.height() / 2 + metrics.ascent(); | 316 y = v->getPaintHeight() / 2 - metrics.height() / 2 + metrics.ascent(); |
304 break; | 317 break; |
305 case LabelBottom: | 318 case LabelBottom: |
306 y = v->height() - metrics.height() + metrics.ascent() - 6; | 319 y = v->getPaintHeight() - metrics.height() + metrics.ascent() - 6; |
307 } | 320 } |
308 | 321 |
309 if (v->getViewManager() && v->getViewManager()->getOverlayMode() != | 322 if (v->getViewManager() && v->getViewManager()->getOverlayMode() != |
310 ViewManager::NoOverlays) { | 323 ViewManager::NoOverlays) { |
311 | 324 |
312 if (v->getLayer(0) == this) { | 325 if (v->getView()->getLayer(0) == this) { |
313 // backmost layer, don't worry about outlining the text | 326 // backmost layer, don't worry about outlining the text |
314 paint.drawText(x+2 - tw/2, y, text); | 327 paint.drawText(x+2 - tw/2, y, text); |
315 } else { | 328 } else { |
316 v->drawVisibleText(paint, x+2 - tw/2, y, text, View::OutlinedText); | 329 PaintAssistant::drawVisibleText(v, paint, x+2 - tw/2, y, text, PaintAssistant::OutlinedText); |
317 } | 330 } |
318 } | 331 } |
319 } | 332 } |
320 | 333 |
321 paint.setPen(greyColour); | 334 paint.setPen(greyColour); |
342 | 355 |
343 int sz = 5; | 356 int sz = 5; |
344 if (ticks == 10) { | 357 if (ticks == 10) { |
345 if ((i % 2) == 1) { | 358 if ((i % 2) == 1) { |
346 if (i == 5) { | 359 if (i == 5) { |
347 paint.drawLine(x, 0, x, v->height()); | 360 paint.drawLine(x, 0, x, v->getPaintHeight()); |
348 } else sz = 3; | 361 } else sz = 3; |
349 } else { | 362 } else { |
350 sz = 7; | 363 sz = 7; |
351 } | 364 } |
352 } | 365 } |
353 paint.drawLine(x, 0, x, sz); | 366 paint.drawLine(x, 0, x, sz); |
354 paint.drawLine(x, v->height() - sz - 1, x, v->height() - 1); | 367 paint.drawLine(x, v->getPaintHeight() - sz - 1, x, v->getPaintHeight() - 1); |
355 } | 368 } |
356 | 369 |
357 ms += incms; | 370 ms += incms; |
358 } | 371 } |
359 | 372 |