diff widgets/WindowShapePreview.cpp @ 1154:07e8ac88bcce 3.0-integration

Add out-of-process execution to prefs dialog Also, scale the window shape preview labels 'cos they look funny
author Chris Cannam
date Fri, 21 Oct 2016 14:40:48 +0100
parents c5a82068bd60
children e6c798c9bc91
line wrap: on
line diff
--- a/widgets/WindowShapePreview.cpp	Thu Oct 20 14:06:05 2016 +0100
+++ b/widgets/WindowShapePreview.cpp	Fri Oct 21 14:40:48 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);