ganeswidgets/src/hgwidgets.cpp
changeset 0 89c329efa980
child 1 e48454f237ca
equal deleted inserted replaced
-1:000000000000 0:89c329efa980
       
     1 /*
       
     2 * Copyright (c) 2010 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 #include <QGraphicsSceneResizeEvent>
       
    19 #include <hbmainwindow>
       
    20 #include <hbscrollbar.h>
       
    21 #include <qapplication.h>
       
    22 #include <hgwidgets/hgwidgets.h>
       
    23 #include <hbstyleloader.h>
       
    24 
       
    25 #include "hgwidgets_p.h"
       
    26 #include "hgcontainer.h"
       
    27 #include "hgwidgetitem.h"
       
    28 #include "hgscrollbuffermanager.h"
       
    29 #include "hgcoverflowcontainer.h"
       
    30 #include "hggridcontainer.h"
       
    31 #include "trace.h"
       
    32 
       
    33 HgWidget::HgWidget(HbWidgetPrivate* widgetPrivate, QGraphicsItem *parent ):
       
    34     HbWidget(*widgetPrivate, parent)
       
    35 {
       
    36     Q_D(HgWidget);
       
    37     d->q_ptr = this;
       
    38 
       
    39     HbStyleLoader::registerFilePath(":/hgwidget.css");
       
    40     HbStyleLoader::registerFilePath(":/hgwidget.widgetml");    
       
    41 }
       
    42 
       
    43 HgWidget::~HgWidget()
       
    44 {
       
    45     HbStyleLoader::unregisterFilePath(":/hgwidget.css");
       
    46     HbStyleLoader::unregisterFilePath(":/hgwidget.widgetml");
       
    47 }
       
    48 
       
    49 /*!
       
    50     Returns model that view is currently presenting.
       
    51 */
       
    52 QAbstractItemModel *HgWidget::model() const
       
    53 {
       
    54     Q_D(const HgWidget);
       
    55     return d->mModel;
       
    56 }
       
    57 
       
    58 /*!
       
    59     Sets the model to \a model and replaces current item prototype with \a prototype.
       
    60     Ownership of the model is not taken. Ownership of the prototype is taken.
       
    61     If no prototype has been passed, default prototype is used.
       
    62  */
       
    63 void HgWidget::setModel(QAbstractItemModel *model )
       
    64 {
       
    65     Q_D(HgWidget);
       
    66     d->setModel(model);
       
    67 }
       
    68 
       
    69 void HgWidget::setSelectionModel(QItemSelectionModel *selectionModel)
       
    70 {
       
    71     Q_D(HgWidget);
       
    72     d->setSelectionModel(selectionModel);
       
    73 }
       
    74 
       
    75 QItemSelectionModel *HgWidget::selectionModel() const
       
    76 {
       
    77     Q_D(const HgWidget);
       
    78     return d->selectionModel();
       
    79 }
       
    80 
       
    81 HgWidget::SelectionMode HgWidget::selectionMode() const
       
    82 {
       
    83     Q_D(const HgWidget);
       
    84     return d->selectionMode();
       
    85 }
       
    86 
       
    87 /*!
       
    88     If newMode is not same as current selection mode of view, updates
       
    89     selection mode and all viewitems. If resetSelection is true (the default),
       
    90     it clears all existing selections.
       
    91 */
       
    92 void HgWidget::setSelectionMode(SelectionMode mode, bool resetSelection)
       
    93 {
       
    94     Q_D(HgWidget);
       
    95     d->setSelectionMode(mode, resetSelection);
       
    96 }
       
    97 
       
    98 void HgWidget::selectAll()
       
    99 {
       
   100     Q_D(HgWidget);
       
   101     d->selectAll();
       
   102 }
       
   103 
       
   104 void HgWidget::clearSelection()
       
   105 {
       
   106     Q_D(HgWidget);
       
   107     d->clearSelection();
       
   108 }
       
   109 
       
   110 QModelIndex HgWidget::currentIndex() const
       
   111 {
       
   112     Q_D(const HgWidget);
       
   113     return d->currentIndex();
       
   114 }
       
   115 
       
   116 void HgWidget::setCurrentIndex(
       
   117     const QModelIndex &index, QItemSelectionModel::SelectionFlags selectionFlag)
       
   118 {
       
   119     Q_D(HgWidget);
       
   120     d->setCurrentIndex(index, selectionFlag);
       
   121 }
       
   122 
       
   123 void HgWidget::scrollTo(const QModelIndex &index)
       
   124 {
       
   125     Q_D(HgWidget);
       
   126     d->scrollTo(index);
       
   127 }
       
   128 
       
   129 void HgWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
       
   130 {
       
   131     Q_D( HgWidget);
       
   132     // TODO,take columns into count
       
   133     for( int i = topLeft.row(); i <= bottomRight.row(); i++ ){
       
   134         // if data for item outside our current buffer has changed
       
   135         // we just have to ignore it since we dont have resources
       
   136         // to handle it(or we dont want to waste resources).
       
   137         if(d->mBufferManager->positionInsideBuffer(i)){
       
   138             HgWidgetItem* item = d->mContainer->itemByIndex( i );
       
   139             if( item ){
       
   140                 item->updateItemData();
       
   141             }
       
   142         }
       
   143     }
       
   144     d->mContainer->itemDataChanged( topLeft, bottomRight );
       
   145 }
       
   146 
       
   147 /*!
       
   148  * Returns true if the scroll area handles
       
   149  * long press gestures, false otherwise
       
   150  *
       
   151  * \sa HbScrollArea::setHandleLongPress()
       
   152  */
       
   153 bool HgWidget::longPressEnabled() const
       
   154 {
       
   155     Q_D( const HgWidget );
       
   156 
       
   157     return d->mHandleLongPress;
       
   158 }
       
   159 
       
   160 /*!
       
   161  * Sets the value of the handleLongPress property.  This value is set
       
   162  * to true if the widget is to respond to long press gestures, false otherwise.
       
   163  *
       
   164  * The default value is false.
       
   165  *
       
   166  * \sa HbScrollArea::handleLongPress()
       
   167  */
       
   168 void HgWidget::setLongPressEnabled (bool value)
       
   169 {
       
   170     Q_D( HgWidget );
       
   171 
       
   172     if (d->mHandleLongPress != value)
       
   173     {
       
   174         d->mHandleLongPress = value;
       
   175         if (value)
       
   176         {
       
   177             grabGesture(Qt::TapAndHoldGesture);
       
   178         }
       
   179         else
       
   180         {
       
   181             ungrabGesture(Qt::TapAndHoldGesture);
       
   182         }
       
   183     }
       
   184 
       
   185     // TODO, should we do something like this?????
       
   186 //    if (isChanged) {
       
   187 //        d->updateGestures();
       
   188 //        emit gestureSceneFilterChanged( d->mGestureFilter );
       
   189 //    }
       
   190 }
       
   191 
       
   192 HgWidget::ScrollBarPolicy HgWidget::scrollBarPolicy() const
       
   193 {
       
   194     Q_D(const HgWidget);
       
   195     return d->mScrollBarPolicy;
       
   196 }
       
   197 
       
   198 /*!
       
   199     Sets the policy for vertical scrollbar
       
   200 
       
   201     The default policy is HgWidget::ScrollBarAutoHide.
       
   202 
       
   203     \sa setHorizontalScrollBarPolicy(), verticalScrollBarPolicy()
       
   204 */
       
   205 void HgWidget::setScrollBarPolicy(ScrollBarPolicy policy)
       
   206 {
       
   207     Q_D(HgWidget);
       
   208     d->setScrollBarPolicy(policy);
       
   209 }
       
   210 
       
   211 /*!
       
   212   Returns the vertical scroll bar.
       
   213 
       
   214   \sa verticalScrollBarPolicy(), horizontalScrollBar()
       
   215  */
       
   216 HbScrollBar *HgWidget::scrollBar() const
       
   217 {
       
   218     Q_D(const HgWidget);
       
   219     return d->mScrollBar;
       
   220 }
       
   221 
       
   222 /*!
       
   223    Replaces the existing vertical scroll bar with \a scrollBar. The former
       
   224    scroll bar is deleted.
       
   225 
       
   226    HgWidget already provides vertical and horizontal scroll bars by
       
   227    default. You can call this function to replace the default vertical
       
   228    scroll bar with your own custom scroll bar.
       
   229 
       
   230    \sa verticalScrollBar(), setHorizontalScrollBar()
       
   231 */
       
   232 void HgWidget::setScrollBar(HbScrollBar *scrollBar)
       
   233 {
       
   234     Q_D(HgWidget);
       
   235     if (!scrollBar) {
       
   236         qWarning("HgWidget::setVerticalScrollBar: Cannot set a null scroll bar");
       
   237         return;
       
   238     }
       
   239 
       
   240     d->replaceScrollBar(scrollBar);
       
   241 }
       
   242 
       
   243 bool HgWidget::eventFilter(QObject *obj,QEvent *event)
       
   244 {
       
   245     Q_D(HgWidget);
       
   246     switch (event->type() )
       
   247         {
       
   248         case QEvent::ApplicationActivate:
       
   249             {
       
   250             d->gainedForeground();
       
   251             break;
       
   252             }
       
   253         case QEvent::ApplicationDeactivate:
       
   254             {
       
   255             d->lostForeground();
       
   256             break;
       
   257             }
       
   258         case QEvent::GraphicsSceneResize:
       
   259             {
       
   260             d->adjustGeometry();
       
   261             break;
       
   262             }
       
   263         default:
       
   264             break;
       
   265         }
       
   266     return QObject::eventFilter(obj, event);
       
   267 }
       
   268 
       
   269 bool HgWidget::event(QEvent *event)
       
   270 {
       
   271     Q_D(HgWidget);
       
   272 
       
   273     bool value(false);
       
   274     if (event){
       
   275         value = HbWidget::event(event);
       
   276         if (event->type() == QEvent::GraphicsSceneResize){
       
   277             d->adjustGeometry();
       
   278         }
       
   279     }
       
   280     return value;
       
   281 }
       
   282 
       
   283 bool HgWidget::getItemOutline(const QModelIndex& index, QPolygonF& points)
       
   284 {
       
   285     Q_D(HgWidget);
       
   286 
       
   287     return d->getItemOutline(index, points);
       
   288 }
       
   289 
       
   290 void HgWidget::aboutToChangeOrientation()
       
   291 {
       
   292 
       
   293 }
       
   294 
       
   295 void HgWidget::orientationChanged(Qt::Orientation orientation)
       
   296 {
       
   297     Q_D(HgWidget);
       
   298     d->orientationChanged(orientation);
       
   299 }
       
   300 
       
   301 Qt::Orientation HgWidget::scrollDirection() const
       
   302 {
       
   303     Q_D(const HgWidget);
       
   304     return d->scrollDirection();
       
   305 }
       
   306 
       
   307 QList<QModelIndex> HgWidget::getVisibleItemIndices() const
       
   308 {
       
   309     Q_D(const HgWidget);
       
   310     return d->getVisibleItemIndices();
       
   311 }
       
   312 
       
   313 void HgWidget::setIndexFeedbackPolicy(IndexFeedbackPolicy policy)
       
   314 {
       
   315     Q_D(HgWidget);
       
   316     d->setIndexFeedbackPolicy(policy);
       
   317 }
       
   318 
       
   319 HgWidget::IndexFeedbackPolicy HgWidget::indexFeedbackPolicy() const
       
   320 {
       
   321     Q_D(const HgWidget);
       
   322     return d->indexFeedbackPolicy();
       
   323 }
       
   324 
       
   325 // EOF