X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=lrameter.cpp;h=f4395bec39ceb1094e4a472d67a110e4a05c4515;hb=29cccb8cb0bb613b7f4b3e9d27a4a5c71a2f82e8;hp=6e9fed429a5862563c79144424acd2d0a70e2ff7;hpb=d7bba4abb3d56893399578f0540b9ded0a28380f;p=nageru diff --git a/lrameter.cpp b/lrameter.cpp index 6e9fed4..f4395be 100644 --- a/lrameter.cpp +++ b/lrameter.cpp @@ -14,12 +14,25 @@ LRAMeter::LRAMeter(QWidget *parent) { } +void LRAMeter::resizeEvent(QResizeEvent *event) +{ + const int margin = 5; + + on_pixmap = QPixmap(width(), height()); + QPainter on_painter(&on_pixmap); + on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window()); + draw_vu_meter(on_painter, width(), height(), margin, true); + + off_pixmap = QPixmap(width(), height()); + QPainter off_painter(&off_pixmap); + off_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window()); + draw_vu_meter(off_painter, width(), height(), margin, false); +} + void LRAMeter::paintEvent(QPaintEvent *event) { QPainter painter(this); - painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window()); - float level_lufs; float range_low_lufs; float range_high_lufs; @@ -33,13 +46,21 @@ void LRAMeter::paintEvent(QPaintEvent *event) float level_lu = level_lufs + 23.0f; float range_low_lu = range_low_lufs + 23.0f; float range_high_lu = range_high_lufs + 23.0f; - const int margin = 5; - draw_vu_meter(painter, range_low_lu, range_high_lu, width(), height(), margin); + int range_low_pos = lrint(lufs_to_pos(range_low_lu, height())); + int range_high_pos = lrint(lufs_to_pos(range_high_lu, height())); + + QRect top_off_rect(0, 0, width(), range_high_pos); + QRect on_rect(0, range_high_pos, width(), range_low_pos - range_high_pos); + QRect bottom_off_rect(0, range_low_pos, width(), height() - range_low_pos); + + painter.drawPixmap(top_off_rect, off_pixmap, top_off_rect); + painter.drawPixmap(on_rect, on_pixmap, on_rect); + painter.drawPixmap(bottom_off_rect, off_pixmap, bottom_off_rect); // Draw the target area (+/-1 LU is allowed EBU range). // It turns green when we're within. - int min_y = lufs_to_pos(1.0f, height()); - int max_y = lufs_to_pos(-1.0f, height()); + int min_y = lrint(lufs_to_pos(1.0f, height())); + int max_y = lrint(lufs_to_pos(-1.0f, height())); // FIXME: This outlining isn't so pretty. { @@ -61,7 +82,7 @@ void LRAMeter::paintEvent(QPaintEvent *event) } // Draw the integrated loudness meter, in the same color as the target area. - int y = lufs_to_pos(level_lu, height()); + int y = lrint(lufs_to_pos(level_lu, height())); { QPen pen(Qt::black); pen.setWidth(5);