|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definition file for class CalenGridItemPrototype. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QDebug> |
|
20 #include <QPainter> |
|
21 #include <QPen> |
|
22 #include <QGraphicsWidget> |
|
23 #include <QGraphicsLinearLayout> |
|
24 #include <hblabel.h> |
|
25 #include <hbcolorscheme.h> |
|
26 |
|
27 // User includes |
|
28 #include "calengriditemprototype.h" |
|
29 #include "calengriditem.h" |
|
30 #include "calencommon.h" |
|
31 |
|
32 #define GRIDLINE_WIDTH 0.075 //units |
|
33 /*! |
|
34 \class CalenGridItemPrototype |
|
35 |
|
36 Prototype class for HbGridView. |
|
37 */ |
|
38 |
|
39 /*! |
|
40 Constructor. |
|
41 */ |
|
42 CalenGridItemPrototype::CalenGridItemPrototype(QGraphicsWidget *parent) : |
|
43 HbAbstractViewItem(parent), |
|
44 mLayout(0), |
|
45 mCurrentDateColor(Qt::black), |
|
46 mGridBorderColor(Qt::gray), |
|
47 mIsSeventhColumn(false) |
|
48 { |
|
49 // Nothing yet. |
|
50 } |
|
51 |
|
52 /*! |
|
53 From HbAbstractViewItem. |
|
54 |
|
55 \return CalenGridItemPrototype* Pointer to the constructed object. |
|
56 \sa HbAbstractViewItem, HbGridViewItem |
|
57 */ |
|
58 HbAbstractViewItem *CalenGridItemPrototype::createItem() |
|
59 { |
|
60 CalenGridItemPrototype *item = new CalenGridItemPrototype(); |
|
61 item->createItemLayout(); |
|
62 return item; |
|
63 } |
|
64 |
|
65 /*! |
|
66 From HbAbstractViewItem. |
|
67 |
|
68 \sa HbAbstractViewItem, HbGridViewItem |
|
69 */ |
|
70 void CalenGridItemPrototype::updateChildItems() |
|
71 { |
|
72 // Here update content of each item. |
|
73 |
|
74 QVariant monthDayRole = |
|
75 modelIndex().data(CalendarNamespace::CalendarMonthDayRole); |
|
76 if (monthDayRole.isValid()) { |
|
77 if (monthDayRole.canConvert<QString>()) { |
|
78 mWidget->updateMonthDayInfo(monthDayRole.toString()); |
|
79 } |
|
80 } |
|
81 |
|
82 QVariant monthEventRole = |
|
83 modelIndex().data(CalendarNamespace::CalendarMonthEventRole); |
|
84 if (monthEventRole.isValid()) { |
|
85 if (monthEventRole.canConvert<QString>()) { |
|
86 mWidget->updateEventIndicator(monthEventRole.toString()); |
|
87 } |
|
88 } |
|
89 |
|
90 QVariant monthFocusRole = |
|
91 modelIndex().data(CalendarNamespace::CalendarMonthFocusRole); |
|
92 if (monthFocusRole.isValid()) { |
|
93 if (monthFocusRole.canConvert<QString>()) { |
|
94 mWidget->updateFocusIndicator(monthFocusRole.toString()); |
|
95 } |
|
96 } |
|
97 |
|
98 QVariant monthTextColorRole = |
|
99 modelIndex().data(CalendarNamespace::CalendarMonthTextColorRole); |
|
100 if (monthTextColorRole.isValid()) { |
|
101 if (monthTextColorRole.canConvert<QColor>()) { |
|
102 mWidget->updateMonthDayInfoColor(monthTextColorRole.value<QColor>()); |
|
103 } |
|
104 } |
|
105 |
|
106 QVariant seventhColumnRole = |
|
107 modelIndex().data(CalendarNamespace::CalendarMonthSeventhColumn); |
|
108 if (seventhColumnRole.isValid()) { |
|
109 if (seventhColumnRole.canConvert<bool>()) { |
|
110 mIsSeventhColumn = seventhColumnRole.value<bool>(); |
|
111 } |
|
112 } |
|
113 bool underlineEnabled = modelIndex().data( |
|
114 CalendarNamespace::CalendarMonthUnderlineRole).value<bool>(); |
|
115 mWidget->drawUnderline(underlineEnabled); |
|
116 |
|
117 } |
|
118 |
|
119 /*! |
|
120 Creates the item layout. |
|
121 */ |
|
122 void CalenGridItemPrototype::createItemLayout() |
|
123 { |
|
124 mLayout = new QGraphicsLinearLayout(Qt::Vertical, this); |
|
125 |
|
126 mWidget = new CalenGridItem(this); |
|
127 mLayout->addItem(mWidget); |
|
128 |
|
129 mLayout->setSpacing(0); |
|
130 mLayout->setContentsMargins(0, 0, 0, 0); |
|
131 |
|
132 setLayout(mLayout); |
|
133 } |
|
134 |
|
135 /*! |
|
136 To paint grid item border |
|
137 */ |
|
138 void CalenGridItemPrototype::paint(QPainter* painter, |
|
139 const QStyleOptionGraphicsItem* option, |
|
140 QWidget* widget) |
|
141 { |
|
142 Q_UNUSED(option); |
|
143 Q_UNUSED(widget); |
|
144 |
|
145 QPen pen;// |
|
146 pen.setStyle(Qt::SolidLine); |
|
147 pen.setWidth(GRIDLINE_WIDTH); |
|
148 QColor gridLineColor = HbColorScheme::color("qtc_cal_grid_line"); |
|
149 if (gridLineColor.isValid()) { |
|
150 pen.setBrush(gridLineColor); |
|
151 } else { |
|
152 pen.setBrush(mGridBorderColor); |
|
153 } |
|
154 painter->setPen(pen); |
|
155 QRectF controlRect = boundingRect(); |
|
156 // Check if this is seventh column item |
|
157 if ( !mIsSeventhColumn ) { |
|
158 // Then draw right and bottom borders |
|
159 QPointF startPoint = controlRect.bottomLeft(); |
|
160 QPointF endPoint = controlRect.bottomRight(); |
|
161 // Draw the bottom border |
|
162 painter->drawLine(startPoint, endPoint); |
|
163 startPoint = controlRect.topRight(); |
|
164 // Draw right border |
|
165 painter->drawLine(startPoint, endPoint); |
|
166 } else { |
|
167 // Then draw only bottom border |
|
168 QPointF startPoint = controlRect.bottomLeft(); |
|
169 QPointF endPoint = controlRect.bottomRight(); |
|
170 // Draw the bottom border |
|
171 painter->drawLine(startPoint, endPoint); |
|
172 } |
|
173 } |
|
174 // End of file --Don't remove this. |