diff widgets/WindowShapePreview.cpp @ 1159:8a5f0c8d5608 3.0-integration

Merge from branch piper
author Chris Cannam
date Fri, 28 Oct 2016 15:20:58 +0100
parents e6c798c9bc91
children 6796afa25c88
line wrap: on
line diff
--- a/widgets/WindowShapePreview.cpp	Thu Oct 20 11:20:27 2016 +0100
+++ b/widgets/WindowShapePreview.cpp	Fri Oct 28 15:20:58 2016 +0100
@@ -47,12 +47,17 @@
 void
 WindowShapePreview::updateLabels()
 {
-    int step = 24;
-    float peak = 48;
-    int w = step * 4, h = 64;
+    float scaleRatio = float(QFontMetrics(font()).height()) / 14.f;
+    if (scaleRatio < 1.f) scaleRatio = 1.f;
+
+    int step = int(24 * scaleRatio);
+    float peak = float(48 * scaleRatio);
+
+    int w = step * 4, h = int((peak * 4) / 3);
+
     WindowType type = m_windowType;
     Window<float> windower = Window<float>(type, step * 2);
-
+    
     QPixmap timeLabel(w, h + 1);
     timeLabel.fill(Qt::white);
     QPainter timePainter(&timeLabel);
@@ -68,7 +73,7 @@
     
     path = QPainterPath();
 
-    float *acc = new float(w);
+    float *acc = new float[w];
     for (int i = 0; i < w; ++i) acc[i] = 0.f;
     for (int j = 0; j < 3; ++j) {
         for (int i = 0; i < step * 2; ++i) {
@@ -105,7 +110,7 @@
     timePainter.drawPath(path);
 
     QFont font;
-    font.setPixelSize(10);
+    font.setPixelSize(int(10 * scaleRatio));
     font.setItalic(true);
     timePainter.setFont(font);
     QString label = tr("V / time");
@@ -114,9 +119,7 @@
 
     m_windowTimeExampleLabel->setPixmap(timeLabel);
     
-    int fw = 100;
-
-    QPixmap freqLabel(fw, h + 1);
+    QPixmap freqLabel(w, h + 1);
     freqLabel.fill(Qt::white);
     QPainter freqPainter(&freqLabel);
     path = QPainterPath();
@@ -161,7 +164,7 @@
 //    float ly = h - ((-80.f + -mindb) / maxval) * peak + 1;
 
     path.moveTo(0, float(h) - peak + 1);
-    path.lineTo(fw, float(h) - peak + 1);
+    path.lineTo(w, float(h) - peak + 1);
 
     freqPainter.setPen(Qt::gray);
     freqPainter.setRenderHint(QPainter::Antialiasing, true);
@@ -178,14 +181,14 @@
         float val = db + -mindb;
         if (val < 0) val = 0;
         float norm = val / maxval;
-        float x = (float(fw) / float(fftsize/2)) * float(i);
+        float x = (float(w) / float(fftsize/2)) * float(i);
         float y = float(h) - norm * peak + 1;
         if (i == 0) path.moveTo(x, y);
         else path.lineTo(x, y);
     }
 
     freqPainter.setRenderHint(QPainter::Antialiasing, true);
-    path.addRect(0, 0, fw, h + 1);
+    path.addRect(0, 0, w, h + 1);
     freqPainter.drawPath(path);
 
     fftf_free(input);
@@ -193,7 +196,7 @@
 
     freqPainter.setFont(font);
     label = tr("dB / freq");
-    freqPainter.drawText(fw - freqPainter.fontMetrics().width(label) - 4,
+    freqPainter.drawText(w - freqPainter.fontMetrics().width(label) - 4,
                          freqPainter.fontMetrics().ascent() + 1, label);
 
     m_windowFreqExampleLabel->setPixmap(freqLabel);