calendarui/views/dayview/src/calendayitemview.cpp
changeset 58 ef813d54df51
parent 50 579cc610882e
child 68 a5a1242fd2e8
equal deleted inserted replaced
50:579cc610882e 58:ef813d54df51
    28 #include "calendaycontainer.h"
    28 #include "calendaycontainer.h"
    29 #include "calendayinfo.h"
    29 #include "calendayinfo.h"
    30 #include "calendaymodel.h"
    30 #include "calendaymodel.h"
    31 #include "calenservices.h"
    31 #include "calenservices.h"
    32 #include "calencontext.h"
    32 #include "calencontext.h"
       
    33 #include "calenagendautils.h"
    33 #include "CalenUid.h"
    34 #include "CalenUid.h"
    34 
    35 
    35 
    36 
    36 // -----------------------------------------------------------------------------
    37 /*!
    37 // CalenDayItemView()
    38    \brief Constructor
    38 // Constructor
    39 */
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CalenDayItemView::CalenDayItemView( MCalenServices &services, HbModelIterator *iterator, QGraphicsItem *parent ) 
    40 CalenDayItemView::CalenDayItemView( MCalenServices &services, HbModelIterator *iterator, QGraphicsItem *parent ) 
    42 : HbAbstractItemView(mContainer = new CalenDayContainer(), iterator, parent),
    41 : HbAbstractItemView(mContainer = new CalenDayContainer(), iterator, parent),
    43   mServices( services )
    42   mServices( services )
    44 {
    43 {
    45     mInfo = new CalenDayInfo( CalenDayInfo::ETwo );
    44     mInfo = new CalenDayInfo( CalenDayInfo::ETwo );
    69       
    68       
    70     setupSlots();
    69     setupSlots();
    71     setupContextMenu();
    70     setupContextMenu();
    72 }
    71 }
    73 
    72 
    74 // -----------------------------------------------------------------------------
    73 /*!
    75 // ~CalenDayItemView()
    74    \brief Destructor
    76 // Destructor
    75 */
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CalenDayItemView::~CalenDayItemView()
    76 CalenDayItemView::~CalenDayItemView()
    80 {
    77 {
    81     delete mInfo;
    78     delete mInfo;
    82 }
    79 }
    83 
    80 
    84 // -----------------------------------------------------------------------------
    81 /*!
    85 // scrollTo()
    82    \brief Scrolls to given index
    86 // 
    83 */
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CalenDayItemView::scrollTo(const QModelIndex &index, HbAbstractItemView::ScrollHint hint)
    84 void CalenDayItemView::scrollTo(const QModelIndex &index, HbAbstractItemView::ScrollHint hint)
    90 {
    85 {
    91     HbAbstractItemView::scrollTo(index, hint);
    86     HbAbstractItemView::scrollTo(index, hint);
    92 }
    87 }
    93 
    88 
    94 // -----------------------------------------------------------------------------
    89 /*!
    95 // reset()
    90    \brief Currently empty implementation.
    96 // 
    91 */
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CalenDayItemView::reset()
    92 void CalenDayItemView::reset()
   100 {
    93 {
   101 //    CalenDayItemView::reset();
    94 
   102 }
    95 }
   103 
    96 
   104 // -----------------------------------------------------------------------------
    97 
   105 // modelAboutToBeReset()
    98 /*!
   106 // Handles signal that is emitted when reset() is called, before the model's
    99    \brief Handles signal that is emitted when reset() is called, before the model's
   107 // internal state (e.g. persistent model indexes) has been invalidated.
   100           internal state (e.g. persistent model indexes) has been invalidated.
   108 // -----------------------------------------------------------------------------
   101 */
   109 //
       
   110 void CalenDayItemView::modelAboutToBeReset()
   102 void CalenDayItemView::modelAboutToBeReset()
   111 {
   103 {
   112     
   104     
   113 }
   105 }
   114 
   106 
   115 // -----------------------------------------------------------------------------
   107 /*!
   116 // modelReset()
   108    \brief Handles signal that is emitted when reset() is called, before the model's
   117 // Handles signal that is emitted when reset() is called, after the model's
   109           internal state (e.g. persistent model indexes) has been invalidated.
   118 // internal state (e.g. persistent model indexes) has been invalidated.
   110 */
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CalenDayItemView::modelReset()
   111 void CalenDayItemView::modelReset()
   122 {
   112 {
   123     if ( !mInfo ) {
   113     if ( !mInfo ) {
   124         return;
   114         return;
   125     }
   115     }
   126     //reset day info
   116     //reset day info
   127     mInfo->Reset();
   117     mInfo->Reset();
   128     
   118 
   129     CalenDayModel* model(0);
   119     CalenDayModel* model(0);
   130     model = static_cast<CalenDayModel*>(this->model());
   120     model = static_cast<CalenDayModel*>(this->model());
   131     if ( !model ) {
   121     if ( !model ) {
   132         return;
   122         return;
   133     }
   123     }
       
   124     
       
   125     mContainer->setDate(model->modelDate().date());
   134     int rowCount = model->rowCount( );
   126     int rowCount = model->rowCount( );
   135     SCalenApptInfo apptInfo; 
   127     SCalenApptInfo apptInfo; 
   136     for( int row = 0; row < rowCount; row++ ) {
   128     for( int row = 0; row < rowCount; row++ ) {
   137         QModelIndex idx = model->index( row, 0 );
   129         QModelIndex idx = model->index( row, 0 );
   138         QVariant variant = idx.data( CalenDayEntry );
   130         QVariant variant = idx.data( CalenDayEntry );
   152         id.mEntryLocalUid = row;
   144         id.mEntryLocalUid = row;
   153         id.mInstanceTime = apptInfo.iStartTime; 
   145         id.mInstanceTime = apptInfo.iStartTime; 
   154         apptInfo.iId = id;
   146         apptInfo.iId = id;
   155         apptInfo.iColor = 0xffff;
   147         apptInfo.iColor = 0xffff;
   156         
   148         
   157         if ( entry.isTimedEntry() )
   149         if ( entry.isTimedEntry() && !CalenAgendaUtils::isAlldayEvent(entry))
   158         	{
   150         	{
   159             apptInfo.iAllDay = false;
   151             apptInfo.iAllDay = false;
   160             mInfo->InsertTimedEvent( apptInfo );
   152             mInfo->InsertTimedEvent( apptInfo );
   161         	}
   153         	}
   162         else if( entry.type() == AgendaEntry::TypeEvent) //all-day event
   154         else if(CalenAgendaUtils::isAlldayEvent(entry)) //all-day event
   163         	{
   155         	{
   164         	apptInfo.iAllDay = true;
   156         	apptInfo.iAllDay = true;
   165         	mInfo->InsertAlldayEvent( apptInfo );
   157         	mInfo->InsertAlldayEvent( apptInfo );
   166         	}
   158         	}
   167     }
   159     }
   168     
   160     
   169     HbAbstractItemView::reset();
   161     HbAbstractItemView::reset();
   170 }
   162 }
   171 
   163 
   172 // -----------------------------------------------------------------------------
   164 /*!
   173 // scrollVertically()
   165    \brief Scrolls view vertically to the given position.
   174 //  
   166    
   175 // -----------------------------------------------------------------------------
   167    \param newPosition position to scroll to.
   176 //
   168 */
   177 void CalenDayItemView::scrollVertically( const QPointF &newPosition )
   169 void CalenDayItemView::scrollVertically( const QPointF &newPosition )
   178 {
   170 {
   179     QPointF currentPos = contentWidget()->pos();
   171     QPointF currentPos = contentWidget()->pos();
   180     if (abs(newPosition.y()) != abs(currentPos.y())) {
   172     if (abs(newPosition.y()) != abs(currentPos.y())) {
   181         currentPos.setY(newPosition.y());
   173         currentPos.setY(newPosition.y());
   182         scrollContentsTo(currentPos, 0);
   174         scrollContentsTo(currentPos, 0);
   183     }
   175     }
   184 }
   176 }
   185 
   177 
   186 // -----------------------------------------------------------------------------
   178 /*!
   187 // itemPressed()
   179    \brief This function is called when a touch press event is received 
   188 // This function is called when a touch down event is received within Abstract view item that is representing index. 
   180           within Abstract view item that is representing index.
   189 // -----------------------------------------------------------------------------
   181           Currently it does nothing.
   190 //
   182 */
   191 void CalenDayItemView::itemPressed( const QPointF &position )
   183 void CalenDayItemView::itemPressed( const QPointF &position )
   192 {
   184 {
   193     Q_UNUSED( position )
   185     Q_UNUSED( position )
   194 }
   186 }
   195 
   187 
   196 // -----------------------------------------------------------------------------
   188 /*!
   197 // itemReleased()
   189    \brief This function is called when a touch release event is received 
   198 // This function is called when a touch release event is received within Abstract view item that is representing index.
   190           within Abstract view item that is representing index.
   199 // -----------------------------------------------------------------------------
   191           Currently it does nothing.
   200 //
   192 */
   201 void CalenDayItemView::itemReleased( const QPointF &position )
   193 void CalenDayItemView::itemReleased( const QPointF &position )
   202 {
   194 {
   203     Q_UNUSED( position )
   195     Q_UNUSED( position )
   204 }
   196 }
   205 
   197 
   206 // -----------------------------------------------------------------------------
   198 /*!
   207 // itemActivated()
   199    \brief This function is called when the item specified by index is activated by the user.
   208 // This function is called when the item specified by index is activated by the user.
   200    
   209 // -----------------------------------------------------------------------------
   201    \param position Not used.
   210 //
   202 */
   211 void CalenDayItemView::itemActivated( const QPointF &position )
   203 void CalenDayItemView::itemActivated( const QPointF &position )
   212 {
   204 {
   213     Q_UNUSED( position )
   205     Q_UNUSED( position )
   214     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender());
   206     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender());
   215     QModelIndex index = item->modelIndex();
   207     QModelIndex index = item->modelIndex();
   218         selModel->select( index, QItemSelectionModel::Current | QItemSelectionModel::Select );
   210         selModel->select( index, QItemSelectionModel::Current | QItemSelectionModel::Select );
   219         openSelectedItem();
   211         openSelectedItem();
   220     }
   212     }
   221 }
   213 }
   222 
   214 
   223 // -----------------------------------------------------------------------------
   215 /*!
   224 // itemLongPressed()
   216    \brief This function is called when long press event is received within Abstract view item viewItem.
   225 // This function is called when long press event is received within Abstract view item viewItem.
   217 
   226 // -----------------------------------------------------------------------------
   218    \param item Pointer to pressed item.
   227 //
   219    \param coord Position where item was pressed.
       
   220 */
   228 void CalenDayItemView::itemLongPressed(HbAbstractViewItem* item, QPointF coords)
   221 void CalenDayItemView::itemLongPressed(HbAbstractViewItem* item, QPointF coords)
   229 {
   222 {
   230     QModelIndex index = item->modelIndex();
   223     QModelIndex index = item->modelIndex();
   231     QItemSelectionModel* selModel( selectionModel() );
   224     QItemSelectionModel* selModel( selectionModel() );
   232     if ( index.isValid() && selModel && mContextMenu) {
   225     if ( index.isValid() && selModel && mContextMenu) {
   234         mContextMenu->setPreferredPos( coords, HbPopup::BottomRightCorner );
   227         mContextMenu->setPreferredPos( coords, HbPopup::BottomRightCorner );
   235         mContextMenu->open();
   228         mContextMenu->open();
   236     }
   229     }
   237 }
   230 }
   238 
   231 
   239 // -----------------------------------------------------------------------------
   232 /*!
   240 // orientationChanged()
   233    \brief Slot which is called whenever the orientation of the device changes.
   241 // Slot which is called whenever the orientation of the device changes.
   234 
   242 // -----------------------------------------------------------------------------
   235    \param orientation New orientation.
   243 //
   236 */
   244 void CalenDayItemView::orientationChanged( Qt::Orientation orientation )
   237 void CalenDayItemView::orientationChanged( Qt::Orientation orientation )
   245 {
   238 {
   246     // Update the width of screen
   239     // Update the width of screen
   247     qreal contentWidth = CalenDayUtils::instance()->contentWidth();
   240     qreal contentWidth = CalenDayUtils::instance()->contentWidth();
   248     setMinimumWidth(contentWidth);
   241     setMinimumWidth(contentWidth);
   250     if( mContainer ) {
   243     if( mContainer ) {
   251         mContainer->orientationChanged( orientation );
   244         mContainer->orientationChanged( orientation );
   252     }
   245     }
   253 }
   246 }
   254 
   247 
   255 // -----------------------------------------------------------------------------
   248 /*!
   256 // openSelectedItem()
   249    \brief Opens currently selected model item.
   257 // Opens currently selected model item.
   250 */
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CalenDayItemView::openSelectedItem()
   251 void CalenDayItemView::openSelectedItem()
   261 {
   252 {
   262     issueCommandOnSelectedItem( ECalenEventView );
   253     issueCommandOnSelectedItem( ECalenEventView );
   263 }
   254 }
   264 
   255 
   265 // -----------------------------------------------------------------------------
   256 /*!
   266 // editSelectedItem()
   257    \brief Edits currently selected model item.
   267 // Edits currently selected model item.
   258 */
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CalenDayItemView::editSelectedItem()
   259 void CalenDayItemView::editSelectedItem()
   271 {
   260 {
   272     issueCommandOnSelectedItem( ECalenEditCurrentEntry );
   261     issueCommandOnSelectedItem( ECalenEditCurrentEntry );
   273 }
   262 }
   274 
   263 
   275 // -----------------------------------------------------------------------------
   264 /*!
   276 // deleteSelectedIten()
   265    \brief Deletes currently selected model item.
   277 // Deletes currently selected model item.
   266 */
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CalenDayItemView::deleteSelectedItem()
   267 void CalenDayItemView::deleteSelectedItem()
   281 {
   268 {
   282     issueCommandOnSelectedItem( ECalenDeleteCurrentEntry );
   269     issueCommandOnSelectedItem( ECalenDeleteCurrentEntry );
   283 }
   270 }
   284 
   271 
   285 // -----------------------------------------------------------------------------
   272 /*!
   286 // setupSlots()
   273    \brief Connects item view's slots.
   287 // Connects item view's slots.
   274 */
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CalenDayItemView::setupSlots()
   275 void CalenDayItemView::setupSlots()
   291 {
   276 {
   292     // Connect to main window's orientationChanged signal to handle orientation
   277     // Connect to main window's orientationChanged signal to handle orientation
   293     // switching
   278     // switching
   294     QObject::connect(CalenDayUtils::instance()->mainWindow(), 
   279     QObject::connect(CalenDayUtils::instance()->mainWindow(), 
   315         SLOT(const QPointF&));
   300         SLOT(const QPointF&));
   316     QObject::connect(this, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
   301     QObject::connect(this, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
   317         this, SLOT(itemLongPressed(HbAbstractViewItem*, QPointF)));
   302         this, SLOT(itemLongPressed(HbAbstractViewItem*, QPointF)));
   318 }
   303 }
   319 
   304 
   320 // -----------------------------------------------------------------------------
   305 /*!
   321 // setupSlots()
   306    \brief Creates context menu.
   322 // Creates Context menu.
   307 */
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CalenDayItemView::setupContextMenu()
   308 void CalenDayItemView::setupContextMenu()
   326 {
   309 {
   327     mContextMenu = new HbMenu();
   310     mContextMenu = new HbMenu();
   328     HbAction *openAction = mContextMenu->addAction(hbTrId("txt_common_menu_open"));
   311     HbAction *openAction = mContextMenu->addAction(hbTrId("txt_common_menu_open"));
   329     if (openAction) {
   312     if (openAction) {
   338         connect(deleteAction, SIGNAL(triggered()), this,
   321         connect(deleteAction, SIGNAL(triggered()), this,
   339             SLOT(deleteSelectedItem()));
   322             SLOT(deleteSelectedItem()));
   340     }
   323     }
   341 }
   324 }
   342 
   325 
   343 // -----------------------------------------------------------------------------
   326 /*!
   344 // issueCommandOnSelectedItem()
   327    \brief Sets context to currently selected model item and issues calendar command.
   345 // Sets context to currently selected model item and issues calendar command.
   328    
   346 // -----------------------------------------------------------------------------
   329    \param command A command to be issued.
   347 //
   330 */
   348 bool CalenDayItemView::issueCommandOnSelectedItem( int command )
   331 bool CalenDayItemView::issueCommandOnSelectedItem( int command )
   349 {
   332 {
   350     bool retVal(false);
   333     bool retVal(false);
   351     QItemSelectionModel* selModel(selectionModel());
   334     QItemSelectionModel* selModel(selectionModel());
   352     if (!selModel){
   335     if (!selModel){
   375         clearSelectionInModel();
   358         clearSelectionInModel();
   376     }
   359     }
   377     return retVal;
   360     return retVal;
   378 }
   361 }
   379 
   362 
   380 // -----------------------------------------------------------------------------
   363 /*!
   381 // clearSelectionInModel()
   364    \brief Clears current selection in Selection Model.
   382 // Clears current selection in Selection Model.
   365 */
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void CalenDayItemView::clearSelectionInModel()
   366 void CalenDayItemView::clearSelectionInModel()
   386 {
   367 {
   387     QItemSelectionModel* selModel(selectionModel());
   368     QItemSelectionModel* selModel(selectionModel());
   388     if (selModel) {
   369     if (selModel) {
   389         selModel->clear();
   370         selModel->clear();