mpviewplugins/mpmediawallviewplugin/src/mpmediawallview.cpp
changeset 41 ea59c434026a
parent 32 c163ef0b758d
child 43 0f32e550d9d8
equal deleted inserted replaced
32:c163ef0b758d 41:ea59c434026a
    21 #include <hbicon.h>
    21 #include <hbicon.h>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbapplication.h>
    23 #include <hbapplication.h>
    24 #include <hbscrollbar.h>
    24 #include <hbscrollbar.h>
    25 #include <hblabel.h>
    25 #include <hblabel.h>
    26 #include <hbpushbutton.h>
       
    27 #include <hbtoolbutton.h>
    26 #include <hbtoolbutton.h>
       
    27 #include <hblistview.h>
       
    28 #include <hbstyleloader.h>
    28 
    29 
    29 #include <hgmediawall.h>
    30 #include <hgmediawall.h>
    30 
    31 
    31 #include "mpmediawallview.h"
    32 #include "mpmediawallview.h"
    32 #include "mpmediawalldocumentloader.h"
    33 #include "mpmediawalldocumentloader.h"
   129         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   130         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   130         mPlayIcon = new HbIcon( "qtg_mono_play" );
   131         mPlayIcon = new HbIcon( "qtg_mono_play" );
   131         mPlayPauseAction = new HbAction( HbIcon() , QString(), this );  
   132         mPlayPauseAction = new HbAction( HbIcon() , QString(), this );  
   132         mPlaybackData = MpEngineFactory::sharedEngine()->playbackData();
   133         mPlaybackData = MpEngineFactory::sharedEngine()->playbackData();
   133         qobject_cast<HbToolButton*>( widget )->setAction( mPlayPauseAction );
   134         qobject_cast<HbToolButton*>( widget )->setAction( mPlayPauseAction );
   134         //we need this widget to hide the play pause button, for soem reaosn it does not want to hide.
   135         //we need this widget to hide the play pause button, for some reason it does not want to hide.
   135         mPlayPauseContainer = mDocumentLoader->findWidget( QString( "playPauseButtonContainer" ) );
   136         mPlayPauseContainer = mDocumentLoader->findWidget( QString( "playPauseButtonContainer" ) );
   136         updatePlayPauseAction();
   137         updatePlayPauseAction();
   137         connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   138         connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   138                  this, SLOT( updatePlayPauseAction() ) );
   139                  this, SLOT( updatePlayPauseAction() ) );
   139         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   140         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   160         TX_LOG_ARGS( "Error: invalid xml file." );
   161         TX_LOG_ARGS( "Error: invalid xml file." );
   161         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   162         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   162     }
   163     }
   163     
   164     
   164     mAlbumCover = new MpAlbumCoverWidget( this );
   165     mAlbumCover = new MpAlbumCoverWidget( this );
   165     mAlbumCover->setDefaultIcon( HbIcon( "qtg_large_music_album" ) );
   166     mAlbumCover->setDefaultIcon( HbIcon( "qtg_large_album_art" ) );
   166     mAlbumCover->hide();
   167     mAlbumCover->hide();
   167     
   168     
   168     mTrackList = new MpTrackListWidget( this );
   169     mTrackList = new MpTrackListWidget( this );
   169     mTrackList->list()->setModel( new MpCollectionTBoneListDataModel(mCollectionData, mPlaybackData, mTrackList ) );
   170     mTrackList->list()->setModel( new MpCollectionTBoneListDataModel(mCollectionData, mPlaybackData, mTrackList ) );
   170     mTrackList->hide();
   171     mTrackList->hide();
   171     
   172     
   172     connect(mAlbumCover,SIGNAL(clicked()),this, SLOT(hideTracksList()));
   173     connect(mAlbumCover,SIGNAL(clicked()),this, SLOT(hideTracksList()));
   173     connect(mTrackList->list(), SIGNAL(activated(QModelIndex)), this, SLOT(listItemActivated(QModelIndex)));
   174     connect(mTrackList->list(), SIGNAL(activated(QModelIndex)), this, SLOT(listItemActivated(QModelIndex)));
   174     connect(mTrackList,SIGNAL(close()),this, SLOT(hideTracksList()));
   175     connect(mTrackList,SIGNAL(closed()),this, SLOT(hideTracksList()));
   175 
   176 
   176 
   177     HbStyleLoader::registerFilePath(":/css/mpcustommediawall.css");
       
   178     HbStyleLoader::registerFilePath(":/css/mpcustommediawall.hgmediawall.widgetml");  
   177     
   179     
   178     TX_EXIT
   180     TX_EXIT
   179 }
   181 }
   180 
   182 
   181 /*!
   183 /*!
   225         } else {
   227         } else {
   226             bool ok = false;
   228             bool ok = false;
   227             mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, "mediaWall", &ok);
   229             mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, "mediaWall", &ok);
   228             if ( ok ) {
   230             if ( ok ) {
   229                 QGraphicsWidget *widget;
   231                 QGraphicsWidget *widget;
   230                 widget = mDocumentLoader->findWidget(QString("mediaWallWidget"));
   232                 widget = mDocumentLoader->findWidget(QString("MPmediaWallWidget"));
   231                 mMediaWallWidget = qobject_cast<HgMediawall*>(widget);
   233                 mMediaWallWidget = qobject_cast<HgMediawall*>(widget);
       
   234                 //set these items as children of the media wall so they show behind the scrollbar.
       
   235                 mTrackList->setParentItem(mMediaWallWidget);
       
   236                 mAlbumCover->setParentItem(mMediaWallWidget);
   232                 mModel->refreshModel();
   237                 mModel->refreshModel();
   233                 setUpMediaWallWidget();
   238                 setUpMediaWallWidget();
   234             }
   239             }
   235             else {
   240             else {
   236                 TX_LOG_ARGS("Error: invalid xml file.");
   241                 TX_LOG_ARGS("Error: invalid xml file.");
   239             }          
   244             }          
   240         }
   245         }
   241     }
   246     }
   242     else {
   247     else {
   243         if ( mMediaWallWidget ) {
   248         if ( mMediaWallWidget ) {
       
   249             //Take ownership of these items to prevent delete from media wall widget.
       
   250             mTrackList->setParentItem( this );
       
   251             mAlbumCover->setParentItem( this );
   244             delete mMediaWallWidget;
   252             delete mMediaWallWidget;
   245             mMediaWallWidget = 0;
   253             mMediaWallWidget = 0;
   246             
   254             
   247         }
   255         }
   248         if ( !mNoMusic ) {
   256         if ( !mNoMusic ) {
   342     }
   350     }
   343     mShowingSongsList = true;
   351     mShowingSongsList = true;
   344     setUpListAnimation();
   352     setUpListAnimation();
   345     mListShowAnimationGroup->setDirection(QAbstractAnimation::Forward);
   353     mListShowAnimationGroup->setDirection(QAbstractAnimation::Forward);
   346     mListShowAnimationGroup->start();
   354     mListShowAnimationGroup->start();
       
   355     mModel->setItemVisibility( mMediaWallWidget->currentIndex(), false );
   347 }
   356 }
   348 
   357 
   349 /*!
   358 /*!
   350  Slot to be called to starts the album and list closing animation.
   359  Slot to be called to starts the album and list closing animation.
   351  */
   360  */
   365         return;
   374         return;
   366     }
   375     }
   367     mShowingSongsList = false;
   376     mShowingSongsList = false;
   368     mAlbumCover->hide();
   377     mAlbumCover->hide();
   369     mTrackList->hide();
   378     mTrackList->hide();
       
   379     mModel->setItemVisibility( mMediaWallWidget->currentIndex(), true );
   370     mListShowAnimationGroup->stop();
   380     mListShowAnimationGroup->stop();
   371     disconnect(mListShowAnimationGroup, SIGNAL(finished()), this, SLOT(dismissListClosingAnimation()));
   381     disconnect(mListShowAnimationGroup, SIGNAL(finished()), this, SLOT(dismissListClosingAnimation()));
   372 }
   382 }
   373 
   383 
   374 /*!
   384 /*!
   381     //points to albums on media wall, this is used to construct the playlist.
   391     //points to albums on media wall, this is used to construct the playlist.
   382     MpEngineFactory::sharedEngine()->playAlbumSongs( albumIndex, index.row(), mCollectionData );
   392     MpEngineFactory::sharedEngine()->playAlbumSongs( albumIndex, index.row(), mCollectionData );
   383 }
   393 }
   384 
   394 
   385 /*!
   395 /*!
       
   396  Slot to be called to fetch the songs for an album.
       
   397  */
       
   398 void MpMediaWallView::fetchAlbumSongs(QModelIndex index)
       
   399 {
       
   400     if ( !mCollectionData->setCurrentAlbum( index.row() ) ) {
       
   401         mEngine->findAlbumSongs( index.row() );
       
   402     }
       
   403 }
       
   404 
       
   405 /*!
   386  Loads the media wall widget.
   406  Loads the media wall widget.
   387  */
   407  */
   388 void MpMediaWallView::setUpMediaWallWidget()
   408 void MpMediaWallView::setUpMediaWallWidget()
   389 {
   409 {
   390     HbIcon defaultIcon( "qtg_large_music_album" );
   410     HbIcon defaultIcon( "qtg_large_album_art" );
   391     defaultIcon.setSize(mMediaWallWidget->itemSize());
   411     defaultIcon.setSize(mMediaWallWidget->itemSize());
   392     mMediaWallWidget->setDefaultImage( defaultIcon.pixmap().toImage() );
   412     mMediaWallWidget->setDefaultImage( defaultIcon.pixmap().toImage() );
   393     mMediaWallWidget->enableReflections( false );
   413     mMediaWallWidget->enableReflections( true );
   394     mMediaWallWidget->setModel( mModel );
   414     mMediaWallWidget->setModel( mModel );
   395     if ( mPlaybackData->playbackState() != MpPlaybackData::NotPlaying ) {
   415     if ( mPlaybackData->playbackState() != MpPlaybackData::NotPlaying ) {
   396         scrollToNowPlaying();
   416         scrollToNowPlaying();
   397     }
   417     }
   398     //The rest of the cases are attepting to balance the items on screen.
   418     //The rest of the cases are attepting to balance the items on screen.
   425     mMediaWallWidget->setTitleFontSpec( HbFontSpec( HbFontSpec::Primary ) );
   445     mMediaWallWidget->setTitleFontSpec( HbFontSpec( HbFontSpec::Primary ) );
   426     mMediaWallWidget->setDescriptionFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
   446     mMediaWallWidget->setDescriptionFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
   427     mMediaWallWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); //HgWidget::ScrollBarAutoHide
   447     mMediaWallWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); //HgWidget::ScrollBarAutoHide
   428     mMediaWallWidget->scrollBar()->setInteractive( true );
   448     mMediaWallWidget->scrollBar()->setInteractive( true );
   429     mMediaWallWidget->setIndexFeedbackPolicy( HgWidget::IndexFeedbackSingleCharacter );
   449     mMediaWallWidget->setIndexFeedbackPolicy( HgWidget::IndexFeedbackSingleCharacter );
       
   450     connect(mMediaWallWidget, SIGNAL(animationAboutToEnd(QModelIndex)), SLOT(fetchAlbumSongs(QModelIndex)));
   430     connect(mMediaWallWidget, SIGNAL(activated(QModelIndex)), SLOT(showTrackList()));
   451     connect(mMediaWallWidget, SIGNAL(activated(QModelIndex)), SLOT(showTrackList()));
   431     connect(mMediaWallWidget, SIGNAL(scrollingStarted()), SLOT(dismissListClosingAnimation()));
   452     connect(mMediaWallWidget, SIGNAL(scrollingStarted()), SLOT(dismissListClosingAnimation()));
   432 }
   453 }
   433 
   454 
   434 /*!
   455 /*!
   456         mCoverShowListAnimation->setEasingCurve(QEasingCurve::InOutCubic);
   477         mCoverShowListAnimation->setEasingCurve(QEasingCurve::InOutCubic);
   457         mListShowAnimationGroup->addAnimation(mCoverShowListAnimation);
   478         mListShowAnimationGroup->addAnimation(mCoverShowListAnimation);
   458         mListShowListAnimation = new QPropertyAnimation( mTrackList, "geometry", this );
   479         mListShowListAnimation = new QPropertyAnimation( mTrackList, "geometry", this );
   459         mListShowListAnimation->setDuration( 400 );
   480         mListShowListAnimation->setDuration( 400 );
   460         mListShowListAnimation->setEasingCurve(QEasingCurve::InOutCubic);
   481         mListShowListAnimation->setEasingCurve(QEasingCurve::InOutCubic);
   461         mListShowAnimationGroup->addAnimation(mListShowListAnimation);
   482         mListShowAnimationGroup->addAnimation(mListShowListAnimation);      
   462         //track list goes on top of media wall.
       
   463         mTrackList->setZValue(mMediaWallWidget->zValue()+1);
       
   464         //album cover goes on top of track list.
       
   465         mAlbumCover->setZValue(mMediaWallWidget->zValue()+2);
       
   466     }
   483     }
   467     
   484     
   468     //Get the current album cover geometry.
   485     //Get the current album cover geometry.
   469     QPolygonF poly;
   486     QPolygonF poly;
   470     QModelIndex index = mMediaWallWidget->currentIndex();
   487     QModelIndex index = mMediaWallWidget->currentIndex();
   471     if ( !mMediaWallWidget->getItemOutline( index, poly ) ) {
   488     if ( !mMediaWallWidget->getItemOutline( index, poly ) ) {
   472         return;
   489         return;
   473     }
   490     }
   474     QRectF itemRect = poly.boundingRect();
   491     QRectF itemRect = poly.boundingRect();
   475 
       
   476     //Request the albums tracks, they are set to the track list model.
       
   477     if ( !mCollectionData->setCurrentAlbum( index.row() ) ) {
       
   478         mEngine->findAlbumSongs( index.row() );
       
   479     }
       
   480     
   492     
   481     //Get the album cover icon.
   493     //Get the album cover icon.
   482     QVariant image = mModel->data(index, Qt::DecorationRole);
   494     QVariant image = mModel->data(index, Qt::DecorationRole);
   483     if ( image.canConvert<HbIcon>() ) {
   495     if ( image.canConvert<HbIcon>() ) {
   484        mAlbumCover->setIcon(image.value<HbIcon>());
   496        mAlbumCover->setIcon(image.value<HbIcon>());
   492     //Calculate start and end position of items for the animation.
   504     //Calculate start and end position of items for the animation.
   493     QRectF endRect = itemRect;
   505     QRectF endRect = itemRect;
   494     endRect.moveTo( endRect.topLeft().x() - endRect.size().width() / 2.0, endRect.topLeft().y() );
   506     endRect.moveTo( endRect.topLeft().x() - endRect.size().width() / 2.0, endRect.topLeft().y() );
   495     mCoverShowListAnimation->setStartValue(itemRect);
   507     mCoverShowListAnimation->setStartValue(itemRect);
   496     mCoverShowListAnimation->setEndValue(endRect);
   508     mCoverShowListAnimation->setEndValue(endRect);
   497     endRect.moveTo(endRect.topRight() - QPointF(1,0)); //adjust by one pixel to prevent a gap.
   509     endRect.moveTo( endRect.topRight() );
   498     mListShowListAnimation->setStartValue(itemRect);
   510     mListShowListAnimation->setStartValue(itemRect);
   499     mListShowListAnimation->setEndValue(endRect);
   511     mListShowListAnimation->setEndValue(endRect);
   500     
   512     
   501     //set initial condition and show to prevent flicker.
   513     //set initial condition and show to prevent flicker.
   502     mAlbumCover->setPos(itemRect.topLeft());
   514     mAlbumCover->setPos(itemRect.topLeft());