calendarui/views/dayview/src/calendayitem.cpp
changeset 63 a3cb48f6c889
parent 57 bb2d3e476f29
child 64 1881ad52dc45
--- a/calendarui/views/dayview/src/calendayitem.cpp	Mon Aug 09 18:30:52 2010 +0530
+++ b/calendarui/views/dayview/src/calendayitem.cpp	Wed Aug 25 14:02:13 2010 +0530
@@ -16,15 +16,15 @@
 *
 */
 
-//System includes
-#include <hbframeitem.h>
-#include <hbtextitem.h>
+// System includes
+#include <HbFrameItem>
+#include <HbTextItem>
+#include <HbStyle>
+#include <HbColorScheme>
 #include <agendaentry.h>
-#include <hbstyle.h>
-#include <hbcolorscheme.h>
 
-
-//User inlcudes
+// User includes
+#include "calendaycommonheaders.h"
 #include "calendayitem.h"
 #include "calendaystatusstrip.h"
 #include "calendaymodel.h"
@@ -33,69 +33,61 @@
 #include "calendaycontainer.h"
 
 /*!
-   \brief Constructor.
-*/
-CalenDayItem::CalenDayItem(const CalenDayContainer *container):
-    mContainer(container), mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0), 
-    mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
+ \brief Constructor.
+ */
+CalenDayItem::CalenDayItem(const CalenDayContainer *container) :
+    mContainer(container), mUpdated(false), mBg(0), mEventDesc(0),
+        mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
 {
 }
 
 /*!
-   \brief Constructor.
-*/
+ \brief Constructor.
+ */
 CalenDayItem::CalenDayItem(const CalenDayItem & source) :
