kivio
kivio_gradient.cpp
00001 /* 00002 * Kivio - Visual Modelling and Flowcharting 00003 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 #include "kivio_gradient.h" 00020 #include "kivio_point.h" 00027 KivioGradient::KivioGradient() 00028 : m_pColors(NULL), 00029 m_pPoints(NULL) 00030 { 00031 // Allocate the color list 00032 m_pColors = new QPtrList<QColor>; 00033 m_pColors->setAutoDelete(true); 00034 00035 // Allocate the point list 00036 m_pPoints = new QPtrList<KivioPoint>; 00037 m_pPoints->setAutoDelete(true); 00038 00039 m_gradientType = kgtNone; 00040 } 00041 00042 00048 KivioGradient::~KivioGradient() 00049 { 00050 if( m_pColors ) 00051 { 00052 delete m_pColors; 00053 m_pColors = NULL; 00054 } 00055 00056 if( m_pPoints ) 00057 { 00058 delete m_pPoints; 00059 m_pPoints = NULL; 00060 } 00061 } 00062 00063 00072 KivioGradient::KivioGradient( const KivioGradient &source ) 00073 : m_pColors(NULL), 00074 m_pPoints(NULL) 00075 { 00076 00077 m_gradientType = source.m_gradientType; 00078 00079 // Duplicate the colors list 00080 QColor *pColor; 00081 m_pColors = new QPtrList<QColor>; 00082 pColor = source.m_pColors->first(); 00083 while( pColor ) 00084 { 00085 m_pColors->append( new QColor(*pColor) ); 00086 00087 pColor = source.m_pColors->next(); 00088 } 00089 00090 00091 // Duplicate the point list 00092 KivioPoint *pPoint; 00093 m_pPoints = new QPtrList<KivioPoint>; 00094 pPoint = source.m_pPoints->first(); 00095 while( pPoint ) 00096 { 00097 m_pPoints->append( new KivioPoint( *pPoint ) ); 00098 00099 pPoint = source.m_pPoints->next(); 00100 } 00101 } 00102 00103 00111 void KivioGradient::copyInto( KivioGradient *pTarget ) const 00112 { 00113 if( !pTarget ) 00114 return; 00115 00116 // Copy the gradient type 00117 pTarget->m_gradientType = m_gradientType; 00118 00119 // Delete the old color array if we have one 00120 if( pTarget->m_pColors ) 00121 { 00122 delete pTarget->m_pColors; 00123 pTarget->m_pColors = NULL; 00124 } 00125 00126 // Allocate a new color array 00127 pTarget->m_pColors = new QPtrList<QColor>; 00128 pTarget->m_pColors->setAutoDelete(true); 00129 00130 00131 // Copy the colors 00132 QColor *pColor; 00133 pColor = m_pColors->first(); 00134 while( pColor ) 00135 { 00136 pTarget->m_pColors->append( new QColor(*pColor) ); 00137 00138 pColor = m_pColors->next(); 00139 } 00140 00141 if( pTarget->m_pPoints ) 00142 { 00143 delete pTarget->m_pPoints; 00144 pTarget->m_pPoints = NULL; 00145 } 00146 00147 pTarget->m_pPoints = new QPtrList<KivioPoint>; 00148 pTarget->m_pPoints->setAutoDelete(true); 00149 00150 KivioPoint *pPoint; 00151 pPoint = m_pPoints->first(); 00152 while( pPoint ) 00153 { 00154 pTarget->m_pPoints->append( new KivioPoint( *pPoint ) ); 00155 00156 pPoint = m_pPoints->next(); 00157 } 00158 } 00159 00160 00166 bool KivioGradient::loadXML( const QDomElement & ) 00167 { 00168 return false; 00169 } 00170 00171 00177 QDomElement KivioGradient::saveXML( QDomDocument &doc ) 00178 { 00179 00180 return doc.createElement("KivioGradient"); 00181 }