comparison layer/Colour3DPlotLayer.cpp @ 54:8dae7f6732c1

* improve label drawing logic in colour plot layer
author Chris Cannam
date Wed, 15 Mar 2006 18:21:17 +0000
parents ad214997dddb
children 01ab51f72e84
comparison
equal deleted inserted replaced
53:68869408f5c7 54:8dae7f6732c1
283 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", window size " << m_model->getWindowSize() << std::endl; 283 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", window size " << m_model->getWindowSize() << std::endl;
284 */ 284 */
285 285
286 QPoint illuminatePos; 286 QPoint illuminatePos;
287 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); 287 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
288 char labelbuf[10];
288 289
289 for (int sx = sx0 - 1; sx <= sx1; ++sx) { 290 for (int sx = sx0 - 1; sx <= sx1; ++sx) {
290 291
291 int fx = sx * int(modelWindow); 292 int fx = sx * int(modelWindow);
292 293
293 if (fx + modelWindow < int(modelStart) || 294 if (fx + modelWindow < int(modelStart) ||
294 fx > int(modelEnd)) continue; 295 fx > int(modelEnd)) continue;
295 296
297 int rx0 = v->getXForFrame(fx + int(modelStart));
298 int rx1 = v->getXForFrame(fx + int(modelStart) + int(modelWindow));
299
300 int w = rx1 - rx0;
301 if (w < 1) w = 1;
302
303 bool showLabel = (w > 10 &&
304 paint.fontMetrics().width("0.000000") < w - 3 &&
305 paint.fontMetrics().height() < (h / sh));
306
296 for (int sy = 0; sy < sh; ++sy) { 307 for (int sy = 0; sy < sh; ++sy) {
297
298 int rx0 = v->getXForFrame(fx + int(modelStart));
299 int rx1 = v->getXForFrame(fx + int(modelStart) + int(modelWindow));
300 308
301 int ry0 = h - (sy * h) / sh - 1; 309 int ry0 = h - (sy * h) / sh - 1;
302 int ry1 = h - ((sy + 1) * h) / sh - 2; 310 int ry1 = h - ((sy + 1) * h) / sh - 2;
303 QRgb pixel = qRgb(255, 255, 255); 311 QRgb pixel = qRgb(255, 255, 255);
304 if (sx >= 0 && sx < m_cache->width() && 312 if (sx >= 0 && sx < m_cache->width() &&
305 sy >= 0 && sy < m_cache->height()) { 313 sy >= 0 && sy < m_cache->height()) {
306 pixel = m_cache->pixel(sx, sy); 314 pixel = m_cache->pixel(sx, sy);
307 } 315 }
308 316
309 QColor pen(255, 255, 255, 80); 317 QColor pen(255, 255, 255, 80);
310 // QColor pen(pixel);
311 QColor brush(pixel); 318 QColor brush(pixel);
312 brush.setAlpha(160); 319 brush.setAlpha(160);
313 // paint.setPen(pen);
314 paint.setPen(Qt::NoPen); 320 paint.setPen(Qt::NoPen);
315 paint.setBrush(brush); 321 paint.setBrush(brush);
316
317 int w = rx1 - rx0;
318 if (w < 1) w = 1;
319 322
320 QRect r(rx0, ry0 - h / sh - 1, w, h / sh + 1); 323 QRect r(rx0, ry0 - h / sh - 1, w, h / sh + 1);
321 324
322 if (illuminate) { 325 if (illuminate) {
323 if (r.contains(illuminatePos)) { 326 if (r.contains(illuminatePos)) {
325 } 328 }
326 } 329 }
327 330
328 paint.drawRect(r); 331 paint.drawRect(r);
329 332
330 if (sx >= 0 && sx < m_cache->width() && 333 if (showLabel) {
331 sy >= 0 && sy < m_cache->height()) { 334 if (sx >= 0 && sx < m_cache->width() &&
332 if (w > 10) { 335 sy >= 0 && sy < m_cache->height()) {
333 int dv = m_cache->pixelIndex(sx, sy); 336 int dv = m_cache->pixelIndex(sx, sy);
334 // if (dv != 0 && paint.fontMetrics().height() < (h / sh)) { 337 float value = m_model->getBinValue(fx, sy);
335 if (paint.fontMetrics().height() < (h / sh)) { 338 sprintf(labelbuf, "%06f", value);
336 float value = m_model->getBinValue(fx, sy); 339 QString text(labelbuf);
337 QString text = QString("%1").arg(value); //dv); 340 paint.setPen(Qt::white);
338 if (paint.fontMetrics().width(text) < w - 3) { 341 paint.drawText(rx0 + 2,
339 paint.setPen(Qt::white); 342 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
340 paint.drawText(rx0 + 2, 343 text);
341 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
342 QString("%1").arg(value));
343 }
344 }
345 } 344 }
346 } 345 }
347 } 346 }
348 } 347 }
349 348