kivio

kivio_connector_target.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_common.h"
00020 #include "kivio_connector_point.h"
00021 #include "kivio_connector_target.h"
00022 #include "kivio_point.h"
00023 #include "kivio_stencil.h"
00024 #include "kivio_intra_stencil_data.h"
00025 
00026 #include <kdebug.h>
00027 
00028 KivioConnectorTarget::KivioConnectorTarget()
00029     : m_pConnectors(NULL)
00030 {
00031     m_position.setX( 0.0f );
00032     m_position.setY( 0.0f );
00033     m_pConnectors = new QPtrList<KivioConnectorPoint>;
00034     m_pConnectors->setAutoDelete(false);
00035     m_id = -1;
00036     m_xOffset = m_yOffset = 0;
00037 }
00038 
00039 KivioConnectorTarget::KivioConnectorTarget(double x, double y)
00040 {
00041     m_position.setX( x );
00042     m_position.setY( y );
00043     m_pConnectors = new QPtrList<KivioConnectorPoint>;
00044     m_pConnectors->setAutoDelete(false);
00045 
00046     m_id = -1;
00047     m_xOffset = m_yOffset = 0;
00048 }
00049 
00050 KivioConnectorTarget::KivioConnectorTarget(double x, double y, double xOffset, double yOffset)
00051 {
00052     m_position.setX( x );
00053     m_position.setY( y );
00054     m_pConnectors = new QPtrList<KivioConnectorPoint>;
00055     m_pConnectors->setAutoDelete(false);
00056 
00057     m_id = -1;
00058     setOffsets(xOffset, yOffset);
00059 }
00060 
00067 KivioConnectorTarget *KivioConnectorTarget::duplicate()
00068 {
00069     KivioConnectorTarget *pTarget = new KivioConnectorTarget( m_position.x(), m_position.y(), m_xOffset, m_yOffset );
00070 
00071     return pTarget;
00072 }
00073 
00074 
00081 KivioConnectorTarget::~KivioConnectorTarget()
00082 {
00083     // Iterate through all connectors diconnecting them from this
00084     KivioConnectorPoint *point;
00085 
00086     if( m_pConnectors )
00087     {
00088         point = m_pConnectors->first();
00089         point = m_pConnectors->take();
00090 
00091         while( point )
00092         {
00093        kdDebug(43000) << "KivioConnectorTarget:: -> diconnecting" << endl;
00094 
00095             // Disconnect the point.  But tell the point to not call
00096             // KivioConnectorTarget::removeConnectorFromList() because it will cause our
00097             // position in the list to be screwed up.
00098             point->disconnect( false );
00099 
00100             point = m_pConnectors->take();
00101         }
00102 
00103         delete m_pConnectors;
00104         m_pConnectors = NULL;
00105     }
00106 }
00107 
00108 
00112 bool KivioConnectorTarget::loadXML( const QDomElement &e )
00113 {
00114     if( e.tagName().compare( "KivioConnectorTarget" ) != 0 )
00115     {
00116        kdDebug(43000) << "Attempted to load KivioConnectorTarget from non-KivioConnectorTarget element" << endl;
00117         return false;
00118     }
00119 
00120     m_position.setX(XmlReadFloat( e, "x", 1.0f ));
00121     m_position.setY(XmlReadFloat( e, "y", 1.0f ));
00122 
00123     m_id = XmlReadInt( e, "id", -1 );
00124 
00125     return true;
00126 }
00127 
00128 
00132 QDomElement KivioConnectorTarget::saveXML( QDomDocument &doc )
00133 {
00134     QDomElement e;
00135 
00136     e = doc.createElement("KivioConnectorTarget");
00137 
00138     XmlWriteFloat( e, "x", m_position.x() );
00139     XmlWriteFloat( e, "y", m_position.y() );
00140 
00141     if( m_id != -1 )
00142         XmlWriteInt( e, "id", m_id );
00143 
00144     return e;
00145 }
00146 
00147 
00151 void KivioConnectorTarget::addConnectorPointToList( KivioConnectorPoint *p )
00152 {
00153     if( p )
00154         m_pConnectors->append(p);
00155 }
00156 
00157 
00166 bool KivioConnectorTarget::removeConnectorPointFromList( KivioConnectorPoint *p )
00167 {
00168     if( !p )
00169         return false;
00170 
00171 
00172     return m_pConnectors->remove(p);
00173 }
00174 
00175 
00179 void KivioConnectorTarget::setX( float _x )
00180 {
00181     m_position.setX(_x);
00182 
00183     KivioConnectorPoint *pPoint = m_pConnectors->first();
00184     while( pPoint )
00185     {
00186         pPoint->setX( _x, true );
00187 
00188         pPoint = m_pConnectors->next();
00189     }
00190 }
00191 
00192 
00197 void KivioConnectorTarget::setY( float _y )
00198 {
00199     m_position.setY(_y);
00200 
00201     KivioConnectorPoint *pPoint = m_pConnectors->first();
00202     while( pPoint )
00203     {
00204         pPoint->setY( _y, true );
00205 
00206         pPoint = m_pConnectors->next();
00207     }
00208 }
00209 
00210 
00215 void KivioConnectorTarget::setPosition( float _x, float _y )
00216 {
00217     m_position.setX( _x );
00218     m_position.setY( _y );
00219 
00220     KivioConnectorPoint *pPoint = m_pConnectors->first();
00221     while( pPoint )
00222     {
00223         pPoint->setPosition( _x, _y, true );
00224 
00225         pPoint = m_pConnectors->next();
00226     }
00227 }
00228 
00229 
00233 void KivioConnectorTarget::paintOutline( KivioIntraStencilData *pData )
00234 {
00235     KivioConnectorPoint *pPoint;
00236     KivioStencil *pStencil;
00237 
00238     pPoint = m_pConnectors->first();
00239     while( pPoint )
00240     {
00241         pStencil = pPoint->stencil();
00242 
00243         if( pStencil )
00244             pStencil->paintOutline( pData );
00245 
00246         pPoint = m_pConnectors->next();
00247     }
00248 }
00249 
00250 
00254 bool KivioConnectorTarget::hasConnections()
00255 {
00256     KivioConnectorPoint *pPoint = m_pConnectors->first();
00257 
00258     if( pPoint )
00259         return true;
00260 
00261     return false;
00262 }
00263 
00264 
00268 void KivioConnectorTarget::setId( int i )
00269 {
00270     KivioConnectorPoint *pPoint = m_pConnectors->first();
00271     m_id= i;
00272 
00273     while( pPoint )
00274     {
00275         pPoint->setTargetId( i );
00276 
00277         pPoint = m_pConnectors->next();
00278     }
00279 }
00280 
00281 void KivioConnectorTarget::setOffsets(double x, double y)
00282 {
00283   m_xOffset = x;
00284   m_yOffset = y;
00285 }
KDE Home | KDE Accessibility Home | Description of Access Keys