24
|
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 |
|
|
18 |
// System includes
|
|
19 |
#include <QPainter>
|
|
20 |
#include <QStringListModel>
|
|
21 |
#include <QGraphicsSceneResizeEvent>
|
|
22 |
#include <QPen>
|
|
23 |
#include <HbPushButton>
|
|
24 |
#include <QTimer>
|
|
25 |
#include <HbColorScheme>
|
|
26 |
#include <HbEvent>
|
|
27 |
#include <HbSwipeGesture>
|
|
28 |
|
|
29 |
#include "radiofrequencystrip.h"
|
|
30 |
#include "radiofrequencyitem.h"
|
|
31 |
#include "radiouiengine.h"
|
|
32 |
#include "radiostation.h"
|
|
33 |
#include "radiostationmodel.h"
|
|
34 |
#include "radiouiutilities.h"
|
|
35 |
#include "radiologger.h"
|
|
36 |
|
|
37 |
// Frequency lines
|
|
38 |
const int KTabHeightSmall = 10;
|
|
39 |
const int KTabHeightBig = 15;
|
|
40 |
const int KTabWidthFavorite = 4;
|
|
41 |
const qreal KIndicatorWidth = 2.0;
|
|
42 |
|
|
43 |
const qreal KRounder = 0.5;
|
|
44 |
const int KSelectorWidth = 2;
|
|
45 |
const int KSelectorZPos = 100;
|
|
46 |
|
|
47 |
const int KHalfHertz = KOneHertz / 2;
|
|
48 |
const int KOneTabDistance = 15;
|
|
49 |
const uint KOneTabInHz = 0.2 * KOneHertz;
|
|
50 |
const qreal KPixelInHz = KOneTabInHz / KOneTabDistance;
|
|
51 |
const int KWidth = KOneTabDistance * 5;
|
|
52 |
//const int KPixmapWidth = KWidth + KOneTabDistance;
|
|
53 |
const int KHeight = 50; //TODO: Remove hardcoding
|
|
54 |
|
|
55 |
const int K100Khz = 100000;
|
|
56 |
|
|
57 |
const char* KSlideToLeft = "SlideToLeft";
|
|
58 |
const char* KSlideFromLeft = "SlideFromLeft";
|
|
59 |
const char* KSlideToRight = "SlideToRight";
|
|
60 |
const char* KSlideFromRight = "SlideFromRight";
|
|
61 |
const char* LEFT_BUTTON = "tv:left_button";
|
|
62 |
const char* RIGHT_BUTTON = "tv:right_button";
|
|
63 |
|
|
64 |
const char* TEXT_COLOR_ATTRIBUTE = "text";
|
|
65 |
const int BUTTON_HIDE_TIMEOUT = 500;
|
|
66 |
const int BUTTON_SHOW_TIMEOUT = 1000;
|
|
67 |
|
|
68 |
/*!
|
|
69 |
*
|
|
70 |
*/
|
|
71 |
static QLineF makeTab( qreal pos, int height )
|
|
72 |
{
|
|
73 |
return QLineF( pos, KHeight - height, pos, KHeight );
|
|
74 |
}
|
|
75 |
|
|
76 |
/*!
|
|
77 |
*
|
|
78 |
*/
|
|
79 |
RadioFrequencyStrip::RadioFrequencyStrip() :
|
|
80 |
RadioStripBase(),
|
|
81 |
mUiEngine( NULL ),
|
|
82 |
mMinFrequency( 87500000 ),
|
|
83 |
mMaxFrequency( 108000000 ),
|
|
84 |
mFrequencyStepSize( 100000 ),
|
|
85 |
mFrequency( 87500000 ),
|
|
86 |
mSelectorImage( new QGraphicsPixmapItem( this ) ),
|
|
87 |
mSeparatorPos( 0.0 ),
|
|
88 |
mMaxWidth( 0 ),
|
|
89 |
mSelectorPos( 0.0 ),
|
|
90 |
mLeftButton( new HbPushButton( this ) ),
|
|
91 |
mRightButton( new HbPushButton( this ) ),
|
|
92 |
mButtonTimer( NULL ),
|
|
93 |
mButtonsVisible( true ),
|
|
94 |
mUserIsScrolling( false ),
|
|
95 |
mForegroundColor( Qt::white )//HbColorScheme::color( TEXT_COLOR_ATTRIBUTE ) )
|
|
96 |
{
|
|
97 |
RadioUiUtilities::setFrequencyStrip( this );
|
|
98 |
|
|
99 |
setScrollingStyle( HbScrollArea::Pan );
|
|
100 |
setItemSize( QSizeF( KWidth, KHeight ) );
|
|
101 |
setFrictionEnabled( true );
|
|
102 |
|
|
103 |
initModel();
|
|
104 |
|
|
105 |
initSelector();
|
|
106 |
|
|
107 |
initButtons();
|
|
108 |
|
|
109 |
initEmptyItems();
|
|
110 |
|
|
111 |
mFrequency = RadioUiEngine::lastTunedFrequency();
|
|
112 |
scrollToFrequency( mFrequency, 0 );
|
|
113 |
}
|
|
114 |
|
|
115 |
/*!
|
|
116 |
*
|
|
117 |
*/
|
|
118 |
void RadioFrequencyStrip::setLeftButtonIcon( const HbIcon& leftButtonIcon )
|
|
119 |
{
|
|
120 |
mLeftButtonIcon = leftButtonIcon;
|
|
121 |
if ( mLeftButton ) {
|
|
122 |
mLeftButtonIcon.setColor( Qt::white );
|
|
123 |
mLeftButton->setIcon( mLeftButtonIcon );
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
/*!
|
|
128 |
*
|
|
129 |
*/
|
|
130 |
HbIcon RadioFrequencyStrip::leftButtonIcon() const
|
|
131 |
{
|
|
132 |
return mLeftButtonIcon;
|
|
133 |
}
|
|
134 |
|
|
135 |
/*!
|
|
136 |
*
|
|
137 |
*/
|
|
138 |
void RadioFrequencyStrip::setRightButtonIcon( const HbIcon& rightButtonIcon )
|
|
139 |
{
|
|
140 |
mRightButtonIcon = rightButtonIcon;
|
|
141 |
if ( mRightButton ) {
|
|
142 |
mRightButtonIcon.setColor( Qt::white );
|
|
143 |
mRightButton->setIcon( mRightButtonIcon );
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
/*!
|
|
148 |
*
|
|
149 |
*/
|
|
150 |
HbIcon RadioFrequencyStrip::rightButtonIcon() const
|
|
151 |
{
|
|
152 |
return mRightButtonIcon;
|
|
153 |
}
|
|
154 |
|
|
155 |
/*!
|
|
156 |
*
|
|
157 |
*/
|
|
158 |
void RadioFrequencyStrip::init( RadioUiEngine* engine )
|
|
159 |
{
|
|
160 |
mUiEngine = engine;
|
|
161 |
mMinFrequency = mUiEngine->minFrequency();
|
|
162 |
mMaxFrequency = mUiEngine->maxFrequency();
|
|
163 |
mFrequencyStepSize = mUiEngine->frequencyStepSize();
|
|
164 |
mFrequency = mUiEngine->currentFrequency();
|
|
165 |
scrollToFrequency( mFrequency, 0 );
|
|
166 |
|
|
167 |
mButtonTimer = new QTimer( this );
|
|
168 |
mButtonTimer->setInterval( BUTTON_HIDE_TIMEOUT );
|
|
169 |
mButtonTimer->setSingleShot( true );
|
|
170 |
connectAndTest( mButtonTimer, SIGNAL(timeout()),
|
|
171 |
this, SLOT(toggleButtons()) );
|
|
172 |
|
|
173 |
connectAndTest( mLeftButton, SIGNAL(clicked()),
|
|
174 |
this, SLOT(handleLeftButton()) );
|
|
175 |
connectAndTest( mRightButton, SIGNAL(clicked()),
|
|
176 |
this, SLOT(handleRightButton()) );
|
|
177 |
connectAndTest( mLeftButton, SIGNAL(longPress(QPointF)),
|
|
178 |
this, SLOT(handleLongLeftButton()) );
|
|
179 |
connectAndTest( mRightButton, SIGNAL(longPress(QPointF)),
|
|
180 |
this, SLOT(handleLongRightButton()) );
|
|
181 |
|
|
182 |
connectAndTest( this, SIGNAL(scrollingEnded()),
|
|
183 |
this, SLOT(checkIllegalPos()) );
|
|
184 |
|
|
185 |
grabGesture( Qt::SwipeGesture );
|
|
186 |
|
|
187 |
//TODO: Remove. Stepsize hardcoded to 100 Khz in europe region during demo
|
|
188 |
if ( mFrequencyStepSize < K100Khz ) {
|
|
189 |
mFrequencyStepSize = K100Khz;
|
|
190 |
}
|
|
191 |
|
|
192 |
RadioStationModel* stationModel = &mUiEngine->stationModel();
|
|
193 |
connectAndTest( stationModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
194 |
this, SLOT(updateStation(QModelIndex,int,int)) );
|
|
195 |
connectAndTest( stationModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
196 |
this, SLOT(updateStation(QModelIndex,int,int)) );
|
|
197 |
connectAndTest( stationModel, SIGNAL(modelReset()),
|
|
198 |
this, SLOT(initEmptyItems()) );
|
|
199 |
|
|
200 |
initPositions();
|
|
201 |
|
|
202 |
void updateItems();
|
|
203 |
}
|
|
204 |
|
|
205 |
/*!
|
|
206 |
*
|
|
207 |
*/
|
|
208 |
void RadioFrequencyStrip::setFrequency( const uint frequency, int reason )
|
|
209 |
{
|
|
210 |
LOG_FORMAT( "RadioFrequencyStrip::setFrequency, frequency: %d, reason: %d", frequency, reason );
|
|
211 |
if ( reason != TuneReason::FrequencyStrip && // Not sent by the FrequencyStrip
|
|
212 |
frequency != mFrequency && // Different from the current
|
|
213 |
mFrequencies.contains( frequency ) ) // 0 frequency means any illegal value
|
|
214 |
{
|
|
215 |
scrollToFrequency( frequency, mAutoScrollTime );
|
|
216 |
if ( reason != TuneReason::Skip && reason != TuneReason::StationScan ) {
|
|
217 |
emitFrequencyChanged( frequency );
|
|
218 |
}
|
|
219 |
}
|
|
220 |
}
|
|
221 |
|
|
222 |
/*!
|
|
223 |
*
|
|
224 |
*/
|
|
225 |
uint RadioFrequencyStrip::frequency() const
|
|
226 |
{
|
|
227 |
return mFrequency;
|
|
228 |
}
|
|
229 |
|
|
230 |
/*!
|
|
231 |
* Public slot
|
|
232 |
*
|
|
233 |
*/
|
|
234 |
void RadioFrequencyStrip::updateFavorite( const RadioStation& station )
|
|
235 |
{
|
|
236 |
LOG_SLOT_CALLER;
|
|
237 |
FrequencyPos pos = mFrequencies.value( station.frequency() );
|
|
238 |
updateFavorites( pos.mItem );
|
|
239 |
}
|
|
240 |
|
|
241 |
/*!
|
|
242 |
* Public slot
|
|
243 |
*
|
|
244 |
*/
|
|
245 |
void RadioFrequencyStrip::setScanningMode( bool isScanning )
|
|
246 |
{
|
|
247 |
mButtonTimer->stop();
|
|
248 |
if ( isScanning ) {
|
|
249 |
scrollToFrequency( mMinFrequency, mAutoScrollTime );
|
|
250 |
hideButtons();
|
|
251 |
} else {
|
|
252 |
showButtons();
|
|
253 |
|
|
254 |
}
|
|
255 |
setEnabled( !isScanning );
|
|
256 |
}
|
|
257 |
|
|
258 |
/*!
|
|
259 |
* Private slot
|
|
260 |
*
|
|
261 |
*/
|
|
262 |
void RadioFrequencyStrip::updateStation( const QModelIndex& parent, int first, int last )
|
|
263 |
{
|
|
264 |
Q_UNUSED( parent );
|
|
265 |
RadioStationModel& model = mUiEngine->stationModel();
|
|
266 |
uint frequency = 0;
|
|
267 |
for ( int i = first; i <= last; ++i ) {
|
|
268 |
frequency = model.data( model.index( i, 0, QModelIndex() ),
|
|
269 |
RadioStationModel::RadioStationRole ).value<RadioStation>().frequency();
|
|
270 |
if ( mFrequencies.contains( frequency ) ) {
|
|
271 |
FrequencyPos pos = mFrequencies.value( frequency );
|
|
272 |
updateFavorites( pos.mItem );
|
|
273 |
}
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
/*!
|
|
278 |
* Private slot
|
|
279 |
*
|
|
280 |
*/
|
|
281 |
void RadioFrequencyStrip::initEmptyItems()
|
|
282 |
{
|
|
283 |
LOG_METHOD;
|
|
284 |
QList<RadioStation> emptyList;
|
|
285 |
foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
|
|
286 |
QPixmap pixmap = drawPixmap( item->frequency(), emptyList, item );
|
|
287 |
item->setPixmap( pixmap );
|
|
288 |
}
|
|
289 |
}
|
|
290 |
|
|
291 |
/*!
|
|
292 |
* Private slot
|
|
293 |
*/
|
|
294 |
void RadioFrequencyStrip::handleLeftButton()
|
|
295 |
{
|
|
296 |
emit skipRequested( StationSkip::PreviousFavorite );
|
|
297 |
}
|
|
298 |
|
|
299 |
/*!
|
|
300 |
* Private slot
|
|
301 |
*/
|
|
302 |
void RadioFrequencyStrip::handleLongLeftButton()
|
|
303 |
{
|
|
304 |
emit seekRequested( Seeking::Down );
|
|
305 |
}
|
|
306 |
|
|
307 |
/*!
|
|
308 |
* Private slot
|
|
309 |
*/
|
|
310 |
void RadioFrequencyStrip::handleRightButton()
|
|
311 |
{
|
|
312 |
emit skipRequested( StationSkip::NextFavorite );
|
|
313 |
}
|
|
314 |
|
|
315 |
/*!
|
|
316 |
* Private slot
|
|
317 |
*/
|
|
318 |
void RadioFrequencyStrip::handleLongRightButton()
|
|
319 |
{
|
|
320 |
emit seekRequested( Seeking::Up );
|
|
321 |
}
|
|
322 |
|
|
323 |
/*!
|
|
324 |
* Private slot
|
|
325 |
*/
|
|
326 |
void RadioFrequencyStrip::toggleButtons()
|
|
327 |
{
|
|
328 |
if ( mButtonsVisible ) {
|
|
329 |
hideButtons();
|
|
330 |
} else {
|
|
331 |
showButtons();
|
|
332 |
}
|
|
333 |
}
|
|
334 |
|
|
335 |
/*!
|
|
336 |
* Private slot
|
|
337 |
*/
|
|
338 |
void RadioFrequencyStrip::checkIllegalPos()
|
|
339 |
{
|
|
340 |
// Check if the selector is in the invalid area where the strip loops around
|
|
341 |
const int selectorPosition = selectorPos();
|
|
342 |
if ( !mPositions.contains( selectorPosition ) ) {
|
|
343 |
if ( selectorPosition < mMaxWidth - KWidth + mSeparatorPos ) {
|
|
344 |
scrollToFrequency( mMaxFrequency, 500 );
|
|
345 |
emitFrequencyChanged( mMaxFrequency );
|
|
346 |
} else {
|
|
347 |
scrollToFrequency( mMinFrequency, 500 );
|
|
348 |
emitFrequencyChanged( mMinFrequency );
|
|
349 |
}
|
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
/*!
|
|
354 |
* \reimp
|
|
355 |
*/
|
|
356 |
void RadioFrequencyStrip::updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex )
|
|
357 |
{
|
|
358 |
QGraphicsPixmapItem* item = static_cast<QGraphicsPixmapItem*>( itemToUpdate );
|
|
359 |
if ( itemIndex < mFrequencyItems.count() ) {
|
|
360 |
item->setPixmap( mFrequencyItems.at( itemIndex )->updatePrimitive( item ) );
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
/*!
|
|
365 |
* \reimp
|
|
366 |
*/
|
|
367 |
QGraphicsItem* RadioFrequencyStrip::createItemPrimitive( QGraphicsItem* parent )
|
|
368 |
{
|
|
369 |
return new QGraphicsPixmapItem( parent );
|
|
370 |
}
|
|
371 |
|
|
372 |
/*!
|
|
373 |
* \reimp
|
|
374 |
*/
|
|
375 |
void RadioFrequencyStrip::scrollPosChanged( QPointF newPosition )
|
|
376 |
{
|
|
377 |
Q_UNUSED( newPosition );
|
|
378 |
|
|
379 |
if ( mUserIsScrolling ) {
|
|
380 |
const int pos = selectorPos();
|
|
381 |
emitFrequencyChanged( mPositions.value( pos ) );
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
/*!
|
|
386 |
* \reimp
|
|
387 |
*/
|
|
388 |
void RadioFrequencyStrip::resizeEvent ( QGraphicsSceneResizeEvent* event )
|
|
389 |
{
|
|
390 |
LOG_METHOD_ENTER;
|
|
391 |
RadioStripBase::resizeEvent( event );
|
|
392 |
|
|
393 |
mSelectorPos = event->newSize().width() / 2;
|
|
394 |
mSelectorImage->setOffset( mSelectorPos - (KIndicatorWidth / 2), 0.0 );
|
|
395 |
|
|
396 |
const int stripHeight = event->newSize().height();
|
|
397 |
if ( !mLeftButtonIcon.isNull() ) {
|
|
398 |
mLeftButton->resize( stripHeight, stripHeight );
|
|
399 |
mLeftButton->setBackground( mLeftButtonIcon );
|
|
400 |
}
|
|
401 |
|
|
402 |
if ( !mRightButtonIcon.isNull() ) {
|
|
403 |
mRightButton->resize( stripHeight, stripHeight );
|
|
404 |
mRightButton->setBackground( mRightButtonIcon );
|
|
405 |
}
|
|
406 |
mRightButton->setPos( QPointF( size().width() - mRightButton->size().width(), 0 ) );
|
|
407 |
|
|
408 |
scrollToFrequency( mFrequency, 0 );
|
|
409 |
}
|
|
410 |
|
|
411 |
/*!
|
|
412 |
* \reimp
|
|
413 |
*/
|
|
414 |
void RadioFrequencyStrip::showEvent( QShowEvent* event )
|
|
415 |
{
|
|
416 |
Q_UNUSED( event );
|
|
417 |
scrollToFrequency( mFrequency, 0 );
|
|
418 |
}
|
|
419 |
|
|
420 |
/*!
|
|
421 |
* \reimp
|
|
422 |
*/
|
|
423 |
void RadioFrequencyStrip::changeEvent( QEvent* event )
|
|
424 |
{
|
|
425 |
if ( event->type() == HbEvent::ThemeChanged ) {
|
|
426 |
// Update the foreground color and redraw each item
|
|
427 |
mForegroundColor = Qt::white;// HbColorScheme::color( TEXT_COLOR_ATTRIBUTE );
|
|
428 |
updateItems();
|
|
429 |
}
|
|
430 |
|
|
431 |
return HbWidgetBase::changeEvent(event);
|
|
432 |
}
|
|
433 |
|
|
434 |
/*!
|
|
435 |
* \reimp
|
|
436 |
*/
|
|
437 |
void RadioFrequencyStrip::mousePressEvent( QGraphicsSceneMouseEvent* event )
|
|
438 |
{
|
|
439 |
RadioStripBase::mousePressEvent( event );
|
|
440 |
mUserIsScrolling = true;
|
|
441 |
mButtonTimer->stop();
|
|
442 |
mButtonTimer->start( BUTTON_HIDE_TIMEOUT );
|
|
443 |
}
|
|
444 |
|
|
445 |
/*!
|
|
446 |
* \reimp
|
|
447 |
*/
|
|
448 |
void RadioFrequencyStrip::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
|
|
449 |
{
|
|
450 |
mUserIsScrolling = false;
|
|
451 |
RadioStripBase::mouseReleaseEvent( event );
|
|
452 |
|
|
453 |
// if ( !mIsPanGesture ) {
|
|
454 |
// const qreal touchDelta = event->pos().x() - mSelectorPos;
|
|
455 |
// const int touchPos = selectorPosition + touchDelta;
|
|
456 |
// const uint frequencyAtPos = mPositions.value( touchPos );
|
|
457 |
//
|
|
458 |
// uint foundFrequency = 0;
|
|
459 |
// for ( int i = 0; i < 10; ++i ) {
|
|
460 |
// const uint delta = i * mFrequencyStepSize;
|
|
461 |
// FrequencyPos leftFreq = mFrequencies.value( frequencyAtPos - delta );
|
|
462 |
// FrequencyPos rightFreq = mFrequencies.value( frequencyAtPos + delta );
|
|
463 |
//
|
|
464 |
// if ( touchPos - leftFreq.mPosition > KTouchPosThreshold ) {
|
|
465 |
// break;
|
|
466 |
// }
|
|
467 |
//
|
|
468 |
// if ( leftFreq.mFavorite || leftFreq.mLocalStation ) {
|
|
469 |
// foundFrequency = frequencyAtPos - delta;
|
|
470 |
// break;
|
|
471 |
// } else if ( rightFreq.mFavorite || rightFreq.mLocalStation ) {
|
|
472 |
// foundFrequency = frequencyAtPos + delta;
|
|
473 |
// break;
|
|
474 |
// }
|
|
475 |
// }
|
|
476 |
//
|
|
477 |
// if ( foundFrequency > 0 ) {
|
|
478 |
// setFrequency( foundFrequency, 0 );
|
|
479 |
// }
|
|
480 |
// }
|
|
481 |
|
|
482 |
mButtonTimer->stop();
|
|
483 |
if ( !mButtonsVisible ) {
|
|
484 |
mButtonTimer->start( BUTTON_SHOW_TIMEOUT );
|
|
485 |
}
|
|
486 |
}
|
|
487 |
|
|
488 |
/*!
|
|
489 |
* \reimp
|
|
490 |
*/
|
|
491 |
void RadioFrequencyStrip::gestureEvent( QGestureEvent* event )
|
|
492 |
{
|
|
493 |
if ( HbSwipeGesture* gesture = static_cast<HbSwipeGesture*>( event->gesture( Qt::SwipeGesture ) ) ) {
|
|
494 |
if ( gesture->state() == Qt::GestureFinished ) {
|
|
495 |
if ( gesture->horizontalDirection() == QSwipeGesture::Left ) {
|
|
496 |
emit skipRequested( StationSkip::Next );
|
|
497 |
} else if ( gesture->horizontalDirection() == QSwipeGesture::Right ) {
|
|
498 |
emit skipRequested( StationSkip::Previous );
|
|
499 |
}
|
|
500 |
}
|
|
501 |
} else {
|
|
502 |
RadioStripBase::gestureEvent( event );
|
|
503 |
}
|
|
504 |
}
|
|
505 |
|
|
506 |
/*!
|
|
507 |
*
|
|
508 |
*/
|
|
509 |
void RadioFrequencyStrip::initModel()
|
|
510 |
{
|
|
511 |
const uint minFreq = uint( qreal(mMinFrequency) / KOneHertz + KRounder );
|
|
512 |
const uint maxFreq = uint( qreal(mMaxFrequency) / KOneHertz + 0.9 ); // always round up
|
|
513 |
|
|
514 |
QStringList list;
|
|
515 |
QString freqText;
|
|
516 |
for ( uint i = minFreq; i <= maxFreq; ++i ) {
|
|
517 |
freqText = QString::number( i );
|
|
518 |
list.append( freqText );
|
|
519 |
mFrequencyItems.append( new RadioFrequencyItem( freqText ) );
|
|
520 |
}
|
|
521 |
mFrequencyItems.append( new RadioFrequencyItem( "" ) );
|
|
522 |
list.append( "" );
|
|
523 |
|
|
524 |
mMaxWidth = list.count() * KWidth;
|
|
525 |
|
|
526 |
mSeparatorPos = qreal(KWidth) / 2;
|
|
527 |
const uint minDrawableFreq = minFreq * KOneHertz - KHalfHertz;;
|
|
528 |
const uint maxDrawableFreq = maxFreq * KOneHertz + KHalfHertz;
|
|
529 |
mSeparatorPos += qreal( ( mMinFrequency - minDrawableFreq ) / 2 ) / KPixelInHz;
|
|
530 |
mSeparatorPos -= qreal( ( maxDrawableFreq - mMaxFrequency ) / 2 ) / KPixelInHz;
|
|
531 |
|
|
532 |
setModel( new QStringListModel( list, this ) );
|
|
533 |
}
|
|
534 |
|
|
535 |
/*!
|
|
536 |
*
|
|
537 |
*/
|
|
538 |
void RadioFrequencyStrip::initSelector()
|
|
539 |
{
|
|
540 |
QPixmap selectorPixmap = QPixmap( QSize( KSelectorWidth, KHeight ) );
|
|
541 |
selectorPixmap.fill( Qt::red );
|
|
542 |
mSelectorImage->setPixmap( selectorPixmap );
|
|
543 |
mSelectorImage->setZValue( KSelectorZPos );
|
|
544 |
}
|
|
545 |
|
|
546 |
/*!
|
|
547 |
*
|
|
548 |
*/
|
|
549 |
void RadioFrequencyStrip::initPositions()
|
|
550 |
{
|
|
551 |
int prevPos = 0;
|
|
552 |
int nextPos = 0;
|
|
553 |
const int lastPos = mFrequencies.value( mMaxFrequency ).mPosition;
|
|
554 |
for ( int i = mFrequencies.value( mMinFrequency ).mPosition; i < lastPos; ++i ) {
|
|
555 |
if ( mPositions.contains( i ) ) {
|
|
556 |
prevPos = i;
|
|
557 |
const uint freq = mPositions.value( prevPos ) + mFrequencyStepSize;
|
|
558 |
if ( mFrequencies.contains( freq ) ) {
|
|
559 |
nextPos = mFrequencies.value( freq ).mPosition;
|
|
560 |
} else {
|
|
561 |
nextPos = prevPos;
|
|
562 |
}
|
|
563 |
} else {
|
|
564 |
const int nearestHit = ( i - prevPos ) < ( nextPos - i ) ? prevPos : nextPos;
|
|
565 |
mPositions.insert( i, mPositions.value( nearestHit ) );
|
|
566 |
}
|
|
567 |
}
|
|
568 |
}
|
|
569 |
|
|
570 |
/*!
|
|
571 |
*
|
|
572 |
*/
|
|
573 |
void RadioFrequencyStrip::initButtons()
|
|
574 |
{
|
|
575 |
mLeftButton->setZValue( KSelectorZPos );
|
|
576 |
mLeftButton->setObjectName( LEFT_BUTTON );
|
|
577 |
mRightButton->setZValue( KSelectorZPos );
|
|
578 |
mRightButton->setObjectName( RIGHT_BUTTON );
|
|
579 |
|
|
580 |
QEffectList effectList;
|
|
581 |
effectList.append( EffectInfo( mLeftButton, ":/effects/slide_to_left.fxml", KSlideToLeft ) );
|
|
582 |
effectList.append( EffectInfo( mLeftButton, ":/effects/slide_from_left.fxml", KSlideFromLeft ) );
|
|
583 |
effectList.append( EffectInfo( mRightButton, ":/effects/slide_to_right.fxml", KSlideToRight ) );
|
|
584 |
effectList.append( EffectInfo( mRightButton, ":/effects/slide_from_right.fxml", KSlideFromRight ) );
|
|
585 |
RadioUiUtilities::addEffects( effectList );
|
|
586 |
}
|
|
587 |
|
|
588 |
/*!
|
|
589 |
*
|
|
590 |
*/
|
|
591 |
void RadioFrequencyStrip::addFrequencyPos( int pos, uint frequency, RadioFrequencyItem* item )
|
|
592 |
{
|
|
593 |
mFrequencies.insert( frequency, FrequencyPos( pos, item ) );
|
|
594 |
mPositions.insert( pos, frequency );
|
|
595 |
}
|
|
596 |
|
|
597 |
/*!
|
|
598 |
*
|
|
599 |
*/
|
|
600 |
void RadioFrequencyStrip::updateFavorites( RadioFrequencyItem* item )
|
|
601 |
{
|
|
602 |
if ( item ) {
|
|
603 |
uint frequency = item->frequency();
|
|
604 |
QList<RadioStation> stations;
|
|
605 |
if ( mUiEngine ) {
|
|
606 |
stations = mUiEngine->stationsInRange( frequency - KHalfHertz, frequency + KHalfHertz );
|
|
607 |
}
|
|
608 |
|
|
609 |
QPixmap pixmap = drawPixmap( frequency, stations, item );
|
|
610 |
item->setPixmap( pixmap );
|
|
611 |
|
|
612 |
foreach ( const RadioStation& station, stations ) {
|
|
613 |
frequency = station.frequency();
|
|
614 |
FrequencyPos pos = mFrequencies.value( frequency );
|
|
615 |
mFrequencies.insert( frequency, pos );
|
|
616 |
}
|
|
617 |
}
|
|
618 |
}
|
|
619 |
|
|
620 |
/*!
|
|
621 |
*
|
|
622 |
*/
|
|
623 |
void RadioFrequencyStrip::updateItems()
|
|
624 |
{
|
|
625 |
foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
|
|
626 |
updateFavorites( item );
|
|
627 |
}
|
|
628 |
}
|
|
629 |
|
|
630 |
/*!
|
|
631 |
*
|
|
632 |
*/
|
|
633 |
QPixmap RadioFrequencyStrip::drawPixmap( uint frequency, QList<RadioStation> stations, RadioFrequencyItem* item )
|
|
634 |
{
|
|
635 |
QPixmap pixmap( KWidth, KHeight );
|
|
636 |
pixmap.fill( Qt::transparent );
|
|
637 |
QPainter painter( &pixmap );
|
|
638 |
QPen normalPen = painter.pen();
|
|
639 |
QPen favoritePen = normalPen;
|
|
640 |
normalPen.setColor( mForegroundColor );
|
|
641 |
painter.setPen( normalPen );
|
|
642 |
|
|
643 |
if ( frequency == 0 ) {
|
|
644 |
painter.drawLine( makeTab( mSeparatorPos - 1 + KRounder, KHeight ) );
|
|
645 |
painter.drawLine( makeTab( mSeparatorPos + KRounder, KHeight ) );
|
|
646 |
return pixmap;
|
|
647 |
}
|
|
648 |
|
|
649 |
const QString itemText = QString::number( frequency / KOneHertz );
|
|
650 |
const uint startFrequency = frequency - KHalfHertz;
|
|
651 |
const uint endFrequency = startFrequency + KOneHertz;
|
|
652 |
const uint roundedMin = int( qreal(mMinFrequency) / KOneHertz + KRounder );
|
|
653 |
const uint freq = frequency / KOneHertz;
|
|
654 |
const int diff = freq - roundedMin;
|
|
655 |
const qreal startPixel = diff * KWidth;
|
|
656 |
qreal pixels = 0.0;
|
|
657 |
QFont painterFont = painter.font();
|
|
658 |
painterFont.setPointSize( 6 );
|
|
659 |
painter.setFont( painterFont );
|
|
660 |
|
|
661 |
const int charWidth = painter.fontMetrics().averageCharWidth();
|
|
662 |
for ( uint frequency = startFrequency; frequency <= endFrequency; frequency += mFrequencyStepSize ) {
|
|
663 |
|
|
664 |
if ( frequency < mMinFrequency || frequency > mMaxFrequency ) {
|
|
665 |
continue;
|
|
666 |
}
|
|
667 |
|
|
668 |
pixels = qreal( frequency - startFrequency ) / KPixelInHz;
|
|
669 |
if ( frequency % KOneHertz == 0 ) {
|
|
670 |
|
|
671 |
// Draw the high frequency tab and the frequency text for the even number
|
|
672 |
painter.drawLine( makeTab( pixels, KTabHeightBig ) );
|
|
673 |
const int textPosX = pixels - itemText.length() * charWidth / 2;
|
|
674 |
painter.drawText( QPoint( textPosX, 20 ), itemText );
|
|
675 |
|
|
676 |
} else if ( frequency % KOneTabInHz == 0 ) {
|
|
677 |
|
|
678 |
// Draw the low frequency tab for the uneven number
|
|
679 |
painter.drawLine( makeTab( pixels, KTabHeightSmall ) );
|
|
680 |
|
|
681 |
}
|
|
682 |
|
|
683 |
addFrequencyPos( startPixel + pixels + KRounder, frequency, item );
|
|
684 |
}
|
|
685 |
|
|
686 |
// Draw favorites and local stations
|
|
687 |
favoritePen.setColor( Qt::yellow );
|
|
688 |
|
|
689 |
const int markerYPos = KHeight - 20;
|
|
690 |
foreach ( const RadioStation& station, stations ) {
|
|
691 |
const uint frequency = station.frequency();
|
|
692 |
pixels = qreal( frequency - startFrequency ) / KPixelInHz;
|
|
693 |
|
|
694 |
if ( station.isFavorite() ) {
|
|
695 |
favoritePen.setWidth( KTabWidthFavorite );
|
|
696 |
painter.setPen( favoritePen );
|
|
697 |
painter.drawEllipse( pixels - 3, markerYPos - 3, 6, 6 );
|
|
698 |
// painter.drawPixmap( pixels - 10, 20, 20, 20, mFavoriteIcon.pixmap() );
|
|
699 |
} else if ( station.isType( RadioStation::LocalStation ) ) {
|
|
700 |
// painter.setPen( normalPen );
|
|
701 |
// painter.drawLine( pixels, // Start X
|
|
702 |
// KHeight - KTabHeightFavorite, // Start Y
|
|
703 |
// pixels, // End X
|
|
704 |
// KHeight ); // End Y
|
|
705 |
|
|
706 |
favoritePen.setWidth( 1 );
|
|
707 |
painter.setPen( favoritePen );
|
|
708 |
painter.drawEllipse( pixels - 4, markerYPos - 4, 8, 8 );
|
|
709 |
}
|
|
710 |
}
|
|
711 |
|
|
712 |
return pixmap;
|
|
713 |
}
|
|
714 |
|
|
715 |
/*!
|
|
716 |
*
|
|
717 |
*/
|
|
718 |
void RadioFrequencyStrip::emitFrequencyChanged( uint frequency )
|
|
719 |
{
|
|
720 |
if ( frequency > 0 && frequency != mFrequency ) {
|
|
721 |
mFrequency = frequency;
|
|
722 |
emit frequencyChanged( frequency, TuneReason::FrequencyStrip );
|
|
723 |
}
|
|
724 |
}
|
|
725 |
|
|
726 |
/*!
|
|
727 |
*
|
|
728 |
*/
|
|
729 |
int RadioFrequencyStrip::selectorPos() const
|
|
730 |
{
|
|
731 |
const int pos = ( -contentWidget()->x() + mSelectorPos ) + KRounder;
|
|
732 |
return pos % mMaxWidth;
|
|
733 |
}
|
|
734 |
|
|
735 |
/*!
|
|
736 |
*
|
|
737 |
*/
|
|
738 |
void RadioFrequencyStrip::scrollToFrequency( uint frequency, int time )
|
|
739 |
{
|
|
740 |
// Find the shortest route to the requested frequency.
|
|
741 |
const int pos = ( -contentWidget()->x() + mSelectorPos ) + KRounder;
|
|
742 |
if ( pos >= mMaxWidth - KWidth + mSeparatorPos ) {
|
|
743 |
const qreal newPos = qreal( mFrequencies.value( frequency ).mPosition ) - mSelectorPos + mMaxWidth;
|
|
744 |
scrollContentsTo( QPointF( newPos, 0 ), time );
|
|
745 |
} else {
|
|
746 |
scrollContentsTo( QPointF( qreal( mFrequencies.value( frequency ).mPosition ) - mSelectorPos, 0 ), time );
|
|
747 |
}
|
|
748 |
}
|
|
749 |
|
|
750 |
/*!
|
|
751 |
*
|
|
752 |
*/
|
|
753 |
void RadioFrequencyStrip::hideButtons()
|
|
754 |
{
|
|
755 |
mButtonsVisible = false;
|
|
756 |
HbEffect::start( mLeftButton, KSlideToLeft );
|
|
757 |
HbEffect::start( mRightButton, KSlideToRight );
|
|
758 |
}
|
|
759 |
|
|
760 |
/*!
|
|
761 |
*
|
|
762 |
*/
|
|
763 |
void RadioFrequencyStrip::showButtons()
|
|
764 |
{
|
|
765 |
mButtonsVisible = true;
|
|
766 |
HbEffect::start( mLeftButton, KSlideFromLeft );
|
|
767 |
HbEffect::start( mRightButton, KSlideFromRight );
|
|
768 |
}
|