Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
1153:c5a82068bd60 | 1154:07e8ac88bcce |
---|---|
45 } | 45 } |
46 | 46 |
47 void | 47 void |
48 WindowShapePreview::updateLabels() | 48 WindowShapePreview::updateLabels() |
49 { | 49 { |
50 int step = 24; | 50 float scaleRatio = QFontMetrics(font()).height() / 14.f; |
51 float peak = 48; | 51 if (scaleRatio < 1.f) scaleRatio = 1.f; |
52 int w = step * 4, h = 64; | 52 |
53 int step = int(24 * scaleRatio); | |
54 float peak = int(48 * scaleRatio); | |
55 | |
56 int w = step * 4, h = (peak * 4) / 3; | |
57 | |
53 WindowType type = m_windowType; | 58 WindowType type = m_windowType; |
54 Window<float> windower = Window<float>(type, step * 2); | 59 Window<float> windower = Window<float>(type, step * 2); |
55 | 60 |
56 QPixmap timeLabel(w, h + 1); | 61 QPixmap timeLabel(w, h + 1); |
57 timeLabel.fill(Qt::white); | 62 timeLabel.fill(Qt::white); |
58 QPainter timePainter(&timeLabel); | 63 QPainter timePainter(&timeLabel); |
59 | 64 |
60 QPainterPath path; | 65 QPainterPath path; |
103 timePainter.setRenderHint(QPainter::Antialiasing, true); | 108 timePainter.setRenderHint(QPainter::Antialiasing, true); |
104 path.addRect(0, 0, w, h + 1); | 109 path.addRect(0, 0, w, h + 1); |
105 timePainter.drawPath(path); | 110 timePainter.drawPath(path); |
106 | 111 |
107 QFont font; | 112 QFont font; |
108 font.setPixelSize(10); | 113 font.setPixelSize(int(10 * scaleRatio)); |
109 font.setItalic(true); | 114 font.setItalic(true); |
110 timePainter.setFont(font); | 115 timePainter.setFont(font); |
111 QString label = tr("V / time"); | 116 QString label = tr("V / time"); |
112 timePainter.drawText(w - timePainter.fontMetrics().width(label) - 4, | 117 timePainter.drawText(w - timePainter.fontMetrics().width(label) - 4, |
113 timePainter.fontMetrics().ascent() + 1, label); | 118 timePainter.fontMetrics().ascent() + 1, label); |
114 | 119 |
115 m_windowTimeExampleLabel->setPixmap(timeLabel); | 120 m_windowTimeExampleLabel->setPixmap(timeLabel); |
116 | 121 |
117 int fw = 100; | 122 QPixmap freqLabel(w, h + 1); |
118 | |
119 QPixmap freqLabel(fw, h + 1); | |
120 freqLabel.fill(Qt::white); | 123 freqLabel.fill(Qt::white); |
121 QPainter freqPainter(&freqLabel); | 124 QPainter freqPainter(&freqLabel); |
122 path = QPainterPath(); | 125 path = QPainterPath(); |
123 | 126 |
124 int fftsize = 512; | 127 int fftsize = 512; |
159 float maxval = maxdb + -mindb; | 162 float maxval = maxdb + -mindb; |
160 | 163 |
161 // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1; | 164 // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1; |
162 | 165 |
163 path.moveTo(0, float(h) - peak + 1); | 166 path.moveTo(0, float(h) - peak + 1); |
164 path.lineTo(fw, float(h) - peak + 1); | 167 path.lineTo(w, float(h) - peak + 1); |
165 | 168 |
166 freqPainter.setPen(Qt::gray); | 169 freqPainter.setPen(Qt::gray); |
167 freqPainter.setRenderHint(QPainter::Antialiasing, true); | 170 freqPainter.setRenderHint(QPainter::Antialiasing, true); |
168 freqPainter.drawPath(path); | 171 freqPainter.drawPath(path); |
169 | 172 |
176 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; | 179 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; |
177 float db = 20.f * log10f(power); | 180 float db = 20.f * log10f(power); |
178 float val = db + -mindb; | 181 float val = db + -mindb; |
179 if (val < 0) val = 0; | 182 if (val < 0) val = 0; |
180 float norm = val / maxval; | 183 float norm = val / maxval; |
181 float x = (float(fw) / float(fftsize/2)) * float(i); | 184 float x = (float(w) / float(fftsize/2)) * float(i); |
182 float y = float(h) - norm * peak + 1; | 185 float y = float(h) - norm * peak + 1; |
183 if (i == 0) path.moveTo(x, y); | 186 if (i == 0) path.moveTo(x, y); |
184 else path.lineTo(x, y); | 187 else path.lineTo(x, y); |
185 } | 188 } |
186 | 189 |
187 freqPainter.setRenderHint(QPainter::Antialiasing, true); | 190 freqPainter.setRenderHint(QPainter::Antialiasing, true); |
188 path.addRect(0, 0, fw, h + 1); | 191 path.addRect(0, 0, w, h + 1); |
189 freqPainter.drawPath(path); | 192 freqPainter.drawPath(path); |
190 | 193 |
191 fftf_free(input); | 194 fftf_free(input); |
192 fftf_free(output); | 195 fftf_free(output); |
193 | 196 |
194 freqPainter.setFont(font); | 197 freqPainter.setFont(font); |
195 label = tr("dB / freq"); | 198 label = tr("dB / freq"); |
196 freqPainter.drawText(fw - freqPainter.fontMetrics().width(label) - 4, | 199 freqPainter.drawText(w - freqPainter.fontMetrics().width(label) - 4, |
197 freqPainter.fontMetrics().ascent() + 1, label); | 200 freqPainter.fontMetrics().ascent() + 1, label); |
198 | 201 |
199 m_windowFreqExampleLabel->setPixmap(freqLabel); | 202 m_windowFreqExampleLabel->setPixmap(freqLabel); |
200 } | 203 } |
201 | 204 |