diff options
Diffstat (limited to 'kivio/plugins/kivioconnectortool/straight_connector')
4 files changed, 547 insertions, 0 deletions
diff --git a/kivio/plugins/kivioconnectortool/straight_connector/Makefile.am b/kivio/plugins/kivioconnectortool/straight_connector/Makefile.am new file mode 100644 index 00000000..47d68538 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/Makefile.am @@ -0,0 +1,32 @@ +stencildir = $(kde_datadir)/kivio/autoloadStencils +stencil_DATA = straight_connector.xpm + +kde_module_LTLIBRARIES =straight_connector.la + +straight_connector_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) + +# Hack to make it work (dave m) +straight_connector_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOTEXT_INCLUDES)\ + $(KOFFICE_INCLUDES) $(all_includes) +METASOURCES = AUTO + +straight_connector_la_SOURCES = \ + straight_connector.cpp +EXTRA_DIST = \ + straight_connector.cpp\ + straight_connector.h\ + straight_connector.xpm + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(stencildir) + -rm -f $(DESTDIR)$(stencildir)/straight_connector.so + $(LN_S) $(kde_moduledir)/straight_connector.so $(DESTDIR)$(stencildir)/straight_connector.so + +uninstall-local: + -rm -f $(DESTDIR)$(stencildir)/straight_connector.so + diff --git a/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.cpp b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.cpp new file mode 100644 index 00000000..233c7ab8 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.cpp @@ -0,0 +1,379 @@ +/* + * 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 <stdio.h> +#include <math.h> +#include "straight_connector.h" + +#include "kivio_common.h" +#include "kivio_connector_target.h" +#include "kivio_layer.h" +#include "kivio_line_style.h" +#include "kivio_page.h" +#include "kivio_painter.h" +#include "kivio_stencil.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_text_style.h" +#include "tkmath.h" + +#include <qcolor.h> +#include <qpixmap.h> +#include <kdebug.h> +#include <KoZoomHandler.h> + +#include "straight_connector.xpm" + + +static QPixmap *pIcon = NULL; + +static KivioStencilSpawnerInfo sinfo = KivioStencilSpawnerInfo("Dave Marotti", "Straight Connector", "Dave Marotti - Straight Connector", "Basic Straight Connector", "0.1", "http://localhost/", "", "off"); + +#include <kgenericfactory.h> +K_EXPORT_COMPONENT_FACTORY( straight_connector, KGenericFactory<KivioConnectorFactory>( "KivioConnectorFactory" ) ) + +KivioConnectorFactory::KivioConnectorFactory(QObject *parent, const char* name, const QStringList& args) : + KivioStencilFactory(parent, name, args) +{ + kdDebug(43000) << "new straight line connector factory: " << endl; +} + +KivioStencil *KivioConnectorFactory::NewStencil() +{ + return new KivioStraightConnector(); +} + +KivioStencil *KivioConnectorFactory::NewStencil(const QString&) +{ + return new KivioStraightConnector(); +} + +//FIXME: Is this a memory leak? +QPixmap *KivioConnectorFactory::GetIcon() +{ + if( pIcon ) + return pIcon; + + pIcon = new QPixmap( (const char **)straight_connector_xpm ); + return pIcon; +} + +KivioStencilSpawnerInfo *KivioConnectorFactory::GetSpawnerInfo() +{ + return &sinfo; +} + + +KivioStraightConnector::KivioStraightConnector() + : Kivio1DStencil() +{ + m_pStart->setPosition(0.0f, 0.0f, false); + m_pEnd->setPosition(72.0f, 72.0f, false); + + m_startAH = new KivioArrowHead(); + m_endAH = new KivioArrowHead(); + m_needsWidth = false; + m_needsText = true; + + m_pCanProtect->clearBit( kpAspect ); + m_pCanProtect->clearBit( kpWidth ); + m_pCanProtect->clearBit( kpHeight ); + m_pCanProtect->clearBit( kpX ); + m_pCanProtect->clearBit( kpY ); + + // This is a stencil of type connector + setType(kstConnector); +} + +KivioStraightConnector::~KivioStraightConnector() +{ + delete m_startAH; + delete m_endAH; +} + +void KivioStraightConnector::setStartPoint( double x, double y ) +{ + m_pStart->setPosition( x, y, false ); + m_pStart->disconnect(); +} + +void KivioStraightConnector::setEndPoint( double x, double y ) +{ + m_pEnd->setPosition( x, y, false ); + m_pEnd->disconnect(); + + if( m_needsText ) + { + m_pTextConn->setPosition( (m_pStart->x()+m_pEnd->x())/2.0f, + (m_pStart->y()+m_pEnd->y())/2.0f, + false ); + } +} + +KivioCollisionType KivioStraightConnector::checkForCollision( KoPoint *p, double threshold ) +{ + const double end_thresh = 4.0f; + + double px = p->x(); + double py = p->y(); + + KivioConnectorPoint *pPoint; + + int i = kctCustom + 1; + pPoint = m_pConnectorPoints->first(); + while( pPoint ) + { + if( px >= pPoint->x() - end_thresh && + px <= pPoint->x() + end_thresh && + py >= pPoint->y() - end_thresh && + py <= pPoint->y() + end_thresh ) + { + return (KivioCollisionType)i; + } + + i++; + pPoint = m_pConnectorPoints->next(); + } + + + if( collisionLine( m_pStart->x(), m_pStart->y(), + m_pEnd->x(), m_pEnd->y(), + px, py, + threshold ) ) + { + return kctBody; + } + + return kctNone; +} + +KivioStencil *KivioStraightConnector::duplicate() +{ + KivioStraightConnector *pStencil = new KivioStraightConnector(); + + copyBasicInto( pStencil ); + + // Copy the arrow head information + pStencil->setStartAHType( m_startAH->type() ); + pStencil->setStartAHWidth( m_startAH->width() ); + pStencil->setStartAHLength( m_startAH->length() ); + + pStencil->setEndAHType( m_endAH->type() ); + pStencil->setEndAHWidth( m_endAH->width() ); + pStencil->setEndAHLength( m_endAH->length() ); + + *(pStencil->protection()) = *m_pProtection; + *(pStencil->canProtect()) = *m_pCanProtect; + + return pStencil; +} + +void KivioStraightConnector::paint( KivioIntraStencilData *pData ) +{ + KivioPainter *painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + double x1, y1, x2, y2; + double vecX, vecY; + double len; + + + painter->setLineStyle(m_pLineStyle); + double lineWidth = m_pLineStyle->width(); + painter->setLineWidth(zoomHandler->zoomItY(lineWidth)); + + x1 = zoomHandler->zoomItX(m_pStart->x()); + x2 = zoomHandler->zoomItX(m_pEnd->x()); + + y1 = zoomHandler->zoomItY(m_pStart->y()); + y2 = zoomHandler->zoomItY(m_pEnd->y()); + + + // Calculate the direction vector from start -> end + vecX = m_pEnd->x() - m_pStart->x(); + vecY = m_pEnd->y() - m_pStart->y(); + + // Normalize the vector + len = sqrt( vecX*vecX + vecY*vecY ); + if( len ) + { + vecX /= len; + vecY /= len; + + // Move the endpoints by the cuts + x1 += vecX * zoomHandler->zoomItX(m_startAH->cut()); + y1 += vecY * zoomHandler->zoomItY(m_startAH->cut()); + + x2 -= vecX * zoomHandler->zoomItX(m_endAH->cut()); + y2 -= vecY * zoomHandler->zoomItY(m_endAH->cut()); + } + + + // Draw the line + painter->drawLine( x1, y1, x2, y2 ); + + + // Now draw the arrow heads + if( len ) + { + painter->setBGColor( m_pFillStyle->color() ); + + m_startAH->paint(painter, m_pStart->x(), m_pStart->y(), -vecX, -vecY, zoomHandler); + m_endAH->paint(painter, m_pEnd->x(), m_pEnd->y(), vecX, vecY, zoomHandler); + } + + // Text + drawText(pData); +} + +void KivioStraightConnector::paintOutline( KivioIntraStencilData *pData ) +{ + KivioPainter *painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + double x1, y1, x2, y2; + double vecX, vecY; + double len; + + + painter->setLineStyle(m_pLineStyle); + double lineWidth = m_pLineStyle->width(); + painter->setLineWidth(zoomHandler->zoomItY(lineWidth)); + + x1 = zoomHandler->zoomItX(m_pStart->x()); + x2 = zoomHandler->zoomItX(m_pEnd->x()); + + y1 = zoomHandler->zoomItY(m_pStart->y()); + y2 = zoomHandler->zoomItY(m_pEnd->y()); + + + // Calculate the direction vector from start -> end + vecX = m_pEnd->x() - m_pStart->x(); + vecY = m_pEnd->y() - m_pStart->y(); + + // Normalize the vector + len = sqrt( vecX*vecX + vecY*vecY ); + if( len ) + { + vecX /= len; + vecY /= len; + + // Move the endpoints by the cuts + x1 += vecX * zoomHandler->zoomItX(m_startAH->cut()); + y1 += vecY * zoomHandler->zoomItY(m_startAH->cut()); + + x2 -= vecX * zoomHandler->zoomItX(m_endAH->cut()); + y2 -= vecY * zoomHandler->zoomItY(m_endAH->cut()); + } + + + // Draw the line + painter->drawLine( x1, y1, x2, y2 ); + + + // Now draw the arrow heads + if( len ) + { + painter->setBGColor( m_pFillStyle->color() ); + + m_startAH->paint(painter, m_pStart->x(), m_pStart->y(), -vecX, -vecY, zoomHandler); + m_endAH->paint(painter, m_pEnd->x(), m_pEnd->y(), vecX, vecY, zoomHandler); + } + + // Text + // Don't paint text in outline mode as it makes moving harder + drawText(pData); +} + +bool KivioStraightConnector::saveCustom( QDomElement &e, QDomDocument &doc ) +{ + e.appendChild( saveArrowHeads(doc) ); + + return true; +} + +bool KivioStraightConnector::loadCustom( const QDomElement &e ) +{ + QDomNode node; + QString name; + + node = e.firstChild(); + while( !node.isNull() ) + { + name = node.nodeName(); + if( name == "KivioArrowHeads" ) + { + loadArrowHeads( node.toElement() ); + } + + node = node.nextSibling(); + } + + updateGeometry(); + + return true; +} + +QDomElement KivioStraightConnector::saveArrowHeads( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioArrowHeads"); + + e.appendChild( m_startAH->saveXML(doc) ); + e.appendChild( m_endAH->saveXML(doc) ); + + return e; +} + +bool KivioStraightConnector::loadArrowHeads( const QDomElement &e ) +{ + QDomNode node; + QString nodeName; + QDomElement arrowE; + bool first=true; + + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + arrowE = node.toElement(); + + if( nodeName == "KivioArrowHead" ) + { + if( first==true ) + { + m_startAH->loadXML(arrowE); + + first = false; + } + else + { + m_endAH->loadXML(arrowE); + } + } + + node = node.nextSibling(); + } + + return true; +} + +bool KivioStraightConnector::hasTextBox() const +{ + return true; +} + +#include "straight_connector.moc" diff --git a/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.h b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.h new file mode 100644 index 00000000..9cc602a5 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.h @@ -0,0 +1,95 @@ +/* + * 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. + */ +#ifndef STRAIGHT_CONNECTOR_H +#define STRAIGHT_CONNECTOR_H + + +#include "kivio_arrowhead.h" +#include "kivio_connector_point.h" +#include "kivio_custom_drag_data.h" +#include "kivio_intra_stencil_data.h" +#include "kiviostencilfactory.h" +#include "kivio_point.h" +#include "kivio_stencil.h" + +class KivioPage; + +#include <qcolor.h> +#include <qdom.h> + +#include "kivio_1d_stencil.h" + + +class KivioStraightConnector : public Kivio1DStencil +{ + protected: + KivioArrowHead *m_startAH; + KivioArrowHead *m_endAH; + + bool loadArrowHeads( const QDomElement & ); + QDomElement saveArrowHeads( QDomDocument & ); + + public: + KivioStraightConnector(); + virtual ~KivioStraightConnector(); + + virtual void setStartPoint( double, double ); + virtual void setEndPoint( double, double ); + + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + + virtual KivioStencil* duplicate(); + + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + + virtual bool loadCustom( const QDomElement & ); + virtual bool saveCustom( QDomElement &, QDomDocument & ); + + + virtual void setStartAHType( int i ) { m_startAH->setType(i); } + virtual void setStartAHWidth( double f ) { m_startAH->setWidth(f); } + virtual void setStartAHLength( double f ) { m_startAH->setLength(f); } + virtual void setEndAHType( int i ) { m_endAH->setType(i); } + virtual void setEndAHWidth( double f ) { m_endAH->setWidth(f); } + virtual void setEndAHLength( double f ) { m_endAH->setLength(f); } + + virtual int startAHType() { return m_startAH->type(); } + virtual double startAHWidth() { return m_startAH->width(); } + virtual double startAHLength() { return m_startAH->length(); } + virtual int endAHType() { return m_endAH->type(); } + virtual double endAHWidth() { return m_endAH->width(); } + virtual double endAHLength() { return m_endAH->length(); } + + virtual bool hasTextBox() const; +}; + +class KIVIOPLUGINS_EXPORT KivioConnectorFactory : public KivioStencilFactory +{ + Q_OBJECT + public: + KivioConnectorFactory(QObject *parent=0, const char* name=0, const QStringList& args = QStringList()); + KivioStencil *NewStencil(const QString& name); + KivioStencil *NewStencil(); + QPixmap *GetIcon(); + KivioStencilSpawnerInfo *GetSpawnerInfo(); +}; + +#endif + diff --git a/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.xpm b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.xpm new file mode 100644 index 00000000..ffe56ed7 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.xpm @@ -0,0 +1,41 @@ +/* XPM */ +static const char * straight_connector_xpm[] = { +"32 32 6 1", +" c None", +". c #F8FCF8", +"+ c #808080", +"@ c #FFFA00", +"# c #000000", +"$ c #29D82F", +"...............................+", +".+++++++++++++++++++++++++++++.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@#@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@#@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@#@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@#@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@#@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@#@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@#@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@#@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@#@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@#@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@#@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@#@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@#@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@#@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@#@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +"...............................+", +"++++++++++++++++++++++++++++++++"}; |