comparison layer/SpectrogramLayer.cpp @ 607:5b72899d692b

Give a dedicated key to toggling the centre line, and move it out of the overlay level setting -- reducing number of overlay levels to 3. Introduce two distinct vertical scale types (so that we can hide the spectrogram colour scale part easily)
author Chris Cannam
date Mon, 30 Jan 2012 16:01:59 +0000
parents 4806715f7a19
children 0dba6a391760
comparison
equal deleted inserted replaced
606:fbab21439115 607:5b72899d692b
3029 extents.push_back(vertical); 3029 extents.push_back(vertical);
3030 3030
3031 QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1); 3031 QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1);
3032 extents.push_back(horizontal); 3032 extents.push_back(horizontal);
3033 3033
3034 int sw = getVerticalScaleWidth(v, paint); 3034 int sw = getVerticalScaleWidth(v, false, paint);//!!!
3035 3035
3036 QRect freq(sw, cursorPos.y() - paint.fontMetrics().ascent() - 2, 3036 QRect freq(sw, cursorPos.y() - paint.fontMetrics().ascent() - 2,
3037 paint.fontMetrics().width("123456 Hz") + 2, 3037 paint.fontMetrics().width("123456 Hz") + 2,
3038 paint.fontMetrics().height()); 3038 paint.fontMetrics().height());
3039 extents.push_back(freq); 3039 extents.push_back(freq);
3063 SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint, 3063 SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint,
3064 QPoint cursorPos) const 3064 QPoint cursorPos) const
3065 { 3065 {
3066 paint.save(); 3066 paint.save();
3067 3067
3068 int sw = getVerticalScaleWidth(v, paint); 3068 int sw = getVerticalScaleWidth(v, false, paint); //!!!
3069 3069
3070 QFont fn = paint.font(); 3070 QFont fn = paint.font();
3071 if (fn.pointSize() > 8) { 3071 if (fn.pointSize() > 8) {
3072 fn.setPointSize(fn.pointSize() - 1); 3072 fn.setPointSize(fn.pointSize() - 1);
3073 paint.setFont(fn); 3073 paint.setFont(fn);
3258 3258
3259 return cw; 3259 return cw;
3260 } 3260 }
3261 3261
3262 int 3262 int
3263 SpectrogramLayer::getVerticalScaleWidth(View *, QPainter &paint) const 3263 SpectrogramLayer::getVerticalScaleWidth(View *, bool detailed, QPainter &paint) const
3264 { 3264 {
3265 if (!m_model || !m_model->isOK()) return 0; 3265 if (!m_model || !m_model->isOK()) return 0;
3266 3266
3267 int cw = getColourScaleWidth(paint); 3267 int cw = 0;
3268 if (detailed) cw = getColourScaleWidth(paint);
3268 3269
3269 int tw = paint.fontMetrics().width(QString("%1") 3270 int tw = paint.fontMetrics().width(QString("%1")
3270 .arg(m_maxFrequency > 0 ? 3271 .arg(m_maxFrequency > 0 ?
3271 m_maxFrequency - 1 : 3272 m_maxFrequency - 1 :
3272 m_model->getSampleRate() / 2)); 3273 m_model->getSampleRate() / 2));
3278 3279
3279 return cw + tickw + tw + 13; 3280 return cw + tickw + tw + 13;
3280 } 3281 }
3281 3282
3282 void 3283 void
3283 SpectrogramLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const 3284 SpectrogramLayer::paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const
3284 { 3285 {
3285 if (!m_model || !m_model->isOK()) { 3286 if (!m_model || !m_model->isOK()) {
3286 return; 3287 return;
3287 } 3288 }
3288 3289
3301 if (m_maxFrequency > 0) { 3302 if (m_maxFrequency > 0) {
3302 bins = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); 3303 bins = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1);
3303 if (bins > m_fftSize / 2) bins = m_fftSize / 2; 3304 if (bins > m_fftSize / 2) bins = m_fftSize / 2;
3304 } 3305 }
3305 3306
3306 int cw = getColourScaleWidth(paint); 3307 int cw = 0;
3308
3309 if (detailed) cw = getColourScaleWidth(paint);
3307 int cbw = paint.fontMetrics().width("dB"); 3310 int cbw = paint.fontMetrics().width("dB");
3308 3311
3309 int py = -1; 3312 int py = -1;
3310 int textHeight = paint.fontMetrics().height(); 3313 int textHeight = paint.fontMetrics().height();
3311 int toff = -textHeight + paint.fontMetrics().ascent() + 2; 3314 int toff = -textHeight + paint.fontMetrics().ascent() + 2;
3312 3315
3313 if (h > textHeight * 3 + 10) { 3316 if (detailed && (h > textHeight * 3 + 10)) {
3314 3317
3315 int topLines = 2; 3318 int topLines = 2;
3316 if (m_colourScale == PhaseColourScale) topLines = 1; 3319 if (m_colourScale == PhaseColourScale) topLines = 1;
3317 3320
3318 int ch = h - textHeight * (topLines + 1) - 8; 3321 int ch = h - textHeight * (topLines + 1) - 8;