diff -r 3ec52facab4d -r 8192e5b5c935 utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp --- a/utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp Fri May 14 15:49:53 2010 +0300 +++ b/utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp Thu May 27 12:49:57 2010 +0300 @@ -24,6 +24,7 @@ #include #include #include +#include #include "mpnowplayingwidget_p.h" #include "mpnowplayingwidget.h" @@ -31,6 +32,7 @@ #include "mptrace.h" const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml"; +const char *NOW_PLAYING_CSS = ":/css/banner_color.css"; /*! \internal @@ -46,32 +48,23 @@ \internal Constructs the now playing widget private. */ -MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate(long int playerId, MpNowPlayingWidget *qq ) +MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( long int playerId, MpNowPlayingWidget *qq ) : q_ptr( qq ), mPrimaryText(0), mSecondaryText(0), mState( NotPlaying ), mIcon(0), - mDocumentLoader(0) + mDocumentLoader(0), + mCurrentPressedState( BannerNone ) { TX_ENTRY_ARGS( "Player ID =" << playerId << " Q pointer=" << ( void * )qq ) QGraphicsWidget *widget; bool widgetsOk = false; - - //TODO final color resources should be qtc_multimedia_trans_normal when available - QColor normalColor( HbColorScheme::color("foreground") ); - //TODO final color resources should be qtc_multimedia_trans_pressed when available - QColor pressedColor( HbColorScheme::color("popupbackground") ); + + HbStyleLoader::registerFilePath(NOW_PLAYING_CSS); - mPlayIconNormal = new HbIcon( QString("qtg_mono_play")); - mPlayIconNormal->setColor( normalColor ); - mPauseIconNormal = new HbIcon( QString("qtg_mono_pause")); - mPauseIconNormal->setColor( normalColor ); - - mPlayIconPressed = new HbIcon( QString("qtg_mono_play")); - mPlayIconPressed->setColor( pressedColor ); - mPauseIconPressed = new HbIcon( QString("qtg_mono_pause")); - mPauseIconPressed->setColor( pressedColor ); + mPlayIcon = new HbIcon( QString( "qtg_mono_play" ) ); + mPauseIcon = new HbIcon( QString( "qtg_mono_pause" ) ); mDocumentLoader = new HbDocumentLoader(); if (mDocumentLoader) { @@ -87,18 +80,21 @@ widget = mDocumentLoader->findWidget(QString("primaryText")); mPrimaryText = qobject_cast(widget); - //TODO final color resource should be qtc_multimedia_trans_normal when available - mPrimaryText->setTextColor( normalColor ); - + mPrimaryText->setObjectName( "bannerLabel" ); + mPrimaryText->setProperty( "state", "normal" ); + widget = mDocumentLoader->findWidget(QString("secondaryText")); mSecondaryText = qobject_cast(widget); - //TODO final color resource should be qtc_multimedia_trans_normal when available - mSecondaryText->setTextColor( normalColor ); + mSecondaryText->setObjectName( "bannerLabel" ); + mSecondaryText->setProperty( "state", "normal" ); + widget = mDocumentLoader->findWidget(QString("playPause")); mIcon = qobject_cast(widget); - + mIcon->setObjectName( "bannerLabel" ); + mIcon->setProperty( "state", "normal" ); + HbStackedLayout *mylayout; mylayout = new HbStackedLayout(q_ptr); mylayout->addItem( container ); @@ -124,10 +120,8 @@ { TX_ENTRY delete mBackEnd; - delete mPlayIconNormal; - delete mPauseIconNormal; - delete mPlayIconPressed; - delete mPauseIconPressed; + delete mPlayIcon; + delete mPauseIcon; delete mDocumentLoader; TX_EXIT } @@ -143,10 +137,10 @@ this, SLOT(setState(SimplifiedPlayerState)) ); connect( mBackEnd, SIGNAL(titleChanged(QString)), - mPrimaryText, SLOT(setPlainText(QString)) ); + this, SLOT(setTitle(QString)) ); connect( mBackEnd, SIGNAL(artistChanged(QString)), - mSecondaryText, SLOT(setPlainText(QString)) ); + this, SLOT(setArtist(QString)) ); mBackEnd->update(); } else { @@ -165,15 +159,32 @@ \internal Offers click \a event to the widget privated side, if event is consumed it returns true. */ + bool MpNowPlayingWidgetPrivate::handleClickEvent(QGraphicsSceneMouseEvent *event) { - if ( mIcon->windowFrameGeometry().contains( event->pos() ) ) { - mBackEnd->playPause(); - return true; + bool ret = true; + if ( mCurrentPressedState != BannerNone ) { + //Widget was previosly pressed, handle the event. + QRectF geometry = q_ptr->rect(); + qreal delta = mIcon->windowFrameGeometry().top() - geometry.top(); + QRectF iconTouchRect( mIcon->windowFrameGeometry() ); + iconTouchRect.adjust( -delta, -delta, delta, delta ); + if ( iconTouchRect.contains( event->pos() ) ) { + if ( mCurrentPressedState == BannerIcon ) { + // click on play/pause + mBackEnd->playPause(); + } + } + else if ( mCurrentPressedState == BannerLabels && geometry.contains( event->pos() )){ + // click somewhere else on the widget. + ret = false; + } + /*else { + // click outside the widget. + }*/ + mCurrentPressedState = BannerNone; } - else { - return false; - } + return ret; } /*! @@ -182,58 +193,63 @@ */ void MpNowPlayingWidgetPrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event, bool pressed) { - //TODO final color resources should be qtc_multimedia_trans_pressed when available - QColor pressedColor( HbColorScheme::color("popupbackground") ); - //TODO final color resources should be qtc_multimedia_trans_normal when available - QColor normalColor( HbColorScheme::color("foreground") ); + + QRectF geometry = q_ptr->rect(); + qreal delta = mIcon->windowFrameGeometry().top() - geometry.top(); + QRectF iconTouchRect( mIcon->windowFrameGeometry() ); + iconTouchRect.adjust( -delta, -delta, delta, delta ); - if( mIcon->windowFrameGeometry().contains( event->pos() ) && pressed) { - if ( mState == Playing ) { - mIcon->setIcon( *mPauseIconPressed ); + if( iconTouchRect.contains( event->pos() ) && pressed ) { + if( mCurrentPressedState == BannerNone ) { + mCurrentPressedState = BannerIcon; } - else { - mIcon->setIcon( *mPlayIconPressed ); - } + mIcon->setProperty( "state", "pressed" ); } - else if( q_ptr->rect().contains( event->pos() ) && pressed ){ - mPrimaryText->setTextColor( pressedColor ); - mSecondaryText->setTextColor( pressedColor ); + else if( geometry.contains( event->pos() ) && pressed ){ + if( mCurrentPressedState == BannerNone ) { + mCurrentPressedState = BannerLabels; + } + mPrimaryText->setProperty( "state", "pressed" ); + mSecondaryText->setProperty( "state", "pressed" ); } else { - mPrimaryText->setTextColor( normalColor ); - mSecondaryText->setTextColor( normalColor ); - if( mState == Playing){ - mIcon->setIcon( *mPauseIconNormal ); - } - else{ - mIcon->setIcon( *mPlayIconNormal ); - } + mIcon->setProperty( "state", "normal" ); + mPrimaryText->setProperty( "state", "normal" ); + mSecondaryText->setProperty( "state", "normal" ); } } /*! \internal - Handles theme change + Changes text and icon color when moved */ -void MpNowPlayingWidgetPrivate::handleThemeChange() -{ - //TODO final color resources should be qtc_multimedia_trans_pressed when available - QColor pressedColor( HbColorScheme::color("popupbackground") ); - //TODO final color resources should be qtc_multimedia_trans_normal when available - QColor normalColor( HbColorScheme::color("foreground") ); +void MpNowPlayingWidgetPrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + + QRectF geometry = q_ptr->rect(); + qreal delta = mIcon->windowFrameGeometry().top() - geometry.top(); + QRectF iconTouchRect( mIcon->windowFrameGeometry() ); + iconTouchRect.adjust( -delta, -delta, delta, delta ); - mPrimaryText->setTextColor( normalColor ); - mSecondaryText->setTextColor( normalColor ); - mPauseIconNormal->setColor( normalColor ); - mPlayIconNormal->setColor( normalColor ); - mPauseIconPressed->setColor( pressedColor ); - mPlayIconPressed->setColor( pressedColor ); - - if( mState == Playing){ - mIcon->setIcon( *mPauseIconNormal ); + if( iconTouchRect.contains( event->pos() ) ) { + if( mCurrentPressedState == BannerIcon ) { + mIcon->setProperty( "state", "pressed" ); + } + else { + mIcon->setProperty( "state", "normal" ); + } + mPrimaryText->setProperty( "state", "normal" ); + mSecondaryText->setProperty( "state", "normal" ); } - else{ - mIcon->setIcon( *mPlayIconNormal ); + else if( geometry.contains( event->pos() ) && mCurrentPressedState == BannerLabels ){ + mPrimaryText->setProperty( "state", "pressed" ); + mSecondaryText->setProperty( "state", "pressed" ); + mIcon->setProperty( "state", "normal" ); + } + else { + mIcon->setProperty( "state", "normal" ); + mPrimaryText->setProperty( "state", "normal" ); + mSecondaryText->setProperty( "state", "normal" ); } } @@ -250,13 +266,15 @@ emit q_ptr->playbackAttachmentChanged( false ); break; case Playing: - mIcon->setIcon(*mPauseIconNormal); - if (mState == NotPlaying) + mIcon->setIcon( *mPauseIcon ); + mIcon->setProperty( "state", mIcon->property("state").toString() ); + if ( mState == NotPlaying ) emit q_ptr->playbackAttachmentChanged( true ); break; case Paused: - mIcon->setIcon(*mPlayIconNormal); - if (mState == NotPlaying) + mIcon->setIcon( *mPlayIcon ); + mIcon->setProperty( "state", mIcon->property("state").toString() ); + if ( mState == NotPlaying ) emit q_ptr->playbackAttachmentChanged( true ); break; default: @@ -266,4 +284,24 @@ TX_EXIT } +/*! + \internal + Sets the \a title + */ +void MpNowPlayingWidgetPrivate::setTitle( const QString &title ) +{ + mPrimaryText->setPlainText( title ); + mPrimaryText->setProperty( "state", mPrimaryText->property("state").toString() ); +} +/*! + \internal + Sets the \a artist + */ +void MpNowPlayingWidgetPrivate::setArtist( const QString &artist ) +{ + mSecondaryText->setPlainText( artist ); + mSecondaryText->setProperty( "state", mSecondaryText->property("state").toString() ); +} + +