5 #include "correlation_meter.h"
9 CorrelationMeter::CorrelationMeter(QWidget *parent)
14 void CorrelationMeter::resizeEvent(QResizeEvent *event)
16 on_pixmap = QPixmap(width(), height());
17 QPainter on_painter(&on_pixmap);
18 QLinearGradient on(0, 0, width(), 0);
19 on.setColorAt(0.0f, QColor(255, 0, 0));
20 on.setColorAt(0.5f, QColor(255, 255, 0));
21 on.setColorAt(0.8f, QColor(0, 255, 0));
22 on.setColorAt(0.95f, QColor(255, 255, 0));
23 on_painter.fillRect(0, 0, width(), height(), Qt::black);
24 on_painter.fillRect(1, 1, width() - 2, height() - 2, on);
26 off_pixmap = QPixmap(width(), height());
27 QPainter off_painter(&off_pixmap);
28 QLinearGradient off(0, 0, width(), 0);
29 off.setColorAt(0.0f, QColor(127, 0, 0));
30 off.setColorAt(0.5f, QColor(127, 127, 0));
31 off.setColorAt(0.8f, QColor(0, 127, 0));
32 off.setColorAt(0.95f, QColor(127, 127, 0));
33 off_painter.fillRect(0, 0, width(), height(), Qt::black);
34 off_painter.fillRect(1, 1, width() - 2, height() - 2, off);
37 void CorrelationMeter::paintEvent(QPaintEvent *event)
39 QPainter painter(this);
43 unique_lock<mutex> lock(correlation_mutex);
44 correlation = this->correlation;
48 correlation = std::min(std::max(correlation, -1.0f), 1.0f);
50 int pos = 3 + lrintf(0.5f * (correlation + 1.0f) * (width() - 6));
51 QRect off_rect(0, 0, width(), height());
52 QRect on_rect(pos - 2, 0, 5, height());
54 painter.drawPixmap(off_rect, off_pixmap, off_rect);
55 painter.drawPixmap(on_rect, on_pixmap, on_rect);