calendarui/views/dayview/src/calendayitemview.cpp
changeset 57 bb2d3e476f29
parent 55 2c54b51f39c4
child 63 a3cb48f6c889
equal deleted inserted replaced
55:2c54b51f39c4 57:bb2d3e476f29
    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     }
   154         id.mEntryLocalUid = row;
   144         id.mEntryLocalUid = row;
   155         id.mInstanceTime = apptInfo.iStartTime; 
   145         id.mInstanceTime = apptInfo.iStartTime; 
   156         apptInfo.iId = id;
   146         apptInfo.iId = id;
   157         apptInfo.iColor = 0xffff;
   147         apptInfo.iColor = 0xffff;
   158         
   148         
   159         if ( entry.isTimedEntry() )
   149         if ( entry.isTimedEntry() && !CalenAgendaUtils::isAlldayEvent(entry))
   160         	{
   150         	{
   161             apptInfo.iAllDay = false;
   151             apptInfo.iAllDay = false;
   162             mInfo->InsertTimedEvent( apptInfo );
   152             mInfo->InsertTimedEvent( apptInfo );
   163         	}
   153         	}
   164         else if( entry.type() == AgendaEntry::TypeEvent) //all-day event
   154         else if(CalenAgendaUtils::isAlldayEvent(entry)) //all-day event
   165         	{
   155         	{
   166         	apptInfo.iAllDay = true;
   156         	apptInfo.iAllDay = true;
   167         	mInfo->InsertAlldayEvent( apptInfo );
   157         	mInfo->InsertAlldayEvent( apptInfo );
   168         	}
   158         	}
   169     }
   159     }
   170     
   160     
   171     HbAbstractItemView::reset();
   161     HbAbstractItemView::reset();
   172 }
   162 }
   173 
   163 
   174 // -----------------------------------------------------------------------------
   164 /*!
   175 // scrollVertically()
   165    \brief Scrolls view vertically to the given position.
   176 //  
   166    
   177 // -----------------------------------------------------------------------------
   167    \param newPosition position to scroll to.
   178 //
   168 */
   179 void CalenDayItemView::scrollVertically( const QPointF &newPosition )
   169 void CalenDayItemView::scrollVertically( const QPointF &newPosition )
   180 {
   170 {
   181     QPointF currentPos = contentWidget()->pos();
   171     QPointF currentPos = contentWidget()->pos();
   182     if (abs(newPosition.y()) != abs(currentPos.y())) {
   172     if (abs(newPosition.y()) != abs(currentPos.y())) {
   183         currentPos.setY(newPosition.y());
   173         currentPos.setY(newPosition.y());
   184         scrollContentsTo(currentPos, 0);
   174         scrollContentsTo(currentPos, 0);
   185     }
   175     }
   186 }
   176 }
   187 
   177 
   188 // -----------------------------------------------------------------------------
   178 /*!
   189 // itemPressed()
   179    \brief This function is called when a touch press event is received 
   190 // 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.
   191 // -----------------------------------------------------------------------------
   181           Currently it does nothing.
   192 //
   182 */
   193 void CalenDayItemView::itemPressed( const QPointF &position )
   183 void CalenDayItemView::itemPressed( const QPointF &position )
   194 {
   184 {
   195     Q_UNUSED( position )
   185     Q_UNUSED( position )
   196 }
   186 }
   197 
   187 
   198 // -----------------------------------------------------------------------------
   188 /*!
   199 // itemReleased()
   189    \brief This function is called when a touch release event is received 
   200 // 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.
   201 // -----------------------------------------------------------------------------
   191           Currently it does nothing.
   202 //
   192 */
   203 void CalenDayItemView::itemReleased( const QPointF &position )
   193 void CalenDayItemView::itemReleased( const QPointF &position )
   204 {
   194 {
   205     Q_UNUSED( position )
   195     Q_UNUSED( position )
   206 }
   196 }
   207 
   197 
   208 // -----------------------------------------------------------------------------
   198 /*!
   209 // itemActivated()
   199    \brief This function is called when the item specified by index is activated by the user.
   210 // This function is called when the item specified by index is activated by the user.
   200    
   211 // -----------------------------------------------------------------------------
   201    \param position Not used.
   212 //
   202 */
   213 void CalenDayItemView::itemActivated( const QPointF &position )
   203 void CalenDayItemView::itemActivated( const QPointF &position )
   214 {
   204 {
   215     Q_UNUSED( position )
   205     Q_UNUSED( position )
   216     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender());
   206     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender());
   217     QModelIndex index = item->modelIndex();
   207     QModelIndex index = item->modelIndex();
   220         selModel->select( index, QItemSelectionModel::Current | QItemSelectionModel::Select );
   210         selModel->select( index, QItemSelectionModel::Current | QItemSelectionModel::Select );
   221         openSelectedItem();
   211         openSelectedItem();
   222     }
   212     }
   223 }
   213 }
   224 
   214 
   225 // -----------------------------------------------------------------------------
   215 /*!
   226 // itemLongPressed()
   216    \brief This function is called when long press event is received within Abstract view item viewItem.
   227 // This function is called when long press event is received within Abstract view item viewItem.
   217 
   228 // -----------------------------------------------------------------------------
   218    \param item Pointer to pressed item.
   229 //
   219    \param coord Position where item was pressed.
       
   220 */
   230 void CalenDayItemView::itemLongPressed(HbAbstractViewItem* item, QPointF coords)
   221 void CalenDayItemView::itemLongPressed(HbAbstractViewItem* item, QPointF coords)
   231 {
   222 {
   232     QModelIndex index = item->modelIndex();
   223     QModelIndex index = item->modelIndex();
   233     QItemSelectionModel* selModel( selectionModel() );
   224     QItemSelectionModel* selModel( selectionModel() );
   234     if ( index.isValid() && selModel && mContextMenu) {
   225     if ( index.isValid() && selModel && mContextMenu) {
   236         mContextMenu->setPreferredPos( coords, HbPopup::BottomRightCorner );
   227         mContextMenu->setPreferredPos( coords, HbPopup::BottomRightCorner );
   237         mContextMenu->open();
   228         mContextMenu->open();
   238     }
   229     }
   239 }
   230 }
   240 
   231 
   241 // -----------------------------------------------------------------------------
   232 /*!
   242 // orientationChanged()
   233    \brief Slot which is called whenever the orientation of the device changes.
   243 // Slot which is called whenever the orientation of the device changes.
   234 
   244 // -----------------------------------------------------------------------------
   235    \param orientation New orientation.
   245 //
   236 */
   246 void CalenDayItemView::orientationChanged( Qt::Orientation orientation )
   237 void CalenDayItemView::orientationChanged( Qt::Orientation orientation )
   247 {
   238 {
   248     // Update the width of screen
   239     // Update the width of screen
   249     qreal contentWidth = CalenDayUtils::instance()->contentWidth();
   240     qreal contentWidth = CalenDayUtils::instance()->contentWidth();
   250     setMinimumWidth(contentWidth);
   241     setMinimumWidth(contentWidth);
   252     if( mContainer ) {
   243     if( mContainer ) {
   253         mContainer->orientationChanged( orientation );
   244         mContainer->orientationChanged( orientation );
   254     }
   245     }
   255 }
   246 }
   256 
   247 
   257 // -----------------------------------------------------------------------------
   248 /*!
   258 // openSelectedItem()
   249    \brief Opens currently selected model item.
   259 // Opens currently selected model item.
   250 */
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CalenDayItemView::openSelectedItem()
   251 void CalenDayItemView::openSelectedItem()
   263 {
   252 {
   264     issueCommandOnSelectedItem( ECalenEventView );
   253     issueCommandOnSelectedItem( ECalenEventView );
   265 }
   254 }
   266 
   255 
   267 // -----------------------------------------------------------------------------
   256 /*!
   268 // editSelectedItem()
   257    \brief Edits currently selected model item.
   269 // Edits currently selected model item.
   258 */
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CalenDayItemView::editSelectedItem()
   259 void CalenDayItemView::editSelectedItem()
   273 {
   260 {
   274     issueCommandOnSelectedItem( ECalenEditCurrentEntry );
   261     issueCommandOnSelectedItem( ECalenEditCurrentEntry );
   275 }
   262 }
   276 
   263 
   277 // -----------------------------------------------------------------------------
   264 /*!
   278 // deleteSelectedIten()
   265    \brief Deletes currently selected model item.
   279 // Deletes currently selected model item.
   266 */
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CalenDayItemView::deleteSelectedItem()
   267 void CalenDayItemView::deleteSelectedItem()
   283 {
   268 {
   284     issueCommandOnSelectedItem( ECalenDeleteCurrentEntry );
   269     issueCommandOnSelectedItem( ECalenDeleteCurrentEntry );
   285 }
   270 }
   286 
   271 
   287 // -----------------------------------------------------------------------------
   272 /*!
   288 // setupSlots()
   273    \brief Connects item view's slots.
   289 // Connects item view's slots.
   274 */
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CalenDayItemView::setupSlots()
   275 void CalenDayItemView::setupSlots()
   293 {
   276 {
   294     // Connect to main window's orientationChanged signal to handle orientation
   277     // Connect to main window's orientationChanged signal to handle orientation
   295     // switching
   278     // switching
   296     QObject::connect(CalenDayUtils::instance()->mainWindow(), 
   279     QObject::connect(CalenDayUtils::instance()->mainWindow(), 
   317         SLOT(const QPointF&));
   300         SLOT(const QPointF&));
   318     QObject::connect(this, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
   301     QObject::connect(this, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
   319         this, SLOT(itemLongPressed(HbAbstractViewItem*, QPointF)));
   302         this, SLOT(itemLongPressed(HbAbstractViewItem*, QPointF)));
   320 }
   303 }
   321 
   304 
   322 // -----------------------------------------------------------------------------
   305 /*!
   323 // setupSlots()
   306    \brief Creates context menu.
   324 // Creates Context menu.
   307 */
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CalenDayItemView::setupContextMenu()
   308 void CalenDayItemView::setupContextMenu()
   328 {
   309 {
   329     mContextMenu = new HbMenu();
   310     mContextMenu = new HbMenu();
   330     HbAction *openAction = mContextMenu->addAction(hbTrId("txt_common_menu_open"));
   311     HbAction *openAction = mContextMenu->addAction(hbTrId("txt_common_menu_open"));
   331     if (openAction) {
   312     if (openAction) {
   340         connect(deleteAction, SIGNAL(triggered()), this,
   321         connect(deleteAction, SIGNAL(triggered()), this,
   341             SLOT(deleteSelectedItem()));
   322             SLOT(deleteSelectedItem()));
   342     }
   323     }
   343 }
   324 }
   344 
   325 
   345 // -----------------------------------------------------------------------------
   326 /*!
   346 // issueCommandOnSelectedItem()
   327    \brief Sets context to currently selected model item and issues calendar command.
   347 // Sets context to currently selected model item and issues calendar command.
   328    
   348 // -----------------------------------------------------------------------------
   329    \param command A command to be issued.
   349 //
   330 */
   350 bool CalenDayItemView::issueCommandOnSelectedItem( int command )
   331 bool CalenDayItemView::issueCommandOnSelectedItem( int command )
   351 {
   332 {
   352     bool retVal(false);
   333     bool retVal(false);
   353     QItemSelectionModel* selModel(selectionModel());
   334     QItemSelectionModel* selModel(selectionModel());
   354     if (!selModel){
   335     if (!selModel){
   377         clearSelectionInModel();
   358         clearSelectionInModel();
   378     }
   359     }
   379     return retVal;
   360     return retVal;
   380 }
   361 }
   381 
   362 
   382 // -----------------------------------------------------------------------------
   363 /*!
   383 // clearSelectionInModel()
   364    \brief Clears current selection in Selection Model.
   384 // Clears current selection in Selection Model.
   365 */
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CalenDayItemView::clearSelectionInModel()
   366 void CalenDayItemView::clearSelectionInModel()
   388 {
   367 {
   389     QItemSelectionModel* selModel(selectionModel());
   368     QItemSelectionModel* selModel(selectionModel());
   390     if (selModel) {
   369     if (selModel) {
   391         selModel->clear();
   370         selModel->clear();