1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/***************************************************************************
rectitem.cpp - description
-------------------
begin : Do Sep 2 2004
copyright : (C) 2004 by Dominik Seichter
email : [email protected]
***************************************************************************/
/***************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#include "rectitem.h"
#include <qdom.h>
#include <qpainter.h>
RectItem::RectItem()
: DocumentItem()
{
init();
}
void RectItem::loadXML (QDomElement* element)
{
DocumentItem::loadXML( element );
m_color = readXMLColor( element, "fill-color", Qt::white );
m_filled = element->attribute( "filled", "0" ).toInt();
m_circle = element->attribute( "circle", "0" ).toInt();
}
void RectItem::saveXML (QDomElement* element)
{
DocumentItem::saveXML( element );
writeXMLColor( element, "fill-color", m_color );
element->setAttribute( "filled", m_filled );
element->setAttribute( "circle", m_circle );
}
void RectItem::draw (QPainter* painter)
{
if( m_circle )
{
if( m_filled )
{
painter->save();
painter->setPen( QPen( Qt::NoPen ) );
painter->setBrush( m_color );
painter->drawEllipse( rect() );
painter->restore();
}
if( border() )
{
painter->save();
painter->setPen( pen() );
painter->drawEllipse( rect() );
painter->restore();
}
}
else
{
if( m_filled )
painter->fillRect( rect(), m_color );
DocumentItem::drawBorder( painter );
}
}
void RectItem::drawZpl( QTextStream* stream )
{
// TODO: refactor later and respect millimeters
int thick = pen().width();
*stream << ZPLUtils::fieldOrigin( rect().x(), rect().y() );
if( m_circle )
*stream << QString("~GE%1,%2,%3,B").arg( rect().width() ).arg( rect().height() ).arg( thick );
else
*stream << QString("~GB%1,%2,%3,B,0").arg( rect().width() ).arg( rect().height() ).arg( thick );
}
void RectItem::drawIpl( QTextStream* stream, IPLUtils* utils )
{
// TODO: refactor later and respect millimeters
int thick = pen().width();
if( m_circle )
qDebug("Cirlce not implemented for IPL");
else
{
int counter = utils->counter();
QString s = QString("W%1;").arg( counter ); // field number
s += utils->fieldOrigin( rect().x(), rect().y() );
s += QString("l%1;").arg( rect().width() ); // box length
s += QString("h%1;").arg( rect().height() ); // box height
s += QString("w%1;").arg( thick );
*stream << utils->field( s );
}
}
void RectItem::drawEPcl( QTextStream* stream )
{
QString s = QString("C %1").arg( rect().x()+1 );
s += QString(" %1").arg( rect().y()+1 );
s += QString(" %1").arg( rect().width() );
s += QString(" %1").arg( rect().height() );
s += QString(" %1 2").arg( pen().width() );
*stream << EPCLUtils::field( s );
}
void RectItem::init()
{
m_color = Qt::white;
m_filled = true;
m_circle = false;
setRect( QRect( 0, 0, 20, 20 ) );
}
void RectItem::setColor (const QColor & c)
{
m_color = c;
}
QColor RectItem::color () const
{
return m_color;
}
void RectItem::setFilled (bool f)
{
m_filled = f;
}
bool RectItem::filled () const
{
return m_filled;
}
void RectItem::setCircle (bool b)
{
m_circle = b;
}
bool RectItem::circle () const
{
return m_circle;
}
|