calendarui/views/dayview/src/calendayitem.cpp
author hgs
Mon, 28 Jun 2010 15:22:02 +0530
changeset 45 b6db4fd4947b
child 55 2c54b51f39c4
child 58 ef813d54df51
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Event view item, exact size and position of event is set in 
hgs
parents:
diff changeset
    15
*  				CalenDayContainer::setItemModelIndex based on event duration
hgs
parents:
diff changeset
    16
*
hgs
parents:
diff changeset
    17
*/
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
//System includes
hgs
parents:
diff changeset
    20
#include <hbframeitem.h>
hgs
parents:
diff changeset
    21
#include <hbtextitem.h>
hgs
parents:
diff changeset
    22
#include <agendaentry.h>
hgs
parents:
diff changeset
    23
#include <hbstyle.h>
hgs
parents:
diff changeset
    24
#include <hbcolorscheme.h>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
//User inlcudes
hgs
parents:
diff changeset
    28
#include "calendayitem.h"
hgs
parents:
diff changeset
    29
#include "calendaystatusstrip.h"
hgs
parents:
diff changeset
    30
#include "calendaymodel.h"
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    33
// CalenDayItem()
hgs
parents:
diff changeset
    34
// Constructor.
hgs
parents:
diff changeset
    35
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    36
//
hgs
parents:
diff changeset
    37
CalenDayItem::CalenDayItem():
hgs
parents:
diff changeset
    38
    mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0), 
hgs
parents:
diff changeset
    39
    mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
hgs
parents:
diff changeset
    40
{
hgs
parents:
diff changeset
    41
}
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    44
// CalenBCDayView()
hgs
parents:
diff changeset
    45
// Copy constructor.
hgs
parents:
diff changeset
    46
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    47
//
hgs
parents:
diff changeset
    48
CalenDayItem::CalenDayItem(const CalenDayItem & source) :
hgs
parents:
diff changeset
    49
    HbAbstractViewItem(source), mUpdated(false), mBg(0), mEventDesc(0), 
hgs
parents:
diff changeset
    50
    mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
hgs
parents:
diff changeset
    51
{	
hgs
parents:
diff changeset
    52
    // TODO: "qtg_fr_btn_pressed" need to replaced with qtg_fr_cal_meeting_bg
hgs
parents:
diff changeset
    53
	// when available
hgs
parents:
diff changeset
    54
    mBg = new HbFrameItem("qtg_fr_btn_pressed", HbFrameDrawer::NinePieces, this);
hgs
parents:
diff changeset
    55
    mEventDesc = new HbTextItem(this);
hgs
parents:
diff changeset
    56
    // TODO: probably ElideLeft needed for mirrored layout
hgs
parents:
diff changeset
    57
    mEventDesc->setElideMode(Qt::ElideRight);
hgs
parents:
diff changeset
    58
    mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
hgs
parents:
diff changeset
    59
    
hgs
parents:
diff changeset
    60
    mColorStripe = new CalenDayStatusStrip(this);
hgs
parents:
diff changeset
    61
    
hgs
parents:
diff changeset
    62
    HbStyle::setItemName(mBg, QLatin1String("backgroundFrame"));
hgs
parents:
diff changeset
    63
    HbStyle::setItemName(mEventDesc, QLatin1String("eventDescription"));
hgs
parents:
diff changeset
    64
    HbStyle::setItemName(static_cast<QGraphicsItem *>(mColorStripe), QLatin1String("colorStripe"));
hgs
parents:
diff changeset
    65
    
hgs
parents:
diff changeset
    66
    HbDeviceProfile deviceProfile;
hgs
parents:
diff changeset
    67
    HbStyle style;
hgs
parents:
diff changeset
    68
    
hgs
parents:
diff changeset
    69
    qreal horizontalSpacing = 0.0;
hgs
parents:
diff changeset
    70
    qreal rightMargin = 0.0;
hgs
parents:
diff changeset
    71
    
hgs
parents:
diff changeset
    72
    style.parameter(QString("hb-param-margin-gene-middle-horizontal"), 
hgs
parents:
diff changeset
    73
        horizontalSpacing, deviceProfile);
hgs
parents:
diff changeset
    74
    style.parameter(QString("hb-param-margin-gene-right"), 
hgs
parents:
diff changeset
    75
        rightMargin, deviceProfile); 
hgs
parents:
diff changeset
    76
    
hgs
parents:
diff changeset
    77
    qreal stripeWidth = 1.5 * deviceProfile.unitValue(); //1.5un according to UI spec
hgs
parents:
diff changeset
    78
    
hgs
parents:
diff changeset
    79
    mFrameMinWidth = 2 * horizontalSpacing + stripeWidth; //smallest width for which background frame is displayed
hgs
parents:
diff changeset
    80
    mEventDescMinWidth = mFrameMinWidth + rightMargin;//smallest width for which text can be displayed
hgs
parents:
diff changeset
    81
    
hgs
parents:
diff changeset
    82
    //Minimum width is assured by widgetml and css
hgs
parents:
diff changeset
    83
    //additionally called here to prevent minimum size hint caching inside effectiveSizeHint
hgs
parents:
diff changeset
    84
    setMinimumWidth(stripeWidth);
hgs
parents:
diff changeset
    85
}
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    88
// ~CalenDayItem()
hgs
parents:
diff changeset
    89
