swift
levelmeter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 // Class based on qt example: Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
4 
6 
7 #ifndef SWIFT_GUI_LEVELMETER_H
8 #define SWIFT_GUI_LEVELMETER_H
9 
10 #include <QColor>
11 #include <QElapsedTimer>
12 #include <QFrame>
13 #include <QObject>
14 
15 #include "gui/swiftguiexport.h"
16 
17 class QPaintEvent;
18 class QTimer;
19 
20 namespace swift::gui
21 {
24  class SWIFT_GUI_EXPORT CLevelMeter : public QFrame
25  {
26  Q_OBJECT
27 
30  Q_PROPERTY(QColor lowColor READ getLowColor WRITE setLowColor)
31  Q_PROPERTY(QColor highColor READ getHighColor WRITE setHighColor)
32  Q_PROPERTY(QColor peakColor READ getPeakColor WRITE setPeakColor)
34 
35  public:
37  CLevelMeter(QWidget *parent = nullptr);
38 
40  virtual ~CLevelMeter() override;
41 
43  void paintEvent(QPaintEvent *event) override;
44 
46  void reset();
47 
49  void levelChanged(double level);
50 
53  const QColor &getLowColor() const { return m_lowColor; }
54  const QColor &getHighColor() const { return m_highColor; }
55  const QColor &getPeakColor() const { return m_peakColor; }
56  void setLowColor(const QColor &color) { m_lowColor = color; }
57  void setHighColor(const QColor &color) { m_highColor = color; }
58  void setPeakColor(const QColor &color) { m_peakColor = color; }
60 
61  private:
63  void redrawTimerExpired();
64 
65  const int RedrawInterval = 100; // ms
66  const int PeakHoldLevelDuration = 1000; // ms
67 
69  double m_level = 0.0;
70 
72  double m_peakLevel = 0.0;
73 
75  QElapsedTimer m_peakLevelChanged;
76 
77  static constexpr double High = 0.60;
78  static constexpr double DecayValue = 0.10;
79  QTimer *m_redrawTimer = nullptr;
80  QColor m_lowColor;
81  QColor m_highColor;
82  QColor m_peakColor;
83  };
84 } // namespace swift::gui
85 
86 #endif // SWIFT_GUI_LEVELMETER_H
Widget which displays a audio level meter, indicating the level and peak levels of the window of audi...
Definition: levelmeter.h:25
void setHighColor(const QColor &color)
Color properties.
Definition: levelmeter.h:57
void setLowColor(const QColor &color)
Color properties.
Definition: levelmeter.h:56
void setPeakColor(const QColor &color)
Color properties.
Definition: levelmeter.h:58
const QColor & getLowColor() const
Color properties.
Definition: levelmeter.h:53
const QColor & getHighColor() const
Color properties.
Definition: levelmeter.h:54
const QColor & getPeakColor() const
Color properties.
Definition: levelmeter.h:55
GUI related classes.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.