1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //  $Id: meter.h,v 1.1.1.1.2.2 2009/05/03 04:14:00 terminator356 Exp $
5 //  redesigned by oget on 2011/08/15
6 //
7 //  (C) Copyright 2000 Werner Schweer (ws@seh.de)
8 //  (C) Copyright 2011 Orcan Ogetbil (ogetbilo at sf.net)
9 //  (C) Copyright 2011-2016 Tim E. Real (terminator356 on users DOT sourceforge DOT net)
10 //
11 //  This program is free software; you can redistribute it and/or
12 //  modify it under the terms of the GNU General Public License
13 //  as published by the Free Software Foundation; version 2 of
14 //  the License, or (at your option) any later version.
15 //
16 //  This program is distributed in the hope that it will be useful,
17 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 //  GNU General Public License for more details.
20 //
21 //  You should have received a copy of the GNU General Public License
22 //  along with this program; if not, write to the Free Software
23 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 //
25 //=========================================================
26 
27 #ifndef __METER_H__
28 #define __METER_H__
29 
30 #include <QFrame>
31 #include <QTimer>
32 #include <QResizeEvent>
33 #include <QMouseEvent>
34 #include <QPainter>
35 #include <QPainterPath>
36 #include <QBitmap>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
39 #include <QSpacerItem>
40 
41 #include "sclif.h"
42 #include "scldraw.h"
43 
44 namespace MusEGui {
45 
46 // -----------------------------------------------
47 //   MeterLayout:
48 //   Convenience class that can align the ends of meters
49 //    with class Slider scale end points, for example.
50 // -----------------------------------------------
51 
52 class MeterLayout : public QVBoxLayout {
53     Q_OBJECT
54 
55     Q_PROPERTY(int endsMargin READ meterEndsMargin WRITE setMeterEndsMargin)
56 
57     int _endsMargin;
58     QHBoxLayout* _hlayout;
59     QSpacerItem* _spacer1;
60     QSpacerItem* _spacer2;
61 
62   public:
63     MeterLayout(int endsMargin = 0, QWidget* parent = nullptr);
64     int meterEndsMargin() const;
65     void setMeterEndsMargin(int m);
66     // This is the horizontal layout where meters can be added.
67     QHBoxLayout* hlayout();
68 };
69 
70 // -----------------------------------------------
71 //   Meter:
72 //   Convenience class that can align the ends of meters
73 //    with class Slider scale end points, for example.
74 // -----------------------------------------------
75 
76 class Meter : public QFrame, public ScaleIf {
77     Q_OBJECT
78 
79     Q_PROPERTY(int radius READ radius WRITE setRadius)
80     Q_PROPERTY(bool vu3d READ vu3d WRITE setVu3d)
81 
82     int _radius;
83     int _vu3d;
84 
85    public:
86       enum MeterType {DBMeter, LinMeter};
87       enum ScalePos { None, Left, Right, Top, Bottom, InsideHorizontal, InsideVertical };
88 
89    private:
90      QColor _primaryColor;
91      QColor _bgColor;
92      bool _frame;
93      QColor _frameColor;
94 
95    protected:
96       QLinearGradient darkGradRed;
97       QColor dark_red_end;
98       QColor dark_red_begin;
99 
100       QLinearGradient darkGradYellow;
101       QColor dark_yellow_end;
102       QColor dark_yellow_center;
103       QColor dark_yellow_begin;
104 
105       QLinearGradient darkGradGreen;
106       QColor dark_green_end;
107       QColor dark_green_begin;
108 
109       QLinearGradient lightGradRed;
110       QColor light_red_end;
111       QColor light_red_begin;
112 
113       QLinearGradient lightGradYellow;
114       QColor light_yellow_end;
115       QColor light_yellow_center;
116       QColor light_yellow_begin;
117 
118       QLinearGradient lightGradGreen;
119       QColor light_green_end;
120       QColor light_green_begin;
121 
122       QLinearGradient maskGrad;
123       QColor mask_center;
124       QColor mask_edge;
125 
126       QColor separator_color;
127       QColor peak_color;
128 //      int xrad, yrad;
129 
130       virtual void resizeEvent(QResizeEvent*);
131       virtual void paintEvent(QPaintEvent*);
132       virtual void mousePressEvent(QMouseEvent*);
133 
134       // Adjust scale so marks are not too close together.
135       void adjustScale();
136 
137    private:
138       MeterType mtype;
139       Qt::Orientation _orient;
140       ScalePos _scalePos;
141       int _refreshRate;
142       int _scaleDist;
143       bool overflow;
144       double val;
145       double targetVal;
146       double targetValStep;
147       double maxVal;
148       double targetMaxVal;
149       double minScale, maxScale;
150       int yellowScale, redScale;
151       int cur_pixv, last_pixv, cur_pixmax, last_pixmax;
152       bool _showText;
153       QString _text;
154       QRect _textRect;
155       void updateText(double val);
156 
157       void drawVU(QPainter& p, const QRect&, const QPainterPath&, int);
158 
159       void scaleChange();
160 
161       QTimer fallingTimer;
162 
163    public slots:
164       void resetPeaks();
165       void setVal(double, double, bool);
166       void updateTargetMeterValue();
167 
168    signals:
169       void mousePress();
170 
171    public:
172       Meter(QWidget* parent,
173             MeterType type = DBMeter,
174             Qt::Orientation orient = Qt::Vertical,
175             double scaleMin = -60.0, double scaleMax = 10.0,
176             ScalePos scalePos = None,
177             const QColor& primaryColor = QColor(0, 255, 0),
178             ScaleDraw::TextHighlightMode textHighlightMode = ScaleDraw::TextHighlightNone,
179             int refreshRate = 20);
180 
181 //      QColor primaryColor() const { return _primaryColor; }
182       void setPrimaryColor(const QColor& color, const QColor& bgColor = Qt::black);
183 
184       void setRange(double min, double max);
185 
186       void setRefreshRate(int rate);
187 
showText()188       bool showText() const { return _showText; }
setShowText(bool v)189       void setShowText(bool v) { _showText = v; update(); }
190 
orientation()191       Qt::Orientation orientation() const { return _orient; }
setOrientation(Qt::Orientation o)192       void setOrientation(Qt::Orientation o) { _orient = o; update(); }
193 
194       virtual QSize sizeHint() const;
195 
radius()196       int radius() const { return _radius; }
setRadius(int radius)197       void setRadius(int radius) { _radius = radius; }
vu3d()198       int vu3d() const { return _vu3d; }
setVu3d(int vu3d)199       void setVu3d(int vu3d) { _vu3d = vu3d; }
200 
setFrame(bool frame,const QColor & color)201       void setFrame(bool frame, const QColor& color) { _frame = frame; _frameColor = color; }
202       };
203 
204 } // namespace MusEGui
205 
206 #endif
207 
208