-    HbAbstractViewItem(source), mContainer(source.container()), mUpdated(false), mBg(0), mEventDesc(0), 
-    mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
+    HbAbstractViewItem(source), mContainer(source.container()),
+        mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0),
+        mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
 {
-    // TODO: "qtg_fr_btn_pressed" need to replaced with qtg_fr_cal_meeting_bg
-	// when available
-    mBg = new HbFrameItem("qtg_fr_btn_pressed", HbFrameDrawer::NinePieces, this);
+    mBg = new HbFrameItem("qtg_fr_cal_meeting_bg", HbFrameDrawer::NinePieces,
+        this);
     mEventDesc = new HbTextItem(this);
     // TODO: probably ElideLeft needed for mirrored layout
     mEventDesc->setElideMode(Qt::ElideRight);
     mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
-    
     mColorStripe = new CalenDayStatusStrip(this);
-    
+
     HbStyle::setItemName(mBg, QLatin1String("backgroundFrame"));
     HbStyle::setItemName(mEventDesc, QLatin1String("eventDescription"));
-    HbStyle::setItemName(static_cast<QGraphicsItem *>(mColorStripe), QLatin1String("colorStripe"));
-    
+    HbStyle::setItemName(static_cast<QGraphicsItem *> (mColorStripe),
+        QLatin1String("colorStripe"));
+
     HbDeviceProfile deviceProfile;
-    HbStyle style;
-    
-    qreal horizontalSpacing = 0.0;
-    qreal rightMargin = 0.0;
-    
-    style.parameter(QString("hb-param-margin-gene-middle-horizontal"), 
-        horizontalSpacing, deviceProfile);
-    style.parameter(QString("hb-param-margin-gene-right"), 
-        rightMargin, deviceProfile); 
-    
-    qreal stripeWidth = 1.5 * deviceProfile.unitValue(); //1.5un according to UI spec
-    
-    mFrameMinWidth = 2 * horizontalSpacing + stripeWidth; //smallest width for which background frame is displayed
-    mEventDescMinWidth = mFrameMinWidth + rightMargin;//smallest width for which text can be displayed
-    
-    //Minimum width is assured by widgetml and css
-    //additionally called here to prevent minimum size hint caching inside effectiveSizeHint
+    qreal stripeWidth = KCalenTimeStripWidth * deviceProfile.unitValue();
+    mColorStripe->setPreferredWidth(stripeWidth);
+
+    // Minimum size of event frame (without/with description) 
+    mFrameMinWidth = KCalenMinEventWidth * deviceProfile.unitValue();
+    mEventDescMinWidth = KCalenMinTouchableEventWidth
+        * deviceProfile.unitValue();
+
+    // Minimum width is assured by widgetml and css, additionally called here 
+    // to prevent minimum size hint caching inside effectiveSizeHint
     setMinimumWidth(stripeWidth);
-
 }
 
 /*!
-   \brief Destructor.
-*/
+ \brief Destructor.
+ */
 CalenDayItem::~CalenDayItem()
 {
 }
 
 /*!
-   \brief Creates new instance of day item.
-   
-   \return New instance of day item.
-*/
+ \brief Creates new instance of day item.
+ 
+ \return New instance of day item.
+ */
 HbAbstractViewItem * CalenDayItem::createItem()
 {
     CalenDayItem* newItem = new CalenDayItem(*this);
@@ -104,17 +96,16 @@
 
 
 /*!
-   \brief Sets data to be displayed on item.
-*/
+ \brief Sets data to be displayed on item.
+ */
 void CalenDayItem::updateChildItems()
 {
     // there is no need to update items after creation
     if (!mUpdated) {
         AgendaEntry entry;
-        entry = modelIndex().data(CalenDayEntry).value<AgendaEntry>();
+        entry = modelIndex().data(CalenDayEntry).value<AgendaEntry> ();
 
-		bool isAllDayEvent = CalenAgendaUtils::isAlldayEvent(entry); 
-
+        bool isAllDayEvent = CalenAgendaUtils::isAlldayEvent(entry);
         setDescription(entry, isAllDayEvent);
         setStatusStrip(entry, isAllDayEvent);
 
@@ -128,62 +119,53 @@
 
 
 /*!
-   \brief Adds event description for the item.
-   
-   \param entry An for which description needs to be displayed.
-   \param allDayEvent Flag that indicates whether an item is all day event
-*/
+ \brief Adds event description for the item.
+ 
+ \param entry An for which description needs to be displayed.
+ \param allDayEvent Flag that indicates whether an item is all day event
+ */
 void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent)
 {
-	QString description(entry.summary());
-	QString location(entry.location());
-	
-	
-	int separtorPos = 0;
-	
-	if(!location.isEmpty()) {
-	    if ( !description.isEmpty() ) {
-	    	separtorPos = description.count();
-	    	description.append(", ");
-			}
-	    
-		description.append(location);
-		}
-	
-	if ( description.isEmpty() ) {
-	    description.append(hbTrId("txt_calendar_dblist_unnamed"));
-	}
-	
-	//Description of all day events has to be displayed vertically
-	if(allDayEvent){
+    QString description(entry.summary());
+    QString location(entry.location());
+
+    int separtorPos = 0;
+    if (!location.isEmpty()) {
+        if (!description.isEmpty()) {
+            separtorPos = description.count();
+            description.append(", ");
+        }
+        description.append(location);
+    }
+
+    if (description.isEmpty()) {
+        description.append(hbTrId("txt_calendar_dblist_unnamed"));
+    }
 
-	    QString verticalString;
-	    for(int i=0; i<description.count(); i++){
-	    
-	        verticalString.append(QString(description.at(i)) + "\n");
-	    }
-	
-	    // remove "\n" before comma separator if exist
-	    if (separtorPos)
-	    	{
-	    	verticalString.remove( 2*separtorPos-1, 1);
-	    	}
-	    description = verticalString;
-	}	
-	
-	mEventDesc->setText(description);
+    //Description of all day events has to be displayed vertically
+    if (allDayEvent) {
+        QString verticalString;
+        for (int i = 0; i < description.count(); i++) {
+            verticalString.append(QString(description.at(i)) + "\n");
+        }
+
+        // remove "\n" before comma separator if exist
+        if (separtorPos) {
+            verticalString.remove(2 * separtorPos - 1, 1);
+        }
+        description = verticalString;
+    }
+
+    mEventDesc->setText(description);
 }
 
 /*!
-   \brief It set all needed things for status strip from Agenda Entry.
-   
-   \param entry Status Strip is created from Agenda Entry
-*/
+ \brief It set all needed things for status strip from Agenda Entry.
+ 
+ \param entry Status Strip is created from Agenda Entry
+ */
 void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent)
 {
-    QColor color = HbColorScheme::color("qtc_cal_month_current_day");
-    mColorStripe->setColor(color);
-    
     if (!allDayEvent) {
 
         QDateTime startTime;
@@ -191,8 +173,8 @@
         QDateTime currentDateTime;
         currentDateTime.setDate(container()->date());
 
-        CalenDayUtils::instance()->getEventValidStartEndTime(startTime, endTime, entry,
-            currentDateTime);
+        CalenDayUtils::instance()->getEventValidStartEndTime(startTime,
+            endTime, entry, currentDateTime);
 
         mColorStripe->setStartEndTime(startTime.time(), endTime.time());
     }
@@ -202,49 +184,52 @@
         // 00:00:00 and 00:00:00 next day respectively.
         // To draw it correctly we need times like those visible for user in
         // editor: 00:00:00 to 23:59:59 (the same day)
-        mColorStripe->setStartEndTime(entry.startTime().time(), entry.endTime().time().addSecs(-1));
+        mColorStripe->setStartEndTime(entry.startTime().time(),
+            entry.endTime().time().addSecs(-1));
     }
-    
+
     switch (entry.status()) {
         case AgendaEntry::Confirmed:
             mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
-        break;
+            break;
         case AgendaEntry::Tentative:
             mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines);
-        break;
+            break;
         case AgendaEntry::Cancelled:
             mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame);
-        break;
+            break;
         default:
             mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
-        break;
+            break;
     }
 }
 
 /*!
-   \brief Reimplemented from HbWidget. Handles resize event.
-   
-   \param event Instance of an event to be handled.
-*/
+ \brief Reimplemented from HbWidget. Handles resize event.
+ 
+ \param event Instance of an event to be handled.
+ */
 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
 {
     Q_UNUSED(event)
 
     qreal width = rect().width();
 
-    if(width < mEventDescMinWidth){
+    if (width < mEventDescMinWidth) {
         mEventDesc->hide();
-    } else{
+    }
+    else {
         mEventDesc->show();
     }
-        
-    if(width < mFrameMinWidth){
+
+    if (width < mFrameMinWidth) {
         mBg->hide();
-    } else{
+    }
+    else {
         mBg->show();
     }
 
-    //Necessary to switch layout
+    // Necessary to switch layout
     repolish();
 }