- // Minimum distance between two lines
- const uint minDistY = 30;
- const uint minDistX = 40;
- const uint textDistX = 10;
- const uint textDistY = 25;
- const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
- const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
- const uint dbDiff = ceil((float)minDistY/m_innerScopeRect.height() * (m_dBmax-m_dBmin));
- const int mouseX = m_mousePos.x() - m_innerScopeRect.left();
- const int mouseY = m_mousePos.y() - m_innerScopeRect.top();
-
- QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
- hud.fill(qRgba(0,0,0,0));
-
- QPainter davinci(&hud);
- davinci.setPen(AbstractScopeWidget::penLight);
-
- int y;
- for (int db = -dbDiff; db > m_dBmin; db -= dbDiff) {
- y = topDist + m_innerScopeRect.height() * ((float)db)/(m_dBmin - m_dBmax);
- if (y-topDist > m_innerScopeRect.height()-minDistY+10) {
- // Abort here, there is still a line left for min dB to paint which needs some room.
- break;
- }
- davinci.drawLine(leftDist, y, leftDist + m_innerScopeRect.width()-1, y);
- davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, y + 6, i18n("%1 dB", m_dBmax + db));
- }
- davinci.drawLine(leftDist, topDist, leftDist + m_innerScopeRect.width()-1, topDist);
- davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+6, i18n("%1 dB", m_dBmax));
- davinci.drawLine(leftDist, topDist+m_innerScopeRect.height()-1, leftDist + m_innerScopeRect.width()-1, topDist+m_innerScopeRect.height()-1);
- davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+m_innerScopeRect.height()+6, i18n("%1 dB", m_dBmin));
-
- const uint hzDiff = ceil( ((float)minDistX)/m_innerScopeRect.width() * m_freqMax / 1000 ) * 1000;
- int x = 0;
- const int rightBorder = leftDist + m_innerScopeRect.width()-1;
- y = topDist + m_innerScopeRect.height() + textDistY;
- for (int hz = 0; x <= rightBorder; hz += hzDiff) {
- davinci.setPen(AbstractScopeWidget::penLighter);
- x = leftDist + m_innerScopeRect.width() * ((float)hz)/m_freqMax;
-
- if (x <= rightBorder) {
- davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6);
- }
- if (hz < m_freqMax && x+textDistY < leftDist + m_innerScopeRect.width()) {
- davinci.drawText(x-4, y, QVariant(hz/1000).toString());
- } else {
- x = leftDist + m_innerScopeRect.width();
- davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6);
- davinci.drawText(x-10, y, i18n("%1 kHz").arg((double)m_freqMax/1000, 0, 'f', 1));
+ if (m_innerScopeRect.height() > 0 && m_innerScopeRect.width() > 0) { // May be below 0 if widget is too small
+
+ // Minimum distance between two lines
+ const uint minDistY = 30;
+ const uint minDistX = 40;
+ const uint textDistX = 10;
+ const uint textDistY = 25;
+ const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
+ const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
+ const uint dbDiff = ceil((float)minDistY/m_innerScopeRect.height() * (m_dBmax-m_dBmin));
+ const int mouseX = m_mousePos.x() - m_innerScopeRect.left();
+ const int mouseY = m_mousePos.y() - m_innerScopeRect.top();
+
+
+ QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
+ hud.fill(qRgba(0,0,0,0));
+
+ QPainter davinci(&hud);
+ davinci.setPen(AbstractScopeWidget::penLight);
+
+ int _dw = m_innerScopeRect.width();
+ int _dh = m_innerScopeRect.height();
+ int _dld = m_innerScopeRect.width() + leftDist + textDistX;
+ int _dtd = topDist+ m_innerScopeRect.height() + 6;
+ int _fw = AbstractScopeWidget::geometry().width();
+ int _fh = AbstractScopeWidget::geometry().height();
+
+ int y;
+ for (int db = -dbDiff; db > m_dBmin; db -= dbDiff) {
+ y = topDist + m_innerScopeRect.height() * ((float)db)/(m_dBmin - m_dBmax);
+ if (y-topDist > m_innerScopeRect.height()-minDistY+10) {
+ // Abort here, there is still a line left for min dB to paint which needs some room.
+ break;
+ }
+ davinci.drawLine(leftDist, y, leftDist + m_innerScopeRect.width()-1, y);
+ davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, y + 6, i18n("%1 dB", m_dBmax + db));