insilmaril@0
|
1 |
#include "frameobj.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include <qcolor.h>
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
6 |
// FrameObj
|
insilmaril@0
|
7 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
8 |
FrameObj::FrameObj() : MapObj()
|
insilmaril@0
|
9 |
{
|
insilmaril@0
|
10 |
// cout << "Const FrameObj ()\n";
|
insilmaril@0
|
11 |
init ();
|
insilmaril@0
|
12 |
}
|
insilmaril@0
|
13 |
|
insilmaril@408
|
14 |
FrameObj::FrameObj(QGraphicsScene *s) :MapObj(s)
|
insilmaril@0
|
15 |
{
|
insilmaril@0
|
16 |
// cout << "Const FrameObj\n";
|
insilmaril@0
|
17 |
init ();
|
insilmaril@0
|
18 |
}
|
insilmaril@0
|
19 |
|
insilmaril@0
|
20 |
FrameObj::~FrameObj()
|
insilmaril@0
|
21 |
{
|
insilmaril@0
|
22 |
clear();
|
insilmaril@0
|
23 |
}
|
insilmaril@0
|
24 |
|
insilmaril@0
|
25 |
void FrameObj::init()
|
insilmaril@0
|
26 |
{
|
insilmaril@0
|
27 |
type=NoFrame;
|
insilmaril@470
|
28 |
padding=10;
|
insilmaril@470
|
29 |
borderWidth=1;
|
insilmaril@442
|
30 |
penColor=QColor (Qt::black);
|
insilmaril@442
|
31 |
brushColor=QColor (Qt::white);
|
insilmaril@0
|
32 |
}
|
insilmaril@0
|
33 |
|
insilmaril@0
|
34 |
void FrameObj::clear()
|
insilmaril@0
|
35 |
{
|
insilmaril@0
|
36 |
switch (type)
|
insilmaril@0
|
37 |
{
|
insilmaril@0
|
38 |
case NoFrame:
|
insilmaril@0
|
39 |
break;
|
insilmaril@0
|
40 |
case Rectangle:
|
insilmaril@0
|
41 |
delete rectFrame;
|
insilmaril@0
|
42 |
break;
|
insilmaril@421
|
43 |
case Ellipse:
|
insilmaril@421
|
44 |
delete ellipseFrame;
|
insilmaril@421
|
45 |
break;
|
insilmaril@0
|
46 |
}
|
insilmaril@0
|
47 |
type=NoFrame;
|
insilmaril@470
|
48 |
padding=0;
|
insilmaril@0
|
49 |
}
|
insilmaril@0
|
50 |
|
insilmaril@0
|
51 |
void FrameObj::move(double x, double y)
|
insilmaril@0
|
52 |
{
|
insilmaril@0
|
53 |
switch (type)
|
insilmaril@0
|
54 |
{
|
insilmaril@0
|
55 |
case NoFrame:
|
insilmaril@0
|
56 |
break;
|
insilmaril@0
|
57 |
case Rectangle:
|
insilmaril@408
|
58 |
rectFrame->setPos (x,y);
|
insilmaril@0
|
59 |
break;
|
insilmaril@421
|
60 |
case Ellipse:
|
insilmaril@421
|
61 |
ellipseFrame->setPos (x,y);
|
insilmaril@421
|
62 |
break;
|
insilmaril@0
|
63 |
}
|
insilmaril@0
|
64 |
}
|
insilmaril@0
|
65 |
|
insilmaril@0
|
66 |
void FrameObj::moveBy(double x, double y)
|
insilmaril@0
|
67 |
{
|
insilmaril@0
|
68 |
MapObj::moveBy (x,y);
|
insilmaril@0
|
69 |
}
|
insilmaril@0
|
70 |
|
insilmaril@0
|
71 |
void FrameObj::positionBBox()
|
insilmaril@0
|
72 |
{
|
insilmaril@0
|
73 |
}
|
insilmaril@0
|
74 |
|
insilmaril@0
|
75 |
void FrameObj::calcBBoxSize()
|
insilmaril@0
|
76 |
{
|
insilmaril@0
|
77 |
}
|
insilmaril@0
|
78 |
|
insilmaril@408
|
79 |
void FrameObj::setRect(const QRectF &r)
|
insilmaril@0
|
80 |
{
|
insilmaril@0
|
81 |
bbox=r;
|
insilmaril@0
|
82 |
switch (type)
|
insilmaril@0
|
83 |
{
|
insilmaril@0
|
84 |
case NoFrame:
|
insilmaril@0
|
85 |
break;
|
insilmaril@0
|
86 |
case Rectangle:
|
insilmaril@425
|
87 |
// rectFrame->prepareGeometryChange();
|
insilmaril@408
|
88 |
rectFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
|
insilmaril@0
|
89 |
break;
|
insilmaril@421
|
90 |
case Ellipse:
|
insilmaril@425
|
91 |
// ellipseFrame->prepareGeometryChange();
|
insilmaril@421
|
92 |
ellipseFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
|
insilmaril@421
|
93 |
break;
|
insilmaril@0
|
94 |
}
|
insilmaril@0
|
95 |
}
|
insilmaril@0
|
96 |
|
insilmaril@470
|
97 |
void FrameObj::setPadding (const int &i)
|
insilmaril@0
|
98 |
{
|
insilmaril@470
|
99 |
padding=i;
|
insilmaril@470
|
100 |
repaint();
|
insilmaril@0
|
101 |
}
|
insilmaril@0
|
102 |
|
insilmaril@470
|
103 |
int FrameObj::getPadding()
|
insilmaril@470
|
104 |
{
|
insilmaril@470
|
105 |
if (type==NoFrame)
|
insilmaril@470
|
106 |
return 0;
|
insilmaril@470
|
107 |
else
|
insilmaril@470
|
108 |
return padding;
|
insilmaril@470
|
109 |
}
|
insilmaril@470
|
110 |
|
insilmaril@470
|
111 |
void FrameObj::setBorderWidth (const int &i)
|
insilmaril@470
|
112 |
{
|
insilmaril@470
|
113 |
borderWidth=i;
|
insilmaril@470
|
114 |
repaint();
|
insilmaril@470
|
115 |
}
|
insilmaril@470
|
116 |
|
insilmaril@470
|
117 |
int FrameObj::getBorderWidth()
|
insilmaril@470
|
118 |
{
|
insilmaril@470
|
119 |
return borderWidth;
|
insilmaril@470
|
120 |
}
|
insilmaril@470
|
121 |
|
insilmaril@470
|
122 |
FrameObj::FrameType FrameObj::getFrameType()
|
insilmaril@0
|
123 |
{
|
insilmaril@0
|
124 |
return type;
|
insilmaril@0
|
125 |
}
|
insilmaril@0
|
126 |
|
insilmaril@0
|
127 |
QString FrameObj::getFrameTypeName()
|
insilmaril@0
|
128 |
{
|
insilmaril@0
|
129 |
switch (type)
|
insilmaril@0
|
130 |
{
|
insilmaril@0
|
131 |
case Rectangle:
|
insilmaril@0
|
132 |
return "Rectangle";
|
insilmaril@0
|
133 |
break;
|
insilmaril@421
|
134 |
case Ellipse:
|
insilmaril@421
|
135 |
return "Ellipse";
|
insilmaril@421
|
136 |
break;
|
insilmaril@0
|
137 |
default:
|
insilmaril@0
|
138 |
return "NoFrame";
|
insilmaril@0
|
139 |
}
|
insilmaril@0
|
140 |
}
|
insilmaril@0
|
141 |
|
insilmaril@0
|
142 |
void FrameObj::setFrameType(const FrameType &t)
|
insilmaril@0
|
143 |
{
|
insilmaril@0
|
144 |
if (t!=type)
|
insilmaril@0
|
145 |
{
|
insilmaril@0
|
146 |
clear();
|
insilmaril@0
|
147 |
type=t;
|
insilmaril@0
|
148 |
switch (type)
|
insilmaril@0
|
149 |
{
|
insilmaril@0
|
150 |
case NoFrame:
|
insilmaril@0
|
151 |
break;
|
insilmaril@0
|
152 |
case Rectangle:
|
insilmaril@442
|
153 |
rectFrame = scene->addRect(QRectF(0,0,0,0), QPen(penColor), brushColor);
|
insilmaril@408
|
154 |
rectFrame->setZValue(Z_FRAME);
|
insilmaril@442
|
155 |
rectFrame->show();
|
insilmaril@421
|
156 |
break;
|
insilmaril@421
|
157 |
case Ellipse:
|
insilmaril@442
|
158 |
ellipseFrame = scene->addEllipse(QRectF(0,0,0,0), QPen(penColor), brushColor);
|
insilmaril@421
|
159 |
ellipseFrame->setZValue(Z_FRAME);
|
insilmaril@442
|
160 |
ellipseFrame->show();
|
insilmaril@0
|
161 |
break;
|
insilmaril@0
|
162 |
}
|
insilmaril@0
|
163 |
}
|
insilmaril@442
|
164 |
setVisibility (visible);
|
insilmaril@0
|
165 |
}
|
insilmaril@0
|
166 |
|
insilmaril@0
|
167 |
void FrameObj::setFrameType(const QString &t)
|
insilmaril@0
|
168 |
{
|
insilmaril@0
|
169 |
if (t=="Rectangle")
|
insilmaril@0
|
170 |
FrameObj::setFrameType (Rectangle);
|
insilmaril@421
|
171 |
else if (t=="Ellipse")
|
insilmaril@421
|
172 |
FrameObj::setFrameType (Ellipse);
|
insilmaril@0
|
173 |
else
|
insilmaril@0
|
174 |
FrameObj::setFrameType (NoFrame);
|
insilmaril@0
|
175 |
}
|
insilmaril@0
|
176 |
|
insilmaril@442
|
177 |
void FrameObj::setPenColor (QColor col)
|
insilmaril@442
|
178 |
{
|
insilmaril@442
|
179 |
penColor=col;
|
insilmaril@442
|
180 |
repaint();
|
insilmaril@442
|
181 |
}
|
insilmaril@442
|
182 |
|
insilmaril@442
|
183 |
QColor FrameObj::getPenColor ()
|
insilmaril@442
|
184 |
{
|
insilmaril@442
|
185 |
return penColor;
|
insilmaril@442
|
186 |
}
|
insilmaril@442
|
187 |
|
insilmaril@442
|
188 |
void FrameObj::setBrushColor (QColor col)
|
insilmaril@442
|
189 |
{
|
insilmaril@442
|
190 |
brushColor=col;
|
insilmaril@442
|
191 |
repaint();
|
insilmaril@442
|
192 |
}
|
insilmaril@442
|
193 |
|
insilmaril@442
|
194 |
QColor FrameObj::getBrushColor ()
|
insilmaril@442
|
195 |
{
|
insilmaril@442
|
196 |
return brushColor;
|
insilmaril@442
|
197 |
}
|
insilmaril@442
|
198 |
|
insilmaril@442
|
199 |
void FrameObj::repaint()
|
insilmaril@442
|
200 |
{
|
insilmaril@470
|
201 |
QPen pen;
|
insilmaril@470
|
202 |
pen.setColor (penColor);
|
insilmaril@470
|
203 |
pen.setWidth (borderWidth);
|
insilmaril@470
|
204 |
QBrush brush (brushColor);
|
insilmaril@442
|
205 |
switch (type)
|
insilmaril@442
|
206 |
{
|
insilmaril@442
|
207 |
case Rectangle:
|
insilmaril@470
|
208 |
rectFrame->setPen (pen);
|
insilmaril@470
|
209 |
rectFrame->setBrush (brush);
|
insilmaril@442
|
210 |
break;
|
insilmaril@442
|
211 |
case Ellipse:
|
insilmaril@470
|
212 |
ellipseFrame->setPen (pen);
|
insilmaril@470
|
213 |
ellipseFrame->setBrush (brush);
|
insilmaril@442
|
214 |
break;
|
insilmaril@442
|
215 |
default:
|
insilmaril@442
|
216 |
break;
|
insilmaril@442
|
217 |
}
|
insilmaril@442
|
218 |
}
|
insilmaril@442
|
219 |
|
insilmaril@442
|
220 |
|
insilmaril@0
|
221 |
void FrameObj::setVisibility (bool v)
|
insilmaril@0
|
222 |
{
|
insilmaril@0
|
223 |
MapObj::setVisibility(v);
|
insilmaril@140
|
224 |
switch (type)
|
insilmaril@140
|
225 |
{
|
insilmaril@140
|
226 |
case NoFrame:
|
insilmaril@140
|
227 |
break;
|
insilmaril@140
|
228 |
case Rectangle:
|
insilmaril@140
|
229 |
if (visible)
|
insilmaril@140
|
230 |
rectFrame->show();
|
insilmaril@140
|
231 |
else
|
insilmaril@140
|
232 |
rectFrame->hide();
|
insilmaril@140
|
233 |
break;
|
insilmaril@421
|
234 |
case Ellipse:
|
insilmaril@421
|
235 |
if (visible)
|
insilmaril@421
|
236 |
ellipseFrame->show();
|
insilmaril@421
|
237 |
else
|
insilmaril@421
|
238 |
ellipseFrame->hide();
|
insilmaril@421
|
239 |
break;
|
insilmaril@140
|
240 |
}
|
insilmaril@0
|
241 |
}
|
insilmaril@0
|
242 |
|
insilmaril@421
|
243 |
QString FrameObj::saveToDir ()
|
insilmaril@421
|
244 |
{
|
insilmaril@470
|
245 |
if (type==NoFrame) return QString();
|
insilmaril@421
|
246 |
QString frameTypeAttr=attribut ("frameType",getFrameTypeName());
|
insilmaril@442
|
247 |
QString penColAttr=attribut ("penColor",penColor.name() );
|
insilmaril@442
|
248 |
QString brushColAttr=attribut ("brushColor",brushColor.name() );
|
insilmaril@470
|
249 |
QString paddingAttr=attribut ("padding",QString::number (padding) );
|
insilmaril@470
|
250 |
QString borderWidthAttr=attribut ("borderWidth",QString::number (borderWidth) );
|
insilmaril@470
|
251 |
return singleElement (
|
insilmaril@470
|
252 |
"frame",frameTypeAttr +
|
insilmaril@470
|
253 |
penColAttr +
|
insilmaril@470
|
254 |
brushColAttr +
|
insilmaril@470
|
255 |
paddingAttr +
|
insilmaril@470
|
256 |
borderWidthAttr);
|
insilmaril@421
|
257 |
}
|
insilmaril@421
|
258 |
|