// Destructor.
hgs
parents:
diff changeset
    90
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    91
//
hgs
parents:
diff changeset
    92
CalenDayItem::~CalenDayItem()
hgs
parents:
diff changeset
    93
{
hgs
parents:
diff changeset
    94
}
hgs
parents:
diff changeset
    95
hgs
parents:
diff changeset
    96
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    97
// 
hgs
parents:
diff changeset
    98
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    99
//
hgs
parents:
diff changeset
   100
HbAbstractViewItem * CalenDayItem::createItem()
hgs
parents:
diff changeset
   101
{
hgs
parents:
diff changeset
   102
    CalenDayItem* newItem = new CalenDayItem(*this);
hgs
parents:
diff changeset
   103
    return newItem;
hgs
parents:
diff changeset
   104
}
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
hgs
parents:
diff changeset
   107
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   108
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   109
//
hgs
parents:
diff changeset
   110
void CalenDayItem::updateChildItems()
hgs
parents:
diff changeset
   111
{
hgs
parents:
diff changeset
   112
	// there is no need to update items after creation
hgs
parents:
diff changeset
   113
	if (!mUpdated)
hgs
parents:
diff changeset
   114
		{
hgs
parents:
diff changeset
   115
		AgendaEntry entry;
hgs
parents:
diff changeset
   116
		entry = modelIndex().data( CalenDayEntry ).value<AgendaEntry>();
hgs
parents:
diff changeset
   117
		
hgs
parents:
diff changeset
   118
		bool isAllDayEvent = (entry.type() == AgendaEntry::TypeEvent)
hgs
parents:
diff changeset
   119
								&& !entry.isTimedEntry(); 
hgs
parents:
diff changeset
   120
		
hgs
parents:
diff changeset
   121
		setDescription(entry, isAllDayEvent);
hgs
parents:
diff changeset
   122
		setStatusStrip(entry, isAllDayEvent);
hgs
parents:
diff changeset
   123
		
hgs
parents:
diff changeset
   124
		mUpdated = true;
hgs
parents:
diff changeset
   125
		}
hgs
parents:
diff changeset
   126
	
hgs
parents:
diff changeset
   127
	//TODO: check if needed
hgs
parents:
diff changeset
   128
	//repolish(); 
hgs
parents:
diff changeset
   129
	//HbAbstractViewItem::updateChildItems();
hgs
parents:
diff changeset
   130
}
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   134
// setDescription()
hgs
parents:
diff changeset
   135
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   136
//
hgs
parents:
diff changeset
   137
void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent)
hgs
parents:
diff changeset
   138
{
hgs
parents:
diff changeset
   139
	QString description(entry.summary());
hgs
parents:
diff changeset
   140
	QString location(entry.location());
hgs
parents:
diff changeset
   141
	
hgs
parents:
diff changeset
   142
	
hgs
parents:
diff changeset
   143
	int separtorPos = 0;
hgs
parents:
diff changeset
   144
	
hgs
parents:
diff changeset
   145
	if(!location.isEmpty()) {
hgs
parents:
diff changeset
   146
	    if ( !description.isEmpty() ) {
hgs
parents:
diff changeset
   147
	    	separtorPos = description.count();
hgs
parents:
diff changeset
   148
	    	description.append(", ");
hgs
parents:
diff changeset
   149
			}
hgs
parents:
diff changeset
   150
	    
hgs
parents:
diff changeset
   151
		description.append(location);
hgs
parents:
diff changeset
   152
		}
hgs
parents:
diff changeset
   153
	
hgs
parents:
diff changeset
   154
	if ( description.isEmpty() ) {
hgs
parents:
diff changeset
   155
	    description.append(hbTrId("txt_calendar_dblist_unnamed"));
hgs
parents:
diff changeset
   156
	}
hgs
parents:
diff changeset
   157
	
hgs
parents:
diff changeset
   158
	//Description of all day events has to be displayed vertically
hgs
parents:
diff changeset
   159
	if(allDayEvent){
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
	    QString verticalString;
hgs
parents:
diff changeset
   162
	    for(int i=0; i<description.count(); i++){
hgs
parents:
diff changeset
   163
	    
hgs
parents:
diff changeset
   164
	        verticalString.append(QString(description.at(i)) + "\n");
hgs
parents:
diff changeset
   165
	    }
hgs
parents:
diff changeset
   166
	
hgs
parents:
diff changeset
   167
	    // remove "\n" before comma separator if exist
hgs
parents:
diff changeset
   168
	    if (separtorPos)
hgs
parents:
diff changeset
   169
	    	{
hgs
parents:
diff changeset
   170
	    	verticalString.remove( 2*separtorPos-1, 1);
hgs
parents:
diff changeset
   171
	    	}
hgs
parents:
diff changeset
   172
	    description = verticalString;
hgs
parents:
diff changeset
   173
	}	
hgs
parents:
diff changeset
   174
	
hgs
parents:
diff changeset
   175
	mEventDesc->setText(description);
hgs
parents:
diff changeset
   176
}
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
/*!
hgs
parents:
diff changeset
   179
   \brief It set all needed things for status strip from Agenda Entry.
hgs
parents:
diff changeset
   180
   
hgs
parents:
diff changeset
   181
   \param entry Status Strip is created from Agenda Entry
hgs
parents:
diff changeset
   182
 */
