diff options
Diffstat (limited to 'kivio/plugins/kiviosmlconnector')
-rw-r--r-- | kivio/plugins/kiviosmlconnector/Makefile.am | 24 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/README | 16 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop | 50 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc | 8 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/plugin.cpp | 58 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/plugin.h | 44 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am | 23 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp | 434 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h | 104 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.xpm | 41 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/tool_connector.cpp | 248 | ||||
-rw-r--r-- | kivio/plugins/kiviosmlconnector/tool_connector.h | 85 |
12 files changed, 1135 insertions, 0 deletions
diff --git a/kivio/plugins/kiviosmlconnector/Makefile.am b/kivio/plugins/kiviosmlconnector/Makefile.am new file mode 100644 index 00000000..ee352d9a --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/Makefile.am @@ -0,0 +1,24 @@ +SUBDIRS=. sml_connector +kde_module_LTLIBRARIES =libkiviosmlconnector.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + -I$(top_srcdir)/kivio/plugins/kiviosmlconnector/sml_connector \ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) + +METASOURCES = AUTO +libkiviosmlconnector_la_SOURCES = plugin.cpp tool_connector.cpp +libkiviosmlconnector_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +libkiviosmlconnector_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + + + +rc_DATA = kiviosmlconnector.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kiviosmlconnector.desktop +desktopdir = $(kde_servicesdir) + diff --git a/kivio/plugins/kiviosmlconnector/README b/kivio/plugins/kiviosmlconnector/README new file mode 100644 index 00000000..07f4bb31 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/README @@ -0,0 +1,16 @@ +DESIGN: + This plugin will create a connector from a path created from a series of points. At each point a handle will be placed, this includes connection points and control handles. + + Arrows are only available at the end points and only end points can connect to other shapes. + +Example SML: +<KivioConnector> + <Type data="Xor"/> + <Points> + <KivioPoint x="40" y="50" type="bezier"/> + <KivioPoint x="30" y="40" type="bezier"/> + <KivioPoint x="10" y="40" type="bezier"/> + <KivioPoint x="0" y="50" type="bezier"/> + </Points> +</KivioConnector +This will create an arc shaped connector with handles at the control points and handles at the end points diff --git a/kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop new file mode 100644 index 00000000..b835128a --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop @@ -0,0 +1,50 @@ +[Desktop Entry] +X-KDE-Library=libkiviosmlconnector +Name=SML Based ConnectorTool for Kivio +Name[bg]=Инструмент базиран на SML за свързване за Kivio +Name[ca]=Eina de connexió per a Kivio basada en SML +Name[cs]=Spojovací nástroj pro Kivio (SML) +Name[cy]=ErfynCysylltu i Kivio, wedi'i Seilio ar SML +Name[da]=SML-baseret Connector-værktøj for Kivio +Name[de]=SML-basiertes Verbindungswerkzeug für Kivio +Name[el]=Εργαλείο σύνδεσης βασισμένο σε SML για το Kivio +Name[eo]=SML-bazita Konektilo por Kivio +Name[es]=Herramienta de conexión para Kivio basada en SML +Name[et]=Kivio SML-põhine ühenduste tööriist +Name[eu]=Kivio-ren SML-n oinarritutako konexiorako tresna +Name[fa]=ابزار اتصال بر اساس SML برای Kivio +Name[fi]=SML-pohjainen yhdistämistyökalu Kivioon +Name[fr]=Outil connexion, basé sur SML, pour Kivio +Name[fy]=SML-basearre ferbiningshelpprogramma foar Kivio +Name[gl]=Ferramenta de Conexón baseada en SML para Kivio +Name[he]=כלי חיבור מבוסס SML עבור Kivio +Name[hr]=Alat povezivanja za Kivio zasnovan na SML +Name[hu]=SML-alapú összekapcsoló eszköz a Kivióhoz +Name[is]=SML byggt tengitól fyrir Kivio +Name[it]=Strumento di connessione basato su SML per Kivio +Name[ja]=Kivio SML ベースのコネクタツール +Name[km]=ឧបករណ៍តភ្ជាប់ផ្អែកលើ SML សម្រាប់ Kivio +Name[lv]=SML bāzēts savienotājrīks priekš Kivio +Name[ms]=Alat Penyambung Berasaskan SML bagi Kivio +Name[nb]=SML-basert koblingsverktøy for Kivio +Name[nds]=Op SML opbuut Tokoppelwarktüüch för Kivio +Name[ne]=किभियोका लागि SML आधारित योजक +Name[nl]=SML-gebaseerd verbindingshulpprogramma voor Kivio +Name[nn]=SML-basert sambandsverktøy for Kivio +Name[pl]=Narzędzie łącznika oparte na SML dla Kivio +Name[pt]=Ferramenta de Ligação baseada em SML para o Kivio +Name[pt_BR]=Ferramenta SML Baseada em Conector para o Kivio +Name[ru]=Соединения SML для Kivio +Name[se]=SML-vuođđuduvvon oktavuohtareaidu Kivio várás +Name[sk]=Spojovací nástroj pre Kivio založený na SML +Name[sl]=Priključno orodje za Kivio na osnovi SML +Name[sr]=Алат за повезивање за Kivio заснован на SML-у +Name[sr@Latn]=Alat za povezivanje za Kivio zasnovan na SML-u +Name[sv]=SML-baserat kopplingsverktyg för Kivio +Name[ta]= SML Kivio இணைப்புக்கருவி +Name[tg]=SML Асбоби Пайвандкунаки База барои Kivio +Name[tr]=SML tabanlı Kivio Bağlantı Aracı +Name[uk]=З'єднання SML для Kivio +Name[zh_CN]=Kivio 基于 SML 的连接件工具 +Name[zh_TW]=Kivio SML式連接器工具 +Type=Service diff --git a/kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc new file mode 100644 index 00000000..fc70e42d --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc @@ -0,0 +1,8 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioSMLConnector" library="libkiviosmlconnector" version="2"> +<MenuBar> + <Menu name="Tools"> + <Action name="sml_connector"/> + </Menu> +</MenuBar> +</kpartgui> diff --git a/kivio/plugins/kiviosmlconnector/plugin.cpp b/kivio/plugins/kiviosmlconnector/plugin.cpp new file mode 100644 index 00000000..ee12cf17 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/plugin.cpp @@ -0,0 +1,58 @@ +/* + * 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 "plugin.h" +#include "tool_connector.h" + +#include "kivio_view.h" + +#include <kinstance.h> +#include <kiconloader.h> + +/*************************************************** + * Factory + ***************************************************/ +K_EXPORT_COMPONENT_FACTORY( libkiviosmlconnector, SMLConnectorFactory ) + +KInstance* SMLConnectorFactory::s_global = 0; + +SMLConnectorFactory::SMLConnectorFactory( QObject* parent, const char* name ) +: KLibFactory( parent, name ) +{ + s_global = new KInstance("kivio"); +} + +SMLConnectorFactory::~SMLConnectorFactory() +{ + delete s_global; +} + +QObject* SMLConnectorFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject *obj = new SMLConnector( (KivioView*)parent ); + return obj; +} + +KInstance* SMLConnectorFactory::global() +{ + return s_global; +} +#include "plugin.moc" diff --git a/kivio/plugins/kiviosmlconnector/plugin.h b/kivio/plugins/kiviosmlconnector/plugin.h new file mode 100644 index 00000000..530d8de8 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/plugin.h @@ -0,0 +1,44 @@ +/* + * 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 SML_CONNECTOR_PLUGIN_H +#define SML_CONNECTOR_PLUGIN_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class SMLConnectorFactory : public KLibFactory +{ Q_OBJECT +public: + SMLConnectorFactory( QObject* parent = 0, const char* name = 0 ); + ~SMLConnectorFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + + static KInstance* global(); + +private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am b/kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am new file mode 100644 index 00000000..0b60c3f6 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am @@ -0,0 +1,23 @@ +kde_module_LTLIBRARIES =sml_connector.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) + +METASOURCES = AUTO + +sml_connector_la_SOURCES = sml_connector.cpp +sml_connector_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +sml_connector_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +stencildir = $(kde_datadir)/kivio/autoloadStencils +stencil_DATA = sml_connector.xpm + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(stencildir) + rm -f $(DESTDIR)$(stencildir)/sml_connector.so + $(LN_S) $(kde_moduledir)/sml_connector.so $(DESTDIR)$(stencildir)/sml_connector.so + +uninstall-local: + rm -f $(DESTDIR)$(stencildir)/sml_connector.so diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp new file mode 100644 index 00000000..b6770700 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp @@ -0,0 +1,434 @@ +/* +* 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 "sml_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 "kivio_shape.h" +#include "kivio_shape_data.h" +#include "kivio_point.h" + +#include "tkmath.h" + +#include <qcolor.h> +#include <qpixmap.h> +#include <kdebug.h> +#include <KoZoomHandler.h> +#include <kiconloader.h> + +static KivioStencilSpawnerInfo sinfo = KivioStencilSpawnerInfo( "Ian Reinhart Geiser", "SML Connector", "SML Connector", "SML Based Connector", "0.1", "http://localhost/", "", "off" ); +#include <kgenericfactory.h> + +K_EXPORT_COMPONENT_FACTORY( sml_connector, KGenericFactory<KivioSMLConnectorFactory>( "KivioSMLConnectorFactory" ) ) + +KivioSMLConnectorFactory::KivioSMLConnectorFactory( QObject *parent, const char* name, const QStringList& args ) : + KivioStencilFactory( parent, name, args ) +{ + kdDebug(43000) << "new sml stencil factory: " << endl; +} + +KivioStencil *KivioSMLConnectorFactory::NewStencil( const QString& name ) +{ + return new KivioSMLConnector( name ); +} + +KivioStencil *KivioSMLConnectorFactory::NewStencil() +{ + return new KivioSMLConnector( "basic_line" ); +} + + +QPixmap *KivioSMLConnectorFactory::GetIcon() +{ + return & BarIcon( "SML_conn" ); +} + +KivioStencilSpawnerInfo *KivioSMLConnectorFactory::GetSpawnerInfo() +{ + return & sinfo; +} + +KivioSMLConnector::KivioSMLConnector( const QString &name ) + : Kivio1DStencil(), m_name( name ) +{ + + 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 ); + + // We only have one shape, an open path. + //m_shape = new KivioShape(); + //m_shape->shapeData() ->setShapeType( KivioShapeData::kstOpenPath ); + loadPath( name ); +} + +KivioSMLConnector::~KivioSMLConnector() +{ + delete m_startAH; + delete m_endAH; +} + +void KivioSMLConnector::setStartPoint( double x, double y ) +{ + m_pStart->setPosition( x, y, false ); + m_pStart->disconnect(); + + if ( m_needsText ) + { + m_pTextConn->setPosition( ( m_pEnd->x() + m_pStart->x() ) / 2.0f, + ( m_pEnd->y() + m_pStart->y() ) / 2.0f, + false ); + } + + // Set list end point + m_pConnectorPoints ->first() ->setX( x ); + m_pConnectorPoints ->first() ->setY( y ); + +} + +void KivioSMLConnector::setEndPoint( double x, double y ) +{ + m_pEnd->setPosition( x, y, false ); + m_pEnd->disconnect(); + m_pConnectorPoints ->last() ->setX( x ); + m_pConnectorPoints ->last() ->setY( y ); +} + +KivioCollisionType KivioSMLConnector::checkForCollision( KivioPoint *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 *KivioSMLConnector::duplicate() +{ + KivioSMLConnector * pStencil = new KivioSMLConnector( m_name ); + + + // TODO: Copy internal pointlist information? + + // 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 KivioSMLConnector::drawOpenPath( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter * painter; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPoint, *pNewPoint; + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete( true ); + + pPoint = pPointList->first(); + while ( pPoint ) + { + pNewPoint = new KivioPoint( pData->zoomHandler->zoomItX( pPoint->x() ), + pData->zoomHandler->zoomItY( pPoint->y() ), + pPoint->pointType() ); + pNewPoints->append( pNewPoint ); + + pPoint = pPointList->next(); + } + + painter = pData->painter; + double lineWidth = pShapeData->lineStyle() ->width(); + painter->setLineWidth( pData->zoomHandler->zoomItY( lineWidth ) ); + painter->setFGColor( pShapeData->lineStyle() ->color() ); + + painter->drawOpenPath( pNewPoints ); + delete pNewPoints; +} +*/ +void KivioSMLConnector::paint( KivioIntraStencilData *pData ) +{ + KivioPainter * painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + double x1, y1, x2, y2; + double vecX, vecY; + double len; + + + painter->setFGColor( m_pLineStyle->color() ); + painter->setLineWidth( zoomHandler->zoomItY( m_pLineStyle->width() ) ); + + 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() ); + } + + + // Build shape up from m_pConnectorPoints + + + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete( true ); + + pNewPoints->append(new KivioPoint( zoomHandler->zoomItX( m_pStart->x() ), + zoomHandler->zoomItY( m_pStart->y() ))); + + KivioConnectorPoint *pPoint = m_PointList.first(); + while ( pPoint ) + { + KivioPoint *pNewPoint = new KivioPoint( zoomHandler->zoomItX( pPoint->x() ), + zoomHandler->zoomItY( pPoint->y() )); + pNewPoints->append( pNewPoint ); + + pPoint = m_PointList.next(); + } + + pNewPoints->append(new KivioPoint( zoomHandler->zoomItX( m_pEnd->x() ), + zoomHandler->zoomItY( m_pEnd->y() ))); + painter = pData->painter; + double lineWidth = m_pLineStyle ->width(); + painter->setLineWidth( zoomHandler->zoomItY( lineWidth ) ); + painter->setFGColor( m_pLineStyle ->color() ); + + painter->drawOpenPath( pNewPoints ); + delete pNewPoints; + + // 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 ); + } + + // TODO: Text + drawText( pData ); +} + +void KivioSMLConnector::paintOutline( KivioIntraStencilData *pData ) +{ + paint( pData ); +} + +bool KivioSMLConnector::saveCustom( QDomElement &e, QDomDocument &doc ) +{ + kdDebug(43000) << "Save custom " << endl; + e.appendChild( saveArrowHeads( doc ) ); + + //QDomElement type = m_shape->saveXML(doc); + KivioConnectorPoint *p = m_PointList.first(); + while ( p ) + { + QDomElement pt = p->saveXML( doc ); + e.appendChild( pt ); + p = m_PointList.next(); + } + return true; +} + +bool KivioSMLConnector::loadCustom( const QDomElement &e ) +{ + kdDebug(43000) << "Load custom " << endl; + QDomNode node; + QString name; + + node = e.firstChild(); + while ( !node.isNull() ) + { + name = node.nodeName(); + if ( name == "KivioArrowHeads" ) + { + loadArrowHeads( node.toElement() ); + } + else if ( name == "KivioShape" ) + { + //m_shape->loadXML(node.toElement()); + QDomNode pts = node.firstChild(); + while ( !pts.isNull() ) + { + KivioConnectorPoint * pt = new KivioConnectorPoint(); + pt->loadXML( pts.toElement() ); + m_pConnectorPoints->append( pt ); + m_PointList.append( pt ); + pts = pts.nextSibling(); + } + } + node = node.nextSibling(); + } + + updateGeometry(); + + return true; +} + +QDomElement KivioSMLConnector::saveArrowHeads( QDomDocument &doc ) +{ + QDomElement e = doc.createElement( "KivioArrowHeads" ); + + e.appendChild( m_startAH->saveXML( doc ) ); + e.appendChild( m_endAH->saveXML( doc ) ); + + return e; +} + +bool KivioSMLConnector::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 KivioSMLConnector::loadPath( const QString &file ) +{ + kdDebug(43000) << "Loading :" << file << endl; + + m_PointList.clear(); + m_PointList.append(m_pStart); + + KivioConnectorPoint *pt = new KivioConnectorPoint(this,false); + pt->setPosition(m_pStart->x()+10,m_pStart->y()+10,false); +// m_PointList.append( pt ); + m_pConnectorPoints->append(pt); + + pt = new KivioConnectorPoint(this,false); + pt->setPosition(m_pStart->x()+20,m_pStart->y()+20,false); + m_PointList.append( pt ); + m_pConnectorPoints->append(pt); + + pt = new KivioConnectorPoint(this,false); + pt->setPosition(m_pStart->x()+30,m_pStart->y()+30,false); + m_PointList.append( pt ); + m_pConnectorPoints->append(pt); + +// m_PointList.append(m_pEnd); + m_name = file; + return true; +} + +#include "sml_connector.moc" diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h new file mode 100644 index 00000000..4371ff8a --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h @@ -0,0 +1,104 @@ +/* + * 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 SML_CONNECTOR_H +#define SML_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_text_style.h" +#include "kivio_point.h" +#include "kivio_stencil.h" + +class KivioPage; +class KivioShape; +#include <qstringlist.h> +#include <qcolor.h> +#include <qdom.h> + +#include "kivio_1d_stencil.h" + + +class KivioSMLConnector : public Kivio1DStencil +{ +private: + bool loadPath(const QString &file); + //void drawOpenPath( KivioShape *, KivioIntraStencilData * ); + KivioShape *m_shape; + QPtrList<KivioConnectorPoint> m_PointList; + + QString m_name; +protected: + + KivioArrowHead *m_startAH; + KivioArrowHead *m_endAH; + + bool loadArrowHeads( const QDomElement & ); + QDomElement saveArrowHeads( QDomDocument & ); + virtual bool loadCustom( const QDomElement & ); + virtual bool saveCustom( QDomElement &, QDomDocument & ); + +public: + KivioSMLConnector(const QString& name); + virtual ~KivioSMLConnector(); + + virtual void setStartPoint( double, double ); + virtual void setEndPoint( double, double ); + + virtual KivioCollisionType checkForCollision( KivioPoint *, double ); + + virtual KivioStencil* duplicate(); + + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + + + + + 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(); } + +}; + +class KivioSMLConnectorFactory : public KivioStencilFactory +{ + Q_OBJECT + public: + KivioSMLConnectorFactory(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/kiviosmlconnector/sml_connector/sml_connector.xpm b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.xpm new file mode 100644 index 00000000..ffe56ed7 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/sml_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", +"...............................+", +".+++++++++++++++++++++++++++++.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@#@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@#@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@#@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@#@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@#@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@#@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@#@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@#@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@#@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@#@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@#@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@#@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@#@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@#@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@#@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +"...............................+", +"++++++++++++++++++++++++++++++++"}; diff --git a/kivio/plugins/kiviosmlconnector/tool_connector.cpp b/kivio/plugins/kiviosmlconnector/tool_connector.cpp new file mode 100644 index 00000000..ded38f13 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/tool_connector.cpp @@ -0,0 +1,248 @@ +/* + * 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 "tool_connector.h" + +#include <qcursor.h> +#include <kdebug.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <KoPoint.h> +#include <KoZoomHandler.h> +#include <kactionclasses.h> +#include <klocale.h> + +#include "kivio_view.h" +#include "kivio_canvas.h" +#include "kivio_page.h" +#include "kivio_doc.h" +#include "kivio_factory.h" + +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner.h" +#include "kivio_custom_drag_data.h" +#include "kivio_layer.h" +#include "kivio_point.h" +#include "kivio_stencil.h" +#include "sml_connector.h" + +SMLConnector::SMLConnector( KivioView* view ) + : Kivio::MouseTool(view, "SMLConnector") +{ + m_connectorAction = new KToggleAction(i18n("Polyline Connector"), "", 0, + actionCollection(), "sml_connector"); + connect(m_connectorAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + + m_mode = stmNone; + + m_pConnectorCursor1 = new QCursor(BarIcon("kivio_connector_cursor1",KivioFactory::global()),2,2); + m_pConnectorCursor2 = new QCursor(BarIcon("kivio_connector_cursor2",KivioFactory::global()),2,2); +} + +SMLConnector::~SMLConnector() +{ + delete m_pConnectorCursor1; + delete m_pConnectorCursor2; +} + + +/** + * Event delegation + * + * @param e The event to be identified and processed + * + */ +bool SMLConnector::processEvent( QEvent* e ) +{ + switch (e->type()) + { + case QEvent::MouseButtonPress: + mousePress( (QMouseEvent*)e ); + return true; + break; + + case QEvent::MouseButtonRelease: + mouseRelease( (QMouseEvent*)e ); + return true; + break; + + case QEvent::MouseMove: + mouseMove( (QMouseEvent*)e ); + return true; + break; + + default: + break; + } + + return false; +} + +void SMLConnector::setActivated(bool a) +{ + m_connectorAction->setChecked(a); + + if(a) { + kdDebug(43000) << "SMLConnector activate" << endl; + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; + m_pStencil = 0; + m_pDragData = 0; + emit activated(this); + } else { + m_pStencil = 0; + delete m_pDragData; + m_pDragData = 0; + } +} + +void SMLConnector::connector(QRect) +{ + if (!m_pStencil) + return; + + delete m_pDragData; + m_pDragData = 0; + + KivioDoc* doc = view()->doc(); + KivioPage* page = view()->activePage(); + + if (m_pStencil->w() < 3.0 && m_pStencil->h() < 3.0) { + page->unselectAllStencils(); + page->selectStencil(m_pStencil); + page->deleteSelectedStencils(); + m_pStencil = 0; + doc->updateView(page); + return; + } + + m_pStencil->searchForConnections(page, view()->zoomHandler()->unzoomItY(4)); + doc->updateView(page); +} + +void SMLConnector::mousePress( QMouseEvent *e ) +{ + if(e->button() == RightButton) + { + return; + } + if( startRubberBanding( e ) ) + { + m_mode = stmDrawRubber; + } +} + + +/** + * Tests if we should start rubber banding (always returns true). + */ +bool SMLConnector::startRubberBanding( QMouseEvent *e ) +{ + KivioDoc* doc = view()->doc(); + KivioPage* pPage = view()->activePage(); + KivioCanvas* canvas = view()->canvasWidget(); + + startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() )); + + // Create the stencil + KivioStencilSpawner* ss = doc->findInternalStencilSpawner("SML Connector"); + + if (!ss) { + kdDebug(43000) << "SMLTool: Failed to find StencilSpawner!" << endl; + return false; + } + + startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() )); + + // Create the stencil + m_pStencil = (KivioSMLConnector*)ss->newStencil("basic_line"); + m_pStencil->setTextFont(doc->defaultFont()); + + // Unselect everything, add the stencil to the page, and select it + pPage->unselectAllStencils(); + pPage->addStencil(m_pStencil); + pPage->selectStencil(m_pStencil); + + // Get drag info ready + m_pDragData = new KivioCustomDragData(); + m_pDragData->page = pPage; + m_pDragData->x = startPoint.x(); + m_pDragData->y = startPoint.y(); + m_pDragData->id = kctCustom + 2; + + m_pStencil->setStartPoint(startPoint.x() + 10.0f, startPoint.y() + 10.0f); + m_pStencil->setEndPoint(startPoint.x(), startPoint.y()); + m_pStencil->customDrag(m_pDragData); + + + canvas->repaint(); + canvas->setCursor(*m_pConnectorCursor2); + return true; +} + +void SMLConnector::mouseMove( QMouseEvent * e ) +{ + switch( m_mode ) + { + case stmDrawRubber: + continueRubberBanding(e); + break; + + default: + break; + } +} + +void SMLConnector::continueRubberBanding( QMouseEvent *e ) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint endPoint = canvas->mapFromScreen( e->pos() ); + endPoint = canvas->snapToGrid(endPoint); + + m_pStencil->setStartPoint(endPoint.x(), endPoint.y()); + + + m_pDragData->x = endPoint.x(); + m_pDragData->y = endPoint.y(); + m_pDragData->id = kctCustom + 1; + m_pStencil->customDrag(m_pDragData); + + m_pStencil->updateGeometry(); + canvas->repaint(); +} + +void SMLConnector::mouseRelease( QMouseEvent *e ) +{ + switch( m_mode ) + { + case stmDrawRubber: + endRubberBanding(e); + break; + } + + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; +} + +void SMLConnector::endRubberBanding(QMouseEvent *) +{ + connector(view()->canvasWidget()->rect()); + m_pStencil = 0; +} + +#include "tool_connector.moc" diff --git a/kivio/plugins/kiviosmlconnector/tool_connector.h b/kivio/plugins/kiviosmlconnector/tool_connector.h new file mode 100644 index 00000000..aecb26db --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/tool_connector.h @@ -0,0 +1,85 @@ +/* + * 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 SML_TOOL_CONNECTOR_H +#define SML_TOOL_CONNECTOR_H + +#include "kivio_mousetool.h" +#include <KoPoint.h> + +class QMouseEvent; +class QCursor; + +class KToggleAction; + +class KivioView; +class KivioPage; +class KivioSMLConnector; +class KivioCustomDragData; + +class SMLConnector : public Kivio::MouseTool +{ Q_OBJECT +public: + SMLConnector( KivioView* view ); + ~SMLConnector(); + + virtual bool processEvent( QEvent* ); + + void connector(QRect); + +public slots: + virtual void setActivated(bool a); + +signals: + void operationDone(); + +protected: + void mousePress(QMouseEvent *); + void mouseMove(QMouseEvent *); + void mouseRelease(QMouseEvent *); + + bool startRubberBanding(QMouseEvent*); + void continueRubberBanding(QMouseEvent *); + void endRubberBanding(QMouseEvent *); + + + + QPoint m_startPoint, m_releasePoint; + + // Connector Tool Mode + enum + { + stmNone, + stmDrawRubber + }; + +private: + // Flag to indicate that we are drawing a rubber band + int m_mode; + QCursor* m_pConnectorCursor1; + QCursor* m_pConnectorCursor2; + KivioSMLConnector* m_pStencil; + KoPoint startPoint; + KivioCustomDragData* m_pDragData; + + KToggleAction* m_connectorAction; +}; + +#endif + + |