diff options
Diffstat (limited to 'kivio/kiviopart/kiviosdk')
72 files changed, 19748 insertions, 0 deletions
diff --git a/kivio/kiviopart/kiviosdk/Makefile.am b/kivio/kiviopart/kiviosdk/Makefile.am new file mode 100644 index 000000000..468c42ab2 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/Makefile.am @@ -0,0 +1,45 @@ +KDE_OPTIONS = nofinal + +noinst_LTLIBRARIES =libkiviosdk.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + $(KOFFICECORE_INCLUDES) $(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) $(PYTHONINC) + +libkiviosdk_la_METASOURCES = AUTO + +libkiviosdk_la_SOURCES = \ + kivio_common.cpp\ + kivio_wrap.cpp\ + kivio_py_stencil.cpp\ + kivio_py_stencil_spawner.cpp\ + kivio_fill_style.cpp\ + kivio_gradient.cpp\ + kivio_point.cpp\ + kivio_shape.cpp\ + kivio_shape_data.cpp\ + kivio_sml_stencil.cpp\ + kivio_sml_stencil_spawner.cpp\ + kivio_dia_stencil_spawner.cpp\ + kivio_stencil.cpp\ + kivio_stencil_spawner.cpp\ + kivio_stencil_spawner_info.cpp\ + kivio_stencil_spawner_set.cpp\ + kivio_painter.cpp\ + kivio_screen_painter.cpp\ + kivio_layer.cpp\ + kivio_connector_target.cpp\ + kivio_group_stencil.cpp\ + kivio_connector_point.cpp\ + kivio_plugin_stencil_spawner.cpp\ + kivio_custom_drag_data.cpp\ + kivio_shape_painter.cpp\ + kivio_arrowhead.cpp\ + kivio_base_connector_stencil.cpp\ + kivio_line_style.cpp\ + kivio_text_style.cpp\ + kivio_1d_stencil.cpp \ + diapathparser.cpp \ + kiviopolylineconnector.cpp \ + polylineconnectorspawner.cpp diff --git a/kivio/kiviopart/kiviosdk/diapathparser.cpp b/kivio/kiviopart/kiviosdk/diapathparser.cpp new file mode 100644 index 000000000..d0ceb271a --- /dev/null +++ b/kivio/kiviopart/kiviosdk/diapathparser.cpp @@ -0,0 +1,140 @@ +/* This file is part of the KDE project + Copyright (C) 2003, The Kivio Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "diapathparser.h" + +DiaPointFinder::DiaPointFinder(QValueList<float> *xlist, QValueList<float> *ylist) : + SVGPathParser(), m_xlist(xlist), m_ylist(ylist) +{ + ; +} + +void DiaPointFinder::svgMoveTo( double x1, double y1, bool ) +{ + m_xlist->append(x1); + m_ylist->append(y1); +} +void DiaPointFinder::svgLineTo( double x1, double y1, bool ) +{ + m_xlist->append(x1); + m_ylist->append(y1); +} +void DiaPointFinder::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool ) +{ + m_xlist->append(x1); + m_ylist->append(y1); + m_xlist->append(x2); + m_ylist->append(y2); + m_xlist->append(x3); + m_ylist->append(y3); +} +void DiaPointFinder::svgClosePath() +{ + +} +DiaPathParser::DiaPathParser(QDomDocument *doc, QDomElement *shape, float xscale, float yscale, float lowestx, float lowesty) : + SVGPathParser(), m_doc(doc), m_shape(shape), + m_xscale(xscale), m_yscale(yscale), + m_lowestx(lowestx), m_lowesty(lowesty) +{ + lastX = 0.0; + lastY = 0.0; +} + +void DiaPathParser::svgMoveTo( double x1, double y1, bool ) +{ + lastX = x1; + lastY = y1; +} +void DiaPathParser::svgLineTo( double x1, double y1, bool ) +{ + // Line + float currentX = x1; + float currentY = y1; + + // Create the line + QDomElement kivioPointElement = m_doc->createElement("KivioPoint"); + kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(lastX,true) * m_xscale)); + kivioPointElement.setAttribute("y", QString::number(diaPointToKivio(lastY, false) * m_yscale)); + m_shape->appendChild(kivioPointElement); + + kivioPointElement = m_doc->createElement("KivioPoint"); + kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(currentX,true) * m_xscale)); + kivioPointElement.setAttribute("y", QString::number(diaPointToKivio(currentY, false) * m_yscale)); + m_shape->appendChild(kivioPointElement); + lastX = currentX; + lastY = currentY; +} + +void DiaPathParser::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool ) +{ + // Spline + float lastControlX = x1; + float lastControlY = y1; + float currentControlX = x2; + float currentControlY = y2; + float currentX = x3; + float currentY = y3; + + // Create the bezier + QDomElement kivioPointElement = m_doc->createElement("KivioPoint"); + kivioPointElement.setAttribute("x", + QString::number(diaPointToKivio(lastX,true) * m_xscale)); + kivioPointElement.setAttribute("y", + QString::number(diaPointToKivio(lastY, false) * m_yscale)); + kivioPointElement.setAttribute("type", "bezier"); + m_shape->appendChild(kivioPointElement); + + kivioPointElement = m_doc->createElement("KivioPoint"); + kivioPointElement.setAttribute("x", + QString::number(diaPointToKivio(lastControlX,true) * m_xscale)); + kivioPointElement.setAttribute("y", + QString::number(diaPointToKivio(lastControlY, false) * m_yscale)); + kivioPointElement.setAttribute("type", "bezier"); + m_shape->appendChild(kivioPointElement); + + kivioPointElement = m_doc->createElement("KivioPoint"); + kivioPointElement.setAttribute("x", + QString::number(diaPointToKivio(currentControlX,true) * m_xscale)); + kivioPointElement.setAttribute("y", + QString::number(diaPointToKivio(currentControlY, false) * m_yscale)); + kivioPointElement.setAttribute("type", "bezier"); + m_shape->appendChild(kivioPointElement); + + kivioPointElement = m_doc->createElement("KivioPoint"); + kivioPointElement.setAttribute("x", + QString::number(diaPointToKivio(currentX,true) * m_xscale)); + kivioPointElement.setAttribute("y", + QString::number(diaPointToKivio(currentY, false) * m_yscale)); + kivioPointElement.setAttribute("type", "bezier"); + m_shape->appendChild(kivioPointElement); + lastX = currentX; + lastY = currentY; +} +void DiaPathParser::svgClosePath() +{ + +} +float DiaPathParser::diaPointToKivio(float point, bool xpoint) +{ + if(xpoint) + return point - m_lowestx; + else + return point - m_lowesty; +} diff --git a/kivio/kiviopart/kiviosdk/diapathparser.h b/kivio/kiviopart/kiviosdk/diapathparser.h new file mode 100644 index 000000000..b4522400c --- /dev/null +++ b/kivio/kiviopart/kiviosdk/diapathparser.h @@ -0,0 +1,64 @@ +/* This file is part of the KDE project + Copyright (C) 2003, The Kivio Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __DIAPATHPARSER_H__ +#define __DIAPATHPARSER_H__ + +#include "svgpathparser.h" +#include <qvaluelist.h> +#include <qdom.h> + +class DiaPointFinder : public SVGPathParser +{ + public: + DiaPointFinder(QValueList<float> *xlist, QValueList<float> *ylist); + void svgMoveTo( double x1, double y1, bool abs = true ); + void svgLineTo( double x1, double y1, bool abs = true ); + void svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool abs = true ); + void svgClosePath(); + + private: + QValueList<float> *m_xlist; + QValueList<float> *m_ylist; +}; + +class DiaPathParser : public SVGPathParser +{ + public: + DiaPathParser(QDomDocument *doc, QDomElement *shape, float xscale, float yscale, float lowestx, float lowesty); + + void svgMoveTo( double x1, double y1, bool abs = true ); + void svgLineTo( double x1, double y1, bool abs = true ); + void svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool abs = true ); + void svgClosePath(); + + private: + float diaPointToKivio(float point, bool xpoint); + + QDomDocument *m_doc; + QDomElement *m_shape; + float lastX; + float lastY; + float m_xscale; + float m_yscale; + float m_lowestx; + float m_lowesty; + +}; +#endif diff --git a/kivio/kiviopart/kiviosdk/kivio_1d_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_1d_stencil.cpp new file mode 100644 index 000000000..9971f5f76 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_1d_stencil.cpp @@ -0,0 +1,1011 @@ +/* + * 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. + */ + +/* + * Implementing a connector involves deriving from this class. + * + * You need to implement the following routines: + * setStartPoint + * setEndPoint + * checkForCollision + * duplicate + * paint + * paintOutline + * saveXML + * loadXML + * + * Save and Load should call saveConnectors, loadConnectors, saveProperties, and + * loadProperties. These are helper functions which take care of the common + * acts of saving/loading connectors and colors/line-styles, etc... + * + */ + +#include "kivio_1d_stencil.h" +#include "kivio_arrowhead.h" +#include "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_custom_drag_data.h" +#include "kivio_fill_style.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_layer.h" +#include "kivio_line_style.h" +#include "kivio_page.h" +#include "kivio_painter.h" +#include "kivio_point.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_connector_target.h" + +#include <kdebug.h> +#include <math.h> +#include <KoZoomHandler.h> + +#include <qbitmap.h> +#include <qpainter.h> + +/** + * Default constructor. + * + * This will allocate a new fill style object, a list for + * connection points, and set some default values. + */ +Kivio1DStencil::Kivio1DStencil() + : KivioStencil() +{ + m_pFillStyle = new KivioFillStyle(); + m_pLineStyle = new KivioLineStyle(); + m_pTextStyle = new KivioTextStyle(); + + m_pConnectorPoints = new QPtrList<KivioConnectorPoint>; + m_pConnectorPoints->setAutoDelete(true); + + m_pStart = new KivioConnectorPoint(this, true); + m_pStart->setPosition(72.0f, 18.0f, false); + + m_pEnd = new KivioConnectorPoint(this, true); + m_pEnd->setPosition(0.0f, 18.0f, false); + + m_pLeft = new KivioConnectorPoint(this, false); + m_pLeft->setPosition(36.0f, 36.0f, false); + + m_pRight = new KivioConnectorPoint(this, false); + m_pRight->setPosition(36.0f, 0.0f, false); + + m_pTextConn = new KivioConnectorPoint(this, false); + m_pTextConn->setPosition(36.0f, 18.0f, false); + + m_connectorWidth = 36.0f; + m_needsWidth = true; + m_needsText = false; + + m_pConnectorPoints->append( m_pStart ); + m_pConnectorPoints->append( m_pEnd ); + m_pConnectorPoints->append( m_pLeft ); + m_pConnectorPoints->append( m_pRight ); + m_pConnectorPoints->append( m_pTextConn ); +} + + +/** + * Destructor + */ +Kivio1DStencil::~Kivio1DStencil() +{ + delete m_pFillStyle; + delete m_pLineStyle; + delete m_pTextStyle; + delete m_pConnectorPoints; +} + +void Kivio1DStencil::setFGColor( QColor c ) +{ + m_pLineStyle->setColor(c); +} + +QColor Kivio1DStencil::fgColor() +{ + return m_pLineStyle->color(); +} + +void Kivio1DStencil::setLineWidth( double f ) +{ + m_pLineStyle->setWidth(f); +} + +double Kivio1DStencil::lineWidth() +{ + return m_pLineStyle->width(); +} + +void Kivio1DStencil::setLinePattern(int p) +{ + m_pLineStyle->setStyle(p); +} + +int Kivio1DStencil::linePattern() +{ + return m_pLineStyle->style(); +} + +void Kivio1DStencil::setFillPattern(int p) +{ + m_pFillStyle->setBrushStyle(static_cast<Qt::BrushStyle>(p)); +} + +int Kivio1DStencil::fillPattern() +{ + return m_pFillStyle->brushStyle(); +} + +void Kivio1DStencil::setBGColor( QColor c ) +{ + m_pFillStyle->setColor(c); +} + +QColor Kivio1DStencil::bgColor() +{ + return m_pFillStyle->color(); +} + + +///////////////////////////////// +// Position functions +///////////////////////////////// +void Kivio1DStencil::setX( double x ) +{ + double dx = x - m_x; + KivioConnectorPoint *p = m_pConnectorPoints->first(); + + while( p ) + { + p->disconnect(); + p->setX( p->x() + dx, false ); + p = m_pConnectorPoints->next(); + } + + m_x = x; +} + +void Kivio1DStencil::setY( double y ) +{ + double dy = y - m_y; + KivioConnectorPoint *p = m_pConnectorPoints->first(); + + while( p ) + { + p->disconnect(); + p->setY( p->y() + dy, false ); + p = m_pConnectorPoints->next(); + } + + m_y = y; +} + +void Kivio1DStencil::setPosition( double x, double y ) +{ + double dx = x - m_x; + double dy = y - m_y; + + m_x += dx; + m_y += dy; + + KivioConnectorPoint *p = m_pConnectorPoints->first(); + while( p ) + { + p->setPosition( p->x()+dx, p->y()+dy, false ); + p->disconnect(); + + p = m_pConnectorPoints->next(); + } + + + m_x = x; + m_y = y; +} + + + +///////////////////////////// +// Connection tool functions +///////////////////////////// +void Kivio1DStencil::setStartPoint( double x, double y ) +{ + double oldX = m_pStart->x(); + double oldY = m_pStart->y(); + + m_pStart->setPosition(x, y, false); + m_pStart->disconnect(); + + updateConnectorPoints(m_pStart, oldX, oldY); +} + + +void Kivio1DStencil::setEndPoint( double x, double y ) +{ + double oldX = m_pEnd->x(); + double oldY = m_pEnd->y(); + + m_pEnd->setPosition(x, y, false); + m_pEnd->disconnect(); + + updateConnectorPoints(m_pEnd, oldX, oldY); +} + +void Kivio1DStencil::updateConnectorPoints( KivioConnectorPoint *p, double /*oldX*/, double /*oldY*/ ) +{ + // If p is the start or end, we need to adjust the width connectors + if( p == m_pStart || p == m_pEnd ) + { + double vx = m_pStart->x() - m_pEnd->x(); + double vy = m_pStart->y() - m_pEnd->y(); + double len = sqrt( vx*vx + vy*vy ); + double midX = (m_pStart->x() + m_pEnd->x())/2.0f; + double midY = (m_pStart->y() + m_pEnd->y())/2.0f; + + vx /= len; + vy /= len; + + double d = m_connectorWidth/2.0f; + + m_pLeft->setPosition( midX + d*vy, midY + d*(-vx), false ); + m_pRight->setPosition( midX + d*(-vy), midY + d*vx, false ); + } + + updateGeometry(); +} + + +void Kivio1DStencil::paint( KivioIntraStencilData * ) +{ + /* Derived class must implement this */ +} + +void Kivio1DStencil::paintOutline( KivioIntraStencilData *pData ) +{ + /* Derived class should implement this */ + paint( pData ); +} + +void Kivio1DStencil::paintConnectorTargets( KivioIntraStencilData * ) +{ +} + +void Kivio1DStencil::paintSelectionHandles( KivioIntraStencilData *pData ) +{ + KivioPainter *painter = pData->painter; + double x1, y1; + int flag; + + KoZoomHandler* zoomHandler = pData->zoomHandler; + + KivioConnectorPoint *p = m_pConnectorPoints->first(); + while( p ) + { + // If we don't need width connectors and we are on a width connector, + // ignore it. + x1 = zoomHandler->zoomItX(p->x()); + y1 = zoomHandler->zoomItY(p->y()); + + flag = (p->target()) ? KivioPainter::cpfConnected : 0; + + if( p==m_pTextConn ) + { + if( m_needsText==true ) + { + painter->drawHandle( x1, y1, 0 ); + } + } + else if( p==m_pLeft || p==m_pRight ) + { + if( m_needsWidth==true ) + { + painter->drawHandle( x1, y1, 0 ); + } + } + else if( p==m_pStart ) + { + painter->drawHandle( x1, y1, KivioPainter::cpfStart | flag ); + } + else if( p==m_pEnd ) + { + painter->drawHandle( x1, y1, KivioPainter::cpfEnd | flag ); + } + else + { + if( p->connectable() ) { + painter->drawHandle( x1, y1, KivioPainter::cpfConnectable | flag ); + } else { + painter->drawHandle( x1, y1, flag ); + } + } + + p = m_pConnectorPoints->next(); + } +} + + + +/////////////////////////////// +// Collision detection +/////////////////////////////// +KivioCollisionType Kivio1DStencil::checkForCollision( KoPoint *, double ) +{ + /* Derived class must implement this */ + + return kctNone; +} + + + + +///////////////////////////////// +// Custom dragging +///////////////////////////////// +/** + * Custom drag the connector points. + * + * The default action of this function is to locate the point + * in the connector list by the id and then drag it around. + * Then attempt to snap it to another stencil. Otherwise + * disconnect it. + */ +void Kivio1DStencil::customDrag( KivioCustomDragData *pData ) +{ + setCustomIDPoint(pData->id, KoPoint(pData->x, pData->y), pData->page); +} + + +/** + * Sets the position and dimensions of this stencil based on its connection points. + */ +void Kivio1DStencil::updateGeometry() +{ + double minX, minY, maxX, maxY; + + minX = 1000000000000.0f; + minY = minX; + maxX = -100000000000.0f; + maxY = maxX; + + + KivioConnectorPoint *p; + p = m_pConnectorPoints->first(); + while( p ) + { + if( p->x() < minX ) + minX = p->x(); + if( p->x() > maxX ) + maxX = p->x(); + if( p->y() < minY ) + minY = p->y(); + if( p->y() > maxY ) + maxY = p->y(); + + p = m_pConnectorPoints->next(); + } + + + m_x = minX; + m_y = minY; + m_w = maxX - minX + 1.0f; + m_h = maxY - minY + 1.0f; +} + + + +// file i/o routines +bool Kivio1DStencil::loadXML( const QDomElement &e ) +{ + QDomNode node; + QString name; + + node = e.firstChild(); + while( !node.isNull() ) + { + name = node.nodeName(); + + if( name == "KivioStencilProperties" ) + { + loadProperties(node.toElement() ); + } + + node = node.nextSibling(); + } + + updateGeometry(); + + return true; +} + + +QDomElement Kivio1DStencil::createRootElement( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioPluginStencil"); + + XmlWriteString( e, "id", m_pSpawner->info()->id() ); + XmlWriteString( e, "setId", m_pSpawner->set()->id() ); + + return e; +} + + +QDomElement Kivio1DStencil::saveXML( QDomDocument &doc ) +{ + QDomElement e = createRootElement(doc); + + e.appendChild( saveProperties(doc) ); + + return e; +} + + + +KivioStencil *Kivio1DStencil::duplicate() +{ + /* Derived class must implement this function */ + return NULL; +} + + +bool Kivio1DStencil::boolAllTrue( bool *boolArray, int count ) +{ + int i; + + for( i=0; i<count; i++ ) + { + if( boolArray[i]==false ) + return false; + } + + return true; +} + +bool Kivio1DStencil::boolContainsFalse( bool *boolArray, int count ) +{ + int i; + + for( i=0; i<count; i++ ) + { + if( boolArray[i]==false ) + return true; + } + + return false; +} + +void Kivio1DStencil::searchForConnections( KivioPage *pPage ) +{ + bool *done = new bool[ m_pConnectorPoints->count()]; + unsigned int i; + + for(i = 0; i < m_pConnectorPoints->count(); i++) { + done[i] = false; + } + + KivioConnectorPoint *p; + i = 0; + p = m_pConnectorPoints->first(); + + while( p ) + { + if( p->targetId() == -1 ) { + done[i] = true; + } + + i++; + p = m_pConnectorPoints->next(); + } + + // No connections? BaiL! + if( boolAllTrue( done, m_pConnectorPoints->count() ) ) + { + delete [] done; + return; + } + + KivioLayer *pLayer = pPage->firstLayer(); + + while( pLayer && ( boolContainsFalse(done, m_pConnectorPoints->count()) ) ) + { + KivioStencil *pStencil = pLayer->firstStencil(); + + while( pStencil && ( boolContainsFalse(done, m_pConnectorPoints->count()) ) ) + { + // No connecting to ourself! + if((pStencil != this)) + { + + // Iterate through all connectors attempting to connect it to the stencil. + // If it connects, mark it as done + i=0; + p = m_pConnectorPoints->first(); + while( p ) + { + if( !done[i] && p->targetId() != -1 ) + { + if(pStencil->connectToTarget( p, p->targetId())) + { + done[i] = true; + } + } + + i++; + p = m_pConnectorPoints->next(); + } + + } + + pStencil = pLayer->nextStencil(); + } + + pLayer = pPage->nextLayer(); + } + + delete [] done; +} + +void Kivio1DStencil::searchForConnections( KivioPage *pPage, double threshold ) +{ + bool *done = new bool[ m_pConnectorPoints->count()]; + int i; + + for( i=0; i<(int)m_pConnectorPoints->count(); i++ ) { + done[i] = false; + } + + KivioConnectorPoint *p; + i = 0; + p = m_pConnectorPoints->first(); + + while( p ) + { + if(p->target() != 0L) { + done[i] = true; + } + + i++; + p = m_pConnectorPoints->next(); + } + + // No connections? BaiL! + if( boolAllTrue( done, m_pConnectorPoints->count() ) ) + { + delete [] done; + return; + } + + KivioLayer *pLayer = pPage->firstLayer(); + + while( pLayer && ( boolContainsFalse(done, m_pConnectorPoints->count()) ) ) + { + KivioStencil *pStencil = pLayer->firstStencil(); + + while( pStencil && ( boolContainsFalse(done, m_pConnectorPoints->count()) ) ) + { + // No connecting to ourself! + if( pStencil != this ) + { + + // Iterate through all connectors attempting to connect it to the stencil. + // If it connects, mark it as done + i = 0; + p = m_pConnectorPoints->first(); + + while( p ) + { + if( !done[i] && p->target() == 0 ) + { + if( pStencil->connectToTarget( p, threshold ) ) + { + done[i] = true; + } + } + + i++; + p = m_pConnectorPoints->next(); + } + + } + + pStencil = pLayer->nextStencil(); + } + + pLayer = pPage->nextLayer(); + } + + delete [] done; +} + +////////////////////// +// resize handles +////////////////////// +int Kivio1DStencil::resizeHandlePositions() +{ + return (int)krhpNone; +} + +QDomElement Kivio1DStencil::saveConnectors( QDomDocument &doc ) +{ + QDomElement eConns = doc.createElement("KivioConnectorList"); + + KivioConnectorPoint *p; + p = m_pConnectorPoints->first(); + while( p ) + { + eConns.appendChild( p->saveXML(doc) ); + + p = m_pConnectorPoints->next(); + } + + return eConns; +} + +bool Kivio1DStencil::loadConnectors( const QDomElement &e ) +{ + m_pConnectorPoints->clear(); + + KivioConnectorPoint *p; + + QDomNode node = e.firstChild(); + QDomElement e2; + QString name; + + while( !node.isNull() ) + { + e2 = node.toElement(); + name = e2.nodeName(); + + if( name == "KivioConnectorPoint" ) + { + p = new KivioConnectorPoint(); + p->setStencil(this); + p->loadXML( e2 ); + + m_pConnectorPoints->append( p ); + p = NULL; + } + + node = node.nextSibling(); + } + + // Set the pointers to the start,end,left,right points + m_pStart = m_pConnectorPoints->first(); + m_pEnd = m_pConnectorPoints->next(); + m_pLeft = m_pConnectorPoints->next(); + m_pRight = m_pConnectorPoints->next(); + m_pTextConn = m_pConnectorPoints->next(); + + // Hopefully this will help with backwards compatibility + if( m_pStart == NULL ) { + m_pStart = new KivioConnectorPoint(this, true); + } + if( m_pEnd == NULL ) { + m_pEnd = new KivioConnectorPoint(this, true); + } + if( m_pLeft == NULL ) { + m_pLeft = new KivioConnectorPoint(this, false); + } + if( m_pRight == NULL ) { + m_pRight = new KivioConnectorPoint(this, false); + } + if( m_pTextConn == NULL ) { + m_pTextConn = new KivioConnectorPoint(this, false); + } + + + return true; +} + +QDomElement Kivio1DStencil::saveProperties( QDomDocument &doc ) +{ + QDomElement propE = doc.createElement("KivioStencilProperties"); + + QDomElement connE = doc.createElement("Kivio1DProperties"); + XmlWriteFloat( connE, "connectorWidth", m_connectorWidth ); + XmlWriteInt( connE, "needsWidth", m_needsWidth ); + propE.appendChild( connE ); + + propE.appendChild( m_pLineStyle->saveXML( doc ) ); + + propE.appendChild( m_pFillStyle->saveXML( doc ) ); + + propE.appendChild( m_pTextStyle->saveXML( doc ) ); + + propE.appendChild( saveConnectors(doc) ); + + QDomElement customE = doc.createElement("CustomData"); + if( saveCustom( customE, doc )==true ) + { + propE.appendChild( customE ); + } + + return propE; +} + +bool Kivio1DStencil::loadProperties( const QDomElement &e ) +{ + QDomNode node; + QDomElement nodeE; + QString nodeName; + + node = e.firstChild(); + while( !node.isNull() ) + { + nodeE = node.toElement(); + nodeName = node.nodeName(); + + if( nodeName == "KivioFillStyle" ) + { + m_pFillStyle->loadXML( nodeE ); + } + else if( nodeName == "KivioLineStyle" ) + { + m_pLineStyle->loadXML( nodeE ); + } + else if( nodeName == "KivioTextStyle" ) + { + m_pTextStyle->loadXML( nodeE ); + } + else if( nodeName == "KivioConnectorList" ) + { + loadConnectors( nodeE ); + } + else if( nodeName == "Kivio1DProperties" ) + { + m_needsWidth = (bool)XmlReadInt( nodeE, "needsWidth", (int)true ); + m_connectorWidth = XmlReadFloat( nodeE, "connectorWidth", 36.0f ); + } + else if( nodeName == "CustomData" ) + { + loadCustom( nodeE ); + } + + node = node.nextSibling(); + } + + return true; +} + +bool Kivio1DStencil::loadCustom( const QDomElement & ) +{ + return true; +} + +bool Kivio1DStencil::saveCustom( QDomElement &, QDomDocument & ) +{ + return false; +} + +void Kivio1DStencil::copyBasicInto( Kivio1DStencil *pStencil ) +{ + KivioConnectorPoint *pSrc, *pTg; + + // Copy the spawner + pStencil->setSpawner( m_pSpawner ); + + // Copy the connector points + pSrc = m_pConnectorPoints->first(); + pTg = pStencil->m_pConnectorPoints->first(); + while( pSrc && pTg ) + { + pTg->setPosition( pSrc->x(), pSrc->y(), false ); + + pSrc = m_pConnectorPoints->next(); + pTg = pStencil->m_pConnectorPoints->next(); + } + + // Copy the dimensions + pStencil->m_x = m_x; + pStencil->m_y = m_y; + pStencil->m_w = m_w; + pStencil->m_h = m_h; + + // Copy over the width info + pStencil->m_connectorWidth = m_connectorWidth; + pStencil->m_needsWidth = m_needsWidth; + + // Copy over the styles + m_pFillStyle->copyInto( pStencil->m_pFillStyle ); + m_pLineStyle->copyInto( pStencil->m_pLineStyle ); + m_pTextStyle->copyInto( pStencil->m_pTextStyle ); + + // Copy over the protection + *(pStencil->m_pProtection) = *m_pProtection; + *(pStencil->m_pCanProtect) = *m_pCanProtect; +} + +void Kivio1DStencil::drawText( KivioIntraStencilData *pData ) +{ + if(m_pTextStyle->text().isEmpty()) { + return; + } + + KoZoomHandler* zoomHandler = pData->zoomHandler; + KivioPainter *painter = pData->painter; + + int _x, _y, _w, _h; + + _x = zoomHandler->zoomItX(m_pTextConn->x()); + _y = zoomHandler->zoomItY(m_pTextConn->y()); + _w = 10000000; + _h = 10000000; + + QFont f = m_pTextStyle->font(); + int tf = m_pTextStyle->hTextAlign() | m_pTextStyle->vTextAlign(); + + f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0)); + painter->setFont(f); + QRect boundRect = painter->boundingRect( _x, _y, _w, _h, tf, m_pTextStyle->text() ); + QPixmap pix(boundRect.width(), boundRect.height()); + pix.fill(); + QPainter p(&pix); + p.setPen(m_pTextStyle->color()); + p.setFont(f); + p.drawText( 0, 0, boundRect.width(), boundRect.height(), tf, m_pTextStyle->text() ); + QBitmap mask; + mask = pix; + pix.setMask(mask); + painter->drawPixmap(_x, _y, pix); +} + +bool Kivio1DStencil::connected() +{ + KivioConnectorPoint *p; + p = m_pConnectorPoints->first(); + + while( p ) + { + if(p->target() != 0) { + return true; + } + + p = m_pConnectorPoints->next(); + } + + return false; +} + +void Kivio1DStencil::disconnectFromTargets() +{ + KivioConnectorPoint *p; + p = m_pConnectorPoints->first(); + + while( p ) + { + p->disconnect(true); + p = m_pConnectorPoints->next(); + } +} + +KivioLineStyle Kivio1DStencil::lineStyle() +{ + return *m_pLineStyle; +} + +void Kivio1DStencil::setLineStyle(KivioLineStyle ls) +{ + ls.copyInto(m_pLineStyle); +} + +void Kivio1DStencil::setCustomIDPoint(int customID, const KoPoint& point, KivioPage* page) +{ + double oldX, oldY; + KivioConnectorPoint *p; + + // Locate the point specified by customID + p = m_pConnectorPoints->at( customID - (kctCustom+1)); + + if( !p ) + { + kdDebug(43000) << "Kivio1DStencil::customDrag() - KivioConnectorPoint customID: " << (customID - (kctCustom+1)) << " not found\n" << endl; + return; + } + + oldX = p->x(); + oldY = p->y(); + p->setPosition(point.x(),point.y(),true); + + if( p->connectable()==true ) + { + // Attempt a snap.... + KivioLayer *pCurLayer = page->curLayer(); + KivioLayer *pLayer = page->firstLayer(); //page->curLayer(); + bool foundConnection = false; + + while( pLayer && !foundConnection ) + { + // To be connected to, a layer must be visible and connectable + if( pLayer!=pCurLayer ) + { + if( pLayer->connectable()==false || pLayer->visible()==false ) + { + pLayer = page->nextLayer(); + continue; + } + } + + // Tell the layer to search for a target + if( pLayer->connectPointToTarget( p, 8.0f ) ) + { + foundConnection = true; + } + + pLayer = page->nextLayer(); + } + + if( foundConnection == false ) + { + p->disconnect(); + } + } + + // If it is a start/end point, then make a request to update the connectors (must be implemented by stencil developer) + if( customID == kctCustom+1 || customID == kctCustom+2 ) + { + // If it's the end connector, then update the text point + if( p==m_pEnd && m_needsText==true ) + { + m_pTextConn->setPosition( m_pTextConn->x() + (m_pEnd->x() - oldX), + m_pTextConn->y() + (m_pEnd->y() - oldY), false ); + } + + updateConnectorPoints(p, oldX, oldY); + } + // If it is one of the width handles, then fix the width and update the opposite point + // only if the stencils 'needs width' connectors + else if( (customID == kctCustom+3 || customID == kctCustom+4) && (m_needsWidth==true) ) + { + double vx = m_pStart->x() - m_pEnd->x(); + double vy = m_pStart->y() - m_pEnd->y(); + double len = sqrt( vx*vx + vy*vy ); + double midX = (m_pStart->x() + m_pEnd->x())/2.0f; + double midY = (m_pStart->y() + m_pEnd->y())/2.0f; + + vx /= len; + vy /= len; + + double d = shortestDistance( m_pStart, m_pEnd, (customID==kctCustom+3) ? m_pLeft : m_pRight ); + + m_pLeft->setPosition( midX + d*vy, midY + d*(-vx), false ); + m_pRight->setPosition( midX + d*(-vy), midY + d*vx, false ); + + m_connectorWidth = d*2.0f; + + updateConnectorPoints(p, oldX, oldY); + return; + } + // Text handle + else if( customID == kctCustom+5 ) + { + updateConnectorPoints(p, oldX, oldY); + } +} + +KoPoint Kivio1DStencil::customIDPoint(int customID) +{ + KivioConnectorPoint *p; + + // Locate the point specified by customID + p = m_pConnectorPoints->at( customID - (kctCustom+1)); + + return p->position(); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_1d_stencil.h b/kivio/kiviopart/kiviosdk/kivio_1d_stencil.h new file mode 100644 index 000000000..a1af20863 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_1d_stencil.h @@ -0,0 +1,158 @@ +#ifndef _KIVIO_1D_STENCIL_H +#define _KIVIO_1D_STENCIL_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qdom.h> +#include <qptrlist.h> + +#include <koffice_export.h> + +#include "kivio_stencil.h" +#include "kivio_text_style.h" + +class KivioArrowHead; +class KivioConnectorPoint; +class KivioCustomDragData; +class KivioFillStyle; +class KivioLineStyle; +class KivioIntraStencilData; +class KivioStencil; + + +class KIVIO_EXPORT Kivio1DStencil : public KivioStencil +{ +protected: + QPtrList <KivioConnectorPoint> *m_pConnectorPoints; + + KivioConnectorPoint *m_pStart, *m_pEnd; + KivioConnectorPoint *m_pLeft, *m_pRight; + KivioConnectorPoint *m_pTextConn; + + double m_connectorWidth; + bool m_needsWidth; + bool m_needsText; + + KivioFillStyle *m_pFillStyle; + KivioLineStyle *m_pLineStyle; + KivioTextStyle *m_pTextStyle; + + // Utility routines + bool boolAllTrue( bool *, int ); + bool boolContainsFalse( bool *, int ); + + virtual QDomElement createRootElement( QDomDocument & ); + + virtual bool saveCustom( QDomElement &, QDomDocument & ); + QDomElement saveConnectors( QDomDocument &doc ); + QDomElement saveProperties( QDomDocument &doc ); + + virtual bool loadCustom( const QDomElement & ); + bool loadConnectors( const QDomElement & ); + bool loadProperties( const QDomElement & ); + + // For easier duplication + void copyBasicInto( Kivio1DStencil * ); + void drawText( KivioIntraStencilData * ); + +public: + Kivio1DStencil(); + virtual ~Kivio1DStencil(); + + virtual bool connected(); + + // fg color functions + virtual void setFGColor( QColor c ); + virtual QColor fgColor(); + + + // bg color functions + virtual void setBGColor( QColor c ); + virtual QColor bgColor(); + + virtual void setText( const QString & t ) { m_pTextStyle->setText(t); } + virtual QString text() { return m_pTextStyle->text(); } + + virtual void setTextColor( QColor c ) { m_pTextStyle->setColor(c); } + virtual QColor textColor() { return m_pTextStyle->color(); } + + virtual QFont textFont() { return m_pTextStyle->font(); } + virtual void setTextFont( const QFont &f ) { m_pTextStyle->setFont(f); } + + virtual int hTextAlign() { return m_pTextStyle->hTextAlign(); } + virtual int vTextAlign() { return m_pTextStyle->vTextAlign(); } + + virtual void setHTextAlign(int i) { m_pTextStyle->setHTextAlign(i); } + virtual void setVTextAlign(int i) { m_pTextStyle->setVTextAlign(i); } + + + // line width functions + virtual void setLineWidth( double f ); + virtual double lineWidth(); + + virtual void setLinePattern(int p); + virtual int linePattern(); + + virtual void setFillPattern(int p); + virtual int fillPattern(); + + // position functions + virtual void setX( double ); + virtual void setY( double ); + virtual void setPosition( double, double ); + + + // required for connector tool + virtual void setStartPoint( double, double ); + virtual void setEndPoint( double, double ); + + + // painting functions + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + virtual void paintSelectionHandles( KivioIntraStencilData * ); + + + // collision detection + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + + + // custom dragging + virtual void customDrag( KivioCustomDragData * ); + + + // geometry management + virtual void updateGeometry(); + virtual void updateConnectorPoints( KivioConnectorPoint *, double, double ); + + + // file i/o routines + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + + + // duplication routines + virtual KivioStencil* duplicate(); + + + // connection search routines + virtual void searchForConnections( KivioPage * ); + virtual void searchForConnections( KivioPage *pPage, double threshold ); + + + // returns which resize handles are valid + virtual int resizeHandlePositions(); + + virtual void disconnectFromTargets(); + virtual KivioLineStyle lineStyle(); + virtual void setLineStyle(KivioLineStyle ls); + + virtual void setCustomIDPoint(int customID, const KoPoint& point, KivioPage* page); + virtual KoPoint customIDPoint(int customID); +}; + + +#endif diff --git a/kivio/kiviopart/kiviosdk/kivio_arrowhead.cpp b/kivio/kiviopart/kiviosdk/kivio_arrowhead.cpp new file mode 100644 index 000000000..de464113d --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_arrowhead.cpp @@ -0,0 +1,786 @@ +/* + * 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 "kivio_arrowhead.h" +#include "kivio_common.h" +#include "kivio_painter.h" +#include "kivio_point.h" +#include "kivio_fill_style.h" + +#include <math.h> +#include <kdebug.h> +#include <KoZoomHandler.h> + +KivioArrowHead::KivioArrowHead() +{ + // Both of these values are in pixels + m_cut = 0.0f; + m_w = m_l = 10.0f; + + m_type = kahtNone; +} + +KivioArrowHead::~KivioArrowHead() +{ +} + +QDomElement KivioArrowHead::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioArrowHead"); + + XmlWriteFloat( e, "cut", m_cut ); + XmlWriteFloat( e, "w", m_w ); + XmlWriteFloat( e, "l", m_l ); + XmlWriteInt( e, "type", m_type ); + + return e; +} + +bool KivioArrowHead::loadXML( const QDomElement &e ) +{ + m_cut = XmlReadFloat( e, "cut", 0.0f ); + m_w = XmlReadFloat( e, "w", 10.0f ); + m_l = XmlReadFloat( e, "l", 10.0f ); + m_type = XmlReadInt( e, "type", m_type ); + + return true; +} + +void KivioArrowHead::setType(int t) +{ + m_type = t; + + switch( t ) + { + case kahtNone: + m_cut = 0.0f; + break; + + case kahtArrowLine: + case kahtForwardSlash: + case kahtBackSlash: + case kahtPipe: + case kahtCrowFoot: + case kahtFork: + case kahtCrowFootPipe: + case kahtMidForwardSlash: + case kahtMidBackSlash: + case kahtMidPipe: + m_cut = 0.0f; + break; + + case kahtArrowTriangleSolid: + case kahtArrowTriangleHollow: + case kahtDoubleTriangleSolid: + case kahtDoubleTriangleHollow: + case kahtDiamondSolid: + case kahtDiamondHollow: +// case kahtCircleSolid: +// case kahtCircleHollow: + m_cut = KIVIO_CUT_LENGTH; + break; + + default: + m_type = kahtNone; + m_cut = 0.0f; + break; + } +} + +float KivioArrowHead::cut() +{ + if( m_cut == KIVIO_CUT_LENGTH ) + return m_l; + + else if( m_cut == KIVIO_CUT_HALF_LENGTH ) + return m_l / 2.0f; + + return m_cut; +} + +/** + * Paints the arrow head at a given point, direction, and scale. + * + * @param painter The painter object to draw with + * @param x The x position of the arrow head (the point) + * @param y The y position of the arrow head (the point) + * @param vecX The X component of the negative direction vector + * @param vecY The Y component of the negative direction vector + * @param zoomHandler The zoom handler to use to scale + * + * The (x,y) should be the vertex + * representing the endpoint of the line. The <vecX, vecY> is a vector + * pointing to (x,y) (in the direction of the arrow head). + */ +void KivioArrowHead::paint( KivioPainter *painter, float x, float y, float vecX, float vecY, KoZoomHandler* zoomHandler ) +{ + KivioArrowHeadData d; + + d.painter = painter; + d.x = x; + d.y = y; + d.vecX = vecX; + d.vecY = vecY; + d.zoomHandler = zoomHandler; + + // One big-ass switch statement + switch( m_type ) + { + case kahtNone: + return; + + case kahtArrowLine: + paintArrowLine( &d ); + break; + + case kahtArrowTriangleSolid: + paintArrowTriangle( &d, true ); + break; + + case kahtArrowTriangleHollow: + paintArrowTriangle( &d, false ); + break; + + case kahtDoubleTriangleSolid: + paintDoubleTriangle( &d, true ); + break; + + case kahtDoubleTriangleHollow: + paintDoubleTriangle( &d, false ); + break; + + case kahtForwardSlash: + paintForwardSlash( &d ); + break; + + case kahtBackSlash: + paintBackSlash( &d ); + break; + + case kahtPipe: + paintPipe( &d ); + break; + + case kahtMidForwardSlash: + paintMidForwardSlash( &d ); + break; + + case kahtMidBackSlash: + paintMidBackSlash( &d ); + break; + + case kahtMidPipe: + paintMidPipe( &d ); + break; + + case kahtDiamondSolid: + paintDiamond( &d, true ); + break; + + case kahtDiamondHollow: + paintDiamond( &d, false ); + break; + + case kahtCrowFoot: + paintCrowFoot( &d ); + break; + + case kahtFork: + paintFork( &d ); + break; + + case kahtCrowFootPipe: + paintCrowFootPipe( &d ); + break; +/* + case kahtCircleSolid: + paintCircle( &d, true ); + break; + + case kahtCircleHollow: + paintCircle( &d, false ); + break; +*/ + default: + break; + } +} + +void KivioArrowHead::paintArrowLine( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + float length; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + QPtrList<KivioPoint>l; + l.setAutoDelete(true); + + float _x; + float _y; + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX(d->x); + _y = zoomHandler->zoomItY(d->y); + + l.append( new KivioPoint( _x, _y ) ); // point + + + pvecX *= -1.0f; + pvecY *= -1.0f; + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + + painter->drawPolyline( &l ); +} + +void KivioArrowHead::paintArrowTriangle( KivioArrowHeadData *d, bool solid ) +{ + KivioPainter *painter = d->painter; + QColor cbg = painter->bgColor(); + + if(solid) { + painter->setBGColor(painter->fgColor()); + } + + float vecX = d->vecX; + float vecY = d->vecY; + + float length; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + QPtrList<KivioPoint>l; + l.setAutoDelete(true); + + float _x = zoomHandler->zoomItX(d->x); + float _y = zoomHandler->zoomItY(d->y); + + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + pvecX *= -1.0f; + pvecY *= -1.0f; + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + l.append( new KivioPoint( zoomHandler->zoomItX(d->x), zoomHandler->zoomItY(d->y) ) ); + + painter->drawPolygon( &l ); + painter->setBGColor(cbg); +} + +void KivioArrowHead::paintDoubleTriangle( KivioArrowHeadData *d, bool solid ) +{ + KivioPainter *painter = d->painter; + QColor cbg = painter->bgColor(); + + if(solid) { + painter->setBGColor(painter->fgColor()); + } + + float vecX = d->vecX; + float vecY = d->vecY; + + float length; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + QPtrList<KivioPoint> l1; + l1.setAutoDelete(true); + QPtrList<KivioPoint> l2; + l2.setAutoDelete(true); + + float _x = zoomHandler->zoomItX(d->x); + float _y = zoomHandler->zoomItY(d->y); + l1.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX(d->x + nvecX * (m_l / 2.0f)); + _y = zoomHandler->zoomItY(d->y + nvecY * (m_l / 2.0f)); + l2.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * (m_l / 2.0f)) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * (m_l / 2.0f)) + pvecY*(m_w/2.0f)); + l1.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + l2.append( new KivioPoint( _x, _y ) ); + + pvecX *= -1.0f; + pvecY *= -1.0f; + + _x = zoomHandler->zoomItX((d->x + nvecX * (m_l / 2.0f)) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * (m_l / 2.0f)) + pvecY*(m_w/2.0f)); + l1.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + l2.append( new KivioPoint( _x, _y ) ); + + l1.append( new KivioPoint( zoomHandler->zoomItX(d->x), zoomHandler->zoomItY(d->y) ) ); + + _x = zoomHandler->zoomItX(d->x + nvecX * (m_l / 2.0f)); + _y = zoomHandler->zoomItY(d->y + nvecY * (m_l / 2.0f)); + l2.append( new KivioPoint( _x, _y ) ); + + painter->drawPolygon( &l1 ); + painter->drawPolygon( &l2 ); + painter->setBGColor(cbg); +} + +void KivioArrowHead::paintForwardSlash( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX((d->x + nvecX * (m_l/2.0f)) + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY((d->y + nvecY * (m_l/2.0f)) + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX((d->x - nvecX * (m_l/2.0f)) - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY((d->y - nvecY * (m_l/2.0f)) - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); +} + +void KivioArrowHead::paintBackSlash( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX((d->x - nvecX * (m_l/2.0f)) + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY((d->y - nvecY * (m_l/2.0f)) + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX((d->x + nvecX * (m_l/2.0f)) - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY((d->y + nvecY * (m_l/2.0f)) - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); +} + +void KivioArrowHead::paintPipe( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX(d->x + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY(d->y + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX(d->x - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY(d->y - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); +} + +void KivioArrowHead::paintDiamond( KivioArrowHeadData *d, bool solid ) +{ + KivioPainter *painter = d->painter; + QColor cbg = painter->bgColor(); + + if(solid) { + painter->setBGColor(painter->fgColor()); + } + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + QPtrList<KivioPoint> l; + l.setAutoDelete(true); + + float _x = zoomHandler->zoomItX(d->x); + float _y = zoomHandler->zoomItY(d->y); + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * (m_l/2.0f)) - pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * (m_l/2.0f)) - pvecY*(m_w/2.0f)); + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l)); + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * (m_l/2.0f)) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * (m_l/2.0f)) + pvecY*(m_w/2.0f)); + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX(d->x); + _y = zoomHandler->zoomItY(d->y); + l.append( new KivioPoint( _x, _y ) ); + + painter->drawPolygon( &l ); + painter->setBGColor(cbg); +} + +void KivioArrowHead::paintCircle( KivioArrowHeadData *d, bool solid ) +{ + KivioPainter *painter = d->painter; + QColor cbg = painter->bgColor(); + + if(solid) { + painter->setBGColor(painter->fgColor()); + } + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x = zoomHandler->zoomItX(d->x + nvecX * (m_l / 2.0f)); + int y = zoomHandler->zoomItY(d->y + nvecY * (m_l / 2.0f)); + int w = zoomHandler->zoomItY(m_w); + int h = zoomHandler->zoomItX(m_l); + + painter->drawEllipse(x, y, w, h); + painter->setBGColor(cbg); +} + +void KivioArrowHead::paintCrowFoot( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + float length; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + QPtrList<KivioPoint>l; + l.setAutoDelete(true); + + float _x; + float _y; + + _x = zoomHandler->zoomItX(d->x + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY(d->y + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX(d->x + nvecX * m_l); + _y = zoomHandler->zoomItY(d->y + nvecY * m_l); + + l.append( new KivioPoint( _x, _y ) ); // point + + + pvecX *= -1.0f; + pvecY *= -1.0f; + + _x = zoomHandler->zoomItX(d->x + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY(d->y + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + + painter->drawPolyline( &l ); +} + +void KivioArrowHead::paintFork( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + float length; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + QPtrList<KivioPoint>l; + l.setAutoDelete(true); + + float _x; + float _y; + + _x = zoomHandler->zoomItX(d->x + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY(d->y + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + pvecX *= -1.0f; + pvecY *= -1.0f; + + _x = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + _x = zoomHandler->zoomItX(d->x + pvecX*(m_w/2.0f)); + _y = zoomHandler->zoomItY(d->y + pvecY*(m_w/2.0f)); + + l.append( new KivioPoint( _x, _y ) ); + + + painter->drawPolyline( &l ); +} + +void KivioArrowHead::paintCrowFootPipe( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX((d->x + nvecX * m_l) - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY((d->y + nvecY * m_l) - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); + paintCrowFoot( d ); +} + +void KivioArrowHead::paintMidForwardSlash( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX(d->x + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY(d->y + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX((d->x + nvecX * m_l) - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY((d->y + nvecY * m_l) - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); +} + +void KivioArrowHead::paintMidBackSlash( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX((d->x + nvecX * m_l) + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY((d->y + nvecY * m_l) + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX(d->x - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY(d->y - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); +} + +void KivioArrowHead::paintMidPipe( KivioArrowHeadData *d ) +{ + KivioPainter *painter = d->painter; + + float vecX = d->vecX; + float vecY = d->vecY; + + KoZoomHandler* zoomHandler = d->zoomHandler; + + float nvecX, nvecY; // normalized vectors + float pvecX, pvecY; // normal perpendicular vector + + float length = sqrt( vecX*vecX + vecY*vecY ); + + nvecX = - vecX / length; + nvecY = - vecY / length; + + pvecX = nvecY; + pvecY = -nvecX; + + int x1 = zoomHandler->zoomItX((d->x + nvecX * (m_l/2.0f)) + pvecX*(m_w/2.0f)); + int y1 = zoomHandler->zoomItY((d->y + nvecY * (m_l/2.0f)) + pvecY*(m_w/2.0f)); + int x2 = zoomHandler->zoomItX((d->x + nvecX * (m_l/2.0f)) - pvecX*(m_w/2.0f)); + int y2 = zoomHandler->zoomItY((d->y + nvecY * (m_l/2.0f)) - pvecY*(m_w/2.0f)); + + painter->drawLine(x1, y1, x2, y2); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_arrowhead.h b/kivio/kiviopart/kiviosdk/kivio_arrowhead.h new file mode 100644 index 000000000..e76faebf0 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_arrowhead.h @@ -0,0 +1,144 @@ +/* + * 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 KIVIO_ARROWHEAD_H +#define KIVIO_ARROWHEAD_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qcolor.h> +#include <qdom.h> +#include <koffice_export.h> +#define KIVIO_CUT_LENGTH -1.0f +#define KIVIO_CUT_HALF_LENGTH -2.0f + +class KivioPainter; +class KoZoomHandler; + +typedef enum { + kahtNone=0, + kahtArrowLine, + kahtArrowTriangleSolid, + kahtArrowTriangleHollow, + kahtDoubleTriangleSolid, + kahtDoubleTriangleHollow, + kahtForwardSlash, // -----/ + kahtBackSlash, + kahtPipe, // -----| + kahtMidForwardSlash, // -----/-- + kahtMidBackSlash, + kahtMidPipe, // -----|-- + kahtDiamondSolid, + kahtDiamondHollow, + kahtCrowFoot, + kahtFork, + kahtCrowFootPipe +/* kahtArrowTriangleConcaveSolid, + kahtRectangleSolid, + kahtCircleSolid, + kahtCircleHollow, + + kahtCrowFootCircleHollow, + kahtCrowFootCircleSolid, + + kahtFemaleSignHollow, // ------o|- + kahtPipeCircleHollow, // -------|o + kaht2PipeCircleHollow, // ------||o + kaht3PipeCircleHollow, // -----|||o + kahtDiamondCircleHollow, // -----<>o + + kahtPipeFemaleSignSolid, // ------o|- + kahtPipeCircleSolid, // -------|o + kaht2PipeCircleSolid, // ------||o + kaht3PipeCircleSolid, // -----|||o + kahtDiamondCircleSolid, // -----<>o*/ +} KivioArrowHeadType; + + +typedef struct KivioArrowHeadData KivioArrowHeadData; +struct KivioArrowHeadData +{ + float x, y; + float vecX, vecY; + KoZoomHandler* zoomHandler; + + KivioPainter* painter; +}; + + +class KIVIO_EXPORT KivioArrowHead +{ + protected: + /** + * The cut is the distance 'into' the arrowhead the line should continue + */ + float m_cut; + + /** + * The width/length of the arrowhead + */ + float m_w, m_l; + + /** + * The type of arrow + */ + int m_type; + + + void paintArrowLine( KivioArrowHeadData * ); + void paintArrowTriangle( KivioArrowHeadData *, bool ); + void paintDoubleTriangle( KivioArrowHeadData *, bool ); + void paintForwardSlash( KivioArrowHeadData * ); + void paintBackSlash( KivioArrowHeadData * ); + void paintPipe( KivioArrowHeadData * ); + void paintDiamond( KivioArrowHeadData *, bool ); + void paintCircle( KivioArrowHeadData *, bool ); + void paintCrowFoot( KivioArrowHeadData * ); + void paintFork( KivioArrowHeadData * ); + void paintCrowFootPipe( KivioArrowHeadData * ); + void paintMidForwardSlash( KivioArrowHeadData * ); + void paintMidBackSlash( KivioArrowHeadData * ); + void paintMidPipe( KivioArrowHeadData * ); + + public: + KivioArrowHead(); + virtual ~KivioArrowHead(); + + void setType( int ); + inline int type() { return m_type; } + + float cut(); + + void setWidth( float f ) { m_w = f; } + void setLength( float f ) { m_l = f; } + + void setSize( float f1, float f2 ) { m_w=f1; m_l=f2; } + + inline float width() { return m_w; } + inline float length() { return m_l; } + + void paint( KivioPainter *, float, float, float, float, KoZoomHandler* zoomHandler ); + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_base_connector_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_base_connector_stencil.cpp new file mode 100644 index 000000000..9073e1529 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_base_connector_stencil.cpp @@ -0,0 +1,567 @@ +/* + * 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. + */ + +/* + * Implementing a connector involves deriving from this class. + * + * You need to implement the following routines: + * setStartPoint + * setEndPoint + * checkForCollision + * duplicate + * paint + * paintOutline + * saveXML + * loadXML + * + * Save and Load should call saveConnectors, loadConnectors, saveProperties, and + * loadProperties. These are helper functions which take care of the common + * acts of saving/loading connectors and colors/line-styles, etc... + * + */ + +#include "kivio_arrowhead.h" +#include "kivio_base_connector_stencil.h" +#include "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_custom_drag_data.h" +#include "kivio_fill_style.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_layer.h" +#include "kivio_line_style.h" +#include "kivio_page.h" +#include "kivio_painter.h" +#include "kivio_point.h" +#include "kivio_stencil.h" + +#include <kdebug.h> +#include <KoZoomHandler.h> + +/** + * Default constructor. + * + * This will allocate a new fill style object, a list for + * connection points, and set some default values. + */ +KivioBaseConnectorStencil::KivioBaseConnectorStencil() + : KivioStencil() +{ + m_pFillStyle = new KivioFillStyle(); + m_pLineStyle = new KivioLineStyle(); + + m_pConnectorPoints = new QPtrList<KivioConnectorPoint>; + m_pConnectorPoints->setAutoDelete(true); + +} + + +/** + * Destructor + */ +KivioBaseConnectorStencil::~KivioBaseConnectorStencil() +{ + delete m_pFillStyle; + delete m_pLineStyle; + delete m_pConnectorPoints; +} + +void KivioBaseConnectorStencil::setFGColor( QColor c ) +{ + m_pLineStyle->setColor(c); +} + +QColor KivioBaseConnectorStencil::fgColor() +{ + return m_pLineStyle->color(); +} + +void KivioBaseConnectorStencil::setLineWidth( double f ) +{ + m_pLineStyle->setWidth(f); +} + +double KivioBaseConnectorStencil::lineWidth() +{ + return m_pLineStyle->width(); +} + +void KivioBaseConnectorStencil::setBGColor( QColor c ) +{ + m_pFillStyle->setColor(c); +} + +QColor KivioBaseConnectorStencil::bgColor() +{ + return m_pFillStyle->color(); +} + + +///////////////////////////////// +// Position functions +///////////////////////////////// +void KivioBaseConnectorStencil::setX( double x ) +{ + double dx = x - m_x; + + m_x += dx; + + KivioConnectorPoint *p = m_pConnectorPoints->first(); + while( p ) + { + p->setX( p->x() + dx, false ); + p->disconnect(); + + p = m_pConnectorPoints->next(); + } + + + m_x = x; +} + +void KivioBaseConnectorStencil::setY( double y ) +{ + double dy = y - m_y; + + m_y += dy; + + KivioConnectorPoint *p = m_pConnectorPoints->first(); + while( p ) + { + p->setY( p->y() + dy, false ); + p->disconnect(); + + p = m_pConnectorPoints->next(); + } + + m_y = y; +} + +void KivioBaseConnectorStencil::setPosition( double x, double y ) +{ + double dx = x - m_x; + double dy = y - m_y; + + m_x += dx; + m_y += dy; + + KivioConnectorPoint *p = m_pConnectorPoints->first(); + while( p ) + { + p->setPosition( p->x()+dx, p->y()+dy, false ); + p->disconnect(); + + p = m_pConnectorPoints->next(); + } + + + m_x = x; + m_y = y; +} + + + +///////////////////////////// +// Connection tool functions +///////////////////////////// +void KivioBaseConnectorStencil::setStartPoint( double /*x*/, double /*y*/ ) +{ + /* Derived class must implement this function */ + // m_start.setPosition( x, y, false ); + // m_start.disconnect(); +} + + +void KivioBaseConnectorStencil::setEndPoint( double /*x*/, double /*y*/ ) +{ + /* Derived class must implement this function */ + // m_end.setPosition( x, y, false ); + // m_end.disconnect(); +} + + +void KivioBaseConnectorStencil::paint( KivioIntraStencilData * ) +{ + /* Derived class must implement this */ +} + +void KivioBaseConnectorStencil::paintOutline( KivioIntraStencilData *pData ) +{ + /* Derived class should implement this */ + paint( pData ); +} + +void KivioBaseConnectorStencil::paintConnectorTargets( KivioIntraStencilData * ) +{ +} + +void KivioBaseConnectorStencil::paintSelectionHandles( KivioIntraStencilData *pData ) +{ + // Handle Width + const double HW = 6.0f; + const double HWP1 = HW+1.0f; + + // Handle Width Over 2 + const double HWo2 = HW/2.0f; + + // Stencil data + KoZoomHandler* zoomHandler = pData->zoomHandler; + KivioPainter *painter = pData->painter; + double x1, y1; + + painter->setLineWidth(1.0f); + painter->setFGColor(QColor(0,0,0)); + + KivioConnectorPoint *p = m_pConnectorPoints->first(); + while( p ) + { + x1 = zoomHandler->zoomItX(p->x()) - HWo2; + y1 = zoomHandler->zoomItY(p->y()) - HWo2; + + if( p->target() ) + painter->setBGColor(QColor(200,0,0)); + else + painter->setBGColor(QColor(0,200,0)); + + painter->fillRect( x1, y1, HWP1, HWP1 ); + + p = m_pConnectorPoints->next(); + } +} + + + +/////////////////////////////// +// Collision detection +/////////////////////////////// +KivioCollisionType KivioBaseConnectorStencil::checkForCollision( KoPoint *, double ) +{ + /* Derived class must implement this */ + return kctNone; +} + + + + +///////////////////////////////// +// Custom dragging +///////////////////////////////// +/** + * Custom drag the connector points. + * + * The default action of this function is to locate the point + * in the connector list by the id and then drag it around. + * Then attempt to snap it to another stencil. Otherwise + * disconnect it. + */ +void KivioBaseConnectorStencil::customDrag( KivioCustomDragData *pData ) +{ + double _x = pData->x; + double _y = pData->y; + int id = pData->id; + + KivioConnectorPoint *p; + + // Locate the point specified by id + p = m_pConnectorPoints->at( id - (kctCustom+1)); + + if( !p ) + { + kdDebug(43000) << "KivioBaseConnectorStencil::customDrag() - KivioConnectorPoint id: " << (id - (kctCustom+1)) << " not found\n" << endl; + return; + } + + p->setPosition( _x, _y, true ); + + + KivioLayer *pCurLayer = pData->page->curLayer(); + KivioLayer *pLayer = pData->page->firstLayer(); //pData->page->curLayer(); + + while( pLayer ) + { + // To be connected to, a layer must be visible and connectable + if( pLayer!=pCurLayer ) + { + if( pLayer->connectable()==false || pLayer->visible()==false ) + { + pLayer = pData->page->nextLayer(); + continue; + } + } + + // Tell the layer to search for a target + if( pLayer->connectPointToTarget( p, 8.0f ) ) + { + return; + } + + pLayer = pData->page->nextLayer(); + } + + + // Nope, disconnect + p->disconnect(); +} + + +/** + * Sets the position and dimensions of this stencil based on its connection points. + */ +void KivioBaseConnectorStencil::updateGeometry() +{ + double minX, minY, maxX, maxY; + + minX = 1000000000000.0f; + minY = minX; + maxX = -100000000000.0f; + maxY = maxX; + + KivioConnectorPoint *p; + p = m_pConnectorPoints->first(); + while( p ) + { + if( p->x() < minX ) + minX = p->x(); + if( p->x() > maxX ) + maxX = p->x(); + if( p->y() < minY ) + minY = p->y(); + if( p->y() > maxY ) + maxY = p->y(); + + p = m_pConnectorPoints->next(); + } + + m_x = minX; + m_y = minY; + m_w = maxX - minX + 1.0f; + m_h = maxY - minY + 1.0f; +} + + + +// file i/o routines +bool KivioBaseConnectorStencil::loadXML( const QDomElement & ) +{ + return false; +} + +QDomElement KivioBaseConnectorStencil::saveXML( QDomDocument & ) +{ + return QDomElement(); +} + + + +KivioStencil *KivioBaseConnectorStencil::duplicate() +{ + /* Derived class must implement this function */ + return NULL; +} + + +bool KivioBaseConnectorStencil::boolAllTrue( bool *boolArray, int count ) +{ + int i; + + for( i=0; i<count; i++ ) + { + if( boolArray[i]==false ) + return false; + } + + return true; +} + +bool KivioBaseConnectorStencil::boolContainsFalse( bool *boolArray, int count ) +{ + int i; + + for( i=0; i<count; i++ ) + { + if( boolArray[i]==false ) + return true; + } + + return false; +} + + +void KivioBaseConnectorStencil::searchForConnections( KivioPage *pPage ) +{ + bool *done = new bool[ m_pConnectorPoints->count() ]; + + int i; + + for( i=0; i<(int)m_pConnectorPoints->count(); i++ ) + done[i] = false; + + KivioConnectorPoint *p; + + i=0; + p = m_pConnectorPoints->first(); + while( p ) + { + if( p->targetId() == -1 ) + done[i] = true; + + i++; + p = m_pConnectorPoints->next(); + } + + + // No connections? BaiL! + if( boolAllTrue( done, m_pConnectorPoints->count() ) ) + { + delete [] done; + return; + } + + + + KivioLayer *pLayer = pPage->firstLayer(); + while( pLayer && ( boolContainsFalse(done, m_pConnectorPoints->count()) ) ) + { + KivioStencil *pStencil = pLayer->firstStencil(); + + while( pStencil && ( boolContainsFalse(done, m_pConnectorPoints->count()) ) ) + { + // No connecting to ourself! + if( pStencil != this ) + { + + // Iterate through all connectors attempting to connect it to the stencil. + // If it connects, mark it as done + i=0; + p = m_pConnectorPoints->first(); + while( p ) + { + if( !done[i] && + p->targetId() != -1 ) + { + if( pStencil->connectToTarget( p, p->targetId() ) ) + { + done[i] = true; + } + } + + i++; + p = m_pConnectorPoints->next(); + } + + } + + pStencil = pLayer->nextStencil(); + } + + pLayer = pPage->nextLayer(); + } + + delete [] done; +} + + +////////////////////// +// resize handles +////////////////////// +int KivioBaseConnectorStencil::resizeHandlePositions() +{ + return (int)krhpNone; +} + +QDomElement KivioBaseConnectorStencil::saveConnectors( QDomDocument &doc ) +{ + QDomElement eConns = doc.createElement("KivioConnectors"); + + KivioConnectorPoint *p; + p = m_pConnectorPoints->first(); + while( p ) + { + eConns.appendChild( p->saveXML(doc) ); + + p = m_pConnectorPoints->next(); + } + + return eConns; +} + +bool KivioBaseConnectorStencil::loadConnectors( const QDomElement &e ) +{ + m_pConnectorPoints->clear(); + + KivioConnectorPoint *p; + + QDomNode node = e.firstChild(); + QDomElement e2; + QString name; + + while( !node.isNull() ) + { + e2 = node.toElement(); + name = e2.nodeName(); + + if( name == "KivioConnectorPoint" ) + { + p = new KivioConnectorPoint(); + p->setStencil(this); + p->loadXML( e2 ); + + m_pConnectorPoints->append( p ); + p = NULL; + } + + node = node.nextSibling(); + } + + return true; +} + +QDomElement KivioBaseConnectorStencil::saveProperties( QDomDocument &doc ) +{ + QDomElement propE = doc.createElement("KivioConnectorProperties"); + + propE.appendChild( m_pLineStyle->saveXML( doc ) ); + + propE.appendChild( m_pFillStyle->saveXML( doc ) ); + + return propE; +} + +bool KivioBaseConnectorStencil::loadProperties( const QDomElement &e ) +{ + QDomNode node; + QString nodeName; + + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + if( nodeName == "KivioFillStyle" ) + { + m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return true; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_base_connector_stencil.h b/kivio/kiviopart/kiviosdk/kivio_base_connector_stencil.h new file mode 100644 index 000000000..e8d621c0c --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_base_connector_stencil.h @@ -0,0 +1,126 @@ +/* + * 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 KIVIO_BASE_CONNECTOR_STENCIL_H +#define KIVIO_BASE_CONNECTOR_STENCIL_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qdom.h> +#include <qptrlist.h> + +#include "kivio_stencil.h" + +class KivioArrowHead; +class KivioConnectorPoint; +class KivioCustomDragData; +class KivioFillStyle; +class KivioLineStyle; +class KivioIntraStencilData; +class KivioStencil; + +class KivioBaseConnectorStencil : public KivioStencil +{ +protected: + QPtrList <KivioConnectorPoint> *m_pConnectorPoints; + + KivioFillStyle *m_pFillStyle; + KivioLineStyle *m_pLineStyle; + + + // Utility routines + bool boolAllTrue( bool *, int ); + bool boolContainsFalse( bool *, int ); + + QDomElement saveConnectors( QDomDocument &doc ); + bool loadConnectors( const QDomElement & ); + + QDomElement saveProperties( QDomDocument &doc ); + bool loadProperties( const QDomElement & ); + +public: + KivioBaseConnectorStencil(); + virtual ~KivioBaseConnectorStencil(); + + // fg color functions + virtual void setFGColor( QColor c ); + virtual QColor fgColor(); + + + // bg color functions + virtual void setBGColor( QColor c ); + virtual QColor bgColor(); + + + // line width functions + virtual void setLineWidth( double f ); + virtual double lineWidth(); + + + // position functions + virtual void setX( double ); + virtual void setY( double ); + virtual void setPosition( double, double ); + + + // required for connector tool + virtual void setStartPoint( double, double ); + virtual void setEndPoint( double, double ); + + + // painting functions + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + virtual void paintSelectionHandles( KivioIntraStencilData * ); + + + // collision detection + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + + + // custom dragging + virtual void customDrag( KivioCustomDragData * ); + + + // geometry management + virtual void updateGeometry(); + + + // file i/o routines + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + + + // duplication routines + virtual KivioStencil* duplicate(); + + + // connection search routines + virtual void searchForConnections( KivioPage * ); + + + // returns which resize handles are valid + virtual int resizeHandlePositions(); + +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_base_target_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_base_target_stencil.cpp new file mode 100644 index 000000000..8a79c287c --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_base_target_stencil.cpp @@ -0,0 +1,530 @@ +#include "kivio_base_target_stencil.h" +#include "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_connector_target.h" +#include "kivio_fill_style.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_line_style.h" +#include "kivio_painter.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_text_style.h" + +#include <KoZoomHandler.h> + +KivioBaseTargetStencil::KivioBaseTargetStencil() + : KivioStencil() +{ + m_pFillStyle = new KivioFillStyle(); + m_pLineStyle = new KivioLineStyle(); + m_pTextStyle = new KivioTextStyle(); + + m_pTargets = new QPtrList<KivioConnectorTarget>; + m_pTargets->setAutoDelete(true); +} + +KivioBaseTargetStencil::~KivioBaseTargetStencil() +{ + delete m_pFillStyle; + delete m_pLineStyle; + delete m_pTextStyle; + delete m_pTargets; +} + + + + +////////////////////////////////////////////////////////////////////////////// +// +// KivioLineStyle +// +////////////////////////////////////////////////////////////////////////////// +QColor KivioBaseTargetStencil::fgColor() +{ + return m_pLineStyle->color(); +} + +void KivioBaseTargetStencil::setFGColor( QColor c ) +{ + m_pLineStyle->setColor(c); +} + +void KivioBaseTargetStencil::setLineWidth( double l ) +{ + m_pLineStyle->setWidth(l); +} + +double KivioBaseTargetStencil::lineWidth() +{ + return m_pLineStyle->width(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// +// KivioFillStyle +// +////////////////////////////////////////////////////////////////////////////// +void KivioBaseTargetStencil::setBGColor( QColor c ) +{ + m_pFillStyle->setColor(c); +} + +QColor KivioBaseTargetStencil::bgColor() +{ + return m_pFillStyle->color(); +} + +KivioFillStyle *KivioBaseTargetStencil::fillStyle() +{ + return m_pFillStyle; +} + + + + + + +////////////////////////////////////////////////////////////////////////////// +// +// KivioTextStyle +// +////////////////////////////////////////////////////////////////////////////// +QColor KivioBaseTargetStencil::textColor() +{ + return m_pTextStyle->color(); +} +void KivioBaseTargetStencil::setTextColor( QColor c ) +{ + m_pTextStyle->setColor(c); +} + +QFont KivioBaseTargetStencil::textFont() +{ + return m_pTextStyle->font(); +} +void KivioBaseTargetStencil::setTextFont( const QFont &f ) +{ + m_pTextStyle->setFont(f); +} + +int KivioBaseTargetStencil::hTextAlign() +{ + return m_pTextStyle->hTextAlign(); +} + +int KivioBaseTargetStencil::vTextAlign() +{ + return m_pTextStyle->vTextAlign(); +} + +void KivioBaseTargetStencil::setHTextAlign(int a) +{ + m_pTextStyle->setHTextAlign(a); +} + +void KivioBaseTargetStencil::setVTextAlign(int a) +{ + m_pTextStyle->setVTextAlign(a); +} + +void KivioBaseTargetStencil::setText( const QString &a ) +{ + m_pTextStyle->setText(a); +} + +QString KivioBaseTargetStencil::text() +{ + return m_pTextStyle->text(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// +// Paint Routines +// +////////////////////////////////////////////////////////////////////////////// + +void KivioBaseTargetStencil::paint( KivioIntraStencilData * ) +{ + ; +} + +void KivioBaseTargetStencil::paintOutline( KivioIntraStencilData * ) +{ + ; +} + +void KivioBaseTargetStencil::paintConnectorTargets( KivioIntraStencilData *pData ) +{ + QPixmap *targetPic; + KivioPainter *painter; + double x, y; + + // We don't draw these if we are selected!!! + if( isSelected() == true ) + return; + + // Obtain the graphic used for KivioConnectorTargets + targetPic = KivioConfig::config()->connectorTargetPixmap(); + + + KoZoomHandler* zoomHandler = pData->zoomHandler; + painter = pData->painter; + + KivioConnectorTarget *pTarget; + pTarget = m_pTargets->first(); + while( pTarget ) + { + x = zoomHandler->zoomItX(pTarget->x()); + y = zoomHandler->zoomItY(pTarget->y()); + + painter->drawPixmap( x-3, y-3, *targetPic ); + + pTarget = m_pTargets->next(); + } +} + + + + + +////////////////////////////////////////////////////////////////////////////// +// +// File I/O +// +////////////////////////////////////////////////////////////////////////////// +bool KivioBaseTargetStencil::loadXML( const QDomElement &e ) +{ + QDomNode node; + QString name; + + node = e.firstChild(); + while( !node.isNull() ) + { + name = node.nodeName(); + + if( name == "KivioStencilProperties" ) + { + loadProperties(node.toElement()); + } + + node = node.nextSibling(); + } + + updateGeometry(); + + return true; +} + +QDomElement KivioBaseTargetStencil::createRootElement( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioPluginStencil"); + + XmlWriteString( e, "id", m_pSpawner->info()->id() ); + XmlWriteString( e, "setId", m_pSpawner->set()->id() ); + + return e; +} + +QDomElement KivioBaseTargetStencil::saveXML( QDomDocument &doc ) +{ + QDomElement e = createRootElement( doc ); + + e.appendChild( saveProperties(doc) ); + + return e; +} + + +QDomElement KivioBaseTargetStencil::saveProperties( QDomDocument &doc ) +{ + QDomElement baseE = doc.createElement("KivioStencilProperties"); + + QDomElement geoE = doc.createElement("Geometry"); + XmlWriteFloat( geoE, "x", m_x ); + XmlWriteFloat( geoE, "y", m_y ); + XmlWriteFloat( geoE, "w", m_w ); + XmlWriteFloat( geoE, "h", m_h ); + baseE.appendChild( geoE ); + + baseE.appendChild( m_pLineStyle->saveXML(doc) ); + baseE.appendChild( m_pFillStyle->saveXML(doc) ); + baseE.appendChild( m_pTextStyle->saveXML(doc) ); + baseE.appendChild( saveTargets(doc) ); + + // Only save custom data if this returns true (means there is custom data) + QDomElement customE = doc.createElement("CustomData"); + if( saveCustom( customE, doc )==true ) + { + baseE.appendChild( customE ); + } + + return baseE; +} + +bool KivioBaseTargetStencil::loadProperties( const QDomElement &e ) +{ + QDomNode node; + QDomElement nodeE; + QString nodeName; + + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + nodeE = node.toElement(); + + if( nodeName == "KivioFillStyle" ) + { + m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + m_pLineStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioTextStyle" ) + { + m_pTextStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioTargetList" ) + { + loadTargets( node.toElement() ); + } + else if( nodeName == "CustomData" ) + { + loadCustom( node.toElement() ); + } + else if( nodeName == "Geometry" ) + { + m_x = XmlReadFloat( nodeE, "x", 0.0f ); + m_y = XmlReadFloat( nodeE, "y", 0.0f ); + m_w = XmlReadFloat( nodeE, "w", 72.0f ); + m_h = XmlReadFloat( nodeE, "h", 72.0f ); + } + + node = node.nextSibling(); + } + + return true; +} + +bool KivioBaseTargetStencil::saveCustom( QDomElement &, QDomDocument & ) +{ + return false; +} + +bool KivioBaseTargetStencil::loadCustom( const QDomElement & ) +{ + return true; +} + +QDomElement KivioBaseTargetStencil::saveTargets( QDomDocument &doc ) +{ + KivioConnectorTarget *p; + + QDomElement e = doc.createElement("TargetList"); + + p = m_pTargets->first(); + while( p ) + { + e.appendChild( p->saveXML(doc) ); + + p = m_pTargets->next(); + } + + return e; +} + +bool KivioBaseTargetStencil::loadTargets( const QDomElement &e ) +{ + KivioConnectorTarget *p; + QDomNode node; + QDomElement targetE; + QString nodeName; + + m_pTargets->clear(); + + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + targetE = node.toElement(); + + if( nodeName == "KivioConnectorTarget" ) + { + p = new KivioConnectorTarget(); + p->loadXML( targetE ); + m_pTargets->append(p); + p = NULL; + } + + + node = node.nextSibling(); + } + + + return true; +} + + + +////////////////////////////////////////////////////////////////////////////// +// +// Geometry Routine +// +////////////////////////////////////////////////////////////////////////////// +void KivioBaseTargetStencil::updateGeometry() +{ + ; +} + + + + +////////////////////////////////////////////////////////////////////////////// +// +// Target Routines +// +////////////////////////////////////////////////////////////////////////////// +KivioConnectorTarget *KivioBaseTargetStencil::connectToTarget( KivioConnectorPoint *p, double threshHold) +{ + double px = p->x(); + double py = p->y(); + + double tx, ty; + + KivioConnectorTarget *pTarget = m_pTargets->first(); + while( pTarget ) + { + tx = pTarget->x(); + ty = pTarget->y(); + + + if( px >= tx - threshHold && + px <= tx + threshHold && + py >= ty - threshHold && + py <= ty + threshHold ) + { + // setTarget calls pTarget->addConnectorPoint() and removes + // any previous connections from p + p->setTarget( pTarget ); + return pTarget; + } + + pTarget = m_pTargets->next(); + } + + return NULL; +} + +// we probably don't need targetID in the function since it's stored in p... but I don't remember so +// i'm leaving it here for now. +KivioConnectorTarget *KivioBaseTargetStencil::connectToTarget( KivioConnectorPoint *p, int /*targetID*/ ) +{ + int id = p->targetId(); + + KivioConnectorTarget *pTarget = m_pTargets->first(); + while( pTarget ) + { + if( pTarget->id() == id ) + { + p->setTarget(pTarget); + + return pTarget; + } + + pTarget = m_pTargets->next(); + } + + return NULL; +} + + + + +////////////////////////////////////////////////////////////////////////////// +// +// ID Generation +// +////////////////////////////////////////////////////////////////////////////// +int KivioBaseTargetStencil::generateIds( int nextAvailable ) +{ + KivioConnectorTarget *pTarget = m_pTargets->first(); + + // Iterate through all the targets + while( pTarget ) + { + // If this target has something connected to it + if( pTarget->hasConnections() ) + { + // Set it's id to the next available id + pTarget->setId( nextAvailable ); + + // Increment the next available id + nextAvailable++; + } + else + { + // Otherwise mark it as unused (-1) + pTarget->setId( -1 ); + } + + pTarget = m_pTargets->next(); + } + + // Return the next availabe id + return nextAvailable; +} + +void KivioBaseTargetStencil::copyBasicInto( KivioBaseTargetStencil *pStencil ) +{ + pStencil->setSpawner( m_pSpawner ); + + m_pFillStyle->copyInto( pStencil->m_pFillStyle ); + m_pLineStyle->copyInto( pStencil->m_pLineStyle ); + m_pTextStyle->copyInto( pStencil->m_pTextStyle ); + + // Copy the targets + KivioConnectorTarget *pSrcTarget, *pTgTarget; + pSrcTarget = m_pTargets->first(); + pTgTarget = pStencil->m_pTargets->first(); + + while( pSrcTarget && pTgTarget ) + { + pTgTarget->setPosition( pSrcTarget->x(), pSrcTarget->y() ); + + pSrcTarget = m_pTargets->next(); + pTgTarget = pStencil->m_pTargets->next(); + } + + // Copy the geometry + pStencil->m_x = m_x; + pStencil->m_y = m_y; + pStencil->m_w = m_w; + pStencil->m_h = m_h; + + *(pStencil->m_pProtection) = *m_pProtection; + *(pStencil->m_pCanProtect) = *m_pCanProtect; +} + +int KivioBaseTargetStencil::resizeHandlePositions() +{ + // Calculate the resize handle positions + int mask = KIVIO_RESIZE_HANDLE_POSITION_ALL; + + if( m_pProtection->at( kpWidth ) ) + { + mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpE | krhpW); + } + + if( m_pProtection->at( kpHeight) ) + { + mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpN | krhpS); + } + + return mask; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_base_target_stencil.h b/kivio/kiviopart/kiviosdk/kivio_base_target_stencil.h new file mode 100644 index 000000000..7af497187 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_base_target_stencil.h @@ -0,0 +1,172 @@ +/* + * 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 KIVIO_BASE_TARGET_STENCIL_H +#define KIVIO_BASE_TARGET_STENCIL_H + +#include <qfont.h> +#include <qcolor.h> +#include <qdom.h> +#include <qptrlist.h> + +class KivioCustomDragData; +class KivioConnectorPoint; +class KivioConnectorTarget; +class KivioFillStyle; +class KivioIntraStencilData; +class KivioLineStyle; +class KivioPage; +class KivioStencilSpawner; +class KivioTextStyle; + +#include "kivio_stencil.h" + + +class KivioBaseTargetStencil : public KivioStencil +{ +protected: + KivioLineStyle *m_pLineStyle; + KivioFillStyle *m_pFillStyle; + KivioTextStyle *m_pTextStyle; + + QPtrList<KivioConnectorTarget> *m_pTargets; + + virtual QDomElement createRootElement( QDomDocument & ); + + virtual bool saveCustom( QDomElement &, QDomDocument & ); + virtual QDomElement saveProperties( QDomDocument & ); + virtual QDomElement saveTargets( QDomDocument & ); + + virtual bool loadCustom( const QDomElement & ); + virtual bool loadProperties( const QDomElement & ); + virtual bool loadTargets( const QDomElement & ); + + virtual void copyBasicInto( KivioBaseTargetStencil * ); + +public: + KivioBaseTargetStencil(); + virtual ~KivioBaseTargetStencil(); + + virtual KivioStencil *duplicate() { return NULL; } + + + ////////////////////////////// + // + // KivioLineStyle + // + ////////////////////////////// + virtual QColor fgColor(); + virtual void setFGColor( QColor c ); + + virtual void setLineWidth( double l ); + virtual double lineWidth(); + + + + ////////////////////////////// + // + // KivioFillStyle + // + ////////////////////////////// + virtual void setBGColor( QColor c ); + virtual QColor bgColor(); + + virtual KivioFillStyle *fillStyle(); + + + + ////////////////////////////// + // + // KivioTextStyle + // + ////////////////////////////// + virtual QColor textColor(); + virtual void setTextColor( QColor c ); + + virtual QFont textFont(); + virtual void setTextFont( const QFont &f ); + + virtual int hTextAlign(); + virtual int vTextAlign(); + + virtual void setHTextAlign(int a); + virtual void setVTextAlign(int a); + + virtual void setText( const QString &a ); + virtual QString text(); + + + + /////////////////////////////// + // + // Paint Routines + // + /////////////////////////////// + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + + + + /////////////////////////////// + // + // File I/O + // + /////////////////////////////// + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + + + + /////////////////////////////// + // + // Geometry + // + /////////////////////////////// + virtual void updateGeometry(); + + + + /////////////////////////////// + // + // Connection Routines + // + /////////////////////////////// + // This attempts to connect based on position + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, double ); + + // This attempts to connect based on a targetID. This should ***ONLY*** be used + // right after a load + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, int ); + + + /////////////////////////////// + // + // ID Generation + // + /////////////////////////////// + virtual int generateIds( int ); + + + + virtual int resizeHandlePositions(); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_common.cpp b/kivio/kiviopart/kiviosdk/kivio_common.cpp new file mode 100644 index 000000000..8de8e1e04 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_common.cpp @@ -0,0 +1,452 @@ +/* + * 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 "kivio_common.h" +#include "kivio_connector_point.h" +#include <kdebug.h> +#include <qstringlist.h> +#include <math.h> +#include <KoPoint.h> +#include <KoRect.h> + +/** + * Read a floating point value from a @ref QDomElement. + * + * @param e The @ref QDomElement to read from + * @param att The attribute to locate + * @param def The default value to return if the attribute is not found + * + * This will read a floating point attribute from a @ref QDomElement, and + * if it is not found, return the default value. + */ +float XmlReadFloat( const QDomElement &e, const QString &att, const float &def) +{ + // Check if this value exists, if not, return the default + if( e.hasAttribute( att )==false ) + return def; + + // Read the attribute + QString val = e.attribute( att ); + bool ok=false; + + // Make sure it is a floating point value. If not, return the default + float fVal = val.toFloat( &ok ); + if( !ok ) + { + kdDebug(43000) << "Invalid XML-value read for " << att.ascii() << ", expected float\n" << endl; + return 1.0; + } + + // Return the value + return fVal; +} + + +/** + * Write a floating point value to a @ref QDomElement + * + * @param e The @ref QDomElement to write to + * @param att The attribute to write + * @param val The value of the attribute to write + * + * This will write a floating point value to a @ref QDomElement. + */ +void XmlWriteFloat( QDomElement &e, const QString &att, const float &val ) +{ + e.setAttribute( att, (double)val ); +} + + +/** + * Read an int value from a @ref QDomElement. + * + * @param e The @ref QDomElement to read from + * @param att The attribute to locate + * @param def The default value to return if the attribute is not found + * + * This will read an int attribute from a @ref QDomElement, and + * if it is not found, return the default value. + */ +int XmlReadInt( const QDomElement &e, const QString &att, const int &def) +{ + // Check if this value exists, if not, return the default + if( e.hasAttribute( att )==false ) + return def; + + // Read the attribute + QString val = e.attribute( att, "1" ); + bool ok=false; + + // Make sure it is a floating point value. If not, return the default + int iVal = val.toInt( &ok ); + if( !ok ) + { + kdDebug(43000) << "Invalid XML-value read for " << att << " expected int\n" << endl; + return 1; + } + + // Return the value + return iVal; +} + + +/** + * Write a int value to a @ref QDomElement + * + * @param e The @ref QDomElement to write to + * @param att The attribute to write + * @param val The value of the attribute to write + * + * This will write an int value to a @ref QDomElement. + */ +void XmlWriteInt( QDomElement &e, const QString &att, const int &val ) +{ + e.setAttribute( att, (int)val ); +} + + +/** + * Read an uint value from a @ref QDomElement. + * + * @param e The @ref QDomElement to read from + * @param att The attribute to locate + * @param def The default value to return if the attribute is not found + * + * This will read an uint attribute from a @ref QDomElement, and + * if it is not found, return the default value. + */ +uint XmlReadUInt( const QDomElement &e, const QString &att, const uint &def) +{ + // Check if this value exists, if not, return the default + if( e.hasAttribute( att )==false ) + return def; + + // Read the attribute + QString val = e.attribute( att, "1" ); + bool ok=false; + + // Make sure it is a floating point value. If not, return the default + uint iVal = val.toUInt( &ok ); + if( !ok ) + { + kdDebug(43000) << "Invalid XML-value read for " << att.ascii() << ", expected uint\n" << endl; + return 1; + } + + // Return the value + return iVal; +} + + +/** + * Write an uint value to a @ref QDomElement + * + * @param e The @ref QDomElement to write to + * @param att The attribute to write + * @param val The value of the attribute to write + * + * This will write an uint value to a @ref QDomElement. + */ +void XmlWriteUInt( QDomElement &e, const QString &att, const uint &val ) +{ + e.setAttribute( att, (uint)val ); +} + + +/** + * Read a @ref QString from a @ref QDomElement. + * + * @param e The @ref QDomElement to read from + * @param att The attribute to locate + * @param def The default value to return if the attribute is not found + * + * This will read a QString attribute from a @ref QDomElement, and + * if it is not found, return the default value. + */ +QString XmlReadString( const QDomElement &e, const QString &att, const QString &def ) +{ + // Check if the attribute exists, if not, return the default + if( e.hasAttribute( att )==false ) + return QString(def); + // Otherwise return the attribute + else return e.attribute( att ); +} + + +/** + * Write a QString to a @ref QDomElement + * + * @param e The @ref QDomElement to write to + * @param att The attribute to write + * @param val The value of the attribute to write + * + * This will write a QString to a @ref QDomElement. + */ +void XmlWriteString( QDomElement &e, const QString &att, const QString &val ) +{ + e.setAttribute( att, val ); +} + + +/** + * Read a QColor value from a @ref QDomElement. + * + * @param e The @ref QDomElement to read from + * @param att The attribute to locate + * @param def The default value to return if the attribute is not found + * + * This will read a QColor attribute from a @ref QDomElement, and + * if it is not found, return the default value. + */ +QColor XmlReadColor( const QDomElement &e, const QString &att, const QColor &def) +{ + // Check if this value exists, if not, return the default + if( e.hasAttribute( att )==false ) + return def; + + // Read the attribute + QString val = e.attribute( att, "1" ); + bool ok=false; + QColor newColor; + + if( val.contains("#") ) // Is it #RRGGBB format? + { + newColor.setNamedColor(val); + return newColor; + } + + // Otherwise it is a #xxxxxxxx color (rgb format) + // Make sure it is a uint value. If not, return the default + uint iVal = val.toUInt( &ok ); + if( !ok ) + { + kdDebug(43000) << "Invalid XML-value read for " << att.ascii() << ", expected QColor" << endl; + return 1; + } + + // Return the value + return QColor(iVal); +} + + +/** + * Write a QColor value to a @ref QDomElement + * + * @param e The @ref QDomElement to write to + * @param att The attribute to write + * @param val The value of the attribute to write + * + * This will write a QColor value to a @ref QDomElement. + */ +void XmlWriteColor( QDomElement &e, const QString &att, const QColor &val ) +{ + // Write it out in #RRGGBB format + e.setAttribute( att, val.name() ); +} + + +/** + * Read a double value from a @ref QDomElement. + * + * @param e The @ref QDomElement to read from + * @param att The attribute to locate + * @param def The default value to return if the attribute is not found + * + * This will read a double attribute from a @ref QDomElement, and + * if it is not found, return the default value. + */ +double XmlReadDouble( const QDomElement &e, const QString &att, const double &def) +{ + // Check if this value exists, if not, return the default + if( e.hasAttribute( att )==false ) + return def; + + // Read the attribute + QString val = e.attribute( att, "1.0" ); + bool ok=false; + + // Make sure it is a floating point value. If not, return the default + double dVal = val.toDouble( &ok ); + if( !ok ) + { + kdDebug(43000) << "Invalid XML-value read for ," << att.ascii() << " expected double" << endl; + return 1.0; + } + + // Return the value + return dVal; +} + + +/** + * Write a double value to a @ref QDomElement + * + * @param e The @ref QDomElement to write to + * @param att The attribute to write + * @param val The value of the attribute to write + * + * This will write a double value to a @ref QDomElement. + */ +void XmlWriteDouble( QDomElement &e, const QString &att, const double &val ) +{ + e.setAttribute( att, (double)val ); +} + + +#define WHICH_QUAD( vertex, hitPos ) \ + ( (vertex.x() > hitPos->x()) ? ((vertex.y() > hitPos->y()) ? 1 : 4 ) : ((vertex.y() > hitPos->y())?2:3)) + +#define X_INTERCEPT( point1, point2, hitY ) \ + (point2.x() - (((point2.y()-hitY)*(point1.x()-point2.x()))/(point1.y()-point2.y()))) + +/** + * Determines if a point is inside a given polygon + * @param points An array of points representing the polygon + * @param numPoints The number of points in the array + * @param hitPos The point we are to check + * + * Code taken from Game Developer magazine page 22, January 1999 issue + * Explaination: + * + * A better strategy is to divide the polygon into quadrants centered on the test point. + * Start at the first vertex in the polygon and set a counter to 0. Anytime an edge crosses + * from one quadrant to the next, add one to the counter if it crosses clockwise around the + * test point and subtract one if it crosses counter-clockwise. If the edge crosses diagonally + * across two quadrants, you need to determine which side of the test point it crossed, and then + * either add or subtract 2. + * + * Quad layout: + * 1 2 + * 4 3 + */ +bool PointInPoly( KoPoint *points, int numPoints, KoPoint *hitPos ) +{ + int edge, next; + int quad, next_quad, delta, total; + + edge = 0; + + quad = WHICH_QUAD( points[ edge ], hitPos ); + total = 0; // count of absolute sectors crossed + + // Loop through all the vertices + do { + next = (edge + 1) % numPoints; + next_quad = WHICH_QUAD( points[ next ], hitPos ); + + // Calculate how many quads have been crossed + delta = next_quad - quad; + + // Special case to handle crossings of more than one quad + switch( delta ) + { + case 2: // If we crossed the middle, figure out if it was clockwise or counter clockwise + case -2: // Use the X-position at the hit point to determine which way around + if( X_INTERCEPT( points[edge], points[next], hitPos->y() ) > hitPos->x() ) + delta = -delta; + break; + + case 3: // Moving 3 quads is like moving back 1 + delta = -1; + break; + + case -3: // Moving back 3 is like moving forward 1 + delta = 1; + break; + } + + // Add in the delta + total += delta; + quad = next_quad; + edge = next; + } while( edge != 0 ); + + + // After everything, if the total is 4, then we are inside + if((total==4) || (total==-4)) + return true; + else + return false; +} + +KoRect XmlReadRect( const QDomElement &e, const QString &att, const KoRect &def ) +{ + // Check if this value exists, if not, return the default + if( e.hasAttribute( att )==false ) + return def; + + // Read the attribute + QString val = e.attribute( att ); + + if (val.find("[") == 0 && val.find("]") == (int)val.length()-1) { + val.remove(0,1); + val.remove(val.length()-1,1); + QStringList vlist = QStringList::split(",",val); + if (vlist.count() == 4) { + bool allOk = true; + bool ok = false; + + double x = vlist[0].toDouble(&ok); + allOk = allOk & ok; + + double y = vlist[1].toDouble(&ok); + allOk = allOk & ok; + + double w = vlist[2].toDouble(&ok); + allOk = allOk & ok; + + double h = vlist[3].toDouble(&ok); + allOk = allOk & ok; + + if (allOk) + return KoRect(x, y, w, h); + } + } + + return def; +} + +void XmlWriteRect( QDomElement &e, const QString &att, const KoRect &val ) +{ + e.setAttribute( att, QString("[%1,%2,%3,%4]").arg(val.x()).arg(val.y()).arg(val.width()).arg(val.height()) ); +} + + +float shortestDistance( KivioConnectorPoint *pStart, KivioConnectorPoint *pEnd, KivioConnectorPoint *q ) +{ + float uX, uY; + float pqX, pqY; + + uX = pStart->x() - pEnd->x(); + uY = pStart->y() - pEnd->y(); + + pqX = pStart->x() - q->x(); + pqY = pStart->y() - q->y(); + + float magTop = fabs(pqX*uY - (pqY*uX)); + + float magU = sqrt( uX*uX + uY*uY ); + + if( magU == 0.0f ) + { + kdDebug(43000) << "shortestDistance() - SERIOUS ERROR: magU is 0.0f!\n"; + return 10.0f; + } + + return magTop / magU; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_common.h b/kivio/kiviopart/kiviosdk/kivio_common.h new file mode 100644 index 000000000..7ddb33825 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_common.h @@ -0,0 +1,60 @@ +/* + * 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 KIVIO_COMMON_H +#define KIVIO_COMMON_H + +#include <qdom.h> +#include <qcolor.h> + +class KivioConnectorPoint; +class KoPoint; +class KoRect; + +extern "C" { + + KoRect XmlReadRect( const QDomElement &, const QString &, const KoRect & ); + void XmlWriteRect( QDomElement &, const QString &, const KoRect & ); + + QColor XmlReadColor( const QDomElement &, const QString &, const QColor & ); + void XmlWriteColor( QDomElement &, const QString &, const QColor & ); + + int XmlReadInt( const QDomElement &, const QString &, const int & ); + void XmlWriteInt( QDomElement &, const QString &, const int & ); + + uint XmlReadUInt( const QDomElement &, const QString &, const uint & ); + void XmlWriteUInt( QDomElement &, const QString &, const uint & ); + + double XmlReadDouble( const QDomElement &, const QString &, const double & ); + void XmlWriteDouble( QDomElement &, const QString &, const double & ); + + float XmlReadFloat( const QDomElement &, const QString &, const float & ); + void XmlWriteFloat( QDomElement &, const QString &, const float & ); + + QString XmlReadString( const QDomElement &, const QString &, const QString & ); + void XmlWriteString( QDomElement &, const QString &, const QString & ); + + bool PointInPoly( KoPoint *points, int numPoints, KoPoint *hitPos ); + + float shortestDistance( KivioConnectorPoint *pStart, KivioConnectorPoint *pEnd, KivioConnectorPoint *q ); + +} + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_connector_point.cpp b/kivio/kiviopart/kiviosdk/kivio_connector_point.cpp new file mode 100644 index 000000000..d0ca66164 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_connector_point.cpp @@ -0,0 +1,217 @@ +/* + * 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 "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_connector_target.h" +#include "kivio_stencil.h" + +KivioConnectorPoint::KivioConnectorPoint() +{ + m_pTarget = 0L; + m_pStencil = 0L; + m_targetId = -1; + m_connectable = true; +} + +KivioConnectorPoint::KivioConnectorPoint( KivioStencil *pParent, bool conn ) +{ + m_pTarget = 0L; + m_pStencil = pParent; + m_targetId = -1; + m_connectable = conn; +} + +KivioConnectorPoint::~KivioConnectorPoint() +{ + if( m_pTarget ) + { + m_pTarget->removeConnectorPointFromList( this ); + m_pTarget = 0L; + } + + m_pStencil = 0L; +} + +/** + * Sets the target to a value. + * + * @param pTarget The target to connect to + * + * This sets the KivioConnectorTarget we are attached to. In addition to + * setting the pointer, it also tells the target to add this as a connected + * point. + */ +void KivioConnectorPoint::setTarget( KivioConnectorTarget *pTarget ) +{ + if( m_connectable == false ) + { + return; + } + + if( m_pTarget ) + { + m_pTarget->removeConnectorPointFromList( this ); + } + + + m_pTarget = pTarget; + + m_pos.setX(pTarget->x()); + m_pos.setY(pTarget->y()); + + m_pTarget->addConnectorPointToList( this ); +} + + +/** + * Sets the x coordinate. + * + * @param newX The new value + * @param updateStencil Whether or not the stencil's geometry should be updated (def=true) + * + * Sets the X coordinate to a new value, and optionally + * updates the stencil's geometry if updateStencil is true. + */ +void KivioConnectorPoint::setX( double newX, bool updateStencil ) +{ + double oldX = m_pos.x(); + m_pos.setX(newX); + + if( updateStencil && m_pStencil ) + m_pStencil->updateConnectorPoints(this, oldX, m_pos.y()); +} + + +/** + * Sets the y coordinate. + * + * @param newY The new value + * @param updateStencil Whether or not the stencil's geometry should be updated (def=true) + * + * Sets the Y coordinate to a new value, and optionally + * updates the stencil's geometry if updateStencil is true. + */ +void KivioConnectorPoint::setY( double newY, bool updateStencil ) +{ + double oldY = m_pos.y(); + m_pos.setY(newY); + + if( updateStencil && m_pStencil ) + m_pStencil->updateConnectorPoints(this, m_pos.x(), oldY); +} + + +/** + * Sets the coordinates. + * + * @param newX The new x value + * @param newY The new y value + * @param updateStencil Whether or not the stencil's geometry should be updated (def=true) + * + * Sets the X & Y coordinates to new values, and optionally + * updates the stencil's geometry if updateStencil is true. + */ + void KivioConnectorPoint::setPosition( double newX, double newY, bool updateStencil ) +{ + double oldX = m_pos.x(); + double oldY = m_pos.y(); + + m_pos.setCoords(newX, newY); + + if( updateStencil && m_pStencil ) + m_pStencil->updateConnectorPoints(this, oldX, oldY); +} + + +/** + * Disconnects from the target, with optional behavior. + * + * @param removeFromTargetList Whether we should tell the target to remove us from it's list or not. (Default=true). + * + * Call this function if you want this connector to disconnect itself from it's target. If removeFromTargetList is + * true, then we call KivioConnectorTarget::removeConnectorPointFromList() which causes the target to look for + * us in his list of connections and remove us. + */ +void KivioConnectorPoint::disconnect( bool removeFromTargetList ) +{ + if( m_pTarget ) + { + if( removeFromTargetList == true ) + m_pTarget->removeConnectorPointFromList(this); + + m_pTarget = 0L; + m_targetId = -1; + } + +} + + +/** + * Loads this object from an XML file. + * + * @param e The QDomElement to load from. + * + * This will load the necessary values from an XML file. + */ +bool KivioConnectorPoint::loadXML( const QDomElement &e ) +{ + m_pos.setX(XmlReadFloat( e, "x", 1.0f )); + m_pos.setY(XmlReadFloat( e, "y", 1.0f )); + m_targetId = XmlReadInt( e, "targetId", -1 ); + m_connectable = (bool)XmlReadInt( e, "connectable", (int)true ); + + return true; +} + + +/** + * Saves this object to an XML file. + * + * @param doc The QDomDocument to save to. + * + * This creates a new QDomElement and saves its data to it. + * + * @returns The new element created and saved to. + */ +QDomElement KivioConnectorPoint::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioConnectorPoint"); + + XmlWriteFloat( e, "x", m_pos.x() ); + XmlWriteFloat( e, "y", m_pos.y() ); + XmlWriteInt( e, "connectable", (int)m_connectable ); + + if( m_targetId != -1 ) + XmlWriteInt( e, "targetId", m_targetId ); + + return e; +} + +void KivioConnectorPoint::moveBy( double _x, double _y, bool updateStencil ) +{ + m_pos += KoPoint(_x, _y); + + if( updateStencil && m_pStencil ) + m_pStencil->updateConnectorPoints(this, _x, _y); +} + +bool KivioConnectorPoint::isConnected() +{ + return (m_pTarget != 0L); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_connector_point.h b/kivio/kiviopart/kiviosdk/kivio_connector_point.h new file mode 100644 index 000000000..f5cb58c2a --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_connector_point.h @@ -0,0 +1,81 @@ +/* + * 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 KIVIO_CONNECTOR_POINT_H +#define KIVIO_CONNECTOR_POINT_H + +#include <qdom.h> + +#include <KoPoint.h> +#include <koffice_export.h> +class KivioConnectorTarget; +class KivioStencil; + + +class KIVIO_EXPORT KivioConnectorPoint +{ +protected: + // The position of this connector point + KoPoint m_pos; + + // The target this connector is connected to + KivioConnectorTarget *m_pTarget; + + // The stencil this point belongs to + KivioStencil *m_pStencil; + + int m_targetId; + + bool m_connectable; + + +public: + KivioConnectorPoint( KivioStencil *, bool conn=true ); + KivioConnectorPoint(); + virtual ~KivioConnectorPoint(); + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + KivioConnectorTarget *target() const { return m_pTarget; } + void setTarget( KivioConnectorTarget * ); + + KivioStencil *stencil() const { return m_pStencil; } + void setStencil( KivioStencil *p ) { m_pStencil=p; } + + void setTargetId( int i ) { m_targetId = i; } + int targetId() const { return m_targetId; } + + double x() const { return m_pos.x(); } + double y() const { return m_pos.y(); } + KoPoint position() const { return m_pos; } + + void setX( double, bool updateStencil = true ); + void setY( double, bool updateStencil = true ); + void setPosition( double, double, bool updateStencil = true ); + void moveBy( double _x, double _y, bool updateStencil = true ); + + bool connectable() const { return m_connectable; } + void setConnectable( bool b ) { m_connectable = b; if( b==false ) { disconnect(); } } + + void disconnect(bool removeFromTargetList = true); + bool isConnected(); +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_connector_target.cpp b/kivio/kiviopart/kiviosdk/kivio_connector_target.cpp new file mode 100644 index 000000000..60fe03161 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_connector_target.cpp @@ -0,0 +1,285 @@ +/* + * 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 "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_connector_target.h" +#include "kivio_point.h" +#include "kivio_stencil.h" +#include "kivio_intra_stencil_data.h" + +#include <kdebug.h> + +KivioConnectorTarget::KivioConnectorTarget() + : m_pConnectors(NULL) +{ + m_position.setX( 0.0f ); + m_position.setY( 0.0f ); + m_pConnectors = new QPtrList<KivioConnectorPoint>; + m_pConnectors->setAutoDelete(false); + m_id = -1; + m_xOffset = m_yOffset = 0; +} + +KivioConnectorTarget::KivioConnectorTarget(double x, double y) +{ + m_position.setX( x ); + m_position.setY( y ); + m_pConnectors = new QPtrList<KivioConnectorPoint>; + m_pConnectors->setAutoDelete(false); + + m_id = -1; + m_xOffset = m_yOffset = 0; +} + +KivioConnectorTarget::KivioConnectorTarget(double x, double y, double xOffset, double yOffset) +{ + m_position.setX( x ); + m_position.setY( y ); + m_pConnectors = new QPtrList<KivioConnectorPoint>; + m_pConnectors->setAutoDelete(false); + + m_id = -1; + setOffsets(xOffset, yOffset); +} + +/** + * Duplicates this target. + * + * Duplicates this target, only the position. The connections + * are not preserved. + */ +KivioConnectorTarget *KivioConnectorTarget::duplicate() +{ + KivioConnectorTarget *pTarget = new KivioConnectorTarget( m_position.x(), m_position.y(), m_xOffset, m_yOffset ); + + return pTarget; +} + + +/** + * Kill this object and disconnects all KivioConnectorPoints from this. + * + * This is a slightly odd function in that it does not call the disconnect() method + * of KivioConnectorPoint. The reason for this is that FIX ME DAVE! + */ +KivioConnectorTarget::~KivioConnectorTarget() +{ + // Iterate through all connectors diconnecting them from this + KivioConnectorPoint *point; + + if( m_pConnectors ) + { + point = m_pConnectors->first(); + point = m_pConnectors->take(); + + while( point ) + { + kdDebug(43000) << "KivioConnectorTarget:: -> diconnecting" << endl; + + // Disconnect the point. But tell the point to not call + // KivioConnectorTarget::removeConnectorFromList() because it will cause our + // position in the list to be screwed up. + point->disconnect( false ); + + point = m_pConnectors->take(); + } + + delete m_pConnectors; + m_pConnectors = NULL; + } +} + + +/** + * Loads this object from an XML file. + */ +bool KivioConnectorTarget::loadXML( const QDomElement &e ) +{ + if( e.tagName().compare( "KivioConnectorTarget" ) != 0 ) + { + kdDebug(43000) << "Attempted to load KivioConnectorTarget from non-KivioConnectorTarget element" << endl; + return false; + } + + m_position.setX(XmlReadFloat( e, "x", 1.0f )); + m_position.setY(XmlReadFloat( e, "y", 1.0f )); + + m_id = XmlReadInt( e, "id", -1 ); + + return true; +} + + +/** + * Saves this object to an XML file. + */ +QDomElement KivioConnectorTarget::saveXML( QDomDocument &doc ) +{ + QDomElement e; + + e = doc.createElement("KivioConnectorTarget"); + + XmlWriteFloat( e, "x", m_position.x() ); + XmlWriteFloat( e, "y", m_position.y() ); + + if( m_id != -1 ) + XmlWriteInt( e, "id", m_id ); + + return e; +} + + +/** + * Adds a KivioConnectorPoint to the list of connections. + */ +void KivioConnectorTarget::addConnectorPointToList( KivioConnectorPoint *p ) +{ + if( p ) + m_pConnectors->append(p); +} + + +/** + * Removes a KivioConnectorPoint from the list of connections. + * + * Removes a KivioConnectorPoint from the list of connections. Note, it does + * not disconnect the point on the KivioConnectorPoint side. This function + * is mainly used by KivioConnectorPoint, and probably shouldn't be used by + * anything/one else unless you really know what you are doing. + */ +bool KivioConnectorTarget::removeConnectorPointFromList( KivioConnectorPoint *p ) +{ + if( !p ) + return false; + + + return m_pConnectors->remove(p); +} + + +/** + * Sets a new position and updates all connected points. + */ +void KivioConnectorTarget::setX( float _x ) +{ + m_position.setX(_x); + + KivioConnectorPoint *pPoint = m_pConnectors->first(); + while( pPoint ) + { + pPoint->setX( _x, true ); + + pPoint = m_pConnectors->next(); + } +} + + +/** + * Sets a new position and updates all connected points. + */ + +void KivioConnectorTarget::setY( float _y ) +{ + m_position.setY(_y); + + KivioConnectorPoint *pPoint = m_pConnectors->first(); + while( pPoint ) + { + pPoint->setY( _y, true ); + + pPoint = m_pConnectors->next(); + } +} + + +/** + * Sets a new position and updates all connected points. + */ + +void KivioConnectorTarget::setPosition( float _x, float _y ) +{ + m_position.setX( _x ); + m_position.setY( _y ); + + KivioConnectorPoint *pPoint = m_pConnectors->first(); + while( pPoint ) + { + pPoint->setPosition( _x, _y, true ); + + pPoint = m_pConnectors->next(); + } +} + + +/** + * Issues paintOutline requests to all connected stencils. + */ +void KivioConnectorTarget::paintOutline( KivioIntraStencilData *pData ) +{ + KivioConnectorPoint *pPoint; + KivioStencil *pStencil; + + pPoint = m_pConnectors->first(); + while( pPoint ) + { + pStencil = pPoint->stencil(); + + if( pStencil ) + pStencil->paintOutline( pData ); + + pPoint = m_pConnectors->next(); + } +} + + +/** + * Tests is this target has any connections. + */ +bool KivioConnectorTarget::hasConnections() +{ + KivioConnectorPoint *pPoint = m_pConnectors->first(); + + if( pPoint ) + return true; + + return false; +} + + +/** + * Sets this target's unique ID, for generateIds() during a saveXML(). + */ +void KivioConnectorTarget::setId( int i ) +{ + KivioConnectorPoint *pPoint = m_pConnectors->first(); + m_id= i; + + while( pPoint ) + { + pPoint->setTargetId( i ); + + pPoint = m_pConnectors->next(); + } +} + +void KivioConnectorTarget::setOffsets(double x, double y) +{ + m_xOffset = x; + m_yOffset = y; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_connector_target.h b/kivio/kiviopart/kiviosdk/kivio_connector_target.h new file mode 100644 index 000000000..533102aba --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_connector_target.h @@ -0,0 +1,77 @@ +/* + * 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 KIVIO_CONNECTOR_TARGET_H +#define KIVIO_CONNECTOR_TARGET_H + +#include <qdom.h> +#include <qptrlist.h> + +#include <KoPoint.h> + +class KivioIntraStencilData; +class KivioPainter; +class KivioStencil; +class KivioConnectorPoint; + +class KivioConnectorTarget +{ +protected: + KoPoint m_position; + double m_xOffset, m_yOffset; + int m_id; + QPtrList<KivioConnectorPoint> *m_pConnectors; + +public: + KivioConnectorTarget(); + KivioConnectorTarget( double, double ); + KivioConnectorTarget( double, double, double, double ); + virtual ~KivioConnectorTarget(); + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + KivioConnectorTarget *duplicate(); + + inline float x() { return m_position.x(); } + inline float y() { return m_position.y(); } + inline KoPoint position() { return m_position; } + + void setId( int id ); + inline int id() { return m_id; } + + void setX( float ); + void setY( float ); + void setPosition( float, float ); + + void addConnectorPointToList( KivioConnectorPoint * ); + bool removeConnectorPointFromList( KivioConnectorPoint * ); + + void paintOutline( KivioIntraStencilData * ); + + void disconnectPoint( KivioConnectorPoint * ); + + bool hasConnections(); + + void setOffsets(double x, double y); + double xOffset() { return m_xOffset; } + double yOffset() { return m_yOffset; } +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_custom_drag_data.cpp b/kivio/kiviopart/kiviosdk/kivio_custom_drag_data.cpp new file mode 100644 index 000000000..31f9c38e0 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_custom_drag_data.cpp @@ -0,0 +1,32 @@ +/* + * 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 "kivio_custom_drag_data.h" + +KivioCustomDragData::KivioCustomDragData() +{ + page = 0L; + x = y = dx = dy = 0.0f; + id = 0; + scale = 0.0f; +} + +KivioCustomDragData::~KivioCustomDragData() +{ +} diff --git a/kivio/kiviopart/kiviosdk/kivio_custom_drag_data.h b/kivio/kiviopart/kiviosdk/kivio_custom_drag_data.h new file mode 100644 index 000000000..3dc28b961 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_custom_drag_data.h @@ -0,0 +1,39 @@ +/* + * 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 KIVIO_CUSTOM_DRAG_DATA_H +#define KIVIO_CUSTOM_DRAG_DATA_H + +class KivioPage; +#include <koffice_export.h> + +class KIVIO_EXPORT KivioCustomDragData +{ +public: + KivioCustomDragData(); + ~KivioCustomDragData(); + + float x, y; // mouse coordinates + float dx, dy; // change in mouse coordinates + int id; // drag id + KivioPage *page; // page the drag is happening on + float scale; // the scaling factor +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_dia_stencil_spawner.cpp b/kivio/kiviopart/kiviosdk/kivio_dia_stencil_spawner.cpp new file mode 100644 index 000000000..ba7cd9baa --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_dia_stencil_spawner.cpp @@ -0,0 +1,503 @@ +/* +* Kivio - Visual Modelling and Flowcharting +* Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org> +* +* 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 <qdom.h> +#include <qfile.h> +#include <qregexp.h> +#include <qstringlist.h> +#include <kdebug.h> +#include <math.h> + +#include "kivio_stencil.h" +#include "kivio_dia_stencil_spawner.h" +#include "diapathparser.h" + +KivioDiaStencilSpawner::KivioDiaStencilSpawner(KivioStencilSpawnerSet *p) : KivioStencilSpawner(p) +{ + m_smlStencilSpawner = new KivioSMLStencilSpawner(p); +} + +KivioDiaStencilSpawner::~KivioDiaStencilSpawner() +{ +} + +QDomElement KivioDiaStencilSpawner::saveXML(QDomDocument &d) +{ + return m_smlStencilSpawner->saveXML(d); +} + +void KivioDiaStencilSpawner::calculateDimensions(float x, float y) +{ + m_xlist.append(x); + m_ylist.append(y); +} + +float KivioDiaStencilSpawner::diaPointToKivio(float point, bool xpoint) +{ + float returnPoint = 0.0; + if(xpoint) + { + //if(m_lowestx < 0) + returnPoint = point - m_lowestx; + //else + // returnPoint = (fabs(m_highestx) - fabs(m_lowestx)) - (fabs(m_highestx) + fabs(point)); + } + else + { + //if(m_lowesty < 0) + returnPoint =point - m_lowesty; + //else + // returnPoint = (fabs(m_highesty) + fabs(m_lowesty)) - (fabs(m_highesty) + fabs(point)); + } + //kdDebug () << "Point " << point << " Return point " << returnPoint << endl; + return returnPoint; +} + +bool KivioDiaStencilSpawner::load(const QString &file) +{ + QDomDocument dia("test"); + QDomDocument kivio("XML"); + + m_filename = file; + QFile f(file); + + if(f.open(IO_ReadOnly) == false) + { + kdDebug(43000) << "KivioDiaStencilSpawner::load() - Error opening stencil: " << file << endl; + return false; + } + dia.setContent(&f); + QDomNode diaMain = dia.namedItem("shape"); + + // Set "creator" attribute + QDomElement firstElement = kivio.createElement("KivioShapeStencil"); + firstElement.setAttribute("creator", "kiviodiafilter"); + + kivio.appendChild(firstElement); + + // Add KivioSMLStencilSpawnerInfo + QDomElement spawnerInfoElement = kivio.createElement("KivioSMLStencilSpawnerInfo"); + QDomElement authorInfoElement = kivio.createElement("Author"); + authorInfoElement.setAttribute("data", "n/a"); + QDomElement titleInfoElement = kivio.createElement("Title"); + titleInfoElement.setAttribute("data", diaMain.namedItem("name").toElement().text()); + QDomElement idInfoElement = kivio.createElement("Id"); + idInfoElement.setAttribute("data", diaMain.namedItem("name").toElement().text()); + QDomElement descriptionInfoElement = kivio.createElement("Description"); + descriptionInfoElement.setAttribute("data", diaMain.namedItem("description").toElement().text()); + QDomElement versionInfoElement = kivio.createElement("Version"); + versionInfoElement.setAttribute("data", "1.0"); + QDomElement webInfoElement = kivio.createElement("Web"); + webInfoElement.setAttribute("data", "http://"); + QDomElement emailInfoElement = kivio.createElement("Email"); + emailInfoElement.setAttribute("data", "n/a"); + QDomElement copyrightInfoElement = kivio.createElement("Copyright"); + copyrightInfoElement.setAttribute("data", "n/a"); + QDomElement autoUpdateInfoElement = kivio.createElement("AutoUpdate"); + autoUpdateInfoElement.setAttribute("data", "off"); + + spawnerInfoElement.appendChild(authorInfoElement); + spawnerInfoElement.appendChild(titleInfoElement); + spawnerInfoElement.appendChild(idInfoElement); + spawnerInfoElement.appendChild(descriptionInfoElement); + spawnerInfoElement.appendChild(versionInfoElement); + spawnerInfoElement.appendChild(webInfoElement); + spawnerInfoElement.appendChild(emailInfoElement); + spawnerInfoElement.appendChild(copyrightInfoElement); + spawnerInfoElement.appendChild(autoUpdateInfoElement); + + kivio.documentElement().appendChild(spawnerInfoElement); + + m_xscale = m_yscale = 20.0f; + + // Add Dimensions + QDomElement dimensionsElement = kivio.createElement("Dimensions"); + kivio.documentElement().appendChild(dimensionsElement); + + // Calculate Dimensions + QDomElement svgElement = diaMain.namedItem("svg:svg").toElement(); + QDomNode svgNode = svgElement.firstChild(); + while(!svgNode.isNull()) + { + QDomElement svgChild = svgNode.toElement(); + if(!svgChild.isNull()) + { + if(svgChild.tagName() == "svg:rect") + { + // TODO: rx and ry -> rounded rects + if(svgChild.hasAttribute("x") && svgChild.hasAttribute("y") && svgChild.hasAttribute("width") && svgChild.hasAttribute("height")) + { + calculateDimensions(svgChild.attribute("x").toFloat(), svgChild.attribute("y").toFloat()); + calculateDimensions(svgChild.attribute("x").toFloat() + svgChild.attribute("width").toFloat(), svgChild.attribute("y").toFloat() + svgChild.attribute("height").toFloat()); + } + } + else if(svgChild.tagName() == "svg:circle") + { + if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && svgChild.hasAttribute("r")) + { + calculateDimensions((svgChild.attribute("cx").toFloat()) - (svgChild.attribute("r").toFloat()), (svgChild.attribute("cy").toFloat()) - (svgChild.attribute("r").toFloat())); + calculateDimensions((svgChild.attribute("cx").toFloat()) + (svgChild.attribute("r").toFloat()), (svgChild.attribute("cy").toFloat()) + (svgChild.attribute("r").toFloat())); + } + } + else if(svgChild.tagName() == "svg:ellipse") + { + if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && svgChild.hasAttribute("rx") && svgChild.hasAttribute("ry")) + { + calculateDimensions((svgChild.attribute("cx").toFloat()) - (svgChild.attribute("rx").toFloat()), (svgChild.attribute("cy").toFloat()) - (svgChild.attribute("ry").toFloat())); + calculateDimensions((svgChild.attribute("cx").toFloat()) + (svgChild.attribute("rx").toFloat()), (svgChild.attribute("cy").toFloat()) + (svgChild.attribute("ry").toFloat())); + } + } + else if(svgChild.tagName() == "svg:line") + { + if(svgChild.hasAttribute("x1") && svgChild.hasAttribute("y1") && svgChild.hasAttribute("x2") && svgChild.hasAttribute("y2")) + { + calculateDimensions(svgChild.attribute("x1").toFloat(), svgChild.attribute("y1").toFloat()); + calculateDimensions(svgChild.attribute("x2").toFloat(), svgChild.attribute("y2").toFloat()); + } + } + else if(svgChild.tagName() == "svg:polyline") + { + if(svgChild.hasAttribute("points")) + { + QStringList points = QStringList::split(" ", svgChild.attribute("points")); + for(QStringList::Iterator it = points.begin(); it != points.end(); ++it) + { + QString x, y; + + QStringList parsed = QStringList::split(",", (*it)); + QStringList::Iterator itp = parsed.begin(); + x = (*itp); + ++itp; + y = (*itp); + + calculateDimensions(x.toFloat(), y.toFloat()); + } + } + } + else if(svgChild.tagName() == "svg:polygon") + { + if(svgChild.hasAttribute("points")) + { + QStringList points = QStringList::split(" ", svgChild.attribute("points")); + for(QStringList::Iterator it = points.begin(); it != points.end(); ++it) + { + QString x, y; + + QStringList parsed = QStringList::split(",", (*it)); + QStringList::Iterator itp = parsed.begin(); + x = (*itp); + ++itp; + y = (*itp); + + calculateDimensions(x.toFloat(), y.toFloat()); + } + } + } + else if(svgChild.tagName() == "svg:path") + { + if(svgChild.hasAttribute("d")) + { + DiaPointFinder *dpf = new DiaPointFinder(&m_xlist, &m_ylist); + dpf->parseSVG(svgChild.attribute("d"), true); + delete dpf; + } + } + } + svgNode = svgNode.nextSibling(); + } + + QValueList<float>::Iterator itx = m_xlist.begin(); + QValueList<float>::Iterator ity = m_ylist.begin(); + m_highestx = *itx; + m_lowestx = *itx; + m_highesty = *ity; + m_lowesty = *ity; + ++itx; + ++ity; + + for( ; itx != m_xlist.end(); ++itx) + { + m_highestx = QMAX(m_highestx, *itx); + m_lowestx = QMIN(m_lowestx, *itx); + } + + for( ; ity != m_ylist.end(); ++ity) + { + m_highesty = QMAX(m_highesty, *ity); + m_lowesty = QMIN(m_lowesty, *ity); + } + + //if( svgElement.hasAttribute("width") && svgElement.hasAttribute("height")) + //{ + // m_yscale = svgElement.attribute("height").toFloat()/(m_highesty - m_lowesty); + // m_xscale = svgElement.attribute("width").toFloat()/(m_highestx - m_lowestx); + //} + //else + { + // scale the shape to be close to 30 by 30 + m_yscale = 30.0/(m_highesty - m_lowesty); + m_xscale = 30.0/(m_highestx - m_lowestx); + } + + // Add KivioConnectorTarget's + QDomElement connectionsElement = diaMain.namedItem("connections").toElement(); + QDomNode connectionsNode = connectionsElement.firstChild(); + while(!connectionsNode.isNull()) + { + QDomElement connectionChild = connectionsNode.toElement(); + if(!connectionChild.isNull()) + { + if(connectionChild.tagName() == "point") + { + if(connectionChild.hasAttribute("x") && connectionChild.hasAttribute("y")) + { + QDomElement kivioConnectorTarget = kivio.createElement("KivioConnectorTarget"); + kivioConnectorTarget.setAttribute("x", QString::number(diaPointToKivio(connectionChild.attribute("x").toFloat(),true) * m_xscale)); + kivioConnectorTarget.setAttribute("y", QString::number(diaPointToKivio(connectionChild.attribute("y").toFloat(), false) * m_yscale)); + + kivio.documentElement().appendChild(kivioConnectorTarget); + } + } + } + connectionsNode = connectionsNode.nextSibling(); + } + + // Add KivioShape's and convert to Kivio's Coordinate System + svgNode = svgElement.firstChild(); + int runs = 0; + while(!svgNode.isNull()) + { + QDomElement svgChild = svgNode.toElement(); + if(!svgChild.isNull()) + { + if(svgChild.tagName() == "svg:rect") + { + runs++; + // TODO: rx and ry -> rounded rects + if(svgChild.hasAttribute("x") && svgChild.hasAttribute("y") && svgChild.hasAttribute("width") && svgChild.hasAttribute("height")) + { + QDomElement kivioShape = kivio.createElement("KivioShape"); + kivioShape.setAttribute("type", "Rectangle"); + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + kivioShape.setAttribute("x", QString::number(diaPointToKivio(svgChild.attribute("x").toFloat(),true) * m_xscale)); + kivioShape.setAttribute("y", QString::number(diaPointToKivio(svgChild.attribute("y").toFloat(), false) * m_yscale)); + kivioShape.setAttribute("w", QString::number(svgChild.attribute("width").toFloat() * m_xscale)); + kivioShape.setAttribute("h", QString::number(svgChild.attribute("height").toFloat() * m_yscale)); + kivio.documentElement().appendChild(kivioShape); + } + } + else if(svgChild.tagName() == "svg:circle") + { + runs++; + if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && svgChild.hasAttribute("r")) + { + QDomElement kivioShape = kivio.createElement("KivioShape"); + kivioShape.setAttribute("type", "Ellipse"); + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + kivioShape.setAttribute("x", QString::number((diaPointToKivio(svgChild.attribute("cx").toFloat() - svgChild.attribute("r").toFloat(),true) * m_xscale))); + kivioShape.setAttribute("y", QString::number((diaPointToKivio(svgChild.attribute("cy").toFloat() - svgChild.attribute("r").toFloat(), false) * m_yscale))); + kivioShape.setAttribute("w", QString::number(svgChild.attribute("r").toFloat() * m_xscale * 2)); + kivioShape.setAttribute("h", QString::number(svgChild.attribute("r").toFloat() * m_yscale * 2)); + kivio.documentElement().appendChild(kivioShape); + } + } + else if(svgChild.tagName() == "svg:ellipse") + { + runs++; + if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && svgChild.hasAttribute("rx") && svgChild.hasAttribute("ry")) + { + QDomElement kivioShape = kivio.createElement("KivioShape"); + kivioShape.setAttribute("type", "Ellipse"); + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + kivioShape.setAttribute("x", QString::number((diaPointToKivio(svgChild.attribute("cx").toFloat() - svgChild.attribute("rx").toFloat(),true) * m_xscale))); + kivioShape.setAttribute("y", QString::number((diaPointToKivio(svgChild.attribute("cy").toFloat() - svgChild.attribute("ry").toFloat(), false) * m_yscale))); + kivioShape.setAttribute("w", QString::number(svgChild.attribute("rx").toFloat() * m_xscale * 2)); + kivioShape.setAttribute("h", QString::number(svgChild.attribute("ry").toFloat() * m_yscale * 2)); + kivio.documentElement().appendChild(kivioShape); + } + } + else if(svgChild.tagName() == "svg:line") + { + runs++; + if(svgChild.hasAttribute("x1") && svgChild.hasAttribute("y1") && svgChild.hasAttribute("x2") && svgChild.hasAttribute("y2")) + { + QDomElement kivioShape = kivio.createElement("KivioShape"); + kivioShape.setAttribute("type", "LineArray"); + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + + QDomElement lineArrayElement = kivio.createElement("Line"); + lineArrayElement.setAttribute("x1", QString::number(diaPointToKivio(svgChild.attribute("x1").toFloat(),true) * m_xscale)); + lineArrayElement.setAttribute("y1", QString::number(diaPointToKivio(svgChild.attribute("y1").toFloat(), false) * m_yscale)); + lineArrayElement.setAttribute("x2", QString::number(diaPointToKivio(svgChild.attribute("x2").toFloat(),true) * m_xscale)); + lineArrayElement.setAttribute("y2", QString::number(diaPointToKivio(svgChild.attribute("y2").toFloat(), false) * m_yscale)); + + kivioShape.appendChild(lineArrayElement); + kivio.documentElement().appendChild(kivioShape); + } + } + else if(svgChild.tagName() == "svg:polyline") + { + runs++; + if(svgChild.hasAttribute("points")) + { + QDomElement kivioShape = kivio.createElement("KivioShape"); + kivioShape.setAttribute("type", "Polyline"); + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + + QStringList points = QStringList::split(" ", svgChild.attribute("points")); + for(QStringList::Iterator it = points.begin(); it != points.end(); ++it) + { + QString x, y; + + QStringList parsed = QStringList::split(",", (*it)); + QStringList::Iterator itp = parsed.begin(); + x = (*itp); + ++itp; + y = (*itp); + + QDomElement kivioPointElement = kivio.createElement("KivioPoint"); + kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(x.toFloat(),true) * m_xscale)); + kivioPointElement.setAttribute("y", QString::number(diaPointToKivio(y.toFloat(), false) * m_yscale)); + + kivioShape.appendChild(kivioPointElement); + } + kivio.documentElement().appendChild(kivioShape); + } + } + else if(svgChild.tagName() == "svg:polygon") + { + runs++; + if(svgChild.hasAttribute("points")) + { + QDomElement kivioShape = kivio.createElement("KivioShape"); + kivioShape.setAttribute("type", "Polygon"); + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + + QStringList points = QStringList::split(" ", svgChild.attribute("points")); + for(QStringList::Iterator it = points.begin(); it != points.end(); ++it) + { + QString x, y; + + QStringList parsed = QStringList::split(",", (*it)); + QStringList::Iterator itp = parsed.begin(); + x = (*itp); + ++itp; + y = (*itp); + + QDomElement kivioPointElement = kivio.createElement("KivioPoint"); + kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(x.toFloat(),true) * m_xscale)); + kivioPointElement.setAttribute("y", QString::number(diaPointToKivio(y.toFloat(), false) * m_yscale)); + + kivioShape.appendChild(kivioPointElement); + } + kivio.documentElement().appendChild(kivioShape); + } + } + else if(svgChild.tagName() == "svg:path") + { + runs++; + bool isClosed; + QDomElement kivioShape = kivio.createElement("KivioShape"); + if(svgChild.hasAttribute("d")) + { + + if(svgChild.attribute("d").contains('z') || svgChild.attribute("d").contains('Z')) + { + isClosed = true; + kivioShape.setAttribute("type", "ClosedPath"); + } + else + { + isClosed = false; + kivioShape.setAttribute("type", "OpenPath"); + } + + kivioShape.setAttribute("name", QString::fromLatin1("Element") + QString::number(runs)); + + DiaPathParser *dpp = new DiaPathParser(&kivio, + &kivioShape, m_xscale, m_yscale, + m_lowestx, m_lowesty); + dpp->parseSVG(svgChild.attribute("d"), true); + delete dpp; + + + } + + if( svgChild.hasAttribute("style")) + { + // style="stroke: background; stroke-width: 0.8; stroke-miterlimit: 1; stroke-linecap: round; stroke-linejoin: round" + // Supported: + // stroke-width: + // stroke-linejoin: milter, bevel, round + // stroke-linecap: round, square, flat + // fill: ? + QStringList styles = QStringList::split(";", svgChild.attribute("style")); + for( uint idx = 0; idx < styles.count(); idx++) + { + //kdDebug(43000) << "Style: " << styles[idx] << endl; + if( isClosed && styles[idx].contains("fill:")) + { + QDomElement fillStyle = kivio.createElement("KivioFillStyle"); + if( styles[idx].contains("forground")) + fillStyle.setAttribute("color", "#0000"); + else if (styles[idx].contains("background")) + fillStyle.setAttribute("color", "#ffff"); + + fillStyle.setAttribute("colorStyle", "1"); + kivioShape.appendChild(fillStyle); + } + } + } + kivio.documentElement().appendChild(kivioShape); + } + } + svgNode = svgNode.nextSibling(); + } + + // Apply width and height + + dimensionsElement.setAttribute("w", QString::number((fabs(m_highestx - m_lowestx)) * m_xscale)); + dimensionsElement.setAttribute("h", QString::number((fabs(m_highesty - m_lowesty)) * m_yscale)); + + m_xlist.clear(); + m_ylist.clear(); + + return loadXML(file, kivio); +} + +bool KivioDiaStencilSpawner::loadXML(const QString &file, QDomDocument &d) +{ + bool ret = m_smlStencilSpawner->loadXML(file, d); + + m_icon = *m_smlStencilSpawner->icon(); + m_pSet = m_smlStencilSpawner->set(); + m_pInfo = m_smlStencilSpawner->info(); + m_defWidth = m_smlStencilSpawner->defWidth(); + m_defHeight = m_smlStencilSpawner->defHeight(); + + return ret; +} + +KivioStencil *KivioDiaStencilSpawner::newStencil() +{ + KivioStencil *newStencil = m_smlStencilSpawner->newStencil(); + newStencil->setSpawner(this); + + return newStencil; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_dia_stencil_spawner.h b/kivio/kiviopart/kiviosdk/kivio_dia_stencil_spawner.h new file mode 100644 index 000000000..2ae8ef47d --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_dia_stencil_spawner.h @@ -0,0 +1,69 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org> + * + * 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 KIVIO_DIA_STENCIL_SPAWNER_H +#define KIVIO_DIA_STENCIL_SPAWNER_H + +#include <qdom.h> +#include <qvaluelist.h> +#include <qptrlist.h> +#include <qstring.h> + +#include "kivio_connector_target.h" +//#define protected public // ewww... what a gory hack +#include "kivio_stencil_spawner.h" +//#undef protected +#include "kivio_sml_stencil_spawner.h" + +class KivioDiaStencilSpawner : public KivioStencilSpawner +{ + public: + KivioDiaStencilSpawner(KivioStencilSpawnerSet *); + virtual ~KivioDiaStencilSpawner(); + + virtual bool load(const QString &file); + virtual bool loadXML(const QString &file, QDomDocument &d); + + virtual QDomElement saveXML(QDomDocument &d); + + virtual QString &filename() { return m_filename; } + + virtual KivioStencil *newStencil(); + + QPtrList<KivioConnectorTarget> *targets() { return m_smlStencilSpawner->targets(); } + + protected: + void calculateDimensions(float x, float y); + float diaPointToKivio(float point, bool xpoint); + + KivioSMLStencilSpawner *m_smlStencilSpawner; + QString m_filename; + + QValueList<float> m_xlist; + QValueList<float> m_ylist; + float m_lowestx; + float m_lowesty; + float m_highestx; + float m_highesty; + float m_xscale; + float m_yscale; +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_fill_style.cpp b/kivio/kiviopart/kiviosdk/kivio_fill_style.cpp new file mode 100644 index 000000000..893dd6fc0 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_fill_style.cpp @@ -0,0 +1,143 @@ +/* + * 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 "kivio_common.h" +#include "kivio_fill_style.h" + +#include <kdebug.h> + +/** + * Default constructor + * + * Sets the color style to solid, the color to white, and the brush to a + * a solid pattern. It also sets the gradient pointer to null. + */ +KivioFillStyle::KivioFillStyle() +{ + m_colorStyle = kcsSolid; + m_color = QColor(255,255,255); + m_color2 = QColor(255,255,255); + m_brushStyle = QBrush::SolidPattern; + m_gradientType = KImageEffect::VerticalGradient; +} + + + +/** + * Copy constrcutor + * + * @param source The source object to copy from. + * + * Copies all attributes from source, to this object. + */ +KivioFillStyle::KivioFillStyle( const KivioFillStyle &source ) +{ + m_colorStyle = source.colorStyle(); + m_color = source.color(); + m_brushStyle = source.brushStyle(); + m_gradientType = source.gradientType(); + m_color2 = source.color2(); +} + + + +/** + * Copies this objects attributes into a target. + * + * @param pTarget The target object to copy into. + * + * Copies all attributes of this fillstyle into pTarget. + */ +void KivioFillStyle::copyInto( KivioFillStyle *pTarget ) const +{ + if( !pTarget ) + return; + + pTarget->setKivioColorStyle(m_colorStyle); + pTarget->setColor(m_color); + pTarget->setBrushStyle(m_brushStyle); + pTarget->setGradientType(m_gradientType); + pTarget->setColor2(m_color2); +} + + +/** + * Load this object from an XML element + * + * @param e The element to load from + */ +bool KivioFillStyle::loadXML( const QDomElement &e ) +{ + QDomElement ele; + QDomNode node; + + m_color = XmlReadColor( e, "color", QColor(255,255,255).rgb() ); + m_color2 = XmlReadColor( e, "gradientColor", QColor(255,255,255).rgb() ); + + m_colorStyle = static_cast<KivioColorStyle>(XmlReadInt( e, "colorStyle", kcsSolid )); + + m_gradientType = static_cast<KImageEffect::GradientType>(XmlReadInt(e, "gradientType", KImageEffect::VerticalGradient)); + + return true; +} + + + +/** + * Save this object to an XML element + * + * @param doc The document to create nodes for. + * + * @returns QDomElement is returned. + */ +QDomElement KivioFillStyle::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioFillStyle"); + + XmlWriteColor( e, "color", m_color ); + XmlWriteColor( e, "gradientColor", m_color2 ); + + XmlWriteInt( e, "colorStyle", static_cast<int>(m_colorStyle) ); + + XmlWriteInt( e, "gradientType", static_cast<int>(m_gradientType) ); + + return e; +} + +QBrush KivioFillStyle::brush() +{ + QBrush b; + b.setColor(m_color); + + switch(m_colorStyle) { + case kcsSolid: + b.setStyle(m_brushStyle); + break; + + case kcsNone: + b.setStyle(QBrush::NoBrush); + break; + + case kcsGradient: + case kcsPixmap: + default: + break; + } + + return b; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_fill_style.h b/kivio/kiviopart/kiviosdk/kivio_fill_style.h new file mode 100644 index 000000000..e6f96eb89 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_fill_style.h @@ -0,0 +1,82 @@ +/* + * 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 KIVIO_FILL_STYLE_H +#define KIVIO_FILL_STYLE_H + +#include <qbrush.h> +#include <qcolor.h> +#include <qdom.h> + +#include <kimageeffect.h> + +class KivioFillStyle +{ +public: + /* + * kcsNone - No fill + * kcsSolid - Solid fill + * kcsGradient - Gradient fill + * kcsPixmap - Pixmap fill + */ + typedef enum { + kcsNone = 0, + kcsSolid, + kcsGradient, + kcsPixmap + } KivioColorStyle; + +protected: + KivioColorStyle m_colorStyle; // The color style to use when filling + QColor m_color; // The color to use when solid filling + QColor m_color2; // The second color to use when using a gradient + QBrush::BrushStyle m_brushStyle; // The brush pattern to use when solid filling (maybe gradient too?) + KImageEffect::GradientType m_gradientType; //Which type of gradient to use + +public: + KivioFillStyle(); + KivioFillStyle( const KivioFillStyle & ); + + + void copyInto( KivioFillStyle *pTarget ) const; + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + + inline KivioColorStyle colorStyle() const { return m_colorStyle; } + inline void setKivioColorStyle( KivioColorStyle k ) { m_colorStyle = k; } + + + inline QColor color() const { return m_color; } + inline void setColor( const QColor& c ) { m_color = c; } + inline QColor color2() const { return m_color2; } + inline void setColor2( const QColor& c ) { m_color2 = c; } + + inline QBrush::BrushStyle brushStyle() const { return m_brushStyle; } + inline void setBrushStyle( QBrush::BrushStyle b ) { m_brushStyle = b; } + + inline KImageEffect::GradientType gradientType() const { return m_gradientType; } + inline void setGradientType(KImageEffect::GradientType t) { m_gradientType = t; } + + QBrush brush(); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_gradient.cpp b/kivio/kiviopart/kiviosdk/kivio_gradient.cpp new file mode 100644 index 000000000..0cae5d5e4 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_gradient.cpp @@ -0,0 +1,181 @@ +/* + * 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 "kivio_gradient.h" +#include "kivio_point.h" +/** + * Default constructor + * + * Allocates a new list of colors, and a new list of points for the + * gradient. Also, sets the gradient type to none. + */ +KivioGradient::KivioGradient() + : m_pColors(NULL), + m_pPoints(NULL) +{ + // Allocate the color list + m_pColors = new QPtrList<QColor>; + m_pColors->setAutoDelete(true); + + // Allocate the point list + m_pPoints = new QPtrList<KivioPoint>; + m_pPoints->setAutoDelete(true); + + m_gradientType = kgtNone; +} + + +/** + * Destructor + * + * Deletes the color and point lists. + */ +KivioGradient::~KivioGradient() +{ + if( m_pColors ) + { + delete m_pColors; + m_pColors = NULL; + } + + if( m_pPoints ) + { + delete m_pPoints; + m_pPoints = NULL; + } +} + + +/** + * Copy constructor + * + * @param source The source @ref KivioGradient to copy from + * + * This creates a new KivioGradient as a copy of source. New colors + * and points are allocated. + */ +KivioGradient::KivioGradient( const KivioGradient &source ) + : m_pColors(NULL), + m_pPoints(NULL) +{ + + m_gradientType = source.m_gradientType; + + // Duplicate the colors list + QColor *pColor; + m_pColors = new QPtrList<QColor>; + pColor = source.m_pColors->first(); + while( pColor ) + { + m_pColors->append( new QColor(*pColor) ); + + pColor = source.m_pColors->next(); + } + + + // Duplicate the point list + KivioPoint *pPoint; + m_pPoints = new QPtrList<KivioPoint>; + pPoint = source.m_pPoints->first(); + while( pPoint ) + { + m_pPoints->append( new KivioPoint( *pPoint ) ); + + pPoint = source.m_pPoints->next(); + } +} + + +/** + * Copy all attributes of this into pTarget + * + * @param pTarget The object to copy into + * + * This will copy all colors/points/everything-else into pTarget. + */ +void KivioGradient::copyInto( KivioGradient *pTarget ) const +{ + if( !pTarget ) + return; + + // Copy the gradient type + pTarget->m_gradientType = m_gradientType; + + // Delete the old color array if we have one + if( pTarget->m_pColors ) + { + delete pTarget->m_pColors; + pTarget->m_pColors = NULL; + } + + // Allocate a new color array + pTarget->m_pColors = new QPtrList<QColor>; + pTarget->m_pColors->setAutoDelete(true); + + + // Copy the colors + QColor *pColor; + pColor = m_pColors->first(); + while( pColor ) + { + pTarget->m_pColors->append( new QColor(*pColor) ); + + pColor = m_pColors->next(); + } + + if( pTarget->m_pPoints ) + { + delete pTarget->m_pPoints; + pTarget->m_pPoints = NULL; + } + + pTarget->m_pPoints = new QPtrList<KivioPoint>; + pTarget->m_pPoints->setAutoDelete(true); + + KivioPoint *pPoint; + pPoint = m_pPoints->first(); + while( pPoint ) + { + pTarget->m_pPoints->append( new KivioPoint( *pPoint ) ); + + pPoint = m_pPoints->next(); + } +} + + +/** + * Load this object from an XML element + * + * FIXME: Implement this + */ +bool KivioGradient::loadXML( const QDomElement & ) +{ + return false; +} + + +/** + * Save this object to an XML element + * + * FIXME: Implement this + */ +QDomElement KivioGradient::saveXML( QDomDocument &doc ) +{ + + return doc.createElement("KivioGradient"); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_gradient.h b/kivio/kiviopart/kiviosdk/kivio_gradient.h new file mode 100644 index 000000000..0d9acfee5 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_gradient.h @@ -0,0 +1,69 @@ +/* + * 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 KIVIO_GRADIENT_H +#define KIVIO_GRADIENT_H + +#include <qptrlist.h> +#include <qcolor.h> +#include <qdom.h> +class KivioPoint; + +class KivioGradient +{ +public: + // Gradient type enumerations + typedef enum { + kgtNone=0, + kgtLinear, + kgtBiLinear, + kgtRadial, + kgtSquare, + kgtConicalSymmetric, + kgtConicalAsymmetric, + kgtLast + } KivioGradientType; + +protected: + QPtrList <QColor> *m_pColors; // A list of the colors in the gradient + QPtrList <KivioPoint> *m_pPoints; // A list of the points for each color + KivioGradientType m_gradientType; // The type of gradient + + +public: + KivioGradient(); + KivioGradient( const KivioGradient & ); + virtual ~KivioGradient(); + + void copyInto( KivioGradient *pTarget ) const; + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + + QPtrList<QColor> *colors() const { return m_pColors; } + + QPtrList<KivioPoint> *points() const { return m_pPoints; } + + KivioGradientType gradientType() const { return m_gradientType; } + void setGradientType( KivioGradientType t ) { m_gradientType=t; } +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_group_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_group_stencil.cpp new file mode 100644 index 000000000..f29fee68a --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_group_stencil.cpp @@ -0,0 +1,748 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2004 theKompany.com & Dave Marotti + * Peter Simonsson + * + * 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 "kivio_group_stencil.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_layer.h" + +#include <kdebug.h> + +#include <KoGlobal.h> + +KivioGroupStencil::KivioGroupStencil() + : KivioStencil(), + m_pGroupList(NULL) +{ + m_pGroupList = new QPtrList<KivioStencil>; + m_pGroupList->setAutoDelete(true); + + m_x = m_y = 1000000000000.0f; + m_w = m_h = -10000000000.0f; + setType(kstGroup); +} + +KivioGroupStencil::~KivioGroupStencil() +{ + if( m_pGroupList ) + { + delete m_pGroupList; + m_pGroupList = NULL; + } +} + + +void KivioGroupStencil::paint( KivioIntraStencilData *pData ) +{ + // Draw the group + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->paint(pData); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::paintOutline( KivioIntraStencilData *pData ) +{ + // Draw the group in outline mode + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->paintOutline(pData); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::paintConnectorTargets( KivioIntraStencilData *pData ) +{ + // Draw the group in outline mode + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->paintConnectorTargets(pData); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setFGColor( QColor c ) +{ + // Draw the group in outline mode + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setFGColor(c); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setBGColor( QColor c ) +{ + // Draw the group in outline mode + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setBGColor(c); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setLineWidth( double f ) +{ + // Draw the group in outline mode + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setLineWidth(f); + + pStencil = m_pGroupList->next(); + } +} + +KivioCollisionType KivioGroupStencil::checkForCollision( KoPoint *p, double threshold ) +{ + KivioCollisionType colType; + + // Draw the group in outline mode + KivioStencil *pStencil = m_pGroupList->last(); + while( pStencil ) + { + colType = pStencil->checkForCollision( p, threshold ); + if( colType != kctNone && pStencil->type()!=kstConnector) { + return colType; + } + + pStencil = m_pGroupList->prev(); + } + + return kctNone; +} + +void KivioGroupStencil::addToGroup( KivioStencil *pStencil ) +{ + double left, right, top, bottom; + + + m_pGroupList->append(pStencil); + + // Special case it + if( m_pGroupList->count() == 1 ) + { + m_x = pStencil->x(); + m_y = pStencil->y(); + m_w = pStencil->w(); + m_h = pStencil->h(); + } + else + { + right = pStencil->x() + pStencil->w(); + left = pStencil->x(); + top = pStencil->y(); + bottom = pStencil->y() + pStencil->h(); + + // Adjust the borders to new limits + if( left < m_x ) + { + m_w = m_w + (m_x - left); + m_x = left; + } + if( right > m_x + m_w ) + { + m_w = right - m_x; + } + if( top < m_y ) + { + m_h = m_h + (m_y - top); + m_y = top; + } + if( bottom > m_y + m_h ) + { + m_h = bottom - m_y; + } + } +} + +KivioStencil *KivioGroupStencil::duplicate() +{ + KivioGroupStencil *pGroup; + KivioStencil *pStencil; + + pGroup = new KivioGroupStencil(); + + pStencil = m_pGroupList->first(); + while( pStencil ) + { + pGroup->addToGroup( pStencil->duplicate() ); + + pStencil = m_pGroupList->next(); + } + + *(pGroup->protection()) = *m_pProtection; + + return pGroup; +} + +bool KivioGroupStencil::loadXML( const QDomElement &e, KivioLayer *pLayer ) +{ + QDomNode node; + KivioStencil *pStencil; + + node = e.firstChild(); + while( !node.isNull() ) + { + QString name = node.nodeName(); + + if( name == "KivioGroupStencil" ) + { + pStencil = pLayer->loadGroupStencil( node.toElement() ); + if( pStencil ) + { + addToGroup( pStencil ); + } + else + { + kdDebug(43000) << "KivioGroupStencil::loadXML() - Error loading group stencil" << endl; + } + } + else if( name == "KivioSMLStencil" || name == "KivioPyStencil" ) + { + pStencil = pLayer->loadSMLStencil( node.toElement() ); + if( pStencil ) + { + addToGroup( pStencil ); + } + else + { + kdDebug(43000) << "KivioGroupStencil::loadXML() - Error loading group stencil" << endl; + } + } + else if( name == "KivioPluginStencil" ) + { + KivioStencil *pStencil = pLayer->loadPluginStencil( node.toElement() ); + if( pStencil ) + { + addToGroup( pStencil ); + } + else + { + kdDebug(43000) << "KivioGroupStencil::loadXML() - Error loading group stencil" << endl; + } + } + + node = node.nextSibling(); + } + + return true; +} + +QDomElement KivioGroupStencil::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioGroupStencil"); + + QDomElement stencilE; + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + stencilE = pStencil->saveXML( doc ); + + e.appendChild( stencilE ); + + pStencil = m_pGroupList->next(); + } + + return e; +} + +void KivioGroupStencil::setX( double newX ) +{ + double dx = newX - m_x; + + m_x = newX; + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + if( pStencil->protection()->at(kpX)==false ) + { + pStencil->setX( pStencil->x() + dx ); + } + + pStencil = m_pGroupList->next(); + } + +} + +void KivioGroupStencil::setY( double newY ) +{ + double dy = newY - m_y; + + m_y = newY; + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + if( pStencil->protection()->at(kpY)==false ) + { + pStencil->setY( pStencil->y() + dy ); + } + + pStencil = m_pGroupList->next(); + } + +} + +void KivioGroupStencil::setPosition( double newX, double newY ) +{ + double dx = newX - m_x; + double dy = newY - m_y; + + double newX2, newY2; + + m_x = newX; + m_y = newY; + + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + if(((pStencil->type() == kstConnector) && !pStencil->connected()) || + pStencil->type() != kstConnector) + { + if( pStencil->protection()->at(kpX)==false ) { + newX2 = pStencil->x() + dx; + } else { + newX2 = pStencil->x(); + } + + if( pStencil->protection()->at(kpY)==false ) { + newY2 = pStencil->y() + dy; + } else { + newY2 = pStencil->y(); + } + + pStencil->setPosition( newX2, newY2 ); + } + + pStencil = m_pGroupList->next(); + } + +} + +void KivioGroupStencil::setW( double newW ) +{ + double percInc = newW / m_w; + + if( newW > 0.0f ) { + m_w = newW; + } + + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + if(((pStencil->type() == kstConnector) && !pStencil->connected()) || + pStencil->type() != kstConnector) + { + if( pStencil->protection()->at(kpX)==false ) { + pStencil->setX( ((pStencil->x() - m_x) * percInc) + m_x ); + } + + if( pStencil->protection()->at(kpWidth)==false ) { + pStencil->setW( pStencil->w() * percInc ); + } + } + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setH( double newH ) +{ + double percInc = newH / m_h; + + if( newH > 0.0f ) { + m_h = newH; + } + + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + if(((pStencil->type() == kstConnector) && !pStencil->connected()) || + pStencil->type() != kstConnector) + { + if( pStencil->protection()->at(kpY)==false ) { + pStencil->setY( ((pStencil->y() - m_y) * percInc) + m_y ); + } + + if( pStencil->protection()->at(kpHeight)==false ) { + pStencil->setH( pStencil->h() * percInc ); + } + } + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setDimensions( double newW, double newH ) +{ + double percIncX = newW / m_w; + double percIncY = newH / m_h; + + if( newW > 0.0f ) { + m_w = newW; + } + if( newH > 0.0f ) { + m_h = newH; + } + + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + if(((pStencil->type() == kstConnector) && !pStencil->connected()) || + pStencil->type() != kstConnector) + { + if( newW > 0.0f ) { + if( pStencil->protection()->at(kpX)==false ) { + pStencil->setX( ((pStencil->x() - m_x) * percIncX) + m_x ); + } + if( pStencil->protection()->at(kpWidth)==false ) { + pStencil->setW( pStencil->w() * percIncX ); + } + } + + if( newH > 0.0f ) { + if( pStencil->protection()->at(kpY)==false ) { + pStencil->setY( ((pStencil->y() - m_y) * percIncY) + m_y ); + } + if( pStencil->protection()->at(kpHeight)==false ) { + pStencil->setH( pStencil->h() * percIncY ); + } + } + } + + pStencil = m_pGroupList->next(); + } + +} + +int KivioGroupStencil::generateIds( int next ) +{ + KivioStencil *pStencil = m_pGroupList->first(); + + while( pStencil ) + { + next = pStencil->generateIds( next ); + + pStencil = m_pGroupList->next(); + } + + return next; +} + + +KivioConnectorTarget *KivioGroupStencil::connectToTarget( KivioConnectorPoint *p, double thresh) +{ + KivioConnectorTarget *pTarget; + + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pTarget = pStencil->connectToTarget( p, thresh ); + if( pTarget ) + return pTarget; + + pStencil = m_pGroupList->next(); + } + + return NULL; +} + +KivioConnectorTarget *KivioGroupStencil::connectToTarget( KivioConnectorPoint *p, int id ) +{ + KivioConnectorTarget *pTarget; + + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pTarget = pStencil->connectToTarget( p, id ); + if( pTarget ) + return pTarget; + + pStencil = m_pGroupList->next(); + } + + return NULL; +} + +void KivioGroupStencil::searchForConnections( KivioPage *p ) +{ + KivioStencil *pCur = 0; + KivioStencil *pStencil = m_pGroupList->first(); + + while( pStencil ) + { + // Backup the current list position + pCur = pStencil; + + pStencil->searchForConnections( p ); + + // Restore it + m_pGroupList->find( pCur ); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setTextColor( QColor c ) +{ + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setTextColor(c); + + pStencil = m_pGroupList->next(); + } +} + +void KivioGroupStencil::setText( const QString &text ) +{ + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setText(text); + + pStencil = m_pGroupList->next(); + } +} + +QString KivioGroupStencil::text() +{ + KivioStencil *pStencil = m_pGroupList->first(); + + if( !pStencil ) + return QString(""); + + return pStencil->text(); +} + +void KivioGroupStencil::setHTextAlign( int a ) +{ + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setHTextAlign(a); + + pStencil = m_pGroupList->next(); + } +} + +int KivioGroupStencil::hTextAlign() +{ + KivioStencil *pStencil = m_pGroupList->first(); + + if( !pStencil ) + return Qt::AlignHCenter; + + return pStencil->hTextAlign(); +} + +void KivioGroupStencil::setVTextAlign( int a ) +{ + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setVTextAlign(a); + + pStencil = m_pGroupList->next(); + } +} + +int KivioGroupStencil::vTextAlign() +{ + KivioStencil *pStencil = m_pGroupList->first(); + + if( !pStencil ) + return Qt::AlignVCenter; + + return pStencil->vTextAlign(); +} + +void KivioGroupStencil::setTextFont( const QFont &f ) +{ + KivioStencil *pStencil = m_pGroupList->first(); + while( pStencil ) + { + pStencil->setTextFont(f); + + pStencil = m_pGroupList->next(); + } +} + +QFont KivioGroupStencil::textFont() +{ + KivioStencil *pStencil = m_pGroupList->first(); + + if( !pStencil ) + return KoGlobal::defaultFont(); + + return pStencil->textFont(); +} + +QColor KivioGroupStencil::textColor() +{ + KivioStencil *pStencil = m_pGroupList->first(); + + if( !pStencil ) + return QColor(0, 0, 0); + + return pStencil->textColor(); +} + +int KivioGroupStencil::resizeHandlePositions() +{ + return KIVIO_RESIZE_HANDLE_POSITION_ALL; +} + +QString KivioGroupStencil::getTextBoxName(const KoPoint& p) +{ + int id = checkForCollision(p); + + if(id < 0) { + return QString::null; + } + + KivioStencil* pStencil = m_pGroupList->at(id); + QString name = QString::number(id) + "-" + pStencil->getTextBoxName(p); + return name; +} + +void KivioGroupStencil::setText(const QString& text, const QString& name) +{ + int id = name.section("-", 0, 0).toInt(); + QString n = name.section("-", 1); + + m_pGroupList->at(id)->setText(text, n); +} + +QString KivioGroupStencil::text(const QString& name) +{ + int id = name.section("-", 0, 0).toInt(); + QString n = name.section("-", 1); + + return m_pGroupList->at(id)->text(n); +} + +int KivioGroupStencil::checkForCollision(const KoPoint& p) +{ + KivioStencil *pStencil = m_pGroupList->first(); + KoPoint pos = p; + int id = 0; + + while(pStencil) + { + if(pStencil->checkForCollision(&pos, 4.0) != kctNone) { + return id; + } + + pStencil = m_pGroupList->next(); + id++; + } + + return -1; +} + +bool KivioGroupStencil::hasTextBox() const +{ + KivioStencil *pStencil = m_pGroupList->first(); + + while(pStencil) + { + if(pStencil->hasTextBox()) { + return true; + } + + pStencil = m_pGroupList->next(); + } + + return false; +} + +QColor KivioGroupStencil::textColor(const QString& textBoxName) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + return m_pGroupList->at(id)->textColor(n); +} + +void KivioGroupStencil::setTextColor(const QString& textBoxName, const QColor& color) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + m_pGroupList->at(id)->setTextColor(n, color); +} + +QFont KivioGroupStencil::textFont(const QString& textBoxName) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + return m_pGroupList->at(id)->textFont(n); +} + +void KivioGroupStencil::setTextFont(const QString& textBoxName, const QFont& font) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + m_pGroupList->at(id)->setTextFont(n, font); +} + +int KivioGroupStencil::hTextAlign(const QString& textBoxName) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + return m_pGroupList->at(id)->hTextAlign(n); +} + +int KivioGroupStencil::vTextAlign(const QString& textBoxName) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + return m_pGroupList->at(id)->vTextAlign(n); +} + +void KivioGroupStencil::setHTextAlign(const QString& textBoxName, int align) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + m_pGroupList->at(id)->setHTextAlign(n, align); +} + +void KivioGroupStencil::setVTextAlign(const QString& textBoxName, int align) +{ + int id = textBoxName.section("-", 0, 0).toInt(); + QString n = textBoxName.section("-", 1); + + m_pGroupList->at(id)->setVTextAlign(n, align); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_group_stencil.h b/kivio/kiviopart/kiviosdk/kivio_group_stencil.h new file mode 100644 index 000000000..e2ae148fa --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_group_stencil.h @@ -0,0 +1,141 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2004 theKompany.com & Dave Marotti + * Peter Simonsson + * + * 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 KIVIO_GROUP_STENCIL_H +#define KIVIO_GROUP_STENCIL_H + +#include "kivio_stencil.h" + +#include <qdom.h> + +class KivioIntraStencilData; +class KivioLayer; +class KivioPage; +class KivioPainter; + +class KivioGroupStencil : public KivioStencil +{ + protected: + // The list of child stencils + QPtrList<KivioStencil> *m_pGroupList; + int checkForCollision(const KoPoint& p); + + public: + KivioGroupStencil(); + virtual ~KivioGroupStencil(); + + + // File I/O routines + virtual bool loadXML( const QDomElement &, KivioLayer * ); + virtual QDomElement saveXML( QDomDocument & ); + + + // Painting routines + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paint( KivioIntraStencilData * ); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + + + // Duplication + virtual KivioStencil *duplicate(); + + + // FG/Color operations + virtual void setFGColor( QColor ); + virtual void setBGColor( QColor ); + + + + // Text operations + virtual QColor textColor(); + virtual void setTextColor( QColor ); + + virtual QFont textFont(); + virtual void setTextFont( const QFont & ); + + virtual int hTextAlign(); + virtual int vTextAlign(); + + virtual void setHTextAlign(int); + virtual void setVTextAlign(int); + + virtual void setText( const QString & ); + virtual QString text(); + + + // Line width + virtual void setLineWidth( double ); + + + // Collision detection + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + + + // Group operations + virtual void addToGroup( KivioStencil * ); + virtual QPtrList<KivioStencil> *groupList() { return m_pGroupList; } + + + // Position / Dimension operations + virtual void setX( double ); + virtual void setY( double ); + virtual void setW( double ); + virtual void setH( double ); + virtual void setPosition( double f1, double f2 ); + virtual void setDimensions( double f1, double f2 ); + + + // ID generation + virtual int generateIds( int ); + + + // Connection operations + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, double ); + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, int ); + + virtual void searchForConnections( KivioPage * ); + + virtual int resizeHandlePositions(); + + /** + Returns the name of the text box that is at @param p. + If there exist no text box at @param p then it returns QString::null. + */ + virtual QString getTextBoxName(const KoPoint& p); + + virtual void setText(const QString& text, const QString& name); + virtual QString text(const QString& name); + + virtual bool hasTextBox() const; + + virtual QColor textColor(const QString& textBoxName); + virtual void setTextColor(const QString& textBoxName, const QColor& color); + + virtual QFont textFont(const QString& textBoxName); + virtual void setTextFont(const QString& textBoxName, const QFont& font); + + virtual int hTextAlign(const QString& textBoxName); + virtual int vTextAlign(const QString& textBoxName); + + virtual void setHTextAlign(const QString& textBoxName, int align); + virtual void setVTextAlign(const QString& textBoxName, int align); +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_layer.cpp b/kivio/kiviopart/kiviosdk/kivio_layer.cpp new file mode 100644 index 000000000..4c567f003 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_layer.cpp @@ -0,0 +1,591 @@ +/* + * 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 "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_connector_target.h" +#include "kivio_group_stencil.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_layer.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 "KIvioLayerIface.h" +#include "kivio_doc.h" +#include "kivio_page.h" + +#include <qdom.h> + +#include <klocale.h> +#include <kdebug.h> +#include <KoZoomHandler.h> +#include <KoPoint.h> +#include <KoStore.h> +#include <KoXmlWriter.h> + +KivioLayer::KivioLayer( KivioPage *pPage ) + :m_pStencilList(NULL) +{ + m_pPage = pPage; + m_name = i18n("Untitled Layer"); + + m_pStencilList = new QPtrList<KivioStencil>; + m_pStencilList->setAutoDelete(true); + + m_pDeletedStencilList = new QPtrList<KivioStencil>; + m_pDeletedStencilList->setAutoDelete(true); + + m_flags = 0; + m_dcop = 0; + setVisible(true); + setConnectable(false); + setEditable(true); + setPrintable(true); +} + +DCOPObject* KivioLayer::dcopObject() +{ + if ( !m_dcop ) + m_dcop = new KIvioLayerIface( this ); + return m_dcop; +} + +KivioLayer::~KivioLayer() +{ + kdDebug(43000)<<"KivioLayer::~KivioLayer()***************:"<<this<<endl; + if( m_pStencilList ) + { + delete m_pStencilList; + m_pStencilList = NULL; + } + delete m_pDeletedStencilList; + delete m_dcop; +} + +bool KivioLayer::addStencil( KivioStencil *pStencil ) +{ + int pos = m_pDeletedStencilList->findRef(pStencil); + if ( pos != -1 ) + m_pDeletedStencilList->take( pos); + + m_pStencilList->append( pStencil ); + + return true; +} + +void KivioLayer::takeStencilFromList( KivioStencil *pStencil ) +{ + int pos=m_pStencilList->findRef(pStencil); + m_pStencilList->take( pos ); + m_pDeletedStencilList->append( pStencil ); +} + +void KivioLayer::insertStencil( KivioStencil *pStencil ) +{ + int pos=m_pDeletedStencilList->findRef(pStencil); + if ( pos != -1 ) + m_pDeletedStencilList->take( pos); + + m_pStencilList->append( pStencil ); +} + +bool KivioLayer::removeStencil( KivioStencil *pStencil ) +{ + return m_pStencilList->remove( pStencil ); +} + + +/** + * Returns a new stencil of the type described by stencilE + * + * @param stencilE The XML element to load from + * + * This will search through all KivioStencilSpawnerSets and attempt to + * locate the stencil described by stencilE. If it finds it, it allocates + * a new copy of it, loads the data from stencilE into it, and returns + * it. + * + * @returns A new, loaded stencil. + */ +KivioStencil *KivioLayer::loadSMLStencil( const QDomElement &stencilE ) +{ + QString setId, _id; + + kdDebug(43000) << "KivioLayer::loadSMLStencil() " << setId << " " << _id << endl; + + setId = XmlReadString( stencilE, "setId", "" ); + _id = XmlReadString( stencilE, "id", "" ); + + + if( setId.length() == 0 || + _id.length() == 0 ) + { + return NULL; + } + + + // Locate the spawner set + KivioStencilSpawner *pSpawner = m_pPage->doc()->findStencilSpawner(setId,_id); + if( pSpawner ) + { + KivioStencil *pStencil = pSpawner->newStencil(); + pStencil->loadXML( stencilE ); + + return pStencil; + } + + return NULL; +} + +/** + * Returns a new stencil of the type described by stencilE + * + * @param stencilE The XML element to load from + * + * This will search through all KivioStencilSpawnerSets and attempt to + * locate the stencil described by stencilE. If it finds it, it allocates + * a new copy of it, loads the data from stencilE into it, and returns + * it. + * + * @returns A new, loaded stencil. + */ +KivioStencil *KivioLayer::loadGroupStencil( const QDomElement &stencilE ) +{ + kdDebug(43000) << "KivioLayer::loadGroupStencil()" << endl; + + KivioGroupStencil *pStencil = new KivioGroupStencil(); + + if(pStencil->loadXML( stencilE, this )==false) + { + delete pStencil; + return NULL; + } + + return pStencil; +} + +KivioStencil *KivioLayer::loadPluginStencil( const QDomElement &stencilE ) +{ + QString setId, _id; + + kdDebug(43000) << "KivioLayer::loadPluginStencil() " << setId.ascii() << " / " << _id << endl; + + + setId = XmlReadString( stencilE, "setId", "" ); + _id = XmlReadString( stencilE, "id", "" ); + + + if( setId.length() == 0 || + _id.length() == 0 ) + return NULL; + + + // Locate the spawner set + KivioStencilSpawner *pSpawner = m_pPage->doc()->findStencilSpawner(setId, _id); + if( pSpawner ) + { + KivioStencil *pStencil = pSpawner->newStencil(); + pStencil->loadXML( stencilE ); + + return pStencil; + } + + return NULL; +} + +bool KivioLayer::loadXML( const QDomElement &layerE ) +{ + m_flags = XmlReadInt( layerE, "flags", 1 ); + kdDebug(43000) << "Flags: " << m_flags << endl; + m_name = XmlReadString( layerE, "name", "layerX" ); + + QDomNode node; + node = layerE.firstChild(); + while( !node.isNull() ) + { + QString name = node.nodeName(); + if( name == "KivioSMLStencil" || name == "KivioPyStencil" ) + { + KivioStencil *pStencil = loadSMLStencil( node.toElement() ); + if( pStencil ) + { + pStencil->updateGeometry(); + m_pStencilList->append( pStencil ); + } + else + { + kdWarning(43000) << "KivioLayer::loadXML() - Unknown KivioSMLStencil (id=" << + XmlReadString( node.toElement(), "id", "" ) << " set=" << + XmlReadString( node.toElement(), "setId", "" ) << ") found." << endl; + } + } + else if( name == "KivioGroupStencil" ) + { + KivioStencil *pStencil = loadGroupStencil( node.toElement() ); + if( pStencil ) + { + m_pStencilList->append(pStencil); + } + else + { + kdWarning(43000) << "KivioLayer::loadXML() - Unable to load KivioGroupStencil" << endl; + } + } + else if( name == "KivioPluginStencil" ) + { + KivioStencil *pStencil = loadPluginStencil( node.toElement() ); + if( pStencil ) + { + m_pStencilList->append(pStencil); + } + else + { + kdWarning(43000) << "KivioLayer - Unable to load KivioPluginStencil" << endl; + kdWarning(43000) << "KivioLayer::loadXML() - Unable to load KivioPluginStencil (id=" << + XmlReadString( node.toElement(), "id", "" ) << " set=" << + XmlReadString( node.toElement(), "setId", "" ) << ") found." << endl; + } + } + + node = node.nextSibling(); + } + + return true; +} + +void KivioLayer::loadOasis(const QDomElement& layer) +{ + m_name = layer.attribute("draw:name"); + // TODO OASIS Load flags +} + + +QDomElement KivioLayer::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioLayer"); + + XmlWriteInt( e, "flags", m_flags ); + XmlWriteString( e, "name", m_name ); + + KivioStencil *pStencil = m_pStencilList->first(); + while( pStencil ) + { + e.appendChild( pStencil->saveXML( doc ) ); + + pStencil = m_pStencilList->next(); + } + + return e; +} + +void KivioLayer::saveOasis(KoXmlWriter* layerWriter) +{ + layerWriter->startElement("draw:layer"); + layerWriter->addAttribute("draw:name", m_name); + // TODO OASIS Save flags + layerWriter->endElement(); // draw:layer +} + +void KivioLayer::paintContent( KivioPainter& painter, const QRect&, bool, QPoint, + KoZoomHandler* zoom ) +{ + if(!visible()) { + return; + } + + KivioStencil *pStencil = m_pStencilList->first(); + KivioIntraStencilData data; + + painter.setFGColor( QColor(0,0,0) ); + + data.painter = &painter; + data.zoomHandler = zoom; + + while( pStencil ) + { + if(!pStencil->hidden()) { + pStencil->paint( &data ); + } + + pStencil = m_pStencilList->next(); + } +} + +void KivioLayer::printContent( KivioPainter& painter, int xdpi, int ydpi ) +{ + if(!printable() || !visible()) + return; + + if(!xdpi) { + xdpi = KoGlobal::dpiX(); + } + + if(!ydpi) { + ydpi = KoGlobal::dpiY(); + } + + KivioStencil *pStencil = m_pStencilList->first(); + KivioIntraStencilData data; + KoZoomHandler zoomHandler; + zoomHandler.setZoomAndResolution(100, xdpi, ydpi); + + painter.setFGColor( QColor(0,0,0) ); + + data.painter = &painter; + data.zoomHandler = &zoomHandler; + data.printing = true; + + while( pStencil ) + { + pStencil->paint( &data ); + + pStencil = m_pStencilList->next(); + } +} + +void KivioLayer::printContent(KivioPainter& painter, KoZoomHandler* zoomHandler) +{ + if(!printable() || !visible()) + return; + + KivioStencil *pStencil = m_pStencilList->first(); + KivioIntraStencilData data; + + painter.setFGColor( QColor(0,0,0) ); + + data.painter = &painter; + data.zoomHandler = zoomHandler; + data.printing = true; + + while( pStencil ) + { + pStencil->paint( &data ); + + pStencil = m_pStencilList->next(); + } +} + +void KivioLayer::paintConnectorTargets( KivioPainter& painter, const QRect&, bool, QPoint, + KoZoomHandler* zoom ) +{ + if(!visible()) { + return; + } + + KivioIntraStencilData data; + + painter.setFGColor( QColor(0,0,0) ); + + data.painter = &painter; + data.zoomHandler = zoom; + + KivioStencil *pStencil = m_pStencilList->first(); + while( pStencil ) + { + if(!pStencil->hidden()) { + pStencil->paintConnectorTargets( &data ); + } + + pStencil = m_pStencilList->next(); + } +} + +void KivioLayer::paintSelectionHandles( KivioPainter& painter, const QRect&, bool, QPoint, KoZoomHandler* zoom ) +{ + if(!visible()) { + return; + } + + KivioIntraStencilData data; + + painter.setFGColor( QColor(0,0,0) ); + + data.painter = &painter; + data.zoomHandler = zoom; + + KivioStencil *pStencil = m_pStencilList->first(); + while( pStencil ) + { + if( pStencil->isSelected() && !pStencil->hidden() ) + pStencil->paintSelectionHandles( &data ); + + pStencil = m_pStencilList->next(); + } +} + +KivioStencil *KivioLayer::checkForStencil( KoPoint *pPoint, int *collisionType, float threshold, bool selectedOnly ) +{ + KivioStencil *pStencil; + int colType; + + if(editable()) { + pStencil = m_pStencilList->last(); + while( pStencil ) + { + // If we are only supposed to check the selected stencils, then only do that. Otherwise + // check them all. + if( (selectedOnly==true && pStencil->isSelected()==true) || + (selectedOnly==false) ) + { + if( (colType = pStencil->checkForCollision( pPoint, threshold )) != kctNone ) + { + // Assign the collision type and return + *collisionType = colType; + return pStencil; + } + } + + pStencil = m_pStencilList->prev(); + } + } + + *collisionType = kctNone; + + return NULL; +} + +void KivioLayer::setVisible( bool f ) +{ + if( f==true ) + { + m_flags = m_flags | FLOW_LAYER_VISIBLE; + } + else + { + m_flags = m_flags & (~FLOW_LAYER_VISIBLE); + } +} + +void KivioLayer::setConnectable( bool f ) +{ + if( f==true ) + { + m_flags = m_flags | FLOW_LAYER_CONNECTABLE; + } + else + { + m_flags = m_flags & (~FLOW_LAYER_CONNECTABLE); + } +} + +void KivioLayer::setEditable(bool f) +{ + if(f) { + m_flags = m_flags & (~FLOW_LAYER_NOT_EDITABLE); + } else { + m_flags = m_flags | FLOW_LAYER_NOT_EDITABLE; + } +} + +void KivioLayer::setPrintable(bool f) +{ + if(f) { + m_flags = m_flags & (~FLOW_LAYER_NOT_PRINTABLE); + } else { + m_flags = m_flags | FLOW_LAYER_NOT_PRINTABLE; + } +} + +int KivioLayer::generateStencilIds( int next ) +{ + KivioStencil *pStencil; + + pStencil = m_pStencilList->first(); + while( pStencil ) + { + next = pStencil->generateIds( next ); + + pStencil = m_pStencilList->next(); + } + + return next; +} + +void KivioLayer::searchForConnections( KivioPage *p ) +{ + KivioStencil *pStencil; + KivioStencil *pCur; + + pStencil = m_pStencilList->first(); + while( pStencil ) + { + // Backup the current list position + pCur = pStencil; + + pStencil->searchForConnections( p ); + + // Restore it + m_pStencilList->find( pCur ); + + pStencil = m_pStencilList->next(); + } +} + +KivioStencil *KivioLayer::takeStencil( KivioStencil *p ) +{ + m_pStencilList->find( p ); + + return m_pStencilList->take(); +} + + +/** + * Attempts to connect a KivioConnectorPoint to a KivioConnectorTarget of each stencil. + * + * @param p The point to attempt the connection with + * @param thresh The threshold to use + * @returns The KivioConnectorTarget the point connected to + */ +KivioConnectorTarget *KivioLayer::connectPointToTarget( KivioConnectorPoint *p, float thresh ) +{ + KivioConnectorTarget *pTarget; + + KivioStencil *pStencil = m_pStencilList->last(); + while( pStencil ) + { + // Don't allow the connector point to connect to the stencil that owns it + if( pStencil != p->stencil() ) + { + pTarget = pStencil->connectToTarget(p, thresh); + if( pTarget ) + { + return pTarget; + } + } + + pStencil = m_pStencilList->prev(); + } + + return NULL; +} + +KoPoint KivioLayer::snapToTarget( const KoPoint& p, double thresh, bool& hit ) +{ + KoPoint retVal = p; + KivioStencil *pStencil = m_pStencilList->last(); + + while( pStencil && !hit) + { + retVal = pStencil->snapToTarget(p, thresh, hit); + pStencil = m_pStencilList->prev(); + } + + return retVal; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_layer.h b/kivio/kiviopart/kiviosdk/kivio_layer.h new file mode 100644 index 000000000..88cbe2e0b --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_layer.h @@ -0,0 +1,128 @@ +/* + * 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 KIVIO_LAYER_H +#define KIVIO_LAYER_H + +#include <qdom.h> +#include <qptrlist.h> +#include <qobject.h> +#include <KoPoint.h> +class KivioConnectorPoint; +class KivioConnectorTarget; +class KivioPage; +class KivioPainter; +class KoPoint; +class DCOPObject; +class KoZoomHandler; +class QDomElement; +class KoStore; +class KoXmlWriter; + +#include "kivio_stencil.h" + +#define FLOW_LAYER_VISIBLE 0x0001 +#define FLOW_LAYER_CONNECTABLE 0x0002 +#define FLOW_LAYER_NOT_EDITABLE 0x0004 +#define FLOW_LAYER_NOT_PRINTABLE 0x0008 + +class KivioLayer +{ +protected: + friend class KivioGroupStencil; + + int m_flags; + QPtrList <KivioStencil> *m_pStencilList; + QPtrList <KivioStencil> *m_pDeletedStencilList; + QString m_name; + KivioPage *m_pPage; + DCOPObject* m_dcop; + + KivioStencil *loadSMLStencil( const QDomElement & ); + KivioStencil *loadGroupStencil( const QDomElement & ); + KivioStencil *loadPluginStencil( const QDomElement & ); + + +public: + KivioLayer( KivioPage * ); + virtual ~KivioLayer(); + + KivioPage *page()const{return m_pPage;} + + virtual DCOPObject* dcopObject(); + + QPtrList<KivioStencil> *stencilList() { return m_pStencilList; } + + bool visible() { return (m_flags & FLOW_LAYER_VISIBLE); } + void setVisible( bool f ); + + bool connectable() { return (m_flags & FLOW_LAYER_CONNECTABLE); } + void setConnectable( bool f ); + + void setEditable(bool f); + bool editable() { return !(m_flags & FLOW_LAYER_NOT_EDITABLE); } + + void setPrintable(bool f); + bool printable() { return !(m_flags & FLOW_LAYER_NOT_PRINTABLE); } + + QString name() const { return m_name; } + void setName( const QString &n ) { m_name = QString(n); } + + bool addStencil( KivioStencil * ); + bool removeStencil( KivioStencil * ); + + bool loadXML( const QDomElement & ); + void loadOasis(const QDomElement& layer); + QDomElement saveXML( QDomDocument & ); + void saveOasis(KoXmlWriter* layerWriter); + + KivioStencil *checkForStencil( KoPoint *, int *, float, bool ); + + void printContent( KivioPainter& painter, int xdpi = 0, int ydpi = 0 ); + void printContent(KivioPainter& painter, KoZoomHandler* zoomHandler); + void paintContent( KivioPainter& painter, const QRect& rect, bool transparent, QPoint p0, + KoZoomHandler* zoom ); + void paintConnectorTargets( KivioPainter& painter, const QRect& rect, bool transparent, + QPoint p0, KoZoomHandler* zoom ); + void paintSelectionHandles( KivioPainter& painter, const QRect& rect, bool transparent, + QPoint p0, KoZoomHandler* zoom ); + + KivioStencil *firstStencil() { return m_pStencilList->first(); } + KivioStencil *nextStencil() { return m_pStencilList->next(); } + KivioStencil *prevStencil() { return m_pStencilList->prev(); } + KivioStencil *takeStencil() { return m_pStencilList->take(); } + KivioStencil *currentStencil() { return m_pStencilList->current(); } + KivioStencil *lastStencil() { return m_pStencilList->last(); } + + KivioStencil *takeStencil( KivioStencil * ); + + KivioConnectorTarget *connectPointToTarget( KivioConnectorPoint *, float ); + + KoPoint snapToTarget( const KoPoint& p, double thresh, bool& hit ); + + int generateStencilIds( int ); + + void searchForConnections( KivioPage * ); + void takeStencilFromList( KivioStencil *pStencil ); + void insertStencil( KivioStencil *pStencil ); + +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_layers.h b/kivio/kiviopart/kiviosdk/kivio_layers.h new file mode 100644 index 000000000..0cb3e4175 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_layers.h @@ -0,0 +1,45 @@ +#ifndef KIVIO_LAYERS_H +#define KIVIO_LAYERS_H + +#include "kivio_page.h" +#include "kivio_view.h" +#include <KoZoomHandler.h> + + extern KivioPage *page; + extern KivioView* view; + + void update() { page->update(); } + + bool isStencilSelected( KivioStencil *s ) { return page->isStencilSelected(s); } + void selectAllStencils() { page->selectAllStencils(); } + void unselectAllStencils() { page->unselectAllStencils(); } + bool unselectStencil( KivioStencil *s ) { return page->unselectStencil(s); } + void selectStencil( KivioStencil *s ) { page->selectStencil(s); } + + KivioLayer *curLayer() { return page->curLayer(); } + void setCurLayer( KivioLayer *pLayer ) { page->setCurLayer(pLayer); } + + KivioLayer *firstLayer() { return page->firstLayer(); } + KivioLayer *nextLayer() { return page->nextLayer(); } + KivioLayer *lastLayer() { return page->lastLayer(); } + KivioLayer *prevLayer() { return page->prevLayer(); } + + bool removeCurrentLayer() { return page->removeCurrentLayer(); } + void addLayer( KivioLayer *l ) { page->addLayer(l); } + void insertLayer( int i, KivioLayer *l ) { page->insertLayer(i,l); } + KivioLayer *layerAt( int i ) { return page->layerAt(i); } + + bool addStencil( KivioStencil *s ) { page->addStencil(s); return TRUE; } + + void deleteSelectedStencils() { page->deleteSelectedStencils(); } + void groupSelectedStencils() { page->groupSelectedStencils(); } + void ungroupSelectedStencils() { page->ungroupSelectedStencils(); } + + void bringToFront() { page->bringToFront(); } + void sendToBack() { page->sendToBack(); } + + void copy() { page->copy(); } + void cut() { page->cut(); } + void paste() { page->paste(view); } + +#endif diff --git a/kivio/kiviopart/kiviosdk/kivio_line_style.cpp b/kivio/kiviopart/kiviosdk/kivio_line_style.cpp new file mode 100644 index 000000000..f321a60fd --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_line_style.cpp @@ -0,0 +1,87 @@ +/* + * 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 "kivio_common.h" +#include "kivio_line_style.h" + +KivioLineStyle::KivioLineStyle() +{ + m_color = QColor(0,0,0); + m_width = 1.0f; + m_capStyle = Qt::FlatCap; + m_joinStyle = Qt::RoundJoin; + m_style = Qt::SolidLine; +} + +KivioLineStyle::KivioLineStyle( const KivioLineStyle &ls ) +{ + m_color = ls.color(); + m_width = ls.width(); + m_capStyle = ls.capStyle(); + m_joinStyle = ls.joinStyle(); + m_style = ls.style(); +} + +KivioLineStyle::~KivioLineStyle() +{ +} + +void KivioLineStyle::copyInto( KivioLineStyle *pTarget ) +{ + pTarget->m_color = m_color; + pTarget->m_width = m_width; + pTarget->m_capStyle = m_capStyle; + pTarget->m_joinStyle = m_joinStyle; + pTarget->m_style = m_style; +} + +QDomElement KivioLineStyle::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioLineStyle"); + + XmlWriteColor( e, "color", m_color ); + XmlWriteFloat( e, "width", m_width ); + XmlWriteInt( e, "capStyle", m_capStyle ); + XmlWriteInt( e, "joinStyle", m_joinStyle ); + XmlWriteInt( e, "pattern", m_style ); + return e; +} + +bool KivioLineStyle::loadXML( const QDomElement &e ) +{ + m_color = XmlReadColor( e, "color", QColor(0,0,0) ); + m_width = XmlReadFloat( e, "width", 1.0f ); + m_capStyle = XmlReadInt( e, "capStyle", Qt::RoundCap ); + m_joinStyle = XmlReadInt( e, "joinStyle", Qt::RoundJoin ); + m_style = XmlReadInt( e, "pattern", Qt::SolidLine ); + return true; +} + +QPen KivioLineStyle::pen( float scale ) const +{ + QPen p; + float s = m_width * scale; + + p.setColor( m_color ); + p.setWidth( (int)s ); + p.setJoinStyle( (Qt::PenJoinStyle)m_joinStyle ); + p.setCapStyle( (Qt::PenCapStyle)m_capStyle ); + p.setStyle( (Qt::PenStyle)m_style ); + + return p; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_line_style.h b/kivio/kiviopart/kiviosdk/kivio_line_style.h new file mode 100644 index 000000000..4126324b8 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_line_style.h @@ -0,0 +1,70 @@ +/* + * 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 KIVIO_LINE_STYLE_H +#define KIVIO_LINE_STYLE_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qcolor.h> +#include <qdom.h> +#include <qpen.h> + + +class KivioLineStyle +{ +protected: + QColor m_color; + float m_width; + int m_capStyle; + int m_joinStyle; + int m_style; + +public: + KivioLineStyle(); + KivioLineStyle( const KivioLineStyle & ); + + virtual ~KivioLineStyle(); + + void copyInto( KivioLineStyle * ); + + QDomElement saveXML( QDomDocument & ); + bool loadXML( const QDomElement & ); + + QPen pen( float ) const; + + QColor color() const { return m_color; } + void setColor( QColor c ){ m_color=c; } + + float width() const { return m_width; } + void setWidth( float f ){ m_width=f; } + + int capStyle() const { return m_capStyle; } + void setCapStyle( int p ){ m_capStyle=p; } + + int joinStyle() const { return m_joinStyle; } + void setJoinStyle( int j ){ m_joinStyle=j; } + + int style() const { return m_style; } + void setStyle( int p ) { m_style=p; } +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_painter.cpp b/kivio/kiviopart/kiviosdk/kivio_painter.cpp new file mode 100644 index 000000000..33f5eb6d0 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_painter.cpp @@ -0,0 +1,75 @@ +/* + * 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 "kivio_fill_style.h" +#include "kivio_line_style.h" +#include "kivio_painter.h" +#include "kivio_point.h" + +KivioPainter::KivioPainter() + : m_pFillStyle(NULL) +{ + m_pFillStyle = new KivioFillStyle(); + m_pLineStyle = new KivioLineStyle(); +} + +KivioPainter::~KivioPainter() +{ + if( m_pFillStyle ) + { + delete m_pFillStyle; + m_pFillStyle = NULL; + } + + if( m_pLineStyle ) + { + delete m_pLineStyle; + m_pLineStyle = NULL; + } +} + + +void KivioPainter::setFGColor( const QColor &c ) +{ + m_pLineStyle->setColor(c); +} + +QColor KivioPainter::fgColor() const +{ + return m_pLineStyle->color(); +} + +float KivioPainter::lineWidth() const +{ + return m_pLineStyle->width(); +} + +void KivioPainter::setLineWidth( const float &f ) +{ + m_pLineStyle->setWidth(f); +} + +void KivioPainter::setLineStyle( KivioLineStyle *pStyle ) +{ + pStyle->copyInto( m_pLineStyle ); +} + +void KivioPainter::setFillStyle( KivioFillStyle * s ) +{ + s->copyInto( m_pFillStyle ); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_painter.h b/kivio/kiviopart/kiviosdk/kivio_painter.h new file mode 100644 index 000000000..6e0869fdc --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_painter.h @@ -0,0 +1,153 @@ +/* + * 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 KIVIO_PAINTER_H +#define KIVIO_PAINTER_H + +#include <qfont.h> +#include <qptrlist.h> +#include <qpaintdevice.h> +#include <qpixmap.h> +#include <qpointarray.h> +#include <qwmatrix.h> + +#include "kivio_fill_style.h" + +class KivioPoint; +class KivioFillStyle; +class KivioLineStyle; + +class KivioPainter +{ +protected: + KivioFillStyle *m_pFillStyle; + KivioLineStyle *m_pLineStyle; + + QColor m_textColor; + +public: + KivioPainter(); + virtual ~KivioPainter(); + + virtual bool start( QPaintDevice * ) { return false;} + virtual bool stop() { return false;} + + + /*\ + |*| + |*| + |*| PROPERTY SETTINGS + |*| + |*| (probably don't need to reimplement -- unless you are optimizing) + \*/ + virtual float lineWidth() const; + virtual void setLineWidth( const float &f ); + + // virtual void setClipRect( QRect * ); + // virtual QRect *clipRect(); + + virtual QColor fgColor() const; + virtual void setFGColor( const QColor &c ); + + virtual QColor bgColor() const { return m_pFillStyle->color(); } + virtual void setBGColor( const QColor &c ) { m_pFillStyle->setColor(c); } + + virtual QColor textColor() const { return m_textColor; } + virtual void setTextColor( const QColor &c ) { m_textColor = c; } + + virtual KivioFillStyle *fillStyle() { return m_pFillStyle; } + + virtual void setLineStyle( KivioLineStyle * ); + virtual void setFillStyle( KivioFillStyle * ); + + /*\ + |*| + |*| + |*| PRIMITIVE FUNCTIONS + |*| + |*| (all descendants *must* reimplement these) + \*/ + virtual void drawLine( float, float, float, float ) {;} + virtual void drawArc( float, float, float, float, float, float ) {;} + + virtual void drawBezier( QPtrList<KivioPoint> * ) {;} + virtual void drawBezier( QPointArray & ) {;} + + virtual void drawRect( float, float, float, float ) {;} + virtual void fillRect( float, float, float, float ) {;} + + virtual void drawRoundRect( float, float, float, float, float, float ) {;} + virtual void fillRoundRect( float, float, float, float, float, float ) {;} + + virtual void drawEllipse( float, float, float, float ) {;} + virtual void fillEllipse( float, float, float, float ) {;} + + virtual void drawPie( float, float, float, float, float, float ) {;} + virtual void fillPie( float, float, float, float, float, float ) {;} + + virtual void drawChord( float, float, float, float, float, float ) {;} + virtual void fillChord( float, float, float, float, float, float ) {;} + + virtual void drawOpenPath( QPtrList<KivioPoint> * ) {;} + virtual void drawClosedPath( QPtrList<KivioPoint> * ) {;} + + virtual void drawLineArray( QPtrList<KivioPoint> * ) {;} + virtual void drawPolyline( QPtrList<KivioPoint> * ) {;} + virtual void drawPolygon( QPtrList<KivioPoint> * ) {;} + + virtual void drawLineArray( QPointArray & ) {;} + virtual void drawPolyline( QPointArray & ) {;} + virtual void drawPolygon( QPointArray & ) {;} + + virtual void setFont( const QFont & ) {;} + virtual void drawText( int, int, int, int, int, const QString & ) {;} + virtual QRect boundingRect( int, int, int, int, int, const QString & ) { return QRect(0,0,100,100); } + + + // These shouldn't be used for anything except the screen painter right now... + virtual void drawPixmap( float, float, const QPixmap & ) {;} + + /*\ + |*| Miscellaneous Functions + |*| note: These don't need to be implemented by everything + \*/ + // connector point flags + enum { + cpfConnectable=0x1, + cpfStart=0x2, + cpfEnd=0x4, + cpfConnected=0x8, + cpfLock=0x10 + }; + virtual void drawHandle( float, float, int ) { ; } + virtual void drawSelectionBox( const QRect& ) { ; } + + virtual void saveState() {;} + virtual void restoreState() {;} + virtual void setTranslation(float, float) {;} + virtual void translateBy(float, float) {;} + virtual void setRotation(int) {;} + virtual void rotateBy(int) {;} + virtual int rotation() { return 0; } + + virtual void setWorldMatrix(QWMatrix, bool) {;} +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_plugin_stencil_spawner.cpp b/kivio/kiviopart/kiviosdk/kivio_plugin_stencil_spawner.cpp new file mode 100644 index 000000000..be4ce300c --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_plugin_stencil_spawner.cpp @@ -0,0 +1,100 @@ +/* + * 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 <config.h> +#include "kivio_plugin_stencil_spawner.h" +#include <kparts/part.h> +#include <kparts/componentfactory.h> +#include "kiviostencilfactory.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_common.h" +#include "kivio_stencil.h" + +#include <qdom.h> +#include <qfileinfo.h> +#include <kdebug.h> + +KivioPluginStencilSpawner::KivioPluginStencilSpawner( KivioStencilSpawnerSet *pSet ) + : KivioStencilSpawner( pSet ), + m_handle(NULL) +{ + pNewStencil = NULL; +} + +KivioPluginStencilSpawner::~KivioPluginStencilSpawner() +{ +} + +bool KivioPluginStencilSpawner::load( const QString &f ) +{ + QFileInfo lib(f); + + if( lib.exists()) + { + m_fileName = lib.baseName(); + } else { + return false; + } + + fac = KParts::ComponentFactory::createInstanceFromLibrary<KivioStencilFactory>(m_fileName.local8Bit()); + + if( !fac) + { + kdDebug(43000) << "Failed to load: " << m_fileName << endl; + return false; + } + + // Get the icon + m_pIcon = fac->GetIcon(); + + // Get the info + m_pSInfo = fac->GetSpawnerInfo(); + + return true; +} + +QDomElement KivioPluginStencilSpawner::saveXML( QDomDocument &doc ) +{ + QDomElement spawnE = doc.createElement("KivioPluginStencilSpawner"); + + XmlWriteString( spawnE, "id", m_pInfo->id() ); + + return spawnE; +} + +KivioStencil *KivioPluginStencilSpawner::newStencil() +{ + KivioStencil *pStencil = fac->NewStencil(); + + pStencil->setSpawner(this); + return pStencil; +} + + +KivioStencil *KivioPluginStencilSpawner::newStencil(const QString& arg) +{ + KivioStencil *pStencil = fac->NewStencil(arg); + + pStencil->setSpawner(this); + return pStencil; +} +KivioStencilSpawnerInfo *KivioPluginStencilSpawner::info() +{ + return m_pSInfo; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_plugin_stencil_spawner.h b/kivio/kiviopart/kiviosdk/kivio_plugin_stencil_spawner.h new file mode 100644 index 000000000..da4cb932a --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_plugin_stencil_spawner.h @@ -0,0 +1,63 @@ +/* + * 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 KIVIO_PLUGIN_STENCIL_H +#define KIVIO_PLUGIN_STENCIL_H + +class KivioIntraStencilData; +class KivioStencil; +class KivioStencilFactory; +class QDomDocument; + +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include <qpixmap.h> + +//typedef KivioStencil *(*NewStencilFunc)(); +//typedef QPixmap *(*GetIconFunc)(); +//typedef KivioStencilSpawnerInfo *(*GetSpawnerInfoFunc)(); + + +class KivioPluginStencilSpawner : public KivioStencilSpawner +{ +protected: + KivioStencilFactory *fac; + void *m_handle; + QPixmap *m_pIcon; + QString m_filename; + KivioStencilSpawnerInfo *m_pSInfo; + + KivioStencil *(*pNewStencil)(); + QPixmap *(*pGetIcon)(); + KivioStencilSpawnerInfo *(*pGetSpawnerInfo)(); + +public: + KivioPluginStencilSpawner( KivioStencilSpawnerSet * ); + virtual ~KivioPluginStencilSpawner(); + + virtual bool load( const QString & ); + virtual QDomElement saveXML( QDomDocument & ); + + virtual KivioStencil *newStencil(); + virtual KivioStencil *newStencil(const QString &arg); + virtual KivioStencilSpawnerInfo *info(); + + virtual QPixmap *icon() { return m_pIcon; } +}; + +#endif diff --git a/kivio/kiviopart/kiviosdk/kivio_point.cpp b/kivio/kiviopart/kiviosdk/kivio_point.cpp new file mode 100644 index 000000000..a18a41763 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_point.cpp @@ -0,0 +1,171 @@ +/* + * 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 "kivio_point.h" +#include "kivio_common.h" + +#include <kdebug.h> + + +/* + * Names for the different point types. invalid + * and last are not used for any real point type, + * and only serve as bounds checking devices. + */ +static const char *KivioPointTypeNames[]={ + "invalid", "normal", "bezier", "arc", "last" +}; + + +/** + * Constructor + * + * Sets this point to (0,0) and of type normal. + */ +KivioPoint::KivioPoint() +{ + m_x = 0.0f; + m_y = 0.0f; + m_pointType = kptNormal; +} + + +/** + * Copy constructor + * + * @param copy The KivioPoint to make a copy of. + * + * Copies copy into this object. + */ +KivioPoint::KivioPoint( const KivioPoint © ) +{ + m_x = copy.m_x; + m_y = copy.m_y; + m_pointType = copy.m_pointType; +} + + +/** + * Alternate constructor. + * + * @param newX The x value of the point + * @param newY The y value of the point + * @param pt The point type + * + * Creates a new point with values. + */ +KivioPoint::KivioPoint( double newX, double newY, KivioPointType pt ) +{ + m_x = newX; + m_y = newY; + m_pointType = pt; +} + + +/** + * Destructor + */ +KivioPoint::~KivioPoint() +{ +} + + +/** + * Copies this object's data into pTarget + * + * @param pTarget The destination of the copy + */ +void KivioPoint::copyInto( KivioPoint *pTarget ) const +{ + if( !pTarget ) + return; + + pTarget->m_x = m_x; + pTarget->m_y = m_y; + pTarget->m_pointType = m_pointType; +} + + +/** + * Figure out the KivioPointType from a string + * + * @param str The string to search with + * + * This will figure out the KivioPointType from a string. For example, + * "normal" will return kptNormal. + */ +KivioPoint::KivioPointType KivioPoint::pointTypeFromString( const QString &str ) +{ + int i; + + // Iterate through all the possible enums + for( i=(int)kptNone+1; i<(int)kptLast; i++ ) + { + // If we find it, return it + if( str.compare( KivioPointTypeNames[i] )==0 ) + { + return (KivioPointType)i; + } + } + + // Otherwise return an invalid type + return kptNone; +} + + + +/** + * Load this object from an XML element + * + * @param e The element to load from + * @returns true on success, false on failure. + */ +bool KivioPoint::loadXML( const QDomElement &e ) +{ + if( e.tagName().compare( "KivioPoint" ) != 0 ) + { + kdDebug(43000) << "Attempted to load KivioPoint from non-KivioPoint element" << endl; + return false; + } + + m_x = XmlReadFloat( e, "x", 1.0f ); + m_y = XmlReadFloat( e, "y", 1.0f ); + m_pointType = (KivioPointType)pointTypeFromString( XmlReadString( e, "type", "normal" ) ); + + + return true; +} + + + +/** + * Save this object to an XML element + * + * @param doc The document we are saving to + * @returns QDomElement + */ +QDomElement KivioPoint::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioPoint"); + + + XmlWriteFloat( e, QString("x"), m_x ); + XmlWriteFloat( e, QString("y"), m_y ); + XmlWriteString( e, QString("type"), QString(KivioPointTypeNames[m_pointType]) ); + return e; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_point.h b/kivio/kiviopart/kiviosdk/kivio_point.h new file mode 100644 index 000000000..52158c92f --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_point.h @@ -0,0 +1,70 @@ +/* + * 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 KIVIO_POINT_H +#define KIVIO_POINT_H + +#include <qdom.h> + +class KivioPoint +{ +public: + // KivioPoint type enumerations + typedef enum { + kptNone=0, // Bounds check + kptNormal, // Normal point (for polygons, etc) + kptBezier, // Bezier point (these come in groups of 4) + kptArc, // Arc point (I think these come in groups of 3... unimplemented) + kptLast // Bounds check + } KivioPointType; + +protected: + double m_x, m_y; // Coordinates of the point + KivioPointType m_pointType; // The point type + +public: + KivioPoint(); + KivioPoint( const KivioPoint & ); + KivioPoint( double, double, KivioPointType pt=kptNormal ); + virtual ~KivioPoint(); + + void copyInto( KivioPoint * ) const; + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + static KivioPoint::KivioPointType pointTypeFromString( const QString & ); + + inline double x() const { return m_x; } + inline double y() const { return m_y; } + inline KivioPointType pointType() const { return m_pointType; } + + inline void setX( double newX ) { m_x=newX; } + inline void setY( double newY ) { m_y=newY; } + inline void setPointType( KivioPointType pt ) { m_pointType=pt; } + + inline void set( double newX, double newY, KivioPointType pt=kptNormal ) { m_x=newX; m_y=newY; m_pointType=pt; } + inline void set( const KivioPoint &p, KivioPointType pt=kptNormal ) { m_x=p.x(); m_y=p.y(); m_pointType=pt; } + + inline void moveBy( double dx, double dy ) { m_x += dx; m_y += dy; } + inline void moveBy( const KivioPoint &p ) { m_x += p.x(); m_y += p.y(); } +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp new file mode 100644 index 000000000..0b34f46da --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp @@ -0,0 +1,1024 @@ + +#include "kivio_py_stencil.h" +#include "kivio_view.h" + +KivioPage *page; +KivioView *view; +#ifdef HAVE_PYTHON + +#include "kivioglobal.h" +#include "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_connector_target.h" +#include "kivio_fill_style.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_line_style.h" +#include "kivio_painter.h" +#include "kivio_point.h" +#include "kivio_screen_painter.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil_spawner_set.h" + +#include "kivio_py_stencil_spawner.h" + +#include "kivio_page.h" + +#include <qpainter.h> +#include <qbrush.h> +#include <qcolor.h> +#include <kdebug.h> +#include <math.h> +#include <KoZoomHandler.h> + +#include "py_kivio.h" + +extern "C" { + void initkivioc(void); +} + +KivioPyStencil::KivioPyStencil() + : KivioStencil() +{ + m_pConnectorTargets = new QPtrList<KivioConnectorTarget>; + m_pConnectorTargets->setAutoDelete(true); + + static bool first_time = true; + if ( first_time ) { + Py_Initialize(); // initialize python only once + //kdDebug(43000) << "init kivioc" << endl; + initkivioc(); + first_time = false; + } + + PyObject* mainmod = PyImport_AddModule("__main__"); + globals = PyModule_GetDict(mainmod); + + m_x = old_x = 0.0; + m_y = old_y = 0.0; + m_w = old_w = 72.0; + m_h = old_h = 72.0; + double x2 = m_x+m_w; + double y2 = m_y+m_h; + + + vars = Py_BuildValue( "{s:d,s:d,s:d,s:d,s:d,s:d,s:{},s:[],s:[],s:{}}", + "x", m_x, "y", m_y, "w", m_w, "h", m_h, "x2", x2, "y2", y2 , "style","connectors","connector_targets","shapes"); + + resizeCode = ""; +} + + +KivioPyStencil::~KivioPyStencil() +{ +} + + +int KivioPyStencil::init( QString initCode ) +{ + runPython(kivio_module); + if ( !runPython( initCode ) ) + return 1; + + m_w = getDoubleFromDict( vars, "w"); + m_h = getDoubleFromDict( vars, "h"); + m_x = getDoubleFromDict( vars, "x"); + m_y = getDoubleFromDict( vars, "y"); + + old_x = m_x; + old_y = m_y; + old_w = m_w; + old_h = m_h; + return 1; +} + + +bool KivioPyStencil::loadXML( const QDomElement &e ) +{ + QDomNode node; + QDomElement ele; + + + node = e.firstChild(); + while( !node.isNull() ) + { + QString nodeName = node.nodeName(); + + ele = node.toElement(); + + if( nodeName == "PyData" ) + { + resizeCode = XmlReadString( ele, "resizeCode", "" ); + + QString sVars = XmlReadString( ele, "vars", "" ); + + PyObject* mainmod = PyImport_AddModule("__main__"); + PyObject* gdic = PyModule_GetDict(mainmod); + PyObject *ldic = Py_BuildValue("{s:s,s:{}}", "ldic", sVars.latin1() ,"res"); + + if ( !PyRun_String("import pickle\nres = pickle.loads(ldic)", Py_file_input, gdic, ldic) ) { + PyErr_Print(); + return false; + } + + vars = PyDict_GetItemString( ldic, "res" ); + Py_INCREF(vars); + runPython(kivio_module); + + m_w = getDoubleFromDict( vars, "w"); + m_h = getDoubleFromDict( vars, "h"); + m_x = getDoubleFromDict( vars, "x"); + m_y = getDoubleFromDict( vars, "y"); + + old_x = m_x; + old_y = m_y; + old_w = m_w; + old_h = m_h; + + } + else if( nodeName == "KivioConnectorTargetList" ) + { + loadConnectorTargetListXML( ele ); + } + + node = node.nextSibling(); + } + return true; +} + + +/** + * Help function for loading from an XML node. + */ +void KivioPyStencil::loadConnectorTargetListXML( const QDomElement &e ) +{ + QDomNode node; + QDomElement ele; + QString nodeName; + KivioConnectorTarget *pTarget; + + pTarget = m_pConnectorTargets->first(); + node = e.firstChild(); + while( !node.isNull() && pTarget) + { + nodeName = node.nodeName(); + ele = node.toElement(); + + if( nodeName == "KivioConnectorTarget" ) + { + pTarget->loadXML( ele ); + } + + pTarget = m_pConnectorTargets->next(); + node = node.nextSibling(); + } +} + + +QDomElement KivioPyStencil::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioPyStencil"); + + XmlWriteString( e, "id", m_pSpawner->info()->id() ); + XmlWriteString( e, "setId", m_pSpawner->set()->id() ); + + + QDomElement dE = doc.createElement("PyData"); + + // The python variables + PyObject* mainmod = PyImport_AddModule("__main__"); + PyObject* gdic = PyModule_GetDict(mainmod); + PyObject *ldic = Py_BuildValue("{s:O,s:{}}", "ldic", vars ,"res"); + + char *dump_code = "import copy\n"\ + "import pickle\n"\ + "cres = {}\n"\ + "for key in ldic.keys():\n"\ + " try:\n"\ + " cres[key] = copy.deepcopy(ldic[key])\n"\ + " except:\n"\ + " ii=0\n"\ + "res = pickle.dumps(cres)\n"; + + if ( !PyRun_String(dump_code, Py_file_input, gdic, ldic) ) + PyErr_Print(); + + QString sVars = PyString_AsString( PyDict_GetItemString( ldic, "res") ); + + XmlWriteString( dE, "vars", sVars ); + XmlWriteString( dE, "resizeCode", resizeCode ); + + e.appendChild( dE ); + + + // Save the target list + QDomElement clE = doc.createElement("KivioConnectorTargetList"); + QDomElement targetE; + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + targetE = pTarget->saveXML( doc ); + clE.appendChild( targetE ); + + pTarget = m_pConnectorTargets->next(); + } + e.appendChild( clE ); + + return e; + +} + +void KivioPyStencil::updateGeometry() +{ + + //rescale items : + + rescaleShapes(vars); + + old_x = m_x; + old_y = m_y; + old_w = m_w; + old_h = m_h; + + if ( !resizeCode.isEmpty() ) + runPython(resizeCode); + + // stuff from KivioSMLStensil + + KivioConnectorTarget *pTarget, *pOriginal; + + QPtrList<KivioConnectorTarget> *pOriginalTargets = ((KivioPyStencilSpawner*)m_pSpawner)->targets(); + + pTarget = m_pConnectorTargets->first(); + pOriginal = pOriginalTargets->first(); + + PyObject *targets = PyDict_GetItemString(vars,"connector_targets"); + int size = PyList_Size( targets ); + int i=0; + + while( pTarget && pOriginal && i<size ) + { + PyObject *target = PyList_GetItem( targets, i ); + double x = getDoubleFromDict( target,"x"); + double y = getDoubleFromDict( target,"y"); + + pTarget ->setPosition( x, y ); + pOriginal->setPosition( x, y ); + + pTarget = m_pConnectorTargets->next(); + pOriginal = pOriginalTargets->next(); + i++; + } + +} + +void KivioPyStencil::rescaleShapes( PyObject *o ) +{ + if ( PyDict_Check(o) ) { + + PyObject *o_x = PyDict_GetItemString(o,"x"); + if ( o_x ) { + double x = getDoubleFromDict(o,"x"); + x = m_x+(x-old_x)*m_w/old_w; + PyDict_SetItemString( o, "x", Py_BuildValue( "d", x ) ); + } + + PyObject *o_y = PyDict_GetItemString(o,"y"); + if ( o_y ) { + double y = getDoubleFromDict(o,"y"); + y = m_y+(y-old_y)*m_h/old_h; + PyDict_SetItemString( o, "y", Py_BuildValue( "d", y ) ); + } + + PyObject *o_x2 = PyDict_GetItemString(o,"x2"); + if ( o_x2 ) { + double x = getDoubleFromDict(o,"x2"); + x = m_x+(x-old_x)*m_w/old_w; + PyDict_SetItemString( o, "x2", Py_BuildValue( "d", x ) ); + } + + //PyObject *o_y2 = PyDict_GetItemString(o,"y2"); + if ( o_y ) { + double y = getDoubleFromDict(o,"y2"); + y = m_y+(y-old_y)*m_h/old_h; + PyDict_SetItemString( o, "y2", Py_BuildValue( "d", y ) ); + } + + PyObject *o_w = PyDict_GetItemString(o,"w"); + if ( o_w ) { + double w = getDoubleFromDict(o,"w"); + w = w*m_w/old_w; + PyDict_SetItemString( o, "w", Py_BuildValue( "d", w ) ); + } + + PyObject *o_h = PyDict_GetItemString(o,"h"); + if ( o_h ) { + double h = getDoubleFromDict(o,"h"); + h = h*m_h/old_h; + PyDict_SetItemString( o, "h", Py_BuildValue( "d", h ) ); + } + + PyObject *childs = PyDict_Values( o ); + int size = PyList_Size( childs ); + for ( int i=0; i<size; i++ ) + rescaleShapes(PyList_GetItem(childs,i) ); + + } else + if ( PyList_Check(o) ) { + + int size = PyList_Size( o ); + for ( int i=0; i<size; i++ ) + rescaleShapes( PyList_GetItem(o,i) ); + } +} + +/** + * Duplicates this object. + * + * Duplicates all aspects of this object except for the + * stencil connected to the targets. + */ +KivioStencil *KivioPyStencil::duplicate() +{ + KivioPyStencil *pNewStencil = new KivioPyStencil(); + KivioStencil *pReturn; + + pNewStencil->m_x = m_x; + pNewStencil->m_y = m_y; + pNewStencil->m_w = m_w; + pNewStencil->m_h = m_h; + + pNewStencil->old_x = old_x; + pNewStencil->old_y = old_y; + pNewStencil->old_w = old_w; + pNewStencil->old_h = old_h; + + pNewStencil->m_pSpawner = m_pSpawner; + pNewStencil->resizeCode = resizeCode; + + //make deep copy of vars: + PyObject* mainmod = PyImport_AddModule("__main__"); + PyObject* gdic = PyModule_GetDict(mainmod); + PyObject *ldic = Py_BuildValue("{s:O,s:{}}", "ldic", vars ,"res"); + + char *copy_code = "import copy\n"\ + "for key in ldic.keys():\n"\ + " try:\n"\ + " res[key] = copy.deepcopy(ldic[key])\n"\ + " except:\n"\ + " i=0\n"; + if ( !PyRun_String(copy_code, Py_file_input, gdic, ldic) ) + PyErr_Print(); + + pNewStencil->vars = PyDict_GetItemString( ldic, "res"); + pNewStencil->runPython(kivio_module); + + // Copy the Connector Targets + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + while( pTarget ) + { + pNewStencil->m_pConnectorTargets->append( pTarget->duplicate() ); + pTarget = m_pConnectorTargets->next(); + } + + *(pNewStencil->protection()) = *m_pProtection; + *(pNewStencil->canProtect()) = *m_pCanProtect; + + pReturn = pNewStencil; + return pReturn; +} + + + +void KivioPyStencil::paint( KivioIntraStencilData *d ) +{ + paint(d,false); +} + +void KivioPyStencil::paintOutline( KivioIntraStencilData *d ) +{ + paint(d,true); +} + + +void KivioPyStencil::paint( KivioIntraStencilData *d, bool outlined ) +{ + KoZoomHandler* zoomHandler = d->zoomHandler; + + PyObject *shapes = PyDict_Values( PyDict_GetItemString( vars, "shapes" ) ); + + if ( !shapes ) { + return; + } + + int size = PyList_Size( shapes ); + + for ( int i=0; i<size; i++ ) { + PyObject *shape = PyList_GetItem( shapes, i ); + if ( !PyDict_Check(shape) ) + continue; + + int fill = KivioFillStyle::kcsNone; + + // if style dosn't defined for shape, applay default for stencil + setStyle( d, PyDict_GetItemString( vars, "style" ) , fill ); + setStyle( d, shape, fill ); + + if ( isSelected() ) + setStyle( d, PyDict_GetItemString( shape, "selected" ) , fill ); + + if ( outlined ) + fill = KivioFillStyle::kcsNone; + + QString stype = getStringFromDict( shape, "type" ); + stype = stype.lower(); + + double x = zoomHandler->zoomItX(getDoubleFromDict(shape,"x")); + double y = zoomHandler->zoomItY(getDoubleFromDict(shape,"y")); + double w = zoomHandler->zoomItX(getDoubleFromDict(shape,"w")); + double h = zoomHandler->zoomItY(getDoubleFromDict(shape,"h")); + //double x2 = zoomHandler->zoomItX(getDoubleFromDict(shape,"x2")); + //double y2 = zoomHandler->zoomItY(getDoubleFromDict(shape,"y2")); + + // get points list + QPtrList<KivioPoint> points; + points.setAutoDelete(true); + PyObject *pyPoints = PyDict_GetItemString( shape, "points" ); + if ( pyPoints && PyList_Check(pyPoints) ) { + int size = PyList_Size(pyPoints); + for ( int i=0; i<size; i++ ) { + PyObject *pyPoint = PyList_GetItem(pyPoints,i); + double x = zoomHandler->zoomItX(getDoubleFromDict(pyPoint,"x")); + double y = zoomHandler->zoomItY(getDoubleFromDict(pyPoint,"y")); + points.append( new KivioPoint( x, y, KivioPoint::kptNormal ) ); + } + } + + + if ( stype == "rectangle" ) { + if (fill) + d->painter->fillRect( x, y, w, h ); + else + d->painter->drawRect( x, y, w, h ); + } + + if ( stype == "textbox" ) { + int tf = vTextAlign() | hTextAlign(); + + QFont f = textFont(); + f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0)); + + d->painter->setFont( f ); + QString text = getStringFromDict(shape,"text"); + + if ( !text.isEmpty() ) { + d->painter->drawText( int( x ), int( y ), int( w ), int( h ), tf | Qt::WordBreak, text ); + } + } + + if ( stype == "arc" ) { + double a1 = getDoubleFromDict(shape,"a1"); + double a2 = getDoubleFromDict(shape,"a2"); + d->painter->drawArc(x,y,w,h,a1,a2); + } + + if ( stype == "roundrect" ) { + double rx = zoomHandler->zoomItX(getDoubleFromDict(shape,"rx")); + double ry = zoomHandler->zoomItY(getDoubleFromDict(shape,"ry")); + + if (fill) { + d->painter->fillRoundRect( x, y, w, h, rx, ry ); + } else { + d->painter->drawRoundRect( x, y, w, h, rx, ry ); + } + } + + if ( stype == "linearray" ) { + d->painter->drawLineArray(&points); + } + + if ( stype == "ellipse" ) { + if (fill) { + d->painter->fillEllipse( x, y, w, h ); + } else { + d->painter->drawEllipse( x, y, w, h ); + } + } + + if(stype == "polygon") { + d->painter->drawPolygon(&points); + } + + if(stype == "polyline") { + d->painter->drawPolyline(&points); + } + } + + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + while( pTarget ) + { + pTarget->paintOutline( d ); + pTarget = m_pConnectorTargets->next(); + } +} + + + +int KivioPyStencil::runPython(QString code) +{ + + view = dynamic_cast<KivioView*>(KoDocument::documentList()->first()->views().getFirst()); + if ( view ) { + page = view->activePage(); + } + + //const char *ccode = code.local8Bit().data(); + const char *ccode = code.latin1(); + + //kdDebug(43000) << "code to run:" << endl << ccode << endl; + + PyObject *v = PyRun_String( const_cast<char*>(ccode) , Py_file_input, globals, vars ); + + if (v == NULL) { + PyErr_Print(); + return 0; + } + + if (Py_FlushLine()) + PyErr_Clear(); + + Py_DECREF(v); + return 1; +} + + +double KivioPyStencil::getDoubleFromDict( PyObject *dict, const char *key ) +{ + if (!PyDict_Check(dict)) return 0.0; + + PyObject *val = PyDict_GetItemString(dict,const_cast<char*>(key)); + if ( val ) { + if ( PyFloat_Check(val) ) + return PyFloat_AsDouble( val ); + + if ( PyInt_Check(val) ) + return PyInt_AsLong( val ); + + if ( PyLong_Check(val) ) + return PyLong_AsDouble( val ); + } + return 0.0; +} + +QString KivioPyStencil::getStringFromDict( PyObject *dict, const char *key ) +{ + PyObject *val = PyDict_GetItemString(dict,const_cast<char*>(key)); + if ( val && PyString_Check(val) ) + return QString( PyString_AsString(val) ); + + return QString(""); +} + + +KivioCollisionType KivioPyStencil::checkForCollision( KoPoint *pPoint, double ) +{ + double px = pPoint->x(); + double py = pPoint->y(); + + if( !(px < m_x + m_w && + px >= m_x && + py < m_y + m_h && + py >= m_y ) ) + { + return kctNone; + } + + return kctBody; + +} + + +/** + * Return a set of bits representing what resize handles are available. + */ +int KivioPyStencil::resizeHandlePositions() +{ + // Calculate the resize handle positions + int mask = KIVIO_RESIZE_HANDLE_POSITION_ALL; + + if( m_pProtection->at( kpWidth ) ) + { + mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpE | krhpW); + } + + if( m_pProtection->at( kpHeight) ) + { + mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpN | krhpS); + } + + return mask; +} + + +/** + * Paints the connector targets of this stencil. + */ +void KivioPyStencil::paintConnectorTargets( KivioIntraStencilData *pData ) +{ + QPixmap targetPic; + KivioPainter *painter; + double x, y; + + // We don't draw these if we are selected!!! + if( isSelected() ) + return; + + // Obtain the graphic used for KivioConnectorTargets + targetPic = Kivio::connectorTargetPixmap(); + + + KoZoomHandler* zoomHandler = pData->zoomHandler; + painter = pData->painter; + + KivioConnectorTarget *pTarget; + pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + x = zoomHandler->zoomItX(pTarget->x()); + y = zoomHandler->zoomItY(pTarget->y()); + + painter->drawPixmap( x-3, y-3, targetPic ); + + pTarget = m_pConnectorTargets->next(); + } +} + +/** + * Attempts to connect a KivioConnectorPoint to this stencil. + * + * This function will attempt to locate a KivioConnectorTarget in this + * stencil with-in a given threshold. If it finds it, it will connect + * the point to it, and return the target of the connection. + */ +KivioConnectorTarget *KivioPyStencil::connectToTarget( KivioConnectorPoint *p, double threshHold ) +{ + double px = p->x(); + double py = p->y(); + + double tx, ty; + + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + tx = pTarget->x(); + ty = pTarget->y(); + + + if( px >= tx - threshHold && + px <= tx + threshHold && + py >= ty - threshHold && + py <= ty + threshHold ) + { + // setTarget calls pTarget->addConnectorPoint() and removes + // any previous connections from p + p->setTarget( pTarget ); + return pTarget; + } + + pTarget = m_pConnectorTargets->next(); + } + + return NULL; +} + +KivioConnectorTarget *KivioPyStencil::connectToTarget( KivioConnectorPoint *p, int /*targetID*/ ) +{ + int id = p->targetId(); + + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + if( pTarget->id() == id ) + { + p->setTarget(pTarget); + + return pTarget; + } + + pTarget = m_pConnectorTargets->next(); + } + + return NULL; +} + +int KivioPyStencil::generateIds( int nextAvailable ) +{ + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + // Iterate through all the targets + while( pTarget ) + { + // If this target has something connected to it + if( pTarget->hasConnections() ) + { + // Set it's id to the next available id + pTarget->setId( nextAvailable ); + + // Increment the next available id + nextAvailable++; + } + else + { + // Otherwise mark it as unused (-1) + pTarget->setId( -1 ); + } + + pTarget = m_pConnectorTargets->next(); + } + + // Return the next availabe id + return nextAvailable; +} + +void KivioPyStencil::setStyle( KivioIntraStencilData *d, PyObject *s, int &fillStyle ) +{ + if ( !s ) + return; + + if ( !PyDict_Check(s) ) + return; + + KivioPainter *p = d->painter; + KoZoomHandler* zoomHandler = d->zoomHandler; + + PyObject *color = PyDict_GetItemString(s,"color"); + + if ( color ) { + QColor c = readColor(color); + + if ( c.isValid() ) { + p->setFGColor(c); + } + } + + color = PyDict_GetItemString(s,"bgcolor"); + + if ( color ) { + QColor c = readColor(color); + + if ( c.isValid() ) { + p->setBGColor(c); + } + } + + color = PyDict_GetItemString(s,"textcolor"); + + if ( color ) { + QColor c = readColor(color); + + if ( c.isValid() ) { + p->setTextColor(c); + } + } + + PyObject *lineWidth = PyDict_GetItemString(s,"linewidth"); + + if ( lineWidth ) { + double lw = getDoubleFromDict(s,"linewidth"); + p->setLineWidth( zoomHandler->zoomItY(lw) ); + } + + PyObject *o_fillStyle = PyDict_GetItemString(s,"fillstyle"); + + if ( o_fillStyle ) { + QString sfill = getStringFromDict(s,"fillstyle"); + + if ( sfill == "solid" ) { + fillStyle = KivioFillStyle::kcsSolid; + } + + if ( sfill == "none" ) { + fillStyle = KivioFillStyle::kcsNone; + } + } + + QString sfont = getStringFromDict(s,"font"); + QFont f; + int fontSize = (int)getDoubleFromDict(s,"fontsize"); + + if(!fontSize) { + fontSize = 12; // FIXME: Should use some kind of global setting!!! + } + + f.setPointSize(fontSize); + f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0)); + + if ( !sfont.isEmpty() ) { + f.setFamily(sfont); + } else { + f.setFamily("times"); // FIXME: Should use some kind of global setting!!! + } + + p->setFont(f); +} + +QColor KivioPyStencil::readColor( PyObject *color ) +{ + if ( !color ) + return QColor(); + + if ( PyString_Check(color) ) { + return QColor( PyString_AsString(color) ); + } + + if ( PyList_Check(color) ) { + if ( PyList_Size(color) == 3 ) { + PyObject *ro = PyList_GetItem(color,0); + PyObject *go = PyList_GetItem(color,1); + PyObject *bo = PyList_GetItem(color,2); + + int r=0, g=0, b=0; + if ( PyNumber_Check(ro) ) + r = PyInt_AsLong( PyNumber_Int(ro)); + if ( PyNumber_Check(go) ) + g = PyInt_AsLong( PyNumber_Int(go)); + if ( PyNumber_Check(bo) ) + b = PyInt_AsLong( PyNumber_Int(bo)); + + return QColor(r,g,b); + + } + } + + return QColor(); + +} + +void KivioPyStencil::PyDebug( PyObject * o ) +{ + kdDebug(43000) << "py_debug: " << PyString_AsString(PyObject_Str(o)) << endl; +} + + +QColor KivioPyStencil::fgColor() +{ + QColor color = readColor( PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "color" ) ); + if ( color.isValid() ) + return color; + else + return QColor(0,0,0); +} + +void KivioPyStencil::setFGColor( QColor c ) +{ + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "color" , Py_BuildValue("[i,i,i]", c.red(), c.green(), c.blue() ) ) ; +} + + +QColor KivioPyStencil::bgColor() +{ + QColor color = readColor( PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "bgcolor" ) ); + if ( color.isValid() ) + return color; + else + return QColor(0,0,0); +} + +void KivioPyStencil::setBGColor( QColor c ) +{ + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "bgcolor" , Py_BuildValue("[i,i,i]", c.red(), c.green(), c.blue() ) ) ; +} + + +QColor KivioPyStencil::textColor() +{ + QColor color = readColor( PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "textcolor" ) ); + if ( color.isValid() ) + return color; + else + return QColor(0,0,0); +} + +void KivioPyStencil::setTextColor( QColor c ) +{ + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "textcolor" , Py_BuildValue("[i,i,i]", c.red(), c.green(), c.blue() ) ) ; +} + + +double KivioPyStencil::lineWidth() +{ + PyObject *lw = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "linewidth" ); + if ( lw ) + if ( PyNumber_Check(lw) ) + return ( PyInt_AsLong( PyNumber_Int(lw)) ); + return 1.0; +} + +void KivioPyStencil::setLineWidth( double w ) +{ + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "linewidth" , Py_BuildValue("f",w ) ) ; +} + + +void KivioPyStencil::setText( const QString &s ) +{ + PyObject *to = PyDict_GetItemString( PyDict_GetItemString(vars,"shapes"), "text" ); + if ( to ) + PyDict_SetItemString(to, "text", Py_BuildValue("s", s.latin1() )); +} + + +QString KivioPyStencil::text() +{ + PyObject *to = PyDict_GetItemString( PyDict_GetItemString(vars,"shapes"), "text" ); + if ( to ) { + return getStringFromDict(to, "text"); + } + return QString(""); +} + +void KivioPyStencil::setTextFont( const QFont &f ) +{ + double fs = f.pointSizeFloat(); + QString family = f.family(); + + int bold = f.bold(); + int italic = f.italic(); + int underline= f.underline(); + + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "fontsize" , Py_BuildValue("f",fs ) ) ; + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "font" , Py_BuildValue("s",family.latin1() ) ) ; + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "bold" , Py_BuildValue("i",bold ) ) ; + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "italic" , Py_BuildValue("i",italic ) ) ; + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "underline" , Py_BuildValue("i",underline ) ) ; +} + +QFont KivioPyStencil::textFont() +{ + PyObject *fn = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "font" ); + PyObject *fs = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "fontsize" ); + PyObject *bd = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "bold" ); + PyObject *it = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "italic" ); + PyObject *ul = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "underline" ); + + QFont f; + + if ( fs ) + if ( PyNumber_Check(fs)) + f.setPointSize( PyInt_AsLong( PyNumber_Int(fs))); + + if ( bd ) + if ( PyNumber_Check(bd)) + f.setBold( PyInt_AsLong( PyNumber_Int(bd))); + + if ( it ) + if ( PyNumber_Check(it)) + f.setItalic( PyInt_AsLong( PyNumber_Int(it))); + + if ( ul ) + if ( PyNumber_Check(ul)) + f.setUnderline( PyInt_AsLong( PyNumber_Int(ul))); + + if ( fn ) + if ( PyString_Check(fn)) + f.setFamily( PyString_AsString(fn)); + + return f; +} + +int KivioPyStencil::hTextAlign() +{ + PyObject *hta = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "htextalign" ); + + if ( hta ) + if ( PyNumber_Check(hta) ) + return ( PyInt_AsLong( PyNumber_Int(hta))); + + return Qt::AlignHCenter; +} + +int KivioPyStencil::vTextAlign() +{ + PyObject *vta = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "vtextalign" ); + + if ( vta ) + if ( PyNumber_Check(vta) ) + return ( PyInt_AsLong( PyNumber_Int(vta))); + + return Qt::AlignVCenter; +} + +void KivioPyStencil::setHTextAlign(int hta) +{ + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "htextalign" , Py_BuildValue("i",hta)); +} + +void KivioPyStencil::setVTextAlign(int vta) +{ + PyDict_SetItemString( PyDict_GetItemString(vars,"style") , "vtextalign" , Py_BuildValue("i",vta)); +} + +#endif // HAVE_PYTHON + diff --git a/kivio/kiviopart/kiviosdk/kivio_py_stencil.h b/kivio/kiviopart/kiviosdk/kivio_py_stencil.h new file mode 100644 index 000000000..0ee18a5c3 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_py_stencil.h @@ -0,0 +1,135 @@ +/* + * 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 KIVIO_PY_STENCIL_H +#define KIVIO_PY_STENCIL_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "kivio_stencil.h" + +#ifdef HAVE_PYTHON + +#include <qptrlist.h> +#include <qcolor.h> +#include <qfont.h> + +/* slots gets defined in Qt 3.2 and conflicts with python 2.3 headers */ +#undef slots +#include <Python.h> +#define slots + +class KivioPyStencilSpawner; +class KivioPainter; +class KivioFillStyle; +class KivioView; + +class KivioPyStencil : public KivioStencil +{ + +friend class KivioPyStencilSpawner; + +public: + KivioPyStencil(); + virtual ~KivioPyStencil(); + + + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + virtual void loadConnectorTargetListXML( const QDomElement & ); + + virtual void updateGeometry(); + virtual KivioStencil *duplicate(); + virtual KivioCollisionType checkForCollision( KoPoint *pPoint, double ); + virtual int resizeHandlePositions(); + + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paint( KivioIntraStencilData * , bool outlined); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *p, double threshHold ); + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *p, int targetID ); + + virtual int generateIds( int ); + + virtual QColor fgColor(); + virtual void setFGColor( QColor ); + + virtual void setBGColor( QColor ); + virtual QColor bgColor(); + + virtual void setLineWidth( double ); + virtual double lineWidth(); + + // FOnt stuff + virtual QColor textColor(); + virtual void setTextColor( QColor ); + + virtual QFont textFont(); + virtual void setTextFont( const QFont & ); + + virtual int hTextAlign(); + virtual int vTextAlign(); + + virtual void setHTextAlign(int); + virtual void setVTextAlign(int); + + virtual void setText( const QString & ); + virtual QString text(); + + +protected: + PyObject *vars, *globals; + QString resizeCode; // python code to be runed when resize + double old_x, old_y, old_w, old_h; + + virtual void rescaleShapes( PyObject * ); // find recursive for x,y,w,h in object( dict or list ) and update them + + /** + * set style settings from dict, return tru if need to use fill... methods or false if draw... + */ + virtual void setStyle( KivioIntraStencilData *d, PyObject *style, int &fillStyle ); + QColor readColor( PyObject *color ); // used by setStyle + + + QPtrList<KivioConnectorTarget> *m_pConnectorTargets; + + /** + * init stencil using initCode, return 1, if ok, or 0 if was some error ( maybe python syntax error ) + */ + int init( QString initCode); + + int runPython(QString code); + double getDoubleFromDict( PyObject *dict, const char* key ); + QString getStringFromDict( PyObject *dict, const char* key ); + + void PyDebug( PyObject * ); // show var +}; + +#else // HAVE_PYTHON + + #define KivioPyStencil KivioStencil + +#endif // HAVE_PYTHON + + +#endif // KIVIO_PY_STENCIL_H + diff --git a/kivio/kiviopart/kiviosdk/kivio_py_stencil_spawner.cpp b/kivio/kiviopart/kiviosdk/kivio_py_stencil_spawner.cpp new file mode 100644 index 000000000..e8713917a --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_py_stencil_spawner.cpp @@ -0,0 +1,172 @@ +/* + * 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 "kivio_py_stencil_spawner.h" + +#ifdef HAVE_PYTHON + +#include "kivio_common.h" +#include "kivio_connector_target.h" +#include "kivio_py_stencil.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" + +#include <iostream> +#include <qdom.h> +#include <qfile.h> +#include <qiodevice.h> +#include <qpainter.h> +#include <qpoint.h> +#include <qpixmap.h> +#include <qrect.h> +#include <qfileinfo.h> + +#include <kdebug.h> + +KivioPyStencilSpawner::KivioPyStencilSpawner( KivioStencilSpawnerSet *p ) + : KivioStencilSpawner( p ), + m_pStencil(NULL) +{ + m_pStencil = new KivioPyStencil(); + m_pStencil->setSpawner(this); + + m_pTargets = new QPtrList<KivioConnectorTarget>; + m_pTargets->setAutoDelete(true); +} + +KivioPyStencilSpawner::~KivioPyStencilSpawner() +{ + if( m_pStencil ) + { + delete m_pStencil; + m_pStencil = NULL; + } + + if( m_pTargets ) + { + delete m_pTargets; + m_pTargets = NULL; + } + + kdDebug(43000) << "* PyStencilSpawner "<< m_pInfo->id() << " deleted" << endl; +} + +QDomElement KivioPyStencilSpawner::saveXML( QDomDocument &doc ) +{ + QDomElement spawnE = doc.createElement("KivioPyStencilSpawner"); + + XmlWriteString( spawnE, "id", m_pInfo->id() ); + + return spawnE; +} + +bool KivioPyStencilSpawner::load( const QString &file ) +{ + KivioConnectorTarget *pTarget; + QDomDocument d("test"); + + m_filename = QString(file); + QFile f(file); + + if( f.open( IO_ReadOnly )==false ) + { + kdDebug(43000) << "KivioPyStencilSpawner::load() - Error opening stencil: " << file << endl; + return false; + } + + d.setContent(&f); + + QDomElement root = d.documentElement(); + QDomElement e; + QDomNode node = root.firstChild(); + QString nodeName; + + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + if( nodeName.compare("KivioPyStencilSpawnerInfo")==0 ) + { + m_pInfo->loadXML( (const QDomElement)node.toElement() ); + } + else if( nodeName.compare("init")==0 ) + { + m_pStencil->setSpawner(this); + if ( ! m_pStencil->init( node.toElement().text() ) ) { + return false; + } + // init connector targets list + PyObject *targets = PyDict_GetItemString(m_pStencil->vars,"connector_targets"); + int size = PyList_Size( targets ); + for ( int i=0; i<size; i++ ) { + + PyObject *target = PyList_GetItem( targets, i ); + float x = m_pStencil->getDoubleFromDict( target,"x"); + float y = m_pStencil->getDoubleFromDict( target,"y"); + pTarget = new KivioConnectorTarget(x,y); + m_pStencil->m_pConnectorTargets->append( pTarget ); + m_pTargets->append(pTarget->duplicate()); + } + m_defWidth = m_pStencil->getDoubleFromDict( m_pStencil->vars, "w"); + m_defHeight = m_pStencil->getDoubleFromDict( m_pStencil->vars, "h"); + + } + + else if( nodeName.compare("resize")==0 ) + { + e = node.toElement(); + m_pStencil->resizeCode = node.toElement().text(); + } + else + { + kdDebug(43000) << "KivioPyStencilSpawner::load() - Unknown node " << nodeName << " while loading " << file << endl; + } + + node = node.nextSibling(); + } + + // Now load the xpm + QFileInfo finfo(file); + QString pixFile = finfo.dirPath(true) + "/" + finfo.baseName() + ".xpm"; + + if(!m_icon.load( pixFile )) { + QString pixFile = finfo.dirPath(true) + "/" + finfo.baseName() + ".png"; + m_icon.load( pixFile ); + } + + f.close(); + + return true; +} + + + +/** + * Returns a new stencil, with default width/height of the spawner settings. +*/ +KivioStencil *KivioPyStencilSpawner::newStencil() +{ + + KivioStencil *pNewStencil = m_pStencil->duplicate(); + + return pNewStencil; +} + +#endif // HAVE_PYTHON diff --git a/kivio/kiviopart/kiviosdk/kivio_py_stencil_spawner.h b/kivio/kiviopart/kiviosdk/kivio_py_stencil_spawner.h new file mode 100644 index 000000000..75b4dcb2a --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_py_stencil_spawner.h @@ -0,0 +1,77 @@ +/* + * 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 KIVIO_PY_STENCIL_SPAWNER_H +#define KIVIO_PY_STENCIL_SPAWNER_H + +#include <qdom.h> +#include <qptrlist.h> +#include <qstring.h> + +#include "kivio_stencil_spawner.h" +#include <config.h> + +#ifdef HAVE_PYTHON + +class KivioStencilSpawnerSet; +class KivioStencil; +class KivioPyStencil; +class KivioConnectorTarget; +class QPainter; +class QPixmap; +class QRect; + +class KivioPyStencilSpawner : public KivioStencilSpawner +{ +protected: + KivioPyStencil *m_pStencil; + QString m_filename; + + // Target list + QPtrList<KivioConnectorTarget>*m_pTargets; + +protected: + void loadShape( QDomNode & ); + QString readDesc( const QString & ); + +public: + KivioPyStencilSpawner( KivioStencilSpawnerSet * ); + virtual ~KivioPyStencilSpawner(); + + virtual bool load( const QString & ); + + virtual QDomElement saveXML( QDomDocument & ); + + virtual QString &filename() { return m_filename; } + + virtual KivioStencil *newStencil(); + + QPtrList <KivioConnectorTarget> *targets() { return m_pTargets; } +}; + +#else // HAVE_PYTHON + + #define KivioPyStencilSpawner KivioStencilSpawner + +#endif // HAVE_PYTHON + + +#endif + + + diff --git a/kivio/kiviopart/kiviosdk/kivio_screen_painter.cpp b/kivio/kiviopart/kiviosdk/kivio_screen_painter.cpp new file mode 100644 index 000000000..0e1beb3ee --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_screen_painter.cpp @@ -0,0 +1,980 @@ +/* + * 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 "kivioglobal.h" +#include "kivio_line_style.h" +#include "kivio_point.h" +#include "kivio_screen_painter.h" + +#include <qimage.h> +#include <qpen.h> +#include <qbrush.h> +#include <qsimplerichtext.h> +#include <qpalette.h> + +#include <kdebug.h> + +#define PAINTER_CHECK() { if(!m_pPainter) { kdDebug(43000) << "KivioScreenPainter::PAINTER_CHECK() - no QPainter exists." << endl; } } + + +KivioScreenPainter::KivioScreenPainter() + : m_pPainter(NULL) +{ + m_transX = 0.0f; + m_transY = 0.0f; + m_rotation = 0; +} + +KivioScreenPainter::KivioScreenPainter(QPainter* painter) + : m_pPainter(painter) +{ + m_transX = 0.0f; + m_transY = 0.0f; + m_rotation = 0; +} + +KivioScreenPainter::~KivioScreenPainter() +{ + if( m_pPainter ) + { + kdDebug(43000) << "KivioScreenPainter::~KivioScreenPainter - A QPainter slipped through the cracks" << endl; + delete m_pPainter; + m_pPainter = NULL; + } +} + +/** + * Starts the drawing on a @ref QPaintDevice + * + * @param dev The device to paint on + * + * Call this function before you call any other @ref KivioScreenPainter + * functions. This will create an internal QPainter object for drawing + * with. If you fail to call this function, nothing will work. + */ +bool KivioScreenPainter::start( QPaintDevice *dev ) +{ + // Bomb out if one exists already + if( m_pPainter ) + { + kdDebug(43000) << "KivioScreenPainter::start() - A QPainter already exists" << endl; + return false; + } + + // Allocate a new drawing thingy + m_pPainter = new QPainter(dev); + + return true; +} + + +/** + * Stops the drawing and flushes the drawing pipeline + * + * After using the @ref KivioScreenPainter object, call stop() to + * finalize it all. + */ +bool KivioScreenPainter::stop() +{ + // Bomb out if we don't have a painter. This means that they never + // called @ref start(). + if( !m_pPainter ) + { + kdDebug(43000) <<"KivioScreenPainter::stop() called without previous call to start" << endl; + return false; + } + + // Otherwise delete and nullify the pointer + delete m_pPainter; + m_pPainter = NULL; + + return true; +} + + + +/** + * Draws a line from one point to another + * + * @param x1 The first x coord + * @param y1 The first y coord + * @param x2 The second x coord + * @param y2 The second y coord + * + * This function will draw a line from one point to another in + * the current fgColor and using the current lineWidth. + */ +void KivioScreenPainter::drawLine( float x1, float y1, float x2, float y2 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + + m_pPainter->drawLine( int(x1), int(y1), int(x2), int(y2) ); + +} + + +/** + * Draws an arc + * + * @param x1 The x-coord of the arc-box + * @param y1 The y-coord of the arc-box + * @param w1 The width of the arc + * @param h1 The height of the arc + * @param a1 The starting angle of the arc ?? + * @param a2 The total angle of the arc??? + * + * This will draw an arc in the current fgColor and lineWidth. + */ +void KivioScreenPainter::drawArc( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + + m_pPainter->drawArc( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); +} + + +/** + * Draws a single quad-bezier curve + * + * @param pArray The array of 4 points to draw + * + * This will draw a quad-bezier curve in the current fgColor + * and lineWidth. @ref pArray must have 4 points. + */ +void KivioScreenPainter::drawBezier( QPointArray &pArray ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + + m_pPainter->drawCubicBezier(pArray); +} + + +/** + * Draws a hollow rectangle + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + */ +void KivioScreenPainter::drawRect( float x1, float y1, float w1, float h1 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(QBrush::NoBrush); + m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) ); +} + + +/** + * Draws a filled/outlined rectangle + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * + * This draws a filled, and outlined rectangle in the current + * fgColor, lineWidth, and fillStyle. + */ +void KivioScreenPainter::fillRect( float x1, float y1, float w1, float h1 ) +{ + PAINTER_CHECK(); + + QBrush b; + b = m_pFillStyle->brush(); + + if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) { + QPixmap pix((int)w1, (int)h1); + QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(), + (KImageEffect::GradientType) m_pFillStyle->gradientType()); + pix.convertFromImage(image); + b.setPixmap(pix); + m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY)); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) ); + m_pPainter->setBrushOrigin(0, 0); +} + + +/** + * Draws a hollow round-rectangle + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * @param a1 ???? + * @param a2 ???? + * + * This draws a hollow round-rectangle in the current + * fgColor and lineWidth. + */ +void KivioScreenPainter::drawRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(QBrush::NoBrush); + m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); +} + + + +/** + * Draws a filled/outlined round-rectangle + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * @param a1 ???? + * @param a2 ???? + * + * This draws a hollow round-rectangle in the current + * fgColor, lineWidth, and fillStyle. + */ +void KivioScreenPainter::fillRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + QBrush b; + b = m_pFillStyle->brush(); + + if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) { + QPixmap pix((int)w1, (int)h1); + QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(), + (KImageEffect::GradientType) m_pFillStyle->gradientType()); + pix.convertFromImage(image); + b.setPixmap(pix); + m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY)); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); + m_pPainter->setBrushOrigin(0, 0); +} + + +/** + * Draws a hollow pie + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * @param a1 ???? + * @param a2 ???? + * + * This draws a hollow pie in the current + * fgColor and lineWidth. + */ +void KivioScreenPainter::drawPie( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(QBrush::NoBrush); + m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); +} + + +/** + * Draws a filled/outlined pie + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * @param a1 ???? + * @param a2 ???? + * + * This draws a filled/outlined pie in the current + * fgColor, lineWidth, and fillStyle. + */ +void KivioScreenPainter::fillPie( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + QBrush b; + b = m_pFillStyle->brush(); + + if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) { + QPixmap pix((int)w1, (int)h1); + QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(), + (KImageEffect::GradientType) m_pFillStyle->gradientType()); + pix.convertFromImage(image); + b.setPixmap(pix); + m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY)); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); + m_pPainter->setBrushOrigin(0, 0); +} + + +/** + * Draws a hollow chord + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * @param a1 ???? + * @param a2 ???? + * + * This draws a hollow chord in the current + * fgColor and lineWidth. + */ +void KivioScreenPainter::drawChord( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(QBrush::NoBrush); + m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); +} + + +/** + * Draws a filled/outlined chord + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * @param a1 ???? + * @param a2 ???? + * + * This draws a filled/outlined chord in the current + * fgColor, fillStyle and lineWidth. + */ +void KivioScreenPainter::fillChord( float x1, float y1, float w1, float h1, float a1, float a2 ) +{ + PAINTER_CHECK(); + + QBrush b; + b = m_pFillStyle->brush(); + + if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) { + QPixmap pix((int)w1, (int)h1); + QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), + m_pFillStyle->color2(), m_pFillStyle->gradientType()); + pix.convertFromImage(image); + b.setPixmap(pix); + m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY)); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) ); + m_pPainter->setBrushOrigin(0, 0); +} + + +/** + * Draws a hollow ellipse + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * + * This draws a hollow ellipse in the current + * fgColor and lineWidth. + */ +void KivioScreenPainter::drawEllipse( float x1, float y1, float w1, float h1 ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(QBrush::NoBrush); + m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) ); +} + + +/** + * Draws a filled/outlined ellipse + * + * @param x1 The x coord + * @param y1 The y coord + * @param w1 The width + * @param h1 The height + * + * This draws a filled/outlined ellipse in the current + * fgColor, fillstyle and lineWidth. + */ +void KivioScreenPainter::fillEllipse( float x1, float y1, float w1, float h1 ) +{ + PAINTER_CHECK(); + + QBrush b; + b = m_pFillStyle->brush(); + + if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) { + QPixmap pix((int)w1, (int)h1); + QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(), + (KImageEffect::GradientType) m_pFillStyle->gradientType()); + pix.convertFromImage(image); + b.setPixmap(pix); + m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY)); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) ); + m_pPainter->setBrushOrigin(0, 0); +} + + +/** + * Draws an array of lines + * + * @param pList The array of points to draw lines with + * + * The list of points should contain a list of points in + * pairs. Lines are drawn from p1->p2 p3->p4 p5->p6, etc... + */ +void KivioScreenPainter::drawLineArray( QPtrList<KivioPoint> *pList ) +{ + PAINTER_CHECK(); + + KivioPoint *pPoint; + QPointArray points(pList->count()); + int i; + QBrush b; + + b.setStyle( QBrush::NoBrush ); + + i=0; + pPoint = pList->first(); + while( pPoint ) + { + points.setPoint( i++, int(pPoint->x()), int(pPoint->y()) ); + + pPoint = pList->next(); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + + m_pPainter->drawLineSegments(points); +} + + +/** + * Draws a polyline + * + * @param pList The array of points to draw the polyline with + * + * Draws a polyline (hollow) from p1->p2->p3->pn + */ +void KivioScreenPainter::drawPolyline( QPtrList<KivioPoint> *pList ) +{ + PAINTER_CHECK(); + + KivioPoint *pPoint; + QPointArray points( pList->count() ); + int i = 0; + pPoint = pList->first(); + + while( pPoint ) + { + points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) ); + pPoint = pList->next(); + } + + drawPolyline(points); +} + + + +/** + * Draws a polygon + * + * @param pList The array of points to draw the polyline with + * + * Draws a filled (if set) polygon from p1->p2->p3->pn->p1 + */ +void KivioScreenPainter::drawPolygon( QPtrList<KivioPoint> *pList ) +{ + PAINTER_CHECK(); + + KivioPoint *pPoint; + QPointArray points( pList->count() ); + int i = 0; + pPoint = pList->first(); + + while( pPoint ) + { + points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) ); + pPoint = pList->next(); + } + + drawPolygon(points); +} + +void KivioScreenPainter::drawPolyline( QPointArray &pArray ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush( QBrush::NoBrush ); + + m_pPainter->drawPolyline( pArray, 0, pArray.size() ); +} + +void KivioScreenPainter::drawPolygon( QPointArray &pArray ) +{ + PAINTER_CHECK(); + + QBrush b; + b = m_pFillStyle->brush(); + + if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) { + int x1, y1, w1, h1; + x1 = pArray[0].x(); + y1 = pArray[0].y(); + w1 = h1 = 0; + + for(unsigned int i = 0; i < pArray.count(); i++) { + x1 = QMIN(x1, pArray[i].x()); + y1 = QMIN(y1, pArray[i].y()); + w1 = QMAX(w1, pArray[i].x()); + h1 = QMAX(h1, pArray[i].y()); + } + + w1 = w1 - x1; + h1 = h1 - y1; + + QPixmap pix(w1, h1); + QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(), + (KImageEffect::GradientType) m_pFillStyle->gradientType()); + pix.convertFromImage(image); + b.setPixmap(pix); + m_pPainter->setBrushOrigin(x1 + (int)m_transX, y1 + (int)m_transY); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(b); + + m_pPainter->drawPolygon( pArray, true ); + m_pPainter->setBrushOrigin(0, 0); +} + +void KivioScreenPainter::drawLineArray( QPointArray &pArray ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush(QBrush::NoBrush); + + m_pPainter->drawLineSegments(pArray); +} + + +/** + * Draws a filled path object + * + * @param pPoints The array of points to draw the polyline with + * + * Draws a filled (if set) curve with the points stored + * in pPoints. They can be made up of bezier, arc, and normal points. + */ +void KivioScreenPainter::drawClosedPath( QPtrList<KivioPoint> *pPoints ) +{ + PAINTER_CHECK(); + + QBrush brush; + + KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4; + QPtrList <KivioPoint> *pPointList = pPoints; + QPointArray controlPoints(4), bPoints(0), tmpPoints; + + int pointIndex=0; + pPoint = pPointList->first(); + while( pPoint ) + { + if( pPoint->pointType() == KivioPoint::kptNormal ) + { + bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) ); + pointIndex++; + } + else if( pPoint->pointType() == KivioPoint::kptBezier ) + { + pPoint2 = pPointList->next(); + pPoint3 = pPointList->next(); + pPoint4 = pPointList->next(); + + if( !pPoint2 || !pPoint3 || !pPoint4 ) + { + kdDebug(43000) << "drawClosedPath() - incorrect # of bezier points" << endl; + return; + } + + if( pPoint2->pointType() != KivioPoint::kptBezier || + pPoint3->pointType() != KivioPoint::kptBezier || + pPoint4->pointType() != KivioPoint::kptBezier ) + { + kdDebug(43000) << "drawClosedPath() - bezier curves must have 4 points" << endl; + return; + } + + controlPoints.setPoint( 0, qRound(pPoint->x()), qRound(pPoint->y()) ); + controlPoints.setPoint( 1, qRound(pPoint2->x()), qRound(pPoint2->y()) ); + controlPoints.setPoint( 2, qRound(pPoint3->x()), qRound(pPoint3->y()) ); + controlPoints.setPoint( 3, qRound(pPoint4->x()), qRound(pPoint4->y()) ); + + tmpPoints = controlPoints.cubicBezier(); + + for( int j=0; j<int(tmpPoints.size()); j++ ) + { + bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() ); + pointIndex++; + } + } // end pointtype==bezier + else if( pPoint->pointType() == KivioPoint::kptArc ) + { + pPoint2 = pPointList->next(); + pPoint3 = pPointList->next(); + + if( !pPoint2 || !pPoint3 ) + { + kdDebug(43000) << "drawClosedPath() - incorrect # of arc points" << endl; + return; + } + if( pPoint2->pointType() != KivioPoint::kptArc || + pPoint3->pointType() != KivioPoint::kptArc ) + { + kdDebug(43000) << "drawClosedPath() - Arc points must come in triplets" << endl; + return; + } + + tmpPoints.makeArc( qRound(pPoint->x()), qRound(pPoint->y()), qRound(pPoint2->x()), qRound(pPoint2->y()), + qRound(pPoint3->x()), qRound(pPoint3->y()) ); + + for( int j=0; j<int(tmpPoints.size()); j++ ) + { + bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y()); + pointIndex++; + } + } // end pointtype==arc + else + { + kdDebug(43000) << "drawClosedPath() - Unknown point type discovered. WOOO!!!" << endl; + } + + pPoint = pPointList->next(); + } + + // If we make it here, the list is built + switch( m_pFillStyle->colorStyle() ) + { + case KivioFillStyle::kcsNone: + // A hollow path? That's a polypath! + drawPolyline( bPoints ); + break; + + case KivioFillStyle::kcsSolid: + case KivioFillStyle::kcsGradient: + { + drawPolygon(bPoints); + break; + } + + default: + kdDebug(43000) << "drawClosedPath() - Unknown colors style" << endl; + break; + } +} + +void KivioScreenPainter::drawOpenPath( QPtrList<KivioPoint> *pPoints ) +{ + PAINTER_CHECK(); + + QBrush brush; + + KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4; + QPtrList <KivioPoint> *pPointList = pPoints; + QPointArray controlPoints(4), bPoints(0), tmpPoints; + + int pointIndex=0; + pPoint = pPointList->first(); + while( pPoint ) + { + if( pPoint->pointType() == KivioPoint::kptNormal ) + { + bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) ); + pointIndex++; + } + else if( pPoint->pointType() == KivioPoint::kptBezier ) + { + pPoint2 = pPointList->next(); + pPoint3 = pPointList->next(); + pPoint4 = pPointList->next(); + + if( !pPoint2 || !pPoint3 || !pPoint4 ) + { + kdDebug(43000) << "drawOpenPath() - incorrect # of bezier points" << endl; + return; + } + + if( pPoint2->pointType() != KivioPoint::kptBezier || + pPoint3->pointType() != KivioPoint::kptBezier || + pPoint4->pointType() != KivioPoint::kptBezier ) + { + kdDebug(43000) << "drawOpenPath() - bezier curves must have 4 points" << endl; + return; + } + + controlPoints.setPoint( 0, qRound(pPoint->x()), qRound(pPoint->y()) ); + controlPoints.setPoint( 1, qRound(pPoint2->x()), qRound(pPoint2->y()) ); + controlPoints.setPoint( 2, qRound(pPoint3->x()), qRound(pPoint3->y()) ); + controlPoints.setPoint( 3, qRound(pPoint4->x()), qRound(pPoint4->y()) ); + + tmpPoints = controlPoints.cubicBezier(); + + for( int j=0; j<int(tmpPoints.size()); j++ ) + { + bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() ); + pointIndex++; + } + } // end pointtype==bezier + else if( pPoint->pointType() == KivioPoint::kptArc ) + { + pPoint2 = pPointList->next(); + pPoint3 = pPointList->next(); + + if( !pPoint2 || !pPoint3 ) + { + kdDebug(43000) << "drawOpenPath() - incorrect # of arc points" << endl; + return; + } + if( pPoint2->pointType() != KivioPoint::kptArc || + pPoint3->pointType() != KivioPoint::kptArc ) + { + kdDebug(43000) << "drawOpenPath() - Arc points must come in triplets" << endl; + return; + } + + tmpPoints.makeArc( qRound(pPoint->x()), qRound(pPoint->y()), qRound(pPoint2->x()), qRound(pPoint2->y()), + qRound(pPoint3->x()), qRound(pPoint3->y()) ); + + for( int j=0; j<int(tmpPoints.size()); j++ ) + { + bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y()); + pointIndex++; + } + } // end pointtype==arc + else + { + kdDebug(43000) << "drawOpenPath() - Unknown point type discovered. WOOO!!!" << endl; + } + + pPoint = pPointList->next(); + } + + m_pPainter->setPen(m_pLineStyle->pen(1.0f)); + m_pPainter->setBrush( QBrush::NoBrush ); + + m_pPainter->drawPolyline( bPoints ); +} + +void KivioScreenPainter::setFont( const QFont &f ) +{ + PAINTER_CHECK(); + + m_pPainter->setFont( f ); +} + +void KivioScreenPainter::drawText( int x, int y, int w, int h, int tf, const QString &str ) +{ + PAINTER_CHECK(); + + m_pPainter->setPen( m_textColor ); + m_pPainter->drawText( x, y, w, h, tf, str ); +/* QSimpleRichText textArea(str, m_pPainter->font()); + textArea.setWidth(w); + QColorGroup cg; + cg.setColor(QColorGroup::Base, m_pFillStyle->color()); + cg.setColor(QColorGroup::Text, m_textColor); + QBrush b = m_pFillStyle->brush(); + textArea.draw(m_pPainter, x, y, QRect(0, 0, 0, 0), cg, &b);*/ +} + +QRect KivioScreenPainter::boundingRect( int x, int y, int w, int h, int tf, const QString &str ) +{ + PAINTER_CHECK(); + + return m_pPainter->boundingRect( x,y,w,h, tf, str ); +} + +void KivioScreenPainter::drawPixmap( float x, float y, const QPixmap &pix ) +{ + PAINTER_CHECK(); + m_pPainter->drawPixmap( (int)x, (int)y, pix ); +} + +void KivioScreenPainter::drawHandle( float x, float y, int flags ) +{ + PAINTER_CHECK(); + QColor fillColor, penColor; + QBrush b; + QPen p; + + const float HW = 6.0f; + const float HWP1 = HW+1.0f; + const float HWo2 = HW/2.0f; + + float x1, y1; + + // Is it a locked handle? + if( flags & cpfLock ) + { + x1 = x - 4; + y1 = y - 4; + + m_pPainter->drawPixmap( qRound(x1), qRound(y1), Kivio::lockPixmap() ); + return; + } + + if( flags & cpfConnected ) + { + fillColor = QColor(200,0,0); + } + else + { + fillColor = QColor(0,200,0); + } + + penColor.setRgb(0, 0, 0); + + b.setColor(fillColor); + b.setStyle(Qt::SolidPattern); + p.setColor(penColor); + m_pPainter->setPen(p); + m_pPainter->setBrush(b); + + + x1 = x - HWo2; + y1 = y - HWo2; + + // first fill it +// m_pPainter->fillRect( x1, y1, HWP1, HWP1, b ); + + if(flags & cpfEnd) { + m_pPainter->drawEllipse( qRound(x1), qRound(y1), qRound(HWP1), qRound(HWP1) ); + } else { + m_pPainter->drawRect( qRound(x1), qRound(y1), qRound(HWP1), qRound(HWP1) ); + } + + // Now put something in it if needed + if( flags & cpfConnectable ) + { + b.setColor(QColor(0,0,0)); + + m_pPainter->fillRect(qRound(x-1),qRound(y-1),3,3, b); + } +} + +void KivioScreenPainter::drawSelectionBox( const QRect& r ) +{ + PAINTER_CHECK(); + QPen p; + p.setColor(QColor(0,200,0)); + p.setStyle(Qt::DashLine); + m_pPainter->setBrush(Qt::NoBrush); + m_pPainter->setPen(p); + m_pPainter->drawRect(r); +} + +void KivioScreenPainter::saveState() +{ + PAINTER_CHECK(); + + m_pPainter->save(); +} + +void KivioScreenPainter::restoreState() +{ + PAINTER_CHECK(); + + m_pPainter->restore(); +} + +void KivioScreenPainter::setTranslation( float _x, float _y ) +{ + PAINTER_CHECK(); + + m_transX = _x; + m_transY = _y; + + m_pPainter->translate(_x, _y); +} + +void KivioScreenPainter::translateBy( float _x, float _y ) +{ + PAINTER_CHECK(); + + m_transX += _x; + m_transY += _y; + + m_pPainter->translate( m_transX, m_transY ); +} + +void KivioScreenPainter::setRotation( int _d ) +{ + PAINTER_CHECK(); + + m_rotation = _d; + + m_pPainter->rotate(_d); +} + +void KivioScreenPainter::rotateBy( int _d ) +{ + PAINTER_CHECK(); + + m_rotation += _d; + + m_pPainter->rotate(m_rotation); +} + +int KivioScreenPainter::rotation() +{ + return m_rotation; +} + +void KivioScreenPainter::setWorldMatrix(QWMatrix m, bool c) +{ + PAINTER_CHECK(); + m_pPainter->setWorldMatrix(m, c); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_screen_painter.h b/kivio/kiviopart/kiviosdk/kivio_screen_painter.h new file mode 100644 index 000000000..8d76061d7 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_screen_painter.h @@ -0,0 +1,111 @@ +/* + * 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 KIVIO_SCREEN_PAINTER_H +#define KIVIO_SCREEN_PAINTER_H + +#include "kivio_painter.h" + +#include <qfont.h> +#include <qpainter.h> +#include <qpixmap.h> + +class KivioPoint; + + +class KivioScreenPainter : public KivioPainter +{ +protected: + QPainter *m_pPainter; + float m_transX, m_transY; + int m_rotation; + +public: + KivioScreenPainter(); + KivioScreenPainter(QPainter* painter); + virtual ~KivioScreenPainter(); + + virtual bool start( QPaintDevice * ); + virtual bool stop(); + + QPainter *painter() { return m_pPainter; } + void setPainter(QPainter* p) { m_pPainter = p; } + + /*\ + |*| + |*| PRIMITIVE IMPLEMENTATIONS + |*| + |*| + \*/ + void drawLine( float, float, float, float ); + void drawArc( float, float, float, float, float, float ); + + void drawBezier( QPointArray & ); + + void drawRect( float, float, float, float ); + void fillRect( float, float, float, float ); + + void drawRoundRect( float, float, float, float, float, float ); + void fillRoundRect( float, float, float, float, float, float ); + + void drawPie( float, float, float, float, float, float ); + void fillPie( float, float, float, float, float, float ); + + void drawChord( float, float, float, float, float, float ); + void fillChord( float, float, float, float, float, float ); + + void drawEllipse( float, float, float, float ); + void fillEllipse( float, float, float, float ); + + void drawLineArray( QPtrList<KivioPoint> * ); + + + void drawPolyline( QPtrList<KivioPoint> * ); + void drawPolygon( QPtrList<KivioPoint> * ); + + void drawPolyline( QPointArray & ); + void drawPolygon( QPointArray & ); + void drawLineArray( QPointArray & ); + + void drawClosedPath( QPtrList<KivioPoint> * ); + void drawOpenPath( QPtrList<KivioPoint> * ); + + void setFont( const QFont & ); + void drawText( int x, int y, int w, int h, int tf, + const QString &str ); + virtual QRect boundingRect( int, int, int, int, int, const QString & ); + + void drawPixmap( float, float, const QPixmap & ); + + void drawHandle( float, float, int ); + virtual void drawSelectionBox( const QRect& ); + + virtual void saveState(); + virtual void restoreState(); + virtual void setTranslation(float, float); + virtual void translateBy(float, float); + virtual void setRotation(int); + virtual void rotateBy(int); + virtual int rotation(); + + virtual void setWorldMatrix(QWMatrix, bool); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_shape.cpp b/kivio/kiviopart/kiviosdk/kivio_shape.cpp new file mode 100644 index 000000000..da0234156 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_shape.cpp @@ -0,0 +1,664 @@ +/* + * 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 <kdebug.h> +#include "kivio_common.h" +#include "kivio_fill_style.h" +#include "kivio_line_style.h" +#include "kivio_point.h" +#include "kivio_shape.h" +#include "kivio_text_style.h" + +/** + * Default constructor + * + * Does nothing + */ +KivioShape::KivioShape() +{ +} + + +/** + * Copy constructor + * + * @param source The object to copy data from + * + * Copies all data from source + */ +KivioShape::KivioShape( const KivioShape &source ) +{ + source.m_shapeData.copyInto( &m_shapeData ); +} + + +/** + * Destructor + */ +KivioShape::~KivioShape() +{ +} + + +/** + * Copy all data into pTarget + * + * @param pTarget The target &ref KivioShape to copy into + * + * This will copy all data contained in this, into pTarget. + */ +void KivioShape::copyInto( KivioShape *pTarget ) const +{ + if( !pTarget ) + return; + + m_shapeData.copyInto( &(pTarget->m_shapeData) ); +} + + +/** + * Load this object from an XML element + * + * @param e The element to load from + * @returns true on success, false on failure. + */ +bool KivioShape::loadXML( const QDomElement &e ) +{ + QDomElement ele; + QDomNode node = e.firstChild(); + + QString name = XmlReadString( e, "name", "" ); + m_shapeData.setName( name ); + m_shapeData.setShapeType( (KivioShapeData::KivioShapeType)XmlReadInt( e, "shapeType", -1 )); + + if( m_shapeData.name().isEmpty() || + m_shapeData.shapeType() == -1 ) + { + kdWarning(43000) << "-LOAD KivioShape::loadXML() - Unknown shape or bad name read. Shape load aborted." << endl; + return false; + } + + while( !node.isNull() ) + { + QString nodeName = node.nodeName(); + ele = node.toElement(); + + if( nodeName == "KivioShapeData" ) + { + m_shapeData.loadXML( ele ); + } + + node = node.nextSibling(); + } + return true; +} + + +/** + * Save this object to an XML element + * + * @param doc The document to save to + * @returns QDomElement representing this object. + */ +QDomElement KivioShape::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioShape"); + + XmlWriteString( e, "name", m_shapeData.m_name ); + XmlWriteInt( e, "shapeType", m_shapeData.m_shapeType ); + + e.appendChild( m_shapeData.saveXML( doc ) ); + + return e; +} + + +/** + * Loads a shape of type arc + * + * @param e The element to load from + * @returns A newly allocated KivioShape, or NULL on error. + * + * FIXME: implement this + */ +KivioShape *KivioShape::loadShapeArc( const QDomElement & ) +{ + return NULL; +} + + +/** + * Loads a shape of type closed-path. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeClosedPath( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstClosedPath; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // The line array is made up of pairs of points + if( nodeName == "KivioPoint" ) + { + // Allocate a new point, load it, and store it in the list + pPoint = new KivioPoint(0.0f, 0.0f, KivioPoint::kptBezier); + pPoint->loadXML( node.toElement() ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = NULL; + } + else if( nodeName == "KivioFillStyle" ) + { + pShape->m_shapeData.m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type bezier + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeBezier( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstBezier; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // The line array is made up of pairs of points + if( nodeName == "KivioPoint" ) + { + // Allocate a new point, load it, and store it in the list + pPoint = new KivioPoint(0.0f, 0.0f, KivioPoint::kptBezier); + pPoint->loadXML( node.toElement() ); + if( pPoint->pointType() != KivioPoint::kptBezier ) + { + kdDebug(43000) << "KivioShape::loadShapeBezier() - Non-bezier point found. Aborting shape." << endl; + delete pPoint; + delete pShape; + return NULL; + } + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = NULL; + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + if( pShape->m_shapeData.m_pOriginalPointList->count() != 4 ) + { + kdDebug(43000) << "KivioShape::loadShapeBezier() - Wrong number of points loaded, should be 4, shape aborted" << endl; + delete pShape; + return NULL; + } + + return pShape; +} + + +/** + * Loads a shape of type ellipse. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeEllipse( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstEllipse; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + pShape->m_shapeData.m_position.set( XmlReadFloat( e, "x", 0.0f ), XmlReadFloat( e, "y", 0.0f ) ); + pShape->m_shapeData.m_dimensions.set( XmlReadFloat( e, "w", 0.0f ), XmlReadFloat( e, "h", 0.0f ) ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + if( nodeName == "KivioFillStyle" ) + { + pShape->m_shapeData.m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type line-array. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeLineArray( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + QDomElement lineElement; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstLineArray; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // The line array is made up of pairs of points + if( nodeName == "Line" ) + { + lineElement = node.toElement(); + + // Allocate a new point, load it, and store it in the list + pPoint = new KivioPoint( XmlReadFloat( lineElement, "x1", 0.0f ), XmlReadFloat( lineElement, "y1", 0.0f ) ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = new KivioPoint( XmlReadFloat( lineElement, "x2", 0.0f ), XmlReadFloat( lineElement, "y2", 0.0f ) ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = NULL; + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type open-path. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeOpenPath( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstOpenPath; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // The line array is made up of pairs of points + if( nodeName == "KivioPoint" ) + { + // Allocate a new point, load it, and store it in the list + pPoint = new KivioPoint(0.0f, 0.0f, KivioPoint::kptBezier); + pPoint->loadXML( node.toElement() ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = NULL; + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type pie. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + * + * FIXME: Implement this + */ +KivioShape *KivioShape::loadShapePie( const QDomElement & ) +{ + return NULL; +} + + +/** + * Loads a shape of type polygon. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapePolygon( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstPolygon; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // The polygon is made up of a series of points + if( nodeName == "KivioPoint" ) + { + // Allocate a new point, load it, and store it in the list + pPoint = new KivioPoint(); + pPoint->loadXML( node.toElement() ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = NULL; + } + else if( nodeName == "KivioFillStyle" ) + { + pShape->m_shapeData.m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type polyline. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapePolyline( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstPolyline; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // The polygon is made up of a series of points + if( nodeName == "KivioPoint" ) + { + // Allocate a new point, load it, and store it in the list + pPoint = new KivioPoint(); + pPoint->loadXML( node.toElement() ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + pPoint = NULL; + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type rectangle. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeRectangle( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstRectangle; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + pShape->m_shapeData.m_position.set( XmlReadFloat( e, "x", 0.0f ), XmlReadFloat( e, "y", 0.0f ) ); + pShape->m_shapeData.m_dimensions.set( XmlReadFloat( e, "w", 72.0f ), XmlReadFloat( e, "h", 72.0f ) ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // Read the fill style + if( nodeName == "KivioFillStyle" ) + { + pShape->m_shapeData.m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + + +/** + * Loads a shape of type round rectangle. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeRoundRectangle( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + KivioPoint *pPoint = NULL; + QDomNode node; + QString nodeName; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type, name, and lineWidth properties + pShape->m_shapeData.m_shapeType = KivioShapeData::kstRoundRectangle; + pShape->m_shapeData.m_name = XmlReadString( e, "name", "" ); + + pShape->m_shapeData.m_position.set( XmlReadFloat( e, "x", 0.0f ), XmlReadFloat( e, "y", 0.0f ) ); + pShape->m_shapeData.m_dimensions.set( XmlReadFloat( e, "w", 72.0f ), XmlReadFloat( e, "h", 72.0f ) ); + + // Read and store the radii of the curves + pPoint = new KivioPoint(0.0f, 0.0f); + pPoint->set( XmlReadFloat( e, "r1", 1.0f ), XmlReadFloat( e, "r2", 1.0f ) ); + pShape->m_shapeData.m_pOriginalPointList->append( pPoint ); + + // Iterate through the nodes loading the various items + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + // Read the fill style + if( nodeName == "KivioFillStyle" ) + { + pShape->m_shapeData.m_pFillStyle->loadXML( node.toElement() ); + } + else if( nodeName == "KivioLineStyle" ) + { + pShape->m_shapeData.m_pLineStyle->loadXML( node.toElement() ); + } + + node = node.nextSibling(); + } + + return pShape; +} + + +/** + * Loads a shape of type textbox. + * + * @param e The element to load from. + * @returns A newly allocated KivioShape, or NULL on error. + */ +KivioShape *KivioShape::loadShapeTextBox( const QDomElement &e ) +{ + KivioShape *pShape = NULL; + QDomNode node; + QString nodeName; + KivioTextStyle ts; + QString name; + + + // Create the new shape to load into + pShape = new KivioShape(); + + // Load the type and name + pShape->m_shapeData.setShapeType(KivioShapeData::kstTextBox); + pShape->m_shapeData.setName( XmlReadString( e, "name", "" ) ); + pShape->m_shapeData.setTextColor(XmlReadColor(e,"color",QColor(0,0,0))); + + pShape->m_shapeData.m_position.set( + XmlReadFloat( e, "x", 0.0f ), XmlReadFloat( e, "y", 0.0f ) ); + pShape->m_shapeData.m_dimensions.set( + XmlReadFloat( e, "w", 72.0f ), XmlReadFloat( e, "h", 72.0f ) ); + + // Now look for the KivioTextStyle + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + if( nodeName == "KivioTextStyle" ) + { + ts.loadXML( node.toElement() ); + pShape->m_shapeData.setTextStyle( &ts ); + } + + node = node.nextSibling(); + } +// QString text = XmlReadString( e, "text", "" ); +// pShape->m_shapeData.setText( text ); + + + return pShape; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_shape.h b/kivio/kiviopart/kiviosdk/kivio_shape.h new file mode 100644 index 000000000..6ade18e82 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_shape.h @@ -0,0 +1,62 @@ +/* + * 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 KIVIO_SHAPE_H +#define KIVIO_SHAPE_H + +#include "kivio_shape_data.h" +#include <qdom.h> + + +class KivioShape +{ +protected: + KivioShapeData m_shapeData; // The data inside this shape + +public: + KivioShape(); + KivioShape( const KivioShape & ); + + virtual ~KivioShape(); + + void copyInto( KivioShape * ) const; + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + KivioShapeData::KivioShapeType shapeType() { return m_shapeData.shapeType(); } + + KivioShapeData *shapeData() { return &m_shapeData; } + + static KivioShape *loadShapeArc( const QDomElement & ); + static KivioShape *loadShapeClosedPath( const QDomElement & ); + static KivioShape *loadShapeBezier( const QDomElement & ); + static KivioShape *loadShapeEllipse( const QDomElement & ); + static KivioShape *loadShapeLineArray( const QDomElement & ); + static KivioShape *loadShapeOpenPath( const QDomElement & ); + static KivioShape *loadShapePie( const QDomElement & ); + static KivioShape *loadShapePolygon( const QDomElement & ); + static KivioShape *loadShapePolyline( const QDomElement & ); + static KivioShape *loadShapeRectangle( const QDomElement & ); + static KivioShape *loadShapeRoundRectangle( const QDomElement & ); + static KivioShape *loadShapeTextBox( const QDomElement & ); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_shape_data.cpp b/kivio/kiviopart/kiviosdk/kivio_shape_data.cpp new file mode 100644 index 000000000..ed9748719 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_shape_data.cpp @@ -0,0 +1,563 @@ +/* + * 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 "kivio_common.h" +#include "kivio_fill_style.h" +#include "kivio_line_style.h" +#include "kivio_point.h" +#include "kivio_shape_data.h" +#include "kivio_text_style.h" + +#include <qpainter.h> +#include <kdebug.h> + +/* + * Struct for holding information about a shape type + */ +struct KivioShapeTypeInfo +{ + const char *name; + KivioShapeData::KivioShapeType type; +}; + +/* + * Array of shape info used for loading/saving. + */ +static const int numShapeInfo = 12; +static struct KivioShapeTypeInfo shapeInfo[] = { + { "Arc", KivioShapeData::kstArc }, + { "Pie", KivioShapeData::kstPie }, + { "LineArray", KivioShapeData::kstLineArray }, + { "Polyline", KivioShapeData::kstPolyline }, + { "Polygon", KivioShapeData::kstPolygon }, + { "Bezier", KivioShapeData::kstBezier }, + { "Rectangle", KivioShapeData::kstRectangle }, + { "RoundRectangle", KivioShapeData::kstRoundRectangle }, + { "Ellipse", KivioShapeData::kstEllipse }, + { "OpenPath", KivioShapeData::kstOpenPath }, + { "ClosedPath", KivioShapeData::kstClosedPath }, + { "TextBox", KivioShapeData::kstTextBox } +}; + + +/***************** + * FIXME + * + * Down the road, this will be phased out because of the KivioTextStyle + * class. But it's here for now to keep backwards compatibility with + * beta 2 -- even though noone should be using it for anything important!!! + ****************/ +KivioTextShapeData::KivioTextShapeData() +{ + m_text = ""; + m_textFont = QFont("Times"); + m_textColor = QColor(0,0,0); + m_isHtml = false; + m_hTextAlign = Qt::AlignHCenter; + m_vTextAlign = Qt::AlignVCenter; +} + + +KivioShapeData::KivioShapeData() + : m_pOriginalPointList(NULL), + m_pFillStyle(NULL) +{ + m_pOriginalPointList = new QPtrList<KivioPoint>; + m_pOriginalPointList->setAutoDelete(true); + + m_pFillStyle = new KivioFillStyle(); + m_pLineStyle = new KivioLineStyle(); +// m_fgColor = QColor( 0, 0, 0 ); + + m_shapeType = kstNone; + m_name = ""; +// m_lineWidth = 1.0f; + + m_pTextData = NULL; + + m_position.set( 0.0f, 0.0f ); + m_dimensions.set( 72.0f, 72.0f ); +} + +KivioShapeData::KivioShapeData( const KivioShapeData &source ) + : m_pOriginalPointList(NULL), + m_pFillStyle(NULL) +{ + // Allocate a new point list + KivioPoint *pPoint; + m_pOriginalPointList = new QPtrList<KivioPoint>; + m_pOriginalPointList->setAutoDelete(true); + + // Copy over the point list + pPoint = source.m_pOriginalPointList->first(); + while( pPoint ) + { + m_pOriginalPointList->append( new KivioPoint( *pPoint ) ); + pPoint = source.m_pOriginalPointList->next(); + } + + // Copy the fill/line styles + m_pFillStyle = new KivioFillStyle( *(source.m_pFillStyle) ); + m_pLineStyle = new KivioLineStyle( *(source.m_pLineStyle) ); + + // Copy the fg color + //m_fgColor = source.m_fgColor; + + // Copy the rest + m_shapeType = source.m_shapeType; + m_name = QString(source.m_name); + //m_lineWidth = source.m_lineWidth; + + // Copy the position and size + source.m_position.copyInto( &m_position ); + source.m_dimensions.copyInto( &m_dimensions ); + + // If this is a text shape, allocate a text data struct and copy the info + if( m_shapeType == kstTextBox ) + { + m_pTextData = new KivioTextStyle(); + + source.m_pTextData->copyInto( m_pTextData ); +/* + m_pTextData->m_text = ((KivioShapeData)source).text(); + m_pTextData->m_isHtml = ((KivioShapeData)source).isHtml(); + m_pTextData->m_hTextAlign = ((KivioShapeData)source).hTextAlign(); + m_pTextData->m_vTextAlign = ((KivioShapeData)source).vTextAlign(); + m_pTextData->m_textFont = ((KivioShapeData)source).textFont(); + m_pTextData->m_textColor = ((KivioShapeData)source).textColor(); +*/ + } + else + m_pTextData = NULL; + +} + + +KivioShapeData::~KivioShapeData() +{ + if( m_pOriginalPointList ) + { + delete m_pOriginalPointList; + m_pOriginalPointList = NULL; + } + + if( m_pFillStyle ) + { + delete m_pFillStyle; + m_pFillStyle = NULL; + } + + if( m_pLineStyle ) + { + delete m_pLineStyle; + m_pLineStyle = NULL; + } + + if( m_pTextData ) + { + delete m_pTextData; + m_pTextData = NULL; + } +} + + +void KivioShapeData::copyInto( KivioShapeData *pTarget ) const +{ + KivioPoint *pPoint; + + if( !pTarget ) + return; + + // Delete the old point list + if( pTarget->m_pOriginalPointList ) + { + delete pTarget->m_pOriginalPointList; + pTarget->m_pOriginalPointList = NULL; + } + + // Create a new point list and copy it over + pTarget->m_pOriginalPointList = new QPtrList<KivioPoint>; + pTarget->m_pOriginalPointList->setAutoDelete(true); + pPoint = m_pOriginalPointList->first(); + while( pPoint ) + { + pTarget->m_pOriginalPointList->append( new KivioPoint( *pPoint ) ); + pPoint = m_pOriginalPointList->next(); + } + + // Copy the fill/line styles + m_pFillStyle->copyInto( pTarget->m_pFillStyle ); + m_pLineStyle->copyInto( pTarget->m_pLineStyle ); + + // Copy the fg color + //pTarget->m_fgColor = m_fgColor; + + // Copy the rest + pTarget->m_shapeType = m_shapeType; + pTarget->m_name = QString(m_name); + //pTarget->m_lineWidth = m_lineWidth; + + m_position.copyInto( &(pTarget->m_position) ); + m_dimensions.copyInto( &(pTarget->m_dimensions) ); + + + // If this is a textbox, allocate & copy + if( m_shapeType == kstTextBox ) + { + if( !pTarget->m_pTextData ) + { + pTarget->m_pTextData = new KivioTextStyle(); + } + + if( m_pTextData ) + { + m_pTextData->copyInto( pTarget->m_pTextData ); + } + else + { + kdWarning(43000) << "KivioShapeData::copyInto() - Shape is of type text-box, but our text data doens't exist." << endl; + pTarget->m_pTextData->setText(""); + pTarget->m_pTextData->setIsHtml(false); + pTarget->m_pTextData->setHTextAlign(Qt::AlignHCenter); + pTarget->m_pTextData->setVTextAlign(Qt::AlignVCenter); + pTarget->m_pTextData->setFont( QFont("Times",12) ); + pTarget->m_pTextData->setColor( QColor(0,0,0) ); + } + } + else + { + if( pTarget->m_pTextData ) + { + delete pTarget->m_pTextData; + pTarget->m_pTextData = NULL; + } + } +} + + +/** + * Load this object from an XML element + * + */ +bool KivioShapeData::loadXML( const QDomElement &e ) +{ + QDomNode node; + QDomElement ele; + + // Maintain backwards compatibility with the eariler betas. They saved + // fg color and line style in this node. + m_pLineStyle->setColor( XmlReadColor( e, "fgColor", QColor(0,0,0) ) ); + m_pLineStyle->setWidth( XmlReadFloat( e, "lineWidth", 1.0f ) ); + + + node = e.firstChild(); + while( !node.isNull() ) + { + QString nodeName = node.nodeName(); + ele = node.toElement(); + + if( nodeName == "KivioLineStyle" ) + { + m_pLineStyle->loadXML( ele ); + } + else if( nodeName == "KivioFillStyle" ) + { + m_pFillStyle->loadXML( ele ); + } + else if( nodeName == "KivioTextStyle" ) + { + + // First make sure we are a text box + if( m_shapeType == kstTextBox ) + { + // If we don't have text data, allocate it + if( !m_pTextData ) + m_pTextData = new KivioTextStyle(); + + m_pTextData->loadXML( ele ); + + } // end if m_shapeType==kstTextBox + } + else if( nodeName == "KivioText" ) + { + // First make sure we are a text box + if( m_shapeType == kstTextBox ) + { + KivioTextShapeData *pData = new KivioTextShapeData; + + pData->m_text = XmlReadString( ele, "text", "" ); + pData->m_isHtml = (bool)XmlReadInt( ele, "isHtml", (int)false ); + + pData->m_hTextAlign = XmlReadInt( ele, "hTextAlign", Qt::AlignHCenter ); + pData->m_vTextAlign = XmlReadInt( ele, "vTextAlign", Qt::AlignVCenter ); + + // Search for the font + QDomNode innerNode = ele.firstChild(); + while( !innerNode.isNull() ) + { + QString innerName = innerNode.nodeName(); + QDomElement innerE = innerNode.toElement(); + + if( innerName == "TextFont" ) + { + pData->m_textFont.setFamily( XmlReadString(innerE, "family", "times") ); + pData->m_textFont.setPointSize( XmlReadInt(innerE, "size", 12 ) ); + pData->m_textFont.setBold( (bool)XmlReadInt( innerE, "bold", 12 ) ); + pData->m_textFont.setItalic( (bool)XmlReadInt( innerE, "italic", 12 ) ); + pData->m_textFont.setUnderline( (bool)XmlReadInt( innerE, "underline", 12 ) ); + pData->m_textFont.setStrikeOut( (bool)XmlReadInt( innerE, "strikeOut", 12 ) ); + pData->m_textFont.setFixedPitch( (bool)XmlReadInt( innerE, "fixedPitch", false ) ); + pData->m_textColor = XmlReadColor( innerE, "color", QColor(0,0,0) ); + } + + innerNode = innerNode.nextSibling(); + } + + // Now convert it to a KivioTextStyle + if( !m_pTextData ) + m_pTextData = new KivioTextStyle(); + + m_pTextData->setText( pData->m_text ); + m_pTextData->setHTextAlign( pData->m_hTextAlign ); + m_pTextData->setVTextAlign( pData->m_vTextAlign ); + m_pTextData->setFont( pData->m_textFont ); + m_pTextData->setColor( pData->m_textColor ); + + } // end if m_shapeType==kstTextBox + else + { + kdDebug(43000) << "KivioShapeData::loadXML() - Loading KivioText, but this is not a textbox!" << endl; + } + } + + node = node.nextSibling(); + } + + return true; +} + +/** + * Save this object to an XML element + * + */ +QDomElement KivioShapeData::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioShapeData"); + + // FIXME: Do we need to save m_pOriginalPointList + + // We save all this, but we won't necessarily load it back. + + // The positions + QDomElement posE = doc.createElement("Position"); + XmlWriteFloat( posE, "x", m_position.x() ); + XmlWriteFloat( posE, "y", m_position.y() ); + e.appendChild( posE ); + + // The dimensions + QDomElement dimE = doc.createElement("Dimension"); + XmlWriteFloat( dimE, "w", m_dimensions.x() ); + XmlWriteFloat( dimE, "h", m_dimensions.y() ); + e.appendChild( dimE ); + + // The FGColor +// QDomElement foreE = doc.createElement("Foreground"); +// XmlWriteUInt( foreE, "color", m_fgColor.rgb() ); +// XmlWriteFloat( foreE, "lineWidth", m_lineWidth ); +// e.appendChild( foreE ); + QDomElement foreE = m_pLineStyle->saveXML( doc ); + e.appendChild( foreE ); + + + // Save if we are a text box etc... + if( m_shapeType == kstTextBox ) + { + if( m_pTextData ) + { + e.appendChild( m_pTextData->saveXML(doc) ); + /* + // The text & formatting + QDomElement textE = doc.createElement("KivioText"); + XmlWriteString( textE, "text", m_pTextData->m_text ); + XmlWriteInt( textE, "isHtml", m_pTextData->m_isHtml ); + XmlWriteInt( textE, "hTextAlign", m_pTextData->m_hTextAlign ); + XmlWriteInt( textE, "vTextAlign", m_pTextData->m_vTextAlign ); + + // Text font & color + QDomElement innerTextE = doc.createElement("TextFont"); + XmlWriteString( innerTextE, "family", m_pTextData->m_textFont.family() ); + XmlWriteColor( innerTextE, "color", m_pTextData->m_textColor ); + XmlWriteInt( innerTextE, "size", m_pTextData->m_textFont.pointSize() ); + XmlWriteInt( innerTextE, "bold", m_pTextData->m_textFont.bold() ); + XmlWriteInt( innerTextE, "italic", m_pTextData->m_textFont.italic() ); + XmlWriteInt( innerTextE, "underline", m_pTextData->m_textFont.underline() ); + XmlWriteInt( innerTextE, "strikeOut", m_pTextData->m_textFont.strikeOut() ); + XmlWriteInt( innerTextE, "fixedPitch", m_pTextData->m_textFont.fixedPitch() ); + + textE.appendChild( innerTextE ); + e.appendChild( textE ); + */ + } + } + + + + // The BGFillStyle + e.appendChild( m_pFillStyle->saveXML( doc ) ); + + // Shape type & name are stored in the shape node + //XmlWriteInt( e, "shapeType", m_shapeType ); + //XmlWriteString( e, "name", m_name ); + + return e; +} + + +KivioShapeData::KivioShapeType KivioShapeData::shapeTypeFromString( const QString &str ) +{ + + for( int i=0; i<numShapeInfo; i++ ) + { + if( str.compare( shapeInfo[i].name )==0 ) + return shapeInfo[i].type; + } + + return kstNone; +} + +void KivioShapeData::setShapeType( KivioShapeType st ) +{ + m_shapeType = st; + + // If it is a text box, make sure we have text data + if( st == kstTextBox ) + { + if( !m_pTextData ) + m_pTextData = new KivioTextStyle(); + } + else // Otherwise, make sure we DON'T have it. + { + if( m_pTextData ) + { + delete m_pTextData; + m_pTextData = NULL; + } + } +} + + +QString KivioShapeData::text() +{ + if( m_pTextData ) + return m_pTextData->text(); + + return QString(""); +} + +void KivioShapeData::setText( const QString &newText ) +{ + if( m_pTextData ) + { + m_pTextData->setText(newText); + } +} + +bool KivioShapeData::isHtml() const +{ + if( m_pTextData ) + return m_pTextData->isHtml(); + + return false; +} + +void KivioShapeData::setIsHtml( bool b ) +{ + if( m_pTextData ) + m_pTextData->setIsHtml(b); +} + +int KivioShapeData::hTextAlign() const +{ + if( m_pTextData ) + return m_pTextData->hTextAlign(); + + return Qt::AlignHCenter; +} + +void KivioShapeData::setHTextAlign( int i ) +{ + if( m_pTextData ) + m_pTextData->setHTextAlign(i); +} + +int KivioShapeData::vTextAlign() const +{ + if( m_pTextData ) + return m_pTextData->vTextAlign(); + + return Qt::AlignVCenter; +} + +void KivioShapeData::setVTextAlign( int i ) +{ + if( m_pTextData ) + m_pTextData->setVTextAlign(i); +} + +QFont KivioShapeData::textFont() +{ + if( m_pTextData ) + return m_pTextData->font(); + + return QFont("Times"); +} + +void KivioShapeData::setTextFont( const QFont &f ) +{ + if( m_pTextData ) + m_pTextData->setFont(f); +} + +QColor KivioShapeData::textColor() +{ + if( m_pTextData ) + return m_pTextData->color(); + + return QColor(0,0,0); +} + +void KivioShapeData::setTextColor( QColor c ) +{ + if( m_pTextData ) + m_pTextData->setColor(c); +} + +void KivioShapeData::setTextStyle( KivioTextStyle *pStyle ) +{ + if( m_pTextData ) + { + pStyle->copyInto( m_pTextData ); + } +} + +void KivioShapeData::setLineStyle(KivioLineStyle ls) +{ + if(m_pLineStyle) { + ls.copyInto(m_pLineStyle); + } +} diff --git a/kivio/kiviopart/kiviosdk/kivio_shape_data.h b/kivio/kiviopart/kiviosdk/kivio_shape_data.h new file mode 100644 index 000000000..1c386055e --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_shape_data.h @@ -0,0 +1,152 @@ +/* + * 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 KIVIO_SHAPE_DATA_H +#define KIVIO_SHAPE_DATA_H + +#include <qfont.h> +#include <qcolor.h> +#include <qdom.h> +#include <qptrlist.h> +#include <qstring.h> + +#include "kivio_point.h" + +class KivioFillStyle; +class KivioLineStyle; +class KivioTextStyle; + +class KivioTextShapeData +{ +public: + KivioTextShapeData(); + + QString m_text; // The text inside this shape + QColor m_textColor; // The text color + QFont m_textFont; // The text font + bool m_isHtml; // Is the text HTML formatted? + int m_hTextAlign, m_vTextAlign; // Horizontal and vertical text alignment flags +}; + +/** + * A class containing all the data for a KivioShape. + * + * @author Dave Marotti + */ +class KivioShapeData +{ +public: + /** + * The possible shape types. + */ + typedef enum { + kstNone = 0, + kstArc, + kstPie, + kstLineArray, + kstPolyline, + kstPolygon, + kstBezier, + kstRectangle, + kstRoundRectangle, + kstEllipse, + kstOpenPath, + kstClosedPath, + kstTextBox + } KivioShapeType; + +protected: + friend class KivioShape; + + QPtrList <KivioPoint> *m_pOriginalPointList; // Original point list loaded from an SML file + + KivioShapeType m_shapeType; // The shape type + KivioPoint m_position, m_dimensions; // The position and dimensions + KivioFillStyle *m_pFillStyle; // The fill style + +// QColor m_fgColor; // The foreground color +// float m_lineWidth; // The line width + KivioLineStyle *m_pLineStyle; + + QString m_name; // The name of this shape + + KivioTextStyle *m_pTextData; // A pointer to text data (if applicable, e.g. TextBox) + +public: + KivioShapeData(); + KivioShapeData( const KivioShapeData & ); + virtual ~KivioShapeData(); + + virtual void copyInto( KivioShapeData *pTarget ) const; + + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + + + KivioShapeType shapeType() const { return m_shapeType; } + void setShapeType( KivioShapeType st ); + + static KivioShapeType shapeTypeFromString( const QString & ); + + QPtrList<KivioPoint> *pointList() { return m_pOriginalPointList; } + + KivioFillStyle *fillStyle() const { return m_pFillStyle; } + KivioLineStyle *lineStyle() const { return m_pLineStyle; } + void setLineStyle(KivioLineStyle ls); + + + const QString &name() const { return m_name; } + void setName( const QString &newName ) { m_name=newName; } + + + // Dimensions / Position + KivioPoint *position() { return &m_position; } + KivioPoint *dimensions() { return &m_dimensions; } + + double x() { return m_position.x(); } + double y() { return m_position.y(); } + double w() { return m_dimensions.x(); } + double h() { return m_dimensions.y(); } + + + + // Text functions + QString text(); + void setText( const QString &newText ); + + bool isHtml() const; + void setIsHtml( bool b ); + + int hTextAlign() const; + void setHTextAlign( int i ); + + int vTextAlign() const; + void setVTextAlign( int i ); + + QFont textFont(); + void setTextFont( const QFont &f ); + + QColor textColor(); + void setTextColor( QColor c ); + + void setTextStyle( KivioTextStyle * ); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_shape_painter.cpp b/kivio/kiviopart/kiviosdk/kivio_shape_painter.cpp new file mode 100644 index 000000000..f0d446ccc --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_shape_painter.cpp @@ -0,0 +1,145 @@ +/** + * This class can be used to draw a KivioShape scaled to a given width and height + * at a given point on a drawing surface. Also planned is the ability to + * transform this object, ie rotate/sheer. + */ +#include "kivio_painter.h" +#include "kivio_shape.h" +#include "kivio_shape_data.h" +#include "kivio_shape_painter.h" + +#include <qcolor.h> + + +KivioShapePainter::KivioShapePainter( KivioPainter *p ) +{ + m_pPainter = p; + m_fgColor = QColor(255,255,255); + m_lineWidth = 1.0f; + m_pShape = NULL; + + m_x = m_y = 0.0f; + m_w = m_h = 72.0f; +} + +KivioShapePainter::~KivioShapePainter() +{ +} + +void KivioShapePainter::drawShape( KivioShape *pShape, float x, float y, float w, float h ) +{ + KivioShapeData *pShapeData; + + m_x = x; + m_y = y; + m_w = w; + m_h = h; + + m_pShape = pShape; + + pShapeData = pShape->shapeData(); + + switch( pShapeData->shapeType() ) + { + case KivioShapeData::kstArc: + drawArc(); + break; + + case KivioShapeData::kstPie: + drawPie(); + break; + + case KivioShapeData::kstLineArray: + drawLineArray(); + break; + + case KivioShapeData::kstPolyline: + drawPolyline(); + break; + + case KivioShapeData::kstPolygon: + drawPolygon(); + break; + + case KivioShapeData::kstBezier: + drawBezier(); + break; + + case KivioShapeData::kstRectangle: + drawRectangle(); + break; + + case KivioShapeData::kstRoundRectangle: + drawRoundRectangle(); + break; + + case KivioShapeData::kstEllipse: + drawEllipse(); + break; + + case KivioShapeData::kstOpenPath: + drawOpenPath(); + break; + + case KivioShapeData::kstClosedPath: + drawClosedPath(); + break; + + case KivioShapeData::kstTextBox: + drawTextBox(); + break; + + + case KivioShapeData::kstNone: + default: + break; + } +} + +void KivioShapePainter::drawArc() +{ +} + +void KivioShapePainter::drawBezier() +{ +} + +void KivioShapePainter::drawOpenPath() +{ +} + +void KivioShapePainter::drawClosedPath() +{ +} + +void KivioShapePainter::drawPie() +{ +} + +void KivioShapePainter::drawEllipse() +{ +} + +void KivioShapePainter::drawLineArray() +{ +} + +void KivioShapePainter::drawRectangle() +{ +} + +void KivioShapePainter::drawRoundRectangle() +{ +} + +void KivioShapePainter::drawPolygon() +{ +} + +void KivioShapePainter::drawPolyline() +{ +} + +void KivioShapePainter::drawTextBox() +{ +} diff --git a/kivio/kiviopart/kiviosdk/kivio_shape_painter.h b/kivio/kiviopart/kiviosdk/kivio_shape_painter.h new file mode 100644 index 000000000..5de938a9c --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_shape_painter.h @@ -0,0 +1,52 @@ +#ifndef KIVIO_SHAPE_PAINTER_H +#define KIVIO_SHAPE_PAINTER_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "kivio_fill_style.h" + +class KivioPainter; +class KivioShape; + +class KivioShapePainter +{ +protected: + KivioFillStyle m_fillStyle; + KivioPainter *m_pPainter; + KivioShape *m_pShape; + QColor m_fgColor; + float m_lineWidth; + + float m_x, m_y, m_w, m_h; + + void drawArc(); + void drawBezier(); + void drawOpenPath(); + void drawClosedPath(); + void drawPie(); + void drawEllipse(); + void drawLineArray(); + void drawRectangle(); + void drawRoundRectangle(); + void drawPolygon(); + void drawPolyline(); + void drawTextBox(); + +public: + KivioShapePainter( KivioPainter * ); + virtual ~KivioShapePainter(); + + + void setFGColor( const QColor &c ) { m_fgColor = c; } + void setBGColor( const QColor &c ) { m_fillStyle.setColor(c); } + void setLineWidth( const float &f ) { m_lineWidth = f; } + + void drawShape( KivioShape *, float, float, float, float ); + void drawShapeOutline( KivioShape *, float, float, float, float ); + +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_sml_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_sml_stencil.cpp new file mode 100644 index 000000000..b81ce81bd --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_sml_stencil.cpp @@ -0,0 +1,2228 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2003 theKompany.com & Dave Marotti + * Peter Simonsson + * + * 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 "kivioglobal.h" +#include "kivio_common.h" +#include "kivio_connector_point.h" +#include "kivio_connector_target.h" +#include "kivio_fill_style.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_line_style.h" +#include "kivio_painter.h" +#include "kivio_screen_painter.h" +#include "kivio_shape.h" +#include "kivio_shape_data.h" +#include "kivio_sml_stencil.h" +#include "kivio_dia_stencil_spawner.h" +#include "kivio_sml_stencil_spawner.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil_spawner_set.h" + +#include <qdom.h> +#include <qpainter.h> +#include <qbrush.h> +#include <qcolor.h> +#include <qpalette.h> +#include <qrect.h> +#include <qbitmap.h> +#include <kdebug.h> +#include <KoGlobal.h> +#include <math.h> +#include <KoZoomHandler.h> + +/** + * Default constructor + * + * Allocates a new shape list, connector targets, and original connector targets. + */ +KivioSMLStencil::KivioSMLStencil() + : KivioStencil(), + m_pShapeList(NULL), + m_pSubSelection(NULL), + m_pConnectorTargets(NULL) +{ + m_pShapeList = new QPtrList<KivioShape>; + m_pShapeList->setAutoDelete(true); + + m_pConnectorTargets = new QPtrList<KivioConnectorTarget>; + m_pConnectorTargets->setAutoDelete(true); +} + + +/** + * Destructor + * + * Deletes the allocated objects. + */ +KivioSMLStencil::~KivioSMLStencil() +{ + delete m_pShapeList; + m_pShapeList = 0; + + delete m_pConnectorTargets; + m_pConnectorTargets = 0; + + m_pSubSelection = 0; +} + + +/** + * Loads a KivioSMLStencil from an XML node. + */ +bool KivioSMLStencil::loadXML( const QDomElement &e ) +{ + QDomNode node; + QDomElement ele; + + + node = e.firstChild(); + while( !node.isNull() ) + { + QString nodeName = node.nodeName(); + + ele = node.toElement(); + + if( nodeName == "Position" ) + { + m_x = XmlReadFloat( ele, "x", 0.0f ); + m_y = XmlReadFloat( ele, "y", 0.0f ); + } + else if( nodeName == "Dimension" ) + { + m_w = XmlReadFloat( ele, "w", 0.0f ); + m_h = XmlReadFloat( ele, "h", 0.0f ); + } + else if( nodeName == "KivioShape" ) + { + // Locate the shape we are supposed to load into + KivioShape *pShape = locateShape( XmlReadString( ele, "name", "" ) ); + + if(pShape) { + pShape->loadXML( ele ); + } + } + else if( nodeName == "KivioConnectorTargetList" ) + { + loadConnectorTargetListXML( ele ); + } + + node = node.nextSibling(); + } + return true; +} + +/** + * Help function for loading from an XML node. + */ +void KivioSMLStencil::loadConnectorTargetListXML( const QDomElement &e ) +{ + QDomNode node; + QDomElement ele; + QString nodeName; + KivioConnectorTarget *pTarget; + + pTarget = m_pConnectorTargets->first(); + node = e.firstChild(); + while( !node.isNull() && pTarget) + { + nodeName = node.nodeName(); + ele = node.toElement(); + + if( nodeName == "KivioConnectorTarget" ) + { + pTarget->loadXML( ele ); + pTarget->setOffsets((pTarget->x() - x()) / w(), (pTarget->y() - y()) / h()); + pTarget = m_pConnectorTargets->next(); + } + + node = node.nextSibling(); + } + + while(!node.isNull()) { + nodeName = node.nodeName(); + ele = node.toElement(); + + if( nodeName == "KivioConnectorTarget" ) + { + pTarget = new KivioConnectorTarget(); + pTarget->loadXML( ele ); + pTarget->setOffsets((pTarget->x() - x()) / w(), (pTarget->y() -y()) / h()); + m_pConnectorTargets->append(pTarget); + } + + node = node.nextSibling(); + } +} + + +/** + * Locates a shape in the shape list by name. + */ +KivioShape *KivioSMLStencil::locateShape( const QString &name ) +{ + KivioShape *pShape; + + if( name.isEmpty() ) + return NULL; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->name() == name ) + { + return pShape; + } + + pShape = m_pShapeList->next(); + } + + return NULL; +} + + +/** + * Saves this object to an XMLELement + */ +QDomElement KivioSMLStencil::saveXML( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioSMLStencil"); + + XmlWriteString( e, "id", m_pSpawner->info()->id() ); + XmlWriteString( e, "setId", m_pSpawner->set()->id() ); + + + // The positions + QDomElement posE = doc.createElement("Position"); + XmlWriteFloat( posE, "x", m_x ); + XmlWriteFloat( posE, "y", m_y ); + e.appendChild( posE ); + + // The dimensions + QDomElement dimE = doc.createElement("Dimension"); + XmlWriteFloat( dimE, "w", m_w ); + XmlWriteFloat( dimE, "h", m_h ); + e.appendChild( dimE ); + + // Save the target list + QDomElement clE = doc.createElement("KivioConnectorTargetList"); + QDomElement targetE; + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + targetE = pTarget->saveXML( doc ); + clE.appendChild( targetE ); + + pTarget = m_pConnectorTargets->next(); + } + e.appendChild( clE ); + + // The shape list + KivioShape *pShape = m_pShapeList->first(); + while( pShape ) + { + e.appendChild( pShape->saveXML(doc ) ); + + pShape = m_pShapeList->next(); + } + + return e; +} + + +/** + * Duplicates this object. + * + * Duplicates all aspects of this object except for the + * stencil connected to the targets. + */ +KivioStencil *KivioSMLStencil::duplicate() +{ + KivioSMLStencil *pNewStencil = new KivioSMLStencil(); + KivioStencil *pReturn; + KivioShape *pShape, *pNewShape; + + pNewStencil->m_x = m_x; + pNewStencil->m_y = m_y; + pNewStencil->m_w = m_w; + pNewStencil->m_h = m_h; + + pNewStencil->m_rotation = m_rotation; + + pNewStencil->m_pSpawner = m_pSpawner; + + + // Copy the shape list + pShape = m_pShapeList->first(); + while( pShape ) + { + pNewShape = new KivioShape( *pShape ); + pNewStencil->m_pShapeList->append( pNewShape ); + + pShape = m_pShapeList->next(); + } + + // Copy the Connector Targets + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + while( pTarget ) //&& pOriginal ) + { + pNewStencil->m_pConnectorTargets->append( pTarget->duplicate() ); + pTarget = m_pConnectorTargets->next(); + } + + *(pNewStencil->protection()) = *m_pProtection; + *(pNewStencil->canProtect()) = *m_pCanProtect; + + + pReturn = pNewStencil; + + return pReturn; +} + + +/** + * Paint the outline of the stencil. + */ +void KivioSMLStencil::paintOutline( KivioIntraStencilData *pData ) +{ + KivioShape *pShape; + KivioShapeData *pShapeData; + + m_zoomHandler = pData->zoomHandler; + pData->painter->saveState(); + pData->painter->setTranslation(m_zoomHandler->zoomItX(m_x), m_zoomHandler->zoomItY(m_y)); + rotatePainter(pData); // Rotate the painter if needed + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShapeData = pShape->shapeData(); + + switch( pShapeData->shapeType() ) + { + case KivioShapeData::kstArc: + drawOutlineArc( pShape, pData ); + break; + + case KivioShapeData::kstPie: + drawOutlinePie( pShape, pData ); + break; + + case KivioShapeData::kstLineArray: + drawOutlineLineArray( pShape, pData ); + break; + + case KivioShapeData::kstPolyline: + drawOutlinePolyline( pShape, pData ); + break; + + case KivioShapeData::kstPolygon: + drawOutlinePolygon( pShape, pData ); + break; + + case KivioShapeData::kstBezier: + drawOutlineBezier( pShape, pData ); + break; + + case KivioShapeData::kstRectangle: + drawOutlineRectangle( pShape, pData ); + break; + + case KivioShapeData::kstRoundRectangle: + drawOutlineRoundRectangle( pShape, pData ); + break; + + case KivioShapeData::kstEllipse: + drawOutlineEllipse( pShape, pData ); + break; + + case KivioShapeData::kstOpenPath: + drawOutlineOpenPath( pShape, pData ); + break; + + case KivioShapeData::kstClosedPath: + drawOutlineClosedPath( pShape, pData ); + break; + + case KivioShapeData::kstTextBox: + drawOutlineTextBox( pShape, pData ); + break; + + + case KivioShapeData::kstNone: + default: + kdDebug(43000) << "*** KivioShape::Paint AHHHHH!!! NO SHAPE!" << endl; + break; + } + + pShape = m_pShapeList->next(); + } + pData->painter->restoreState(); + + // Now iterate through anything connected to it drawing it as an outline + KivioConnectorTarget *pTarget; + + pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + pTarget->paintOutline( pData ); + + pTarget = m_pConnectorTargets->next(); + } +} + +void KivioSMLStencil::drawOutlineArc( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _a, _l, _x, _y, _w, _h, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + KivioPoint *pPoint; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + pPoint = pShapeData->pointList()->first(); + _a = m_zoomHandler->zoomItX(pPoint->x()); + _l = m_zoomHandler->zoomItY(pPoint->y()); + + + painter = pData->painter; + painter->drawArc( _x, _y, _w, _h, _a, _l ); +} + +void KivioSMLStencil::drawOutlineBezier( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter *painter; + KivioShapeData *pShapeData = pShape->shapeData(); + + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + + + painter = pData->painter; + pShapeData = pShape->shapeData(); + + KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4; + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + QPointArray controlPoints( 4 ); + + + pPoint = pPointList->first(); + pPoint2 = pPointList->next(); + pPoint3 = pPointList->next(); + pPoint4 = pPointList->next(); + + + controlPoints.setPoint( 0, m_zoomHandler->zoomItX((pPoint->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h) ); + controlPoints.setPoint( 1, m_zoomHandler->zoomItX((pPoint2->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint2->y()/defHeight)*m_h)); + controlPoints.setPoint( 2, m_zoomHandler->zoomItX((pPoint3->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint3->y()/defHeight)*m_h)); + controlPoints.setPoint( 3, m_zoomHandler->zoomItX((pPoint4->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint4->y()/defHeight)*m_h)); + + painter = pData->painter; + painter->drawBezier( controlPoints ); +} + +void KivioSMLStencil::drawOutlineOpenPath( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter *painter; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPoint, *pNewPoint; + + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete(true); + + pPoint = pPointList->first(); + + while( pPoint ) + { + pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h), + pPoint->pointType() ); + pNewPoints->append(pNewPoint); + + pPoint = pPointList->next(); + } + + painter = pData->painter; + painter->drawOpenPath( pNewPoints ); + + delete pNewPoints; +} + +void KivioSMLStencil::drawOutlineClosedPath( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter *painter; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPoint, *pNewPoint; + + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete(true); + + pPoint = pPointList->first(); + while( pPoint ) + { + pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h), + pPoint->pointType() ); + pNewPoints->append(pNewPoint); + + pPoint = pPointList->next(); + } + + painter = pData->painter; + painter->drawOpenPath( pNewPoints ); + + delete pNewPoints; +} + +void KivioSMLStencil::drawOutlineEllipse( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _x, _y, _w, _h, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + + painter = pData->painter; + painter->setFGColor( QColor(0, 0, 0) ); + painter->drawEllipse( _x, _y, _w, _h ); +} + +void KivioSMLStencil::drawOutlineLineArray( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _x, _y, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + QPtrList <KivioPoint> *pList; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + + QPointArray arr( pList->count() ); + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + arr.setPoint( i, (int)_x, (int)_y ); + + i++; + + pPoint = pList->next(); + } + + painter = pData->painter; + painter->drawLineArray( arr ); +} + +void KivioSMLStencil::drawOutlineRectangle( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _x, _y, _w, _h, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + painter = pData->painter; + painter->setFGColor( QColor(0, 0, 0) ); + painter->drawRect( _x, _y, _w, _h ); +} + +void KivioSMLStencil::drawOutlineRoundRectangle( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _rx, _ry, _x, _y, _w, _h, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + KivioPoint *pPoint; + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pPoint = pShapeData->pointList()->first(); + _rx = m_zoomHandler->zoomItX(pPoint->x()); + _ry = m_zoomHandler->zoomItY(pPoint->y()); + + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + + painter = pData->painter; + painter->setFGColor( QColor(0, 0, 0) ); + painter->drawRoundRect( _x, _y, _w, _h, _rx, _ry ); +} + +void KivioSMLStencil::drawOutlinePie( KivioShape *, KivioIntraStencilData * ) +{ + +} + +void KivioSMLStencil::drawOutlinePolygon( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _x, _y, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + QPtrList <KivioPoint> *pList; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + + QPointArray arr( pList->count() ); + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + arr.setPoint( i, (int)_x, (int)_y ); + + i++; + + pPoint = pList->next(); + } + + painter = pData->painter; + painter->drawPolyline( arr ); +} + +void KivioSMLStencil::drawOutlinePolyline( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double _x, _y, defWidth, defHeight; + KivioPainter *painter; + KivioShapeData *pShapeData; + QPtrList <KivioPoint> *pList; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + + QPointArray arr( pList->count() ); + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + arr.setPoint( i, (int)_x, (int)_y ); + + i++; + + pPoint = pList->next(); + } + + painter = pData->painter; + painter->drawPolyline( arr ); +} + +void KivioSMLStencil::drawOutlineTextBox( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + int _x, _y, _w, _h; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPosition = pShapeData->position(); + KivioPoint *pDimensions = pShapeData->dimensions(); + KivioPainter *painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + + if( pShapeData->text().length() <= 0 ) { + return; + } + + + _x = zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + + QPixmap pix(_w, _h); + pix.fill(); + QPainter p(&pix); + + QFont f = pShapeData->textFont(); + f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0)); + p.setFont( f ); + p.setPen( QColor(0, 0, 0) ); + int tf = pShapeData->vTextAlign() | pShapeData->hTextAlign(); + p.drawText( 0, 0, _w, _h, tf | Qt::WordBreak, pShapeData->text() ); + QBitmap mask; + mask = pix; + pix.setMask(mask); + painter->drawPixmap(_x, _y, pix); +} + + +/** + * Paints the stencil + */ +void KivioSMLStencil::paint( KivioIntraStencilData *pData ) +{ + KivioShape *pShape; + KivioShapeData *pShapeData; + + + m_zoomHandler = pData->zoomHandler; + pData->painter->saveState(); + pData->painter->setTranslation(m_zoomHandler->zoomItX(m_x), m_zoomHandler->zoomItY(m_y)); + rotatePainter(pData); // Rotate the painter if needed + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShapeData = pShape->shapeData(); + + switch( pShapeData->shapeType() ) + { + case KivioShapeData::kstArc: + drawArc( pShape, pData ); + break; + + case KivioShapeData::kstPie: + drawPie( pShape, pData ); + break; + + case KivioShapeData::kstLineArray: + drawLineArray( pShape, pData ); + break; + + case KivioShapeData::kstPolyline: + drawPolyline( pShape, pData ); + break; + + case KivioShapeData::kstPolygon: + drawPolygon( pShape, pData ); + break; + + case KivioShapeData::kstBezier: + drawBezier( pShape, pData ); + break; + + case KivioShapeData::kstRectangle: + drawRectangle( pShape, pData ); + break; + + case KivioShapeData::kstRoundRectangle: + drawRoundRectangle( pShape, pData ); + break; + + case KivioShapeData::kstEllipse: + drawEllipse( pShape, pData ); + break; + + case KivioShapeData::kstOpenPath: + drawOpenPath( pShape, pData ); + break; + + case KivioShapeData::kstClosedPath: + drawClosedPath( pShape, pData ); + break; + + case KivioShapeData::kstTextBox: + drawTextBox( pShape, pData ); + break; + + case KivioShapeData::kstNone: + default: + break; + } + + pShape = m_pShapeList->next(); + } + + pData->painter->restoreState(); +} + + +/** + * Paints the connector targets of this stencil. + */ +void KivioSMLStencil::paintConnectorTargets( KivioIntraStencilData *pData ) +{ + // We don't draw these if we are selected!!! + //if( isSelected() == true ) { + // return; + //} + + QPixmap targetPic; + KivioPainter *painter; + int x, y; + + // Obtain the graphic used for KivioConnectorTargets + targetPic = Kivio::connectorTargetPixmap(); + + + m_zoomHandler = pData->zoomHandler; + painter = pData->painter; + + KivioConnectorTarget *pTarget; + pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + x = m_zoomHandler->zoomItX(pTarget->x()); + y = m_zoomHandler->zoomItY(pTarget->y()); + + painter->drawPixmap( x-3, y-3, targetPic ); + + pTarget = m_pConnectorTargets->next(); + } +} + + +void KivioSMLStencil::drawArc( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _a, _l, _x, _y, _w, _h; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + KivioPoint *pPoint; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + pPoint = pShapeData->pointList()->first(); + _a = m_zoomHandler->zoomItX(pPoint->x()); + _l = m_zoomHandler->zoomItY(pPoint->y()); + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + switch( pShapeData->fillStyle()->colorStyle() ) + { + case KivioFillStyle::kcsNone: // Hollow + painter->drawArc( _x, _y, _w, _h, _a, _l ); + break; + + case KivioFillStyle::kcsSolid: // Solid fill + case KivioFillStyle::kcsGradient: // Gradient + painter->setFillStyle( pShapeData->fillStyle() ); + painter->drawArc( _x, _y, _w, _h, _a, _l ); + break; + + case KivioFillStyle::kcsPixmap: + default: + break; + } +} + +void KivioSMLStencil::drawBezier( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter *painter; + KivioShapeData *pShapeData = pShape->shapeData(); + + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + + + painter = pData->painter; + pShapeData = pShape->shapeData(); + + KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4; + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + QPointArray controlPoints( 4 ); + + + pPoint = pPointList->first(); + pPoint2 = pPointList->next(); + pPoint3 = pPointList->next(); + pPoint4 = pPointList->next(); + + + controlPoints.setPoint( 0, m_zoomHandler->zoomItX((pPoint->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h)); + controlPoints.setPoint( 1, m_zoomHandler->zoomItX((pPoint2->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint2->y()/defHeight)*m_h)); + controlPoints.setPoint( 2, m_zoomHandler->zoomItX((pPoint3->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint3->y()/defHeight)*m_h)); + controlPoints.setPoint( 3, m_zoomHandler->zoomItX((pPoint4->x() / defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint4->y()/defHeight)*m_h)); + + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + painter->drawBezier( controlPoints ); +} + +void KivioSMLStencil::drawOpenPath( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter *painter; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPoint, *pNewPoint; + + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete(true); + + pPoint = pPointList->first(); + while( pPoint ) + { + pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h), + pPoint->pointType() ); + pNewPoints->append(pNewPoint); + + pPoint = pPointList->next(); + } + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + painter->drawOpenPath( pNewPoints ); + + delete pNewPoints; +} + +void KivioSMLStencil::drawClosedPath( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter *painter; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPoint, *pNewPoint; + + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete(true); + + pPoint = pPointList->first(); + while( pPoint ) + { + pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w), + m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h), + pPoint->pointType() ); + pNewPoints->append(pNewPoint); + + pPoint = pPointList->next(); + } + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + switch( pShapeData->fillStyle()->colorStyle() ) + { + case KivioFillStyle::kcsNone: // Hollow + painter->drawOpenPath( pNewPoints ); + break; + + case KivioFillStyle::kcsSolid: // Solid fill + case KivioFillStyle::kcsGradient: // Gradient + painter->setFillStyle( pShapeData->fillStyle() ); + painter->drawClosedPath( pNewPoints ); + break; + + case KivioFillStyle::kcsPixmap: + default: + break; + } + + delete pNewPoints; +} + +void KivioSMLStencil::drawPie( KivioShape *, KivioIntraStencilData * ) +{ +} + +void KivioSMLStencil::drawEllipse( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _x, _y, _w, _h; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + switch( pShapeData->fillStyle()->colorStyle() ) + { + case KivioFillStyle::kcsNone: // Hollow + painter->drawEllipse( _x, _y, _w, _h ); + break; + + case KivioFillStyle::kcsSolid: // Solid fill + case KivioFillStyle::kcsGradient: // Gradient + painter->setFillStyle( pShapeData->fillStyle() ); + painter->fillEllipse( _x, _y, _w, _h ); + break; + + case KivioFillStyle::kcsPixmap: + default: + break; + } +} + +void KivioSMLStencil::drawLineArray( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _x, _y; + KivioPainter *painter; + KivioShapeData *pShapeData; + QPtrList <KivioPoint> *pList; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + + QPointArray arr( pList->count() ); + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + arr.setPoint( i, _x, _y ); + + i++; + + pPoint = pList->next(); + } + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + painter->drawLineArray( arr ); +} + +void KivioSMLStencil::drawRectangle( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _x, _y, _w, _h; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + switch( pShapeData->fillStyle()->colorStyle() ) + { + case KivioFillStyle::kcsNone: // Hollow + painter->drawRect( _x, _y, _w, _h ); + break; + + case KivioFillStyle::kcsSolid: // Solid fill + case KivioFillStyle::kcsGradient: // Gradient + painter->setFillStyle( pShapeData->fillStyle() ); + painter->fillRect( _x, _y, _w, _h ); + break; + + case KivioFillStyle::kcsPixmap: + default: + break; + } +} + +void KivioSMLStencil::drawRoundRectangle( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _rx, _ry, _x, _y, _w, _h; + KivioPainter *painter; + KivioShapeData *pShapeData; + KivioPoint *pPosition, *pDimensions; + KivioPoint *pPoint; + + pShapeData = pShape->shapeData(); + pPosition = pShapeData->position(); + pDimensions = pShapeData->dimensions(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + pPoint = pShapeData->pointList()->first(); + _rx = m_zoomHandler->zoomItX(pPoint->x()); + _ry = m_zoomHandler->zoomItY(pPoint->y()); + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + switch( pShapeData->fillStyle()->colorStyle() ) + { + case KivioFillStyle::kcsNone: // Hollow + painter->drawRoundRect( _x, _y, _w, _h, _rx, _ry ); + break; + + case KivioFillStyle::kcsSolid: // Solid fill + case KivioFillStyle::kcsGradient: // Gradient + painter->setFillStyle( pShapeData->fillStyle() ); + painter->fillRoundRect( _x, _y, _w, _h, _rx, _ry ); + break; + + case KivioFillStyle::kcsPixmap: + default: + break; + } +} + +void KivioSMLStencil::drawPolygon( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _x, _y; + KivioPainter *painter; + KivioShapeData *pShapeData; + QPtrList <KivioPoint> *pList; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + + QPointArray arr( pList->count() ); + + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + + arr.setPoint( i, _x, _y ); + + i++; + + pPoint = pList->next(); + } + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + switch( pShapeData->fillStyle()->colorStyle() ) + { + case KivioFillStyle::kcsNone: // Hollow + painter->drawPolygon(arr); + break; + + case KivioFillStyle::kcsSolid: // Solid fill + case KivioFillStyle::kcsGradient: // Gradient + painter->setFillStyle( pShapeData->fillStyle() ); + painter->drawPolygon(arr); + break; + + case KivioFillStyle::kcsPixmap: + default: + break; + } + +} + +void KivioSMLStencil::drawPolyline( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth, defHeight; + int _x, _y; + KivioPainter *painter; + KivioShapeData *pShapeData; + QPtrList <KivioPoint> *pList; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + + QPointArray arr( pList->count() ); + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + arr.setPoint( i, _x, _y ); + + i++; + + pPoint = pList->next(); + } + + painter = pData->painter; + painter->setLineStyle(pShapeData->lineStyle()); + double lineWidth = pShapeData->lineStyle()->width(); + painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth)); + + painter->drawPolyline(arr); +} + +void KivioSMLStencil::drawTextBox( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + double defWidth = m_pSpawner->defWidth(); + double defHeight = m_pSpawner->defHeight(); + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPosition = pShapeData->position(); + KivioPoint *pDimensions = pShapeData->dimensions(); + KivioPainter *painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + + + if(pShapeData->text().isEmpty()) { + return; + } + + int _x = zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w); + int _y = zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h); + int _w = zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1; + int _h = zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1; + + + QFont f = pShapeData->textFont(); + f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0)); + painter->setFont( f ); + painter->setTextColor( pShapeData->textColor() ); + + int tf = pShapeData->vTextAlign() | pShapeData->hTextAlign(); + painter->drawText( _x, _y, _w, _h, tf | Qt::WordBreak, pShapeData->text() ); + // TODO Implement richtext support +} + + + + +/** + * Set the fg color of this stencil. + */ +void KivioSMLStencil::setFGColor( QColor c ) +{ + KivioShape *pShape; + + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShape->shapeData()->lineStyle()->setColor( c ); + + pShape = m_pShapeList->next(); + } +} + + +/** + * Set the bg color of this stencil. + */ +void KivioSMLStencil::setBGColor( QColor c ) +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShape->shapeData()->fillStyle()->setColor( c ); + + pShape = m_pShapeList->next(); + } +} + +void KivioSMLStencil::setFillPattern(int p) +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShape->shapeData()->fillStyle()->setBrushStyle( static_cast<Qt::BrushStyle>(p) ); + + pShape = m_pShapeList->next(); + } +} + +/** + * Set the text color of this stencil. + */ +void KivioSMLStencil::setTextColor( QColor c ) +{ + KivioShape *pShape; + + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShape->shapeData()->setTextColor( c ); + + pShape = m_pShapeList->next(); + } +} + +/** + * Set the text font of this stencil + */ +void KivioSMLStencil::setTextFont( const QFont &f ) +{ + KivioShape *pShape; + + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShape->shapeData()->setTextFont( f ); + + pShape = m_pShapeList->next(); + } +} + + +/** + * Set the line width of this stencil. + */ +void KivioSMLStencil::setLineWidth( double f ) +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + pShape->shapeData()->lineStyle()->setWidth( f ); + + pShape = m_pShapeList->next(); + } +} + +void KivioSMLStencil::setLinePattern(int p) +{ + KivioShape *pShape = m_pShapeList->first(); + + while( pShape ) + { + pShape->shapeData()->lineStyle()->setStyle( p ); + pShape = m_pShapeList->next(); + } +} + +/** + * Attempts to connect a KivioConnectorPoint to this stencil. + * + * This function will attempt to locate a KivioConnectorTarget in this + * stencil with-in a given threshold. If it finds it, it will connect + * the point to it, and return the target of the connection. + */ +KivioConnectorTarget *KivioSMLStencil::connectToTarget( KivioConnectorPoint *p, double threshHold ) +{ + double px = p->x(); + double py = p->y(); + + double tx, ty; + + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + while( pTarget ) + { + tx = pTarget->x(); + ty = pTarget->y(); + + if( px >= tx - threshHold && + px <= tx + threshHold && + py >= ty - threshHold && + py <= ty + threshHold ) + { + // setTarget calls pTarget->addConnectorPoint() and removes + // any previous connections from p + p->setTarget( pTarget ); + return pTarget; + } + + pTarget = m_pConnectorTargets->next(); + } + + return NULL; +} + +KoPoint KivioSMLStencil::snapToTarget( const KoPoint& p, double thresh, bool& hit ) +{ + KoPoint retVal = p; + double tx, ty; + hit = false; + + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + while( pTarget ) + { + tx = pTarget->x(); + ty = pTarget->y(); + + if( retVal.x() >= tx - thresh && + retVal.x() <= tx + thresh && + retVal.y() >= ty - thresh && + retVal.y() <= ty + thresh ) + { + retVal.setX(tx); + retVal.setY(ty); + hit = true; + } + + pTarget = m_pConnectorTargets->next(); + } + + return retVal; +} + +/** + * Connects a KivioConnectorPoint to this stencil via targetID. + * + * This function is called during loads, *ONLY* loads. + */ +KivioConnectorTarget *KivioSMLStencil::connectToTarget( KivioConnectorPoint *p, int /*targetID*/ ) +{ + int id = p->targetId(); + + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + while( pTarget ) + { + if( pTarget->id() == id ) + { + p->setTarget(pTarget); + + return pTarget; + } + + pTarget = m_pConnectorTargets->next(); + } + + return NULL; +} + + +/** + * Updates the geometry of this stencil. + * + * This function rearranges the KivioConnectorTargets to reflect + * that of the width/height/position. + */ +void KivioSMLStencil::updateGeometry() +{ + //kdDebug(43000) << "m_x = " << m_x << " m_y = " << m_y << endl; + + QWMatrix m; + m.translate(m_x, m_y); + m.translate(m_w / 2.0, m_h / 2.0); + m.rotate(m_rotation); + m.translate(-m_w / 2.0, -m_h / 2.0); + + KivioConnectorTarget* pTarget = m_pConnectorTargets->first(); + + while( pTarget ) + { + double _x = pTarget->xOffset() * m_w; + double _y = pTarget->yOffset() * m_h; + double newX = _x * m.m11() + _y * m.m21() + m.dx(); + double newY = _x * m.m12() + _y * m.m22() + m.dy(); + pTarget->setPosition( newX, newY ); + + pTarget = m_pConnectorTargets->next(); + } +} + + +/** + * Gets the font of this stencil + */ +QFont KivioSMLStencil::textFont() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + { + return pShape->shapeData()->textFont(); + } + + pShape = m_pShapeList->next(); + } + + //return QFont("times",12); + return KoGlobal::defaultFont(); +} + +QColor KivioSMLStencil::textColor() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + { + return pShape->shapeData()->textColor(); + } + + pShape = m_pShapeList->next(); + } + + return QColor(0, 0, 0); +} + +/** + * Sets the horizontal alignemnt of this stencil. + */ +void KivioSMLStencil::setHTextAlign(int i) +{ + KivioShape *pShape; + + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + pShape->shapeData()->setHTextAlign( i ); + + pShape = m_pShapeList->next(); + } +} + + +/** + * Set the vertical alignment of this stencil + */ +void KivioSMLStencil::setVTextAlign(int i) +{ + KivioShape *pShape; + + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + pShape->shapeData()->setVTextAlign( i ); + + pShape = m_pShapeList->next(); + } +} + + +/** + * Get the horizontal alignment of this stencil. + */ +int KivioSMLStencil::hTextAlign() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + { + return pShape->shapeData()->hTextAlign(); + } + + pShape = m_pShapeList->next(); + } + + return 1; +} + + +/** + * Get the vertical text alignment of this stencil. + */ +int KivioSMLStencil::vTextAlign() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + { + return pShape->shapeData()->vTextAlign(); + } + + pShape = m_pShapeList->next(); + } + + return 1; +} + + +/** + * Get the text of this stencil + */ +QString KivioSMLStencil::text() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + { + return pShape->shapeData()->text(); + } + + pShape = m_pShapeList->next(); + } + + return QString(""); +} + + +/** + * Set the text of this stencil + */ +void KivioSMLStencil::setText( const QString &t ) +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + while( pShape ) + { + if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox ) + { + pShape->shapeData()->setText(t); + } + + pShape = m_pShapeList->next(); + } +} + + +/** + * Get the line width of this stencil + */ +double KivioSMLStencil::lineWidth() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + if( pShape ) + return pShape->shapeData()->lineStyle()->width(); + + return 1.0f; +} + +int KivioSMLStencil::linePattern() +{ + KivioShape *pShape = m_pShapeList->first(); + + if( pShape ) + return pShape->shapeData()->lineStyle()->style(); + + return 1; +} + +/** + * Get the Fg color of a stencil + */ +QColor KivioSMLStencil::fgColor() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + if( pShape ) + return pShape->shapeData()->lineStyle()->color(); + + return QColor(0,0,0); +} + + +/** + * Get the bg color of this stencil. + */ +QColor KivioSMLStencil::bgColor() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + if( pShape ) + return pShape->shapeData()->fillStyle()->color(); + + return QColor(0,0,0); +} + +int KivioSMLStencil::fillPattern() +{ + KivioShape *pShape; + + pShape = m_pShapeList->first(); + if( pShape ) + return pShape->shapeData()->fillStyle()->brushStyle(); + + return 1; +} + +/** + * Generates the ids for anything needed by this stencil + */ +int KivioSMLStencil::generateIds( int nextAvailable ) +{ + KivioConnectorTarget *pTarget = m_pConnectorTargets->first(); + + // Iterate through all the targets + while( pTarget ) + { + // If this target has something connected to it + if( pTarget->hasConnections() ) + { + // Set it's id to the next available id + pTarget->setId( nextAvailable ); + + // Increment the next available id + nextAvailable++; + } + else + { + // Otherwise mark it as unused (-1) + pTarget->setId( -1 ); + } + + pTarget = m_pConnectorTargets->next(); + } + + // Return the next availabe id + return nextAvailable; +} + +/** + * Check for a collision in this stencil. + */ +KivioCollisionType KivioSMLStencil::checkForCollision( KoPoint *pPoint, double ) +{ + KivioCollisionType type = kctNone; + + QWMatrix m; + m.translate(m_x, m_y); + m.translate(m_w / 2.0, m_h / 2.0); + m.rotate(m_rotation); + m.translate(-m_w / 2.0, -m_h / 2.0); + + KoPoint pPoints[4]; + pPoints[0].setX(0 * m.m11() + 0 * m.m21() + m.dx()); + pPoints[0].setY(0 * m.m12() + 0 * m.m22() + m.dy()); + pPoints[1].setX(m_w * m.m11() + 0 * m.m21() + m.dx()); + pPoints[1].setY(m_w * m.m12() + 0 * m.m22() + m.dy()); + pPoints[2].setX(m_w * m.m11() + m_h * m.m21() + m.dx()); + pPoints[2].setY(m_w * m.m12() + m_h * m.m22() + m.dy()); + pPoints[3].setX(0 * m.m11() + m_h * m.m21() + m.dx()); + pPoints[3].setY(0 * m.m12() + m_h * m.m22() + m.dy()); + + if(PointInPoly(pPoints, 4, pPoint)) { + type = kctBody; + } + + return type; +} + +bool KivioSMLStencil::checkCollisionArc( KivioShape *, KoPoint * ) +{ + return false; +} + + +bool KivioSMLStencil::checkCollisionBezier( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionOpenPath( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionClosedPath( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionPie( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionEllipse( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionLineArray( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionRectangle( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionRoundRectangle( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionPolygon( KivioShape *pShape, KoPoint *pCheckPoint ) +{ + double _x, _y, defWidth, defHeight; + KivioShapeData *pShapeData; + QPtrList<KivioPoint> *pList; + KoPoint *pPoints; + + pShapeData = pShape->shapeData(); + + defWidth = m_pSpawner->defWidth(); + defHeight = m_pSpawner->defHeight(); + + pList = pShapeData->pointList(); + + pPoints = new KoPoint[pList->count()]; + + KivioPoint *pPoint; + int i=0; + pPoint = pList->first(); + while( pPoint ) + { + _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w); + _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h); + + pPoints[i].setX(_x); + pPoints[i].setY(_y); + + i++; + + pPoint = pList->next(); + } + + if( PointInPoly( pPoints, i, pCheckPoint ) ) + { + delete [] pPoints; + return true; + } + + delete [] pPoints; + + return false; +} + +bool KivioSMLStencil::checkCollisionPolyline( KivioShape *, KoPoint * ) +{ + return false; +} + +bool KivioSMLStencil::checkCollisionTextBox( KivioShape *, KoPoint * ) +{ + return false; +} + + +/** + * Return a set of bits representing what resize handles are available. + */ +int KivioSMLStencil::resizeHandlePositions() +{ + // Calculate the resize handle positions + int mask = KIVIO_RESIZE_HANDLE_POSITION_ALL; + + if( m_pProtection->at( kpWidth ) ) + { + mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpE | krhpW); + } + + if( m_pProtection->at( kpHeight ) ) + { + mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpN | krhpS); + } + + if( m_pProtection->at( kpAspect ) ) + { + mask = KIVIO_RESIZE_HANDLE_POSITION_CORNERS; + } + + return mask; +} + +KivioLineStyle KivioSMLStencil::lineStyle() +{ + KivioShape *pShape = m_pShapeList->first(); + + if( pShape ) + return *(pShape->shapeData()->lineStyle()); + + return KivioLineStyle(); +} + +void KivioSMLStencil::setLineStyle(KivioLineStyle ls) +{ + KivioShape *pShape = m_pShapeList->first(); + + while( pShape ) + { + pShape->shapeData()->setLineStyle(ls);; + pShape = m_pShapeList->next(); + } +} + +QString KivioSMLStencil::getTextBoxName(const KoPoint& p) +{ + KivioShape* pShape = m_pShapeList->first(); + KivioShape* first = 0; + KoPoint pos = p; + + // Calculate the rotation... + QWMatrix m; + m.translate(m_x, m_y); + m.translate(m_w / 2.0, m_h / 2.0); + m.rotate(m_rotation); + m.translate(-m_w / 2.0, -m_h / 2.0); + + while(pShape) + { + if(pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox) + { + double x = pShape->shapeData()->x(); + double y = pShape->shapeData()->y(); + double x2 = pShape->shapeData()->w() + x; + double y2 = pShape->shapeData()->h() + y; + + // Create the rotated rectangle + KoPoint pPoints[4]; + pPoints[0].setX(x * m.m11() + y * m.m21() + m.dx()); + pPoints[0].setY(x * m.m12() + y * m.m22() + m.dy()); + pPoints[1].setX(x2 * m.m11() + y * m.m21() + m.dx()); + pPoints[1].setY(x2 * m.m12() + y * m.m22() + m.dy()); + pPoints[2].setX(x2 * m.m11() + y2 * m.m21() + m.dx()); + pPoints[2].setY(x2 * m.m12() + y2 * m.m22() + m.dy()); + pPoints[3].setX(x * m.m11() + y2 * m.m21() + m.dx()); + pPoints[3].setY(x * m.m12() + y2 * m.m22() + m.dy()); + + if(PointInPoly(pPoints, 4, &pos)) { + return pShape->shapeData()->name(); + } + + if(!first) { + first = pShape; + } + } + + pShape = m_pShapeList->next(); + } + + if(first) { + return first->shapeData()->name(); + } + + return QString::null; +} + +void KivioSMLStencil::setText(const QString& text, const QString& name) +{ + KivioShape* pShape = m_pShapeList->first(); + + while(pShape) + { + if(pShape->shapeData()->name() == name) + { + pShape->shapeData()->setText(text); + return; + } + + pShape = m_pShapeList->next(); + } +} + +QString KivioSMLStencil::text(const QString& name) +{ + KivioShape* pShape = m_pShapeList->first(); + + while(pShape) + { + if(pShape->shapeData()->name() == name) + { + return pShape->shapeData()->text(); + } + + pShape = m_pShapeList->next(); + } + + return QString::null; +} + +void KivioSMLStencil::addConnectorTarget(const KoPoint& p) +{ + KivioConnectorTarget* target = new KivioConnectorTarget(p.x(), p.y(), (p.x() - x())/ w(), (p.y() - y())/ h()); + m_pConnectorTargets->append(target); +} + +void KivioSMLStencil::removeConnectorTarget(const KoPoint& pos) +{ + KivioConnectorTarget* target = m_pConnectorTargets->first(); + + while(target) + { + if(target->position() == pos) + { + m_pConnectorTargets->remove(target); + return; + } + + target = m_pConnectorTargets->next(); + } +} + +bool KivioSMLStencil::hasTextBox() const +{ + KivioShape* pShape = m_pShapeList->first(); + while(pShape) { + if(pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox) { + return true; + } + + pShape = m_pShapeList->next(); + } + + return false; +} + +QColor KivioSMLStencil::textColor(const QString& textBoxName) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) + return textColor(); + + return shape->shapeData()->textColor(); +} + +void KivioSMLStencil::setTextColor(const QString& textBoxName, const QColor& color) +{ + KivioShape* shape = locateShape(textBoxName); + + // If we didn't find the shape set the color stencil wide + if(!shape) { + setTextColor(color); + return; + } + + shape->shapeData()->setTextColor(color); +} + +QFont KivioSMLStencil::textFont(const QString& textBoxName) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) + return textFont(); + + return shape->shapeData()->textFont(); +} + +void KivioSMLStencil::setTextFont(const QString& textBoxName, const QFont& font) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) { + setTextFont(font); + return; + } + + shape->shapeData()->setTextFont(font); +} + +int KivioSMLStencil::hTextAlign(const QString& textBoxName) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) + return hTextAlign(); + + return shape->shapeData()->hTextAlign(); +} + +int KivioSMLStencil::vTextAlign(const QString& textBoxName) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) + return vTextAlign(); + + return shape->shapeData()->vTextAlign(); +} + +void KivioSMLStencil::setHTextAlign(const QString& textBoxName, int align) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) { + setHTextAlign(align); + return; + } + + shape->shapeData()->setHTextAlign(align); +} + +void KivioSMLStencil::setVTextAlign(const QString& textBoxName, int align) +{ + KivioShape* shape = locateShape(textBoxName); + + if(!shape) { + setVTextAlign(align); + return; + } + + shape->shapeData()->setVTextAlign(align); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_sml_stencil.h b/kivio/kiviopart/kiviosdk/kivio_sml_stencil.h new file mode 100644 index 000000000..240c99f67 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_sml_stencil.h @@ -0,0 +1,184 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2003 theKompany.com & Dave Marotti, + * Peter Simonsson + * + * 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 KIVIO_SML_STENCIL_H +#define KIVIO_SML_STENCIL_H + +#include <qptrlist.h> + +#include "kivio_stencil.h" +class QDomElement; +class QColor; +class KivioConnectorTarget; +class KivioFillStyle; +class KivioIntraStencilData; +class KivioLineStyle; +class KivioPainter; +class KivioShape; +class KoZoomHandler; + +class KivioSMLStencil : public KivioStencil +{ +protected: + friend class KivioSMLStencilSpawner; + + QPtrList<KivioShape> *m_pShapeList; + KivioShape *m_pSubSelection; + QPtrList<KivioConnectorTarget> *m_pConnectorTargets; + + // Offsets and scale which get reused in between + // various drawing routines. To save time and + // stack space, we keep them around in the class + int _xoff, _yoff; + KoZoomHandler* m_zoomHandler; + +// Drawing routines +protected: + void drawOutlineArc( KivioShape *, KivioIntraStencilData * ); + void drawOutlineBezier( KivioShape *, KivioIntraStencilData * ); + void drawOutlineOpenPath( KivioShape *, KivioIntraStencilData * ); + void drawOutlineClosedPath( KivioShape *, KivioIntraStencilData * ); + void drawOutlinePie( KivioShape *, KivioIntraStencilData * ); + void drawOutlineEllipse( KivioShape *, KivioIntraStencilData * ); + void drawOutlineLineArray( KivioShape *, KivioIntraStencilData * ); + void drawOutlineRectangle( KivioShape *, KivioIntraStencilData * ); + void drawOutlineRoundRectangle( KivioShape *, KivioIntraStencilData * ); + void drawOutlinePolygon( KivioShape *, KivioIntraStencilData * ); + void drawOutlinePolyline( KivioShape *, KivioIntraStencilData * ); + void drawOutlineTextBox( KivioShape *, KivioIntraStencilData * ); + + void drawArc( KivioShape *, KivioIntraStencilData * ); + void drawBezier( KivioShape *, KivioIntraStencilData * ); + void drawOpenPath( KivioShape *, KivioIntraStencilData * ); + void drawClosedPath( KivioShape *, KivioIntraStencilData * ); + void drawPie( KivioShape *, KivioIntraStencilData * ); + void drawEllipse( KivioShape *, KivioIntraStencilData * ); + void drawLineArray( KivioShape *, KivioIntraStencilData * ); + void drawRectangle( KivioShape *, KivioIntraStencilData * ); + void drawRoundRectangle( KivioShape *, KivioIntraStencilData * ); + void drawPolygon( KivioShape *, KivioIntraStencilData * ); + void drawPolyline( KivioShape *, KivioIntraStencilData * ); + void drawTextBox( KivioShape *, KivioIntraStencilData * ); + + bool checkCollisionArc( KivioShape *, KoPoint * ); + bool checkCollisionBezier( KivioShape *, KoPoint * ); + bool checkCollisionOpenPath( KivioShape *, KoPoint * ); + bool checkCollisionClosedPath( KivioShape *, KoPoint * ); + bool checkCollisionPie( KivioShape *, KoPoint * ); + bool checkCollisionEllipse( KivioShape *, KoPoint * ); + bool checkCollisionLineArray( KivioShape *, KoPoint * ); + bool checkCollisionRectangle( KivioShape *, KoPoint * ); + bool checkCollisionRoundRectangle( KivioShape *, KoPoint * ); + bool checkCollisionPolygon( KivioShape *, KoPoint * ); + bool checkCollisionPolyline( KivioShape *, KoPoint * ); + bool checkCollisionTextBox( KivioShape *, KoPoint * ); + + + KivioShape *locateShape( const QString & ); + void loadConnectorTargetListXML( const QDomElement & ); + +public: + KivioSMLStencil(); + virtual ~KivioSMLStencil(); + + + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + + virtual QPtrList<KivioShape> *shapeList() { return m_pShapeList; } + virtual KivioShape *subSelection() { return m_pSubSelection; } + + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paint( KivioIntraStencilData * ); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + + virtual KivioStencil *duplicate(); + + virtual QColor fgColor(); + virtual QColor bgColor(); + virtual void setFGColor(QColor); + virtual void setBGColor(QColor); + virtual void setLineWidth(double); + virtual double lineWidth(); + virtual void setLinePattern(int p); + virtual int linePattern(); + virtual void setFillPattern(int p); + virtual int fillPattern(); + + virtual void setTextColor( QColor ); + virtual void setTextFont( const QFont & ); + + virtual void setHTextAlign(int); + virtual void setVTextAlign(int); + + virtual int hTextAlign(); + virtual int vTextAlign(); + + virtual QString text(); + virtual void setText( const QString & ); + + virtual QFont textFont(); + virtual QColor textColor(); + + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, double ); + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, int ); + + virtual KoPoint snapToTarget( const KoPoint& p, double thresh, bool& hit ); + + virtual void updateGeometry(); + + virtual int generateIds( int ); + + virtual int resizeHandlePositions(); + + virtual KivioLineStyle lineStyle(); + virtual void setLineStyle(KivioLineStyle ls); + + /** + Returns the name of the text box that is at @param p. + If there exist no text box at @param p then it returns QString::null. + */ + virtual QString getTextBoxName(const KoPoint& p); + + virtual void setText(const QString& text, const QString& name); + virtual QString text(const QString& name); + + virtual void addConnectorTarget(const KoPoint&); + virtual void removeConnectorTarget(const KoPoint&); + + virtual bool hasTextBox() const; + + virtual QColor textColor(const QString& textBoxName); + virtual void setTextColor(const QString& textBoxName, const QColor& color); + + virtual QFont textFont(const QString& textBoxName); + virtual void setTextFont(const QString& textBoxName, const QFont& font); + + virtual int hTextAlign(const QString& textBoxName); + virtual int vTextAlign(const QString& textBoxName); + + virtual void setHTextAlign(const QString& textBoxName, int align); + virtual void setVTextAlign(const QString& textBoxName, int align); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp b/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp new file mode 100644 index 000000000..e410d8513 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp @@ -0,0 +1,255 @@ +/* + * 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 "kivio_common.h" +#include "kivio_connector_target.h" +#include "kivio_shape.h" +#include "kivio_shape_data.h" +#include "kivio_sml_stencil.h" +#include "kivio_sml_stencil_spawner.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" + +#include <qdom.h> +#include <qfile.h> +#include <qiodevice.h> +#include <qpainter.h> +#include <qpoint.h> +#include <qpixmap.h> +#include <qrect.h> +#include <qfileinfo.h> + +#include <kdebug.h> + +KivioSMLStencilSpawner::KivioSMLStencilSpawner( KivioStencilSpawnerSet *p ) + : KivioStencilSpawner( p ), + m_pStencil(NULL) +{ + m_pStencil = new KivioSMLStencil(); + + m_pTargets = new QPtrList<KivioConnectorTarget>; + m_pTargets->setAutoDelete(true); +} + +KivioSMLStencilSpawner::~KivioSMLStencilSpawner() +{ + if( m_pStencil ) + { + delete m_pStencil; + m_pStencil = NULL; + } + + if( m_pTargets ) + { + delete m_pTargets; + m_pTargets = NULL; + } + + kdDebug(43000) << "* SMLStencilSpawner "<< m_pInfo->id() << " deleted" << endl; +} + +QDomElement KivioSMLStencilSpawner::saveXML( QDomDocument &doc ) +{ + QDomElement spawnE = doc.createElement("KivioSMLStencilSpawner"); + + XmlWriteString( spawnE, "id", m_pInfo->id() ); + + return spawnE; +} + +bool KivioSMLStencilSpawner::load( const QString &file ) +{ + QDomDocument d("test"); + + m_filename = QString(file); + QFile f(file); + + if( f.open( IO_ReadOnly )==false ) + { + kdDebug(43000) << "KivioSMLStencilSpawner::load() - Error opening stencil: " << file << endl; + return false; + } + d.setContent(&f); + + if(loadXML(file, d)) + { + f.close(); + return true; + } + else + { + f.close(); + return false; + } +} + +bool KivioSMLStencilSpawner::loadXML( const QString &file, QDomDocument &d ) +{ + KivioConnectorTarget *pTarget; + + QDomElement root = d.documentElement(); + QDomElement e; + QDomNode node = root.firstChild(); + QString nodeName; + + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + if( nodeName.compare("KivioSMLStencilSpawnerInfo")==0 ) + { + m_pInfo->loadXML( (const QDomElement)node.toElement() ); + } + else if( nodeName.compare("KivioShape")==0 ) + { + loadShape( node ); + } + else if( nodeName.compare("Dimensions")==0 ) + { + e = node.toElement(); + + m_defWidth = XmlReadFloat( e, "w", 72.0f ); + m_defHeight = XmlReadFloat( e, "h", 72.0f ); + } + else if( nodeName.compare("KivioConnectorTarget")==0 ) + { + pTarget = new KivioConnectorTarget(); + pTarget->loadXML( (const QDomElement)node.toElement() ); + + m_pStencil->m_pConnectorTargets->append( pTarget ); + } + else + { + kdDebug(43000) << "KivioSMLStencilSpawner::load() - Unknown node " << nodeName << " while loading " << file << endl; + } + + node = node.nextSibling(); + } + + pTarget = m_pStencil->m_pConnectorTargets->first(); + + while(pTarget) { + pTarget->setOffsets(pTarget->x() / m_defWidth, pTarget->y() / m_defHeight); + m_pTargets->append(pTarget->duplicate()); + pTarget = m_pStencil->m_pConnectorTargets->next(); + } + + // Now load the xpm + QFileInfo finfo(file); + QString pixFile = finfo.dirPath(true) + "/" + finfo.baseName() + ".xpm"; + + if(!m_icon.load( pixFile )) { + QString pixFile = finfo.dirPath(true) + "/" + finfo.baseName() + ".png"; + m_icon.load( pixFile ); + } + + return true; +} + + +/** + * Loads a shape from an XML node. + */ +void KivioSMLStencilSpawner::loadShape( QDomNode &shapeNode ) +{ + KivioShapeData::KivioShapeType t; + KivioShape *pShape = NULL; + QDomElement shapeElement = shapeNode.toElement(); + + t = KivioShapeData::shapeTypeFromString( XmlReadString( shapeElement, "type", "None" ) ); + + switch( t ) + { + case KivioShapeData::kstNone: + break; + + case KivioShapeData::kstArc: + pShape = KivioShape::loadShapeArc( shapeElement ); + break; + + case KivioShapeData::kstPie: + pShape = KivioShape::loadShapePie( shapeElement ); + break; + + case KivioShapeData::kstLineArray: + pShape = KivioShape::loadShapeLineArray( shapeElement ); + break; + + case KivioShapeData::kstPolyline: + pShape = KivioShape::loadShapePolyline( shapeElement ); + break; + + case KivioShapeData::kstPolygon: + pShape = KivioShape::loadShapePolygon( shapeElement ); + break; + + case KivioShapeData::kstBezier: + pShape = KivioShape::loadShapeBezier( shapeElement ); + break; + + case KivioShapeData::kstRectangle: + pShape = KivioShape::loadShapeRectangle( shapeElement ); + break; + + case KivioShapeData::kstRoundRectangle: + pShape = KivioShape::loadShapeRoundRectangle( shapeElement ); + break; + + case KivioShapeData::kstEllipse: + pShape = KivioShape::loadShapeEllipse( shapeElement ); + break; + + case KivioShapeData::kstOpenPath: + pShape = KivioShape::loadShapeOpenPath( shapeElement ); + break; + + case KivioShapeData::kstClosedPath: + pShape = KivioShape::loadShapeClosedPath( shapeElement ); + break; + + case KivioShapeData::kstTextBox: + pShape = KivioShape::loadShapeTextBox( shapeElement ); + break; + + default: + break; + } + + if( pShape ) + { + m_pStencil->m_pShapeList->append( pShape ); + } + + +} + + +/** + * Returns a new stencil, with default width/height of the spawner settings. +*/ +KivioStencil *KivioSMLStencilSpawner::newStencil() +{ + KivioStencil *pNewStencil = m_pStencil->duplicate(); + + pNewStencil->setSpawner(this); + + pNewStencil->setDimensions( m_defWidth, m_defHeight ); + + return pNewStencil; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.h b/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.h new file mode 100644 index 000000000..bcc8024e0 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.h @@ -0,0 +1,67 @@ +/* + * 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 KIVIO_SML_STENCIL_SPAWNER_H +#define KIVIO_SML_STENCIL_SPAWNER_H + +#include <qdom.h> +#include <qptrlist.h> +#include <qstring.h> + +#include "kivio_stencil_spawner.h" + +class KivioStencilSpawnerSet; +class KivioStencil; +class KivioSMLStencil; +class KivioConnectorTarget; +class QPainter; +class QPixmap; +class QRect; + +class KivioSMLStencilSpawner : public KivioStencilSpawner +{ +protected: + KivioSMLStencil *m_pStencil; + QString m_filename; + + // Target list + QPtrList<KivioConnectorTarget>*m_pTargets; + +protected: + void loadShape( QDomNode & ); + QString readDesc( const QString & ); + +public: + KivioSMLStencilSpawner( KivioStencilSpawnerSet * ); + virtual ~KivioSMLStencilSpawner(); + + virtual bool load( const QString & ); + virtual bool loadXML( const QString &, QDomDocument & ); + + virtual QDomElement saveXML( QDomDocument & ); + + virtual QString &filename() { return m_filename; } + + virtual KivioStencil *newStencil(); + + QPtrList <KivioConnectorTarget> *targets() { return m_pTargets; } +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_stencil.cpp new file mode 100644 index 000000000..e94a9ea2c --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil.cpp @@ -0,0 +1,263 @@ +/* + * 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 "kivio_custom_drag_data.h" +#include "kivio_fill_style.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_painter.h" +#include "kivio_stencil.h" + +#include <KoZoomHandler.h> +#include <KoRect.h> +#include <KIvioStencilIface.h> + +KivioStencil::KivioStencil() + : m_pSpawner(NULL), + m_pProtection(NULL), + m_pCanProtect(NULL) +{ + m_x = m_y = 0.0f; + m_w = m_h = 72.0f; + + m_rotation = 0; + + m_hidden = false; + + m_selected = false; + + m_pProtection = new QBitArray(NUM_PROTECTIONS); + m_pCanProtect = new QBitArray(NUM_PROTECTIONS); + + for( int i = 0; i < NUM_PROTECTIONS; i++ ) + { + m_pProtection->clearBit(i); + m_pCanProtect->setBit(i); + } + + m_type = kstNormal; + m_connected = false; + + iface = new KivioStencilIface(this); +} + +KivioStencil::~KivioStencil() +{ + kdDebug(43000)<<" KivioStencil::~KivioStencil() !"<<this<<endl; + delete m_pProtection; + m_pProtection = NULL; + delete m_pCanProtect; + m_pCanProtect = NULL; + + + m_pSpawner = NULL; +} + +KoRect KivioStencil::rect() +{ + return KoRect( m_x, m_y, m_w, m_h ); +} + + +bool KivioStencil::loadXML( const QDomElement & ) +{ + return false; +} + +QDomElement KivioStencil::saveXML( QDomDocument &doc ) +{ + return doc.createElement(""); +} + +void KivioStencil::paint( KivioIntraStencilData */*pData*/ ) +{ +} + +/* + * Paints the outline of the stencil, no filling is done. + */ +void KivioStencil::paintOutline( KivioIntraStencilData * ) +{ +} + +void KivioStencil::paintConnectorTargets( KivioIntraStencilData * ) +{ +} + +void KivioStencil::paintSelectionHandles( KivioIntraStencilData *pData ) +{ + int newX, newY, newW, newH; + + // Handle Width + //const double HW = 6.0f; + //const double HWP1 = HW+1.0f; + + // Handle Width Over 2 + //const double HWo2 = HW/2.0f; + + KoZoomHandler* zoomHandler = pData->zoomHandler; + + KivioPainter *painter = pData->painter; + + newX = zoomHandler->zoomItX(m_x - qRound(lineWidth() / 2)); + newY = zoomHandler->zoomItY(m_y - qRound(lineWidth() / 2)); + newW = zoomHandler->zoomItX(m_w + lineWidth() + 1); + newH = zoomHandler->zoomItY(m_h + lineWidth() + 1); + + painter->saveState(); + painter->setTranslation(newX, newY); + rotatePainter(pData); // Rotate the painter if needed + + painter->drawSelectionBox(QRect(0, 0, newW, newH)); + + // top left, top right, bottom left, bottom right + if( m_pProtection->at( kpWidth ) || + m_pProtection->at( kpHeight ) ) + { + painter->drawHandle( 0, 0, KivioPainter::cpfLock ); + painter->drawHandle( newW, 0, KivioPainter::cpfLock ); + painter->drawHandle( 0, newH, KivioPainter::cpfLock ); + painter->drawHandle( newW, newH, KivioPainter::cpfLock ); + } + else + { + painter->drawHandle( 0, 0, 0 ); + painter->drawHandle( newW, 0, 0 ); + painter->drawHandle( 0, newH, 0 ); + painter->drawHandle( newW, newH, 0 ); + } + + // Top/bottom + if( m_pProtection->at( kpHeight ) || + m_pProtection->at( kpAspect ) ) + { + painter->drawHandle( newW / 2, 0, KivioPainter::cpfLock ); + painter->drawHandle( newW / 2, newH, KivioPainter::cpfLock ); + } + else + { + painter->drawHandle( newW / 2, 0, 0 ); + painter->drawHandle( newW / 2, newH, 0 ); + } + + // left, right + if( m_pProtection->at( kpWidth ) || + m_pProtection->at( kpAspect ) ) + { + painter->drawHandle( 0, newH / 2, KivioPainter::cpfLock ); + painter->drawHandle( newW, newH / 2, KivioPainter::cpfLock ); + } + else + { + painter->drawHandle( 0, newH / 2, 0 ); + painter->drawHandle( newW, newH / 2, 0 ); + } + painter->restoreState(); +} + +KivioCollisionType KivioStencil::checkForCollision( KoPoint *, double ) +{ + return kctNone; +} + +void KivioStencil::addToGroup( KivioStencil */*pStencil*/ ) +{ + +} + +void KivioStencil::customDrag( KivioCustomDragData * ) +{ +} + +void KivioStencil::updateGeometry() +{ +} + +KivioConnectorTarget *KivioStencil::connectToTarget( KivioConnectorPoint *, double ) +{ + return NULL; +} + +KivioConnectorTarget *KivioStencil::connectToTarget( KivioConnectorPoint *, int ) +{ + return NULL; +} + +KoPoint KivioStencil::snapToTarget( const KoPoint& p, double /*thresh*/, bool& hit ) +{ + KoPoint retVal = p; + hit = false; + return retVal; +} + +int KivioStencil::generateIds(int nextAvailable) +{ + return nextAvailable; +} + +void KivioStencil::searchForConnections( KivioPage * ) +{ +} + +void KivioStencil::searchForConnections( KivioPage *, double ) +{ +} + +void KivioStencil::updateConnectorPoints(KivioConnectorPoint *, double, double) +{ + // Default to just calling updateGeometry + updateGeometry(); +} + +void KivioStencil::rotatePainter(KivioIntraStencilData *pData) +{ + if(m_rotation != 0) { + QWMatrix m; + m.translate(pData->zoomHandler->zoomItX(m_pinPoint.x()), pData->zoomHandler->zoomItY(m_pinPoint.y())); + m.rotate(m_rotation); + m.translate(pData->zoomHandler->zoomItX(-m_pinPoint.x()), pData->zoomHandler->zoomItY(-m_pinPoint.y())); + pData->painter->setWorldMatrix(m, true); + } +} + +KoRect KivioStencil::calculateBoundingBox() +{ + KoRect r; + return r; +} + +void KivioStencil::setRotation(int d) +{ + m_rotation = d; + m_pinPoint.setCoords(m_w / 2.0, m_h / 2.0); + updateGeometry(); +} + +void KivioStencil::move(double xOffset, double yOffset) +{ + setX(x() + xOffset); + setY(y() + yOffset); +} + +bool KivioStencil::isInRect(const KoRect& rect) +{ + bool retVal; + retVal = rect.contains(m_x, m_y); + retVal = retVal && rect.contains(m_x + m_w, m_y + m_h); + + return retVal; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil.h b/kivio/kiviopart/kiviosdk/kivio_stencil.h new file mode 100644 index 000000000..926993f8b --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil.h @@ -0,0 +1,317 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2003 theKompany.com & Dave Marotti, + * Peter Simonsson + * + * 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 KIVIO_STENCIL_H +#define KIVIO_STENCIL_H + +#include <qfont.h> +#include <qcolor.h> +#include <qdom.h> +#include <qptrlist.h> +#include <qbitarray.h> +#include <KoPoint.h> +#include <kglobalsettings.h> +#include <KoRect.h> +#include <koffice_export.h> + +#include "kivio_line_style.h" + +class KivioCustomDragData; +class KivioConnectorPoint; +class KivioConnectorTarget; +class KivioFillStyle; +class KivioIntraStencilData; +class KivioPage; +class KoPoint; +class KoRect; +class KivioStencilSpawner; +class KivioStencil; +class KivioStencilIface; + +// If a custom draggable is clicked, an ID must be returned in the range of kctCustom to MAXINT +typedef enum +{ + kctNone = 0, // No collision + kctBody, // The body of the stencil was clicked + kctCustom=500 // A custom draggable portion was clicked. +} KivioCollisionType; + +typedef enum +{ + kpX = 0, + kpY, + kpWidth, + kpHeight, + kpAspect, + kpDeletion +} KivioProtection; +#define NUM_PROTECTIONS 6 + +typedef enum +{ + krhpNone=0x0000, + krhpNW=0x0001, + krhpN=0x0002, + krhpNE=0x0004, + krhpE=0x0008, + krhpSE=0x0010, + krhpS=0x0020, + krhpSW=0x0040, + krhpW=0x0080, + krhpC=0x0100 +} KivioResizeHandlePosition; + +typedef enum +{ + kstNormal = 0, + kstConnector, + kstGroup, + kstText +} KivioStencilType; + +#define KIVIO_RESIZE_HANDLE_POSITION_ALL \ + ( krhpNW \ + | krhpN \ + | krhpNE \ + | krhpE \ + | krhpSE \ + | krhpS \ + | krhpSW \ + | krhpW \ + | krhpC ) + +#define KIVIO_RESIZE_HANDLE_POSITION_BORDER \ + ( krhpNW \ + | krhpN \ + | krhpNE \ + | krhpE \ + | krhpSE \ + | krhpS \ + | krhpSW \ + | krhpW ) + +#define KIVIO_RESIZE_HANDLE_POSITION_CORNERS \ + ( krhpNW \ + | krhpNE \ + | krhpSE \ + | krhpSW ) + + + +class KIVIO_EXPORT KivioStencil +{ + protected: + // Dimensions, size + double m_x, m_y, m_w, m_h; + + // Rotation + int m_rotation; + KoPoint m_pinPoint; + + // The spawner that created this stencil + KivioStencilSpawner *m_pSpawner; + + // The protection bits of the stencil + QBitArray *m_pProtection; + QBitArray *m_pCanProtect; + + // The stemcil type + KivioStencilType m_type; + bool m_connected; + + // Indicates if this stencil is selected + bool m_selected; + + // Indicates if the stencil is hidden + bool m_hidden; + + protected: + void rotatePainter(KivioIntraStencilData *); + KoRect calculateBoundingBox(); + + public: + KivioStencil(); + virtual ~KivioStencil(); + + virtual KivioStencil *duplicate() { return NULL; } + + virtual KivioStencilType type() { return m_type; } + virtual void setType(KivioStencilType t) { m_type = t; } + virtual bool connected() { return m_connected; } + virtual void setConnected(bool c) { m_connected = c; } + + virtual double x() { return m_x; } + virtual void setX( double f ) { m_x=f; updateGeometry(); } + + virtual double y() { return m_y; } + virtual void setY( double f ) { m_y=f; updateGeometry(); } + + virtual double w() { return m_w; } + virtual void setW( double f ) { if( f > 0 ) { m_w=f; updateGeometry(); } } + + virtual double h() { return m_h; } + virtual void setH( double f ) { if( f > 0 ) { m_h=f; updateGeometry(); } } + + virtual void move(double xOffset, double yOffset); + + virtual KoRect rect(); + + virtual void setPosition( double f1, double f2 ) { m_x=f1; m_y=f2; updateGeometry(); } + virtual void setDimensions( double f1, double f2 ) { m_w=f1; m_h=f2; updateGeometry(); } + + virtual QColor fgColor() { return QColor(0,0,0); } + virtual void setFGColor( QColor ) { ; } + + virtual void setBGColor( QColor ) { ; } + virtual QColor bgColor() { return QColor(0,0,0); } + virtual void setFillPattern(int) { ; } + virtual int fillPattern() { return 1; } + + virtual KivioFillStyle *fillStyle() { return NULL; } + virtual KivioLineStyle lineStyle() { return KivioLineStyle(); } + virtual void setLineStyle(KivioLineStyle) { ; } + + virtual void setLineWidth( double ) { ; } + virtual double lineWidth() { return 1.0f; } + + virtual void setLinePattern(int) { ; } + virtual int linePattern() { return 1; } + + // FOnt stuff + virtual QColor textColor() { return QColor(0,0,0); } + virtual void setTextColor( QColor ) {;} + + virtual QFont textFont() { return KGlobalSettings::generalFont(); } + virtual void setTextFont( const QFont & ) {;} + + virtual int hTextAlign() { return -1; } + virtual int vTextAlign() { return -1; } + + virtual void setHTextAlign(int) { ; } + virtual void setVTextAlign(int) { ; } + + virtual void setText( const QString & ) { ; } + virtual QString text() { return QString(""); } + + virtual void setRotation(int d); + virtual int rotation() { return m_rotation; } + + virtual KivioStencilSpawner *spawner() { return m_pSpawner; } + virtual void setSpawner( KivioStencilSpawner *s ) { m_pSpawner=s; } + + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + virtual void paintConnectorTargets( KivioIntraStencilData * ); + virtual void paintSelectionHandles( KivioIntraStencilData * ); + + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + virtual void customDrag( KivioCustomDragData * ); + + + virtual bool loadXML( const QDomElement & ); + virtual QDomElement saveXML( QDomDocument & ); + + virtual bool isSelected() { return m_selected; } + virtual void select() { m_selected = true; } + virtual void unselect() { m_selected = false; } + virtual void subSelect( const double &, const double & ) { ; } + + virtual QBitArray *protection() { return m_pProtection; } + virtual QBitArray *canProtect() { return m_pCanProtect; } + + virtual void addToGroup( KivioStencil * ); + virtual QPtrList<KivioStencil>* groupList() { return NULL; } + + virtual void updateGeometry(); + virtual void updateConnectorPoints(KivioConnectorPoint *, double oldX, double oldY); + + // This attempts to connect based on position + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, double ); + + // This attempts to connect based on a targetID. This should ***ONLY*** be used + // right after a load + virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, int ); + + virtual KoPoint snapToTarget( const KoPoint& p, double /*thresh*/, bool& hit ); + + virtual void searchForConnections( KivioPage * ); + virtual void searchForConnections( KivioPage *pPage, double threshold ); + + virtual int generateIds( int ); + + virtual int resizeHandlePositions() { return krhpNone; } + + /** + Returns the name of the text box that is at the specified point. + If there exist no text box at the specified point then it returns QString::null. + */ + virtual QString getTextBoxName(const KoPoint& /*p*/) { return QString::null; } + + virtual void setText(const QString& /*text*/, const QString& /*name*/) { ; } + virtual QString text(const QString& /*name*/) { return QString(""); } + + /// Returns true if the stencil has a text box + virtual bool hasTextBox() const { return false; } + + virtual QColor textColor(const QString& /*textBoxName*/) { return QColor(); } + virtual void setTextColor(const QString& /*textBoxName*/, const QColor& /*color*/) {} + + virtual QFont textFont(const QString& /*textBoxName*/) { return KGlobalSettings::generalFont(); } + virtual void setTextFont(const QString& /*textBoxName*/, const QFont& /*font*/) {} + + virtual int hTextAlign(const QString& /*textBoxName*/) { return -1; } + virtual int vTextAlign(const QString& /*textBoxName*/) { return -1; } + + virtual void setHTextAlign(const QString& /*textBoxName*/, int /*align*/) {} + virtual void setVTextAlign(const QString& /*textBoxName*/, int /*align*/) {} + + virtual void setPinPoint(const KoPoint& p) { m_pinPoint = p; } + virtual KoPoint pinPoint() const { return m_pinPoint; } + + virtual void addConnectorTarget(const KoPoint&) {} + virtual void removeConnectorTarget(const KoPoint&) {} + + virtual bool isInRect(const KoRect& rect); + + virtual void setHidden(bool hide) { m_hidden = hide; } + virtual bool hidden() { return m_hidden; } + + virtual void setCustomIDPoint(int, const KoPoint&, KivioPage*) {} + virtual KoPoint customIDPoint(int) { return KoPoint(); } + + /****** ARROW HEAD STUFF *******/ + virtual void setStartAHType( int ) { ; } + virtual void setStartAHWidth( double ) { ; } + virtual void setStartAHLength( double ) { ; } + virtual void setEndAHType( int ) { ; } + virtual void setEndAHWidth( double ) { ; } + virtual void setEndAHLength( double ) { ; } + + virtual int startAHType() { return 0; } + virtual double startAHWidth() { return 0.0f; } + virtual double startAHLength() { return 0.0f; } + virtual int endAHType() { return 0; } + virtual double endAHWidth() { return 0.0f; } + virtual double endAHLength() { return 0.0f; } + + private: + KivioStencilIface *iface; +}; + +#endif diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.cpp b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.cpp new file mode 100644 index 000000000..70f5ff083 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.cpp @@ -0,0 +1,72 @@ +/* + * 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 "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil.h" + + +KivioStencilSpawner::KivioStencilSpawner( KivioStencilSpawnerSet *p ) + : m_pInfo(NULL) +{ + m_pInfo = new KivioStencilSpawnerInfo(); + m_pSet = p; + m_fileName = ""; + m_defWidth = 72.0f; + m_defHeight = 72.0f; +} + +KivioStencilSpawner::~KivioStencilSpawner() +{ + if( m_pInfo ) + { + delete m_pInfo; + m_pInfo = NULL; + } + + m_pSet = NULL; + m_fileName = ""; +} + + +bool KivioStencilSpawner::load( const QString & ) +{ + return false; +} + +bool KivioStencilSpawner::loadXML( const QString &, QDomDocument & ) +{ + return false; +} + + +KivioStencil *KivioStencilSpawner::newStencil() +{ + return NULL; +} + +KivioStencil *KivioStencilSpawner::newStencil(const QString& /*name*/) +{ + return NULL; +} + +QDomElement KivioStencilSpawner::saveXML( QDomDocument &doc ) +{ + return doc.createElement("KivioStencilSpawner"); +} diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.h b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.h new file mode 100644 index 000000000..7ef999938 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.h @@ -0,0 +1,70 @@ +/* + * 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 KIVIO_STENCIL_SPAWNER_H +#define KIVIO_STENCIL_SPAWNER_H + +#include <qstring.h> +#include <qpixmap.h> +#include <qdom.h> +#include <qobject.h> + +class QPainter; +class QRect; +class KivioStencilSpawnerInfo; +class KivioStencilSpawnerSet; +class KivioStencil; + +class KivioStencilSpawner +{ +protected: + QString m_fileName; + QPixmap m_icon; + KivioStencilSpawnerSet *m_pSet; + KivioStencilSpawnerInfo *m_pInfo; + + // Default width and height + float m_defWidth, m_defHeight; + +public: + KivioStencilSpawner( KivioStencilSpawnerSet * ); + virtual ~KivioStencilSpawner(); + + virtual bool load( const QString & ); + virtual bool loadXML( const QString &, QDomDocument & ); + virtual QDomElement saveXML( QDomDocument & ); + + virtual KivioStencil *newStencil(); + virtual KivioStencil *newStencil(const QString& args); + + virtual QString fileName() { return m_fileName; } + virtual KivioStencilSpawnerSet *set() { return m_pSet; } + virtual KivioStencilSpawnerInfo *info() { return m_pInfo; } + + virtual float defWidth() { return m_defWidth; } + virtual float defHeight() { return m_defHeight; } + + virtual QPixmap *icon() { return &m_icon; } + + +// virtual void drawIcon( QPainter *, QRect *, bool ); +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_info.cpp b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_info.cpp new file mode 100644 index 000000000..12a179191 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_info.cpp @@ -0,0 +1,126 @@ +/* + * 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 "kivio_stencil_spawner_info.h" +#include <qdom.h> + +#include <kglobal.h> +#include <klocale.h> + +KivioStencilSpawnerInfo::KivioStencilSpawnerInfo() +{ + m_author = "Joe Bob"; + m_title = "Untitled"; + m_id = ""; + m_desc = "No desc"; + m_version = "1.0"; + m_web = "http://kivio.sourceforge.net"; + m_email = "landshark@ameritech.net"; + m_autoUpdate = ""; +} + +KivioStencilSpawnerInfo::~KivioStencilSpawnerInfo() +{ +} + +KivioStencilSpawnerInfo::KivioStencilSpawnerInfo( const QString &auth, const QString &tit, const QString &_id, const QString &des, const QString &ver, const QString &wb, + const QString &em, const QString &au ) +{ + m_author = auth; + m_title = tit; + m_id = _id; + m_desc = des; + m_version = ver; + m_web = wb; + m_email = em; + m_autoUpdate = au; +} + +bool KivioStencilSpawnerInfo::loadXML( const QDomElement &e ) +{ + QDomNode node; + QDomElement nodeElement; + QString nodeName, origTitle, origDesc; + m_title = ""; + m_desc = ""; + + node = e.firstChild(); + while(!node.isNull()) + { + nodeName = node.nodeName(); + + nodeElement = node.toElement(); + + if( nodeName.compare("Author")==0 ) + { + m_author = nodeElement.attribute("data"); + } + else if((nodeName.compare("Title")==0) && nodeElement.hasAttribute("lang")) + { + if(nodeElement.attribute("lang") == KGlobal::locale()->language()) { + m_title = nodeElement.attribute("data"); + } + } + else if((nodeName.compare("Title")==0) && !nodeElement.hasAttribute("lang")) + { + origTitle = nodeElement.attribute("data"); + } + else if( nodeName.compare("Id")==0 ) + { + m_id = nodeElement.attribute("data"); + } + else if((nodeName.compare("Description")==0) && nodeElement.hasAttribute("lang")) + { + if(nodeElement.attribute("lang") == KGlobal::locale()->language()) { + m_desc = nodeElement.attribute("data"); + } + } + else if((nodeName.compare("Description")==0) && !nodeElement.hasAttribute("lang")) + { + origDesc = nodeElement.attribute("data"); + } + else if( nodeName.compare("Version")==0 ) + { + m_version = nodeElement.attribute("data"); + } + else if( nodeName.compare("Web")==0 ) + { + m_web = nodeElement.attribute("data"); + } + else if( nodeName.compare("Email")==0 ) + { + m_email = nodeElement.attribute("data"); + } + else if( nodeName.compare("AutoUpdate")==0 ) + { + m_autoUpdate = nodeElement.attribute("data"); + } + + if(m_title.isEmpty()) { + m_title = i18n( "Stencils", origTitle.utf8()); + } + + if(m_desc.isEmpty()) { + m_desc = i18n( "Stencils", origDesc.utf8()); + } + + node = node.nextSibling(); + } + + return true; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_info.h b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_info.h new file mode 100644 index 000000000..9c676d660 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_info.h @@ -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. + */ +#ifndef KIVIO_STENCIL_SPAWNER_INFO_H +#define KIVIO_STENCIL_SPAWNER_INFO_H + +#include <qstring.h> +#include <koffice_export.h> +class QDomElement; +class KIVIO_EXPORT KivioStencilSpawnerInfo +{ +protected: + QString m_author, + m_title, + m_id, + m_desc, + m_version, + m_web, + m_email, + m_autoUpdate; + +public: + KivioStencilSpawnerInfo(); + KivioStencilSpawnerInfo( const QString &, const QString &, const QString &, const QString &, const QString &, const QString &, const QString &, const QString & ); + virtual ~KivioStencilSpawnerInfo(); + + bool loadXML( const QDomElement & ); + + + QString author() { return m_author; } + QString title() { return m_title; } + QString id() { return m_id; } + QString desc() { return m_desc; } + QString version() { return m_version; } + QString web() { return m_web; } + QString email() { return m_email; } + QString autoUpdate() { return m_autoUpdate; } + +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp new file mode 100644 index 000000000..66339a0ea --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp @@ -0,0 +1,319 @@ +/* + * 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 "kivio_common.h" +#include "kivio_plugin_stencil_spawner.h" +#include "kivio_sml_stencil_spawner.h" +#include "kivio_dia_stencil_spawner.h" +#include "kivio_py_stencil_spawner.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_set.h" + +#include <qdir.h> +#include <qfile.h> +#include <qstring.h> +#include <kdebug.h> +#include <kglobal.h> +#include <klocale.h> + +KivioStencilSpawnerSet::KivioStencilSpawnerSet(const QString& name) + : m_pSpawners(NULL), + m_pSelected(NULL) +{ + m_hidden = false; + m_dir = ""; + m_name = name.isEmpty() ? QString("Untitled") : name; + + m_pSpawners = new QPtrList<KivioStencilSpawner>; + m_pSpawners->setAutoDelete(true); +} + +KivioStencilSpawnerSet::~KivioStencilSpawnerSet() +{ + delete m_pSpawners; + m_pSpawners = NULL; + kdDebug(43000) << "KivioStencilSpawnerSet::~KivioStencilSpawnerSet() - " << m_name << endl; +} + + +/** + * Loads a stencil spawners from data defined in an XML file + * + * @param e The @ref QDomElement to load from + * + * This is a function that needs to be implemented by all descendant + * classes. It should search the known stencil-paths for the spawner + * specified, and load it. + */ +bool KivioStencilSpawnerSet::loadXML( const QDomElement & ) +{ + return false; +} + + +/** + * Saves a spawner to a @ref QDomElement + * + * @param doc The document to save to + * + * All descendant classes should implement this function. It should + * save the necessary data to a @ref QDomElement such that when + * it is loaded again, it can find the spawner and load it from + * the local filesystem. + */ +QDomElement KivioStencilSpawnerSet::saveXML( QDomDocument &doc ) +{ + QDomElement spawnE = doc.createElement("KivioStencilSpawnerSet"); + + XmlWriteString( spawnE, "id", m_id ); + XmlWriteString(spawnE, "hidden", (m_hidden ? "true" : "false")); + + KivioStencilSpawner *pSpawner = m_pSpawners->first(); + while( pSpawner ) + { + spawnE.appendChild( pSpawner->saveXML( doc ) ); + + pSpawner = m_pSpawners->next(); + } + + + return spawnE; +} + +bool KivioStencilSpawnerSet::loadDir( const QString &dirName ) +{ + QDir d(dirName); + QString fileName; + + m_dir = dirName; + m_name = readTitle( dirName ); + m_id = readId( dirName ); + + d.setNameFilter("*.so *.sml *.ksp *.spy *.shape"); + m_files = d.entryList(); + + return true; +} + +KivioStencilSpawner* KivioStencilSpawnerSet::loadFile( const QString &fileName ) +{ + for (KivioStencilSpawner* ss = m_pSpawners->first(); ss; ss = m_pSpawners->next() ) + if (ss->fileName() == fileName) + return ss; + + KivioStencilSpawner *pSpawner; + + if( fileName.contains( ".sml", false ) ) + { + pSpawner = new KivioSMLStencilSpawner(this); + } + else if( fileName.contains( ".ksp", false ) ) + { + pSpawner = new KivioPluginStencilSpawner(this); + } + else if( fileName.contains( ".so", false ) ) + { + pSpawner = new KivioPluginStencilSpawner(this); + } + else if( fileName.contains( ".spy", false ) ) + { + pSpawner = new KivioPyStencilSpawner(this); + } + else if( fileName.contains( ".shape", false ) ) + { + pSpawner = new KivioDiaStencilSpawner(this); + } + else + { + return 0; + } + + if( pSpawner->load( fileName )==true ) + m_pSpawners->append( pSpawner ); + else + { + delete pSpawner; + return 0; + } + + return pSpawner; +} + +QString KivioStencilSpawnerSet::readTitle( const QString &dir ) +{ + QDomDocument d("StencilSPawnerSet"); + QDomElement root, nodeElement; + QDomNode node; + QString nodeName; + QString title, origTitle; + QFile f(dir+"/desc"); + + if( f.open( IO_ReadOnly )==false ) + { + kdDebug(43000) << "KivioStencilSpawnerSet::readTitle() - Error opening stencil set title: " << + dir << "/desc" << endl; + return dir.right(dir.length() - dir.findRev('/')-1); + } + + d.setContent(&f); + + root = d.documentElement(); + node = root.firstChild(); + + while( !node.isNull() ) + { + nodeName = node.nodeName(); + nodeElement = node.toElement(); + + if( nodeName.compare("Title")==0 && nodeElement.hasAttribute("lang")) + { + if(nodeElement.attribute("lang") == KGlobal::locale()->language()) { + title = XmlReadString( nodeElement, "data", dir ); + } + } + else if( nodeName.compare("Title")==0 && !nodeElement.hasAttribute("lang")) + { + origTitle = XmlReadString( nodeElement, "data", dir ); + } + + node = node.nextSibling(); + } + + if(title.isEmpty()) { + title = i18n( "Stencils", origTitle.utf8() ); + } + + return title; +} + +QString KivioStencilSpawnerSet::readId( const QString &dir ) +{ + QDomDocument d("StencilSPawnerSet"); + QDomElement root; + QDomNode node; + QString nodeName; + QString theid; + QFile f(dir+"/desc"); + + if( f.open( IO_ReadOnly )==false ) + { + kdDebug(43000) << "KivioStencilSpawnerSet::readId() - Error opening stencil set description: " << + dir << "/desc" << endl; + return ""; + } + + d.setContent(&f); + + root = d.documentElement(); + node = root.firstChild(); + + while( !node.isNull() ) + { + nodeName = node.nodeName(); + + if( nodeName.compare("Id")==0 ) + { + theid = XmlReadString( node.toElement(), "data", dir ); + return theid; + } + + node = node.nextSibling(); + } + + kdDebug(43000) << "KivioStencilSpawnerSet::readId() - No id found in " + << dir << "/desc" << endl; + + return ""; +} + +QString KivioStencilSpawnerSet::readDescription(const QString& dir) +{ + QDomDocument d("StencilSPawnerSet"); + QDomElement root, nodeElement; + QDomNode node; + QString nodeName; + QFile f(dir + "/desc"); + + if( f.open( IO_ReadOnly )==false ) + { + kdDebug(43000) << "KivioStencilSpawnerSet::readId() - Error opening stencil set description: " << + dir << "/desc" << endl; + return ""; + } + + d.setContent(&f); + + root = d.documentElement(); + node = root.firstChild(); + QString description, origDesc; + + while( !node.isNull() ) + { + nodeName = node.nodeName(); + nodeElement = node.toElement(); + + if( nodeName.compare("Description")==0 && nodeElement.hasAttribute("lang")) + { + if(nodeElement.attribute("lang") == KGlobal::locale()->language()) { + description = nodeElement.text(); + } + } + else if( nodeName.compare("Description")==0 && !nodeElement.hasAttribute("lang")) + { + origDesc = nodeElement.text(); + } + + node = node.nextSibling(); + } + + if(description.isEmpty() && !origDesc.isEmpty()) { + description = i18n( "Stencils", origDesc.utf8() ); + } + + return description; +} + + +KivioStencilSpawner* KivioStencilSpawnerSet::find( const QString& id) +{ + if(!m_pSpawners || m_pSpawners->isEmpty()) { + return 0; + } + + KivioStencilSpawner* pSpawner = m_pSpawners->first(); + + while( pSpawner ) + { + // If the id matches, this is it! + if( pSpawner->info()->id() == id ) + { + return pSpawner; + } + + pSpawner = m_pSpawners->next(); + } + + return NULL; +} + +void KivioStencilSpawnerSet::addSpawner(KivioStencilSpawner* spawner) +{ + if(spawner) { + m_pSpawners->append(spawner); + } +} diff --git a/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.h b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.h new file mode 100644 index 000000000..717fdd727 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.h @@ -0,0 +1,82 @@ +/* + * 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 KIVIO_STENCIL_SPAWNER_SET_H +#define KIVIO_STENCIL_SPAWNER_SET_H + +#include <qptrlist.h> +#include <qdom.h> + +class KivioStencilSpawner; +class QStringList; + +class KivioStencilSpawnerSet +{ + protected: + QString m_dir; + QString m_name; + QString m_id; + + QStringList m_files; + + QPtrList<KivioStencilSpawner> *m_pSpawners; + KivioStencilSpawner *m_pSelected; + + bool m_hidden; + + public: + KivioStencilSpawnerSet(const QString& name=QString::null); + virtual ~KivioStencilSpawnerSet(); + + bool loadDir( const QString & ); + KivioStencilSpawner* loadFile( const QString & ); + + bool loadXML( const QDomElement & ); + QDomElement saveXML( QDomDocument & ); + + QPtrList<KivioStencilSpawner> *spawners() { return m_pSpawners; } + KivioStencilSpawner *selected() { return m_pSelected; } + + QString dir() { return m_dir; } + QString name() { return m_name; } + QString id() { return m_id; } + + void setDir( const QString &s ) { m_dir=s; } + void setName( const QString &s ) { m_name=s; } + void setId( const QString &s ) { m_id=s; } + + KivioStencilSpawner *spawnerAt( int i ) { return m_pSpawners->at(i); } + KivioStencilSpawner *find( const QString& ); + + int count() { return m_pSpawners->count(); } + + static QString readTitle( const QString & ); + static QString readId( const QString & ); + static QString readDescription(const QString&); + + QStringList files() const { return m_files; } + + void addSpawner(KivioStencilSpawner* spawner); + + void setHidden(bool hide) { m_hidden = hide; } + bool hidden() const { return m_hidden; } +}; + +#endif + + diff --git a/kivio/kiviopart/kiviosdk/kivio_text_style.cpp b/kivio/kiviopart/kiviosdk/kivio_text_style.cpp new file mode 100644 index 000000000..75d975d59 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_text_style.cpp @@ -0,0 +1,88 @@ +#include "kivio_common.h" +#include "kivio_text_style.h" +#include <qdom.h> +#include <qpainter.h> +#include <KoGlobal.h> + +KivioTextStyle::KivioTextStyle() +{ + m_text = ""; + m_color = QColor(0,0,0); + m_hTextAlign = Qt::AlignHCenter; + m_vTextAlign = Qt::AlignVCenter; + m_isHtml = false; + //m_font = QFont("times",12); + m_font = KoGlobal::defaultFont(); +} + +KivioTextStyle::~KivioTextStyle() +{ +} + +void KivioTextStyle::copyInto( KivioTextStyle *pTarget ) +{ + pTarget->m_text = m_text; + pTarget->m_color = m_color; + pTarget->m_hTextAlign = m_hTextAlign; + pTarget->m_vTextAlign = m_vTextAlign; + pTarget->m_isHtml = m_isHtml; + pTarget->m_font = m_font; +} + +QDomElement KivioTextStyle::saveXML( QDomDocument &doc ) +{ + QDomElement textE = doc.createElement("KivioTextStyle"); + + XmlWriteString( textE, "text", m_text ); + XmlWriteInt( textE, "isHtml", m_isHtml ); + XmlWriteInt( textE, "hTextAlign", m_hTextAlign ); + XmlWriteInt( textE, "vTextAlign", m_vTextAlign ); + + // Text font & color + QDomElement innerTextE = doc.createElement("Font"); + XmlWriteColor( innerTextE, "color", m_color ); + XmlWriteString( innerTextE, "family", m_font.family() ); + XmlWriteInt( innerTextE, "size", m_font.pointSize() ); + XmlWriteInt( innerTextE, "bold", m_font.bold() ); + XmlWriteInt( innerTextE, "italic", m_font.italic() ); + XmlWriteInt( innerTextE, "underline", m_font.underline() ); + XmlWriteInt( innerTextE, "strikeOut", m_font.strikeOut() ); + XmlWriteInt( innerTextE, "fixedPitch", m_font.fixedPitch() ); + + textE.appendChild( innerTextE ); + + return textE; +} + +bool KivioTextStyle::loadXML( const QDomElement &e ) +{ + m_text = XmlReadString( e, "text", "" ); + m_isHtml = (bool)XmlReadInt( e, "isHtml", (int)false ); + + m_hTextAlign = XmlReadInt( e, "hTextAlign", Qt::AlignHCenter ); + m_vTextAlign = XmlReadInt( e, "vTextAlign", Qt::AlignVCenter ); + + // Search for the font + QDomNode innerNode = e.firstChild(); + while( !innerNode.isNull() ) + { + QString innerName = innerNode.nodeName(); + QDomElement innerE = innerNode.toElement(); + + if( innerName == "Font" ) + { + m_font.setFamily( XmlReadString(innerE, "family", "times") ); + m_font.setPointSize( XmlReadInt(innerE, "size", 12 ) ); + m_font.setBold( (bool)XmlReadInt( innerE, "bold", 12 ) ); + m_font.setItalic( (bool)XmlReadInt( innerE, "italic", 12 ) ); + m_font.setUnderline( (bool)XmlReadInt( innerE, "underline", 12 ) ); + m_font.setStrikeOut( (bool)XmlReadInt( innerE, "strikeOut", 12 ) ); + m_font.setFixedPitch( (bool)XmlReadInt( innerE, "fixedPitch", false ) ); + m_color = XmlReadColor( innerE, "color", QColor(0,0,0) ); + } + + innerNode = innerNode.nextSibling(); + } + + return true; +} diff --git a/kivio/kiviopart/kiviosdk/kivio_text_style.h b/kivio/kiviopart/kiviosdk/kivio_text_style.h new file mode 100644 index 000000000..5ce3afe99 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_text_style.h @@ -0,0 +1,56 @@ +#ifndef KIVIO_TEXT_STYLE_H +#define KIVIO_TEXT_STYLE_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qfont.h> + +class QDomDocument; +class QPainter; + + +class KivioTextStyle +{ +protected: + QString m_text; // The text inside this shape + QColor m_color; // The text color + QFont m_font; // The text font + bool m_isHtml; // Is the text HTML formatted? + int m_hTextAlign, m_vTextAlign; // Horizontal and vertical text alignment flags + +public: + KivioTextStyle(); + virtual ~KivioTextStyle(); + + QDomElement saveXML( QDomDocument & ); + bool loadXML( const QDomElement & ); + + void copyInto( KivioTextStyle * ); + + + + + inline QString text() { return m_text; } + inline void setText( QString s ) { m_text=s; } + + inline QColor color() { return m_color; } + inline void setColor( QColor c ) { m_color=c; } + + inline QFont font() { return m_font; } + inline void setFont( QFont f ) { m_font=f; } + + inline bool isHtml() { return m_isHtml; } + inline void setIsHtml( bool b ) { m_isHtml=b; } + + inline int hTextAlign() { return m_hTextAlign; } + inline void setHTextAlign(int i) { m_hTextAlign=i; } + + inline int vTextAlign() { return m_vTextAlign; } + inline void setVTextAlign(int i) { m_vTextAlign=i; } + +}; + +#endif + diff --git a/kivio/kiviopart/kiviosdk/kivio_wrap.cpp b/kivio/kiviopart/kiviosdk/kivio_wrap.cpp new file mode 100644 index 000000000..ede8a8890 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kivio_wrap.cpp @@ -0,0 +1,1770 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3u-20000719-0930 (Alpha 3) + * + * Portions Copyright (c) 1995-2000 + * The University of Utah, The Regents of the University of California, and + * The University of Chicago. Permission is hereby granted to use, modify, + * and distribute this file in any manner provided this notice remains intact. + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +/* Implementation : PYTHON */ +#include <config.h> + +#ifdef HAVE_PYTHON + +#define SWIGPYTHON +/*********************************************************************** + * python.swg + * + * This file contains the runtime support for Python modules + * and includes code for managing global variables and pointer + * type checking. + * + * Author : David Beazley (beazley@cs.uchicago.edu) + * + * Copyright (c) 1999-2000, The University of Chicago + * + * This file may be freely redistributed without license or fee provided + * this copyright message remains intact. + ************************************************************************/ + +#include <string.h> +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif +#include "Python.h" + +#if defined(_WIN32) || defined(__WIN32__) +# if defined(_MSC_VER) +# if defined(STATIC_LINKED) +# define SWIGEXPORT(a) a +# else +# define SWIGEXPORT(a) __declspec(dllexport) a +# endif +# else +# if defined(__BORLANDC__) +# define SWIGEXPORT(a) a _export +# else +# define SWIGEXPORT(a) a +# endif +#endif +#else +# define SWIGEXPORT(a) a +#endif + +#ifdef SWIG_GLOBAL +#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a) +#else +#define SWIGSTATICRUNTIME(a) static a +#endif + +/* Type information structure */ + +typedef struct _swig_type_info { + char *name; + void *(*converter)(void *); + struct _swig_type_info *next; + struct _swig_type_info *prev; +} _swig_type_info; + +/* Constant information structure */ +typedef struct _swig_const_info { + int type; + char *name; + long lvalue; + double dvalue; + void *pvalue; + _swig_type_info **ptype; +} _swig_const_info; + +#define SWIG_PY_INT 1 +#define SWIG_PY_FLOAT 2 +#define SWIG_PY_STRING 3 +#define SWIG_PY_POINTER 4 + +#ifdef SWIG_NOINCLUDE + +SWIGEXPORT(PyObject *) SWIG_newvarlink(); +SWIGEXPORT(void) SWIG_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *)); +SWIGEXPORT(_swig_type_info *) SWIG_TypeRegister(_swig_type_info *); +SWIGEXPORT(_swig_type_info *) SWIG_TypeCheck(char *, _swig_type_info *); +SWIGEXPORT(int) SWIG_ConvertPtr(PyObject *, void **, _swig_type_info *, int); +SWIGEXPORT(void) SWIG_MakePtr(char *c, void *, _swig_type_info *); +SWIGEXPORT(PyObject *) SWIG_NewPointerObj(void *, _swig_type_info *); +SWIGEXPORT(void) SWIG_InstallConstants(PyObject *d, _swig_const_info constants[]); + +/* External declarations when using runtime libraries */ + +#else + +/* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + +typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; +} swig_globalvar; + +typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; +} swig_varlinkobject; + +static PyObject * +swig_varlink_repr(swig_varlinkobject *v) { + v = v; + return PyString_FromString("<Global variables>"); +} + +static int +swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) { + swig_globalvar *var; + flags = flags; + fprintf(fp,"Global variables { "); + for (var = v->vars; var; var=var->next) { + fprintf(fp,"%s", var->name); + if (var->next) fprintf(fp,", "); + } + fprintf(fp," }\n"); + return 0; +} + +static PyObject * +swig_varlink_getattr(swig_varlinkobject *v, char *n) { + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + return (*var->get_attr)(); + } + var = var->next; + } + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + return NULL; +} + +static int +swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + return (*var->set_attr)(p); + } + var = var->next; + } + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + return 1; +} + +statichere PyTypeObject varlinktype = { + PyObject_HEAD_INIT(0) + 0, + "swigvarlink", /* Type name */ + sizeof(swig_varlinkobject), /* Basic size */ + 0, /* Itemsize */ + 0, /* Deallocator */ + (printfunc) swig_varlink_print, /* Print */ + (getattrfunc) swig_varlink_getattr, /* get attr */ + (setattrfunc) swig_varlink_setattr, /* Set attr */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_mapping*/ + 0, /* tp_hash */ +}; + +/* Create a variable linking object for use later */ +SWIGSTATICRUNTIME(PyObject *) +SWIG_newvarlink(void) { + swig_varlinkobject *result = 0; + result = PyMem_NEW(swig_varlinkobject,1); + varlinktype.ob_type = &PyType_Type; /* Patch varlinktype into a PyType */ + result->ob_type = &varlinktype; + result->vars = 0; + result->ob_refcnt = 0; + Py_XINCREF((PyObject *) result); + return ((PyObject*) result); +} + +SWIGSTATICRUNTIME(void) +SWIG_addvarlink(PyObject *p, char *name, + PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v; + swig_globalvar *gv; + v= (swig_varlinkobject *) p; + gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + gv->name = (char *) malloc(strlen(name)+1); + strcpy(gv->name,name); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + v->vars = gv; +} + +/* ----------------------------------------------------------------------------- + * Pointer type-checking + * ----------------------------------------------------------------------------- */ + +static _swig_type_info *swig_types = 0; + +/* Register type mappings with the type-checker */ +SWIGSTATICRUNTIME(_swig_type_info *) +SWIG_TypeRegister(_swig_type_info *ti) { + _swig_type_info *tc, *head, *ret, *next; + /* Check to see if this type has already been registered */ + tc = swig_types; + while (tc) { + if (strcmp(tc->name, ti->name) == 0) { + /* Already exists in the table. Just add additional types to the list */ + head = tc; + next = tc->next; + goto l1; + } + tc = tc->prev; + } + head = ti; + next = 0; + + /* Place in list */ + ti->prev = swig_types; + swig_types = ti; + + /* Build linked lists */ + l1: + ret = head; + tc = ti + 1; + while (tc->name) { + head->next = tc; + tc->prev = head; + head = tc; + tc++; + } + head->next = next; + return ret; +} + +/* Check the typename */ +SWIGSTATICRUNTIME(_swig_type_info *) +SWIG_TypeCheck(char *c, _swig_type_info *ty) { + _swig_type_info *s; + char *sn; + if (!ty) return 0; /* Void pointer */ + s = ty->next; /* First element is always just the name */ + while (s) { + sn = s->name; + if ((c == sn) || ((*c == *sn) && (strcmp(sn,c) == 0))) { + if (s == ty->next) return s; + /* Move s to the top of the linked list */ + s->prev->next = s->next; + if (s->next) { + s->next->prev = s->prev; + } + /* Insert s as second element in the list */ + s->next = ty->next; + if (ty->next) ty->next->prev = s; + ty->next = s; + return s; + } + s = s->next; + } + return 0; +} + +/* Convert a pointer value */ +SWIGSTATICRUNTIME(int) +SWIG_ConvertPtr(PyObject *obj, void **ptr, _swig_type_info *ty, int flags) { + unsigned long p; + register int d; + _swig_type_info *tc; + char *c; + static PyObject *SWIG_this = 0; + + if (!obj || (obj == Py_None)) { + *ptr = 0; + return 0; + } +#ifdef SWIG_COBJECT_TYPES + if (!(PyCObject_Check(obj))) { + if (!SWIG_this) + SWIG_this = PyString_InternFromString("this"); + obj = PyObject_GetAttr(obj,SWIG_this); + if ((!obj) || !(PyCObject_Check(obj))) goto type_error; + } + *ptr = PyCObject_AsVoidPtr(obj); + c = (char *) PyCObject_GetDesc(obj); + goto cobject; +#else + if (!(PyString_Check(obj))) { + if (!SWIG_this) + SWIG_this = PyString_InternFromString("this"); + obj = PyObject_GetAttr(obj,SWIG_this); + if ((!obj) || !(PyString_Check(obj))) goto type_error; + } + c = PyString_AsString(obj); + p = 0; + /* Pointer values must start with leading underscore */ + if (*c != '_') { + *ptr = (void *) 0; + if (strcmp(c,"NULL") == 0) return 0; + } + c++; + /* Extract hex value from pointer */ + while (d = *c) { + if ((d >= '0') && (d <= '9')) + p = (p << 4) + (d - '0'); + else if ((d >= 'a') && (d <= 'f')) + p = (p << 4) + (d - ('a'-10)); + else + break; + c++; + } + *ptr = (void *) p; +#endif + +#ifdef SWIG_COBJECT_TYPES +cobject: +#endif + + if (ty) { + tc = SWIG_TypeCheck(c,ty); + if (!tc) goto type_error; + if (tc->converter) { + *ptr = (*tc->converter)((void *) p); + } + } + return 0; + +type_error: + if (flags) { + if (ty) { + char *temp = (char *) malloc(64+strlen(ty->name)); + sprintf(temp,"Type error. Expected %s", ty->name); + PyErr_SetString(PyExc_TypeError, temp); + free((char *) temp); + } else { + PyErr_SetString(PyExc_TypeError,"Expected a pointer"); + } + } + return -1; +} + +/* Take a pointer and convert it to a string */ +SWIGSTATICRUNTIME(void) +SWIG_MakePtr(char *c, void *ptr, _swig_type_info *ty) { + static char hex[17] = "0123456789abcdef"; + unsigned long p, s; + char result[32], *r; + r = result; + p = (unsigned long) ptr; + if (p > 0) { + while (p > 0) { + s = p & 0xf; + *(r++) = hex[s]; + p = p >> 4; + } + *r = '_'; + while (r >= result) + *(c++) = *(r--); + strcpy (c, ty->name); + } else { + strcpy (c, "NULL"); + } +} + +/* Create a new pointer object */ +SWIGSTATICRUNTIME(PyObject *) +SWIG_NewPointerObj(void *ptr, _swig_type_info *type) { + char result[512]; + PyObject *robj; + if (!ptr) { + Py_INCREF(Py_None); + return Py_None; + } +#ifdef SWIG_COBJECT_TYPES + robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL); +#else + SWIG_MakePtr(result,ptr,type); + robj = PyString_FromString(result); +#endif + return robj; +} + +/* Install Constants */ +SWIGSTATICRUNTIME(void) +SWIG_InstallConstants(PyObject *d, _swig_const_info constants[]) { + int i; + PyObject *obj; + for (i = 0; constants[i].type; i++) { + switch(constants[i].type) { + case SWIG_PY_INT: + obj = PyInt_FromLong(constants[i].lvalue); + break; + case SWIG_PY_FLOAT: + obj = PyFloat_FromDouble(constants[i].dvalue); + break; + case SWIG_PY_STRING: + obj = PyString_FromString((char *) constants[i].pvalue); + break; + case SWIG_PY_POINTER: + obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d,constants[i].name,obj); + Py_DECREF(obj); + } + } +} + +#endif + +#ifdef __cplusplus +} +#endif + + +/* ---- TYPES TABLE (BEGIN) ---- */ +#define SWIGTYPE_KivioPage_p _swig_types[0] +#define SWIGTYPE_float_p _swig_types[1] +#define SWIGTYPE_KivioFillStyle_p _swig_types[2] +#define SWIGTYPE_KoRect_p _swig_types[3] +#define SWIGTYPE_KivioStencil_p _swig_types[4] +#define SWIGTYPE_KivioLayer_p _swig_types[5] +static _swig_type_info *_swig_types[7]; +/* ---- TYPES TABLE (END) ---- */ + +#define SWIG_init initkivioc + +#define SWIG_name "kivioc" + + #include "config.h" + +#include "kivio_stencil.h" + +#include "kivio_layer.h" + +#include "kivio_layers.h" +#ifdef __cplusplus +extern "C" { +#endif +static PyObject *_wrap_update(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":update")) + return NULL; + update(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_isStencilSelected(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + bool _result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:isStencilSelected",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (bool )isStencilSelected(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +static PyObject *_wrap_selectAllStencils(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":selectAllStencils")) + return NULL; + selectAllStencils(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_unselectAllStencils(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":unselectAllStencils")) + return NULL; + unselectAllStencils(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_unselectStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + bool _result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:unselectStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (bool )unselectStencil(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +static PyObject *_wrap_selectStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:selectStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + selectStencil(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_curLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,":curLayer")) + return NULL; + _result = (KivioLayer *)curLayer(); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +static PyObject *_wrap_setCurLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:setCurLayer",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + setCurLayer(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_firstLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,":firstLayer")) + return NULL; + _result = (KivioLayer *)firstLayer(); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +static PyObject *_wrap_nextLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,":nextLayer")) + return NULL; + _result = (KivioLayer *)nextLayer(); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +static PyObject *_wrap_lastLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,":lastLayer")) + return NULL; + _result = (KivioLayer *)lastLayer(); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +static PyObject *_wrap_prevLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,":prevLayer")) + return NULL; + _result = (KivioLayer *)prevLayer(); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +static PyObject *_wrap_removeCurrentLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj; + bool _result; + self = self; + if(!PyArg_ParseTuple(args,":removeCurrentLayer")) + return NULL; + _result = (bool )removeCurrentLayer(); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +static PyObject *_wrap_addLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:addLayer",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + addLayer(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_insertLayer(PyObject *self, PyObject *args) { + int _arg0; + PyObject *_resultobj,*_argo1=0; + KivioLayer *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"iO:insertLayer",&_arg0,&_argo1)) + return NULL; + if ((SWIG_ConvertPtr(_argo1,(void **) &_arg1,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + insertLayer(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_layerAt(PyObject *self, PyObject *args) { + int _arg0; + PyObject *_resultobj; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,"i:layerAt",&_arg0)) + return NULL; + _result = (KivioLayer *)layerAt(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +static PyObject *_wrap_addStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + bool _result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:addStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (bool )addStencil(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +static PyObject *_wrap_deleteSelectedStencils(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":deleteSelectedStencils")) + return NULL; + deleteSelectedStencils(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_groupSelectedStencils(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":groupSelectedStencils")) + return NULL; + groupSelectedStencils(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_ungroupSelectedStencils(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":ungroupSelectedStencils")) + return NULL; + ungroupSelectedStencils(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_bringToFront(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":bringToFront")) + return NULL; + bringToFront(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_sendToBack(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":sendToBack")) + return NULL; + sendToBack(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_copy(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":copy")) + return NULL; + copy(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_cut(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":cut")) + return NULL; + cut(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static PyObject *_wrap_paste(PyObject *self, PyObject *args) { + PyObject *_resultobj; + self = self; + if(!PyArg_ParseTuple(args,":paste")) + return NULL; + paste(); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define new_KivioStencil() (new KivioStencil()) +static PyObject *_wrap_new_KivioStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj; + KivioStencil *_result; + self = self; + if(!PyArg_ParseTuple(args,":new_KivioStencil")) + return NULL; + _result = (KivioStencil *)new_KivioStencil(); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define delete_KivioStencil(_swigobj) (delete _swigobj) +static PyObject *_wrap_delete_KivioStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:delete_KivioStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + delete_KivioStencil(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_duplicate(_swigobj) (_swigobj->duplicate()) +static PyObject *_wrap_KivioStencil_duplicate(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_result,*_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_duplicate",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioStencil_duplicate(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define KivioStencil_x(_swigobj) (_swigobj->x()) +static PyObject *_wrap_KivioStencil_x(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_x",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_x(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_setX(_swigobj,_swigarg0) (_swigobj->setX(_swigarg0)) +static PyObject *_wrap_KivioStencil_setX(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setX",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setX(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_y(_swigobj) (_swigobj->y()) +static PyObject *_wrap_KivioStencil_y(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_y",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_y(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_setY(_swigobj,_swigarg0) (_swigobj->setY(_swigarg0)) +static PyObject *_wrap_KivioStencil_setY(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setY",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setY(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_w(_swigobj) (_swigobj->w()) +static PyObject *_wrap_KivioStencil_w(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_w",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_w(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_setW(_swigobj,_swigarg0) (_swigobj->setW(_swigarg0)) +static PyObject *_wrap_KivioStencil_setW(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setW",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setW(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_h(_swigobj) (_swigobj->h()) +static PyObject *_wrap_KivioStencil_h(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_h",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_h(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_setH(_swigobj,_swigarg0) (_swigobj->setH(_swigarg0)) +static PyObject *_wrap_KivioStencil_setH(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setH",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setH(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_rect(_swigobj) (_swigobj->rect()) +static PyObject *_wrap_KivioStencil_rect(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KoRect *_result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_rect",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = new KoRect (KivioStencil_rect(_arg0)); + _resultobj = SWIG_NewPointerObj((void *)_result, SWIGTYPE_KoRect_p); + return _resultobj; +} + +#define KivioStencil_setPosition(_swigobj,_swigarg0,_swigarg1) (_swigobj->setPosition(_swigarg0,_swigarg1)) +static PyObject *_wrap_KivioStencil_setPosition(PyObject *self, PyObject *args) { + float _arg1,_arg2; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Off:KivioStencil_setPosition",&_argo0,&_arg1,&_arg2)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setPosition(_arg0,_arg1,_arg2); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setDimensions(_swigobj,_swigarg0,_swigarg1) (_swigobj->setDimensions(_swigarg0,_swigarg1)) +static PyObject *_wrap_KivioStencil_setDimensions(PyObject *self, PyObject *args) { + float _arg1,_arg2; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Off:KivioStencil_setDimensions",&_argo0,&_arg1,&_arg2)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setDimensions(_arg0,_arg1,_arg2); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_fillStyle(_swigobj) (_swigobj->fillStyle()) +static PyObject *_wrap_KivioStencil_fillStyle(PyObject *self, PyObject *args) { + KivioFillStyle *_result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_fillStyle",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (KivioFillStyle *)KivioStencil_fillStyle(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioFillStyle_p); + return _resultobj; +} + +#define KivioStencil_setLineWidth(_swigobj,_swigarg0) (_swigobj->setLineWidth(_swigarg0)) +static PyObject *_wrap_KivioStencil_setLineWidth(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setLineWidth",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setLineWidth(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_lineWidth(_swigobj) (_swigobj->lineWidth()) +static PyObject *_wrap_KivioStencil_lineWidth(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_lineWidth",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_lineWidth(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_hTextAlign(_swigobj) (_swigobj->hTextAlign()) +static PyObject *_wrap_KivioStencil_hTextAlign(PyObject *self, PyObject *args) { + int _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_hTextAlign",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (int )KivioStencil_hTextAlign(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioStencil_vTextAlign(_swigobj) (_swigobj->vTextAlign()) +static PyObject *_wrap_KivioStencil_vTextAlign(PyObject *self, PyObject *args) { + int _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_vTextAlign",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (int )KivioStencil_vTextAlign(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioStencil_setHTextAlign(_swigobj,_swigarg0) (_swigobj->setHTextAlign(_swigarg0)) +static PyObject *_wrap_KivioStencil_setHTextAlign(PyObject *self, PyObject *args) { + int _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Oi:KivioStencil_setHTextAlign",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setHTextAlign(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setVTextAlign(_swigobj,_swigarg0) (_swigobj->setVTextAlign(_swigarg0)) +static PyObject *_wrap_KivioStencil_setVTextAlign(PyObject *self, PyObject *args) { + int _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Oi:KivioStencil_setVTextAlign",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setVTextAlign(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static void KivioStencil_setText(KivioStencil *self,char * s) { self->setText( QString(s)); } +static PyObject *_wrap_KivioStencil_setText(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + char *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"Os:KivioStencil_setText",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setText(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static char * KivioStencil_text(KivioStencil *self) { return (char*) self->text().latin1(); } +static PyObject *_wrap_KivioStencil_text(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + char *_result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_text",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (char *)KivioStencil_text(_arg0); + _resultobj = Py_BuildValue("s", _result); + return _resultobj; +} + +static char * KivioStencil_textColor(KivioStencil *self) { return (char*) self->textColor().name().latin1(); } +static PyObject *_wrap_KivioStencil_textColor(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + char *_result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_textColor",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (char *)KivioStencil_textColor(_arg0); + _resultobj = Py_BuildValue("s", _result); + return _resultobj; +} + +static void KivioStencil_setTextColor(KivioStencil *self,char * color) { self->setTextColor(QColor(color)); } +static PyObject *_wrap_KivioStencil_setTextColor(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + char *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"Os:KivioStencil_setTextColor",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setTextColor(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static char * KivioStencil_fgColor(KivioStencil *self) { return (char*) self->fgColor().name().latin1(); } +static PyObject *_wrap_KivioStencil_fgColor(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + char *_result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_fgColor",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (char *)KivioStencil_fgColor(_arg0); + _resultobj = Py_BuildValue("s", _result); + return _resultobj; +} + +static void KivioStencil_setFGColor(KivioStencil *self,char * color) { self->setFGColor(QColor(color)); } +static PyObject *_wrap_KivioStencil_setFGColor(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + char *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"Os:KivioStencil_setFGColor",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setFGColor(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +static char * KivioStencil_bgColor(KivioStencil *self) { return (char*) self->bgColor().name().latin1(); } +static PyObject *_wrap_KivioStencil_bgColor(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + char *_result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_bgColor",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (char *)KivioStencil_bgColor(_arg0); + _resultobj = Py_BuildValue("s", _result); + return _resultobj; +} + +static void KivioStencil_setBGColor(KivioStencil *self,char * color) { self->setBGColor(QColor(color)); } +static PyObject *_wrap_KivioStencil_setBGColor(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + char *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"Os:KivioStencil_setBGColor",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setBGColor(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_isSelected(_swigobj) (_swigobj->isSelected()) +static PyObject *_wrap_KivioStencil_isSelected(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + bool _result; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_isSelected",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (bool )KivioStencil_isSelected(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioStencil_select(_swigobj) (_swigobj->select()) +static PyObject *_wrap_KivioStencil_select(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_select",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_select(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_unselect(_swigobj) (_swigobj->unselect()) +static PyObject *_wrap_KivioStencil_unselect(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_unselect",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_unselect(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_subSelect(_swigobj,_swigarg0,_swigarg1) (_swigobj->subSelect(_swigarg0,_swigarg1)) +static PyObject *_wrap_KivioStencil_subSelect(PyObject *self, PyObject *args) { + float *_arg1,*_arg2; + PyObject *_resultobj,*_argo0=0,*_argo1=0,*_argo2=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"OOO:KivioStencil_subSelect",&_argo0,&_argo1,&_argo2)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + if ((SWIG_ConvertPtr(_argo1,(void **) &_arg1,SWIGTYPE_float_p,1)) == -1) return NULL; + if ((SWIG_ConvertPtr(_argo2,(void **) &_arg2,SWIGTYPE_float_p,1)) == -1) return NULL; + KivioStencil_subSelect(_arg0,*_arg1,*_arg2); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_addToGroup(_swigobj,_swigarg0) (_swigobj->addToGroup(_swigarg0)) +static PyObject *_wrap_KivioStencil_addToGroup(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0,*_argo1=0; + KivioStencil *_arg0,*_arg1; + self = self; + if(!PyArg_ParseTuple(args,"OO:KivioStencil_addToGroup",&_argo0,&_argo1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + if ((SWIG_ConvertPtr(_argo1,(void **) &_arg1,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_addToGroup(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_updateGeometry(_swigobj) (_swigobj->updateGeometry()) +static PyObject *_wrap_KivioStencil_updateGeometry(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_updateGeometry",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_updateGeometry(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setStartAHType(_swigobj,_swigarg0) (_swigobj->setStartAHType(_swigarg0)) +static PyObject *_wrap_KivioStencil_setStartAHType(PyObject *self, PyObject *args) { + int _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Oi:KivioStencil_setStartAHType",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setStartAHType(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setStartAHWidth(_swigobj,_swigarg0) (_swigobj->setStartAHWidth(_swigarg0)) +static PyObject *_wrap_KivioStencil_setStartAHWidth(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setStartAHWidth",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setStartAHWidth(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setStartAHLength(_swigobj,_swigarg0) (_swigobj->setStartAHLength(_swigarg0)) +static PyObject *_wrap_KivioStencil_setStartAHLength(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setStartAHLength",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setStartAHLength(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setEndAHType(_swigobj,_swigarg0) (_swigobj->setEndAHType(_swigarg0)) +static PyObject *_wrap_KivioStencil_setEndAHType(PyObject *self, PyObject *args) { + int _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Oi:KivioStencil_setEndAHType",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setEndAHType(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setEndAHWidth(_swigobj,_swigarg0) (_swigobj->setEndAHWidth(_swigarg0)) +static PyObject *_wrap_KivioStencil_setEndAHWidth(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setEndAHWidth",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setEndAHWidth(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_setEndAHLength(_swigobj,_swigarg0) (_swigobj->setEndAHLength(_swigarg0)) +static PyObject *_wrap_KivioStencil_setEndAHLength(PyObject *self, PyObject *args) { + float _arg1; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"Of:KivioStencil_setEndAHLength",&_argo0,&_arg1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + KivioStencil_setEndAHLength(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioStencil_startAHType(_swigobj) (_swigobj->startAHType()) +static PyObject *_wrap_KivioStencil_startAHType(PyObject *self, PyObject *args) { + int _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_startAHType",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (int )KivioStencil_startAHType(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioStencil_startAHWidth(_swigobj) (_swigobj->startAHWidth()) +static PyObject *_wrap_KivioStencil_startAHWidth(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_startAHWidth",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_startAHWidth(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_startAHLength(_swigobj) (_swigobj->startAHLength()) +static PyObject *_wrap_KivioStencil_startAHLength(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_startAHLength",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_startAHLength(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_endAHType(_swigobj) (_swigobj->endAHType()) +static PyObject *_wrap_KivioStencil_endAHType(PyObject *self, PyObject *args) { + int _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_endAHType",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (int )KivioStencil_endAHType(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioStencil_endAHWidth(_swigobj) (_swigobj->endAHWidth()) +static PyObject *_wrap_KivioStencil_endAHWidth(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_endAHWidth",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_endAHWidth(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define KivioStencil_endAHLength(_swigobj) (_swigobj->endAHLength()) +static PyObject *_wrap_KivioStencil_endAHLength(PyObject *self, PyObject *args) { + float _result; + PyObject *_resultobj,*_argo0=0; + KivioStencil *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioStencil_endAHLength",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (float )KivioStencil_endAHLength(_arg0); + _resultobj = Py_BuildValue("f",_result); + return _resultobj; +} + +#define new_KivioLayer(_swigarg0) (new KivioLayer(_swigarg0)) +static PyObject *_wrap_new_KivioLayer(PyObject *self, PyObject *args) { + KivioPage *_arg0; + PyObject *_resultobj,*_argo0=0; + KivioLayer *_result; + self = self; + if(!PyArg_ParseTuple(args,"O:new_KivioLayer",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioPage_p,1)) == -1) return NULL; + _result = (KivioLayer *)new_KivioLayer(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioLayer_p); + return _resultobj; +} + +#define delete_KivioLayer(_swigobj) (delete _swigobj) +static PyObject *_wrap_delete_KivioLayer(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:delete_KivioLayer",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + delete_KivioLayer(_arg0); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioLayer_visible(_swigobj) (_swigobj->visible()) +static PyObject *_wrap_KivioLayer_visible(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + bool _result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_visible",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (bool )KivioLayer_visible(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioLayer_setVisible(_swigobj,_swigarg0) (_swigobj->setVisible(_swigarg0)) +static PyObject *_wrap_KivioLayer_setVisible(PyObject *self, PyObject *args) { + int tempbool1; + PyObject *_resultobj,*_argo0=0; + KivioLayer *_arg0; + bool _arg1; + self = self; + if(!PyArg_ParseTuple(args,"Oi:KivioLayer_setVisible",&_argo0,&tempbool1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _arg1 = (bool ) tempbool1; + KivioLayer_setVisible(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioLayer_connectable(_swigobj) (_swigobj->connectable()) +static PyObject *_wrap_KivioLayer_connectable(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + bool _result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_connectable",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (bool )KivioLayer_connectable(_arg0); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioLayer_setConnectable(_swigobj,_swigarg0) (_swigobj->setConnectable(_swigarg0)) +static PyObject *_wrap_KivioLayer_setConnectable(PyObject *self, PyObject *args) { + int tempbool1; + PyObject *_resultobj,*_argo0=0; + KivioLayer *_arg0; + bool _arg1; + self = self; + if(!PyArg_ParseTuple(args,"Oi:KivioLayer_setConnectable",&_argo0,&tempbool1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _arg1 = (bool ) tempbool1; + KivioLayer_setConnectable(_arg0,_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define KivioLayer_addStencil(_swigobj,_swigarg0) (_swigobj->addStencil(_swigarg0)) +static PyObject *_wrap_KivioLayer_addStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0,*_argo1=0; + bool _result; + KivioLayer *_arg0; + KivioStencil *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"OO:KivioLayer_addStencil",&_argo0,&_argo1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + if ((SWIG_ConvertPtr(_argo1,(void **) &_arg1,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (bool )KivioLayer_addStencil(_arg0,_arg1); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioLayer_removeStencil(_swigobj,_swigarg0) (_swigobj->removeStencil(_swigarg0)) +static PyObject *_wrap_KivioLayer_removeStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0,*_argo1=0; + bool _result; + KivioLayer *_arg0; + KivioStencil *_arg1; + self = self; + if(!PyArg_ParseTuple(args,"OO:KivioLayer_removeStencil",&_argo0,&_argo1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + if ((SWIG_ConvertPtr(_argo1,(void **) &_arg1,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (bool )KivioLayer_removeStencil(_arg0,_arg1); + _resultobj = Py_BuildValue("i",_result); + return _resultobj; +} + +#define KivioLayer_firstStencil(_swigobj) (_swigobj->firstStencil()) +static PyObject *_wrap_KivioLayer_firstStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_firstStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioLayer_firstStencil(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define KivioLayer_nextStencil(_swigobj) (_swigobj->nextStencil()) +static PyObject *_wrap_KivioLayer_nextStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_nextStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioLayer_nextStencil(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define KivioLayer_prevStencil(_swigobj) (_swigobj->prevStencil()) +static PyObject *_wrap_KivioLayer_prevStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_prevStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioLayer_prevStencil(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define KivioLayer_currentStencil(_swigobj) (_swigobj->currentStencil()) +static PyObject *_wrap_KivioLayer_currentStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_currentStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioLayer_currentStencil(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define KivioLayer_lastStencil(_swigobj) (_swigobj->lastStencil()) +static PyObject *_wrap_KivioLayer_lastStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0; + KivioStencil *_result; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"O:KivioLayer_lastStencil",&_argo0)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioLayer_lastStencil(_arg0); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +#define KivioLayer_takeStencil(_swigobj,_swigarg0) (_swigobj->takeStencil(_swigarg0)) +static PyObject *_wrap_KivioLayer_takeStencil(PyObject *self, PyObject *args) { + PyObject *_resultobj,*_argo0=0,*_argo1=0; + KivioStencil *_result,*_arg1; + KivioLayer *_arg0; + self = self; + if(!PyArg_ParseTuple(args,"OO:KivioLayer_takeStencil",&_argo0,&_argo1)) + return NULL; + if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_KivioLayer_p,1)) == -1) return NULL; + if ((SWIG_ConvertPtr(_argo1,(void **) &_arg1,SWIGTYPE_KivioStencil_p,1)) == -1) return NULL; + _result = (KivioStencil *)KivioLayer_takeStencil(_arg0,_arg1); + _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_KivioStencil_p); + return _resultobj; +} + +static PyMethodDef kiviocMethods[] = { + { "KivioLayer_takeStencil", _wrap_KivioLayer_takeStencil, METH_VARARGS }, + { "KivioLayer_lastStencil", _wrap_KivioLayer_lastStencil, METH_VARARGS }, + { "KivioLayer_currentStencil", _wrap_KivioLayer_currentStencil, METH_VARARGS }, + { "KivioLayer_prevStencil", _wrap_KivioLayer_prevStencil, METH_VARARGS }, + { "KivioLayer_nextStencil", _wrap_KivioLayer_nextStencil, METH_VARARGS }, + { "KivioLayer_firstStencil", _wrap_KivioLayer_firstStencil, METH_VARARGS }, + { "KivioLayer_removeStencil", _wrap_KivioLayer_removeStencil, METH_VARARGS }, + { "KivioLayer_addStencil", _wrap_KivioLayer_addStencil, METH_VARARGS }, + { "KivioLayer_setConnectable", _wrap_KivioLayer_setConnectable, METH_VARARGS }, + { "KivioLayer_connectable", _wrap_KivioLayer_connectable, METH_VARARGS }, + { "KivioLayer_setVisible", _wrap_KivioLayer_setVisible, METH_VARARGS }, + { "KivioLayer_visible", _wrap_KivioLayer_visible, METH_VARARGS }, + { "delete_KivioLayer", _wrap_delete_KivioLayer, METH_VARARGS }, + { "new_KivioLayer", _wrap_new_KivioLayer, METH_VARARGS }, + { "KivioStencil_endAHLength", _wrap_KivioStencil_endAHLength, METH_VARARGS }, + { "KivioStencil_endAHWidth", _wrap_KivioStencil_endAHWidth, METH_VARARGS }, + { "KivioStencil_endAHType", _wrap_KivioStencil_endAHType, METH_VARARGS }, + { "KivioStencil_startAHLength", _wrap_KivioStencil_startAHLength, METH_VARARGS }, + { "KivioStencil_startAHWidth", _wrap_KivioStencil_startAHWidth, METH_VARARGS }, + { "KivioStencil_startAHType", _wrap_KivioStencil_startAHType, METH_VARARGS }, + { "KivioStencil_setEndAHLength", _wrap_KivioStencil_setEndAHLength, METH_VARARGS }, + { "KivioStencil_setEndAHWidth", _wrap_KivioStencil_setEndAHWidth, METH_VARARGS }, + { "KivioStencil_setEndAHType", _wrap_KivioStencil_setEndAHType, METH_VARARGS }, + { "KivioStencil_setStartAHLength", _wrap_KivioStencil_setStartAHLength, METH_VARARGS }, + { "KivioStencil_setStartAHWidth", _wrap_KivioStencil_setStartAHWidth, METH_VARARGS }, + { "KivioStencil_setStartAHType", _wrap_KivioStencil_setStartAHType, METH_VARARGS }, + { "KivioStencil_updateGeometry", _wrap_KivioStencil_updateGeometry, METH_VARARGS }, + { "KivioStencil_addToGroup", _wrap_KivioStencil_addToGroup, METH_VARARGS }, + { "KivioStencil_subSelect", _wrap_KivioStencil_subSelect, METH_VARARGS }, + { "KivioStencil_unselect", _wrap_KivioStencil_unselect, METH_VARARGS }, + { "KivioStencil_select", _wrap_KivioStencil_select, METH_VARARGS }, + { "KivioStencil_isSelected", _wrap_KivioStencil_isSelected, METH_VARARGS }, + { "KivioStencil_setBGColor", _wrap_KivioStencil_setBGColor, METH_VARARGS }, + { "KivioStencil_bgColor", _wrap_KivioStencil_bgColor, METH_VARARGS }, + { "KivioStencil_setFGColor", _wrap_KivioStencil_setFGColor, METH_VARARGS }, + { "KivioStencil_fgColor", _wrap_KivioStencil_fgColor, METH_VARARGS }, + { "KivioStencil_setTextColor", _wrap_KivioStencil_setTextColor, METH_VARARGS }, + { "KivioStencil_textColor", _wrap_KivioStencil_textColor, METH_VARARGS }, + { "KivioStencil_text", _wrap_KivioStencil_text, METH_VARARGS }, + { "KivioStencil_setText", _wrap_KivioStencil_setText, METH_VARARGS }, + { "KivioStencil_setVTextAlign", _wrap_KivioStencil_setVTextAlign, METH_VARARGS }, + { "KivioStencil_setHTextAlign", _wrap_KivioStencil_setHTextAlign, METH_VARARGS }, + { "KivioStencil_vTextAlign", _wrap_KivioStencil_vTextAlign, METH_VARARGS }, + { "KivioStencil_hTextAlign", _wrap_KivioStencil_hTextAlign, METH_VARARGS }, + { "KivioStencil_lineWidth", _wrap_KivioStencil_lineWidth, METH_VARARGS }, + { "KivioStencil_setLineWidth", _wrap_KivioStencil_setLineWidth, METH_VARARGS }, + { "KivioStencil_fillStyle", _wrap_KivioStencil_fillStyle, METH_VARARGS }, + { "KivioStencil_setDimensions", _wrap_KivioStencil_setDimensions, METH_VARARGS }, + { "KivioStencil_setPosition", _wrap_KivioStencil_setPosition, METH_VARARGS }, + { "KivioStencil_rect", _wrap_KivioStencil_rect, METH_VARARGS }, + { "KivioStencil_setH", _wrap_KivioStencil_setH, METH_VARARGS }, + { "KivioStencil_h", _wrap_KivioStencil_h, METH_VARARGS }, + { "KivioStencil_setW", _wrap_KivioStencil_setW, METH_VARARGS }, + { "KivioStencil_w", _wrap_KivioStencil_w, METH_VARARGS }, + { "KivioStencil_setY", _wrap_KivioStencil_setY, METH_VARARGS }, + { "KivioStencil_y", _wrap_KivioStencil_y, METH_VARARGS }, + { "KivioStencil_setX", _wrap_KivioStencil_setX, METH_VARARGS }, + { "KivioStencil_x", _wrap_KivioStencil_x, METH_VARARGS }, + { "KivioStencil_duplicate", _wrap_KivioStencil_duplicate, METH_VARARGS }, + { "delete_KivioStencil", _wrap_delete_KivioStencil, METH_VARARGS }, + { "new_KivioStencil", _wrap_new_KivioStencil, METH_VARARGS }, + { "paste", _wrap_paste, METH_VARARGS }, + { "cut", _wrap_cut, METH_VARARGS }, + { "copy", _wrap_copy, METH_VARARGS }, + { "sendToBack", _wrap_sendToBack, METH_VARARGS }, + { "bringToFront", _wrap_bringToFront, METH_VARARGS }, + { "ungroupSelectedStencils", _wrap_ungroupSelectedStencils, METH_VARARGS }, + { "groupSelectedStencils", _wrap_groupSelectedStencils, METH_VARARGS }, + { "deleteSelectedStencils", _wrap_deleteSelectedStencils, METH_VARARGS }, + { "addStencil", _wrap_addStencil, METH_VARARGS }, + { "layerAt", _wrap_layerAt, METH_VARARGS }, + { "insertLayer", _wrap_insertLayer, METH_VARARGS }, + { "addLayer", _wrap_addLayer, METH_VARARGS }, + { "removeCurrentLayer", _wrap_removeCurrentLayer, METH_VARARGS }, + { "prevLayer", _wrap_prevLayer, METH_VARARGS }, + { "lastLayer", _wrap_lastLayer, METH_VARARGS }, + { "nextLayer", _wrap_nextLayer, METH_VARARGS }, + { "firstLayer", _wrap_firstLayer, METH_VARARGS }, + { "setCurLayer", _wrap_setCurLayer, METH_VARARGS }, + { "curLayer", _wrap_curLayer, METH_VARARGS }, + { "selectStencil", _wrap_selectStencil, METH_VARARGS }, + { "unselectStencil", _wrap_unselectStencil, METH_VARARGS }, + { "unselectAllStencils", _wrap_unselectAllStencils, METH_VARARGS }, + { "selectAllStencils", _wrap_selectAllStencils, METH_VARARGS }, + { "isStencilSelected", _wrap_isStencilSelected, METH_VARARGS }, + { "update", _wrap_update, METH_VARARGS }, + { NULL, NULL } +}; +#ifdef __cplusplus +} +#endif +static _swig_type_info _swigt__KivioPage_p[] = {{"_KivioPage_p",0},{"_KivioPage_p",0},{0}}; +static _swig_type_info _swigt__float_p[] = {{"_float_p",0},{"_float_p",0},{0}}; +static _swig_type_info _swigt__KivioFillStyle_p[] = {{"_KivioFillStyle_p",0},{"_KivioFillStyle_p",0},{0}}; +static _swig_type_info _swigt__KoRect_p[] = {{"_KoRect_p",0},{"_KoRect_p",0},{0}}; +static _swig_type_info _swigt__KivioStencil_p[] = {{"_KivioStencil_p",0},{"_KivioStencil_p",0},{0}}; +static _swig_type_info _swigt__KivioLayer_p[] = {{"_KivioLayer_p",0},{"_KivioLayer_p",0},{0}}; + +static _swig_type_info *_swig_types_initial[] = { +_swigt__KivioPage_p, +_swigt__float_p, +_swigt__KivioFillStyle_p, +_swigt__KoRect_p, +_swigt__KivioStencil_p, +_swigt__KivioLayer_p, +0 +}; + +static _swig_const_info _swig_const_table[] = { +{0}}; + +static PyObject *SWIG_globals; +#ifdef __cplusplus +extern "C" +#endif +SWIGEXPORT(void) initkivioc(void) { + PyObject *m, *d; + SWIG_globals = SWIG_newvarlink(); + m = Py_InitModule("kivioc", kiviocMethods); + d = PyModule_GetDict(m); + { + int i; + for (i = 0; _swig_types_initial[i]; i++) { + _swig_types[i] = SWIG_TypeRegister(_swig_types_initial[i]); + } + } + SWIG_InstallConstants(d,_swig_const_table); + +} +#endif // HAVE_PYTHON + diff --git a/kivio/kiviopart/kiviosdk/kiviopolylineconnector.cpp b/kivio/kiviopart/kiviosdk/kiviopolylineconnector.cpp new file mode 100644 index 000000000..9afe2f9e0 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kiviopolylineconnector.cpp @@ -0,0 +1,497 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Peter Simonsson <psn@linux.se>, + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kiviopolylineconnector.h" + +#include <kdebug.h> + +#include <KoZoomHandler.h> +#include <KoSize.h> + +#include "kivio_line_style.h" +#include "kivio_painter.h" +#include "kivio_intra_stencil_data.h" +#include "kivio_connector_point.h" +#include "kivio_custom_drag_data.h" +#include "tkmath.h" +#include "kivio_page.h" +#include "kivio_layer.h" +#include "kivio_common.h" + + +namespace Kivio { + PolyLineConnector::PolyLineConnector() + : Kivio1DStencil() + { + m_startArrow = new KivioArrowHead(); + m_endArrow = new KivioArrowHead(); + + m_needsWidth = false; + m_needsText = false; // FIXME add text support + + 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); + } + + PolyLineConnector::~PolyLineConnector() + { + delete m_startArrow; + delete m_endArrow; + } + + KivioStencil* PolyLineConnector::duplicate() + { + PolyLineConnector* connector = new PolyLineConnector(); + copyBasicInto(connector); + connector->m_points = m_points; + + // Copy the arrow head information + connector->setStartAHType( m_startArrow->type() ); + connector->setStartAHWidth( m_startArrow->width() ); + connector->setStartAHLength( m_startArrow->length() ); + + connector->setEndAHType( m_endArrow->type() ); + connector->setEndAHWidth( m_endArrow->width() ); + connector->setEndAHLength( m_endArrow->length() ); + + return connector; + } + + bool PolyLineConnector::loadCustom(const QDomElement& e) + { + QDomNode node = e.firstChild(); + QString nodeName; + m_points.clear(); + + while(!node.isNull()) { + nodeName = node.nodeName(); + + if(nodeName == "KivioArrowHeads") { + loadArrowHeads(node.toElement()); + } else if(nodeName == "KivioGeometryPoints") { + QDomNode pointsNode = node.firstChild(); + QDomElement el; + + while(!pointsNode.isNull()) { + if(pointsNode.nodeName() == "KivioPoint") { + el = pointsNode.toElement(); + KoPoint p; + p.setX(XmlReadFloat(el, "x", 1.0f)); + p.setY(XmlReadFloat(el, "y", 1.0f)); + addPoint(p); + } + + pointsNode = pointsNode.nextSibling(); + } + } + + node = node.nextSibling(); + } + + return true; + } + + bool PolyLineConnector::saveCustom(QDomElement& e, QDomDocument& doc) + { + e.appendChild(saveArrowHeads(doc)); + QDomElement pointsElement = doc.createElement("KivioGeometryPoints"); + + for(QValueList<KoPoint>::iterator it = m_points.begin(); it != m_points.end(); ++it) { + KoPoint p = (*it); + QDomElement el = doc.createElement("KivioPoint"); + XmlWriteFloat(el, "x", p.x()); + XmlWriteFloat(el, "y", p.y()); + pointsElement.appendChild(el); + } + + e.appendChild(pointsElement); + + return true; + } + + KivioCollisionType PolyLineConnector::checkForCollision(KoPoint* p, double threshold) + { + unsigned int i = 0; + KoPoint point; + double px = p->x(); + double py = p->y(); + uint count = m_points.count(); + + while(i < count) { + point = m_points[i]; + + if(px >= point.x() - threshold && px <= point.x() + threshold && + py >= point.y() - threshold && py <= point.y() + threshold) + { + return static_cast<KivioCollisionType>(i + kctCustom + 1); + } + + i++; + } + + i = 0; + count--; // As we need current + 1; + + while(i < count) { + point = m_points[i]; + + if(collisionLine(point.x(), point.y(), + m_points[i + 1].x(), m_points[i + 1].y(), px, py, threshold)) + { + return kctBody; + } + + i++; + } + + return kctNone; + } + + void PolyLineConnector::paint(KivioIntraStencilData* data) + { + if(m_points.count() < 2) { + kdDebug(43000) << "ARGH! We're missing points in this connector!" << endl; + return; + } + + KoZoomHandler* zoom = data->zoomHandler; + KivioPainter* painter = data->painter; + + painter->setLineStyle(m_pLineStyle); + painter->setLineWidth(zoom->zoomItY(m_pLineStyle->width())); + + QPointArray pa(m_points.count()); + QValueList<KoPoint>::iterator it; + int i = 0; + + for(it = m_points.begin(); it != m_points.end(); ++it) { + pa.setPoint(i, zoom->zoomPoint(*it)); + i++; + } + + KoPoint startVec = m_points[1] - m_points[0]; + KoPoint endVec = m_points.last() - m_points[m_points.count() - 2]; + double startLen = startVec.manhattanLength(); + double endLen = endVec.manhattanLength(); + + if(startLen) { + startVec.setX(startVec.x() / startLen); + startVec.setY(startVec.y() / startLen); + QPoint p = pa[0]; + p.setX(p.x() + qRound(startVec.x() * zoom->zoomItX(m_startArrow->cut()))); + p.setY(p.y() + qRound(startVec.y() * zoom->zoomItY(m_startArrow->cut()))); + } + + if(endLen) { + endVec.setX(endVec.x() / endLen); + endVec.setY(endVec.y() / endLen); + QPoint p = pa[m_points.count() - 1]; + p.setX(p.x() + qRound(endVec.x() * zoom->zoomItX(m_endArrow->cut()))); + p.setY(p.y() + qRound(endVec.y() * zoom->zoomItY(m_endArrow->cut()))); + } + + painter->drawPolyline(pa); + painter->setBGColor(m_pFillStyle->color()); + + if(startLen) { + m_startArrow->paint(painter, m_points[0].x(), m_points[0].y(), -startVec.x(), -startVec.y(), zoom); + } + + if(endLen) { + m_endArrow->paint(painter, m_points.last().x(), m_points.last().y(), endVec.x(), endVec.y(), zoom); + } + } + + void PolyLineConnector::paintOutline(KivioIntraStencilData* data) + { + paint(data); + } + + void PolyLineConnector::paintSelectionHandles( KivioIntraStencilData* data ) + { + KivioPainter* painter = data->painter; + KoZoomHandler* zoomHandler = data->zoomHandler; + QValueList<KoPoint>::Iterator it; + int x, y, flag; + x = y = flag = 0; + + for(it = m_points.begin(); it != m_points.end(); ++it) { + x = zoomHandler->zoomItX((*it).x()); + y = zoomHandler->zoomItY((*it).y()); + + if((*it) == m_pEnd->position()) { + flag = ((m_pEnd->target()) ? KivioPainter::cpfConnected : 0) | KivioPainter::cpfEnd; + } else if((*it) == m_pStart->position()) { + flag = ((m_pStart->target()) ? KivioPainter::cpfConnected : 0) | KivioPainter::cpfStart; + } else { + flag = 0; + } + + painter->drawHandle(x, y, flag); + } + } + + void PolyLineConnector::addPoint(const KoPoint& p) + { + if(m_points.count() == 0) { + m_pStart->setPosition(p.x(), p.y(), false); + m_pStart->disconnect(); + } else { + m_pEnd->setPosition(p.x(), p.y(), false); + m_pEnd->disconnect(); + } + + m_points.append(p); + } + + void PolyLineConnector::movePoint(unsigned int index, double xOffset, double yOffset) + { + if(index >= m_points.count()) { + return; + } + + KoPoint p(xOffset, yOffset); + m_points[index] += p; + + if(index == (m_points.count() - 1)) { + m_pEnd->setPosition(m_points[index].x(), m_points[index].y(), false); + m_pEnd->disconnect(); + } else if(index == 0) { + m_pStart->setPosition(m_points[index].x(), m_points[index].y(), false); + m_pStart->disconnect(); + } + } + + void PolyLineConnector::movePointTo(unsigned int index, const KoPoint& p) + { + m_points[index] = p; + + if(index == (m_points.count() - 1)) { + m_pEnd->setPosition(p.x(), p.y(), false); + m_pEnd->disconnect(); + } else if(index == 0) { + m_pStart->setPosition(p.x(), p.y(), false); + m_pStart->disconnect(); + } + } + + void PolyLineConnector::moveLastPointTo(const KoPoint& p) + { + movePointTo(m_points.count() - 1, p); + } + + void PolyLineConnector::customDrag(KivioCustomDragData* data) + { + KoPoint pos(data->x, data->y); + setCustomIDPoint(data->id, pos, data->page); + } + + void PolyLineConnector::move(double xOffset, double yOffset) + { + for(unsigned int i = 0; i < m_points.count(); i++) { + movePoint(i, xOffset, yOffset); + } + } + + double PolyLineConnector::x() + { + if(m_points.count() == 0) { + return 0; + } + + return rect().x(); + } + + void PolyLineConnector::setX(double newX) + { + double dx = newX - x(); + move(dx, 0); + } + + double PolyLineConnector::y() + { + if(m_points.count() == 0) { + return 0; + } + + return rect().y(); + } + + void PolyLineConnector::setY(double newY) + { + double dy = newY - y(); + move(0, dy); + } + + void PolyLineConnector::checkForConnection(KivioConnectorPoint* cp, KivioPage* page) + { + if(cp->connectable()) { + KivioLayer* currentLayer = page->curLayer(); + KivioLayer* layer = page->firstLayer(); + bool found = false; + + while(layer && !found) { + if((layer != currentLayer) && (!layer->connectable() || !layer->visible())) { + layer = page->nextLayer(); + continue; + } + + if(layer->connectPointToTarget(cp, 8.0f)) { + found = true; + } + + layer = page->nextLayer(); + } + + if(!found) { + cp->disconnect(); + } + } + } + + void PolyLineConnector::updateConnectorPoints(KivioConnectorPoint* cp, double /*oldX*/, double /*oldY*/) + { + if(cp == m_pStart) { + m_points[0] = m_pStart->position(); + } else if(cp == m_pEnd) { + m_points[m_points.count() - 1] = m_pEnd->position(); + } + } + + KoRect PolyLineConnector::rect() + { + KoPoint p = m_points.first(); + KoPoint topLeft(p.x(), p.y()), bottomRight; + QValueList<KoPoint>::iterator it; + QValueList<KoPoint>::iterator itEnd = m_points.end(); + + for(it = m_points.begin(); it != itEnd; ++it) { + p = (*it); + topLeft.setX(QMIN(p.x(), topLeft.x())); + topLeft.setY(QMIN(p.y(), topLeft.y())); + bottomRight.setX(QMAX(p.x(), bottomRight.x())); + bottomRight.setY(QMAX(p.y(), bottomRight.y())); + } + + KoRect rect; + rect.moveTopLeft(topLeft); + rect.setWidth(bottomRight.x() - topLeft.x()); + rect.setHeight(bottomRight.y() - topLeft.y()); + return rect; + } + + bool PolyLineConnector::isInRect(const KoRect& rect) + { + QValueList<KoPoint>::Iterator it; + bool retVal = true; + + for(it = m_points.begin(); it != m_points.end(); ++it) { + retVal = retVal && rect.contains((*it)); + } + + return retVal; + } + + bool PolyLineConnector::loadArrowHeads(const QDomElement& e) + { + bool first = true; + QDomNode node = e.firstChild(); + + while(!node.isNull()) { + if(node.nodeName() == "KivioArrowHead") { + if(first) { + m_startArrow->loadXML(node.toElement()); + first = false; + } else { + m_endArrow->loadXML(node.toElement()); + } + } + + node = node.nextSibling(); + } + + return true; + } + + QDomElement PolyLineConnector::saveArrowHeads(QDomDocument& doc) + { + QDomElement e = doc.createElement("KivioArrowHeads"); + + e.appendChild( m_startArrow->saveXML(doc) ); + e.appendChild( m_endArrow->saveXML(doc) ); + + return e; + } + + void PolyLineConnector::removePoint(unsigned int index) + { + if(index >= m_points.count()) { + return; + } + + m_points.remove(m_points.at(index)); + } + + void PolyLineConnector::removeLastPoint() + { + removePoint(m_points.count() - 1); + } + + void PolyLineConnector::setCustomIDPoint(int customID, const KoPoint& point, KivioPage* page) + { + int index = customID - (kctCustom + 1); + + if((index < 0) || index >= (int)m_points.count()) { + kdDebug(43000) << "PolyLineConnector::setCustomIDPoint: Index out of range! Index = " << index << endl; + return; + } + + movePointTo(index, point); + KivioConnectorPoint* cp; + + if(index == 0) { + cp = m_pStart; + } else if(index == ((int)m_points.count() - 1)) { + cp = m_pEnd; + } else { + return; + } + + checkForConnection(cp, page); + } + + KoPoint PolyLineConnector::customIDPoint(int customID) + { + int index = customID - (kctCustom + 1); + + if((index < 0) || index >= (int)m_points.count()) { + kdDebug(43000) << "PolyLineConnector::customIDPoint: Index out of range! Index = " << index << endl; + return KoPoint(); + } + + return m_points[index]; + } + +} diff --git a/kivio/kiviopart/kiviosdk/kiviopolylineconnector.h b/kivio/kiviopart/kiviosdk/kiviopolylineconnector.h new file mode 100644 index 000000000..26878690e --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kiviopolylineconnector.h @@ -0,0 +1,126 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Peter Simonsson <psn@linux.se>, + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KIVIOKIVIOPOLYLINECONNECTOR_H +#define KIVIOKIVIOPOLYLINECONNECTOR_H + +#include <qvaluelist.h> + +#include <KoPoint.h> +#include <KoRect.h> + +#include "kivio_1d_stencil.h" +#include "kivio_arrowhead.h" +#include <koffice_export.h> +class KivioIntraStencilData; +class KivioCustomDragData; +class KivioPage; + +namespace Kivio { + class KIVIO_EXPORT PolyLineConnector : public Kivio1DStencil + { + public: + PolyLineConnector(); + virtual ~PolyLineConnector(); + + virtual KivioStencil* duplicate(); + + virtual bool loadCustom(const QDomElement& e); + virtual bool saveCustom(QDomElement& e, QDomDocument& doc); + + virtual KivioCollisionType checkForCollision(KoPoint* p, double threshold); + + virtual void paint(KivioIntraStencilData* data); + virtual void paintOutline(KivioIntraStencilData* data); + virtual void paintSelectionHandles(KivioIntraStencilData* data); + + /** Append a new point to the list. + * + * @param p The point to append. + */ + void addPoint(const KoPoint& p); + /// Remove a point from the list. + void removePoint(unsigned int index); + /// Remove the last point from the list + void removeLastPoint(); + + unsigned int pointCount() const { return m_points.count(); } + + /** Move point with index @param index. + * + * @param index Which point to move. + * @param xOffset How far to move the point horizontaly. + * @param yOffset How far to move the point verticaly. + */ + void movePoint(unsigned int index, double xOffset, double yOffset); + + void movePointTo(unsigned int index, const KoPoint& p); + + void moveLastPointTo(const KoPoint& p); + + virtual void customDrag(KivioCustomDragData* data); + virtual void move(double xOffset, double yOffset); + virtual double x(); + virtual void setX(double x); + virtual double y(); + virtual void setY(double y); + virtual double w() { return 0; } + virtual double h() { return 0; } + virtual KoRect rect(); + virtual bool isInRect(const KoRect& rect); + virtual void setCustomIDPoint(int customID, const KoPoint& point, KivioPage* page); + virtual KoPoint customIDPoint(int customID); + + + virtual void updateConnectorPoints(KivioConnectorPoint* cp, double /*oldX*/, double /*oldY*/); + + // Arrow head properties + virtual void setStartAHType(int i) { m_startArrow->setType(i); } + virtual int startAHType() { return m_startArrow->type(); } + + virtual void setStartAHWidth(double f) { m_startArrow->setWidth(f); } + virtual double startAHWidth() { return m_startArrow->width(); } + + virtual void setStartAHLength(double f) { m_startArrow->setLength(f); } + virtual double startAHLength() { return m_startArrow->length(); } + + virtual void setEndAHType(int i) { m_endArrow->setType(i); } + virtual int endAHType() { return m_endArrow->type(); } + + virtual void setEndAHWidth(double f) { m_endArrow->setWidth(f); } + virtual double endAHWidth() { return m_endArrow->width(); } + + virtual void setEndAHLength(double f) { m_endArrow->setLength(f); } + virtual double endAHLength() { return m_endArrow->length(); } + + protected: + void checkForConnection(KivioConnectorPoint* cp, KivioPage* page); + + bool loadArrowHeads(const QDomElement& e); + QDomElement saveArrowHeads(QDomDocument& doc); + + private: + KivioArrowHead* m_startArrow; // Arrow head for the first point. + KivioArrowHead* m_endArrow; // Arrow head for the last point. + + QValueList<KoPoint> m_points; + }; +} + +#endif diff --git a/kivio/kiviopart/kiviosdk/kiviostencilfactory.h b/kivio/kiviopart/kiviosdk/kiviostencilfactory.h new file mode 100644 index 000000000..b037c1bf8 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/kiviostencilfactory.h @@ -0,0 +1,41 @@ +/* + * 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 KIVIO_STENCIL_FACTORY_H +#define KIVIO_STENCIL_FACTORY_H + +class KivioStencil; +class KivioStencilSpawnerInfo; +class QPixmap; + +#include <qstring.h> +#include <qobject.h> +#include <qstringlist.h> +#include <koffice_export.h> +class KIVIO_EXPORT KivioStencilFactory : public QObject +{ + Q_OBJECT + public: + KivioStencilFactory(QObject *parent=0, const char*name=0, const QStringList& args = QStringList()) + : QObject(parent, name) { Q_UNUSED(args) } + virtual KivioStencil *NewStencil(const QString& name) =0; + virtual KivioStencil *NewStencil()=0; + virtual QPixmap *GetIcon()=0; + virtual KivioStencilSpawnerInfo *GetSpawnerInfo()=0; +}; +#endif diff --git a/kivio/kiviopart/kiviosdk/polylineconnectorspawner.cpp b/kivio/kiviopart/kiviosdk/polylineconnectorspawner.cpp new file mode 100644 index 000000000..f8563b5e6 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/polylineconnectorspawner.cpp @@ -0,0 +1,62 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Peter Simonsson <psn@linux.se>, + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#include "polylineconnectorspawner.h" + +#include "kiviopolylineconnector.h" + +namespace Kivio { + +PolyLineConnectorSpawner::PolyLineConnectorSpawner(KivioStencilSpawnerSet* spawnerSet) + : KivioStencilSpawner(spawnerSet) +{ + m_info = KivioStencilSpawnerInfo("Kivio Team", "PolyLine Connector", "Internal - PolyLine Connector", + "PolyLine Connector", "0.1", "http://localhost/", "", "off"); +} + +PolyLineConnectorSpawner::~PolyLineConnectorSpawner() +{ +} + +bool PolyLineConnectorSpawner::load(const QString&) +{ + return true; +} + +QDomElement PolyLineConnectorSpawner::saveXML(QDomDocument& /*doc*/) +{ + return QDomElement(); +} + +KivioStencil* PolyLineConnectorSpawner::newStencil() +{ + PolyLineConnector* connector = new PolyLineConnector(); + connector->setSpawner(this); + + return connector; +} + +KivioStencil* PolyLineConnectorSpawner::newStencil(const QString& /*arg*/) +{ + PolyLineConnector* connector = new PolyLineConnector(); + connector->setSpawner(this); + + return connector; +} + +} diff --git a/kivio/kiviopart/kiviosdk/polylineconnectorspawner.h b/kivio/kiviopart/kiviosdk/polylineconnectorspawner.h new file mode 100644 index 000000000..851603873 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/polylineconnectorspawner.h @@ -0,0 +1,49 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Peter Simonsson <psn@linux.se>, + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KIVIOPOLYLINECONNECTORSPAWNER_H +#define KIVIOPOLYLINECONNECTORSPAWNER_H + +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" + +namespace Kivio { + +class PolyLineConnectorSpawner : public KivioStencilSpawner +{ + public: + PolyLineConnectorSpawner(KivioStencilSpawnerSet* spawnerSet); + ~PolyLineConnectorSpawner(); + + virtual bool load(const QString& ); + virtual QDomElement saveXML(QDomDocument& doc); + + virtual KivioStencil* newStencil(); + virtual KivioStencil* newStencil(const QString& arg); + virtual KivioStencilSpawnerInfo* info() { return &m_info; } + + virtual QPixmap* icon() { return &m_icon; } + + private: + QPixmap m_icon; + KivioStencilSpawnerInfo m_info; +}; + +} + +#endif diff --git a/kivio/kiviopart/kiviosdk/py_kivio.h b/kivio/kiviopart/kiviosdk/py_kivio.h new file mode 100644 index 000000000..530ffae26 --- /dev/null +++ b/kivio/kiviopart/kiviosdk/py_kivio.h @@ -0,0 +1,265 @@ +char kivio_module[] = +"import kivioc\n"\ +"class KivioStencil:\n"\ +" def __init__(self,*args):\n"\ +" self.this = apply(kivioc.new_KivioStencil,args)\n"\ +" self.thisown = 1\n"\ +"\n"\ +" def __del__(self):\n"\ +" if self.thisown == 1 :\n"\ +" kivioc.delete_KivioStencil(self)\n"\ +" def duplicate(*args):\n"\ +" val = apply(kivioc.KivioStencil_duplicate,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def x(*args):\n"\ +" val = apply(kivioc.KivioStencil_x,args)\n"\ +" return val\n"\ +" def setX(*args):\n"\ +" val = apply(kivioc.KivioStencil_setX,args)\n"\ +" return val\n"\ +" def y(*args):\n"\ +" val = apply(kivioc.KivioStencil_y,args)\n"\ +" return val\n"\ +" def setY(*args):\n"\ +" val = apply(kivioc.KivioStencil_setY,args)\n"\ +" return val\n"\ +" def w(*args):\n"\ +" val = apply(kivioc.KivioStencil_w,args)\n"\ +" return val\n"\ +" def setW(*args):\n"\ +" val = apply(kivioc.KivioStencil_setW,args)\n"\ +" return val\n"\ +" def h(*args):\n"\ +" val = apply(kivioc.KivioStencil_h,args)\n"\ +" return val\n"\ +" def setH(*args):\n"\ +" val = apply(kivioc.KivioStencil_setH,args)\n"\ +" return val\n"\ +" def rect(*args):\n"\ +" val = apply(kivioc.KivioStencil_rect,args)\n"\ +" return val\n"\ +" def setPosition(*args):\n"\ +" val = apply(kivioc.KivioStencil_setPosition,args)\n"\ +" return val\n"\ +" def setDimensions(*args):\n"\ +" val = apply(kivioc.KivioStencil_setDimensions,args)\n"\ +" return val\n"\ +" def fillStyle(*args):\n"\ +" val = apply(kivioc.KivioStencil_fillStyle,args)\n"\ +" return val\n"\ +" def setLineWidth(*args):\n"\ +" val = apply(kivioc.KivioStencil_setLineWidth,args)\n"\ +" return val\n"\ +" def lineWidth(*args):\n"\ +" val = apply(kivioc.KivioStencil_lineWidth,args)\n"\ +" return val\n"\ +" def hTextAlign(*args):\n"\ +" val = apply(kivioc.KivioStencil_hTextAlign,args)\n"\ +" return val\n"\ +" def vTextAlign(*args):\n"\ +" val = apply(kivioc.KivioStencil_vTextAlign,args)\n"\ +" return val\n"\ +" def setHTextAlign(*args):\n"\ +" val = apply(kivioc.KivioStencil_setHTextAlign,args)\n"\ +" return val\n"\ +" def setVTextAlign(*args):\n"\ +" val = apply(kivioc.KivioStencil_setVTextAlign,args)\n"\ +" return val\n"\ +" def setText(*args):\n"\ +" val = apply(kivioc.KivioStencil_setText,args)\n"\ +" return val\n"\ +" def text(*args):\n"\ +" val = apply(kivioc.KivioStencil_text,args)\n"\ +" return val\n"\ +" def textColor(*args):\n"\ +" val = apply(kivioc.KivioStencil_textColor,args)\n"\ +" return val\n"\ +" def setTextColor(*args):\n"\ +" val = apply(kivioc.KivioStencil_setTextColor,args)\n"\ +" return val\n"\ +" def fgColor(*args):\n"\ +" val = apply(kivioc.KivioStencil_fgColor,args)\n"\ +" return val\n"\ +" def setFGColor(*args):\n"\ +" val = apply(kivioc.KivioStencil_setFGColor,args)\n"\ +" return val\n"\ +" def bgColor(*args):\n"\ +" val = apply(kivioc.KivioStencil_bgColor,args)\n"\ +" return val\n"\ +" def setBGColor(*args):\n"\ +" val = apply(kivioc.KivioStencil_setBGColor,args)\n"\ +" return val\n"\ +" def isSelected(*args):\n"\ +" val = apply(kivioc.KivioStencil_isSelected,args)\n"\ +" return val\n"\ +" def select(*args):\n"\ +" val = apply(kivioc.KivioStencil_select,args)\n"\ +" return val\n"\ +" def unselect(*args):\n"\ +" val = apply(kivioc.KivioStencil_unselect,args)\n"\ +" return val\n"\ +" def subSelect(*args):\n"\ +" val = apply(kivioc.KivioStencil_subSelect,args)\n"\ +" return val\n"\ +" def addToGroup(*args):\n"\ +" val = apply(kivioc.KivioStencil_addToGroup,args)\n"\ +" return val\n"\ +" def updateGeometry(*args):\n"\ +" val = apply(kivioc.KivioStencil_updateGeometry,args)\n"\ +" return val\n"\ +" def setStartAHType(*args):\n"\ +" val = apply(kivioc.KivioStencil_setStartAHType,args)\n"\ +" return val\n"\ +" def setStartAHWidth(*args):\n"\ +" val = apply(kivioc.KivioStencil_setStartAHWidth,args)\n"\ +" return val\n"\ +" def setStartAHLength(*args):\n"\ +" val = apply(kivioc.KivioStencil_setStartAHLength,args)\n"\ +" return val\n"\ +" def setEndAHType(*args):\n"\ +" val = apply(kivioc.KivioStencil_setEndAHType,args)\n"\ +" return val\n"\ +" def setEndAHWidth(*args):\n"\ +" val = apply(kivioc.KivioStencil_setEndAHWidth,args)\n"\ +" return val\n"\ +" def setEndAHLength(*args):\n"\ +" val = apply(kivioc.KivioStencil_setEndAHLength,args)\n"\ +" return val\n"\ +" def startAHType(*args):\n"\ +" val = apply(kivioc.KivioStencil_startAHType,args)\n"\ +" return val\n"\ +" def startAHWidth(*args):\n"\ +" val = apply(kivioc.KivioStencil_startAHWidth,args)\n"\ +" return val\n"\ +" def startAHLength(*args):\n"\ +" val = apply(kivioc.KivioStencil_startAHLength,args)\n"\ +" return val\n"\ +" def endAHType(*args):\n"\ +" val = apply(kivioc.KivioStencil_endAHType,args)\n"\ +" return val\n"\ +" def endAHWidth(*args):\n"\ +" val = apply(kivioc.KivioStencil_endAHWidth,args)\n"\ +" return val\n"\ +" def endAHLength(*args):\n"\ +" val = apply(kivioc.KivioStencil_endAHLength,args)\n"\ +" return val\n"\ +" def __repr__(self):\n"\ +" return \"<C KivioStencil instance at %s>\" % (self.this,)\n"\ +"class KivioStencilPtr(KivioStencil):\n"\ +" def __init__(self,this):\n"\ +" self.this = this\n"\ +" self.thisown = 0\n"\ +" self.__class__ = KivioStencil\n"\ +"\n"\ +"class KivioLayer:\n"\ +" def __init__(self,*args):\n"\ +" self.this = apply(kivioc.new_KivioLayer,args)\n"\ +" self.thisown = 1\n"\ +"\n"\ +" def __del__(self):\n"\ +" if self.thisown == 1 :\n"\ +" kivioc.delete_KivioLayer(self)\n"\ +" def visible(*args):\n"\ +" val = apply(kivioc.KivioLayer_visible,args)\n"\ +" return val\n"\ +" def setVisible(*args):\n"\ +" val = apply(kivioc.KivioLayer_setVisible,args)\n"\ +" return val\n"\ +" def connectable(*args):\n"\ +" val = apply(kivioc.KivioLayer_connectable,args)\n"\ +" return val\n"\ +" def setConnectable(*args):\n"\ +" val = apply(kivioc.KivioLayer_setConnectable,args)\n"\ +" return val\n"\ +" def addStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_addStencil,args)\n"\ +" return val\n"\ +" def removeStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_removeStencil,args)\n"\ +" return val\n"\ +" def firstStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_firstStencil,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def nextStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_nextStencil,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def prevStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_prevStencil,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def currentStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_currentStencil,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def lastStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_lastStencil,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def takeStencil(*args):\n"\ +" val = apply(kivioc.KivioLayer_takeStencil,args)\n"\ +" if val: val = KivioStencilPtr(val) \n"\ +" return val\n"\ +" def __repr__(self):\n"\ +" return \"<C KivioLayer instance at %s>\" % (self.this,)\n"\ +"class KivioLayerPtr(KivioLayer):\n"\ +" def __init__(self,this):\n"\ +" self.this = this\n"\ +" self.thisown = 0\n"\ +" self.__class__ = KivioLayer\n"\ +"\n"\ +"update = kivioc.update\n"\ +"isStencilSelected = kivioc.isStencilSelected\n"\ +"selectAllStencils = kivioc.selectAllStencils\n"\ +"unselectAllStencils = kivioc.unselectAllStencils\n"\ +"unselectStencil = kivioc.unselectStencil\n"\ +"selectStencil = kivioc.selectStencil\n"\ +"\n"\ +"def curLayer(*args, **kwargs):\n"\ +" val = apply(kivioc.curLayer,args,kwargs)\n"\ +" if val: val = KivioLayerPtr(val)\n"\ +" return val\n"\ +"\n"\ +"setCurLayer = kivioc.setCurLayer\n"\ +"\n"\ +"def firstLayer(*args, **kwargs):\n"\ +" val = apply(kivioc.firstLayer,args,kwargs)\n"\ +" if val: val = KivioLayerPtr(val)\n"\ +" return val\n"\ +"\n"\ +"def nextLayer(*args, **kwargs):\n"\ +" val = apply(kivioc.nextLayer,args,kwargs)\n"\ +" if val: val = KivioLayerPtr(val)\n"\ +" return val\n"\ +"\n"\ +"def lastLayer(*args, **kwargs):\n"\ +" val = apply(kivioc.lastLayer,args,kwargs)\n"\ +" if val: val = KivioLayerPtr(val)\n"\ +" return val\n"\ +"\n"\ +"def prevLayer(*args, **kwargs):\n"\ +" val = apply(kivioc.prevLayer,args,kwargs)\n"\ +" if val: val = KivioLayerPtr(val)\n"\ +" return val\n"\ +"\n"\ +"removeCurrentLayer = kivioc.removeCurrentLayer\n"\ +"addLayer = kivioc.addLayer\n"\ +"insertLayer = kivioc.insertLayer\n"\ +"\n"\ +"def layerAt(*args, **kwargs):\n"\ +" val = apply(kivioc.layerAt,args,kwargs)\n"\ +" if val: val = KivioLayerPtr(val)\n"\ +" return val\n"\ +"\n"\ +"addStencil = kivioc.addStencil\n"\ +"deleteSelectedStencils = kivioc.deleteSelectedStencils\n"\ +"groupSelectedStencils = kivioc.groupSelectedStencils\n"\ +"ungroupSelectedStencils = kivioc.ungroupSelectedStencils\n"\ +"bringToFront = kivioc.bringToFront\n"\ +"sendToBack = kivioc.sendToBack\n"\ +"copy = kivioc.copy\n"\ +"cut = kivioc.cut\n"\ +"paste = kivioc.paste\n"\ +""; diff --git a/kivio/kiviopart/kiviosdk/tkmath.h b/kivio/kiviopart/kiviosdk/tkmath.h new file mode 100644 index 000000000..0edb6b37b --- /dev/null +++ b/kivio/kiviopart/kiviosdk/tkmath.h @@ -0,0 +1,141 @@ +/* + * 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 _TKVECTOR_H +#define _TKVECTOR_H + +#include <math.h> + +class TKVec2 +{ +protected: + double m_x, m_y; + +public: + TKVec2(const double &_x, const double &_y) + { m_x = _x; m_y=_y; } + + inline double dotProduct( const TKVec2 &v2 ) const + { return m_x*v2.m_x + m_y*v2.m_y; } + + inline double crossProduct( const TKVec2 &v2 ) const + { return ( m_x*v2.m_y - m_y*v2.m_x ); } + + inline double magnitude() const + { return sqrt(m_x*m_x + m_y*m_y); } + + inline void normalize() + { double l=this->magnitude(); m_x/=l; m_y/=l; } + + inline void scale( const double &sx, const double &sy ) + { m_x *= sx; m_y *= sy; } + + inline void scale( const TKVec2 &v ) + { m_x *= v.m_x; m_y *= v.m_y; } + + inline void scale( const double &s ) + { m_x*=s; m_y*=s; } + + inline TKVec2 getPerpendicular() const + { return TKVec2(-m_y, m_x); } + + inline void reverse() + { m_x*=-1.0f; m_y*=-1.0f; } + + inline void rotate( const double &rad ) + { double newX, newY; newX= m_x*cos(rad) - m_y*sin(rad); newY=m_x*sin(rad)+m_y*cos(rad); m_x=newX; m_y=newY;} + + inline void rotateDeg( const double ° ) + { double newX, newY, rad=deg*3.14159f/180.0f; + newX= m_x*cos(rad) - m_y*sin(rad); newY=m_x*sin(rad)+m_y*cos(rad); m_x=newX; m_y=newY;} + + inline void translate( const double &tx, const double &ty ) + { m_x += tx; m_y += ty; } + + inline double angle( const TKVec2 &v ) + { return acos( (this->dotProduct(v)) / (this->magnitude() * v.magnitude()) ); } + + inline double x() { return m_x; } + inline double y() { return m_y; } + + inline void setX(const double &_x) { m_x=_x; } + inline void setY(const double &_y) { m_y=_y; } + + inline void set(const double &_x, const double &_y) {m_x=_x; m_y=_y;} +}; + +inline double shortestDistance(double sx, double sy, double ex, double ey, double px, double py ) +{ + TKVec2 u(sx-ex, sy-ey); + TKVec2 pq(sx-px, sy-py); + + double magTop = fabs( pq.crossProduct(u) ); + double magU = u.magnitude(); + + // Eeeewww + if( magU==0.0f ) + { + return -1.0f; + } + + return magTop / magU; +} + +inline bool collisionLine( double sx, double sy, double ex, double ey, double px, double py, double threshold ) +{ + double minx, miny, maxx, maxy; + + if( sx < ex ) { + minx = sx; + maxx = ex; + } + else { + minx = ex; + maxx = sx; + } + + minx -= threshold; + maxx += threshold; + + if( sy < ey ) { + miny = sy; + maxy = ey; + } + else { + miny = ey; + maxy = sy; + } + + miny -= threshold; + maxy += threshold; + + if( !(px >= minx && + px <= maxx && + py >= miny && + py <= maxy ) ) + { + return false; + } + + if( shortestDistance( sx, sy, ex, ey, px, py ) <= threshold ) + return true; + + return false; +} + +#endif |
