summaryrefslogtreecommitdiffstats
path: root/kbarcode/rectitem.cpp
blob: 40ce7fa507a59edcd19b99593da2bcab5c5a2157 (plain)
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                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
                                                                          
    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 <tqdom.h>
#include <tqpainter.h>

RectItem::RectItem()
    : DocumentItem()
{
    init();
}

void RectItem::loadXML (TQDomElement* element)
{
    DocumentItem::loadXML( element );
    
    m_color = readXMLColor( element, "fill-color", TQt::white );
    m_filled = element->attribute( "filled", "0" ).toInt();
    m_circle = element->attribute( "circle", "0" ).toInt();
}

void RectItem::saveXML (TQDomElement* element)
{
    DocumentItem::saveXML( element );
    
    writeXMLColor( element, "fill-color", m_color );
    element->setAttribute( "filled", m_filled );
    element->setAttribute( "circle", m_circle );
}

void RectItem::draw (TQPainter* painter)
{
    if( m_circle )
    {
        if( m_filled )
        {
            painter->save();
            painter->setPen( TQPen( TQt::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( TQTextStream* stream )
{
    // TODO: refactor later and respect millimeters
    int thick = pen().width();
    
    *stream << ZPLUtils::fieldOrigin( rect().x(), rect().y() );
    if( m_circle )
        *stream << TQString("~GE%1,%2,%3,B").tqarg( rect().width() ).tqarg( rect().height() ).tqarg( thick );
    else
        *stream << TQString("~GB%1,%2,%3,B,0").tqarg( rect().width() ).tqarg( rect().height() ).tqarg( thick );
}

void RectItem::drawIpl( TQTextStream* 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();
        
        TQString s = TQString("W%1;").tqarg( counter ); // field number
    
        s += utils->fieldOrigin( rect().x(), rect().y() );
        s += TQString("l%1;").tqarg( rect().width() ); // box length
        s += TQString("h%1;").tqarg( rect().height() ); // box height
        s += TQString("w%1;").tqarg( thick );
    
        *stream << utils->field( s );
    }
}

void RectItem::drawEPcl( TQTextStream* stream )
{
    TQString s = TQString("C %1").tqarg( rect().x()+1 );
    s += TQString(" %1").tqarg( rect().y()+1 );
    s += TQString(" %1").tqarg( rect().width() );
    s += TQString(" %1").tqarg( rect().height() );
    s += TQString(" %1 2").tqarg( pen().width() );

    *stream << EPCLUtils::field( s );
}

void RectItem::init()
{
    m_color = TQt::white;
    m_filled = true;
    m_circle = false;
    setRect( TQRect( 0, 0, 20, 20 ) );
}

void RectItem::setColor (const TQColor & c) 
{
    m_color = c;    
}

TQColor 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;    
}