kivio

kivio_gradient.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_gradient.h"
20#include "kivio_point.h"
27KivioGradient::KivioGradient()
28 : m_pColors(NULL),
29 m_pPoints(NULL)
30{
31 // Allocate the color list
32 m_pColors = new TQPtrList<TQColor>;
33 m_pColors->setAutoDelete(true);
34
35 // Allocate the point list
36 m_pPoints = new TQPtrList<KivioPoint>;
37 m_pPoints->setAutoDelete(true);
38
39 m_gradientType = kgtNone;
40}
41
42
48KivioGradient::~KivioGradient()
49{
50 if( m_pColors )
51 {
52 delete m_pColors;
53 m_pColors = NULL;
54 }
55
56 if( m_pPoints )
57 {
58 delete m_pPoints;
59 m_pPoints = NULL;
60 }
61}
62
63
72KivioGradient::KivioGradient( const KivioGradient &source )
73 : m_pColors(NULL),
74 m_pPoints(NULL)
75{
76
77 m_gradientType = source.m_gradientType;
78
79 // Duplicate the colors list
80 TQColor *pColor;
81 m_pColors = new TQPtrList<TQColor>;
82 pColor = source.m_pColors->first();
83 while( pColor )
84 {
85 m_pColors->append( new TQColor(*pColor) );
86
87 pColor = source.m_pColors->next();
88 }
89
90
91 // Duplicate the point list
92 KivioPoint *pPoint;
93 m_pPoints = new TQPtrList<KivioPoint>;
94 pPoint = source.m_pPoints->first();
95 while( pPoint )
96 {
97 m_pPoints->append( new KivioPoint( *pPoint ) );
98
99 pPoint = source.m_pPoints->next();
100 }
101}
102
103
111void KivioGradient::copyInto( KivioGradient *pTarget ) const
112{
113 if( !pTarget )
114 return;
115
116 // Copy the gradient type
117 pTarget->m_gradientType = m_gradientType;
118
119 // Delete the old color array if we have one
120 if( pTarget->m_pColors )
121 {
122 delete pTarget->m_pColors;
123 pTarget->m_pColors = NULL;
124 }
125
126 // Allocate a new color array
127 pTarget->m_pColors = new TQPtrList<TQColor>;
128 pTarget->m_pColors->setAutoDelete(true);
129
130
131 // Copy the colors
132 TQColor *pColor;
133 pColor = m_pColors->first();
134 while( pColor )
135 {
136 pTarget->m_pColors->append( new TQColor(*pColor) );
137
138 pColor = m_pColors->next();
139 }
140
141 if( pTarget->m_pPoints )
142 {
143 delete pTarget->m_pPoints;
144 pTarget->m_pPoints = NULL;
145 }
146
147 pTarget->m_pPoints = new TQPtrList<KivioPoint>;
148 pTarget->m_pPoints->setAutoDelete(true);
149
150 KivioPoint *pPoint;
151 pPoint = m_pPoints->first();
152 while( pPoint )
153 {
154 pTarget->m_pPoints->append( new KivioPoint( *pPoint ) );
155
156 pPoint = m_pPoints->next();
157 }
158}
159
160
166bool KivioGradient::loadXML( const TQDomElement & )
167{
168 return false;
169}
170
171
177TQDomElement KivioGradient::saveXML( TQDomDocument &doc )
178{
179
180 return doc.createElement("KivioGradient");
181}