28 |
28 |
29 #include "hblistviewitem_p.h" |
29 #include "hblistviewitem_p.h" |
30 #include <QGestureEvent> |
30 #include <QGestureEvent> |
31 #include <QCoreApplication> |
31 #include <QCoreApplication> |
32 #include <hbwidgetfeedback.h> |
32 #include <hbwidgetfeedback.h> |
|
33 |
|
34 #include <QPainter> |
|
35 #include <qmath.h> |
|
36 #include <QtDebug> |
|
37 #include <hbcolorscheme.h> |
|
38 #include <hbevent.h> |
|
39 #include <QDynamicPropertyChangeEvent> |
|
40 #include <hbtextitem.h> |
|
41 #include <QTextLayout> |
|
42 #if 0 |
|
43 #define DEBUG qDebug() |
|
44 #else |
|
45 #define DEBUG if(0)qDebug() |
|
46 #endif |
|
47 |
|
48 #undef ZOOMTEXT |
|
49 class HbRotatingText : public HbTextItem |
|
50 { |
|
51 public: |
|
52 HbRotatingText(QGraphicsItem* parent =0 ):HbTextItem(parent) |
|
53 { |
|
54 mTextCol = HbColorScheme::color("qtc_tumbler_normal"); |
|
55 mSelTextCol = HbColorScheme::color("qtc_tumbler_selected"); |
|
56 |
|
57 setFlag(ItemSendsGeometryChanges); |
|
58 setFlag(ItemSendsScenePositionChanges); |
|
59 if(parent){ |
|
60 parent->setFlag(ItemSendsGeometryChanges); |
|
61 parent->setFlag(ItemSendsScenePositionChanges); |
|
62 } |
|
63 } |
|
64 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
65 { |
|
66 Q_UNUSED(option); |
|
67 Q_UNUSED(widget); |
|
68 QTransform oldTrans = painter->transform(); |
|
69 QBrush oldBrush = painter->brush(); |
|
70 bool atialiased = false; |
|
71 if(!painter->testRenderHint(QPainter::Antialiasing)){ |
|
72 painter->setRenderHint(QPainter::Antialiasing); |
|
73 atialiased = true; |
|
74 } |
|
75 if(refereceItem){ |
|
76 QRectF viewBounds = refereceItem->mapToScene(refereceItem->boundingRect()).boundingRect(); |
|
77 QRectF itemBounds = mapToScene(this->boundingRect()).boundingRect(); |
|
78 if(viewBounds.intersect(itemBounds).isValid()){ |
|
79 |
|
80 QRectF refbounds = mapFromItem(refereceItem,refereceItem->boundingRect()).boundingRect(); |
|
81 |
|
82 |
|
83 qreal dy = boundingRect().center().y()- refbounds.center().y(); |
|
84 qreal radius = (refbounds.height()+boundingRect().height())/2; |
|
85 QLinearGradient gr(QPointF(refbounds.center().x(),refbounds.center().y()-radius), |
|
86 QPointF(refbounds.width()/2,refbounds.center().y() + radius)); |
|
87 gr.setColorAt(0, mTextCol); |
|
88 gr.setColorAt(0.5, mSelTextCol); |
|
89 gr.setColorAt(1, mTextCol) ; |
|
90 QPen pen; |
|
91 pen.setBrush(QBrush(gr)); |
|
92 painter->setPen(pen); |
|
93 painter->setBrush(QBrush(gr)); |
|
94 |
|
95 #if QT_VERSION >= 0x040700 |
|
96 if(rotate){ |
|
97 |
|
98 qreal ratio = dy/radius; |
|
99 qreal absRatio = qAbs(ratio); |
|
100 if(absRatio <= 1.0){ |
|
101 qreal angle = qAsin(ratio); |
|
102 DEBUG<<"Angle"<<angle; |
|
103 QTransform current = painter->transform(); |
|
104 painter->setTransform(current.rotateRadians(angle,Qt::XAxis)); |
|
105 |
|
106 } |
|
107 |
|
108 } |
|
109 dy = qAbs(dy); |
|
110 #else |
|
111 dy = (dy<0)?-dy:dy; |
|
112 #endif |
|
113 |
|
114 |
|
115 |
|
116 QFont thefont = font(); |
|
117 |
|
118 // qreal len = (radius-dy); |
|
119 |
|
120 // if(len >0 ){ |
|
121 // qreal pixeSize = thefont.pixelSize(); |
|
122 // qreal ratio = (0.5+len/radius); |
|
123 |
|
124 // pixeSize = ((ratio>1)?1:ratio) *pixeSize; |
|
125 // thefont.setPixelSize((int)pixeSize); |
|
126 // painter->setFont(thefont); |
|
127 |
|
128 // } |
|
129 |
|
130 QFontMetrics fm(thefont); |
|
131 QPointF center = boundingRect().center(); |
|
132 QSizeF textSize = fm.size(Qt::TextSingleLine,text); |
|
133 qreal middlex = center.x()-(textSize.width()/2); |
|
134 qreal middley = center.y()-textSize.height()/2; |
|
135 |
|
136 textlayout.setFont(thefont); |
|
137 |
|
138 textlayout.setText(text); |
|
139 textlayout.beginLayout(); |
|
140 textlayout.createLine(); |
|
141 textlayout.endLayout(); |
|
142 textlayout.draw(painter,QPointF(middlex,middley)); |
|
143 |
|
144 |
|
145 |
|
146 // for (int i=0; i<paths.size(); ++i) { |
|
147 // QPainterPath path = lensDeform(paths[i], |
|
148 // QPointF(size().width()/2-m_pathBounds.width()/2, |
|
149 // size().height()/2-m_pathBounds.height()/2)); |
|
150 |
|
151 |
|
152 // painter->drawPath(path); |
|
153 // } |
|
154 |
|
155 } |
|
156 |
|
157 |
|
158 |
|
159 } |
|
160 //HbTextItem::paint(painter,option,widget); |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 if(atialiased){ |
|
167 painter->setRenderHint(QPainter::Antialiasing,false); |
|
168 } |
|
169 |
|
170 painter->setTransform(oldTrans); |
|
171 painter->setBrush(oldBrush); |
|
172 } |
|
173 void setReferenceItem(QGraphicsItem* item) |
|
174 { |
|
175 refereceItem = item; |
|
176 } |
|
177 void changeEvent(QEvent *event) |
|
178 { |
|
179 |
|
180 if (event->type() == HbEvent::ThemeChanged) { |
|
181 mTextCol = HbColorScheme::color("qtc_tumbler_normal"); |
|
182 mSelTextCol = HbColorScheme::color("qtc_tumbler_selected"); |
|
183 |
|
184 } |
|
185 |
|
186 // Call base class version of changeEvent() |
|
187 return HbTextItem::changeEvent(event); |
|
188 } |
|
189 QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
|
190 { |
|
191 if(change == ItemScenePositionHasChanged){ |
|
192 |
|
193 } |
|
194 return HbTextItem::itemChange(change,value); |
|
195 |
|
196 } |
|
197 // void gestureEvent(QGestureEvent *event) |
|
198 // { |
|
199 // HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
|
200 // if(gesture){ |
|
201 // switch(gesture->state()){ |
|
202 // case Qt::GestureUpdated: |
|
203 |
|
204 // HbRotatingText::rotate = !HbRotatingText::rotate; |
|
205 // } |
|
206 |
|
207 // } |
|
208 // event->ignore(); |
|
209 // } |
|
210 |
|
211 void setText(const QString& text); |
|
212 QPainterPath lensDeform(const QPainterPath &source, const QPointF &offset); |
|
213 bool event(QEvent *e); |
|
214 QGraphicsItem* refereceItem; |
|
215 QColor mTextCol,mSelTextCol; |
|
216 QString text; |
|
217 QVector<QPainterPath> paths; |
|
218 QRectF m_pathBounds; |
|
219 QTextLayout textlayout; |
|
220 static bool rotate; |
|
221 |
|
222 |
|
223 }; |
|
224 bool HbRotatingText::rotate = true; |
|
225 |
|
226 QPainterPath HbRotatingText::lensDeform(const QPainterPath &source, const QPointF &offset) |
|
227 { |
|
228 |
|
229 QPainterPath path; |
|
230 path.addPath(source); |
|
231 if(1){ |
|
232 qreal flip = 70 / qreal(100); |
|
233 QPointF centerPos; |
|
234 qreal radius; |
|
235 if(refereceItem){ |
|
236 QRectF refbounds = mapFromItem(refereceItem,refereceItem->boundingRect()).boundingRect(); |
|
237 centerPos=refbounds.center(); |
|
238 radius = refereceItem->boundingRect().height()/2; |
|
239 |
|
240 |
|
241 } |
|
242 else{ |
|
243 centerPos=source.boundingRect().center(); |
|
244 radius = source.boundingRect().height(); |
|
245 } |
|
246 |
|
247 for (int i=0; i<path.elementCount(); ++i) { |
|
248 const QPainterPath::Element &e = path.elementAt(i); |
|
249 |
|
250 qreal x = e.x + offset.x(); |
|
251 qreal y = e.y + offset.y(); |
|
252 |
|
253 qreal dx =0;//x - centerPos.x(); |
|
254 qreal dy = y - centerPos.y(); |
|
255 |
|
256 qreal len = radius - qSqrt(dx * dx + dy * dy); |
|
257 |
|
258 if (len > 0 ) { |
|
259 path.setElementPositionAt(i, |
|
260 x + flip * dx *len / (radius*2), |
|
261 y + flip * dy * len / (radius+2*len)); |
|
262 } else { |
|
263 path.setElementPositionAt(i, x, y); |
|
264 } |
|
265 |
|
266 } |
|
267 |
|
268 |
|
269 |
|
270 } |
|
271 |
|
272 return path; |
|
273 } |
|
274 |
|
275 bool HbRotatingText::event(QEvent *e) |
|
276 { |
|
277 |
|
278 switch(e->type()){ |
|
279 case QEvent::FontChange: |
|
280 setText(text); |
|
281 break; |
|
282 default: |
|
283 break; |
|
284 |
|
285 } |
|
286 return HbWidgetBase::event(e); |
|
287 } |
|
288 |
|
289 void HbRotatingText::setText(const QString& text) |
|
290 { |
|
291 HbTextItem::setText(text); |
|
292 this->text = text; |
|
293 // QFontMetrics fm(font()); |
|
294 |
|
295 // paths.clear(); |
|
296 // m_pathBounds = QRect(); |
|
297 |
|
298 // QPointF advance(0, 0); |
|
299 |
|
300 // bool do_quick = true; |
|
301 // for (int i=0; i<text.size(); ++i) { |
|
302 // if (text.at(i).unicode() >= 0x4ff && text.at(i).unicode() <= 0x1e00) { |
|
303 // do_quick = false; |
|
304 // break; |
|
305 // } |
|
306 // } |
|
307 |
|
308 // if (do_quick) { |
|
309 // for (int i=0; i<text.size(); ++i) { |
|
310 // QPainterPath path; |
|
311 // path.addText(advance, font(), text.mid(i, 1)); |
|
312 // m_pathBounds |= path.boundingRect(); |
|
313 // paths << path; |
|
314 // advance += QPointF(fm.width(text.mid(i, 1))+2, 0); |
|
315 // } |
|
316 // } else { |
|
317 // QPainterPath path; |
|
318 // path.addText(advance, font(), text); |
|
319 // m_pathBounds |= path.boundingRect(); |
|
320 // paths << path; |
|
321 // } |
|
322 |
|
323 // for (int i=0; i<paths.size(); ++i){ |
|
324 // paths[i] = paths[i] * QMatrix(1, 0, 0, 1, -m_pathBounds.x(), -m_pathBounds.y()); |
|
325 // // paths[i] = paths[i] * QMatrix(1, 0, 0, 1, 0, m_pathBounds.height()/2); |
|
326 // } |
|
327 |
|
328 update(); |
|
329 } |
|
330 |
33 class HbDatePickerViewItemPrivate:public HbListViewItemPrivate |
331 class HbDatePickerViewItemPrivate:public HbListViewItemPrivate |
34 { |
332 { |
35 public: |
333 public: |
36 HbDatePickerViewItemPrivate(HbDatePickerViewItem *prototype); |
334 HbDatePickerViewItemPrivate(HbDatePickerViewItem *prototype); |
37 void tapTriggered(QGestureEvent *event); |
335 void tapTriggered(QGestureEvent *event); |
38 |
336 #ifdef ZOOMTEXT |
39 Q_DECLARE_PUBLIC(HbDatePickerViewItem) |
337 HbRotatingText *zoomText; |
|
338 #endif |
|
339 |
|
340 Q_DECLARE_PUBLIC(HbDatePickerViewItem); |
40 }; |
341 }; |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
41 HbDatePickerViewItemPrivate::HbDatePickerViewItemPrivate(HbDatePickerViewItem *prototype): |
349 HbDatePickerViewItemPrivate::HbDatePickerViewItemPrivate(HbDatePickerViewItem *prototype): |
42 HbListViewItemPrivate(prototype) |
350 HbListViewItemPrivate(prototype) |
|
351 #ifdef ZOOMTEXT |
|
352 ,zoomText(0) |
|
353 #endif |
43 { |
354 { |
44 } |
355 } |
45 |
356 |
46 void HbDatePickerViewItemPrivate::tapTriggered(QGestureEvent *event) |
357 void HbDatePickerViewItemPrivate::tapTriggered(QGestureEvent *event) |
47 { |
358 { |