1 /* -*- c++ -*- */
2 /* + + +   This Software is released under the "Simplified BSD License"  + + +
3  *
4  * Copyright 2010 Moe Wheatley. All rights reserved.
5  * Copyright 2011-2013 Alexandru Csete OZ9AEC.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  *    1. Redistributions of source code must retain the above copyright notice,
11  *       this list of conditions and the following disclaimer.
12  *
13  *    2. Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in the
15  *       documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY Moe Wheatley ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20  * EVENT SHALL Moe Wheatley OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * The views and conclusions contained in the software and documentation are
29  * those of the authors and should not be interpreted as representing official
30  * policies, either expressed or implied, of Moe Wheatley.
31  */
32 #pragma once
33 
34 #include <QtGui>
35 #include <QFrame>
36 #include <QImage>
37 
38 class CMeter : public QFrame
39 {
40     Q_OBJECT
41 
42 public:
43     explicit CMeter(QWidget *parent = 0);
44     explicit CMeter(float min_level = -100.0, float max_level = 10.0,
45                     QWidget *parent = 0);
46     ~CMeter();
47 
48     QSize minimumSizeHint() const;
49     QSize sizeHint() const;
50 
51     void setMin(float min_level);
52     void setMax(float max_level);
53     void setRange(float min_level, float max_level);
54 
55     void draw();
UpdateOverlay()56     void UpdateOverlay(){DrawOverlay();}
57 
58 public slots:
59     void setLevel(float dbfs);
60     void setSqlLevel(float dbfs);
61 
62 protected:
63     void paintEvent(QPaintEvent *event);
64     void resizeEvent(QResizeEvent* event);
65 
66 private:
67     void DrawOverlay();
68 
69     QFont   m_Font;
70     QPixmap m_2DPixmap;
71     QPixmap m_OverlayPixmap;
72     QSize   m_Size;
73     QString m_Str;
74     qreal   m_pixperdb;     // pixels / dB
75     int     m_Siglevel;
76     int     m_dBFS;
77     qreal   m_Sql;
78     qreal   m_SqlLevel;
79 };
80