radioapp/radiowidgets/src/radiofadinglabel.cpp
branchRCL_3
changeset 19 cce62ebc198e
equal deleted inserted replaced
18:1a6714c53019 19:cce62ebc198e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 // User includes
       
    21 #include "radiofadinglabel.h"
       
    22 #include "radiologger.h"
       
    23 #include "radioutil.h"
       
    24 
       
    25 // Constants
       
    26 const QString HIDE_EFFECT = "hide";
       
    27 const QString SHOW_EFFECT = "show";
       
    28 
       
    29 #ifdef USE_DEPRECATED_ORBIT_APIS
       
    30 #   define SET_CONTENT setText
       
    31 #   define GET_CONTENT text
       
    32 #else
       
    33 #   define SET_CONTENT setHtml
       
    34 #   define GET_CONTENT html
       
    35 #endif // USE_DEPRECATED_ORBIT_APIS
       
    36 
       
    37 /*!
       
    38  *
       
    39  */
       
    40 RadioFadingLabel::RadioFadingLabel( QGraphicsItem* parent ) :
       
    41     HbLabel( parent ),
       
    42     mFadingEnabled( false )
       
    43 {
       
    44     QEffectList effectList;
       
    45 //    effectList.append( EffectInfo( this, ":/effects/fade_in.fxml", SHOW_EFFECT ) );
       
    46 //    effectList.append( EffectInfo( this, ":/effects/fade_out.fxml", HIDE_EFFECT ) );
       
    47     RadioUtil::addEffects( effectList );
       
    48 }
       
    49 
       
    50 /*!
       
    51  *
       
    52  */
       
    53 void RadioFadingLabel::setFadingEnabled( bool fading )
       
    54 {
       
    55     mFadingEnabled = fading;
       
    56 }
       
    57 
       
    58 /*!
       
    59  *
       
    60  */
       
    61 void RadioFadingLabel::setTextWithoutFading( const QString& newText )
       
    62 {
       
    63     HbLabel::SET_CONTENT( trimHtml( newText ) );
       
    64     if ( newText.isEmpty() && mFadingEnabled ) {
       
    65         setOpacity( 0.0 );
       
    66     }
       
    67 }
       
    68 
       
    69 /*!
       
    70  * Public slot
       
    71  *
       
    72  */
       
    73 void RadioFadingLabel::setText( const QString& newText )
       
    74 {
       
    75     if( GET_CONTENT().compare( newText ) != 0 &&                   // Text is different
       
    76             parentItem() && parentItem()->isVisible() &&    // Parent is visible
       
    77             mFadingEnabled ) {                              // Fading is enabled
       
    78         if ( newText.isEmpty() ) {
       
    79             if ( isVisible() ) {
       
    80                 mTextHolder = "";
       
    81                 startEffect( HIDE_EFFECT, "effectFinished" );
       
    82             }
       
    83         } else {
       
    84             if ( GET_CONTENT().isEmpty() ) {
       
    85                 HbLabel::SET_CONTENT( trimHtml( newText ) );
       
    86                 startEffect( SHOW_EFFECT );
       
    87             } else {
       
    88                 mTextHolder = newText;
       
    89                 startEffect( HIDE_EFFECT, "effectFinished" );
       
    90             }
       
    91         }
       
    92     } else {
       
    93         HbLabel::SET_CONTENT( trimHtml( newText ) );
       
    94     }
       
    95 }
       
    96 
       
    97 /*!
       
    98  * Private slot
       
    99  *
       
   100  */
       
   101 void RadioFadingLabel::effectFinished( HbEffect::EffectStatus status )
       
   102 {
       
   103     if ( status.reason == Hb::EffectFinished ) {
       
   104         HbLabel::SET_CONTENT( trimHtml( mTextHolder ) );
       
   105         if ( !mTextHolder.isEmpty() ) {
       
   106             HbEffect::start( this, SHOW_EFFECT );
       
   107         }
       
   108         mTextHolder = "";
       
   109     }
       
   110 }
       
   111 
       
   112 /*!
       
   113  *
       
   114  */
       
   115 void RadioFadingLabel::startEffect( const QString& effectName, const char* slot )
       
   116 {
       
   117     if ( HbEffect::effectRunning( this ) ) {
       
   118         HbEffect::cancel( this );
       
   119     }
       
   120     if ( slot ) {
       
   121         HbEffect::start( this, effectName, this, slot );
       
   122     } else {
       
   123         HbEffect::start( this, effectName );
       
   124     }
       
   125 }
       
   126 
       
   127 /*!
       
   128  *
       
   129  */
       
   130 QString RadioFadingLabel::trimHtml( const QString& text )
       
   131 {
       
   132 #ifdef USE_DEPRECATED_ORBIT_APIS
       
   133     return text;
       
   134 #else
       
   135     return "<font color=\"white\">" + text + "</font>";
       
   136 #endif // USE_DEPRECATED_ORBIT_APIS
       
   137 }