1 /*****************************************************************************
2 * input_manager.cpp : Manage an input and interact with its GUI elements
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "util/input_slider.hpp"
27 #include <QPaintEvent>
31 InputSlider::InputSlider( QWidget *_parent ) : DirectSlider( _parent )
33 InputSlider::InputSlider( Qt::Horizontal, _parent );
36 InputSlider::InputSlider( Qt::Orientation q,QWidget *_parent ) :
37 DirectSlider( q, _parent )
41 setMouseTracking(true);
46 CONNECT( this, valueChanged(int), this, userDrag( int ) );
49 void InputSlider::setPosition( float pos, int a, int b )
56 setValue( (int)(pos * 1000.0 ) );
61 void InputSlider::userDrag( int new_value )
63 float f_pos = (float)(new_value)/1000.0;
66 emit sliderDragged( f_pos );
70 void InputSlider::mouseMoveEvent(QMouseEvent *event)
72 char psz_length[MSTRTIME_MAX_SIZE];
73 secstotimestr( psz_length, ( event->x() * inputLength) / size().width() );
74 setToolTip( psz_length );
77 #define WLENGTH 100 // px
78 #define WHEIGHT 25 // px
79 #define SOUNDMIN 0 // %
80 #define SOUNDMAX 200 // % OR 400 ?
82 SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard )
83 : QAbstractSlider( _parent )
86 f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
87 setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX );
89 pixGradient = QPixmap( QSize( WLENGTH, WHEIGHT ) );
90 // QBixmap mask = QBitmap( QPixmap );
92 QPainter p( &pixGradient );
93 QLinearGradient gradient( 0, 0, WLENGTH, WHEIGHT );
94 gradient.setColorAt( 0.0, Qt::white );
95 gradient.setColorAt( 1.0, Qt::blue );
96 p.setPen( Qt::NoPen );
97 p.setBrush( gradient );
99 //static const QPointF points[3] = { QPointF( 0.0, WHEIGHT ),
100 // QPointF( WLENGTH, WHEIGHT ), QPointF( WLENGTH, 0.0 ) };
102 // p.drawConvexPolygon( points, 3 );
104 p.drawRect( pixGradient.rect() );
107 // pixGradient.setMask( mask );
110 void SoundSlider::wheelEvent( QWheelEvent *event )
112 int newvalue = value() + event->delta() / ( 8 * 15 ) * f_step;
113 setValue( __MIN( __MAX( minimum(), newvalue ), maximum() ) );
115 emit sliderReleased();
118 void SoundSlider::mousePressEvent( QMouseEvent *event )
120 if( event->button() != Qt::RightButton )
122 /* We enter the sliding mode */
124 i_oldvalue = value();
125 emit sliderPressed();
129 void SoundSlider::mouseReleaseEvent( QMouseEvent *event )
131 if( event->button() != Qt::RightButton )
133 if( !b_outside && value() != i_oldvalue )
135 emit sliderReleased();
143 void SoundSlider::mouseMoveEvent( QMouseEvent *event )
147 QRect rect( padding - 15, padding - 1,
148 WLENGTH + 15 * 2, WHEIGHT + 2 );
149 if( !rect.contains( event->pos() ) )
150 { /* We are outside */
152 setValue( i_oldvalue );
156 { /* We are inside */
158 changeValue( event->x() - padding );
159 emit sliderMoved( value() );
166 void SoundSlider::changeValue( int x )
168 setValue( QStyle::sliderValueFromPosition(
169 minimum(), maximum(), x, width() - 2 * padding ) );
172 void SoundSlider::paintEvent(QPaintEvent *e)
174 QPainter painter( this );
175 const int offset = int( double( ( width() - 2 * padding ) * value() ) / maximum() );
176 const QRectF boundsG( padding, 0, offset , pixGradient.height() );
177 painter.drawPixmap( boundsG, pixGradient, boundsG );
180 /* QPainter painter( this );
181 printf( "%i\n", value() );
183 QLinearGradient gradient( 0.0, 0.0, WLENGTH, WHEIGHT );
184 gradient.setColorAt( 0.0, Qt::white );
185 gradient.setColorAt( 1.0, Qt::blue );
187 painter.setPen( QPen( QBrush( Qt::black ), 0, Qt::SolidLine, Qt::RoundCap ) );
188 painter.setBrush( gradient );
189 painter.setRenderHint( QPainter::Antialiasing );