radioapp/radiowidgets/src/radiostripbase.cpp
author William Roberts <williamr@symbian.org>
Thu, 22 Jul 2010 16:33:45 +0100
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 32 189d20c34778
permissions -rw-r--r--
Catchup to latest Symbian^4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*/
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
// System includes
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
#include <QGraphicsSceneEvent>
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
// User includes
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
#include "radiostripbase.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#include "radiologger.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
// Constants
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
RadioStripBase::RadioStripBase( QGraphicsItem* parent ) :
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
    HbScrollArea( parent ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
    mAutoScrollTime( 0 ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
    mStripContainer( new HbWidget( this ) ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
    mModel( 0 ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
    mIsCyclic( true ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
    mAutoCenter( false ),
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    37
    mOverlap( 0 ),
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
    mItemPoolParent( new QGraphicsWidget( NULL ) ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
    mCurrentIndex( 0 ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
    mPressedIndex( 0 ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
    mStripLength( 0 ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
    mContentsLength( 0 )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
    setClampingStyle( HbScrollArea::NoClamping );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
    setScrollDirections( Qt::Horizontal );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
    setFlag( QGraphicsItem::ItemClipsChildrenToShape, true );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
    setContentWidget( mStripContainer );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
    setFrictionEnabled( true );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
    setLongPressEnabled( false );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
    setHorizontalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOff );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
    setVerticalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOff );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
    // mItemParent is used to hold the unused QGraphicsItem's in the pool.  It's visibility is set to false
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
    // so the visibility of the items doesn't need to be modified.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
    mItemPoolParent->setVisible( false );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
RadioStripBase::~RadioStripBase()
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
void RadioStripBase::setAutoScrollTime( const int time )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
    mAutoScrollTime = time;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
int RadioStripBase::autoScrollTime() const
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
    return mAutoScrollTime;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
void RadioStripBase::setModel( QAbstractItemModel* model )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
    if ( mModel != model )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
    //    if ( mModel )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
    //    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
    //        disconnectDataModel();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
    //    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
        mModel = model;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
        if ( mModel )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
    //        connectDataModel();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
            mCurrentIndex = 0;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
            populateAndLayout();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
QAbstractItemModel* RadioStripBase::model() const
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
    return mModel;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   116
void RadioStripBase::setCyclic( bool isCyclic )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   117
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118
    mIsCyclic = isCyclic;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   119
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   120
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   123
 */
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   124
void RadioStripBase::setOverlap( qreal overlap )
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   125
{
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   126
    mOverlap = overlap;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   127
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   128
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   129
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   130
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   131
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   132
void RadioStripBase::setAutoCenter( bool autoCenter )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
    mAutoCenter = autoCenter;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   135
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   136
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   137
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   138
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   139
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   140
void RadioStripBase::setItemSize( const QSizeF& size )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   141
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   142
    if ( mItemSize != size ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   143
        mItemSize = size;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   144
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   145
        prepareGeometryChange();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   146
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   147
        populateAndLayout();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   148
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   149
        update();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   150
        updateGeometry();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   151
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   152
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   153
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   154
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   155
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   156
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   157
void RadioStripBase::setIndex( int index, bool animateToCenter )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   158
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   159
    Q_UNUSED( animateToCenter )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   160
    // Sanity checks
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   161
    if ( !mModel || ( !mIsCyclic && ( index < 0 || index >= mModel->rowCount() ) ) ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   162
        return;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   163
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   164
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   165
    const int oldIndex = mCurrentIndex;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   166
    if ( mIsCyclic )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   167
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   168
        int numRows = mModel->rowCount();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   169
        index = (index + numRows) % numRows;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   170
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   171
    Q_ASSERT( index >= 0 );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   172
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   173
    mCurrentIndex = index;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   174
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   175
    updateItemWithIndex( mCurrentIndex );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   176
    updateItemWithIndex( oldIndex );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   177
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   178
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   179
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   180
 * \reimp
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   181
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   182
void RadioStripBase::resizeEvent( QGraphicsSceneResizeEvent* event )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   183
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   184
    Q_UNUSED( event );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   185
    populateAndLayout();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   186
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   187
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   188
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   189
 * \reimp
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   190
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   191
void RadioStripBase::mousePressEvent( QGraphicsSceneMouseEvent* event )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   192
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   193
    if ( event->button() != Qt::LeftButton || !mModel || !mModel->rowCount() )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   194
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   195
        event->ignore();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   196
        return;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   197
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   198
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   199
    HbScrollArea::mousePressEvent( event );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   200
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   201
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   202
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   203
 * \reimp
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   204
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   205
void RadioStripBase::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   206
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   207
    if ( event->button() != Qt::LeftButton )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   208
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   209
        event->ignore();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   210
        return;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   211
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   212
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   213
    HbScrollArea::mouseReleaseEvent( event );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   214
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   215
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   216
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   217
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   218
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   219
void RadioStripBase::moveAllItemsToPool()
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   220
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   221
    // set parent of all items to pool
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   222
    foreach( QGraphicsItem* item, mItemAtSlot )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   223
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   224
        item->setParentItem( mItemPoolParent );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   225
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   226
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   227
    // move all items to pool
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   228
    mItemPool += mItemAtSlot;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   229
    mItemAtSlot.clear();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   230
    mIndexAtSlot.clear();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   231
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   232
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   233
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   234
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   235
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   236
void RadioStripBase::populateAndLayout()
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   237
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   238
    moveAllItemsToPool();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   239
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   240
    if ( !mModel || mModel->rowCount() == 0 )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   241
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   242
        return;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   243
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   244
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   245
    mStripLength = boundingRect().width();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   246
    qreal itemSize = mItemSize.width();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   247
    mContentsLength = mModel->rowCount() * (itemSize - mOverlap);
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   248
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   249
    if ( mIsCyclic )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   250
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   251
        // if treating the items cyclically, double the content area so it can
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   252
        // be shifted back and forth as you scroll
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   253
        mContentsLength *= 2;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   254
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   255
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   256
    qreal currPos = -mOverlap;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   257
    for ( int i = 0; i < mModel->rowCount(); ++i ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   258
        if ( currPos > mStripLength )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   259
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   260
            break;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   261
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   262
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   263
        QGraphicsItem* item = constructItem( i, true );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   264
        if ( item )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   265
        {
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   266
            item->setPos( QPointF( currPos, 0 ) );
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   267
            currPos += itemSize - mOverlap;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   268
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   269
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   270
32
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   271
    mStripContainer->setPreferredSize( mContentsLength, mItemSize.height() );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   272
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   273
    if ( mCurrentIndex >= 0 )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   274
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   275
        setIndex( mCurrentIndex, false );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   276
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   277
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   278
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   279
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   280
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   281
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   282
QGraphicsItem* RadioStripBase::constructItem( int index, bool append )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   283
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   284
    QGraphicsItem* item = getFromPool();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   285
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   286
    if ( mIsCyclic )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   287
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   288
        Q_ASSERT( index >= 0 && index < 2 * mModel->rowCount() );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   289
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   290
        updateItemPrimitive( item, index % mModel->rowCount() );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   291
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   292
    else
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   293
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   294
        Q_ASSERT( index >= 0 && index < mModel->rowCount() );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   295
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   296
        updateItemPrimitive( item, index );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   297
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   298
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   299
    item->setParentItem( mStripContainer );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   300
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   301
    if ( append )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   302
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   303
        mItemAtSlot.append( item );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   304
        mIndexAtSlot.append( index );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   305
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   306
    else
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   307
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   308
        mItemAtSlot.prepend( item );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   309
        mIndexAtSlot.prepend( index );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   310
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   311
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   312
    return item;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   313
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   314
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   315
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   316
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   317
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   318
QGraphicsItem* RadioStripBase::getFromPool()
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   319
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   320
    QGraphicsItem* item = 0;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   321
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   322
    if ( mItemPool.isEmpty() )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   323
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   324
        item = createItemPrimitive( this );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   325
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   326
    else
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   327
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   328
        item = mItemPool.takeFirst();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   329
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   330
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   331
    return item;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   332
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   333
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   334
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   335
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   336
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   337
void RadioStripBase::returnToPool( QGraphicsItem* item )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   338
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   339
    // Unparent the item so it doesn't get deleted
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   340
    item->setParentItem( mItemPoolParent );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   341
    mItemPool.append( item );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   342
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   343
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   344
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   345
 * Returns starting coordinate of the item with the specified index
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   346
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   347
qreal RadioStripBase::indexToOffset( int index )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   348
{
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   349
    return index * ( mItemSize.width() - mOverlap ) - mOverlap;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   350
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   351
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   352
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   353
 * Returns item index for specified offset amount into the content
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   354
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   355
int RadioStripBase::offsetToIndex( qreal offset )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   356
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   357
    const int rows = mModel->rowCount();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   358
    int index = (int)( offset / ( mItemSize.width() - mOverlap ) );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   359
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   360
    if ( mIsCyclic )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   361
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   362
       return qBound( 0, index, 2 * rows - 1 );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   363
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   364
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   365
    return qBound( 0, index, rows - 1 );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   366
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   367
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   368
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   369
 * updates items with specified index value
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   370
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   371
void RadioStripBase::updateItemWithIndex( int index )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   372
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   373
    if( index >= 0 )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   374
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   375
        QList<QGraphicsItem *>::const_iterator item = mItemAtSlot.constBegin();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   376
        QList<QGraphicsItem *>::const_iterator itemsEnd = mItemAtSlot.constEnd();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   377
        QList<int>::const_iterator itemIndex = mIndexAtSlot.constBegin();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   378
        const int rowCount = mModel->rowCount();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   379
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   380
        // Find all items with this index (can be 2 in special cycling case)
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   381
        for( ; item != itemsEnd; ++item, ++itemIndex )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   382
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   383
            if( index == *itemIndex || index == *itemIndex - rowCount )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   384
            {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   385
                // update those items
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   386
                updateItemPrimitive( *item, index );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   387
            }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   388
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   389
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   390
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   391
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   392
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   393
 * Updates items during scrolling: removing invisible items and adding items that became visible
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   394
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   395
void RadioStripBase::adjustItems()
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   396
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   397
    qreal contentPos = mStripContainer->pos().x();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   398
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   399
    if ( mIsCyclic )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   400
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   401
        if ( -contentPos < 0 )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   402
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   403
            // trying  to display off the left end of the strip, so
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   404
            // shift the strip one length to the left
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   405
            contentPos -= mContentsLength * 0.5;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   406
            mStripContainer->setPos( QPointF ( contentPos, mStripContainer->pos().y() ) );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   407
        } else if (-contentPos > mContentsLength * 0.5) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   408
            // trying to display off the right end of the strip, so
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   409
            // shift the strip one length to the right
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   410
            contentPos += mContentsLength * 0.5;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   411
            mStripContainer->setPos( QPointF ( contentPos, mStripContainer->pos().y() ) );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   412
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   413
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   414
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   415
    // find the first and last indices of the visible items
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   416
    int firstVisibleIndex = offsetToIndex( -contentPos );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   417
    int lastVisibleIndex = offsetToIndex( -contentPos + mStripLength );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   418
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   419
    // remove items at the start that are no longer visible
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   420
    while ( !mIndexAtSlot.isEmpty() )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   421
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   422
        int firstSlotIndex = mIndexAtSlot.first();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   423
        if ( firstVisibleIndex <= firstSlotIndex )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   424
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   425
            break;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   426
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   427
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   428
        returnToPool( mItemAtSlot.first() );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   429
        mItemAtSlot.removeFirst();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   430
        mIndexAtSlot.removeFirst();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   431
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   432
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   433
    // remove items at the end that are no longer visible
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   434
    while ( !mIndexAtSlot.isEmpty() )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   435
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   436
        int lastSlotIndex = mIndexAtSlot.last();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   437
        if ( lastVisibleIndex >= lastSlotIndex )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   438
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   439
            break;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   440
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   441
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   442
        returnToPool( mItemAtSlot.last() );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   443
        mItemAtSlot.removeLast();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   444
        mIndexAtSlot.removeLast();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   445
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   446
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   447
    if ( mItemAtSlot.isEmpty() )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   448
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   449
        // fill area with all needed items
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   450
        for ( int i = firstVisibleIndex; i <= lastVisibleIndex; ++i )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   451
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   452
            QGraphicsItem* item = constructItem( i, true );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   453
            if ( item )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   454
            {
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   455
                item->setPos( QPointF( indexToOffset( i ), 0 ) );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   456
            }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   457
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   458
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   459
    else
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   460
    {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   461
        // add missing items at the front
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   462
        int firstItemToCreate = mIndexAtSlot.first()-1;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   463
        for ( int i = firstItemToCreate; i >= firstVisibleIndex; --i )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   464
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   465
            QGraphicsItem* item = constructItem( i, false );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   466
            if ( item )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   467
            {
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   468
                item->setPos( QPointF( indexToOffset( i ), 0 ) );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   469
            }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   470
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   471
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   472
        // add missing items at the end
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   473
        firstItemToCreate = mIndexAtSlot.last()+1;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   474
        for ( int i = firstItemToCreate; i <= lastVisibleIndex; ++i )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   475
        {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   476
            QGraphicsItem* item = constructItem( i, true );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   477
            if ( item )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   478
            {
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   479
                item->setPos( QPointF( indexToOffset( i ), 0 ) );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   480
            }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   481
        }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   482
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   483
}
32
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   484
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   485
/*!
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   486
 * \reimp
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   487
 */
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   488
bool RadioStripBase::scrollByAmount( const QPointF& delta )
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   489
{
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   490
    bool ret = HbScrollArea::scrollByAmount( delta );
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   491
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   492
    adjustItems();
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   493
    scrollPosChanged();
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   494
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   495
    return ret;
189d20c34778 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 28
diff changeset
   496
}