videocollection/videocollectionview/src/videohintwidget.cpp
changeset 15 cf5481c2bc0b
child 17 69946d1824c4
equal deleted inserted replaced
2:dec420019252 15:cf5481c2bc0b
       
     1 /*
       
     2 * Copyright (c) 2008 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:   Videolist content widget implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbpushbutton.h>
       
    19 #include <hblabel.h>
       
    20 #include <qgraphicsitem.h>
       
    21 #include <hbinstance.h>
       
    22 
       
    23 #include "videohintwidget.h"
       
    24 #include "videocollectionuiloader.h"
       
    25 #include "videocollectionviewutils.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 VideoHintWidget::VideoHintWidget(VideoCollectionUiLoader *uiLoader, QGraphicsItem *parent) :
       
    32 HbWidget(parent),
       
    33 mUiLoader(uiLoader),
       
    34 mServiceIcon(0),
       
    35 mAddVideosIcon(0),
       
    36 mCurrentLevel(AllVideos),
       
    37 mButtonShown(false),
       
    38 mActivated(false)
       
    39 {
       
    40     // NOP
       
    41 }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Destructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 VideoHintWidget::~VideoHintWidget()
       
    48 {
       
    49     delete mServiceIcon;
       
    50     delete mAddVideosIcon;
       
    51 }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // initialize
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 int VideoHintWidget::initialize()
       
    58 {
       
    59     VideoCollectionViewUtils& utils = VideoCollectionViewUtils::instance();
       
    60     return utils.getServiceIconStrings(mServiceIconString, mServiceIconPressedString);
       
    61 }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // setLevel
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void VideoHintWidget::setLevel(HintLevel level)
       
    68 {
       
    69     mCurrentLevel = level;
       
    70     if(mActivated) {
       
    71         updateUiComponents();
       
    72     }
       
    73 }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // setButtonShown
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void VideoHintWidget::setButtonShown(bool shown)
       
    80 {
       
    81     mButtonShown = shown;
       
    82     if(mActivated) {
       
    83         updateUiComponents();
       
    84     }
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // orientationChanged
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void VideoHintWidget::orientationChangedSlot(Qt::Orientation targetOrientation)
       
    92 {
       
    93     Q_UNUSED(targetOrientation);
       
    94     updateUiComponents();
       
    95 }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // activate
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void VideoHintWidget::activate()
       
   102 {
       
   103     if (!mActivated)
       
   104     {
       
   105         if(mServiceIconString.isEmpty() || 
       
   106            mServiceIconPressedString.isEmpty())
       
   107         {
       
   108             return;
       
   109         }
       
   110         
       
   111         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   112         connect(
       
   113             mainWnd, SIGNAL(orientationChanged(Qt::Orientation)),
       
   114             this, SLOT(orientationChangedSlot(Qt::Orientation)));
       
   115         
       
   116         mServiceIcon = new HbIcon(mServiceIconString);
       
   117         mServiceIcon->setIconName(mServiceIconPressedString, QIcon::Normal, QIcon::On);
       
   118         
       
   119         mAddVideosIcon = new HbIcon(":/images/mono_video_addvideos.svg");
       
   120         
       
   121         updateUiComponents();
       
   122         
       
   123         setVisible(true);
       
   124         
       
   125         mActivated = true;
       
   126     }
       
   127 }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // deactivate
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void VideoHintWidget::deactivate()
       
   134 {
       
   135     if (mActivated)
       
   136     {
       
   137         mActivated = false;
       
   138         
       
   139         setVisible(false);
       
   140         
       
   141         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   142         disconnect(
       
   143             mainWnd, SIGNAL(orientationChanged(Qt::Orientation)),
       
   144             this, SLOT(orientationChangedSlot(Qt::Orientation)));
       
   145         
       
   146         HbPushButton *serviceButton =
       
   147             mUiLoader->findWidget<HbPushButton>(
       
   148                 DOCML_NAME_HINT_BUTTON);
       
   149         if (serviceButton)
       
   150         {
       
   151             serviceButton->setIcon(HbIcon());
       
   152         }
       
   153         if(mServiceIcon) {
       
   154             delete mServiceIcon;
       
   155             mServiceIcon = 0;
       
   156         }
       
   157         
       
   158         if(mAddVideosIcon) {
       
   159             delete mAddVideosIcon;
       
   160             mAddVideosIcon = 0;
       
   161         }
       
   162     }
       
   163 }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // updateUiComponents
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void VideoHintWidget::updateUiComponents()
       
   170 {
       
   171     HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   172     if (mainWnd)
       
   173     {
       
   174         HbPushButton *serviceButton =
       
   175             mUiLoader->findWidget<HbPushButton>(
       
   176                 DOCML_NAME_HINT_BUTTON);
       
   177         HbLabel *hintLabel =
       
   178             mUiLoader->findWidget<HbLabel>(
       
   179                 DOCML_NAME_HINT_LABEL);
       
   180         HbLabel *noVideosLabel =
       
   181             mUiLoader->findWidget<HbLabel>(
       
   182                 DOCML_NAME_NO_VIDEOS_LABEL);
       
   183         if (serviceButton && hintLabel && noVideosLabel)
       
   184         {
       
   185             serviceButton->setVisible(mainWnd->orientation() == Qt::Horizontal && mButtonShown);
       
   186             noVideosLabel->setVisible(true);
       
   187             if (mCurrentLevel == Collection)
       
   188             {
       
   189                 hintLabel->setVisible(false);
       
   190                 serviceButton->setIcon(*mAddVideosIcon);
       
   191             }
       
   192             else
       
   193             {               
       
   194                 hintLabel->setVisible(true);
       
   195                 serviceButton->setIcon(*mServiceIcon);
       
   196             }
       
   197         }
       
   198     }
       
   199 }
       
   200 
       
   201 // end of file