changeset 1156:2ab1cf27a766 project-file-rework

Merge from branch 3.0-integration
author Chris Cannam
date Tue, 25 Oct 2016 11:04:50 +0100
parents d1bab6a99100 (current diff) 07e8ac88bcce (diff)
children e6c798c9bc91
files
diffstat 1 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/WindowShapePreview.cpp	Mon Oct 24 17:53:33 2016 +0100
+++ b/widgets/WindowShapePreview.cpp	Tue Oct 25 11:04:50 2016 +0100
@@ -47,12 +47,17 @@
 void
 WindowShapePreview::updateLabels()
 {
-    int step = 24;
-    float peak = 48;
-    int w = step * 4, h = 64;
+    float scaleRatio = QFontMetrics(font()).height() / 14.f;
+    if (scaleRatio < 1.f) scaleRatio = 1.f;
+
+    int step = int(24 * scaleRatio);
+    float peak = int(48 * scaleRatio);
+
+    int w = step * 4, h = (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);
@@ -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);