qtinternetradio/ui/src/irnowplayingcontainer.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     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 #include <HbTextItem>
       
    18 #include <HbLabel>
       
    19 #include <hbeffect.h>
       
    20 #include <hbinstance.h>
       
    21 #include <QGraphicsSceneEvent>
       
    22 #include <hbmarqueeitem.h>
       
    23 #include <QTimer>
       
    24 
       
    25 #include "irnowplayingcontainer.h"
       
    26 #include "iruidefines.h"
       
    27 
       
    28 
       
    29 // Const strings
       
    30 const char* NOW_PLAYING_CONTAINER_OBJECT_NAME = "ex-IRNowPlayingContainer"; // object name in the XML
       
    31 
       
    32 /*
       
    33  * Description : constructor
       
    34  */
       
    35 IRNowPlayingContainer::IRNowPlayingContainer(QObject *aLoaderParent, QGraphicsItem *aParent) :
       
    36     HbWidget(aParent), iLoader(aLoaderParent), iStationName(NULL),
       
    37     iCategory(NULL),
       
    38     iSongName(NULL),
       
    39     iAdvImage(NULL),
       
    40     iLogo(NULL)
       
    41 {
       
    42     // Create widget hierarchy
       
    43     setObjectName(NOW_PLAYING_CONTAINER_OBJECT_NAME);
       
    44 
       
    45     // List existing root elements - this allows us to refer to objects in the XML 
       
    46     // which are created outside the document.
       
    47     QObjectList roots;
       
    48     roots.append(this); // IRNowPlayingContainer is referred in the XML document
       
    49     iLoader.setObjectTree(roots);
       
    50 
       
    51     // Load the XML file
       
    52     iLoader.load(NOW_PLAYING_CONTAINER_LAYOUT_FILENAME);
       
    53 
       
    54     // Find the HbLabel objects
       
    55     iStationName = qobject_cast<HbTextItem *> (iLoader.findObject("stationName"));
       
    56     iStationName->setMaximumLines(2);
       
    57     iCategory = qobject_cast<HbTextItem *> (iLoader.findObject("category"));
       
    58     iCategory->setMaximumLines(2);
       
    59     iSongName = qobject_cast<HbMarqueeItem *> (iLoader.findObject("artistNsongName"));
       
    60     iAdvImage = qobject_cast<HbLabel *> (iLoader.findObject("advertisementImage"));
       
    61     iLogo = qobject_cast<HbLabel *> (iLoader.findObject("stationIcon"));
       
    62 
       
    63     // Set the wrap method
       
    64     iStationName->setTextWrapping(Hb::TextWordWrap);
       
    65     iCategory->setTextWrapping(Hb::TextWordWrap);
       
    66     iSongName->setLoopCount(-1);
       
    67 
       
    68     // Get the display direction
       
    69     constructContainer();
       
    70 }
       
    71 
       
    72 IRNowPlayingContainer::~IRNowPlayingContainer()
       
    73 {
       
    74 }
       
    75 
       
    76 /*
       
    77  * Description : construct the container widget.
       
    78  */
       
    79 void IRNowPlayingContainer::constructContainer()
       
    80 {
       
    81     // Set the text font. It may be deleted in the future to use the default
       
    82     // font.
       
    83     QFont playingFont;
       
    84     playingFont.setPointSizeF(7.0);
       
    85     playingFont.setBold(true);
       
    86     iStationName->setFont(playingFont);
       
    87     playingFont.setPointSizeF(6.0);
       
    88     playingFont.setBold(false);
       
    89     iCategory->setFont(playingFont);
       
    90     iSongName->setFont(playingFont);
       
    91 
       
    92     HbMainWindow *mainWindow = hbInstance->allMainWindows().at(0);
       
    93     resizeContainer(mainWindow->orientation());
       
    94 }
       
    95 
       
    96 /*
       
    97  * Description : set the station name text to the station label
       
    98  * Parameters  : aStationName : station's name
       
    99  */
       
   100 void IRNowPlayingContainer::setStationName(const QString &aStationName)
       
   101 {
       
   102     iStationName->setText(aStationName);
       
   103 }
       
   104 
       
   105 /*
       
   106  * Description : set the category text to the category label
       
   107  * Parameters  : aCategory : station's category
       
   108  */
       
   109 void IRNowPlayingContainer::setCategory(const QString &aCategory)
       
   110 {
       
   111     iCategory->setText(aCategory);
       
   112 }
       
   113 
       
   114 /*
       
   115  * Description : set the song name text to the song name label
       
   116  * Parameters  : aSongName : song's name
       
   117  */
       
   118 void IRNowPlayingContainer::setSongName(const QString &aSongName)
       
   119 {
       
   120     iSongName->setText(aSongName);
       
   121     if ( !iSongName->isAnimating() )
       
   122     {
       
   123         QTimer::singleShot(100, iSongName, SLOT(startAnimation()));
       
   124     }
       
   125 }
       
   126 
       
   127 /*
       
   128  * Description : set the logo picture to the logo label
       
   129  * Parameters  : aLogo : logo picture
       
   130  */
       
   131 void IRNowPlayingContainer::setLogo(const HbIcon& aLogo)
       
   132 {
       
   133     iLogo->setIcon(aLogo);
       
   134     HbEffect::start(iLogo, "nowplaying", "show");
       
   135 }
       
   136 
       
   137 /*
       
   138  * Description : set the advertisment picture
       
   139  * Parameters  : aAdvImage : advertisement picture
       
   140  */
       
   141 void IRNowPlayingContainer::setAdvImage(const HbIcon& aAdvImage)
       
   142 {
       
   143     iAdvImage->setIcon(aAdvImage);
       
   144     HbEffect::start(iAdvImage, "nowplaying", "show");
       
   145 }
       
   146 
       
   147 /*
       
   148  * Description : get the mouse press event and emit a signal.
       
   149  */
       
   150 void IRNowPlayingContainer::mousePressEvent(QGraphicsSceneMouseEvent *aEvent)
       
   151 {
       
   152     QRectF advRect = iAdvImage->geometry();
       
   153     QPointF pos = aEvent->pos();
       
   154     
       
   155     if (advRect.contains(pos))
       
   156     {
       
   157         emit advertisementPressed();
       
   158     }
       
   159     else
       
   160     {
       
   161         emit volumePressed();   
       
   162     }
       
   163 }
       
   164 
       
   165 /*
       
   166  * Description : resize the container if the direction changes.
       
   167  */
       
   168 void IRNowPlayingContainer::orientationChanged(Qt::Orientation aOrientation)
       
   169 {
       
   170     resizeContainer(aOrientation);
       
   171 }
       
   172 
       
   173 /*
       
   174  * Description : load the layout according to the direction.
       
   175  */
       
   176 void IRNowPlayingContainer::resizeContainer(Qt::Orientation aOrientation)
       
   177 {
       
   178     if (aOrientation == Qt::Vertical)
       
   179     {
       
   180         iLoader.load(NOW_PLAYING_CONTAINER_LAYOUT_FILENAME, "portrait");
       
   181     }
       
   182     else
       
   183     {
       
   184         iLoader.load(NOW_PLAYING_CONTAINER_LAYOUT_FILENAME, "landscape");
       
   185     }
       
   186 }
       
   187 
       
   188 void IRNowPlayingContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
       
   189 {
       
   190     Q_UNUSED(option);
       
   191     Q_UNUSED(widget);
       
   192 
       
   193     painter->setPen(QPen(Qt::darkGray));
       
   194     painter->setBrush(QBrush(Qt::darkGray));
       
   195     painter->drawRect(rect());
       
   196 }