22 #include <hbicon.h> |
22 #include <hbicon.h> |
23 #include <hbiconitem.h> |
23 #include <hbiconitem.h> |
24 #include <hbdocumentloader.h> |
24 #include <hbdocumentloader.h> |
25 #include <hbinstance.h> |
25 #include <hbinstance.h> |
26 #include <hbcolorscheme.h> |
26 #include <hbcolorscheme.h> |
|
27 #include <hbstyleloader.h> |
27 |
28 |
28 #include "mpnowplayingwidget_p.h" |
29 #include "mpnowplayingwidget_p.h" |
29 #include "mpnowplayingwidget.h" |
30 #include "mpnowplayingwidget.h" |
30 #include "mpnowplayingbackend.h" |
31 #include "mpnowplayingbackend.h" |
31 #include "mptrace.h" |
32 #include "mptrace.h" |
32 |
33 |
33 const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml"; |
34 const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml"; |
|
35 const char *NOW_PLAYING_CSS = ":/css/banner_color.css"; |
34 |
36 |
35 /*! |
37 /*! |
36 \internal |
38 \internal |
37 \class MpNowPlayingWidgetPrivate |
39 \class MpNowPlayingWidgetPrivate |
38 \brief Custom HB widget that displays currently playing song information. |
40 \brief Custom HB widget that displays currently playing song information. |
44 |
46 |
45 /*! |
47 /*! |
46 \internal |
48 \internal |
47 Constructs the now playing widget private. |
49 Constructs the now playing widget private. |
48 */ |
50 */ |
49 MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate(long int playerId, MpNowPlayingWidget *qq ) |
51 MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( long int playerId, MpNowPlayingWidget *qq ) |
50 : q_ptr( qq ), |
52 : q_ptr( qq ), |
51 mPrimaryText(0), |
53 mPrimaryText(0), |
52 mSecondaryText(0), |
54 mSecondaryText(0), |
53 mState( NotPlaying ), |
55 mState( NotPlaying ), |
54 mIcon(0), |
56 mIcon(0), |
55 mDocumentLoader(0) |
57 mDocumentLoader(0), |
|
58 mCurrentPressedState( BannerNone ) |
56 { |
59 { |
57 TX_ENTRY_ARGS( "Player ID =" << playerId << " Q pointer=" << ( void * )qq ) |
60 TX_ENTRY_ARGS( "Player ID =" << playerId << " Q pointer=" << ( void * )qq ) |
58 QGraphicsWidget *widget; |
61 QGraphicsWidget *widget; |
59 bool widgetsOk = false; |
62 bool widgetsOk = false; |
60 |
|
61 //TODO final color resources should be qtc_multimedia_trans_normal when available |
|
62 QColor normalColor( HbColorScheme::color("foreground") ); |
|
63 //TODO final color resources should be qtc_multimedia_trans_pressed when available |
|
64 QColor pressedColor( HbColorScheme::color("popupbackground") ); |
|
65 |
63 |
66 mPlayIconNormal = new HbIcon( QString("qtg_mono_play")); |
64 HbStyleLoader::registerFilePath(NOW_PLAYING_CSS); |
67 mPlayIconNormal->setColor( normalColor ); |
|
68 mPauseIconNormal = new HbIcon( QString("qtg_mono_pause")); |
|
69 mPauseIconNormal->setColor( normalColor ); |
|
70 |
65 |
71 mPlayIconPressed = new HbIcon( QString("qtg_mono_play")); |
66 mPlayIcon = new HbIcon( QString( "qtg_mono_play" ) ); |
72 mPlayIconPressed->setColor( pressedColor ); |
67 mPauseIcon = new HbIcon( QString( "qtg_mono_pause" ) ); |
73 mPauseIconPressed = new HbIcon( QString("qtg_mono_pause")); |
|
74 mPauseIconPressed->setColor( pressedColor ); |
|
75 |
68 |
76 mDocumentLoader = new HbDocumentLoader(); |
69 mDocumentLoader = new HbDocumentLoader(); |
77 if (mDocumentLoader) { |
70 if (mDocumentLoader) { |
78 mDocumentLoader->load( NOW_PLAYING_XML, &widgetsOk); |
71 mDocumentLoader->load( NOW_PLAYING_XML, &widgetsOk); |
79 } |
72 } |
85 HbWidget* container = qobject_cast<HbWidget*>(widget); |
78 HbWidget* container = qobject_cast<HbWidget*>(widget); |
86 container->setParentItem(q_ptr); |
79 container->setParentItem(q_ptr); |
87 |
80 |
88 widget = mDocumentLoader->findWidget(QString("primaryText")); |
81 widget = mDocumentLoader->findWidget(QString("primaryText")); |
89 mPrimaryText = qobject_cast<HbLabel*>(widget); |
82 mPrimaryText = qobject_cast<HbLabel*>(widget); |
90 //TODO final color resource should be qtc_multimedia_trans_normal when available |
83 mPrimaryText->setObjectName( "bannerLabel" ); |
91 mPrimaryText->setTextColor( normalColor ); |
84 mPrimaryText->setProperty( "state", "normal" ); |
92 |
85 |
93 |
86 |
94 widget = mDocumentLoader->findWidget(QString("secondaryText")); |
87 widget = mDocumentLoader->findWidget(QString("secondaryText")); |
95 mSecondaryText = qobject_cast<HbLabel*>(widget); |
88 mSecondaryText = qobject_cast<HbLabel*>(widget); |
96 //TODO final color resource should be qtc_multimedia_trans_normal when available |
89 mSecondaryText->setObjectName( "bannerLabel" ); |
97 mSecondaryText->setTextColor( normalColor ); |
90 mSecondaryText->setProperty( "state", "normal" ); |
|
91 |
98 |
92 |
99 widget = mDocumentLoader->findWidget(QString("playPause")); |
93 widget = mDocumentLoader->findWidget(QString("playPause")); |
100 mIcon = qobject_cast<HbLabel*>(widget); |
94 mIcon = qobject_cast<HbLabel*>(widget); |
101 |
95 mIcon->setObjectName( "bannerLabel" ); |
|
96 mIcon->setProperty( "state", "normal" ); |
|
97 |
102 HbStackedLayout *mylayout; |
98 HbStackedLayout *mylayout; |
103 mylayout = new HbStackedLayout(q_ptr); |
99 mylayout = new HbStackedLayout(q_ptr); |
104 mylayout->addItem( container ); |
100 mylayout->addItem( container ); |
105 |
101 |
106 q_ptr->setLayout( mylayout ); |
102 q_ptr->setLayout( mylayout ); |
141 if ( enabled ) { |
135 if ( enabled ) { |
142 connect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)), |
136 connect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)), |
143 this, SLOT(setState(SimplifiedPlayerState)) ); |
137 this, SLOT(setState(SimplifiedPlayerState)) ); |
144 |
138 |
145 connect( mBackEnd, SIGNAL(titleChanged(QString)), |
139 connect( mBackEnd, SIGNAL(titleChanged(QString)), |
146 mPrimaryText, SLOT(setPlainText(QString)) ); |
140 this, SLOT(setTitle(QString)) ); |
147 |
141 |
148 connect( mBackEnd, SIGNAL(artistChanged(QString)), |
142 connect( mBackEnd, SIGNAL(artistChanged(QString)), |
149 mSecondaryText, SLOT(setPlainText(QString)) ); |
143 this, SLOT(setArtist(QString)) ); |
150 mBackEnd->update(); |
144 mBackEnd->update(); |
151 } |
145 } |
152 else { |
146 else { |
153 disconnect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)), |
147 disconnect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)), |
154 this, SLOT(setState(SimplifiedPlayerState)) ); |
148 this, SLOT(setState(SimplifiedPlayerState)) ); |
163 |
157 |
164 /*! |
158 /*! |
165 \internal |
159 \internal |
166 Offers click \a event to the widget privated side, if event is consumed it returns true. |
160 Offers click \a event to the widget privated side, if event is consumed it returns true. |
167 */ |
161 */ |
|
162 |
168 bool MpNowPlayingWidgetPrivate::handleClickEvent(QGraphicsSceneMouseEvent *event) |
163 bool MpNowPlayingWidgetPrivate::handleClickEvent(QGraphicsSceneMouseEvent *event) |
169 { |
164 { |
170 if ( mIcon->windowFrameGeometry().contains( event->pos() ) ) { |
165 bool ret = true; |
171 mBackEnd->playPause(); |
166 if ( mCurrentPressedState != BannerNone ) { |
172 return true; |
167 //Widget was previosly pressed, handle the event. |
173 } |
168 QRectF geometry = q_ptr->rect(); |
174 else { |
169 qreal delta = mIcon->windowFrameGeometry().top() - geometry.top(); |
175 return false; |
170 QRectF iconTouchRect( mIcon->windowFrameGeometry() ); |
176 } |
171 iconTouchRect.adjust( -delta, -delta, delta, delta ); |
|
172 if ( iconTouchRect.contains( event->pos() ) ) { |
|
173 if ( mCurrentPressedState == BannerIcon ) { |
|
174 // click on play/pause |
|
175 mBackEnd->playPause(); |
|
176 } |
|
177 } |
|
178 else if ( mCurrentPressedState == BannerLabels && geometry.contains( event->pos() )){ |
|
179 // click somewhere else on the widget. |
|
180 ret = false; |
|
181 } |
|
182 /*else { |
|
183 // click outside the widget. |
|
184 }*/ |
|
185 mCurrentPressedState = BannerNone; |
|
186 } |
|
187 return ret; |
177 } |
188 } |
178 |
189 |
179 /*! |
190 /*! |
180 \internal |
191 \internal |
181 Changes text and icon color when \a pressed |
192 Changes text and icon color when \a pressed |
182 */ |
193 */ |
183 void MpNowPlayingWidgetPrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event, bool pressed) |
194 void MpNowPlayingWidgetPrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event, bool pressed) |
184 { |
195 { |
185 //TODO final color resources should be qtc_multimedia_trans_pressed when available |
196 |
186 QColor pressedColor( HbColorScheme::color("popupbackground") ); |
197 QRectF geometry = q_ptr->rect(); |
187 //TODO final color resources should be qtc_multimedia_trans_normal when available |
198 qreal delta = mIcon->windowFrameGeometry().top() - geometry.top(); |
188 QColor normalColor( HbColorScheme::color("foreground") ); |
199 QRectF iconTouchRect( mIcon->windowFrameGeometry() ); |
|
200 iconTouchRect.adjust( -delta, -delta, delta, delta ); |
189 |
201 |
190 if( mIcon->windowFrameGeometry().contains( event->pos() ) && pressed) { |
202 if( iconTouchRect.contains( event->pos() ) && pressed ) { |
191 if ( mState == Playing ) { |
203 if( mCurrentPressedState == BannerNone ) { |
192 mIcon->setIcon( *mPauseIconPressed ); |
204 mCurrentPressedState = BannerIcon; |
193 } |
205 } |
194 else { |
206 mIcon->setProperty( "state", "pressed" ); |
195 mIcon->setIcon( *mPlayIconPressed ); |
207 } |
196 } |
208 else if( geometry.contains( event->pos() ) && pressed ){ |
197 } |
209 if( mCurrentPressedState == BannerNone ) { |
198 else if( q_ptr->rect().contains( event->pos() ) && pressed ){ |
210 mCurrentPressedState = BannerLabels; |
199 mPrimaryText->setTextColor( pressedColor ); |
211 } |
200 mSecondaryText->setTextColor( pressedColor ); |
212 mPrimaryText->setProperty( "state", "pressed" ); |
|
213 mSecondaryText->setProperty( "state", "pressed" ); |
201 } |
214 } |
202 else { |
215 else { |
203 mPrimaryText->setTextColor( normalColor ); |
216 mIcon->setProperty( "state", "normal" ); |
204 mSecondaryText->setTextColor( normalColor ); |
217 mPrimaryText->setProperty( "state", "normal" ); |
205 if( mState == Playing){ |
218 mSecondaryText->setProperty( "state", "normal" ); |
206 mIcon->setIcon( *mPauseIconNormal ); |
219 } |
207 } |
220 } |
208 else{ |
221 |
209 mIcon->setIcon( *mPlayIconNormal ); |
222 /*! |
210 } |
223 \internal |
211 } |
224 Changes text and icon color when moved |
212 } |
225 */ |
213 |
226 void MpNowPlayingWidgetPrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) |
214 /*! |
227 { |
215 \internal |
228 |
216 Handles theme change |
229 QRectF geometry = q_ptr->rect(); |
217 */ |
230 qreal delta = mIcon->windowFrameGeometry().top() - geometry.top(); |
218 void MpNowPlayingWidgetPrivate::handleThemeChange() |
231 QRectF iconTouchRect( mIcon->windowFrameGeometry() ); |
219 { |
232 iconTouchRect.adjust( -delta, -delta, delta, delta ); |
220 //TODO final color resources should be qtc_multimedia_trans_pressed when available |
|
221 QColor pressedColor( HbColorScheme::color("popupbackground") ); |
|
222 //TODO final color resources should be qtc_multimedia_trans_normal when available |
|
223 QColor normalColor( HbColorScheme::color("foreground") ); |
|
224 |
233 |
225 mPrimaryText->setTextColor( normalColor ); |
234 if( iconTouchRect.contains( event->pos() ) ) { |
226 mSecondaryText->setTextColor( normalColor ); |
235 if( mCurrentPressedState == BannerIcon ) { |
227 mPauseIconNormal->setColor( normalColor ); |
236 mIcon->setProperty( "state", "pressed" ); |
228 mPlayIconNormal->setColor( normalColor ); |
237 } |
229 mPauseIconPressed->setColor( pressedColor ); |
238 else { |
230 mPlayIconPressed->setColor( pressedColor ); |
239 mIcon->setProperty( "state", "normal" ); |
231 |
240 } |
232 if( mState == Playing){ |
241 mPrimaryText->setProperty( "state", "normal" ); |
233 mIcon->setIcon( *mPauseIconNormal ); |
242 mSecondaryText->setProperty( "state", "normal" ); |
234 } |
243 } |
235 else{ |
244 else if( geometry.contains( event->pos() ) && mCurrentPressedState == BannerLabels ){ |
236 mIcon->setIcon( *mPlayIconNormal ); |
245 mPrimaryText->setProperty( "state", "pressed" ); |
|
246 mSecondaryText->setProperty( "state", "pressed" ); |
|
247 mIcon->setProperty( "state", "normal" ); |
|
248 } |
|
249 else { |
|
250 mIcon->setProperty( "state", "normal" ); |
|
251 mPrimaryText->setProperty( "state", "normal" ); |
|
252 mSecondaryText->setProperty( "state", "normal" ); |
237 } |
253 } |
238 } |
254 } |
239 |
255 |
240 /*! |
256 /*! |
241 \internal |
257 \internal |
248 case NotPlaying: |
264 case NotPlaying: |
249 if ( mState != NotPlaying ) |
265 if ( mState != NotPlaying ) |
250 emit q_ptr->playbackAttachmentChanged( false ); |
266 emit q_ptr->playbackAttachmentChanged( false ); |
251 break; |
267 break; |
252 case Playing: |
268 case Playing: |
253 mIcon->setIcon(*mPauseIconNormal); |
269 mIcon->setIcon( *mPauseIcon ); |
254 if (mState == NotPlaying) |
270 mIcon->setProperty( "state", mIcon->property("state").toString() ); |
|
271 if ( mState == NotPlaying ) |
255 emit q_ptr->playbackAttachmentChanged( true ); |
272 emit q_ptr->playbackAttachmentChanged( true ); |
256 break; |
273 break; |
257 case Paused: |
274 case Paused: |
258 mIcon->setIcon(*mPlayIconNormal); |
275 mIcon->setIcon( *mPlayIcon ); |
259 if (mState == NotPlaying) |
276 mIcon->setProperty( "state", mIcon->property("state").toString() ); |
|
277 if ( mState == NotPlaying ) |
260 emit q_ptr->playbackAttachmentChanged( true ); |
278 emit q_ptr->playbackAttachmentChanged( true ); |
261 break; |
279 break; |
262 default: |
280 default: |
263 break; |
281 break; |
264 } |
282 } |
265 mState = state; |
283 mState = state; |
266 TX_EXIT |
284 TX_EXIT |
267 } |
285 } |
268 |
286 |
269 |
287 /*! |
|
288 \internal |
|
289 Sets the \a title |
|
290 */ |
|
291 void MpNowPlayingWidgetPrivate::setTitle( const QString &title ) |
|
292 { |
|
293 mPrimaryText->setPlainText( title ); |
|
294 mPrimaryText->setProperty( "state", mPrimaryText->property("state").toString() ); |
|
295 } |
|
296 |
|
297 /*! |
|
298 \internal |
|
299 Sets the \a artist |
|
300 */ |
|
301 void MpNowPlayingWidgetPrivate::setArtist( const QString &artist ) |
|
302 { |
|
303 mSecondaryText->setPlainText( artist ); |
|
304 mSecondaryText->setProperty( "state", mSecondaryText->property("state").toString() ); |
|
305 } |
|
306 |
|
307 |