From 9b533f055a592821c73baecea90ee910e06e852c Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Thu, 19 Feb 2009 15:03:23 +0000 Subject: [PATCH] rewrote timing of fading animation for not postponing updates of hidden fadeButton until it becomes visible (stable backport) git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/branches/lmms/stable-0.4@2058 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 11 ++++++++++ include/fade_button.h | 6 +++--- src/gui/widgets/fade_button.cpp | 36 ++++++++++++++------------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index d55166477..6014caa67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2009-02-19 Tobias Doerffel + * include/fade_button.h: + * src/gui/widgets/fade_button.cpp: + rewrote timing of fading animation for not postponing updates of + hidden fadeButton until it becomes visible + + * src/gui/widgets/automatable_button.cpp: + * src/core/track.cpp: + make sure all buttons in trackOperationsWidget have focus-policy + set to Qt::NoFocus in order to make space play song even if you clicked + e.g. a mute-button (closes #2486211) + * include/note.h: * src/core/note.cpp: - coding style fixes diff --git a/include/fade_button.h b/include/fade_button.h index 44080df0e..b4001773c 100644 --- a/include/fade_button.h +++ b/include/fade_button.h @@ -1,7 +1,7 @@ /* * fade_button.h - declaration of class fadeButton * - * Copyright (c) 2005-2007 Tobias Doerffel + * Copyright (c) 2005-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -26,6 +26,7 @@ #ifndef _FADE_BUTTON_H #define _FADE_BUTTON_H +#include #include #include @@ -42,7 +43,6 @@ public: public slots: void activate( void ); - void reset( void ); protected: @@ -51,7 +51,7 @@ protected: private: - float m_state; + QTime m_stateTimer; QColor m_normalColor; QColor m_activatedColor; diff --git a/src/gui/widgets/fade_button.cpp b/src/gui/widgets/fade_button.cpp index d604b7c9f..3af7ffe04 100644 --- a/src/gui/widgets/fade_button.cpp +++ b/src/gui/widgets/fade_button.cpp @@ -3,7 +3,7 @@ /* * fade_button.cpp - implementation of fade-button * - * Copyright (c) 2005-2008 Tobias Doerffel + * Copyright (c) 2005-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -35,15 +35,19 @@ #include "update_event.h" +const float FadeDuration = 300; + + fadeButton::fadeButton( const QColor & _normal_color, const QColor & _activated_color, QWidget * _parent ) : QAbstractButton( _parent ), - m_state( 0.0f ), + m_stateTimer(), m_normalColor( _normal_color ), m_activatedColor( _activated_color ) { setAttribute( Qt::WA_OpaquePaintEvent, true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 0, 0 ) ); + setFocusPolicy( Qt::NoFocus ); } @@ -58,21 +62,12 @@ fadeButton::~fadeButton() void fadeButton::activate( void ) { - m_state = 1.00f; + m_stateTimer.restart(); signalUpdate(); } -void fadeButton::reset( void ) -{ - m_state = 0.0f; - signalUpdate(); -} - - - - void fadeButton::customEvent( QEvent * ) { @@ -85,20 +80,19 @@ void fadeButton::customEvent( QEvent * ) void fadeButton::paintEvent( QPaintEvent * _pe ) { QColor col = m_normalColor; - if( m_state > 0.0f ) + if( m_stateTimer.elapsed() < FadeDuration ) { + const float state = 1 - m_stateTimer.elapsed() / FadeDuration; const int r = (int)( m_normalColor.red() * - ( 1.0f - m_state ) + - m_activatedColor.red() * m_state ); + ( 1.0f - state ) + + m_activatedColor.red() * state ); const int g = (int)( m_normalColor.green() * - ( 1.0f - m_state ) + - m_activatedColor.green() * m_state ); + ( 1.0f - state ) + + m_activatedColor.green() * state ); const int b = (int)( m_normalColor.blue() * - ( 1.0f - m_state ) + - m_activatedColor.blue() * m_state ); + ( 1.0f - state ) + + m_activatedColor.blue() * state ); col.setRgb( r, g, b ); - - m_state -= 0.1f; QTimer::singleShot( 20, this, SLOT( update() ) ); }