# HG changeset patch # User Chris Cannam # Date 1142446877 0 # Node ID 8dae7f6732c18aa70aa202c35d9760b0e35b5f5d # Parent 68869408f5c7ea9c231fc50c56e203283404758a * improve label drawing logic in colour plot layer diff -r 68869408f5c7 -r 8dae7f6732c1 layer/Colour3DPlotLayer.cpp --- a/layer/Colour3DPlotLayer.cpp Wed Mar 15 18:11:23 2006 +0000 +++ b/layer/Colour3DPlotLayer.cpp Wed Mar 15 18:21:17 2006 +0000 @@ -285,6 +285,7 @@ QPoint illuminatePos; bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); + char labelbuf[10]; for (int sx = sx0 - 1; sx <= sx1; ++sx) { @@ -293,11 +294,18 @@ if (fx + modelWindow < int(modelStart) || fx > int(modelEnd)) continue; + int rx0 = v->getXForFrame(fx + int(modelStart)); + int rx1 = v->getXForFrame(fx + int(modelStart) + int(modelWindow)); + + int w = rx1 - rx0; + if (w < 1) w = 1; + + bool showLabel = (w > 10 && + paint.fontMetrics().width("0.000000") < w - 3 && + paint.fontMetrics().height() < (h / sh)); + for (int sy = 0; sy < sh; ++sy) { - int rx0 = v->getXForFrame(fx + int(modelStart)); - int rx1 = v->getXForFrame(fx + int(modelStart) + int(modelWindow)); - int ry0 = h - (sy * h) / sh - 1; int ry1 = h - ((sy + 1) * h) / sh - 2; QRgb pixel = qRgb(255, 255, 255); @@ -307,16 +315,11 @@ } QColor pen(255, 255, 255, 80); -// QColor pen(pixel); QColor brush(pixel); brush.setAlpha(160); -// paint.setPen(pen); paint.setPen(Qt::NoPen); paint.setBrush(brush); - int w = rx1 - rx0; - if (w < 1) w = 1; - QRect r(rx0, ry0 - h / sh - 1, w, h / sh + 1); if (illuminate) { @@ -327,21 +330,17 @@ paint.drawRect(r); - if (sx >= 0 && sx < m_cache->width() && - sy >= 0 && sy < m_cache->height()) { - if (w > 10) { + if (showLabel) { + if (sx >= 0 && sx < m_cache->width() && + sy >= 0 && sy < m_cache->height()) { int dv = m_cache->pixelIndex(sx, sy); -// if (dv != 0 && paint.fontMetrics().height() < (h / sh)) { - if (paint.fontMetrics().height() < (h / sh)) { - float value = m_model->getBinValue(fx, sy); - QString text = QString("%1").arg(value); //dv); - if (paint.fontMetrics().width(text) < w - 3) { - paint.setPen(Qt::white); - paint.drawText(rx0 + 2, - ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), - QString("%1").arg(value)); - } - } + float value = m_model->getBinValue(fx, sy); + sprintf(labelbuf, "%06f", value); + QString text(labelbuf); + paint.setPen(Qt::white); + paint.drawText(rx0 + 2, + ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), + text); } } }