kivio

kivio_connector_point.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_stencil.h"
00023 
00024 KivioConnectorPoint::KivioConnectorPoint()
00025 {
00026     m_pTarget = 0L;
00027     m_pStencil = 0L;
00028     m_targetId = -1;
00029     m_connectable = true;
00030 }
00031 
00032 KivioConnectorPoint::KivioConnectorPoint( KivioStencil *pParent, bool conn )
00033 {
00034     m_pTarget = 0L;
00035     m_pStencil = pParent;
00036     m_targetId = -1;
00037     m_connectable = conn;
00038 }
00039 
00040 KivioConnectorPoint::~KivioConnectorPoint()
00041 {
00042     if( m_pTarget )
00043     {
00044         m_pTarget->removeConnectorPointFromList( this );
00045         m_pTarget = 0L;
00046     }
00047 
00048     m_pStencil = 0L;
00049 }
00050 
00060 void KivioConnectorPoint::setTarget( KivioConnectorTarget *pTarget  )
00061 {
00062    if( m_connectable == false )
00063    {
00064       return;
00065    }
00066 
00067     if( m_pTarget )
00068     {
00069          m_pTarget->removeConnectorPointFromList( this );
00070     }
00071 
00072 
00073     m_pTarget = pTarget;
00074 
00075     m_pos.setX(pTarget->x());
00076     m_pos.setY(pTarget->y());
00077 
00078     m_pTarget->addConnectorPointToList( this );
00079 }
00080 
00081 
00091 void KivioConnectorPoint::setX( double newX, bool updateStencil )
00092 {
00093   double oldX = m_pos.x();
00094   m_pos.setX(newX);
00095 
00096   if( updateStencil && m_pStencil )
00097     m_pStencil->updateConnectorPoints(this, oldX, m_pos.y());
00098 }
00099 
00100 
00110 void KivioConnectorPoint::setY( double newY, bool updateStencil )
00111 {
00112    double oldY = m_pos.y();
00113     m_pos.setY(newY);
00114 
00115     if( updateStencil && m_pStencil )
00116         m_pStencil->updateConnectorPoints(this, m_pos.x(), oldY);
00117 }
00118 
00119 
00130  void KivioConnectorPoint::setPosition( double newX, double newY, bool updateStencil )
00131 {
00132   double oldX = m_pos.x();
00133   double oldY = m_pos.y();
00134 
00135   m_pos.setCoords(newX, newY);
00136 
00137   if( updateStencil && m_pStencil )
00138     m_pStencil->updateConnectorPoints(this, oldX, oldY);
00139 }
00140 
00141 
00151 void KivioConnectorPoint::disconnect( bool removeFromTargetList )
00152 {
00153     if( m_pTarget )
00154     {
00155         if( removeFromTargetList == true )
00156             m_pTarget->removeConnectorPointFromList(this);
00157 
00158         m_pTarget = 0L;
00159         m_targetId = -1;
00160     }
00161 
00162 }
00163 
00164 
00172 bool KivioConnectorPoint::loadXML( const QDomElement &e )
00173 {
00174     m_pos.setX(XmlReadFloat( e, "x", 1.0f ));
00175     m_pos.setY(XmlReadFloat( e, "y", 1.0f ));
00176     m_targetId = XmlReadInt( e, "targetId", -1 );
00177     m_connectable = (bool)XmlReadInt( e, "connectable", (int)true );
00178 
00179     return true;
00180 }
00181 
00182 
00192 QDomElement KivioConnectorPoint::saveXML( QDomDocument &doc )
00193 {
00194     QDomElement e = doc.createElement("KivioConnectorPoint");
00195 
00196     XmlWriteFloat( e, "x", m_pos.x() );
00197     XmlWriteFloat( e, "y", m_pos.y() );
00198     XmlWriteInt( e, "connectable", (int)m_connectable );
00199 
00200     if( m_targetId != -1 )
00201         XmlWriteInt( e, "targetId", m_targetId );
00202 
00203     return e;
00204 }
00205 
00206 void KivioConnectorPoint::moveBy( double _x, double _y, bool updateStencil )
00207 {
00208    m_pos += KoPoint(_x, _y);
00209 
00210   if( updateStencil && m_pStencil )
00211     m_pStencil->updateConnectorPoints(this, _x, _y);
00212 }
00213 
00214 bool KivioConnectorPoint::isConnected()
00215 {
00216   return (m_pTarget != 0L);
00217 }
KDE Home | KDE Accessibility Home | Description of Access Keys