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 ?
81 #define SOUNDSTEP 5 // %
83 SoundSlider::SoundSlider( QWidget *_parent ) : QAbstractSlider( _parent )
86 setRange( SOUNDMIN, SOUNDMAX );
88 pixGradient = QPixmap( QSize( WLENGTH, WHEIGHT ) );
89 // QBixmap mask = QBitmap( QPixmap );
91 QPainter p( &pixGradient );
92 QLinearGradient gradient( 0, 0, WLENGTH, WHEIGHT );
93 gradient.setColorAt( 0.0, Qt::white );
94 gradient.setColorAt( 1.0, Qt::blue );
95 p.setPen( Qt::NoPen );
96 p.setBrush( gradient );
98 //static const QPointF points[3] = { QPointF( 0.0, WHEIGHT ),
99 // QPointF( WLENGTH, WHEIGHT ), QPointF( WLENGTH, 0.0 ) };
101 // p.drawConvexPolygon( points, 3 );
103 p.drawRect( pixGradient.rect() );
106 // pixGradient.setMask( mask );
109 void SoundSlider::wheelEvent( QWheelEvent *event )
111 int newvalue = value() + event->delta() / ( 8 * 15 ) * SOUNDSTEP;
112 setValue( __MIN( __MAX( minimum(), newvalue ), maximum() ) );
114 emit sliderReleased();
117 void SoundSlider::mousePressEvent( QMouseEvent *event )
119 if( event->button() != Qt::RightButton )
121 /* We enter the sliding mode */
123 i_oldvalue = value();
124 emit sliderPressed();
128 void SoundSlider::mouseReleaseEvent( QMouseEvent *event )
130 if( event->button() != Qt::RightButton )
132 if( !b_outside && value() != i_oldvalue )
134 emit sliderReleased();
142 void SoundSlider::mouseMoveEvent( QMouseEvent *event )
146 QRect rect( padding - 15, padding - 1,
147 WLENGTH + 15 * 2, WHEIGHT + 2 );
148 if( !rect.contains( event->pos() ) )
149 { /* We are outside */
151 setValue( i_oldvalue );
155 { /* We are inside */
157 changeValue( event->x() - padding );
158 emit sliderMoved( value() );
165 void SoundSlider::changeValue( int x )
167 setValue( QStyle::sliderValueFromPosition(
168 minimum(), maximum(), x, width() - 2 * padding ) );
171 void SoundSlider::paintEvent(QPaintEvent *e)
173 QPainter painter( this );
174 const int offset = int( double( ( width() - 2 * padding ) * value() ) / maximum() );
175 const QRectF boundsG( padding, 0, offset , pixGradient.height() );
176 painter.drawPixmap( boundsG, pixGradient, boundsG );
179 /* QPainter painter( this );
180 printf( "%i\n", value() );
182 QLinearGradient gradient( 0.0, 0.0, WLENGTH, WHEIGHT );
183 gradient.setColorAt( 0.0, Qt::white );
184 gradient.setColorAt( 1.0, Qt::blue );
186 painter.setPen( QPen( QBrush( Qt::black ), 0, Qt::SolidLine, Qt::RoundCap ) );
187 painter.setBrush( gradient );
188 painter.setRenderHint( QPainter::Antialiasing );