1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #include "QcLevelIndicator.h"
23 #include "../QcWidgetFactory.h"
27 static QcWidgetFactory
<QcLevelIndicator
> factory
;
29 QcLevelIndicator::QcLevelIndicator()
30 : _value( 0.f
), _warning(0.6), _critical(0.8),
31 _peak( 0.f
), _drawPeak( false ),
32 _ticks(0), _majorTicks(0),
35 _clipTimer
= new QTimer( this );
36 _clipTimer
->setSingleShot(true);
37 _clipTimer
->setInterval( 1000 );
38 connect( _clipTimer
, SIGNAL(timeout()), this, SLOT(clipTimeout()) );
41 void QcLevelIndicator::clipTimeout()
48 void QcLevelIndicator::paintEvent( QPaintEvent
*e
)
52 QPalette plt
= palette();
54 bool vertical
= height() >= width();
56 float groove
= vertical
? width() : height();
57 if( _ticks
|| _majorTicks
) groove
-= 6;
59 float length
= vertical
? height() : width();
61 float colorValue
= _drawPeak
? _peak
: _value
;
63 if( colorValue
> _critical
) {
72 c
= QColor(255,100,0);
73 else if( colorValue
> _warning
)
74 c
= QColor( 255, 255, 0 );
76 c
= QColor( 0, 255, 0 );
78 p
.fillRect( vertical
? QRectF(0,0,groove
,height()) : QRectF(0,0,width(),groove
),
79 QColor( 130,130,130 ) );
85 r
.setY( (1.f
- _value
) * length
);
86 r
.setBottom( height() );
89 r
.setHeight( groove
);
90 r
.setRight( _value
* length
);
101 y
= (1.f
- _value
) * h
;
103 p
.fillRect( r
, QColor( 130,130,130 ) );
107 if( v
> _critical
) {
109 y
= (1.f
- _critical
) * h
;
111 p
.fillRect( r
, QColor(255,100,0) );
117 y
= (1.f
- _warning
) * h
;
119 p
.fillRect( r
, QColor( 255, 255, 0 ) );
126 p
.fillRect( r
, QColor( 0, 255, 0 ) );
130 if( _drawPeak
&& _peak
> 0.f
) {
131 float peak
= vertical
? _peak
: 1 - _peak
;
133 // compensate for border and peak line width
134 float val
= (1.f
- peak
)
137 QPen
pen( QColor( 255, 200, 0 ) );
141 p
.drawLine( 0.f
, val
, groove
- 1, val
);
143 p
.drawLine( val
, 0.f
, val
, groove
- 1 );
147 p
.setPen( QColor( 170, 170, 170 ) );
148 float dVal
= ( _ticks
> 1 ) ? ( length
-1) / (float)(_ticks
-1) : 0.f
;
150 while( t
< _ticks
) {
153 p
.drawLine( groove
, v
, width(), v
);
155 p
.drawLine( v
, groove
, v
, height() );
161 QPen
pen ( QColor( 170, 170, 170 ) );
164 float dVal
= ( _majorTicks
> 1 ) ? (length
-3) / (float)(_majorTicks
-1) : 0.f
;
166 while( t
< _majorTicks
) {
167 float v
= (int) (t
* dVal
) + 1;
169 p
.drawLine( groove
, v
, width(), v
);
171 p
.drawLine( v
, groove
, v
, height() );
177 r
= rect().adjusted(0,0,0,-1);
178 r
.setWidth( groove
- 1 );
180 r
= rect().adjusted(0,0,-1,0);
181 r
.setHeight( groove
- 1 );
184 p
.setBrush( Qt::NoBrush
);
185 p
.setPen( plt
.color( QPalette::Dark
) );