qt: restore compatibility for Qt 5.5
[vlc.git] / modules / gui / qt / util / input_slider.cpp
blob741eb26c1a6671fafa4516a19c266504d21ec401
1 /*****************************************************************************
2 * input_slider.cpp : VolumeSlider and SeekSlider
3 ****************************************************************************
4 * Copyright (C) 2006-2011 the VideoLAN team
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ludovic Fauvet <etix@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
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.
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 *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include "qt.hpp"
32 #include "util/input_slider.hpp"
33 #include "util/timetooltip.hpp"
34 #include "adapters/seekpoints.hpp"
35 #include "input_manager.hpp"
36 #include "imagehelper.hpp"
38 #include <QPaintEvent>
39 #include <QPainter>
40 #include <QBitmap>
41 #include <QStyleOptionSlider>
42 #include <QLinearGradient>
43 #include <QTimer>
44 #include <QRadialGradient>
45 #include <QLinearGradient>
46 #include <QSize>
47 #include <QPalette>
48 #include <QColor>
49 #include <QPoint>
50 #include <QPropertyAnimation>
51 #include <QApplication>
52 #include <QDebug>
53 #include <QScreen>
54 #include <QSequentialAnimationGroup>
56 namespace {
57 int const MIN_SLIDER_VALUE = 0;
58 int const MAX_SLIDER_VALUE = 10000;
60 int const CHAPTER_SPOT_SIZE = 3;
62 int const FADE_DURATION = 300;
63 int const FADEOUT_DELAY = 2000;
66 SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
67 : QSlider( q, _parent ), b_classic( _static ), animLoading( NULL )
69 isSliding = false;
70 isJumping = false;
71 f_buffering = 0.0;
72 mHandleOpacity = 1.0;
73 mLoading = 0.0;
74 chapters = NULL;
75 mHandleLength = -1;
76 b_seekable = true;
77 alternativeStyle = NULL;
79 // prepare some static colors
80 QPalette p = palette();
81 QColor background = p.color( QPalette::Active, QPalette::Window );
82 tickpointForeground = p.color( QPalette::Active, QPalette::WindowText );
83 tickpointForeground.setHsv( tickpointForeground.hue(),
84 ( background.saturation() + tickpointForeground.saturation() ) / 2,
85 ( background.value() + tickpointForeground.value() ) / 2 );
87 // set the background color and gradient
88 QColor backgroundBase( p.window().color() );
89 backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) );
90 backgroundGradient.setColorAt( 1.0, backgroundBase );
92 // set the foreground color and gradient
93 QColor foregroundBase( 50, 156, 255 );
94 foregroundGradient.setColorAt( 0.0, foregroundBase );
95 foregroundGradient.setColorAt( 1.0, foregroundBase.darker( 140 ) );
97 // prepare the handle's gradient
98 handleGradient.setColorAt( 0.0, p.window().color().lighter( 120 ) );
99 handleGradient.setColorAt( 0.9, p.window().color().darker( 120 ) );
101 // prepare the handle's shadow gradient
102 QColor shadowBase = p.shadow().color();
103 if( shadowBase.lightness() > 100 )
104 shadowBase = QColor( 60, 60, 60 ); // Palette's shadow is too bright
105 shadowDark = shadowBase.darker( 150 );
106 shadowLight = shadowBase.lighter( 180 );
107 shadowLight.setAlpha( 50 );
109 /* Timer used to fire intermediate updatePos() when sliding */
110 seekLimitTimer = new QTimer( this );
111 seekLimitTimer->setSingleShot( true );
113 /* Tooltip bubble */
114 mTimeTooltip = new TimeTooltip( NULL );
115 mTimeTooltip->setMouseTracking( true );
117 /* Properties */
118 setRange( MIN_SLIDER_VALUE, MAX_SLIDER_VALUE );
119 setSingleStep( 2 );
120 setPageStep( 10 );
121 setMouseTracking( true );
122 setTracking( true );
123 setFocusPolicy( Qt::NoFocus );
125 /* Use the new/classic style */
126 setMinimumHeight( 18 );
127 if( !b_classic )
129 alternativeStyle = new SeekStyle;
130 setStyle( alternativeStyle );
133 /* Init to 0 */
134 setPosition( -1.0, 0, 0 );
135 secstotimestr( psz_length, 0 );
137 animHandle = new QPropertyAnimation( this, "handleOpacity", this );
138 animHandle->setDuration( FADE_DURATION );
139 animHandle->setStartValue( 0.0 );
140 animHandle->setEndValue( 1.0 );
142 QPropertyAnimation *animLoadingIn = new QPropertyAnimation( this, "loadingProperty", this );
143 animLoadingIn->setDuration( 2000 );
144 animLoadingIn->setStartValue( 0.0 );
145 animLoadingIn->setEndValue( 1.0 );
146 animLoadingIn->setEasingCurve( QEasingCurve::OutBounce );
147 QPropertyAnimation *animLoadingOut = new QPropertyAnimation( this, "loadingProperty", this );
148 animLoadingOut->setDuration( 2000 );
149 animLoadingOut->setStartValue( 1.0 );
150 animLoadingOut->setEndValue( 0.0 );
151 animLoadingOut->setEasingCurve( QEasingCurve::OutBounce );
153 animLoading = new QSequentialAnimationGroup( this );
154 animLoading->addAnimation( animLoadingIn );
155 animLoading->addAnimation( animLoadingOut );
156 animLoading->setLoopCount( -1 );
158 hideHandleTimer = new QTimer( this );
159 hideHandleTimer->setSingleShot( true );
160 hideHandleTimer->setInterval( FADEOUT_DELAY );
162 startAnimLoadingTimer = new QTimer( this );
163 startAnimLoadingTimer->setSingleShot( true );
164 startAnimLoadingTimer->setInterval( 500 );
166 CONNECT( MainInputManager::getInstance(), inputChanged( bool ), this , inputUpdated( bool ) );
167 CONNECT( this, sliderMoved( int ), this, startSeekTimer() );
168 CONNECT( seekLimitTimer, timeout(), this, updatePos() );
169 CONNECT( hideHandleTimer, timeout(), this, hideHandle() );
170 CONNECT( startAnimLoadingTimer, timeout(), this, startAnimLoading() );
171 mTimeTooltip->installEventFilter( this );
174 SeekSlider::~SeekSlider()
176 delete chapters;
177 if ( alternativeStyle )
178 delete alternativeStyle;
179 delete mTimeTooltip;
182 /***
183 * \brief Sets the chapters seekpoints adapter
185 * \params SeekPoints initilized with current intf thread
186 ***/
187 void SeekSlider::setChapters( SeekPoints *chapters_ )
189 delete chapters;
190 chapters = chapters_;
191 chapters->setParent( this );
194 /***
195 * \brief Main public method, superseeding setValue. Disabling the slider when neeeded
197 * \param pos Position, between 0 and 1. -1 disables the slider
198 * \param time Elapsed time. Unused
199 * \param legnth Duration time.
200 ***/
201 void SeekSlider::setPosition( float pos, int64_t time, int length )
203 VLC_UNUSED(time);
204 if( pos == -1.0 )
206 setEnabled( false );
207 mTimeTooltip->hide();
208 isSliding = false;
210 else
211 setEnabled( b_seekable );
213 if( !isSliding )
215 setValue( pos * static_cast<float>( maximum() ) );
216 if ( animLoading != NULL && pos >= 0.0f && animLoading->state() != QAbstractAnimation::Stopped )
218 animLoading->stop();
219 mLoading = 0.0f;
224 inputLength = length;
227 void SeekSlider::startSeekTimer()
229 /* Only fire one update, when sliding, every 150ms */
230 if( isSliding && !seekLimitTimer->isActive() )
231 seekLimitTimer->start( 150 );
234 void SeekSlider::updatePos()
236 float f_pos = value() / static_cast<float>( maximum() );
237 emit sliderDragged( f_pos ); /* Send new position to VLC's core */
240 void SeekSlider::updateBuffering( float f_buffering_ )
242 if ( f_buffering_ < f_buffering )
243 bufferingStart = QTime::currentTime();
244 f_buffering = f_buffering_;
245 if ( f_buffering > 0.0 || isEnabled() ) {
246 animLoading->stop();
247 startAnimLoadingTimer->stop();
248 mLoading = 0.0;
250 repaint();
253 void SeekSlider::inputUpdated( bool b_has_input )
255 if ( b_has_input == false ) {
256 animLoading->stop();
257 startAnimLoadingTimer->stop();
258 mLoading = 0.0;
259 repaint();
261 else if ( f_buffering == 0.0 && !isEnabled() )
262 startAnimLoadingTimer->start();
265 void SeekSlider::processReleasedButton()
267 if ( !isSliding && !isJumping ) return;
268 isSliding = false;
269 bool b_seekPending = seekLimitTimer->isActive();
270 seekLimitTimer->stop(); /* We're not sliding anymore: only last seek on release */
271 if ( isJumping )
273 isJumping = false;
274 return;
276 if( b_seekPending && isEnabled() )
277 updatePos();
280 void SeekSlider::mouseReleaseEvent( QMouseEvent *event )
282 if ( event->button() != Qt::LeftButton && event->button() != Qt::MidButton )
284 QSlider::mouseReleaseEvent( event );
285 return;
287 event->accept();
288 processReleasedButton();
291 void SeekSlider::mousePressEvent( QMouseEvent* event )
293 /* Right-click */
294 if ( !isEnabled() ||
295 ( event->button() != Qt::LeftButton && event->button() != Qt::MidButton )
298 QSlider::mousePressEvent( event );
299 return;
302 isJumping = false;
303 /* handle chapter clicks */
304 int i_width = size().width();
305 if ( chapters && inputLength && i_width)
307 if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
309 /* only on chapters zone */
310 if ( event->y() < CHAPTER_SPOT_SIZE ||
311 event->y() > ( size().height() - CHAPTER_SPOT_SIZE ) )
313 QList<SeekPoint> points = chapters->getPoints();
314 int i_selected = -1;
315 bool b_startsnonzero = false; /* as we always starts at 1 */
316 if ( points.count() > 0 ) /* do we need an extra offset ? */
317 b_startsnonzero = ( points.at(0).time > 0 );
318 int i_min_diff = i_width + 1;
319 for( int i = 0 ; i < points.count() ; i++ )
321 int x = points.at(i).time / 1000000.0 / inputLength * i_width;
322 int diff_x = abs( x - event->x() );
323 if ( diff_x < i_min_diff )
325 i_min_diff = diff_x;
326 i_selected = i + ( ( b_startsnonzero )? 1 : 0 );
327 } else break;
329 if ( i_selected && i_min_diff < 4 ) // max 4px around mark
331 chapters->jumpTo( i_selected );
332 event->accept();
333 isJumping = true;
334 return;
340 isSliding = true ;
342 setValue( getValueFromXPos( event->x() ) );
343 emit sliderMoved( value() );
344 event->accept();
347 void SeekSlider::mouseMoveEvent( QMouseEvent *event )
349 if ( ! ( event->buttons() & ( Qt::LeftButton | Qt::MidButton ) ) )
351 /* Handle button release when mouserelease has been hijacked by popup */
352 processReleasedButton();
355 if ( !isEnabled() ) return event->accept();
357 if( isSliding )
359 setValue( getValueFromXPos( event->x() ) );
360 emit sliderMoved( value() );
363 /* Tooltip */
364 if ( inputLength > 0 )
366 int margin = handleLength();
367 int posX = qMax( rect().left() + margin, qMin( rect().right() - margin, event->x() ) );
369 QString chapterLabel;
371 if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
373 QList<SeekPoint> points = chapters->getPoints();
374 int i_selected = -1;
375 for( int i = 0 ; i < points.count() ; i++ )
377 int x = margin + points.at(i).time / 1000000.0 / inputLength * (size().width() - 2*margin);
378 if ( event->x() >= x )
379 i_selected = i;
381 if ( i_selected >= 0 && i_selected < points.size() )
383 chapterLabel = points.at( i_selected ).name;
387 QPoint target( event->globalX() - ( event->x() - posX ),
388 QWidget::mapToGlobal( QPoint( 0, 0 ) ).y() );
389 if( likely( size().width() > handleLength() ) ) {
390 secstotimestr( psz_length, getValuePercentageFromXPos( event->x() ) * inputLength );
391 mTimeTooltip->setTip( target, psz_length, chapterLabel );
394 event->accept();
397 void SeekSlider::wheelEvent( QWheelEvent *event )
399 /* Don't do anything if we are for somehow reason sliding */
400 if( !isSliding && isEnabled() )
402 setValue( value() + event->delta() / 12 ); /* 12 = 8 * 15 / 10
403 Since delta is in 1/8 of ° and mouse have steps of 15 °
404 and that our slider is in 0.1% and we want one step to be a 1%
405 increment of position */
406 emit sliderDragged( value() / static_cast<float>( maximum() ) );
408 event->accept();
411 void SeekSlider::enterEvent( QEvent * )
413 /* Cancel the fade-out timer */
414 hideHandleTimer->stop();
415 /* Only start the fade-in if needed */
416 if( isEnabled() && animHandle->direction() != QAbstractAnimation::Forward )
418 /* If pause is called while not running Qt will complain */
419 if( animHandle->state() == QAbstractAnimation::Running )
420 animHandle->pause();
421 animHandle->setDirection( QAbstractAnimation::Forward );
422 animHandle->start();
424 /* Don't show the tooltip if the slider is disabled or a menu is open */
425 if( isEnabled() && inputLength > 0 && !qApp->activePopupWidget() )
426 mTimeTooltip->show();
429 void SeekSlider::leaveEvent( QEvent * )
431 hideHandleTimer->start();
432 /* Hide the tooltip
433 - if the mouse leave the slider rect (Note: it can still be
434 over the tooltip!)
435 - if another window is on the way of the cursor */
436 if( !rect().contains( mapFromGlobal( QCursor::pos() ) ) ||
437 ( !isActiveWindow() && !mTimeTooltip->isActiveWindow() ) )
439 mTimeTooltip->hide();
443 void SeekSlider::paintEvent( QPaintEvent *ev )
445 if ( alternativeStyle )
447 SeekStyle::SeekStyleOption option;
448 option.initFrom( this );
449 if ( QTime::currentTime() > bufferingStart.addSecs( 1 ) )
450 option.buffering = f_buffering;
451 else
452 option.buffering = 0.0;
453 option.length = inputLength;
454 option.animate = ( animHandle->state() == QAbstractAnimation::Running
455 || hideHandleTimer->isActive() );
456 option.animationopacity = mHandleOpacity;
457 option.animationloading = mLoading;
458 option.sliderPosition = sliderPosition();
459 option.sliderValue = value();
460 option.maximum = maximum();
461 option.minimum = minimum();
462 if ( chapters ) foreach( const SeekPoint &point, chapters->getPoints() )
463 option.points << point.time;
464 QPainter painter( this );
465 style()->drawComplexControl( QStyle::CC_Slider, &option, &painter, this );
467 else
468 QSlider::paintEvent( ev );
471 void SeekSlider::hideEvent( QHideEvent * )
473 mTimeTooltip->hide();
476 bool SeekSlider::eventFilter( QObject *obj, QEvent *event )
478 if( obj == mTimeTooltip )
480 if( event->type() == QEvent::MouseMove )
482 QMouseEvent* mev = static_cast<QMouseEvent*>( event );
484 if( rect().contains( mapFromGlobal( mev->globalPos() ) ) )
485 return false;
488 if( event->type() == QEvent::Leave ||
489 event->type() == QEvent::MouseMove )
491 mTimeTooltip->hide();
494 return false;
497 return QSlider::eventFilter( obj, event );
500 QSize SeekSlider::sizeHint() const
502 if ( b_classic )
503 return QSlider::sizeHint();
504 return ( orientation() == Qt::Horizontal ) ? QSize( 100, 18 )
505 : QSize( 18, 100 );
508 qreal SeekSlider::handleOpacity() const
510 return mHandleOpacity;
513 qreal SeekSlider::loading() const
515 return mLoading;
518 void SeekSlider::setHandleOpacity(qreal opacity)
520 mHandleOpacity = opacity;
521 /* Request a new paintevent */
522 update();
525 void SeekSlider::setLoading(qreal loading)
527 mLoading = loading;
528 /* Request a new paintevent */
529 update();
532 inline int SeekSlider::handleLength()
534 if ( mHandleLength > 0 )
535 return mHandleLength;
537 /* Ask for the length of the handle to the underlying style */
538 QStyleOptionSlider option;
539 initStyleOption( &option );
540 mHandleLength = style()->pixelMetric( QStyle::PM_SliderLength, &option );
541 return mHandleLength;
544 inline int SeekSlider::getValueFromXPos( int posX )
546 return QStyle::sliderValueFromPosition(
547 minimum(), maximum(),
548 posX - handleLength() / 2,
549 width() - handleLength(),
550 false
554 inline float SeekSlider::getValuePercentageFromXPos( int posX )
556 return getValueFromXPos( posX ) / static_cast<float>( maximum() );
559 void SeekSlider::hideHandle()
561 /* If pause is called while not running Qt will complain */
562 if( animHandle->state() == QAbstractAnimation::Running )
563 animHandle->pause();
564 /* Play the animation backward */
565 animHandle->setDirection( QAbstractAnimation::Backward );
566 animHandle->start();
569 void SeekSlider::startAnimLoading()
571 animLoading->start();
574 /* This work is derived from Amarok's work under GPLv2+
575 - Mark Kretschmann
576 - Gábor Lehel
578 #define WLENGTH 85 // px
579 #define WHEIGHT 26 // px
580 #define PADDINGL 6 // px
581 #define PADDINGR 6 // px
582 #define SOUNDMIN 0 // %
584 SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
585 char *psz_colors, int max )
586 : QAbstractSlider( _parent )
588 f_step = (float)(_i_step * 10000)
589 / (float)((max - SOUNDMIN) * AOUT_VOLUME_DEFAULT);
590 setRange( SOUNDMIN, max);
591 setMouseTracking( true );
592 isSliding = false;
593 b_mouseOutside = true;
594 b_isMuted = false;
596 setFixedSize( WLENGTH, WHEIGHT );
598 pixOutside = ImageHelper::loadSvgToPixmap(":/toolbar/volslide-outside.svg", width(), height() );
600 const QPixmap temp = ImageHelper::loadSvgToPixmap(":/toolbar/volslide-inside.svg", width(), height() );
601 const QBitmap mask( temp.createHeuristicMask() );
603 pixGradient = QPixmap( pixOutside.size() );
604 pixGradient2 = QPixmap( pixOutside.size() );
605 #if HAS_QT56
606 pixGradient.setDevicePixelRatio(QApplication::primaryScreen()->devicePixelRatio());
607 pixGradient2.setDevicePixelRatio(QApplication::primaryScreen()->devicePixelRatio());
608 #endif
610 /* Gradient building from the preferences */
611 QLinearGradient gradient( PADDINGL, 2, width() - PADDINGR, 2 );
612 QLinearGradient gradient2( PADDINGL, 2, width()- PADDINGR, 2 );
614 QStringList colorList = qfu( psz_colors ).split( ";" );
615 free( psz_colors );
617 /* Fill with 255 if the list is too short */
618 if( colorList.count() < 12 )
619 for( int i = colorList.count(); i < 12; i++)
620 colorList.append( "255" );
622 background = palette().color( QPalette::Active, QPalette::Window );
623 foreground = palette().color( QPalette::Active, QPalette::WindowText );
624 foreground.setHsv( foreground.hue(),
625 ( background.saturation() + foreground.saturation() ) / 2,
626 ( background.value() + foreground.value() ) / 2 );
628 textfont.setPointSize( 7 );
629 textrect.setRect( 0, 0, 34, 15 );
631 /* Regular colors */
632 #define c(i) colorList.at(i).toInt()
633 #define add_color(gradient, range, c1, c2, c3) \
634 gradient.setColorAt( range, QColor( c(c1), c(c2), c(c3) ) );
636 /* Desaturated colors */
637 #define desaturate(c) c->setHsvF( c->hueF(), 0.2 , 0.5, 1.0 )
638 #define add_desaturated_color(gradient, range, c1, c2, c3) \
639 foo = new QColor( c(c1), c(c2), c(c3) );\
640 desaturate( foo ); gradient.setColorAt( range, *foo );\
641 delete foo;
643 /* combine the two helpers */
644 #define add_colors( gradient1, gradient2, range, c1, c2, c3 )\
645 add_color( gradient1, range, c1, c2, c3 ); \
646 add_desaturated_color( gradient2, range, c1, c2, c3 );
648 float f_mid_point = ( 100.0 / maximum() );
649 QColor * foo;
650 add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
651 add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
652 add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
653 add_colors( gradient, gradient2, 1.0, 9, 10, 11 );
655 painter.begin( &pixGradient );
656 painter.setPen( Qt::NoPen );
657 painter.setBrush( gradient );
658 painter.drawRect( pixGradient.rect() );
659 painter.end();
661 painter.begin( &pixGradient2 );
662 painter.setPen( Qt::NoPen );
663 painter.setBrush( gradient2 );
664 painter.drawRect( pixGradient2.rect() );
665 painter.end();
667 pixGradient.setMask( mask );
668 pixGradient2.setMask( mask );
671 void SoundSlider::wheelEvent( QWheelEvent *event )
673 int newvalue = value() + event->delta() / ( 8 * 15 ) * f_step;
674 setValue( __MIN( __MAX( minimum(), newvalue ), maximum() ) );
676 emit sliderReleased();
677 emit sliderMoved( value() );
680 void SoundSlider::mousePressEvent( QMouseEvent *event )
682 if( event->button() != Qt::RightButton )
684 /* We enter the sliding mode */
685 isSliding = true;
686 i_oldvalue = value();
687 emit sliderPressed();
688 changeValue( event->x() );
689 emit sliderMoved( value() );
693 void SoundSlider::processReleasedButton()
695 if( !b_mouseOutside && value() != i_oldvalue )
697 emit sliderReleased();
698 setValue( value() );
699 emit sliderMoved( value() );
701 isSliding = false;
702 b_mouseOutside = false;
705 void SoundSlider::mouseReleaseEvent( QMouseEvent *event )
707 if( event->button() != Qt::RightButton )
708 processReleasedButton();
711 void SoundSlider::mouseMoveEvent( QMouseEvent *event )
713 /* handle mouserelease hijacking */
714 if ( isSliding && ( event->buttons() & ~Qt::RightButton ) == Qt::NoButton )
715 processReleasedButton();
717 if( isSliding )
719 QRect rect( PADDINGL - 15, -1,
720 width() - PADDINGR + 15 * 2 , width() + 5 );
721 if( !rect.contains( event->pos() ) )
722 { /* We are outside */
723 if ( !b_mouseOutside )
724 setValue( i_oldvalue );
725 b_mouseOutside = true;
727 else
728 { /* We are inside */
729 b_mouseOutside = false;
730 changeValue( event->x() );
731 emit sliderMoved( value() );
734 else
736 int i = ( ( event->x() - PADDINGL ) * maximum() ) / ( width() - ( PADDINGR + PADDINGL ) );
737 i = __MIN( __MAX( 0, i ), maximum() );
738 setToolTip( QString("%1 %" ).arg( i ) );
742 void SoundSlider::changeValue( int x )
744 setValue( ( ( x - PADDINGL ) * maximum() ) / ( width() - ( PADDINGR + PADDINGL ) ) );
747 void SoundSlider::setMuted( bool m )
749 b_isMuted = m;
750 update();
753 void SoundSlider::paintEvent( QPaintEvent *e )
755 QPixmap *paintGradient;
756 if (b_isMuted)
757 paintGradient = &this->pixGradient2;
758 else
759 paintGradient = &this->pixGradient;
761 painter.begin( this );
763 float f_scale = paintGradient->width() / float( width() );
764 const int offsetDst = int( ( ( width() - ( PADDINGR + PADDINGL ) ) * value() + 100 ) / maximum() ) + PADDINGL;
765 const int offsetSrc = int( ( ( paintGradient->width() - ( PADDINGR + PADDINGL ) * f_scale ) * value() + 100 ) / maximum() + PADDINGL * f_scale );
767 painter.drawPixmap( 0, 0, offsetDst, height(), *paintGradient, 0, 0, offsetSrc, paintGradient->height() );
768 painter.drawPixmap( 0, 0, width(), height(), pixOutside, 0, 0, pixOutside.width(), pixOutside.height() );
770 painter.setPen( foreground );
771 painter.setFont( textfont );
772 painter.drawText( textrect, Qt::AlignRight | Qt::AlignVCenter,
773 QString::number( value() ) + '%' );
775 painter.end();
776 e->accept();