hgs
parents:
diff changeset
   183
void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent)
hgs
parents:
diff changeset
   184
{
hgs
parents:
diff changeset
   185
    QColor color = HbColorScheme::color("qtc_cal_month_current_day");
hgs
parents:
diff changeset
   186
    mColorStripe->setColor(color);
hgs
parents:
diff changeset
   187
    
hgs
parents:
diff changeset
   188
    if (!allDayEvent) {
hgs
parents:
diff changeset
   189
    	mColorStripe->setStartEndTime(entry.startTime().time(),
hgs
parents:
diff changeset
   190
                                  entry.endTime().time());
hgs
parents:
diff changeset
   191
    } else {
hgs
parents:
diff changeset
   192
    	// This is workaround for displaying all-day events.
hgs
parents:
diff changeset
   193
    	// Now for MS Outlook compability all-day events' start and end time is
hgs
parents:
diff changeset
   194
    	// 00:00:00 and 00:00:00 next day respectively.
hgs
parents:
diff changeset
   195
    	// To draw it correctly we need times like those visible for user in
hgs
parents:
diff changeset
   196
    	// editor: 00:00:00 to 23:59:59 (the same day)
hgs
parents:
diff changeset
   197
    	mColorStripe->setStartEndTime(entry.startTime().time(),
hgs
parents:
diff changeset
   198
    	                                  entry.endTime().time().addSecs(-1));
hgs
parents:
diff changeset
   199
    }
hgs
parents:
diff changeset
   200
    
hgs
parents:
diff changeset
   201
    switch (entry.status()) {
hgs
parents:
diff changeset
   202
        case AgendaEntry::Confirmed:
hgs
parents:
diff changeset
   203
            mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
hgs
parents:
diff changeset
   204
        break;
hgs
parents:
diff changeset
   205
        case AgendaEntry::Tentative:
hgs
parents:
diff changeset
   206
            mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines);
hgs
parents:
diff changeset
   207
        break;
hgs
parents:
diff changeset
   208
        case AgendaEntry::Cancelled:
hgs
parents:
diff changeset
   209
            mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame);
hgs
parents:
diff changeset
   210
        break;
hgs
parents:
diff changeset
   211
        default:
hgs
parents:
diff changeset
   212
            mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
hgs
parents:
diff changeset
   213
        break;
hgs
parents:
diff changeset
   214
    }
hgs
parents:
diff changeset
   215
}
hgs
parents:
diff changeset
   216
hgs
parents:
diff changeset
   217
void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
hgs
parents:
diff changeset
   218
{
hgs
parents:
diff changeset
   219
    Q_UNUSED(event)
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
    qreal width = rect().width();
hgs
parents:
diff changeset
   222
hgs
parents:
diff changeset
   223
    if(width < mEventDescMinWidth){
hgs
parents:
diff changeset
   224
        mEventDesc->hide();
hgs
parents:
diff changeset
   225
    } else{
hgs
parents:
diff changeset
   226
        mEventDesc->show();
hgs
parents:
diff changeset
   227
    }
hgs
parents:
diff changeset
   228
        
hgs
parents:
diff changeset
   229
    if(width < mFrameMinWidth){
hgs
parents:
diff changeset
   230
        mBg->hide();
hgs
parents:
diff changeset
   231
    } else{
hgs
parents:
diff changeset
   232
        mBg->show();
hgs
parents:
diff changeset
   233
    }
hgs
parents:
diff changeset
   234
hgs
parents:
diff changeset
   235
    //Necessary to switch layout
hgs
parents:
diff changeset
   236
    repolish();
hgs
parents:
diff changeset
   237
}
hgs
parents:
diff changeset
   238
hgs
parents:
diff changeset
   239
// End of File