]> git.sesse.net Git - nageru/blob - compression_reduction_meter.h
Release Nageru 1.7.2.
[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 #include "piecewise_interpolator.h"
13
14 class QObject;
15 class QPaintEvent;
16 class QResizeEvent;
17
18 class CompressionReductionMeter : public QWidget
19 {
20         Q_OBJECT
21
22 public:
23         CompressionReductionMeter(QWidget *parent);
24
25         void set_reduction_db(float level_db) {
26                 std::unique_lock<std::mutex> lock(level_mutex);
27                 this->level_db = level_db;
28                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
29         }
30
31 private:
32         void resizeEvent(QResizeEvent *event) override;
33         void paintEvent(QPaintEvent *event) override;
34         void recalculate_pixmaps();
35         void draw_scale(QPainter *painter, int x_pos);
36         double db_to_pos(double db) const;
37         int meter_height() const;
38
39         std::mutex level_mutex;
40         float level_db = 0.0f;
41
42         static constexpr float min_level = 0.0f;  // Must match control_points (in the .cpp file).
43         static constexpr float max_level = 6.0f;  // Same.
44         static constexpr int meter_width = 20;
45
46         // Size of the text box. The meter will be shrunk to make room for the text box
47         // (half the height) on both sides.
48         static constexpr int text_box_width = 15;
49         static constexpr int text_box_height = 10;
50
51         QPixmap on_pixmap, off_pixmap;
52 };
53
54 #endif