27 #include "hbmaskableiconimpl_p.h" |
27 #include "hbmaskableiconimpl_p.h" |
28 |
28 |
29 #include <QStyleOption> |
29 #include <QStyleOption> |
30 #include <QApplication> |
30 #include <QApplication> |
31 |
31 |
32 struct HbPixmapIconMaskedData |
32 struct HbPixmapIconMaskedData { |
33 { |
|
34 QPixmap currentPixmap; |
33 QPixmap currentPixmap; |
35 }; |
34 }; |
36 |
35 |
37 HbPixmapIconRenderer::HbPixmapIconRenderer(const QPixmap &pixmap, HbIconImpl *impl) |
36 HbPixmapIconRenderer::HbPixmapIconRenderer(const QPixmap &pixmap, HbIconImpl *impl) |
38 : iconMode(QIcon::Normal), |
37 : iconMode(QIcon::Normal), |
39 iconPropertiesApplied(false), |
38 iconPropertiesApplied(false), |
40 pixmapData(pixmap), |
39 pixmapData(pixmap), |
41 iconImpl(impl) |
40 iconImpl(impl) |
42 { |
41 { |
43 } |
42 } |
44 |
43 |
45 HbPixmapIconRenderer::~HbPixmapIconRenderer() |
44 HbPixmapIconRenderer::~HbPixmapIconRenderer() |
46 { |
45 { |
47 } |
46 } |
48 |
47 |
49 void HbPixmapIconRenderer::draw(QPainter* painter, |
48 void HbPixmapIconRenderer::draw(QPainter *painter, |
50 const QPointF &topLeft, |
49 const QPointF &topLeft, |
51 const QPainterPath &clipPath, |
50 const QPainterPath &clipPath, |
52 HbMaskableIconImpl * maskIconData) |
51 HbMaskableIconImpl *maskIconData) |
53 { |
52 { |
54 if (!iconPropertiesApplied) { |
53 if (!iconPropertiesApplied) { |
55 applyIconProperties(); |
54 applyIconProperties(); |
56 } |
55 } |
57 |
56 |
65 } |
64 } |
66 |
65 |
67 doDraw(painter, topLeft, pixmapToDraw, clipPath); |
66 doDraw(painter, topLeft, pixmapToDraw, clipPath); |
68 } |
67 } |
69 |
68 |
70 void HbPixmapIconRenderer::doDraw(QPainter * painter, |
69 void HbPixmapIconRenderer::doDraw(QPainter *painter, |
71 const QPointF & topLeft, |
70 const QPointF &topLeft, |
72 const QPixmap & finalPixmap, |
71 const QPixmap &finalPixmap, |
73 const QPainterPath & clipPath) |
72 const QPainterPath &clipPath) |
74 { |
73 { |
75 if (!clipPath.isEmpty()) { |
74 if (!clipPath.isEmpty()) { |
76 QPainterPath oldPath; |
75 QPainterPath oldPath; |
77 bool clipped = painter->hasClipping(); |
76 bool wasClipped = painter->hasClipping(); |
78 |
77 |
79 if (!clipped) { |
78 if (!wasClipped) { |
80 painter->setClipping(true); |
79 painter->setClipping(true); |
81 } |
80 } |
82 |
81 |
83 QRectF cliprect = clipPath.boundingRect(); |
82 QRectF cliprect = clipPath.boundingRect(); |
84 QPainterPath intersect(clipPath); |
83 QPainterPath intersect(clipPath); |
85 if (clipped) { |
84 oldPath = painter->clipPath(); |
86 oldPath = painter->clipPath(); |
85 if (wasClipped) { |
87 QRectF oldrect = oldPath.boundingRect(); |
86 QRectF oldrect = oldPath.boundingRect(); |
88 intersect = oldPath.intersected(clipPath); |
87 intersect = oldPath.intersected(clipPath); |
89 QRectF interrect = intersect.boundingRect(); |
88 QRectF interrect = intersect.boundingRect(); |
90 } |
89 } |
91 |
90 |
92 painter->setClipPath(intersect, Qt::ReplaceClip); |
91 painter->setClipPath(intersect, Qt::ReplaceClip); |
93 painter->drawPixmap(topLeft, finalPixmap); |
92 painter->drawPixmap(topLeft, finalPixmap); |
94 |
93 |
95 if (!clipped) { |
94 painter->setClipPath(oldPath); |
96 painter->setClipPath(oldPath, Qt::NoClip); |
95 painter->setClipping(wasClipped); |
97 } else { |
|
98 painter->setClipPath(oldPath); |
|
99 } |
|
100 painter->setClipping(clipped); |
|
101 } else { |
96 } else { |
102 painter->drawPixmap(topLeft, finalPixmap); |
97 painter->drawPixmap(topLeft, finalPixmap); |
103 } |
98 } |
104 } |
99 } |
105 |
100 |
120 pixmapData = QApplication::style()->generatedIconPixmap(iconMode, pixmapData, &opt); |
115 pixmapData = QApplication::style()->generatedIconPixmap(iconMode, pixmapData, &opt); |
121 } |
116 } |
122 iconPropertiesApplied = true; |
117 iconPropertiesApplied = true; |
123 } |
118 } |
124 |
119 |
125 QPixmap HbPixmapIconRenderer::getMaskedPixmap(HbMaskableIconImpl * maskIconData) |
120 QPixmap HbPixmapIconRenderer::getMaskedPixmap(HbMaskableIconImpl *maskIconData) |
126 { |
121 { |
127 QPixmap maskedPixmap; |
122 QPixmap maskedPixmap; |
128 |
123 |
129 HbPixmapIconMaskedData * mi = (HbPixmapIconMaskedData *)maskIconData->implData(); |
124 HbPixmapIconMaskedData *mi = (HbPixmapIconMaskedData *)maskIconData->implData(); |
130 if (maskIconData->maskChanged()) { |
125 if (maskIconData->maskChanged()) { |
131 if (!mi) { |
126 if (!mi) { |
132 mi = new HbPixmapIconMaskedData(); |
127 mi = new HbPixmapIconMaskedData(); |
133 } |
128 } |
134 |
129 |