logsui/logsapp/src/logspageindicatoritem.cpp
changeset 0 4a5361db8937
child 4 e52d42f9500c
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     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 #include <QGraphicsColorizeEffect>
       
    19 #include <QPropertyAnimation>
       
    20 
       
    21 #include "logspageindicatoritem.h"
       
    22 
       
    23 
       
    24 const char logsNormalIconName[]    = "qtg_graf_hspage_normal";//"qtg_mono_tab_passive";//
       
    25 const char logsHighlightIconName[] = "qtg_graf_hspage_highlight";//"qtg_mono_tab_active";//
       
    26   
       
    27 const int logsEffectDurationInMs = 1000;
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 LogsPageIndicatorItem::LogsPageIndicatorItem(bool active, QGraphicsItem *parent)
       
    34   : HbIconItem(parent),
       
    35     mIsActive(active)
       
    36 {
       
    37     if (active) {
       
    38         setIcon(HbIcon(logsHighlightIconName));
       
    39     } else {
       
    40         setIcon(HbIcon(logsNormalIconName));
       
    41     }
       
    42 
       
    43     QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect;
       
    44     effect->setColor(Qt::white);
       
    45     effect->setStrength(0);
       
    46     effect->setEnabled(false);
       
    47     setGraphicsEffect(effect);
       
    48 }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 LogsPageIndicatorItem::~LogsPageIndicatorItem()
       
    55 {
       
    56 }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void LogsPageIndicatorItem::setActive(bool active)
       
    63 {
       
    64     if (mIsActive != active) {
       
    65         mIsActive = active;
       
    66         if (mIsActive) {
       
    67             setIcon(HbIcon(logsHighlightIconName));
       
    68             startAnimation();
       
    69         } else {
       
    70             setIcon(HbIcon(logsNormalIconName));
       
    71         }
       
    72     }
       
    73 }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 bool LogsPageIndicatorItem::isActive() const
       
    80 {
       
    81     return mIsActive;
       
    82 }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void LogsPageIndicatorItem::startAnimation()
       
    89 {
       
    90     graphicsEffect()->setEnabled(true);
       
    91     setTransformOriginPoint(rect().center());
       
    92     QPropertyAnimation *animation = 
       
    93         new QPropertyAnimation(graphicsEffect(), "strength");
       
    94     animation->setDuration(logsEffectDurationInMs);
       
    95     animation->setKeyValueAt(0.2, 1);
       
    96     animation->setEndValue(0);
       
    97     connect(animation, SIGNAL(finished()), SLOT(animationFinished()));
       
    98     animation->start(QAbstractAnimation::DeleteWhenStopped);
       
    99 }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void LogsPageIndicatorItem::animationFinished()
       
   106 {
       
   107     graphicsEffect()->setEnabled(false);
       
   108 }