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