summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kiviosdk/kivio_gradient.cpp
blob: eaa35c3cdc7fc38bb3bb54e9ce0ef0f48512a8ee (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Kivio - Visual Modelling and Flowcharting
 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#include "kivio_gradient.h"
#include "kivio_point.h"
/**
 * Default constructor
 *
 * Allocates a new list of colors, and a new list of points for the
 * gradient.  Also, sets the gradient type to none.
 */
KivioGradient::KivioGradient()
    : m_pColors(NULL),
      m_pPoints(NULL)
{
    // Allocate the color list
    m_pColors = new TQPtrList<TQColor>;
    m_pColors->setAutoDelete(true);

    // Allocate the point list
    m_pPoints = new TQPtrList<KivioPoint>;
    m_pPoints->setAutoDelete(true);

    m_gradientType = kgtNone;
}


/**
 * Destructor
 *
 * Deletes the color and point lists.
 */
KivioGradient::~KivioGradient()
{
    if( m_pColors )
    {
        delete m_pColors;
        m_pColors = NULL;
    }

    if( m_pPoints )
    {
        delete m_pPoints;
        m_pPoints = NULL;
    }
}


/**
 * Copy constructor
 *
 * @param source The source @ref KivioGradient to copy from
 *
 * This creates a new KivioGradient as a copy of source.  New colors
 * and points are allocated.
 */
KivioGradient::KivioGradient( const KivioGradient &source )
    : m_pColors(NULL),
      m_pPoints(NULL)
{

    m_gradientType = source.m_gradientType;

    // Duplicate the colors list
    TQColor *pColor;
    m_pColors = new TQPtrList<TQColor>;
    pColor = source.m_pColors->first();
    while( pColor )
    {
        m_pColors->append( new TQColor(*pColor) );

        pColor = source.m_pColors->next();
    }


    // Duplicate the point list
    KivioPoint *pPoint;
    m_pPoints = new TQPtrList<KivioPoint>;
    pPoint = source.m_pPoints->first();
    while( pPoint )
    {
        m_pPoints->append( new KivioPoint( *pPoint ) );

        pPoint = source.m_pPoints->next();
    }
}


/**
 * Copy all attributes of this into pTarget
 *
 * @param pTarget The object to copy into
 *
 * This will copy all colors/points/everything-else into pTarget.
 */
void KivioGradient::copyInto( KivioGradient *pTarget ) const
{
    if( !pTarget )
        return;

    // Copy the gradient type
    pTarget->m_gradientType = m_gradientType;

    // Delete the old color array if we have one
    if( pTarget->m_pColors )
    {
        delete pTarget->m_pColors;
        pTarget->m_pColors = NULL;
    }

    // Allocate a new color array
    pTarget->m_pColors = new TQPtrList<TQColor>;
    pTarget->m_pColors->setAutoDelete(true);


    // Copy the colors
    TQColor *pColor;
    pColor = m_pColors->first();
    while( pColor )
    {
        pTarget->m_pColors->append( new TQColor(*pColor) );

        pColor = m_pColors->next();
    }

    if( pTarget->m_pPoints )
    {
        delete pTarget->m_pPoints;
        pTarget->m_pPoints = NULL;
    }

    pTarget->m_pPoints = new TQPtrList<KivioPoint>;
    pTarget->m_pPoints->setAutoDelete(true);

    KivioPoint *pPoint;
    pPoint = m_pPoints->first();
    while( pPoint )
    {
        pTarget->m_pPoints->append( new KivioPoint( *pPoint ) );

        pPoint = m_pPoints->next();
    }
}


/**
 * Load this object from an XML element
 *
 * FIXME: Implement this
 */
bool KivioGradient::loadXML( const TQDomElement & )
{
    return false;
}


/**
 * Save this object to an XML element
 *
 * FIXME: Implement this
 */
TQDomElement KivioGradient::saveXML( TQDomDocument &doc )
{

    return doc.createElement("KivioGradient");
}