calendarui/views/dayview/src/calendayitem.cpp
changeset 68 a5a1242fd2e8
parent 58 ef813d54df51
equal deleted inserted replaced
58:ef813d54df51 68:a5a1242fd2e8
    14 * Description:  Event view item, exact size and position of event is set in 
    14 * Description:  Event view item, exact size and position of event is set in 
    15 *  				CalenDayContainer::setItemModelIndex based on event duration
    15 *  				CalenDayContainer::setItemModelIndex based on event duration
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 //System includes
    19 // System includes
    20 #include <hbframeitem.h>
    20 #include <HbFrameItem>
    21 #include <hbtextitem.h>
    21 #include <HbTextItem>
       
    22 #include <HbStyle>
       
    23 #include <HbColorScheme>
    22 #include <agendaentry.h>
    24 #include <agendaentry.h>
    23 #include <hbstyle.h>
    25 
    24 #include <hbcolorscheme.h>
    26 // User includes
    25 
    27 #include "calendaycommonheaders.h"
    26 
       
    27 //User inlcudes
       
    28 #include "calendayitem.h"
    28 #include "calendayitem.h"
    29 #include "calendaystatusstrip.h"
    29 #include "calendaystatusstrip.h"
    30 #include "calendaymodel.h"
    30 #include "calendaymodel.h"
    31 #include "calendayutils.h"
    31 #include "calendayutils.h"
    32 #include "calenagendautils.h"
    32 #include "calenagendautils.h"
    33 #include "calendaycontainer.h"
    33 #include "calendaycontainer.h"
    34 
    34 
    35 /*!
    35 /*!
    36    \brief Constructor.
    36  \brief Constructor.
    37 */
    37  */
    38 CalenDayItem::CalenDayItem(const CalenDayContainer *container):
    38 CalenDayItem::CalenDayItem(const CalenDayContainer *container) :
    39     mContainer(container), mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0), 
    39     mContainer(container), mUpdated(false), mBg(0), mEventDesc(0),
    40     mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
    40         mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
    41 {
    41 {
    42 }
    42 }
    43 
    43 
    44 /*!
    44 /*!
    45    \brief Constructor.
    45  \brief Constructor.
    46 */
    46  */
    47 CalenDayItem::CalenDayItem(const CalenDayItem & source) :
    47 CalenDayItem::CalenDayItem(const CalenDayItem & source) :
    48     HbAbstractViewItem(source), mContainer(source.container()), mUpdated(false), mBg(0), mEventDesc(0), 
    48     HbAbstractViewItem(source), mContainer(source.container()),
    49     mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
    49         mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0),
    50 {
    50         mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
    51     // TODO: "qtg_fr_btn_pressed" need to replaced with qtg_fr_cal_meeting_bg
    51 {
    52 	// when available
    52     mBg = new HbFrameItem("qtg_fr_cal_meeting_bg", HbFrameDrawer::NinePieces,
    53     mBg = new HbFrameItem("qtg_fr_btn_pressed", HbFrameDrawer::NinePieces, this);
    53         this);
    54     mEventDesc = new HbTextItem(this);
    54     mEventDesc = new HbTextItem(this);
    55     // TODO: probably ElideLeft needed for mirrored layout
    55     // TODO: probably ElideLeft needed for mirrored layout
    56     mEventDesc->setElideMode(Qt::ElideRight);
    56     mEventDesc->setElideMode(Qt::ElideRight);
    57     mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
    57     mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
    58     
       
    59     mColorStripe = new CalenDayStatusStrip(this);
    58     mColorStripe = new CalenDayStatusStrip(this);
    60     
    59 
    61     HbStyle::setItemName(mBg, QLatin1String("backgroundFrame"));
    60     HbStyle::setItemName(mBg, QLatin1String("backgroundFrame"));
    62     HbStyle::setItemName(mEventDesc, QLatin1String("eventDescription"));
    61     HbStyle::setItemName(mEventDesc, QLatin1String("eventDescription"));
    63     HbStyle::setItemName(static_cast<QGraphicsItem *>(mColorStripe), QLatin1String("colorStripe"));
    62     HbStyle::setItemName(static_cast<QGraphicsItem *> (mColorStripe),
       
    63         QLatin1String("colorStripe"));
       
    64 
       
    65     HbDeviceProfile deviceProfile;
       
    66     qreal stripeWidth = KCalenTimeStripWidth * deviceProfile.unitValue();
       
    67     mColorStripe->setPreferredWidth(stripeWidth);
       
    68 
       
    69     // Minimum size of event frame (without/with description) 
       
    70     mFrameMinWidth = KCalenMinEventWidth * deviceProfile.unitValue();
       
    71     mEventDescMinWidth = KCalenMinTouchableEventWidth
       
    72         * deviceProfile.unitValue();
    64     
    73     
    65     HbDeviceProfile deviceProfile;
    74     // Minimum width is assured by widgetml and css, additionally called here 
    66     HbStyle style;
    75     // to prevent minimum size hint caching inside effectiveSizeHint
    67     
       
    68     qreal horizontalSpacing = 0.0;
       
    69     qreal rightMargin = 0.0;
       
    70     
       
    71     style.parameter(QString("hb-param-margin-gene-middle-horizontal"), 
       
    72         horizontalSpacing, deviceProfile);
       
    73     style.parameter(QString("hb-param-margin-gene-right"), 
       
    74         rightMargin, deviceProfile); 
       
    75     
       
    76     qreal stripeWidth = 1.5 * deviceProfile.unitValue(); //1.5un according to UI spec
       
    77     
       
    78     mFrameMinWidth = 2 * horizontalSpacing + stripeWidth; //smallest width for which background frame is displayed
       
    79     mEventDescMinWidth = mFrameMinWidth + rightMargin;//smallest width for which text can be displayed
       
    80     
       
    81     //Minimum width is assured by widgetml and css
       
    82     //additionally called here to prevent minimum size hint caching inside effectiveSizeHint
       
    83     setMinimumWidth(stripeWidth);
    76     setMinimumWidth(stripeWidth);
    84 
    77 }
    85 }
    78 
    86 
    79 /*!
    87 /*!
    80  \brief Destructor.
    88    \brief Destructor.
    81  */
    89 */
       
    90 CalenDayItem::~CalenDayItem()
    82 CalenDayItem::~CalenDayItem()
    91 {
    83 {
    92 }
    84 }
    93 
    85 
    94 /*!
    86 /*!
    95    \brief Creates new instance of day item.
    87  \brief Creates new instance of day item.
    96    
    88  
    97    \return New instance of day item.
    89  \return New instance of day item.
    98 */
    90  */
    99 HbAbstractViewItem * CalenDayItem::createItem()
    91 HbAbstractViewItem * CalenDayItem::createItem()
   100 {
    92 {
   101     CalenDayItem* newItem = new CalenDayItem(*this);
    93     CalenDayItem* newItem = new CalenDayItem(*this);
   102     return newItem;
    94     return newItem;
   103 }
    95 }
   104 
    96 
   105 
    97 
   106 /*!
    98 /*!
   107    \brief Sets data to be displayed on item.
    99  \brief Sets data to be displayed on item.
   108 */
   100  */
   109 void CalenDayItem::updateChildItems()
   101 void CalenDayItem::updateChildItems()
   110 {
   102 {
   111     // there is no need to update items after creation
   103     // there is no need to update items after creation
   112     if (!mUpdated) {
   104     if (!mUpdated) {
   113         AgendaEntry entry;
   105         AgendaEntry entry;
   114         entry = modelIndex().data(CalenDayEntry).value<AgendaEntry>();
   106         entry = modelIndex().data(CalenDayEntry).value<AgendaEntry> ();
   115 
   107 
   116 		bool isAllDayEvent = CalenAgendaUtils::isAlldayEvent(entry); 
   108         bool isAllDayEvent = CalenAgendaUtils::isAlldayEvent(entry);
   117 
       
   118         setDescription(entry, isAllDayEvent);
   109         setDescription(entry, isAllDayEvent);
   119         setStatusStrip(entry, isAllDayEvent);
   110         setStatusStrip(entry, isAllDayEvent);
   120 
   111 
   121         mUpdated = true;
   112         mUpdated = true;
   122     }
   113     }
   123 
   114 }
   124     //TODO: check if needed
   115 
   125     //repolish(); 
   116 
   126     //HbAbstractViewItem::updateChildItems();
   117 /*!
   127 }
   118  \brief Adds event description for the item.
   128 
   119  
   129 
   120  \param entry An for which description needs to be displayed.
   130 /*!
   121  \param allDayEvent Flag that indicates whether an item is all day event
   131    \brief Adds event description for the item.
   122  */
   132    
       
   133    \param entry An for which description needs to be displayed.
       
   134    \param allDayEvent Flag that indicates whether an item is all day event
       
   135 */
       
   136 void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent)
   123 void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent)
   137 {
   124 {
   138 	QString description(entry.summary());
   125     QString description(entry.summary());
   139 	QString location(entry.location());
   126     QString location(entry.location());
   140 	
   127 
   141 	
   128     int separtorPos = 0;
   142 	int separtorPos = 0;
   129     if (!location.isEmpty()) {
   143 	
   130         if (!description.isEmpty()) {
   144 	if(!location.isEmpty()) {
   131             separtorPos = description.count();
   145 	    if ( !description.isEmpty() ) {
   132             description.append(", ");
   146 	    	separtorPos = description.count();
   133         }
   147 	    	description.append(", ");
   134         description.append(location);
   148 			}
   135     }
   149 	    
   136 
   150 		description.append(location);
   137     if (description.isEmpty()) {
   151 		}
   138         description.append(hbTrId("txt_calendar_dblist_unnamed"));
   152 	
   139     }
   153 	if ( description.isEmpty() ) {
   140 
   154 	    description.append(hbTrId("txt_calendar_dblist_unnamed"));
   141     //Description of all day events has to be displayed vertically
   155 	}
   142     if (allDayEvent) {
   156 	
   143         QString verticalString;
   157 	//Description of all day events has to be displayed vertically
   144         for (int i = 0; i < description.count(); i++) {
   158 	if(allDayEvent){
   145             verticalString.append(QString(description.at(i)) + "\n");
   159 
   146         }
   160 	    QString verticalString;
   147 
   161 	    for(int i=0; i<description.count(); i++){
   148         // remove "\n" before comma separator if exist
   162 	    
   149         if (separtorPos) {
   163 	        verticalString.append(QString(description.at(i)) + "\n");
   150             verticalString.remove(2 * separtorPos - 1, 1);
   164 	    }
   151         }
   165 	
   152         description = verticalString;
   166 	    // remove "\n" before comma separator if exist
   153     }
   167 	    if (separtorPos)
   154 
   168 	    	{
   155     mEventDesc->setText(description);
   169 	    	verticalString.remove( 2*separtorPos-1, 1);
   156 }
   170 	    	}
   157 
   171 	    description = verticalString;
   158 /*!
   172 	}	
   159  \brief It set all needed things for status strip from Agenda Entry.
   173 	
   160  
   174 	mEventDesc->setText(description);
   161  \param entry Status Strip is created from Agenda Entry
   175 }
   162  */
   176 
       
   177 /*!
       
   178    \brief It set all needed things for status strip from Agenda Entry.
       
   179    
       
   180    \param entry Status Strip is created from Agenda Entry
       
   181 */
       
   182 void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent)
   163 void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent)
   183 {
   164 {
   184     QColor color = HbColorScheme::color("qtc_cal_month_current_day");
       
   185     mColorStripe->setColor(color);
       
   186     
       
   187     if (!allDayEvent) {
   165     if (!allDayEvent) {
   188 
   166 
   189         QDateTime startTime;
   167         QDateTime startTime;
   190         QDateTime endTime;
   168         QDateTime endTime;
   191         QDateTime currentDateTime;
   169         QDateTime currentDateTime;
   192         currentDateTime.setDate(container()->date());
   170         currentDateTime.setDate(container()->date());
   193 
   171 
   194         CalenDayUtils::instance()->getEventValidStartEndTime(startTime, endTime, entry,
   172         CalenDayUtils::instance()->getEventValidStartEndTime(startTime,
   195             currentDateTime);
   173             endTime, entry, currentDateTime);
   196 
   174 
   197         mColorStripe->setStartEndTime(startTime.time(), endTime.time());
   175         mColorStripe->setStartEndTime(startTime.time(), endTime.time());
   198     }
   176     }
   199     else {
   177     else {
   200         // This is workaround for displaying all-day events.
   178         // This is workaround for displaying all-day events.
   201         // Now for MS Outlook compability all-day events' start and end time is
   179         // Now for MS Outlook compability all-day events' start and end time is
   202         // 00:00:00 and 00:00:00 next day respectively.
   180         // 00:00:00 and 00:00:00 next day respectively.
   203         // To draw it correctly we need times like those visible for user in
   181         // To draw it correctly we need times like those visible for user in
   204         // editor: 00:00:00 to 23:59:59 (the same day)
   182         // editor: 00:00:00 to 23:59:59 (the same day)
   205         mColorStripe->setStartEndTime(entry.startTime().time(), entry.endTime().time().addSecs(-1));
   183         mColorStripe->setStartEndTime(entry.startTime().time(),
   206     }
   184             entry.endTime().time().addSecs(-1));
   207     
   185     }
       
   186 
   208     switch (entry.status()) {
   187     switch (entry.status()) {
   209         case AgendaEntry::Confirmed:
   188         case AgendaEntry::Confirmed:
   210             mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
   189             mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
   211         break;
   190             break;
   212         case AgendaEntry::Tentative:
   191         case AgendaEntry::Tentative:
   213             mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines);
   192             mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines);
   214         break;
   193             break;
   215         case AgendaEntry::Cancelled:
   194         case AgendaEntry::Cancelled:
   216             mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame);
   195             mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame);
   217         break;
   196             break;
   218         default:
   197         default:
   219             mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
   198             mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
   220         break;
   199             break;
   221     }
   200     }
   222 }
   201 }
   223 
   202 
   224 /*!
   203 /*!
   225    \brief Reimplemented from HbWidget. Handles resize event.
   204  \brief Reimplemented from HbWidget. Handles resize event.
   226    
   205  
   227    \param event Instance of an event to be handled.
   206  \param event Instance of an event to be handled.
   228 */
   207  */
   229 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
   208 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
   230 {
   209 {
   231     Q_UNUSED(event)
   210     Q_UNUSED(event)
   232 
   211 
   233     qreal width = rect().width();
   212     qreal width = rect().width();
   234 
   213 
   235     if(width < mEventDescMinWidth){
   214     HbDeviceProfile deviceProfile;
       
   215     if (width < mEventDescMinWidth) {
       
   216         mColorStripe->setPreferredWidth(KCalenMinTimeStripWidth
       
   217             * deviceProfile.unitValue());
   236         mEventDesc->hide();
   218         mEventDesc->hide();
   237     } else{
   219     }
       
   220     else {
       
   221         mColorStripe->setPreferredWidth(KCalenTimeStripWidth
       
   222             * deviceProfile.unitValue());
   238         mEventDesc->show();
   223         mEventDesc->show();
   239     }
   224     }
   240         
   225 
   241     if(width < mFrameMinWidth){
   226     if (width < mFrameMinWidth) {
   242         mBg->hide();
   227         mBg->hide();
   243     } else{
   228     }
       
   229     else {
   244         mBg->show();
   230         mBg->show();
   245     }
   231     }
   246 
   232 
   247     //Necessary to switch layout
   233     // Necessary to switch layout
   248     repolish();
   234     repolish();
   249 }
   235 }
   250 
   236 
   251 // End of File
   237 // End of File