39
|
1 |
/*
|
57
|
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 |
*/
|
39
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <HbDocumentLoader>
|
|
20 |
#include <HbEffect>
|
|
21 |
#include <QPainter>
|
|
22 |
#include <QStringListModel>
|
|
23 |
#include <QGraphicsSceneResizeEvent>
|
|
24 |
#include <QPen>
|
|
25 |
#include <HbPushButton>
|
|
26 |
#include <QTimer>
|
|
27 |
#include <HbColorScheme>
|
|
28 |
#include <HbEvent>
|
|
29 |
#include <HbSwipeGesture>
|
|
30 |
#include <HbDeviceProfile>
|
|
31 |
#include <QDebug>
|
|
32 |
|
|
33 |
// User includes
|
|
34 |
#include "radiofrequencystripbase.h"
|
|
35 |
#include "radiofrequencystripdef.h"
|
|
36 |
#include "radiofrequencyitem.h"
|
|
37 |
|
|
38 |
/*!
|
|
39 |
* Convenience function to check signal-slot connections
|
|
40 |
*/
|
|
41 |
//#define CHECK_SIGNAL_CONNECTIONS
|
|
42 |
static bool connectAndCheck( const QObject* sender, const char* signal,
|
|
43 |
const QObject* receiver, const char* member,
|
|
44 |
Qt::ConnectionType type = Qt::AutoConnection )
|
|
45 |
{
|
|
46 |
bool connected = QObject::connect( sender, signal, receiver, member, type );
|
|
47 |
|
|
48 |
#ifdef CHECK_SIGNAL_CONNECTIONS
|
|
49 |
|
|
50 |
if ( !connected ) {
|
|
51 |
qDebug() << "Failed to make a signal-slot connection!";
|
|
52 |
qDebug() << "sender: " << sender->metaObject()->className();
|
|
53 |
qDebug() << "signal: " << signal;
|
|
54 |
qDebug() << "receiver: " << receiver->metaObject()->className();
|
|
55 |
qDebug() << "slot/signal: " << signal;
|
|
56 |
|
|
57 |
Q_ASSERT( false );
|
|
58 |
|
|
59 |
// ----------------------------------------------------------------
|
|
60 |
// SIGNAL-SLOT CONNECT FAILED!
|
|
61 |
// ----------------------------------------------------------------
|
|
62 |
}
|
|
63 |
|
|
64 |
#endif // CHECK_SIGNAL_CONNECTIONS
|
|
65 |
|
|
66 |
return connected;
|
|
67 |
}
|
|
68 |
|
|
69 |
/*!
|
|
70 |
*
|
|
71 |
*/
|
|
72 |
RadioFrequencyStripBase::RadioFrequencyStripBase( QGraphicsItem* parent ) :
|
|
73 |
RadioStripBase( parent ),
|
57
|
74 |
mItemHeight( FrequencyStrip::DEFAULT_ITEM_HEIGHT_UNITS ),
|
|
75 |
mMinFrequency( FrequencyStrip::DEFAULT_MIN_FREQUENCY ),
|
|
76 |
mMaxFrequency( FrequencyStrip::DEFAULT_MAX_FREQUENCY ),
|
|
77 |
mFrequencyStepSize( FrequencyStrip::DEFAULT_FREQUENCY_STEP ),
|
|
78 |
mFrequency( FrequencyStrip::DEFAULT_MIN_FREQUENCY ),
|
39
|
79 |
mSelectorImage( new QGraphicsPixmapItem( this ) ),
|
|
80 |
mSeparatorPos( 0.0 ),
|
|
81 |
mMaxWidth( 0 ),
|
|
82 |
mSelectorPos( 0.0 ),
|
|
83 |
mLeftButton( 0 ),
|
|
84 |
mRightButton( 0 ),
|
|
85 |
mManualSeekTimer( NULL ),
|
|
86 |
mManualSeekMode( false ),
|
|
87 |
mLastReportedFrequency( 0 ),
|
|
88 |
mManualSeekTimerId( 0 ),
|
57
|
89 |
mForegroundColor( HbColorScheme::color( FrequencyStrip::TEXT_COLOR_ATTRIBUTE ) ),
|
54
|
90 |
mIgnoreScrollingEnd( false )
|
39
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
/*!
|
57
|
95 |
*
|
|
96 |
*/
|
|
97 |
RadioFrequencyStripBase::~RadioFrequencyStripBase()
|
|
98 |
{
|
|
99 |
qDeleteAll( mFrequencyItems );
|
|
100 |
}
|
|
101 |
|
|
102 |
/*!
|
39
|
103 |
* Property
|
|
104 |
*/
|
|
105 |
void RadioFrequencyStripBase::setItemHeight( int itemHeight )
|
|
106 |
{
|
|
107 |
mItemHeight = itemHeight;
|
|
108 |
}
|
|
109 |
|
|
110 |
/*!
|
|
111 |
* Property
|
|
112 |
*/
|
|
113 |
int RadioFrequencyStripBase::itemHeight() const
|
|
114 |
{
|
|
115 |
return mItemHeight;
|
|
116 |
}
|
|
117 |
|
|
118 |
/*!
|
|
119 |
*
|
|
120 |
*/
|
|
121 |
void RadioFrequencyStripBase::initbase( uint minFrequency, uint maxFrequency, uint stepSize, uint frequency )
|
|
122 |
{
|
|
123 |
mMinFrequency = minFrequency;
|
|
124 |
mMaxFrequency = maxFrequency;
|
|
125 |
mFrequencyStepSize = stepSize;
|
|
126 |
mFrequency = frequency;
|
|
127 |
|
54
|
128 |
setScrollingStyle( HbScrollArea::PanWithFollowOn );
|
|
129 |
|
|
130 |
HbDeviceProfile deviceProfile;
|
|
131 |
mItemHeight = static_cast<int>( mItemHeight * deviceProfile.unitValue() );
|
|
132 |
setItemSize( QSizeF( FrequencyStrip::ITEM_WIDTH + FrequencyStrip::PIXMAP_OVERLAP / 2, mItemHeight ) );
|
|
133 |
|
|
134 |
setOverlap( FrequencyStrip::PIXMAP_OVERLAP / 2 );
|
|
135 |
|
57
|
136 |
mStationIcon.setIconName("qtg_graf_tuner_unselected");
|
|
137 |
mFavoriteIcon.setIconName("qtg_graf_tuner_selected");
|
|
138 |
mStationIcon.setSize( QSizeF( FrequencyStrip::STATION_MARKER_SIZE, FrequencyStrip::STATION_MARKER_SIZE ) );
|
|
139 |
mFavoriteIcon.setSize( QSizeF( FrequencyStrip::STATION_MARKER_SIZE, FrequencyStrip::STATION_MARKER_SIZE ) );
|
|
140 |
|
39
|
141 |
initModel();
|
|
142 |
initEmptyItems();
|
|
143 |
initPositions();
|
|
144 |
|
|
145 |
mManualSeekTimer = new QTimer( this );
|
|
146 |
mManualSeekTimer->setInterval( FrequencyStrip::MANUALSEEK_START_TIMEOUT );
|
|
147 |
mManualSeekTimer->setSingleShot( true );
|
|
148 |
connectAndCheck( mManualSeekTimer, SIGNAL(timeout()),
|
|
149 |
this, SLOT(toggleManualSeek()) );
|
|
150 |
|
|
151 |
connectAndCheck( this, SIGNAL(scrollingEnded()),
|
|
152 |
this, SLOT(handleScrollingEnd()) );
|
|
153 |
|
|
154 |
grabGesture( Qt::SwipeGesture );
|
|
155 |
|
|
156 |
//TODO: Remove. Stepsize temporarily hardcoded to 100 Khz in europe region
|
|
157 |
if ( mFrequencyStepSize < FrequencyStrip::ONE_HUNDRED_KHZ ) {
|
|
158 |
mFrequencyStepSize = FrequencyStrip::ONE_HUNDRED_KHZ;
|
|
159 |
}
|
|
160 |
|
|
161 |
updateAllItems();
|
|
162 |
|
|
163 |
showButtons();
|
|
164 |
}
|
|
165 |
|
|
166 |
/*!
|
|
167 |
*
|
|
168 |
*/
|
|
169 |
void RadioFrequencyStripBase::createButtonsFromDocml( HbDocumentLoader& uiLoader, const QString& leftButtonName, const QString& rightButtonName )
|
|
170 |
{
|
|
171 |
Q_ASSERT( !mLeftButton && !mRightButton );
|
|
172 |
mLeftButton = qobject_cast<HbPushButton*>( uiLoader.findWidget( leftButtonName ) );
|
|
173 |
mRightButton = qobject_cast<HbPushButton*>( uiLoader.findWidget( rightButtonName ) );
|
|
174 |
|
|
175 |
initButtons();
|
|
176 |
}
|
|
177 |
|
|
178 |
/*!
|
|
179 |
*
|
|
180 |
*/
|
|
181 |
void RadioFrequencyStripBase::createButtons()
|
|
182 |
{
|
|
183 |
Q_ASSERT( !mLeftButton && !mRightButton );
|
|
184 |
mLeftButton = new HbPushButton( this );
|
|
185 |
mRightButton = new HbPushButton( this );
|
|
186 |
|
|
187 |
mLeftButton->setIcon( HbIcon( "qtg_mono_previous" ) );
|
|
188 |
mRightButton->setIcon( HbIcon( "qtg_mono_next" ) );
|
|
189 |
|
|
190 |
initButtons();
|
|
191 |
}
|
|
192 |
|
|
193 |
/*!
|
|
194 |
*
|
|
195 |
*/
|
|
196 |
void RadioFrequencyStripBase::setFrequency( const uint frequency, int reason, Scroll::Direction direction )
|
|
197 |
{
|
47
|
198 |
Q_UNUSED( reason );
|
|
199 |
|
39
|
200 |
if ( mFrequencies.contains( frequency ) ) {
|
|
201 |
scrollToFrequency( frequency, direction, mAutoScrollTime );
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
/*!
|
|
206 |
*
|
|
207 |
*/
|
|
208 |
uint RadioFrequencyStripBase::frequency() const
|
|
209 |
{
|
|
210 |
return mFrequency;
|
|
211 |
}
|
|
212 |
|
|
213 |
/*!
|
|
214 |
*
|
|
215 |
*/
|
|
216 |
bool RadioFrequencyStripBase::isInManualSeekMode() const
|
|
217 |
{
|
|
218 |
return mManualSeekMode;
|
|
219 |
}
|
|
220 |
|
|
221 |
/*!
|
|
222 |
*
|
|
223 |
*/
|
|
224 |
void RadioFrequencyStripBase::cancelManualSeek()
|
|
225 |
{
|
|
226 |
mManualSeekTimer->stop();
|
|
227 |
if ( mManualSeekMode ) {
|
|
228 |
toggleManualSeek();
|
|
229 |
}
|
|
230 |
}
|
|
231 |
|
|
232 |
/*!
|
|
233 |
*
|
|
234 |
*/
|
|
235 |
void RadioFrequencyStripBase::addScannedStation( uint frequency )
|
|
236 |
{
|
|
237 |
FrequencyPos pos = mFrequencies.value( frequency );
|
|
238 |
updateItem( pos.mItem, frequency );
|
|
239 |
}
|
|
240 |
|
|
241 |
/*!
|
|
242 |
*
|
|
243 |
*/
|
|
244 |
void RadioFrequencyStripBase::updateFavorite( uint frequency )
|
|
245 |
{
|
|
246 |
FrequencyPos pos = mFrequencies.value( frequency );
|
|
247 |
updateItem( pos.mItem );
|
|
248 |
}
|
|
249 |
|
|
250 |
/*!
|
|
251 |
* Public slot
|
|
252 |
*
|
|
253 |
*/
|
|
254 |
void RadioFrequencyStripBase::setScanningMode( bool isScanning )
|
|
255 |
{
|
|
256 |
mManualSeekTimer->stop();
|
|
257 |
if ( isScanning ) {
|
|
258 |
initEmptyItems();
|
|
259 |
hideButtons();
|
|
260 |
scrollToFrequency( mMinFrequency, Scroll::Shortest, mAutoScrollTime );
|
|
261 |
} else {
|
|
262 |
showButtons();
|
|
263 |
}
|
|
264 |
setEnabled( !isScanning );
|
|
265 |
}
|
|
266 |
|
|
267 |
/*!
|
|
268 |
* Private slot
|
|
269 |
*
|
|
270 |
*/
|
|
271 |
void RadioFrequencyStripBase::initEmptyItems()
|
|
272 |
{
|
|
273 |
//TODO: Remove the weird hack of checking the sender
|
|
274 |
if ( !sender() || !isScanning() ) {
|
|
275 |
QList<FrequencyStrip::StationMarker> emptyList;
|
|
276 |
foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
|
|
277 |
QPixmap pixmap = drawPixmap( item->frequency(), emptyList, item );
|
|
278 |
item->setPixmap( pixmap );
|
|
279 |
}
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
/*!
|
|
284 |
* Private slot
|
|
285 |
*
|
|
286 |
*/
|
57
|
287 |
void RadioFrequencyStripBase::stationsRemoved( const QList<uint>& frequencies )
|
39
|
288 |
{
|
57
|
289 |
QList<uint>::const_iterator end = frequencies.constEnd();
|
|
290 |
QSet<RadioFrequencyItem*> freqItems;
|
|
291 |
// go frequencies list throught and fetch all frequencyItems required. Duplicates will be removed
|
|
292 |
// using set to prevent unneccessary item updates.
|
|
293 |
for( QList<uint>::const_iterator iter = frequencies.constBegin(); iter != end; ++iter ) {
|
|
294 |
freqItems.insert( mFrequencies.value( *iter ).mItem );
|
|
295 |
}
|
|
296 |
QSet<RadioFrequencyItem*>::const_iterator setEnd = freqItems.constEnd();
|
|
297 |
QSet<RadioFrequencyItem*>::const_iterator setIter = freqItems.constBegin();
|
|
298 |
for( ; setIter != setEnd; ++setIter ) {
|
|
299 |
updateItem( *setIter, 0, 0 );
|
|
300 |
}
|
39
|
301 |
}
|
|
302 |
|
|
303 |
/*!
|
|
304 |
* Private slot
|
|
305 |
*
|
|
306 |
*/
|
|
307 |
void RadioFrequencyStripBase::updateStation( const QModelIndex& parent, int first, int last )
|
|
308 |
{
|
|
309 |
Q_UNUSED( parent );
|
|
310 |
updateStationsInRange( first, last );
|
|
311 |
}
|
|
312 |
|
|
313 |
/*!
|
|
314 |
* Private slot
|
|
315 |
*/
|
|
316 |
void RadioFrequencyStripBase::handleLeftButton()
|
|
317 |
{
|
44
|
318 |
skipToPrevious();
|
39
|
319 |
}
|
|
320 |
|
|
321 |
/*!
|
|
322 |
* Private slot
|
|
323 |
*/
|
|
324 |
void RadioFrequencyStripBase::handleRightButton()
|
|
325 |
{
|
44
|
326 |
skipToNext();
|
39
|
327 |
}
|
|
328 |
|
|
329 |
/*!
|
|
330 |
* Private slot
|
|
331 |
*/
|
|
332 |
void RadioFrequencyStripBase::handleLongLeftButton()
|
|
333 |
{
|
|
334 |
seekDown();
|
|
335 |
}
|
|
336 |
|
|
337 |
/*!
|
|
338 |
* Private slot
|
|
339 |
*/
|
|
340 |
void RadioFrequencyStripBase::handleLongRightButton()
|
|
341 |
{
|
|
342 |
seekUp();
|
|
343 |
}
|
|
344 |
|
|
345 |
/*!
|
|
346 |
* Private slot
|
|
347 |
*
|
|
348 |
*/
|
|
349 |
void RadioFrequencyStripBase::toggleManualSeek()
|
|
350 |
{
|
|
351 |
mManualSeekMode = !mManualSeekMode;
|
|
352 |
emit manualSeekChanged( mManualSeekMode );
|
|
353 |
|
|
354 |
if ( mManualSeekMode ) {
|
|
355 |
grabMouse();
|
|
356 |
hideButtons();
|
|
357 |
mManualSeekTimerId = startTimer( FrequencyStrip::MANUALSEEK_SIGNAL_DELAY );
|
|
358 |
} else {
|
|
359 |
ungrabMouse();
|
|
360 |
showButtons();
|
|
361 |
killTimer( mManualSeekTimerId );
|
|
362 |
mManualSeekTimerId = 0;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
|
|
366 |
/*!
|
|
367 |
* Private slot
|
|
368 |
*/
|
|
369 |
void RadioFrequencyStripBase::handleScrollingEnd()
|
|
370 |
{
|
54
|
371 |
if ( mIgnoreScrollingEnd ) {
|
|
372 |
mIgnoreScrollingEnd = false;
|
|
373 |
return;
|
|
374 |
}
|
|
375 |
|
39
|
376 |
// Check if the selector is in the invalid area where the strip loops around
|
|
377 |
const int selectorPosition = selectorPos();
|
|
378 |
if ( mManualSeekMode ) {
|
|
379 |
if ( !mPositions.contains( selectorPosition ) ) {
|
|
380 |
if ( selectorPosition < mMaxWidth - FrequencyStrip::ITEM_WIDTH + mSeparatorPos ) {
|
57
|
381 |
scrollToFrequency( mMaxFrequency, Scroll::Shortest, FrequencyStrip::POS_ADJUST_DELAY_MS );
|
39
|
382 |
emitFrequencyChanged( mMaxFrequency, FrequencyStrip::ManualSeekUpdate, Scroll::Shortest );
|
|
383 |
} else {
|
57
|
384 |
scrollToFrequency( mMinFrequency, Scroll::Shortest, FrequencyStrip::POS_ADJUST_DELAY_MS );
|
39
|
385 |
emitFrequencyChanged( mMinFrequency, FrequencyStrip::ManualSeekUpdate, Scroll::Shortest );
|
|
386 |
}
|
|
387 |
}
|
|
388 |
|
|
389 |
mManualSeekTimer->start( FrequencyStrip::MANUALSEEK_END_TIMEOUT );
|
|
390 |
}
|
|
391 |
}
|
|
392 |
|
|
393 |
/*!
|
|
394 |
* \reimp
|
|
395 |
*/
|
|
396 |
void RadioFrequencyStripBase::updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex )
|
|
397 |
{
|
|
398 |
QGraphicsPixmapItem* item = static_cast<QGraphicsPixmapItem*>( itemToUpdate );
|
|
399 |
if ( itemIndex < mFrequencyItems.count() ) {
|
|
400 |
item->setPixmap( mFrequencyItems.at( itemIndex )->updatePrimitive( item ) );
|
|
401 |
}
|
|
402 |
}
|
|
403 |
|
|
404 |
/*!
|
|
405 |
* \reimp
|
|
406 |
*/
|
|
407 |
QGraphicsItem* RadioFrequencyStripBase::createItemPrimitive( QGraphicsItem* parent )
|
|
408 |
{
|
|
409 |
return new QGraphicsPixmapItem( parent );
|
|
410 |
}
|
|
411 |
|
|
412 |
/*!
|
|
413 |
* \reimp
|
|
414 |
*/
|
|
415 |
void RadioFrequencyStripBase::scrollPosChanged()
|
|
416 |
{
|
|
417 |
if ( mManualSeekMode ) {
|
|
418 |
const int pos = selectorPos();
|
|
419 |
const uint frequency = mPositions.value( pos );
|
54
|
420 |
if ( frequency > 0 && mFrequency != frequency ) {
|
|
421 |
mFrequency = frequency;
|
39
|
422 |
emitFrequencyChanged( mFrequency, FrequencyStrip::ManualSeekUpdate, Scroll::Shortest );
|
|
423 |
}
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
/*!
|
|
428 |
* \reimp
|
|
429 |
*/
|
|
430 |
void RadioFrequencyStripBase::resizeEvent ( QGraphicsSceneResizeEvent* event )
|
|
431 |
{
|
|
432 |
RadioStripBase::resizeEvent( event );
|
|
433 |
|
|
434 |
initSelector();
|
|
435 |
|
|
436 |
const qreal height = event->newSize().height();
|
|
437 |
const qreal width = event->newSize().width();
|
|
438 |
|
|
439 |
mSelectorPos = width / 2;
|
|
440 |
mSelectorImage->setOffset( mSelectorPos - ( FrequencyStrip::INDICATOR_WIDTH / 2 ), 0.0 );
|
|
441 |
|
|
442 |
if ( mLeftButton && mRightButton ) {
|
|
443 |
mLeftButton->resize( height, height );
|
|
444 |
mRightButton->resize( height, height );
|
|
445 |
mRightButton->setPos( QPointF( width - height, 0 ) );
|
|
446 |
}
|
|
447 |
|
|
448 |
scrollToFrequency( mFrequency );
|
|
449 |
}
|
|
450 |
|
|
451 |
/*!
|
|
452 |
* \reimp
|
|
453 |
*/
|
|
454 |
void RadioFrequencyStripBase::changeEvent( QEvent* event )
|
|
455 |
{
|
|
456 |
if ( event->type() == HbEvent::ThemeChanged ) {
|
|
457 |
// Update the foreground color and redraw each item
|
|
458 |
mForegroundColor = Qt::white;// HbColorScheme::color( FrequencyStrip::TEXT_COLOR_ATTRIBUTE );
|
|
459 |
updateAllItems();
|
|
460 |
}
|
|
461 |
|
|
462 |
return RadioStripBase::changeEvent(event);
|
|
463 |
}
|
|
464 |
|
|
465 |
/*!
|
|
466 |
* \reimp
|
|
467 |
*/
|
|
468 |
void RadioFrequencyStripBase::mousePressEvent( QGraphicsSceneMouseEvent* event )
|
|
469 |
{
|
|
470 |
RadioStripBase::mousePressEvent( event );
|
|
471 |
|
|
472 |
mManualSeekTimer->stop();
|
|
473 |
if ( mManualSeekMode ) {
|
|
474 |
const bool insideStrip = rect().contains( event->pos() );
|
|
475 |
if ( !insideStrip ) {
|
|
476 |
toggleManualSeek();
|
|
477 |
}
|
|
478 |
} else {
|
|
479 |
mManualSeekTimer->start( FrequencyStrip::MANUALSEEK_START_TIMEOUT );
|
|
480 |
}
|
|
481 |
}
|
|
482 |
|
|
483 |
/*!
|
|
484 |
* \reimp
|
|
485 |
*/
|
|
486 |
void RadioFrequencyStripBase::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
|
|
487 |
{
|
|
488 |
RadioStripBase::mouseReleaseEvent( event );
|
|
489 |
|
|
490 |
mManualSeekTimer->stop();
|
44
|
491 |
if ( mManualSeekMode ) {
|
39
|
492 |
mManualSeekTimer->start( FrequencyStrip::MANUALSEEK_END_TIMEOUT );
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
/*!
|
|
497 |
* \reimp
|
|
498 |
*/
|
|
499 |
void RadioFrequencyStripBase::gestureEvent( QGestureEvent* event )
|
|
500 |
{
|
54
|
501 |
mIgnoreScrollingEnd = true;
|
39
|
502 |
HbSwipeGesture* swipeGesture = static_cast<HbSwipeGesture*>( event->gesture( Qt::SwipeGesture ) );
|
|
503 |
if ( swipeGesture && !mManualSeekMode ) {
|
|
504 |
if ( swipeGesture->state() == Qt::GestureFinished ) {
|
|
505 |
if ( swipeGesture->horizontalDirection() == QSwipeGesture::Left ) {
|
|
506 |
skipToNext();
|
|
507 |
} else if ( swipeGesture->horizontalDirection() == QSwipeGesture::Right ) {
|
|
508 |
skipToPrevious();
|
|
509 |
}
|
|
510 |
}
|
|
511 |
} else if ( mManualSeekMode ) {
|
|
512 |
RadioStripBase::gestureEvent( event );
|
|
513 |
}
|
|
514 |
}
|
|
515 |
|
|
516 |
/*!
|
|
517 |
* \reimp
|
|
518 |
*/
|
|
519 |
void RadioFrequencyStripBase::timerEvent( QTimerEvent* event )
|
|
520 |
{
|
57
|
521 |
RadioStripBase::timerEvent( event );
|
39
|
522 |
if ( mLastReportedFrequency != mFrequency ) {
|
|
523 |
mLastReportedFrequency = mFrequency;
|
|
524 |
emitFrequencyChanged( mFrequency, FrequencyStrip::ManualSeekTune, Scroll::Shortest );
|
|
525 |
}
|
|
526 |
}
|
|
527 |
|
|
528 |
/*!
|
|
529 |
*
|
|
530 |
*/
|
|
531 |
void RadioFrequencyStripBase::initModel()
|
|
532 |
{
|
|
533 |
const uint minFreq = uint( qreal(mMinFrequency) / FrequencyStrip::ONE_HERTZ + FrequencyStrip::ROUNDER );
|
|
534 |
const uint maxFreq = uint( qreal(mMaxFrequency) / FrequencyStrip::ONE_HERTZ + 0.9 ); // always round up
|
|
535 |
|
|
536 |
QStringList list;
|
|
537 |
for ( uint i = minFreq; i <= maxFreq; ++i ) {
|
54
|
538 |
list.append( QString::number( i ) );
|
|
539 |
mFrequencyItems.append( new RadioFrequencyItem( i ) );
|
39
|
540 |
}
|
54
|
541 |
mFrequencyItems.append( new RadioFrequencyItem( 0 ) );
|
39
|
542 |
list.append( "" );
|
|
543 |
|
|
544 |
mMaxWidth = list.count() * FrequencyStrip::ITEM_WIDTH;
|
|
545 |
|
|
546 |
mSeparatorPos = qreal(FrequencyStrip::ITEM_WIDTH) / 2;
|
57
|
547 |
const uint minDrawableFreq = minFreq * FrequencyStrip::ONE_HERTZ - FrequencyStrip::HALF_HERTZ;
|
39
|
548 |
const uint maxDrawableFreq = maxFreq * FrequencyStrip::ONE_HERTZ + FrequencyStrip::HALF_HERTZ;
|
|
549 |
mSeparatorPos += qreal( ( mMinFrequency - minDrawableFreq ) / 2 ) / FrequencyStrip::PIXEL_IN_HZ;
|
|
550 |
mSeparatorPos -= qreal( ( maxDrawableFreq - mMaxFrequency ) / 2 ) / FrequencyStrip::PIXEL_IN_HZ;
|
|
551 |
|
|
552 |
setModel( new QStringListModel( list, this ) );
|
|
553 |
}
|
|
554 |
|
|
555 |
/*!
|
|
556 |
*
|
|
557 |
*/
|
|
558 |
void RadioFrequencyStripBase::initSelector()
|
|
559 |
{
|
54
|
560 |
QPixmap selectorPixmap = QPixmap( QSize( FrequencyStrip::SELECTOR_WIDTH, (int)size().height() - FrequencyStrip::SELECTOR_MARGIN * 2 ) );
|
39
|
561 |
selectorPixmap.fill( Qt::red );
|
|
562 |
mSelectorImage->setPixmap( selectorPixmap );
|
|
563 |
mSelectorImage->setZValue( FrequencyStrip::SELECTOR_Z_POS );
|
54
|
564 |
mSelectorImage->setPos( 0, FrequencyStrip::SELECTOR_MARGIN );
|
39
|
565 |
}
|
|
566 |
|
|
567 |
/*!
|
|
568 |
*
|
|
569 |
*/
|
|
570 |
void RadioFrequencyStripBase::initPositions()
|
|
571 |
{
|
|
572 |
int prevPos = 0;
|
|
573 |
int nextPos = 0;
|
|
574 |
const int lastPos = mFrequencies.value( mMaxFrequency ).mPosition;
|
|
575 |
for ( int i = mFrequencies.value( mMinFrequency ).mPosition; i < lastPos; ++i ) {
|
|
576 |
if ( mPositions.contains( i ) ) {
|
|
577 |
prevPos = i;
|
|
578 |
const uint freq = mPositions.value( prevPos ) + mFrequencyStepSize;
|
|
579 |
if ( mFrequencies.contains( freq ) ) {
|
|
580 |
nextPos = mFrequencies.value( freq ).mPosition;
|
|
581 |
} else {
|
|
582 |
nextPos = prevPos;
|
|
583 |
}
|
|
584 |
} else {
|
|
585 |
const int nearestHit = ( i - prevPos ) < ( nextPos - i ) ? prevPos : nextPos;
|
|
586 |
mPositions.insert( i, mPositions.value( nearestHit ) );
|
|
587 |
}
|
|
588 |
}
|
|
589 |
}
|
|
590 |
|
|
591 |
/*!
|
|
592 |
*
|
|
593 |
*/
|
|
594 |
void RadioFrequencyStripBase::initButtons()
|
|
595 |
{
|
|
596 |
Q_ASSERT( mLeftButton && mRightButton );
|
|
597 |
connectAndCheck( mLeftButton, SIGNAL(clicked()),
|
|
598 |
this, SLOT(handleLeftButton()) );
|
|
599 |
connectAndCheck( mRightButton, SIGNAL(clicked()),
|
|
600 |
this, SLOT(handleRightButton()) );
|
|
601 |
connectAndCheck( mLeftButton, SIGNAL(longPress(QPointF)),
|
|
602 |
this, SLOT(handleLongLeftButton()) );
|
|
603 |
connectAndCheck( mRightButton, SIGNAL(longPress(QPointF)),
|
|
604 |
this, SLOT(handleLongRightButton()) );
|
|
605 |
|
|
606 |
mLeftButton->setZValue( FrequencyStrip::SELECTOR_Z_POS );
|
|
607 |
mLeftButton->setObjectName( FrequencyStrip::LEFT_BUTTON );
|
|
608 |
mRightButton->setZValue( FrequencyStrip::SELECTOR_Z_POS );
|
|
609 |
mRightButton->setObjectName( FrequencyStrip::RIGHT_BUTTON );
|
|
610 |
|
|
611 |
const qreal height = size().height();
|
|
612 |
const qreal width = size().width();
|
|
613 |
mLeftButton->resize( height, height );
|
|
614 |
mRightButton->resize( height, height );
|
|
615 |
mRightButton->setPos( QPointF( width - height, 0 ) );
|
|
616 |
|
|
617 |
// Add left button effects
|
|
618 |
QStringList pathList;
|
|
619 |
pathList << ":/effects/slide_to_left.fxml" << ":/effects/slide_from_left.fxml";
|
|
620 |
QStringList eventList;
|
|
621 |
eventList << FrequencyStrip::SLIDE_TO_LEFT << FrequencyStrip::SLIDE_FROM_LEFT;
|
|
622 |
HbEffect::add( mLeftButton, pathList, eventList );
|
|
623 |
|
|
624 |
// Add right button effects
|
|
625 |
pathList.clear();
|
|
626 |
pathList << ":/effects/slide_to_right.fxml" << ":/effects/slide_from_right.fxml";
|
|
627 |
eventList.clear();
|
|
628 |
eventList << FrequencyStrip::SLIDE_TO_RIGHT << FrequencyStrip::SLIDE_FROM_RIGHT;
|
|
629 |
HbEffect::add( mRightButton, pathList, eventList );
|
|
630 |
}
|
|
631 |
|
|
632 |
/*!
|
|
633 |
*
|
|
634 |
*/
|
|
635 |
void RadioFrequencyStripBase::addFrequencyPos( int pos, uint frequency, RadioFrequencyItem* item )
|
|
636 |
{
|
|
637 |
mFrequencies.insert( frequency, FrequencyPos( pos, item ) );
|
|
638 |
mPositions.insert( pos, frequency );
|
|
639 |
}
|
|
640 |
|
|
641 |
/*!
|
|
642 |
*
|
|
643 |
*/
|
|
644 |
void RadioFrequencyStripBase::updateStationsInRange( int first, int last, bool stationRemoved )
|
|
645 |
{
|
|
646 |
if ( !isScanning() ) {
|
|
647 |
uint frequency = 0;
|
|
648 |
for ( int i = first; i <= last; ++i ) {
|
|
649 |
frequency = frequencyAtIndex( i );
|
|
650 |
if ( mFrequencies.contains( frequency ) ) {
|
|
651 |
FrequencyPos pos = mFrequencies.value( frequency );
|
|
652 |
updateItem( pos.mItem, 0, stationRemoved ? frequency : 0 );
|
|
653 |
}
|
|
654 |
}
|
|
655 |
}
|
|
656 |
}
|
|
657 |
|
|
658 |
/*!
|
|
659 |
*
|
|
660 |
*/
|
|
661 |
void RadioFrequencyStripBase::updateItem( RadioFrequencyItem* item, uint upperRange, uint ignoredFrequency )
|
|
662 |
{
|
|
663 |
if ( item ) {
|
|
664 |
uint frequency = item->frequency();
|
|
665 |
QList<FrequencyStrip::StationMarker> markers;
|
|
666 |
|
|
667 |
if ( upperRange == 0 ) {
|
|
668 |
upperRange = frequency + FrequencyStrip::HALF_HERTZ;
|
|
669 |
}
|
|
670 |
|
|
671 |
if ( isInitialized() ) {
|
|
672 |
markers = stationsInRange( frequency - FrequencyStrip::HALF_HERTZ, upperRange );
|
|
673 |
for ( int i = markers.count() - 1; ignoredFrequency > 0 && i >= 0; --i ) {
|
|
674 |
if ( markers[i].mFrequency == ignoredFrequency ) {
|
|
675 |
markers.removeAt( i );
|
|
676 |
break;
|
|
677 |
}
|
|
678 |
}
|
|
679 |
}
|
|
680 |
|
|
681 |
QPixmap pixmap = drawPixmap( frequency, markers, item );
|
|
682 |
item->setPixmap( pixmap );
|
|
683 |
|
|
684 |
foreach ( const FrequencyStrip::StationMarker& marker, markers ) {
|
|
685 |
FrequencyPos pos = mFrequencies.value( marker.mFrequency );
|
|
686 |
mFrequencies.insert( marker.mFrequency, pos );
|
|
687 |
}
|
|
688 |
}
|
|
689 |
}
|
|
690 |
|
|
691 |
/*!
|
|
692 |
*
|
|
693 |
*/
|
|
694 |
void RadioFrequencyStripBase::updateAllItems()
|
|
695 |
{
|
|
696 |
foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
|
|
697 |
updateItem( item );
|
|
698 |
}
|
|
699 |
}
|
|
700 |
|
|
701 |
/*!
|
|
702 |
*
|
|
703 |
*/
|
54
|
704 |
QPixmap RadioFrequencyStripBase::drawPixmap( uint mainFrequency, QList<FrequencyStrip::StationMarker> stations, RadioFrequencyItem* item )
|
39
|
705 |
{
|
|
706 |
QPixmap pixmap( FrequencyStrip::PIXMAP_WIDTH, mItemHeight );
|
|
707 |
pixmap.fill( Qt::transparent );
|
54
|
708 |
|
|
709 |
if ( mainFrequency == 0 ) {
|
|
710 |
return pixmap;
|
|
711 |
}
|
|
712 |
|
39
|
713 |
QPainter painter( &pixmap );
|
|
714 |
QPen normalPen = painter.pen();
|
57
|
715 |
normalPen.setColor(mForegroundColor);
|
|
716 |
painter.setPen(normalPen);
|
39
|
717 |
|
54
|
718 |
const uint frequencyIncrement = qMin( mFrequencyStepSize, FrequencyStrip::ONE_HUNDRED_KHZ );
|
|
719 |
const QString itemText = QString::number( mainFrequency / FrequencyStrip::ONE_HERTZ );
|
|
720 |
const uint startFrequency = mainFrequency - FrequencyStrip::HALF_HERTZ + frequencyIncrement;
|
|
721 |
const uint endFrequency = mainFrequency + FrequencyStrip::HALF_HERTZ;
|
39
|
722 |
const uint roundedMin = int( qreal(mMinFrequency) / FrequencyStrip::ONE_HERTZ + FrequencyStrip::ROUNDER );
|
54
|
723 |
const uint freq = mainFrequency / FrequencyStrip::ONE_HERTZ;
|
39
|
724 |
const int diff = freq - roundedMin;
|
|
725 |
const qreal startPixel = diff * FrequencyStrip::ITEM_WIDTH;
|
|
726 |
qreal pixels = 0.0;
|
|
727 |
const qreal leftOverlap = FrequencyStrip::PIXMAP_OVERLAP / 2;
|
|
728 |
|
54
|
729 |
for ( uint loopFrequency = startFrequency; loopFrequency <= endFrequency; loopFrequency += frequencyIncrement ) {
|
39
|
730 |
|
54
|
731 |
pixels = qreal( loopFrequency - startFrequency ) / FrequencyStrip::PIXEL_IN_HZ;
|
|
732 |
if ( loopFrequency % FrequencyStrip::ONE_HERTZ == 0 ) {
|
39
|
733 |
|
|
734 |
// Draw the high frequency tab and the frequency text for the even number
|
|
735 |
normalPen.setWidth( 3 );
|
|
736 |
painter.setPen( normalPen );
|
|
737 |
painter.drawLine( makeTab( pixels + leftOverlap - 1, FrequencyStrip::TAB_HEIGHT_BIG ) );
|
|
738 |
normalPen.setWidth( 1 );
|
|
739 |
painter.setPen( normalPen );
|
|
740 |
|
54
|
741 |
// Draw the frequency text and its decimals
|
39
|
742 |
painter.setFont( FrequencyStrip::DECIMAL_FONT );
|
|
743 |
const int decimalWidth = painter.fontMetrics().width( FrequencyStrip::DECIMAL_TEXT );
|
|
744 |
const int decimalSpace = painter.fontMetrics().leftBearing( '.' );
|
|
745 |
painter.setFont( FrequencyStrip::FREQUENCY_FONT );
|
|
746 |
const int frequencyWidth = painter.fontMetrics().width( itemText );
|
|
747 |
const int textPosX = int( pixels + leftOverlap - ( frequencyWidth + decimalSpace + decimalWidth ) / 2 );
|
|
748 |
painter.drawText( QPoint( textPosX, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), itemText );
|
|
749 |
painter.setFont( FrequencyStrip::DECIMAL_FONT );
|
|
750 |
painter.drawText( QPoint( textPosX + frequencyWidth + decimalSpace, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), FrequencyStrip::DECIMAL_TEXT );
|
|
751 |
|
54
|
752 |
} else if ( loopFrequency % FrequencyStrip::ONE_TAB_IN_HZ == 0 ) {
|
39
|
753 |
|
|
754 |
// Draw the low frequency tab for the uneven number
|
|
755 |
painter.drawLine( makeTab( pixels + leftOverlap, FrequencyStrip::TAB_HEIGHT_SMALL ) );
|
|
756 |
|
|
757 |
}
|
|
758 |
|
54
|
759 |
if ( ( loopFrequency - mMinFrequency ) % mFrequencyStepSize == 0 && loopFrequency >= mMinFrequency && loopFrequency <= mMaxFrequency ) {
|
|
760 |
addFrequencyPos( int( startPixel + pixels + FrequencyStrip::ROUNDER ), loopFrequency, item );
|
|
761 |
}
|
39
|
762 |
}
|
|
763 |
|
54
|
764 |
const int markerYPos = mItemHeight - 18;
|
57
|
765 |
const int markerHalf = FrequencyStrip::STATION_MARKER_SIZE / 2;
|
39
|
766 |
foreach ( const FrequencyStrip::StationMarker& station, stations ) {
|
|
767 |
const uint frequency = station.mFrequency;
|
57
|
768 |
pixels = qreal(frequency - startFrequency) / FrequencyStrip::PIXEL_IN_HZ;
|
39
|
769 |
|
57
|
770 |
const QPoint point( int(pixels + leftOverlap - markerHalf ), markerYPos - markerHalf );
|
39
|
771 |
if ( station.mIsFavorite ) {
|
57
|
772 |
painter.drawPixmap( point, mFavoriteIcon.pixmap() );
|
39
|
773 |
} else {
|
57
|
774 |
painter.drawPixmap( point, mStationIcon.pixmap() );
|
39
|
775 |
}
|
|
776 |
}
|
|
777 |
|
|
778 |
return pixmap;
|
|
779 |
}
|
|
780 |
|
|
781 |
/*!
|
|
782 |
*
|
|
783 |
*/
|
|
784 |
QLineF RadioFrequencyStripBase::makeTab( qreal pos, int height )
|
|
785 |
{
|
|
786 |
return QLineF( pos, mItemHeight - height, pos, mItemHeight );
|
|
787 |
}
|
|
788 |
|
|
789 |
/*!
|
|
790 |
*
|
|
791 |
*/
|
|
792 |
int RadioFrequencyStripBase::selectorPos() const
|
|
793 |
{
|
|
794 |
const int pos = int( -contentWidget()->x() + mSelectorPos + FrequencyStrip::ROUNDER );
|
|
795 |
return pos % mMaxWidth;
|
|
796 |
}
|
|
797 |
|
|
798 |
/*!
|
|
799 |
*
|
|
800 |
*/
|
|
801 |
void RadioFrequencyStripBase::scrollToFrequency( uint frequency, Scroll::Direction direction, int time )
|
|
802 |
{
|
47
|
803 |
Q_UNUSED( time );
|
|
804 |
|
39
|
805 |
int targetFreqPos = mFrequencies.value( frequency ).mPosition;
|
|
806 |
const int currentFreqPos = mFrequencies.value( mFrequency ).mPosition;
|
|
807 |
const int currentPos = int( -contentWidget()->x() + mSelectorPos + FrequencyStrip::ROUNDER );
|
|
808 |
const bool isInSecondHalf = currentPos >= mMaxWidth - FrequencyStrip::ITEM_WIDTH + mSeparatorPos;
|
|
809 |
|
|
810 |
// Special case: When there is only one favorite and the user presses skip
|
|
811 |
// the strip must scroll around to the same frequency.
|
|
812 |
if ( mFrequency == frequency && direction != Scroll::Shortest ) {
|
|
813 |
if ( direction == Scroll::Left ) {
|
|
814 |
targetFreqPos += mMaxWidth;
|
|
815 |
} else {
|
|
816 |
targetFreqPos -= mMaxWidth;
|
|
817 |
}
|
|
818 |
}
|
|
819 |
|
|
820 |
mFrequency = frequency;
|
|
821 |
|
|
822 |
qreal newPos = targetFreqPos;
|
|
823 |
if ( direction == Scroll::Left ) {
|
|
824 |
|
|
825 |
if ( currentFreqPos > targetFreqPos ) {
|
|
826 |
newPos += mMaxWidth;
|
|
827 |
}
|
|
828 |
|
|
829 |
} else if ( direction == Scroll::Right ) {
|
|
830 |
|
|
831 |
if ( currentFreqPos < targetFreqPos ) {
|
|
832 |
newPos -= mMaxWidth;
|
|
833 |
}
|
|
834 |
|
|
835 |
}
|
|
836 |
|
|
837 |
if ( isInSecondHalf ) {
|
|
838 |
newPos += mMaxWidth;
|
|
839 |
}
|
|
840 |
|
|
841 |
newPos -= mSelectorPos - FrequencyStrip::ROUNDER;
|
|
842 |
|
57
|
843 |
scrollContentsTo( QPointF( newPos, 0 ), time );
|
39
|
844 |
}
|
|
845 |
|
|
846 |
/*!
|
|
847 |
*
|
|
848 |
*/
|
|
849 |
void RadioFrequencyStripBase::hideButtons()
|
|
850 |
{
|
|
851 |
HbEffect::start( mLeftButton, FrequencyStrip::SLIDE_TO_LEFT );
|
|
852 |
HbEffect::start( mRightButton, FrequencyStrip::SLIDE_TO_RIGHT );
|
|
853 |
}
|
|
854 |
|
|
855 |
/*!
|
|
856 |
*
|
|
857 |
*/
|
|
858 |
void RadioFrequencyStripBase::showButtons()
|
|
859 |
{
|
|
860 |
HbEffect::start( mLeftButton, FrequencyStrip::SLIDE_FROM_LEFT );
|
|
861 |
HbEffect::start( mRightButton, FrequencyStrip::SLIDE_FROM_RIGHT );
|
|
862 |
}
|