SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
levelmeter.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2016 Edouard Griffiths, F4EXB
3  * Modifications made to:
4  * - use the widget horizontally
5  * - differentiate each area with a different color
6  * - allow overload by 25% with indication of 100% threshold and overload
7  * - make it generic to fit many cases: VU, signal strength ...
8 **
9 ** Copyright (C) 2015 The Qt Company Ltd.
10 ** Contact: http://www.qt.io/licensing/
11 **
12 ** This file is part of the examples of the Qt Toolkit.
13 **
14 ** $QT_BEGIN_LICENSE:BSD$
15 ** You may use this file under the terms of the BSD license as follows:
16 **
17 ** "Redistribution and use in source and binary forms, with or without
18 ** modification, are permitted provided that the following conditions are
19 ** met:
20 ** * Redistributions of source code must retain the above copyright
21 ** notice, this list of conditions and the following disclaimer.
22 ** * Redistributions in binary form must reproduce the above copyright
23 ** notice, this list of conditions and the following disclaimer in
24 ** the documentation and/or other materials provided with the
25 ** distribution.
26 ** * Neither the name of The Qt Company Ltd nor the names of its
27 ** contributors may be used to endorse or promote products derived
28 ** from this software without specific prior written permission.
29 **
30 **
31 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
42 **
43 ** $QT_END_LICENSE$
44 **
45 ****************************************************************************/
46 
47 #ifndef SDRBASE_GUI_LEVELMETER_H_
48 #define SDRBASE_GUI_LEVELMETER_H_
49 
50 #include <QTime>
51 #include <QWidget>
52 
53 #include "dsp/dsptypes.h"
54 #include "gui/scaleengine.h"
55 #include "export.h"
56 
62 class SDRGUI_API LevelMeter : public QWidget
63 {
64  Q_OBJECT
65 
66 public:
67  LevelMeter(QWidget *parent = 0);
68  virtual ~LevelMeter();
69 
70  void paintEvent(QPaintEvent *event);
71  void resizeEvent(QResizeEvent * event);
72 
73  void setAverageSmoothing(uint32_t smoothingFactor);
74 
75 public slots:
76  void reset();
77  void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
78 
79 protected slots:
80  void redrawTimerExpired();
81 
82 protected:
87  qreal m_avgLevel;
88 
93  qreal m_peakLevel;
94 
101 
106 
112 
118 
123 
128 
129  QTimer *m_redrawTimer;
130 
131  QColor m_avgColor;
132  QColor m_peakColor;
134 
137 
138  virtual void render(QPainter *painter) = 0;
139  virtual void resized() = 0;
140 
142  int shiftx(int val, int width)
143  {
144  return val == 0 ? 1 : val == width-1 ? width-2 : val;
145  }
146 };
147 
149 {
150 public:
151  LevelMeterVU(QWidget *parent = 0);
152  virtual ~LevelMeterVU();
153 protected:
154  virtual void render(QPainter *painter);
155  virtual void resized();
156 };
157 
159 {
160 public:
161  typedef enum
162  {
166  ColorCyanAndBlue
167  } ColorTheme;
168 
169  LevelMeterSignalDB(QWidget *parent = 0);
170  virtual ~LevelMeterSignalDB();
171 
172  void setColorTheme(ColorTheme colorTheme) { m_colorTheme = colorTheme; }
173  void setRange(int min, int max);
174 
175  static const QColor m_avgColor[4];
176  static const QColor m_decayedPeakColor[4];
177  static const QColor m_peakColor[4];
178 
179 protected:
180  virtual void render(QPainter *painter);
181  virtual void resized();
182 
183  ColorTheme m_colorTheme;
184 };
185 
186 #endif /* SDRBASE_GUI_LEVELMETER_H_ */
qreal m_avgLevel
Definition: levelmeter.h:87
QPixmap * m_backgroundPixmap
Definition: levelmeter.h:136
qreal m_peakHoldLevel
Definition: levelmeter.h:117
virtual void render(QPainter *painter)=0
QTime m_peakLevelChanged
Definition: levelmeter.h:105
unsigned int uint32_t
Definition: rtptypes_win.h:46
ScaleEngine m_scaleEngine
Definition: levelmeter.h:135
#define SDRGUI_API
Definition: export.h:52
QTime m_peakHoldLevelChanged
Definition: levelmeter.h:122
QColor m_avgColor
Definition: levelmeter.h:131
ColorTheme m_colorTheme
Definition: levelmeter.h:183
uint32_t m_avgSmoothing
Definition: levelmeter.h:127
void setColorTheme(ColorTheme colorTheme)
Definition: levelmeter.h:172
int shiftx(int val, int width)
Definition: levelmeter.h:142
QColor m_peakColor
Definition: levelmeter.h:132
qreal m_peakLevel
Definition: levelmeter.h:93
qreal m_peakDecayRate
Definition: levelmeter.h:111
virtual void resized()=0
QColor m_decayedPeakColor
Definition: levelmeter.h:133
QTimer * m_redrawTimer
Definition: levelmeter.h:129
T max(const T &x, const T &y)
Definition: framework.h:446
qreal m_decayedPeakLevel
Definition: levelmeter.h:100
T min(const T &x, const T &y)
Definition: framework.h:440