]> git.sesse.net Git - nageru/blob - nageru/compression_reduction_meter.h
IWYU-fix nageru/*.h.
[nageru] / nageru / compression_reduction_meter.h
1 #ifndef COMPRESSION_REDUCTION_METER_H
2 #define COMPRESSION_REDUCTION_METER_H
3
4 // A meter that goes downwards instead of upwards, and has a non-linear scale.
5
6 #include <math.h>
7 #include <QPixmap>
8 #include <QString>
9 #include <QWidget>
10 #include <mutex>
11
12 class QObject;
13 class QPaintEvent;
14 class QResizeEvent;
15
16 class CompressionReductionMeter : public QWidget
17 {
18         Q_OBJECT
19
20 public:
21         CompressionReductionMeter(QWidget *parent);
22
23         void set_reduction_db(float level_db) {
24                 std::lock_guard<std::mutex> lock(level_mutex);
25                 this->level_db = level_db;
26                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
27         }
28
29 private:
30         void resizeEvent(QResizeEvent *event) override;
31         void paintEvent(QPaintEvent *event) override;
32         void recalculate_pixmaps();
33         void draw_scale(QPainter *painter, int x_pos);
34         double db_to_pos(double db) const;
35         int meter_height() const;
36
37         std::mutex level_mutex;
38         float level_db = 0.0f;
39
40         static constexpr float min_level = 0.0f;  // Must match control_points (in the .cpp file).
41         static constexpr float max_level = 6.0f;  // Same.
42         static constexpr int meter_width = 20;
43
44         // Size of the text box. The meter will be shrunk to make room for the text box
45         // (half the height) on both sides.
46         static constexpr int text_box_width = 15;
47         static constexpr int text_box_height = 10;
48
49         QPixmap on_pixmap, off_pixmap;
50 };
51
52 #endif