calendarui/views/dayview/src/calendaycontainer.cpp
changeset 57 bb2d3e476f29
parent 55 2c54b51f39c4
child 63 a3cb48f6c889
equal deleted inserted replaced
55:2c54b51f39c4 57:bb2d3e476f29
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:  Day view container - parent widget for events (CalenDayItem) and
    14  * Description:  Day view container - parent widget for events (CalenDayItem)
    15 * hours area widgets (CalenDayEventsPane)
    15  * and hours area widgets (CalenDayEventsPane)
    16 * Responsible for positioning and resizing events widgets.
    16  * Responsible for positioning and resizing events widgets.
    17 */
    17  */
    18 
    18 
    19 //System includes
    19 //System includes
    20 #include <QTime>
    20 #include <QTime>
    21 #include <QGraphicsLinearLayout>
    21 #include <QGraphicsLinearLayout>
    22 #include <QGesture>
    22 #include <QGesture>
    23 
    23 
    24 #ifdef _DEBUG
    24 #ifdef _DEBUG
    25 	#include <QPainter>
    25 	#include <QPainter>
    26 #endif
    26 #endif
    27 
    27 
    28 #include <hbabstractitemview.h>
    28 #include <HbAbstractItemView>
    29 #include <hbtextitem.h>
    29 #include <HbTextItem>
    30 #include <hbmodeliterator.h>
    30 #include <HbModelIterator>
    31 #include <hbinstance.h>
    31 #include <HbInstance>
    32 
    32 
    33 //User includes
    33 //User includes
    34 #include "calendaycontainer.h"
    34 #include "calendaycontainer.h"
    35 #include "calendayutils.h"
    35 #include "calendayutils.h"
    36 #include "calendayeventspane.h"
    36 #include "calendayeventspane.h"
    37 #include "calendayitem.h"
    37 #include "calendayitem.h"
    38 #include "calendaymodel.h"
    38 #include "calendaymodel.h"
    39 #include "calendayinfo.h"
    39 #include "calendayinfo.h"
    40 #include "calendayview.h"
    40 #include "calendayview.h"
       
    41 #include "calenagendautils.h"
       
    42 #include "calendaycommonheaders.h"
       
    43 
       
    44 /*!
       
    45  \class CalenDayContainer
       
    46  
       
    47  \brief CalenDayContainer Item container class associated with model.
       
    48  */
    41 
    49 
    42 /*!
    50 /*!
    43  \brief Constructor
    51  \brief Constructor
    44  
    52  
    45  Sets container initial geometry, creates hours area widgets.
    53  Sets container initial geometry, creates hours area widgets.
       
    54  \param parent Parent object
    46  */
    55  */
    47 CalenDayContainer::CalenDayContainer(QGraphicsItem *parent) :
    56 CalenDayContainer::CalenDayContainer(QGraphicsItem *parent) :
    48     HbAbstractItemContainer(parent), mGeometryUpdated(false), mInfo(0)
    57     HbAbstractItemContainer(parent), mGeometryUpdated(false), mInfo(0)
    49 {
    58 {
    50     getTimedEventLayoutValues(mLayoutValues);
    59     getTimedEventLayoutValues(mLayoutValues);
    51     
    60 
    52     QGraphicsLinearLayout* timeLinesLayout = new QGraphicsLinearLayout(
    61     QGraphicsLinearLayout* timeLinesLayout = new QGraphicsLinearLayout(
    53         Qt::Vertical, this);
    62         Qt::Vertical, this);
    54     for (int i = 0; i < 24; i++) {
    63     for (int i = 0; i < KCalenHoursInDay; i++) {
    55         CalenDayEventsPane* element = new CalenDayEventsPane(this);
    64         CalenDayEventsPane* element = new CalenDayEventsPane(this);
    56 		// Draw top line at midnight
    65         // Draw top line at midnight
    57         if (i == 0) {
    66         if (i == 0) {
    58             element->setDrawTopLine(true);
    67             element->setDrawTopLine(true);
    59         }
    68         }
    60         timeLinesLayout->addItem(element);
    69         timeLinesLayout->addItem(element);
    61     }
    70     }
    63     timeLinesLayout->setSpacing(0.0);
    72     timeLinesLayout->setSpacing(0.0);
    64 
    73 
    65     setLayout(timeLinesLayout);
    74     setLayout(timeLinesLayout);
    66 }
    75 }
    67 
    76 
    68 
       
    69 /*!
    77 /*!
    70  \brief Destructor
    78  \brief Destructor
    71  */
    79  */
    72 CalenDayContainer::~CalenDayContainer()
    80 CalenDayContainer::~CalenDayContainer()
    73 {
    81 {
    74 }
    82     // Remove absorbers if exist
    75 
    83     if (mAbsorbers.count()) {
    76 
    84         qDeleteAll(mAbsorbers);
    77 /*
    85         mAbsorbers.clear();
    78     \reimp
    86     }
    79  */
    87 }
    80 void CalenDayContainer::itemAdded( int index, HbAbstractViewItem *item, 
    88 
    81                                      bool animate )
    89 /*
       
    90  \reimp
       
    91  */
       
    92 void CalenDayContainer::itemAdded(
       
    93     int index,
       
    94     HbAbstractViewItem *item,
       
    95     bool animate)
    82 {
    96 {
    83     Q_UNUSED( index )
    97     Q_UNUSED( index )
    84     Q_UNUSED( item )
    98     Q_UNUSED( item )
    85     Q_UNUSED( animate )
    99     Q_UNUSED( animate )
    86 }
   100 }
    87 
   101 
    88 
   102 
    89 /*
   103 /*
    90     \reimp
   104  \brief Resets the state of container.
       
   105  
       
   106  Removes absorbers, gets layout values and maintains current position.
    91  */
   107  */
    92 void CalenDayContainer::reset()
   108 void CalenDayContainer::reset()
    93 {
   109 {
    94 	// remove absorbers if exist
   110     // Remove absorbers if exist
    95 	if (mAbsorbers.count())
   111     if (mAbsorbers.count()) {
    96 		{
   112         qDeleteAll(mAbsorbers);
    97 		qDeleteAll(mAbsorbers);
   113         mAbsorbers.clear();
    98 		mAbsorbers.clear();
   114     }
    99 		}
   115 
   100 	
   116     // Shrink event area when all-day events available after reset
   101 	// shrink event area when all-day events available after reset
   117     getTimedEventLayoutValues(mLayoutValues);
   102 	getTimedEventLayoutValues(mLayoutValues);
   118 
   103 	
   119     // Position need to be maintained while changing model
   104     // position need to be maintained while changing model
       
   105     QPointF position(pos());
   120     QPointF position(pos());
   106     HbAbstractItemContainer::reset();
   121     HbAbstractItemContainer::reset();
   107     setPos( position );
   122     setPos(position);
   108 }
   123 }
   109 
   124 
   110 
   125 /*
   111 /*
   126  \reimp
   112     \reimp
   127  */
   113  */
   128 void CalenDayContainer::itemRemoved(HbAbstractViewItem *item, bool animate)
   114 void CalenDayContainer::itemRemoved( HbAbstractViewItem *item, bool animate )
       
   115 {
   129 {
   116     Q_UNUSED( item )
   130     Q_UNUSED( item )
   117     Q_UNUSED( animate )
   131     Q_UNUSED( animate )
   118 }
   132 }
   119 
   133 
   120 
   134 /*
   121 /*
   135  \reimp
   122     \reimp
   136  */
   123  */
   137 void CalenDayContainer::viewResized(const QSizeF &size)
   124 void CalenDayContainer::viewResized (const QSizeF &size)
       
   125 {
   138 {
   126     resize(size);
   139     resize(size);
   127     if (!mGeometryUpdated) {
   140     if (!mGeometryUpdated) {
   128         mGeometryUpdated = true;
   141         mGeometryUpdated = true;
   129         updateGeometry();
   142         updateGeometry();
   130     }
   143     }
   131 }
   144 }
   132 
   145 
   133 
   146 /*
   134 /*
   147  \reimp
   135     \reimp
       
   136  */
   148  */
   137 HbAbstractViewItem * CalenDayContainer::createDefaultPrototype() const
   149 HbAbstractViewItem * CalenDayContainer::createDefaultPrototype() const
   138 {
   150 {
   139     CalenDayItem *calendarViewItem = new CalenDayItem(this);
   151     CalenDayItem *calendarViewItem = new CalenDayItem(this);
   140     return calendarViewItem;
   152     return calendarViewItem;
   141 }
   153 }
   142 
   154 
   143 
   155 /*
   144 /*
   156  \reimp
   145     \reimp
   157  */
   146  */
   158 void CalenDayContainer::setItemModelIndex(
   147 void CalenDayContainer::setItemModelIndex(HbAbstractViewItem *item, 
   159     HbAbstractViewItem *item,
   148                                             const QModelIndex &index)
   160     const QModelIndex &index)
   149 {
   161 {
   150     QVariant variant = index.data( CalenDayEntry );
   162     QVariant variant = index.data(CalenDayEntry);
   151     AgendaEntry entry = variant.value<AgendaEntry>();
   163     AgendaEntry entry = variant.value<AgendaEntry> ();
   152     
   164 
   153     if (entry.isTimedEntry()) {
   165     // Check for All Day Events and Timed entries
   154         updateTimedEventGeometry( item, index );
   166     if (CalenAgendaUtils::isAlldayEvent(entry)) {
       
   167         updateAllDayEventGeometry(item, index);
   155         item->setParentItem(this);
   168         item->setParentItem(this);
   156     	}
   169     }
   157     else if( entry.type() == AgendaEntry::TypeEvent ){
   170     else
   158         updateAllDayEventGeometry( item, index );
   171         if (entry.isTimedEntry()) {
   159         item->setParentItem(this);
   172             updateTimedEventGeometry(item, index);
   160     	} 
   173             item->setParentItem(this);
   161     else {
   174         }
   162     	item->setVisible(false);
   175         else {
   163     }
   176             item->setVisible(false);
   164     
   177         }
   165     // last item
   178 
       
   179     // Create touch event absorbers after last item
   166     if (index.row() == index.model()->rowCount() - 1) {
   180     if (index.row() == index.model()->rowCount() - 1) {
   167     	createTouchEventAbsorbers();
   181         createTouchEventAbsorbers();
   168     }
   182     }
   169 
   183 
   170     HbAbstractItemContainer::setItemModelIndex(item, index);
   184     HbAbstractItemContainer::setItemModelIndex(item, index);
   171 }
   185 }
   172 
   186 
   173 
   187 
   174 // TODO: updateTimedEventGeometry and updateAllDayEventGeometry
   188 /*!
   175 // methods are very similar and probably can be merged to avoid
   189  \brief Set size and position of singe timed event widget (bubble)
   176 // code duplication
   190  \a item bubble widget
   177 /*!
   191  \a index pointing item data in model
   178 	\brief Set size and position of singe timed event widget (bubble)
   192  */
   179 	\a item bubble widget
   193 void CalenDayContainer::updateTimedEventGeometry(
   180 	\a index pointing item data in model
   194     HbAbstractViewItem *item,
   181  */
   195     const QModelIndex &index)
   182 void CalenDayContainer::updateTimedEventGeometry(HbAbstractViewItem *item, 
   196 {
   183                                                    const QModelIndex &index)
   197     // Safety check
   184 {
   198     if (!mInfo) {
   185 //safety check
       
   186     if ( !mInfo ) {
       
   187         return;
   199         return;
   188     }
   200     }
   189     
   201 
   190     QVariant variant = index.data( CalenDayEntry );
   202     QVariant variant = index.data(CalenDayEntry);
   191     AgendaEntry entry = variant.value<AgendaEntry>();
   203     AgendaEntry entry = variant.value<AgendaEntry> ();
   192     
   204 
   193 //1. get 'virtual' event position from DayInfo
   205     // 1. Get 'virtual' event position from DayInfo
   194 //TODO: k.g.: Day Info should store model index instead of keeping redundant data
       
   195     SCalenApptInfo apptInfo;
   206     SCalenApptInfo apptInfo;
   196     apptInfo.iIndex = index;
   207     apptInfo.iIndex = index;
   197     
   208 
   198     QDateTime start;
   209     QDateTime start;
   199     QDateTime end;
   210     QDateTime end;
   200     QDateTime currentDate;
   211     QDateTime currentDate;
   201     currentDate = static_cast<const CalenDayModel*>(index.model())->modelDate();
   212     currentDate
   202     CalenDayUtils::instance()->getEventValidStartEndTime( start, end, entry,
   213         = static_cast<const CalenDayModel*> (index.model())->modelDate();
   203                                                           currentDate );
   214     CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
       
   215         currentDate);
   204     apptInfo.iStartTime = start;
   216     apptInfo.iStartTime = start;
   205     apptInfo.iEndTime = end;
   217     apptInfo.iEndTime = end;
   206     
   218 
   207     TCalenInstanceId id = TCalenInstanceId::nullInstanceId();
   219     TCalenInstanceId id = TCalenInstanceId::nullInstanceId();
   208     id.mEntryLocalUid = index.row(); //index.row() - temporary ID
   220     id.mEntryLocalUid = index.row(); //index.row() - temporary ID
   209     id.mInstanceTime = apptInfo.iStartTime; 
   221     id.mInstanceTime = apptInfo.iStartTime;
   210     apptInfo.iId = id;
   222     apptInfo.iId = id;
   211     apptInfo.iAllDay = 0;
   223     apptInfo.iAllDay = 0;
   212     apptInfo.iColor = 0xffff;
   224     apptInfo.iColor = 0xffff;
   213     
   225 
   214     int startSlot, endSlot, columnIdx, columns;
   226     int startSlot, endSlot, columnIdx, columns;
   215     mInfo->GetLocation( apptInfo, startSlot, endSlot, columnIdx, columns );
   227     mInfo->GetLocation(apptInfo, startSlot, endSlot, columnIdx, columns);
   216     
   228 
   217 
   229     // 2. Set timed event's geometry
   218 //2. set timed event's geometry
   230     qreal eventStartX(mLayoutValues.eventAreaX);
   219     qreal eventStartX(mLayoutValues.eventAreaX );
       
   220     qreal eventStartY(0.0);
   231     qreal eventStartY(0.0);
   221     qreal eventWidth(mLayoutValues.eventAreaWidth);
   232     qreal eventWidth(mLayoutValues.eventAreaWidth);
   222     qreal eventHeight(0.0);
   233     qreal eventHeight(0.0);
   223        
   234 
   224     //event's startY/height
   235     // Event's startY/height
   225     eventStartY = startSlot * mLayoutValues.slotHeight;
   236     eventStartY = startSlot * mLayoutValues.slotHeight;
   226     eventHeight = (endSlot - startSlot) * mLayoutValues.slotHeight;
   237     eventHeight = (endSlot - startSlot) * mLayoutValues.slotHeight;
   227 
   238 
   228     //event's startX/width
   239     // Event's startX/width
   229     eventWidth /= columns;
   240     eventWidth /= columns;
   230     
   241 
   231     //In case when eventWidth will be smaller then 3.0un we need to 
   242     // In case when eventWidth will be smaller then KCalenMinBubbleWidth [un]
   232     //make spacings between events smaller.
   243     // spacings between events should be smaller.
   233     //Check whether it's possible to shring them so the bubbles 
   244     // Check whether it's possible to shrink them so the bubbles width 
   234     //width can stay at 3.0un (time stripe + frame margins).
   245     // can stay at KCalenMinBubbleWidth [un] (time stripe + frame margins).
   235     qreal minWidth = 3.0 * mLayoutValues.unitInPixels; 
   246     qreal minWidth = KCalenMinBubbleWidth * mLayoutValues.unitInPixels;
   236     if(eventWidth - mLayoutValues.eventMargin < minWidth){
   247     if (eventWidth - mLayoutValues.eventMargin < minWidth) {
   237         
   248 
   238         //Calculate new margin value
   249         // Calculate new margin value
   239         //from totalMarginSpace we need to subtract 
   250         // from totalMarginSpace we need to subtract 
   240         //mLayoutValues.eventMargin because first margin is always 1.5un
   251         // mLayoutValues.eventMargin because first margin is always 1.5un
   241         qreal totalMarginSpace =  mLayoutValues.eventAreaWidth - minWidth * columns - mLayoutValues.eventMargin;
   252         qreal totalMarginSpace = mLayoutValues.eventAreaWidth - minWidth
       
   253             * columns - mLayoutValues.eventMargin;
   242         qreal newMarginValue = totalMarginSpace / (columns - 1);
   254         qreal newMarginValue = totalMarginSpace / (columns - 1);
   243         
   255 
   244         //check if we managed to pack all the events into space we have
   256         // Check if we managed to pack all the events into space we have
   245         if(newMarginValue > 0){
   257         if (newMarginValue > 0) {
   246             
       
   247             eventWidth = minWidth;
   258             eventWidth = minWidth;
   248         }
   259         }
   249         else{
   260         else {
   250             //there's not enough space
   261             // There's not enough space
   251             //new minWidth it's 1.5un (time stripe only)
   262             // New minWidth is KCalenTimeStripWidth [un] (time stripe only)
   252             minWidth = 1.5 * mLayoutValues.unitInPixels; 
   263             minWidth = KCalenTimeStripWidth * mLayoutValues.unitInPixels;
   253             totalMarginSpace =  mLayoutValues.eventAreaWidth - minWidth * columns - mLayoutValues.eventMargin;
   264             totalMarginSpace = mLayoutValues.eventAreaWidth - minWidth * columns 
       
   265 				- mLayoutValues.eventMargin;
   254             newMarginValue = totalMarginSpace / (columns - 1);
   266             newMarginValue = totalMarginSpace / (columns - 1);
   255             eventWidth = minWidth;
   267             eventWidth = minWidth;
   256         }
   268         }
   257         
   269         
   258         //First column margin should be always 1.5un (mLayoutValues.eventMargin)
   270         //First column margin should be always 1.5un (mLayoutValues.eventMargin)
   259         eventStartX += columnIdx * (eventWidth + newMarginValue) + mLayoutValues.eventMargin;
   271         eventStartX += columnIdx * (eventWidth + newMarginValue) + mLayoutValues.eventMargin;
   260     }
   272     }
   261     else{
   273     else {
   262         //add margins between the event
   274         // Add margins between the event
   263         eventStartX += columnIdx * eventWidth + mLayoutValues.eventMargin;
   275         eventStartX += columnIdx * eventWidth + mLayoutValues.eventMargin;
   264         eventWidth -= mLayoutValues.eventMargin;
   276         eventWidth -= mLayoutValues.eventMargin;
   265     }
   277     }
   266     
   278 
   267     QRectF eventGeometry( eventStartX, eventStartY, eventWidth, eventHeight );
   279     QRectF eventGeometry(eventStartX, eventStartY, eventWidth, eventHeight);
   268     item->setGeometry(eventGeometry);
   280     item->setGeometry(eventGeometry);
   269 }
   281 }
   270 
   282 
   271 
   283 
   272 // TODO: updateTimedEventGeometry and updateAllDayEventGeometry
   284 /*!
   273 // methods are very similar and probably can be merged to avoid
   285  \brief Set size and position of singe all-day event widget (bubble)
   274 // code duplication
   286  \a item bubble widget
   275 /*!
   287  \a index pointing item data in model
   276 	\brief Set size and position of singe all-day event widget (bubble)
   288  */
   277 	\a item bubble widget
   289 void CalenDayContainer::updateAllDayEventGeometry(
   278 	\a index pointing item data in model
   290     HbAbstractViewItem *item,
   279  */
   291     const QModelIndex &index)
   280 void CalenDayContainer::updateAllDayEventGeometry(HbAbstractViewItem *item, 
   292 {
   281                                                    const QModelIndex &index)
   293     // Safety check
   282 {
   294     if (!mInfo) {
   283 	//safety check
   295         return;
   284 	if ( !mInfo ) {
   296     }
   285 	      return;
   297 
   286 	}
   298     QVariant variant = index.data(CalenDayEntry);
   287 	    
   299     AgendaEntry entry = variant.value<AgendaEntry> ();
   288 	QVariant variant = index.data( CalenDayEntry );
   300 
   289 	AgendaEntry entry = variant.value<AgendaEntry>();
   301     // 1. Get 'virtual' event position from DayInfo 
   290 	    
   302     SCalenApptInfo apptInfo;
   291 	//1. get 'virtual' event position from DayInfo
   303     apptInfo.iIndex = index;
   292 	//TODO: k.g.: Day Info should store model index instead of keeping redundant data    
   304 
   293 	SCalenApptInfo apptInfo;
   305     QDateTime start;
   294 	apptInfo.iIndex = index;
       
   295 	
       
   296 	
       
   297 	QDateTime start;
       
   298     QDateTime end;
   306     QDateTime end;
   299     QDateTime currentDate;
   307     QDateTime currentDate;
   300     currentDate = static_cast<const CalenDayModel*>(index.model())->modelDate();
   308     currentDate
   301     CalenDayUtils::instance()->getEventValidStartEndTime( start, end, entry,
   309         = static_cast<const CalenDayModel*> (index.model())->modelDate();
   302                                                           currentDate );
   310     CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
       
   311         currentDate);
   303     apptInfo.iStartTime = start;
   312     apptInfo.iStartTime = start;
   304     apptInfo.iEndTime = end;
   313     apptInfo.iEndTime = end;
   305 	
   314 
   306 	TCalenInstanceId id = TCalenInstanceId::nullInstanceId();
   315     TCalenInstanceId id = TCalenInstanceId::nullInstanceId();
   307 	id.mEntryLocalUid = index.row(); //index.row() - temporary ID
   316     id.mEntryLocalUid = index.row(); //index.row() - temporary ID
   308 	id.mInstanceTime = apptInfo.iStartTime; 
   317     id.mInstanceTime = apptInfo.iStartTime;
   309 	apptInfo.iId = id;
   318     apptInfo.iId = id;
   310 	apptInfo.iAllDay = true;
   319     apptInfo.iAllDay = true;
   311 	apptInfo.iColor = 0xffff;
   320     apptInfo.iColor = 0xffff;
   312 	
   321 
   313 	int startSlot, endSlot, columnIdx, columns;
   322     int startSlot, endSlot, columnIdx, columns;
   314 	mInfo->GetLocation( apptInfo, startSlot, endSlot, columnIdx, columns );
   323     mInfo->GetLocation(apptInfo, startSlot, endSlot, columnIdx, columns);
   315 	
   324 
   316 	//2. set timed event's geometry
   325     // 2. Set timed event's geometry
   317 	qreal eventStartX(0.0);
   326     qreal eventStartX(0.0);
   318 	qreal eventStartY(0.0);
   327     qreal eventStartY(0.0);
   319 	qreal eventWidth(mLayoutValues.eventAreaX);
   328     qreal eventWidth(mLayoutValues.eventAreaX);
   320 	qreal eventHeight = (endSlot - startSlot) * mLayoutValues.slotHeight;
   329     qreal eventHeight = (endSlot - startSlot) * mLayoutValues.slotHeight;
   321 
   330 
   322 	
   331     // Event's startX/width
   323 	//event's startX/width
   332     if (columns > 1) {
   324 	if ( columns > 1 ) {
   333         eventWidth /= columns;
   325 		eventWidth /= columns;
   334         eventStartX += columnIdx * eventWidth + mLayoutValues.eventMargin;
   326 		eventStartX += columnIdx * eventWidth + mLayoutValues.eventMargin;
   335         // Add margins between the event
   327 		//add margins between the event
   336         eventWidth -= mLayoutValues.eventMargin;
   328 		eventWidth -= mLayoutValues.eventMargin;
   337     }
   329 	} else {
   338     else {
   330 		eventStartX += mLayoutValues.eventMargin;
   339         eventStartX += mLayoutValues.eventMargin;
   331 		eventWidth -= mLayoutValues.eventMargin;
   340         eventWidth -= mLayoutValues.eventMargin;
   332 	}
   341     }
   333 	
   342 
   334 	QRectF eventGeometry( eventStartX, eventStartY, eventWidth, eventHeight );
   343     QRectF eventGeometry(eventStartX, eventStartY, eventWidth, eventHeight);
   335 	item->setGeometry(eventGeometry);
   344     item->setGeometry(eventGeometry);
   336 	    
   345 }
   337 }
   346 
   338 
   347 
   339 
   348 /*!
   340 /*!
   349  \brief Gets event layout values
   341 	\brief Gets event layout values
   350  \a layoutValues structure to be filled with layout data
   342 	\a layoutValues structure to be filled with layout data
       
   343  */
   351  */
   344 void CalenDayContainer::getTimedEventLayoutValues(LayoutValues& layoutValues)
   352 void CalenDayContainer::getTimedEventLayoutValues(LayoutValues& layoutValues)
   345 {
   353 {
   346     // get the width of content area
   354     // Get the width of content area
   347     qreal contentWidth = CalenDayUtils::instance()->contentWidth();
   355     qreal contentWidth = CalenDayUtils::instance()->contentWidth();
   348 //1.time column width -> eventAreaX[out]
   356 
       
   357     // 1. Time column width -> eventAreaX[out]
   349     HbStyle style;
   358     HbStyle style;
   350     HbDeviceProfile deviceProfile;
   359     HbDeviceProfile deviceProfile;
   351     layoutValues.unitInPixels = deviceProfile.unitValue();
   360     layoutValues.unitInPixels = deviceProfile.unitValue();
   352     
   361 
   353     if ( mInfo && mInfo->AlldayCount())
   362     if (mInfo && mInfo->AlldayCount()) {
   354     	{
   363         layoutValues.eventAreaX = KCalenAllDayEventArea * contentWidth;
   355     	// adccoriding to ui spec all-day event area should take
   364     }
   356 		// 1/4 of content area
   365     else {
   357     	layoutValues.eventAreaX = contentWidth / 4;
   366         layoutValues.eventAreaX = 0;
   358     	}
   367     }
   359     else
   368 
   360     	{
   369     // 2. event area width -> eventAreaWidth[out]
   361     	layoutValues.eventAreaX = 0;
       
   362     	}
       
   363     
       
   364 //2. event area width -> eventAreaWidth[out]
       
   365     qreal emptyRightColumnWidth(0.0);
   370     qreal emptyRightColumnWidth(0.0);
   366     emptyRightColumnWidth = 6.0 * layoutValues.unitInPixels; //pix (according to UI spec)
   371     emptyRightColumnWidth = KCalenEmptyRightColumnWidth
   367     layoutValues.eventAreaWidth = contentWidth - emptyRightColumnWidth - layoutValues.eventAreaX ;
   372         * layoutValues.unitInPixels;
   368 //3. margins between the overlapping events -> eventMargin[out]
   373     layoutValues.eventAreaWidth = contentWidth - emptyRightColumnWidth
   369     layoutValues.eventMargin = 1.5 * layoutValues.unitInPixels;
   374         - layoutValues.eventAreaX;
   370 //4. half-hour slot'h height -> slotHeight[out]
   375 
   371     //curent slot height corresponds to half an hour
   376     // 3. margins between the overlapping events -> eventMargin[out]
   372     layoutValues.slotHeight = 
   377     layoutValues.eventMargin = KCalenSpaceBeetwenEvents
   373         CalenDayUtils::instance()->hourElementHeight() / 2;
   378         * layoutValues.unitInPixels;
   374     
   379 
   375     // 8.2 un (min. touchable event) from layout guide
   380     // 4. half-hour slot'h height -> slotHeight[out]
   376     // used to check should we create absorber over some overlapping region
   381     layoutValues.slotHeight = CalenDayUtils::instance()->hourElementHeight()
   377     layoutValues.maxColumns = layoutValues.eventAreaWidth / (8.2 * layoutValues.unitInPixels);  
   382         / KCalenSlotsInHour;
   378 }
   383 
   379 
   384     // check if we should create absorber over some overlapping region
   380 
   385     layoutValues.maxColumns = layoutValues.eventAreaWidth
   381 /*!
   386         / (KCalenMinTouchableEventWidth * layoutValues.unitInPixels);
   382 	\brief Sets day's info structer to the container.
   387 }
   383 	\a dayInfo day's info data
   388 
   384  */
   389 
   385 void CalenDayContainer::setDayInfo( CalenDayInfo* dayInfo )
   390 /*!
       
   391  \brief Sets day's info structure to the container.
       
   392  \a dayInfo day's info data
       
   393 
       
   394  \sa CalenDayInfo, CalenDayContainer::dayInfo
       
   395  */
       
   396 void CalenDayContainer::setDayInfo(CalenDayInfo* dayInfo)
   386 {
   397 {
   387     mInfo = dayInfo;
   398     mInfo = dayInfo;
   388 }
   399 }
   389 
   400 
   390 // -----------------------------------------------------------------------------
   401 /*!
   391 // setDate()
   402  \brief It return pointer to info structure of container.
   392 // Sets date to the container. Changes according to model which is connected to given view.
   403  
   393 // -----------------------------------------------------------------------------
   404  \sa CalenDayInfo, CalenDayContainer::setDayInfo
   394 //
   405  */
       
   406 CalenDayInfo* CalenDayContainer::dayInfo()
       
   407 {
       
   408     return mInfo;
       
   409 }
       
   410 
       
   411 /*!
       
   412  \brief Sets date to the container. 
       
   413  Changes according to model which is connected to given view.
       
   414  
       
   415  \a date Date of container
       
   416  */
   395 void CalenDayContainer::setDate(const QDate &date)
   417 void CalenDayContainer::setDate(const QDate &date)
   396 {
   418 {
   397     mDate = date;
   419     mDate = date;
   398 }
   420 }
   399 
   421 
   400 // -----------------------------------------------------------------------------
   422 // -----------------------------------------------------------------------------
   401 // date()
   423 // date()
   402 // Returns date of the container.
   424 // Returns date of the container.
   403 // -----------------------------------------------------------------------------
   425 // -----------------------------------------------------------------------------
   404 //
   426 //
       
   427 /*!
       
   428  \brief Returns date of the container.
       
   429  
       
   430  \sa date Date of container
       
   431  */
   405 const QDate &CalenDayContainer::date() const
   432 const QDate &CalenDayContainer::date() const
   406 {
   433 {
   407     return mDate;
   434     return mDate;
   408 }
   435 }
   409 
   436 
   410 /*!
   437 /*!
   411 	\brief Slot handles layout switch.
   438  \brief Slot handles layout switch.
   412 	\a orientation current device orientation
   439  \a orientation current device orientation
   413  */
   440  */
   414 void CalenDayContainer::orientationChanged(Qt::Orientation orientation)
   441 void CalenDayContainer::orientationChanged(Qt::Orientation orientation)
   415 {
   442 {
   416 	getTimedEventLayoutValues(mLayoutValues);
   443     getTimedEventLayoutValues(mLayoutValues);
   417 	
   444 
   418     Q_UNUSED( orientation )
   445     Q_UNUSED( orientation )
   419     QList<HbAbstractViewItem *> items = this->items();
   446     QList<HbAbstractViewItem *> items = this->items();
   420     int count(items.count());
   447     int count(items.count());
   421     for (int i = 0; i < count; i++) {
   448     for (int i = 0; i < count; i++) {
   422         QModelIndex modelIndex = items[i]->modelIndex();
   449         QModelIndex modelIndex = items[i]->modelIndex();
   423         if (modelIndex.isValid()) {
   450         if (modelIndex.isValid()) {
   424             QVariant variant = modelIndex.data(CalenDayEntry);
   451             QVariant variant = modelIndex.data(CalenDayEntry);
   425             AgendaEntry entry = variant.value<AgendaEntry> ();
   452             AgendaEntry entry = variant.value<AgendaEntry> ();
   426             if (entry.isTimedEntry()) {
   453             if (entry.isTimedEntry() && !CalenAgendaUtils::isAlldayEvent(entry)) {
   427                 updateTimedEventGeometry(items[i], modelIndex);
   454                 updateTimedEventGeometry(items[i], modelIndex);
   428             }
   455             }
   429         }
   456             else
   430     }
   457                 if (CalenAgendaUtils::isAlldayEvent(entry)) {
   431     
   458                     updateAllDayEventGeometry(items[i], modelIndex);
       
   459                 }
       
   460         }
       
   461     }
       
   462 
   432     createTouchEventAbsorbers();
   463     createTouchEventAbsorbers();
   433 }
   464 }
   434 
   465 
   435 
   466 
   436 /*!
   467 /*!
   437 	\brief Creates absorbers which prevent touching to small items
   468  \brief Creates absorbers which prevent touching to small items
   438 	According to UI spec items smaller than 8.2 un are untouchable
   469  According to UI spec items smaller than 8.2 un are untouchable
   439  */
   470  */
   440 void CalenDayContainer::createTouchEventAbsorbers()
   471 void CalenDayContainer::createTouchEventAbsorbers()
   441 {
   472 {
   442 	// remove absorbers if exist
   473     // remove absorbers if exist
   443 	if (mAbsorbers.count())
   474     if (mAbsorbers.count()) {
   444 		{
   475         qDeleteAll(mAbsorbers);
   445 		qDeleteAll(mAbsorbers);
   476         mAbsorbers.clear();
   446 		mAbsorbers.clear();
   477     }
   447 		}
   478 
   448 	
   479     // Create absorber for all-day events
   449 	//create absorber for all-day events
   480     Qt::Orientation orientation = CalenDayUtils::instance()->orientation();
   450 	Qt::Orientation orientation = CalenDayUtils::instance()->orientation();
   481     int allDayCount = mInfo->AlldayCount();
   451 	int allDayCount = mInfo->AlldayCount();
   482 
   452 	
   483     if ((orientation == Qt::Vertical 
   453 	if ((orientation == Qt::Vertical && allDayCount > 1) ||
   484         && allDayCount > KCalenTouchableAllDayEventsCountPortrait) 
   454 			(orientation == Qt::Horizontal && allDayCount > 2))
   485         || (orientation == Qt::Horizontal
   455 		{
   486         && allDayCount > KCalenTouchableAllDayEventsCountLandscape)) {
   456 		TouchEventAbsorber* absorber = crateAbsorberBetweenSlots(0, 0, true);
   487         TouchEventAbsorber* absorber = crateAbsorberBetweenSlots(0, 0, true);
   457 		mAbsorbers.append(absorber);
   488         mAbsorbers.append(absorber);
   458 		}
   489     }
   459 	
   490 
   460 	
   491     // Create absorbers for timed events
   461 	// create absorbers for timed events
   492     const QList<CalenTimeRegion>& regionList = mInfo->RegionList();
   462 	const QList<CalenTimeRegion>& regionList = mInfo->RegionList();
   493     for (int i = 0; i < regionList.count(); i++) {
   463 	
   494         if (regionList[i].iColumns.count() > mLayoutValues.maxColumns) {
   464 	for(int i=0; i < regionList.count(); i++)
   495             TouchEventAbsorber* absorber = crateAbsorberBetweenSlots(
   465 		{
   496                 regionList[i].iStartSlot, regionList[i].iEndSlot, false);
   466 		if(regionList[i].iColumns.count() > mLayoutValues.maxColumns )
   497 
   467 			{
   498             mAbsorbers.append(absorber);
   468 			TouchEventAbsorber* absorber = 
   499         }
   469 				crateAbsorberBetweenSlots(regionList[i].iStartSlot, regionList[i].iEndSlot, false);
   500     }
   470 			
   501 }
   471 			mAbsorbers.append(absorber);
   502 
   472 			}
   503 
   473 		}
   504 /*!
   474 	
   505  \brief Creates single absorber in given location
   475 }
   506  \a startSlot absorber area starts from there
   476 
   507  \a endSlot absobrber area ends here
   477 
   508  \a forAllDayEvents if true absorber in all-day events area is created
   478 /*!
   509  */
   479 	\brief Creates single absorber in given location
   510 TouchEventAbsorber *CalenDayContainer::crateAbsorberBetweenSlots(
   480 	\a startSlot absorber area starts from there
   511     int startSlot,
   481 	\a endSlot absobrber area ends here
   512     int endSlot,
   482 	\a forAllDayEvents if true absorber in all-day events area is created
   513     bool forAllDayEvents)
   483  */
       
   484 TouchEventAbsorber *CalenDayContainer::crateAbsorberBetweenSlots
       
   485 												(int startSlot, int endSlot, bool forAllDayEvents)
       
   486 {
   514 {
   487     TouchEventAbsorber *absorber = new TouchEventAbsorber(this);
   515     TouchEventAbsorber *absorber = new TouchEventAbsorber(this);
   488     absorber->setZValue(1000);
   516     absorber->setZValue(1000);
   489     absorber->setVisible(true);
   517     absorber->setVisible(true);
   490     if (!forAllDayEvents)
   518     if (!forAllDayEvents) {
   491     	{
   519         absorber->setGeometry(mLayoutValues.eventAreaX, // x
   492 		absorber->setGeometry( mLayoutValues.eventAreaX,			// x
   520             startSlot * mLayoutValues.slotHeight, // y
   493 				startSlot * mLayoutValues.slotHeight,				// y
   521             mLayoutValues.eventAreaWidth, // w
   494 				mLayoutValues.eventAreaWidth,						// w
   522             (endSlot - startSlot) * mLayoutValues.slotHeight); // h
   495 				(endSlot-startSlot) * mLayoutValues.slotHeight ); 	// h
   523     }
   496     	}
   524     else {
   497     else
   525         absorber->setGeometry(0, 0, mLayoutValues.eventAreaX,
   498     	{
   526             KCalenHoursInDay * KCalenSlotsInHour * mLayoutValues.slotHeight);
   499     	absorber->setGeometry(0, 0, mLayoutValues.eventAreaX,
   527     }
   500     			48 * mLayoutValues.slotHeight);
   528 
   501     	}
       
   502     
       
   503     return absorber;
   529     return absorber;
   504 }
   530 }
   505 
   531 
   506 
   532 
   507 /*!
   533 /*!
   508 	\brief Handles tap event on overlapping area
   534  \brief Handles tap event on overlapping area
   509 	Currently it leads to Agenda View -  as described in UI spec
   535  Currently it leads to Agenda View -  as described in UI spec
   510 	\a event qt gesture event
   536  \a event qt gesture event
   511  */
   537  */
   512 void TouchEventAbsorber::gestureEvent(QGestureEvent *event)
   538 void TouchEventAbsorber::gestureEvent(QGestureEvent *event)
   513 {
   539 {
   514     QTapGesture *tapGesture = qobject_cast<QTapGesture*> (event->gesture(
   540     QTapGesture *tapGesture = qobject_cast<QTapGesture*> (event->gesture(
   515         Qt::TapGesture));
   541         Qt::TapGesture));
   516     
   542     
   517     if (tapGesture && tapGesture->state() == Qt::GestureFinished)
   543     if (tapGesture && tapGesture->state() == Qt::GestureFinished) {
   518     	{
       
   519     	CalenDayView* dayView = static_cast<CalenDayView*>
   544     	CalenDayView* dayView = static_cast<CalenDayView*>
   520                 (CalenDayUtils::instance()->mainWindow()->currentView());
   545                 (CalenDayUtils::instance()->mainWindow()->currentView());
   521     	
   546     	
   522     	dayView->changeView(ECalenAgendaView);
   547     	dayView->changeView(ECalenAgendaView);
   523     	}
   548     }
   524 }
   549 }
   525 
   550 
   526 /*!
   551 /*!
   527 	 \brief Constructor
   552  \brief Constructor
   528  */
   553  */
   529 TouchEventAbsorber::TouchEventAbsorber(QGraphicsItem *parent) : HbWidget(parent)
   554 TouchEventAbsorber::TouchEventAbsorber(QGraphicsItem *parent) :
       
   555     HbWidget(parent)
   530 {
   556 {
   531 #ifdef _DEBUG
   557 #ifdef _DEBUG
   532     setFlag(QGraphicsItem::ItemHasNoContents, false);
   558     setFlag(QGraphicsItem::ItemHasNoContents, false);
   533 #endif	
   559 #endif	
   534     grabGesture(Qt::TapGesture);    	    
   560     grabGesture(Qt::TapGesture);
   535 }
   561 }
   536 
   562 
   537 
   563 
   538 /*!
   564 /*!
   539  \brief Destructor
   565  \brief Destructor
   545 
   571 
   546 }
   572 }
   547 
   573 
   548 
   574 
   549 /*!
   575 /*!
   550 	\brief Used for debugging purposes to see absorbers areas
   576  \brief Used for debugging purposes to see absorbers areas
   551 	Not active in release builds!
   577  Not active in release builds!
   552  
   578  
   553  */
   579  */
   554 #ifdef _DEBUG
   580 #ifdef _DEBUG
   555 void TouchEventAbsorber::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
   581 void TouchEventAbsorber::paint(
   556 								QWidget *widget)
   582     QPainter *painter,
   557 {
   583     const QStyleOptionGraphicsItem *option,
   558 	Q_UNUSED(option)
   584     QWidget *widget)
   559 	Q_UNUSED(widget)
   585 {
   560 	
   586     Q_UNUSED(option)
   561 	painter->save();
   587     Q_UNUSED(widget)
   562 	QPen pen;
   588 
   563 	pen.setWidth(2);
   589     painter->save();
   564 	pen.setColor(Qt::red);
   590     QPen pen;
   565 	painter->setPen(pen);
   591     pen.setWidth(2);
   566 	painter->drawRect(boundingRect());
   592     pen.setColor(Qt::red);
   567 	painter->restore();
   593     painter->setPen(pen);
       
   594     painter->drawRect(boundingRect());
       
   595     painter->restore();
   568 }
   596 }
   569 #endif
   597 #endif
   570 // End of File
   598 // End of File