mpviewplugins/mpcollectionviewplugin/src/mpcollectioninfobar.cpp
changeset 19 4e84c994a771
equal deleted inserted replaced
5:2a40e88564c8 19:4e84c994a771
       
     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: Music Player collection container information bar.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QPainter>
       
    19 #include <QColor>
       
    20 
       
    21 #include <hbstackedlayout.h>
       
    22 #include <hblabel.h>
       
    23 #include <hbdocumentloader.h>
       
    24 #include <hbinstance.h>
       
    25 #include <hbmainwindow.h>
       
    26 
       
    27 #include "mpcollectioninfobar.h"
       
    28 #include "mptrace.h"
       
    29 
       
    30 
       
    31 const char*MUSIC_COLLECTION_INFOBAR_DOCML = ":/docml/musiccollection_infobar.docml";
       
    32 
       
    33 
       
    34 /*!
       
    35     \class MpCollectionInfoBar
       
    36     \brief Music Player collection container information bar.
       
    37 
       
    38     Collection Info Bar is a custom widget,similar to HbWidget that provides
       
    39     up to two text labels, one aligned to left and the other to the right.
       
    40 */
       
    41 
       
    42 /*!
       
    43  Constructs the information bar widget.
       
    44  */
       
    45 MpCollectionInfoBar::MpCollectionInfoBar( QGraphicsItem *parent )
       
    46     : HbWidget(parent),
       
    47       mContainer(0),
       
    48       mTextLeft(0),
       
    49       mTextRight(0)
       
    50 {
       
    51     TX_ENTRY
       
    52     mDocumentLoader = new HbDocumentLoader();
       
    53     bool ok = false;
       
    54     mDocumentLoader->load( MUSIC_COLLECTION_INFOBAR_DOCML, &ok );
       
    55     if ( ok ) {
       
    56         QGraphicsWidget *widget;
       
    57         widget = mDocumentLoader->findWidget(QString("infoBarContainer"));
       
    58         mContainer = qobject_cast<HbWidget*>(widget);
       
    59 
       
    60         widget = mDocumentLoader->findWidget(QString("leftText"));
       
    61         mTextLeft = qobject_cast<HbLabel*>(widget);
       
    62 
       
    63         widget = mDocumentLoader->findWidget(QString("rightText"));
       
    64         mTextRight = qobject_cast<HbLabel*>(widget);
       
    65     }
       
    66     else {
       
    67         TX_LOG_ARGS("Error: invalid xml file.");
       
    68         Q_ASSERT_X(ok, "MpCollectionInfoBar", "invalid xml file");
       
    69     }
       
    70 
       
    71     HbStackedLayout *layout = new HbStackedLayout(this);
       
    72     layout->addItem(mContainer);
       
    73 
       
    74 	HbMainWindow *mainWindow = hbInstance->allMainWindows()[0];
       
    75     mOrientation = mainWindow->orientation();
       
    76     connect( mainWindow, SIGNAL( orientationChanged(Qt::Orientation) ),
       
    77              this, SLOT( orientationChange(Qt::Orientation) ) );
       
    78     TX_EXIT
       
    79 }
       
    80 
       
    81 /*!
       
    82  Destructs the widget.
       
    83  */
       
    84 MpCollectionInfoBar::~MpCollectionInfoBar()
       
    85 {
       
    86     TX_ENTRY
       
    87     delete mContainer;
       
    88     delete mDocumentLoader;
       
    89     TX_EXIT
       
    90 }
       
    91 
       
    92 /*!
       
    93  Sets the left label text to \a textLeft.
       
    94  */
       
    95 void MpCollectionInfoBar::setText(const QString &textLeft)
       
    96 {
       
    97     TX_ENTRY_ARGS("textLeft=" << textLeft);
       
    98 
       
    99     mTextLeft->setPlainText(textLeft);
       
   100     mTextRight->setPlainText(QString::null);
       
   101 
       
   102     bool ok1 = false;
       
   103     bool ok2 = false;
       
   104     mDocumentLoader->load(MUSIC_COLLECTION_INFOBAR_DOCML, "single", &ok1);
       
   105     if ( mOrientation == Qt::Vertical ) {
       
   106         mDocumentLoader->load(MUSIC_COLLECTION_INFOBAR_DOCML, "single singlePortrait", &ok2);
       
   107     }
       
   108     else {
       
   109         mDocumentLoader->load(MUSIC_COLLECTION_INFOBAR_DOCML, "single singleLandscape", &ok2);
       
   110     }
       
   111     if ( !ok1 || !ok2 ) {
       
   112         TX_LOG_ARGS("Error: invalid xml file.");
       
   113         Q_ASSERT_X((ok1 || ok2), "MpCollectionInfoBar::setText 1", "invalid xml file");
       
   114     }
       
   115     mSingleText = true;
       
   116     TX_EXIT
       
   117 }
       
   118 
       
   119 /*!
       
   120  Sets the left label text to \a textLeft and the right label text to \a textRight.
       
   121  */
       
   122 void MpCollectionInfoBar::setText(const QString &textLeft, const QString &textRight)
       
   123 {
       
   124     TX_ENTRY_ARGS("textLeft=" << textLeft << ", textRight=" << textRight);
       
   125 
       
   126     mTextLeft->setPlainText(textLeft);
       
   127     mTextRight->setPlainText(textRight);
       
   128 
       
   129     bool ok1 = false;
       
   130     bool ok2 = false;
       
   131     mDocumentLoader->load(MUSIC_COLLECTION_INFOBAR_DOCML, "double", &ok1);
       
   132     if ( mOrientation == Qt::Vertical ) {
       
   133         mDocumentLoader->load(MUSIC_COLLECTION_INFOBAR_DOCML, "double doublePortrait", &ok2);
       
   134     }
       
   135     else {
       
   136         mDocumentLoader->load(MUSIC_COLLECTION_INFOBAR_DOCML, "double doubleLandscape", &ok2);
       
   137     }
       
   138     if ( !ok1 || !ok2 ) {
       
   139         TX_LOG_ARGS("Error: invalid xml file.");
       
   140         Q_ASSERT_X((ok1 || ok2), "MpCollectionInfoBar::setText 2", "invalid xml file");
       
   141     }
       
   142     mSingleText = false;
       
   143     TX_EXIT
       
   144 }
       
   145 
       
   146 /*!
       
   147     \reimp
       
   148  */
       
   149 void MpCollectionInfoBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
       
   150 {
       
   151     TX_ENTRY
       
   152     HbWidget::paint(painter, option, widget);
       
   153     QColor color(105,105,105,255);
       
   154     painter->fillRect(rect(), color);
       
   155     TX_EXIT
       
   156 }
       
   157 
       
   158 /*!
       
   159  Slot to be called when orientation is changed.
       
   160  Loads the correct layout based on the \a orientation.
       
   161  */
       
   162 void MpCollectionInfoBar::orientationChange( Qt::Orientation orientation )
       
   163 {
       
   164     TX_ENTRY
       
   165     mOrientation = orientation;
       
   166     if ( mSingleText ) {
       
   167         setText( mTextLeft->plainText() );
       
   168     }
       
   169     else {
       
   170         setText( mTextLeft->plainText(), mTextRight->plainText() );
       
   171     }
       
   172     TX_EXIT
       
   173 }