comparison layer/TimeRulerLayer.cpp @ 1345:3fa8cdbf362c zoom

Use more precise text rendering when zoomed in beyond the ms level
author Chris Cannam
date Fri, 28 Sep 2018 12:31:12 +0100
parents ed6400d5b571
children 4c28e3302045
comparison
equal deleted inserted replaced
1344:13d03ae0c6e0 1345:3fa8cdbf362c
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 "base/Preferences.h"
22 #include "view/View.h" 23 #include "view/View.h"
23 24
24 #include "ColourDatabase.h" 25 #include "ColourDatabase.h"
25 #include "PaintAssistant.h" 26 #include "PaintAssistant.h"
26 27
261 262
262 #ifdef DEBUG_TIME_RULER_LAYER 263 #ifdef DEBUG_TIME_RULER_LAYER
263 cerr << "start us = " << us << " at step " << incus << endl; 264 cerr << "start us = " << us << " at step " << incus << endl;
264 #endif 265 #endif
265 266
267 Preferences *prefs = Preferences::getInstance();
268 auto origTimeTextMode = prefs->getTimeToTextMode();
269 if (incus < 1000) {
270 // Temporarily switch to usec display mode (if we aren't using
271 // it already)
272 prefs->blockSignals(true);
273 prefs->setTimeToTextMode(Preferences::TimeToTextUs);
274 }
275
266 // Calculate the number of ticks per increment -- approximate 276 // Calculate the number of ticks per increment -- approximate
267 // values for x and frame counts here will do, no rounding issue. 277 // values for x and frame counts here will do, no rounding issue.
268 // We always use the exact incus in our calculations for where to 278 // We always use the exact incus in our calculations for where to
269 // draw the actual ticks or lines. 279 // draw the actual ticks or lines.
270 280
309 #ifdef DEBUG_TIME_RULER_LAYER 319 #ifdef DEBUG_TIME_RULER_LAYER
310 cerr << "X in range, drawing line here for time " << rt.toText() << " (usec = " << us << ")" << endl; 320 cerr << "X in range, drawing line here for time " << rt.toText() << " (usec = " << us << ")" << endl;
311 #endif 321 #endif
312 322
313 QString text(QString::fromStdString(rt.toText())); 323 QString text(QString::fromStdString(rt.toText()));
324
314 QFontMetrics metrics = paint.fontMetrics(); 325 QFontMetrics metrics = paint.fontMetrics();
315 int tw = metrics.width(text); 326 int tw = metrics.width(text);
316 327
317 if (tw < 50 && 328 if (tw < 50 &&
318 (x < rect.x() - tw/2 || 329 (x < rect.x() - tw/2 ||
387 paint.drawLine(x, v->getPaintHeight() - sz - 1, x, v->getPaintHeight() - 1); 398 paint.drawLine(x, v->getPaintHeight() - sz - 1, x, v->getPaintHeight() - 1);
388 } 399 }
389 400
390 us += incus; 401 us += incus;
391 } 402 }
403
404 prefs->setTimeToTextMode(origTimeTextMode);
405 prefs->blockSignals(false);
392 406
393 paint.restore(); 407 paint.restore();
394 } 408 }
395 409
396 int 410 int