#include <QPaintEvent>
#include <QPainter>
-
+#include <QBitmap>
#include <QStyle>
+
InputSlider::InputSlider( QWidget *_parent ) : DirectSlider( _parent )
{
InputSlider::InputSlider( Qt::Horizontal, _parent );
}
#define WLENGTH 100 // px
-#define WHEIGHT 25 // px
+#define WHEIGHT 28 // px
#define SOUNDMIN 0 // %
#define SOUNDMAX 200 // % OR 400 ?
-#define SOUNDSTEP 5 // %
-SoundSlider::SoundSlider( QWidget *_parent, bool b_hard ) : QAbstractSlider( _parent )
+SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard )
+ : QAbstractSlider( _parent )
{
- padding = 5;
+ padding = 3;
+
+ f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX );
- pixGradient = QPixmap( QSize( WLENGTH, WHEIGHT ) );
-// QBixmap mask = QBitmap( QPixmap );
+ pixOutside = QPixmap( ":/pixmaps/volume-slider-outside.png" );
+
+ const QPixmap temp( ":/pixmaps/volume-slider-inside.png" );
+ const QBitmap mask( temp.createHeuristicMask() );
+
+ setMinimumSize( pixOutside.size() );
+
+ pixGradient = QPixmap( mask.size() );
QPainter p( &pixGradient );
- QLinearGradient gradient( 0, 0, WLENGTH, WHEIGHT );
+ QLinearGradient gradient( padding, 2, WLENGTH , 2 );
gradient.setColorAt( 0.0, Qt::white );
- gradient.setColorAt( 1.0, Qt::blue );
+ gradient.setColorAt( 0.2, QColor( 20, 226, 20 ) );
+ gradient.setColorAt( 0.5, QColor( 255, 176, 15 ) );
+ gradient.setColorAt( 1.0, QColor( 235, 30, 20 ) );
p.setPen( Qt::NoPen );
p.setBrush( gradient );
-//static const QPointF points[3] = { QPointF( 0.0, WHEIGHT ),
- // QPointF( WLENGTH, WHEIGHT ), QPointF( WLENGTH, 0.0 ) };
-
- // p.drawConvexPolygon( points, 3 );
-
p.drawRect( pixGradient.rect() );
p.end();
- // pixGradient.setMask( mask );
+ pixGradient.setMask( mask );
}
void SoundSlider::wheelEvent( QWheelEvent *event )
{
- int newvalue = value() + event->delta() / ( 8 * 15 ) * SOUNDSTEP;
+ int newvalue = value() + event->delta() / ( 8 * 15 ) * f_step;
setValue( __MIN( __MAX( minimum(), newvalue ), maximum() ) );
emit sliderReleased();
if( b_sliding )
{
QRect rect( padding - 15, padding - 1,
- WLENGTH + 15 * 2, WHEIGHT + 2 );
+ WLENGTH + 15 * 2, WHEIGHT + 4 );
if( !rect.contains( event->pos() ) )
{ /* We are outside */
if ( !b_outside )
{
QPainter painter( this );
const int offset = int( double( ( width() - 2 * padding ) * value() ) / maximum() );
- const QRectF boundsG( padding, 0, offset , pixGradient.height() );
+
+ const QRectF boundsG( 0, 0, offset , pixGradient.height() );
painter.drawPixmap( boundsG, pixGradient, boundsG );
- painter.end();
-/* QPainter painter( this );
- printf( "%i\n", value() );
-
- QLinearGradient gradient( 0.0, 0.0, WLENGTH, WHEIGHT );
- gradient.setColorAt( 0.0, Qt::white );
- gradient.setColorAt( 1.0, Qt::blue );
+ const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() );
+ painter.drawPixmap( boundsO, pixOutside, boundsO );
- painter.setPen( QPen( QBrush( Qt::black ), 0, Qt::SolidLine, Qt::RoundCap ) );
- painter.setBrush( gradient );
- painter.setRenderHint( QPainter::Antialiasing );
-
- painter.end();*/
+ painter.end();
}