1 #include "graphicitems.h"
2 #include <QPainter>
3
itemRectangle(QMenu * cntxtMenu)4 itemRectangle:: itemRectangle(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
5 {
6 param.type=RECTANGLE;
7 }
8
drawItem(QPainter * painter)9 void itemRectangle::drawItem(QPainter *painter)
10 {
11 QPen lpen(pen());
12 lpen.setJoinStyle(Qt::MiterJoin);
13 painter->setPen(lpen);
14 painter->drawRect(param.rct);
15 }
16
17
18
itemEllipse(QMenu * cntxtMenu)19 itemEllipse:: itemEllipse(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
20 {
21
22 param.type=ELLIPSE;
23 }
24
drawItem(QPainter * painter)25 void itemEllipse::drawItem(QPainter *painter)
26 {
27 painter->drawEllipse(param.rct);
28 }
29
30
itemLine(QMenu * cntxtMenu)31 itemLine:: itemLine(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
32 {
33 param.type=LINE;
34 param.rct.setHeight(2);
35 }
36
drawItem(QPainter * painter)37 void itemLine::drawItem(QPainter *painter)
38 { QPen lpen(pen());
39 lpen.setCapStyle(Qt::FlatCap);
40 painter->setPen(lpen);
41 painter->drawLine(param.rct.x(),param.rct.y()+param.rct.height()/2,param.rct.x()+param.rct.width(),param.rct.y()+param.rct.height()/2);
42 }
43
44
45
itemImage(QMenu * cntxtMenu)46 itemImage:: itemImage(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
47 {
48 param.type=IMAGE;
49 }
50
drawItem(QPainter * painter)51 void itemImage::drawItem(QPainter *painter)
52 {
53 QImage tim;
54 qreal pad=pen().widthF()/2;
55 tim=param.im.scaled(param.rct.width(),param.rct.height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
56
57 painter->drawImage(param.rct.adjusted(2*pad,2*pad,-2*pad,-2*pad),tim);
58 drawBorder(painter);
59 }
60
61
itemReplayImage(QMenu * cntxtMenu)62 itemReplayImage:: itemReplayImage(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
63 {
64 param.type=REPLAY;
65 }
66
drawItem(QPainter * painter)67 void itemReplayImage::drawItem(QPainter *painter)
68 {
69 QImage tim;
70 qreal pad=pen().widthF()/2;
71 if (param.im.isNull())
72 {
73 QBrush b(Qt::black,Qt::Dense7Pattern);
74 painter->setPen(pen());
75 painter->setBrush(b);
76 painter->drawRect(param.rct.adjusted(2*pad,2*pad,-2*pad,-2*pad));
77
78 }
79 else
80 {
81 tim=param.im.scaled(param.rct.width(),param.rct.height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
82 painter->drawImage(param.rct.adjusted(2*pad,2*pad,-2*pad,-2*pad),tim);
83 }
84 drawBorder(painter);
85 }
86
87
88
itemText(QMenu * cntxtMenu)89 itemText:: itemText(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
90 {
91 param.type=TEXT;
92 param.font.setStyleStrategy(QFont::ForceOutline);
93 }
94
drawItem(QPainter * painter)95 void itemText::drawItem(QPainter *painter)
96 {
97 int i;
98 QPainterPath textPath;
99 QPainterPath testPath;
100 QPainterPath rectPath;
101 qreal height=0;
102 QStringList tlst=param.txt.split("\n");
103 testPath.addText(0,0,param.font,"AQag");
104 height=testPath.boundingRect().height()*1.2;
105 for(i=0;i<tlst.count();i++)
106 {
107 textPath.addText(0, i*height,param.font, tlst.at(i));
108 }
109 painter->setPen(pen());
110 if(param.gradient.type!=sgradientParam::NONE)
111 {
112 painter->setBrush(buildGradient(param.gradient,textPath.boundingRect()));
113
114
115 }
116 else
117 {
118 painter->setBrush(param.fillColor);
119 }
120 painter->drawPath(textPath);
121 // painter->drawPath(rectPath);
122
123 }
124
125
shape() const126 QPainterPath itemText::shape() const
127 {
128 int i;
129 QPainterPath textPath;
130 QPainterPath testPath;
131 QPainterPath shapePath;
132
133 textPath=QPainterPath();
134 QStringList tlst=param.txt.split("\n");
135 testPath.addText(0,0,param.font,"AQag");
136 qreal height=testPath.boundingRect().height();
137 for(i=0;i<tlst.count();i++)
138 {
139 textPath.addText(0, i*height*1.2,param.font, tlst.at(i));
140 }
141 shapePath.addRect(textPath.boundingRect());
142 return qt_graphicsItem_shapeFromPath(shapePath,pen());
143 }
144
145
setText(const QString & t)146 void itemText::setText(const QString &t)
147 {
148 param.modified=true;
149 param.txt=t;
150 update();
151 }
152
setFont(QFont f)153 void itemText::setFont(QFont f)
154 {
155 param.modified=true;
156 param.font=f;
157 param.font.setStyleStrategy(QFont::ForceOutline);
158 update();
159 }
160
itemBorder(QMenu * cntxtMenu)161 itemBorder:: itemBorder(QMenu *cntxtMenu) : graphItemBase(cntxtMenu)
162 {
163 param.type=SBORDER;
164 setRect(0,0,100,100);
165 setFlags(QGraphicsItem::QGraphicsItem::ItemIgnoresTransformations);
166 }
167
drawItem(QPainter * painter)168 void itemBorder::drawItem(QPainter *painter)
169 {
170 QPen pen(painter->pen());
171 pen.setColor(Qt::black);
172 pen.setWidth(1);
173 painter->setBrush(Qt::NoBrush);
174 painter->setPen(pen);
175 painter->drawRect(param.rct);
176 }
177
178