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), |
64 |
63 QLatin1String("colorStripe")); |
|
64 |
65 HbDeviceProfile deviceProfile; |
65 HbDeviceProfile deviceProfile; |
66 HbStyle style; |
66 qreal stripeWidth = KCalenTimeStripWidth * deviceProfile.unitValue(); |
67 |
67 mColorStripe->setPreferredWidth(stripeWidth); |
68 qreal horizontalSpacing = 0.0; |
68 |
69 qreal rightMargin = 0.0; |
69 // Minimum size of event frame (without/with description) |
70 |
70 mFrameMinWidth = KCalenMinEventWidth * deviceProfile.unitValue(); |
71 style.parameter(QString("hb-param-margin-gene-middle-horizontal"), |
71 mEventDescMinWidth = KCalenMinTouchableEventWidth |
72 horizontalSpacing, deviceProfile); |
72 * deviceProfile.unitValue(); |
73 style.parameter(QString("hb-param-margin-gene-right"), |
73 |
74 rightMargin, deviceProfile); |
74 // Minimum width is assured by widgetml and css, additionally called here |
75 |
75 // to prevent minimum size hint caching inside effectiveSizeHint |
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 } |
126 //HbAbstractViewItem::updateChildItems(); |
117 //HbAbstractViewItem::updateChildItems(); |
127 } |
118 } |
128 |
119 |
129 |
120 |
130 /*! |
121 /*! |
131 \brief Adds event description for the item. |
122 \brief Adds event description for the item. |
132 |
123 |
133 \param entry An for which description needs to be displayed. |
124 \param entry An for which description needs to be displayed. |
134 \param allDayEvent Flag that indicates whether an item is all day event |
125 \param allDayEvent Flag that indicates whether an item is all day event |
135 */ |
126 */ |
136 void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent) |
127 void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent) |
137 { |
128 { |
138 QString description(entry.summary()); |
129 QString description(entry.summary()); |
139 QString location(entry.location()); |
130 QString location(entry.location()); |
140 |
131 |
141 |
132 int separtorPos = 0; |
142 int separtorPos = 0; |
133 if (!location.isEmpty()) { |
143 |
134 if (!description.isEmpty()) { |
144 if(!location.isEmpty()) { |
135 separtorPos = description.count(); |
145 if ( !description.isEmpty() ) { |
136 description.append(", "); |
146 separtorPos = description.count(); |
137 } |
147 description.append(", "); |
138 description.append(location); |
148 } |
139 } |
149 |
140 |
150 description.append(location); |
141 if (description.isEmpty()) { |
151 } |
142 description.append(hbTrId("txt_calendar_dblist_unnamed")); |
152 |
143 } |
153 if ( description.isEmpty() ) { |
144 |
154 description.append(hbTrId("txt_calendar_dblist_unnamed")); |
145 //Description of all day events has to be displayed vertically |
155 } |
146 if (allDayEvent) { |
156 |
147 QString verticalString; |
157 //Description of all day events has to be displayed vertically |
148 for (int i = 0; i < description.count(); i++) { |
158 if(allDayEvent){ |
149 verticalString.append(QString(description.at(i)) + "\n"); |
159 |
150 } |
160 QString verticalString; |
151 |
161 for(int i=0; i<description.count(); i++){ |
152 // remove "\n" before comma separator if exist |
162 |
153 if (separtorPos) { |
163 verticalString.append(QString(description.at(i)) + "\n"); |
154 verticalString.remove(2 * separtorPos - 1, 1); |
164 } |
155 } |
165 |
156 description = verticalString; |
166 // remove "\n" before comma separator if exist |
157 } |
167 if (separtorPos) |
158 |
168 { |
159 mEventDesc->setText(description); |
169 verticalString.remove( 2*separtorPos-1, 1); |
160 } |
170 } |
161 |
171 description = verticalString; |
162 /*! |
172 } |
163 \brief It set all needed things for status strip from Agenda Entry. |
173 |
164 |
174 mEventDesc->setText(description); |
165 \param entry Status Strip is created from Agenda Entry |
175 } |
166 */ |
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) |
167 void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent) |
183 { |
168 { |
184 QColor color = HbColorScheme::color("qtc_cal_month_current_day"); |
|
185 mColorStripe->setColor(color); |
|
186 |
|
187 if (!allDayEvent) { |
169 if (!allDayEvent) { |
188 |
170 |
189 QDateTime startTime; |
171 QDateTime startTime; |
190 QDateTime endTime; |
172 QDateTime endTime; |
191 QDateTime currentDateTime; |
173 QDateTime currentDateTime; |
192 currentDateTime.setDate(container()->date()); |
174 currentDateTime.setDate(container()->date()); |
193 |
175 |
194 CalenDayUtils::instance()->getEventValidStartEndTime(startTime, endTime, entry, |
176 CalenDayUtils::instance()->getEventValidStartEndTime(startTime, |
195 currentDateTime); |
177 endTime, entry, currentDateTime); |
196 |
178 |
197 mColorStripe->setStartEndTime(startTime.time(), endTime.time()); |
179 mColorStripe->setStartEndTime(startTime.time(), endTime.time()); |
198 } |
180 } |
199 else { |
181 else { |
200 // This is workaround for displaying all-day events. |
182 // This is workaround for displaying all-day events. |
201 // Now for MS Outlook compability all-day events' start and end time is |
183 // Now for MS Outlook compability all-day events' start and end time is |
202 // 00:00:00 and 00:00:00 next day respectively. |
184 // 00:00:00 and 00:00:00 next day respectively. |
203 // To draw it correctly we need times like those visible for user in |
185 // 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) |
186 // editor: 00:00:00 to 23:59:59 (the same day) |
205 mColorStripe->setStartEndTime(entry.startTime().time(), entry.endTime().time().addSecs(-1)); |
187 mColorStripe->setStartEndTime(entry.startTime().time(), |
206 } |
188 entry.endTime().time().addSecs(-1)); |
207 |
189 } |
|
190 |
208 switch (entry.status()) { |
191 switch (entry.status()) { |
209 case AgendaEntry::Confirmed: |
192 case AgendaEntry::Confirmed: |
210 mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); |
193 mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); |
211 break; |
194 break; |
212 case AgendaEntry::Tentative: |
195 case AgendaEntry::Tentative: |
213 mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines); |
196 mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines); |
214 break; |
197 break; |
215 case AgendaEntry::Cancelled: |
198 case AgendaEntry::Cancelled: |
216 mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame); |
199 mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame); |
217 break; |
200 break; |
218 default: |
201 default: |
219 mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); |
202 mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); |
220 break; |
203 break; |
221 } |
204 } |
222 } |
205 } |
223 |
206 |
224 /*! |
207 /*! |
225 \brief Reimplemented from HbWidget. Handles resize event. |
208 \brief Reimplemented from HbWidget. Handles resize event. |
226 |
209 |
227 \param event Instance of an event to be handled. |
210 \param event Instance of an event to be handled. |
228 */ |
211 */ |
229 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event) |
212 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event) |
230 { |
213 { |
231 Q_UNUSED(event) |
214 Q_UNUSED(event) |
232 |
215 |
233 qreal width = rect().width(); |
216 qreal width = rect().width(); |
234 |
217 |
235 if(width < mEventDescMinWidth){ |
218 if (width < mEventDescMinWidth) { |
236 mEventDesc->hide(); |
219 mEventDesc->hide(); |
237 } else{ |
220 } |
|
221 else { |
238 mEventDesc->show(); |
222 mEventDesc->show(); |
239 } |
223 } |
240 |
224 |
241 if(width < mFrameMinWidth){ |
225 if (width < mFrameMinWidth) { |
242 mBg->hide(); |
226 mBg->hide(); |
243 } else{ |
227 } |
|
228 else { |
244 mBg->show(); |
229 mBg->show(); |
245 } |
230 } |
246 |
231 |
247 //Necessary to switch layout |
232 // Necessary to switch layout |
248 repolish(); |
233 repolish(); |
249 } |
234 } |
250 |
235 |
251 // End of File |
236 // End of File |