diff -r fd30d51f876b -r b6db4fd4947b calendarui/views/dayview/src/calendayitem.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/calendarui/views/dayview/src/calendayitem.cpp Mon Jun 28 15:22:02 2010 +0530 @@ -0,0 +1,239 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Event view item, exact size and position of event is set in +* CalenDayContainer::setItemModelIndex based on event duration +* +*/ + +//System includes +#include +#include +#include +#include +#include + + +//User inlcudes +#include "calendayitem.h" +#include "calendaystatusstrip.h" +#include "calendaymodel.h" + +// ----------------------------------------------------------------------------- +// CalenDayItem() +// Constructor. +// ----------------------------------------------------------------------------- +// +CalenDayItem::CalenDayItem(): + mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0), + mEventDescMinWidth(0.0), mFrameMinWidth(0.0) +{ +} + +// ----------------------------------------------------------------------------- +// CalenBCDayView() +// Copy constructor. +// ----------------------------------------------------------------------------- +// +CalenDayItem::CalenDayItem(const CalenDayItem & source) : + HbAbstractViewItem(source), 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); + 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(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 + setMinimumWidth(stripeWidth); +} + +// ----------------------------------------------------------------------------- +// ~CalenDayItem() +// Destructor. +// ----------------------------------------------------------------------------- +// +CalenDayItem::~CalenDayItem() +{ +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +HbAbstractViewItem * CalenDayItem::createItem() +{ + CalenDayItem* newItem = new CalenDayItem(*this); + return newItem; +} + + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// +void CalenDayItem::updateChildItems() +{ + // there is no need to update items after creation + if (!mUpdated) + { + AgendaEntry entry; + entry = modelIndex().data( CalenDayEntry ).value(); + + bool isAllDayEvent = (entry.type() == AgendaEntry::TypeEvent) + && !entry.isTimedEntry(); + + setDescription(entry, isAllDayEvent); + setStatusStrip(entry, isAllDayEvent); + + mUpdated = true; + } + + //TODO: check if needed + //repolish(); + //HbAbstractViewItem::updateChildItems(); +} + + +// ----------------------------------------------------------------------------- +// setDescription() +// ----------------------------------------------------------------------------- +// +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 verticalString; + for(int i=0; isetText(description); +} + +/*! + \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) { + mColorStripe->setStartEndTime(entry.startTime().time(), + entry.endTime().time()); + } else { + // This is workaround for displaying all-day events. + // Now for MS Outlook compability all-day events' start and end time is + // 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)); + } + + switch (entry.status()) { + case AgendaEntry::Confirmed: + mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); + break; + case AgendaEntry::Tentative: + mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines); + break; + case AgendaEntry::Cancelled: + mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame); + break; + default: + mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); + break; + } +} + +void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + Q_UNUSED(event) + + qreal width = rect().width(); + + if(width < mEventDescMinWidth){ + mEventDesc->hide(); + } else{ + mEventDesc->show(); + } + + if(width < mFrameMinWidth){ + mBg->hide(); + } else{ + mBg->show(); + } + + //Necessary to switch layout + repolish(); +} + +// End of File