comparison layer/SliceLayer.cpp @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents ee01a4062747
children 1a7c2ca31579
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
90 setSliceableModel(0); 90 setSliceableModel(0);
91 } 91 }
92 } 92 }
93 93
94 QString 94 QString
95 SliceLayer::getFeatureDescription(View *v, QPoint &p) const 95 SliceLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const
96 { 96 {
97 int minbin, maxbin, range; 97 int minbin, maxbin, range;
98 return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range); 98 return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range);
99 } 99 }
100 100
101 QString 101 QString
102 SliceLayer::getFeatureDescriptionAux(View *v, QPoint &p, 102 SliceLayer::getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &p,
103 bool includeBinDescription, 103 bool includeBinDescription,
104 int &minbin, int &maxbin, int &range) const 104 int &minbin, int &maxbin, int &range) const
105 { 105 {
106 minbin = 0; 106 minbin = 0;
107 maxbin = 0; 107 maxbin = 0;
108 if (!m_sliceableModel) return ""; 108 if (!m_sliceableModel) return "";
109 109
110 int xorigin = m_xorigins[v]; 110 int xorigin = m_xorigins[v];
111 int w = v->width() - xorigin - 1; 111 int w = v->getPaintWidth() - xorigin - 1;
112 112
113 int mh = m_sliceableModel->getHeight(); 113 int mh = m_sliceableModel->getHeight();
114 minbin = getBinForX(p.x() - xorigin, mh, w); 114 minbin = getBinForX(p.x() - xorigin, mh, w);
115 maxbin = getBinForX(p.x() - xorigin + 1, mh, w); 115 maxbin = getBinForX(p.x() - xorigin + 1, mh, w);
116 116
224 224
225 return bin; 225 return bin;
226 } 226 }
227 227
228 double 228 double
229 SliceLayer::getYForValue(double value, const View *v, double &norm) const 229 SliceLayer::getYForValue(double value, const LayerGeometryProvider *v, double &norm) const
230 { 230 {
231 norm = 0.0; 231 norm = 0.0;
232 232
233 if (m_yorigins.find(v) == m_yorigins.end()) return 0; 233 if (m_yorigins.find(v) == m_yorigins.end()) return 0;
234 234
274 274
275 return y; 275 return y;
276 } 276 }
277 277
278 double 278 double
279 SliceLayer::getValueForY(double y, const View *v) const 279 SliceLayer::getValueForY(double y, const LayerGeometryProvider *v) const
280 { 280 {
281 double value = 0.0; 281 double value = 0.0;
282 282
283 if (m_yorigins.find(v) == m_yorigins.end()) return value; 283 if (m_yorigins.find(v) == m_yorigins.end()) return value;
284 284
311 311
312 return value / m_gain; 312 return value / m_gain;
313 } 313 }
314 314
315 void 315 void
316 SliceLayer::paint(View *v, QPainter &paint, QRect rect) const 316 SliceLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
317 { 317 {
318 if (!m_sliceableModel || !m_sliceableModel->isOK() || 318 if (!m_sliceableModel || !m_sliceableModel->isOK() ||
319 !m_sliceableModel->isReady()) return; 319 !m_sliceableModel->isReady()) return;
320 320
321 paint.save(); 321 paint.save();
332 } 332 }
333 333
334 paint.setPen(getBaseQColor()); 334 paint.setPen(getBaseQColor());
335 335
336 int xorigin = getVerticalScaleWidth(v, true, paint) + 1; 336 int xorigin = getVerticalScaleWidth(v, true, paint) + 1;
337 int w = v->width() - xorigin - 1; 337 int w = v->getPaintWidth() - xorigin - 1;
338 338
339 m_xorigins[v] = xorigin; // for use in getFeatureDescription 339 m_xorigins[v] = xorigin; // for use in getFeatureDescription
340 340
341 int yorigin = v->height() - 20 - paint.fontMetrics().height() - 7; 341 int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 7;
342 int h = yorigin - paint.fontMetrics().height() - 8; 342 int h = yorigin - paint.fontMetrics().height() - 8;
343 343
344 m_yorigins[v] = yorigin; // for getYForValue etc 344 m_yorigins[v] = yorigin; // for getYForValue etc
345 m_heights[v] = h; 345 m_heights[v] = h;
346 346
483 .arg(f1 - f0 + 1); 483 .arg(f1 - f0 + 1);
484 484
485 v->drawVisibleText 485 v->drawVisibleText
486 (paint, xorigin + 5, 486 (paint, xorigin + 5,
487 paint.fontMetrics().ascent() + 5, 487 paint.fontMetrics().ascent() + 5,
488 startText, View::OutlinedText); 488 startText, PaintAssistant::OutlinedText);
489 489
490 v->drawVisibleText 490 v->drawVisibleText
491 (paint, xorigin + 5, 491 (paint, xorigin + 5,
492 paint.fontMetrics().ascent() + paint.fontMetrics().height() + 10, 492 paint.fontMetrics().ascent() + paint.fontMetrics().height() + 10,
493 endText, View::OutlinedText); 493 endText, PaintAssistant::OutlinedText);
494 494
495 v->drawVisibleText 495 v->drawVisibleText
496 (paint, xorigin + 5, 496 (paint, xorigin + 5,
497 paint.fontMetrics().ascent() + 2*paint.fontMetrics().height() + 15, 497 paint.fontMetrics().ascent() + 2*paint.fontMetrics().height() + 15,
498 durationText, View::OutlinedText); 498 durationText, PaintAssistant::OutlinedText);
499 } 499 }
500 */ 500 */
501 } 501 }
502 502
503 int 503 int
504 SliceLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const 504 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
505 { 505 {
506 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) { 506 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) {
507 return std::max(paint.fontMetrics().width("0.0") + 13, 507 return std::max(paint.fontMetrics().width("0.0") + 13,
508 paint.fontMetrics().width("x10-10")); 508 paint.fontMetrics().width("x10-10"));
509 } else { 509 } else {
511 paint.fontMetrics().width(tr("-Inf"))) + 13; 511 paint.fontMetrics().width(tr("-Inf"))) + 13;
512 } 512 }
513 } 513 }
514 514
515 void 515 void
516 SliceLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const 516 SliceLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
517 { 517 {
518 double thresh = m_threshold; 518 double thresh = m_threshold;
519 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) { 519 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) {
520 thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); 520 thresh = AudioLevel::dB_to_multiplier(getThresholdDb());
521 } 521 }
522 522
523 // int h = (rect.height() * 3) / 4; 523 // int h = (rect.height() * 3) / 4;
524 // int y = (rect.height() / 2) - (h / 2); 524 // int y = (rect.height() / 2) - (h / 2);
525 525
526 int yorigin = v->height() - 20 - paint.fontMetrics().height() - 6; 526 int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 6;
527 int h = yorigin - paint.fontMetrics().height() - 8; 527 int h = yorigin - paint.fontMetrics().height() - 8;
528 if (h < 0) return; 528 if (h < 0) return;
529 529
530 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h); 530 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h);
531 531