diff options
Diffstat (limited to 'kivio/plugins')
75 files changed, 6752 insertions, 0 deletions
diff --git a/kivio/plugins/Makefile.am b/kivio/plugins/Makefile.am new file mode 100644 index 00000000..6ab1095e --- /dev/null +++ b/kivio/plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = kivioconnectortool kiviotexttool kiviozoomtool kivioselecttool kiviotargettool #kiviosmlconnector diff --git a/kivio/plugins/kivioconnectortool/Makefile.am b/kivio/plugins/kivioconnectortool/Makefile.am new file mode 100644 index 00000000..10f0edd0 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/Makefile.am @@ -0,0 +1,41 @@ +SUBDIRS = straight_connector . +kde_module_LTLIBRARIES =libkivioconnectortool.la + + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + -I$(top_srcdir)/kivio/plugins/kivioconnectortool/straight_connector \ + -I$(top_srcdir)/kivio/plugins/kivioconnectortool/polyline_connector \ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) +libkivioconnectortool_la_METASOURCES = AUTO +libkivioconnectortool_la_SOURCES = \ + plugin.cpp\ + tool_connector.cpp +EXTRA_DIST = \ + plugin.h\ + plugin.cpp\ + kivio_connector.xpm\ + tool_connector.h\ + tool_connector.cpp\ + kivioconnectortool.rc\ + kivioconnectortool.desktop\ + kivio_connector_cursor2.xpm\ + kivio_connector_cursor1.xpm + +libkivioconnectortool_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +libkivioconnectortool_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +rc_DATA = kivioconnectortool.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kivioconnectortool.desktop +desktopdir = $(kde_servicesdir) + +kiviopics_DATA = kivio_connector_cursor1.png kivio_connector_cursor2.png +kiviopicsdir = $(kde_datadir)/kivio/pics + +kivioicondir = $(kde_datadir)/kivio/icons +kivioicon_ICON = AUTO diff --git a/kivio/plugins/kivioconnectortool/cr22-action-kivio_connector.png b/kivio/plugins/kivioconnectortool/cr22-action-kivio_connector.png Binary files differnew file mode 100644 index 00000000..666742d7 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/cr22-action-kivio_connector.png diff --git a/kivio/plugins/kivioconnectortool/hi22-action-kivio_connector.png b/kivio/plugins/kivioconnectortool/hi22-action-kivio_connector.png Binary files differnew file mode 100644 index 00000000..fa74ce62 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/hi22-action-kivio_connector.png diff --git a/kivio/plugins/kivioconnectortool/kivio_connector_cursor1.png b/kivio/plugins/kivioconnectortool/kivio_connector_cursor1.png Binary files differnew file mode 100644 index 00000000..d3819e5a --- /dev/null +++ b/kivio/plugins/kivioconnectortool/kivio_connector_cursor1.png diff --git a/kivio/plugins/kivioconnectortool/kivio_connector_cursor2.png b/kivio/plugins/kivioconnectortool/kivio_connector_cursor2.png Binary files differnew file mode 100644 index 00000000..a3c8ebff --- /dev/null +++ b/kivio/plugins/kivioconnectortool/kivio_connector_cursor2.png diff --git a/kivio/plugins/kivioconnectortool/kivioconnectortool.desktop b/kivio/plugins/kivioconnectortool/kivioconnectortool.desktop new file mode 100644 index 00000000..1f232bcb --- /dev/null +++ b/kivio/plugins/kivioconnectortool/kivioconnectortool.desktop @@ -0,0 +1,63 @@ +[Desktop Entry] +X-KDE-Library=libkivioconnectortool +Name=ConnectorTool for Kivio +Name[af]=Konnekteer gereedskap vir Kivio +Name[ar]=أداة اتصال Kivio +Name[az]=Kivio üçün bağlantı vasitəsi +Name[bg]=Инструмент за свързване за Kivio +Name[bs]=Konektor alat za Kivio +Name[ca]=Eina connectora per a Kivio +Name[cs]=Spojovací nástroj pro Kivio +Name[cy]=ErfynCysylltu i Kivio +Name[da]=Connector-værktøj for Kivio +Name[de]=Verbindungs-Programm für Kivio +Name[el]=Εργαλείο σύνδεσης για το Kivio +Name[eo]=Konektilo por Kivio +Name[es]=Herramienta de conexiones para Kivio +Name[et]=Kivio ühenduste loomise tööriist +Name[eu]=Kivio-ren konexiorako tresna +Name[fa]=ابزار اتصال برای Kivio +Name[fi]=Yhdistystyökalu Kivioon +Name[fr]=Outil connexion pour Kivio +Name[fy]=Ferbiningsark foar Kivio +Name[gl]=Ferramenta de Conexón para Kivio +Name[he]=כלי חיבור של Kivio +Name[hr]=Alat povezivanja za Kivio +Name[hu]=Összekapcsoló eszköz a Kivio-hoz +Name[id]=Alat Connector buat Kivio +Name[is]=Tengitól fyrir Kivio +Name[it]=Strumento di connessione per Kivio +Name[ja]=Kivio コネクタツール +Name[km]=ឧបករណ៍តភ្ជាប់សម្រាប់ Kivio +Name[lo]=ເຄື່ອງມືການເຊື່ອມຕໍ່ສຳລັບແຜນຜັງໄດອະແກຣມ K +Name[lt]=ConnectorTool skirtas Kivio +Name[lv]=Savienotājrīks priekš Kivio +Name[ms]=Alat Penyambung bagi Kivio +Name[mt]=Għodda tal-Konnessjoni għall-Kivio +Name[nb]=Koblingsverktøy for Kivio +Name[nds]=Tokoppelwarktüüch för Kivio +Name[ne]=किभियोका लागि योजक उपकरण +Name[nl]=Verbindingsgereedschap voor Kivio +Name[nn]=Sambandsverktøy for Kivio +Name[pl]=Narzędzie łącznika dla Kivio +Name[pt]=Ferramenta de Ligação para o Kivio +Name[pt_BR]=Ferramenta de conexão para o Kivio +Name[ro]=Unealtă conectare pentru Kivio +Name[ru]=ConnectorTool для Kivio +Name[se]=Oktavuohtareaidu Kivio várás +Name[sk]=Spojovací nástroj pre Kivio +Name[sl]=Priključno orodje za Kivio +Name[sr]=Алат за повезивање за Kivio +Name[sr@Latn]=Alat za povezivanje za Kivio +Name[sv]=Kopplingsverktyg för Kivio +Name[ta]=Kivio இணைப்புக்கருவி +Name[tg]=Асбоби Алоқакунанда барои Kivio +Name[th]=เครื่องมือการเชื่อมต่อสำหรับแผนผังไดอะแกรม K +Name[tr]=Kivio için Bağlantı Aracı +Name[uk]=Засіб з'єднання для Kivio +Name[ven]=tshishumiswa tshau tumanya tsha Kivio +Name[xh]=Isixhobo Somxhulumanisi we Kivio +Name[zh_CN]=Kivio 连接件工具 +Name[zh_TW]=Kivio 連接器工具 +Name[zu]=Ithuluzi lokuhlanganisa i Kivio +Type=Service diff --git a/kivio/plugins/kivioconnectortool/kivioconnectortool.rc b/kivio/plugins/kivioconnectortool/kivioconnectortool.rc new file mode 100644 index 00000000..de828226 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/kivioconnectortool.rc @@ -0,0 +1,12 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioConnectorTool" library="libkivioconnectortool" version="5"> +<MenuBar> + <Menu name="Tools"> + <Action name="connector"/> + <Action name="polyLineConnector"/> + </Menu> +</MenuBar> +<ToolBar name="ToolsToolBar"> + <Action name="polyLineConnector"/> +</ToolBar> +</kpartgui> diff --git a/kivio/plugins/kivioconnectortool/plugin.cpp b/kivio/plugins/kivioconnectortool/plugin.cpp new file mode 100644 index 00000000..2b4c6e41 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/plugin.cpp @@ -0,0 +1,58 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "plugin.h" +#include "tool_connector.h" + +#include "kivio_view.h" + +#include <kinstance.h> +#include <kiconloader.h> + +/*************************************************** + * Factory + ***************************************************/ +K_EXPORT_COMPONENT_FACTORY( libkivioconnectortool, ConnectorToolFactory ) + +KInstance* ConnectorToolFactory::s_global = 0; + +ConnectorToolFactory::ConnectorToolFactory( QObject* parent, const char* name ) +: KLibFactory( parent, name ) +{ + s_global = new KInstance("kivio"); +} + +ConnectorToolFactory::~ConnectorToolFactory() +{ + delete s_global; +} + +QObject* ConnectorToolFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject *obj = new ConnectorTool( (KivioView*)parent ); + return obj; +} + +KInstance* ConnectorToolFactory::global() +{ + return s_global; +} +#include "plugin.moc" diff --git a/kivio/plugins/kivioconnectortool/plugin.h b/kivio/plugins/kivioconnectortool/plugin.h new file mode 100644 index 00000000..0fbb5a9a --- /dev/null +++ b/kivio/plugins/kivioconnectortool/plugin.h @@ -0,0 +1,44 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef CONNECTOR_PLUGIN_H +#define CONNECTOR_PLUGIN_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class ConnectorToolFactory : public KLibFactory +{ Q_OBJECT +public: + ConnectorToolFactory( QObject* parent = 0, const char* name = 0 ); + ~ConnectorToolFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + + static KInstance* global(); + +private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kivioconnectortool/straight_connector/Makefile.am b/kivio/plugins/kivioconnectortool/straight_connector/Makefile.am new file mode 100644 index 00000000..47d68538 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/Makefile.am @@ -0,0 +1,32 @@ +stencildir = $(kde_datadir)/kivio/autoloadStencils +stencil_DATA = straight_connector.xpm + +kde_module_LTLIBRARIES =straight_connector.la + +straight_connector_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) + +# Hack to make it work (dave m) +straight_connector_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOTEXT_INCLUDES)\ + $(KOFFICE_INCLUDES) $(all_includes) +METASOURCES = AUTO + +straight_connector_la_SOURCES = \ + straight_connector.cpp +EXTRA_DIST = \ + straight_connector.cpp\ + straight_connector.h\ + straight_connector.xpm + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(stencildir) + -rm -f $(DESTDIR)$(stencildir)/straight_connector.so + $(LN_S) $(kde_moduledir)/straight_connector.so $(DESTDIR)$(stencildir)/straight_connector.so + +uninstall-local: + -rm -f $(DESTDIR)$(stencildir)/straight_connector.so + diff --git a/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.cpp b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.cpp new file mode 100644 index 00000000..233c7ab8 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.cpp @@ -0,0 +1,379 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include <stdio.h> +#include <math.h> +#include "straight_connector.h" + +#include "kivio_common.h" +#include "kivio_connector_target.h" +#include "kivio_layer.h" +#include "kivio_line_style.h" +#include "kivio_page.h" +#include "kivio_painter.h" +#include "kivio_stencil.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_text_style.h" +#include "tkmath.h" + +#include <qcolor.h> +#include <qpixmap.h> +#include <kdebug.h> +#include <KoZoomHandler.h> + +#include "straight_connector.xpm" + + +static QPixmap *pIcon = NULL; + +static KivioStencilSpawnerInfo sinfo = KivioStencilSpawnerInfo("Dave Marotti", "Straight Connector", "Dave Marotti - Straight Connector", "Basic Straight Connector", "0.1", "http://localhost/", "", "off"); + +#include <kgenericfactory.h> +K_EXPORT_COMPONENT_FACTORY( straight_connector, KGenericFactory<KivioConnectorFactory>( "KivioConnectorFactory" ) ) + +KivioConnectorFactory::KivioConnectorFactory(QObject *parent, const char* name, const QStringList& args) : + KivioStencilFactory(parent, name, args) +{ + kdDebug(43000) << "new straight line connector factory: " << endl; +} + +KivioStencil *KivioConnectorFactory::NewStencil() +{ + return new KivioStraightConnector(); +} + +KivioStencil *KivioConnectorFactory::NewStencil(const QString&) +{ + return new KivioStraightConnector(); +} + +//FIXME: Is this a memory leak? +QPixmap *KivioConnectorFactory::GetIcon() +{ + if( pIcon ) + return pIcon; + + pIcon = new QPixmap( (const char **)straight_connector_xpm ); + return pIcon; +} + +KivioStencilSpawnerInfo *KivioConnectorFactory::GetSpawnerInfo() +{ + return &sinfo; +} + + +KivioStraightConnector::KivioStraightConnector() + : Kivio1DStencil() +{ + m_pStart->setPosition(0.0f, 0.0f, false); + m_pEnd->setPosition(72.0f, 72.0f, false); + + m_startAH = new KivioArrowHead(); + m_endAH = new KivioArrowHead(); + m_needsWidth = false; + m_needsText = true; + + m_pCanProtect->clearBit( kpAspect ); + m_pCanProtect->clearBit( kpWidth ); + m_pCanProtect->clearBit( kpHeight ); + m_pCanProtect->clearBit( kpX ); + m_pCanProtect->clearBit( kpY ); + + // This is a stencil of type connector + setType(kstConnector); +} + +KivioStraightConnector::~KivioStraightConnector() +{ + delete m_startAH; + delete m_endAH; +} + +void KivioStraightConnector::setStartPoint( double x, double y ) +{ + m_pStart->setPosition( x, y, false ); + m_pStart->disconnect(); +} + +void KivioStraightConnector::setEndPoint( double x, double y ) +{ + m_pEnd->setPosition( x, y, false ); + m_pEnd->disconnect(); + + if( m_needsText ) + { + m_pTextConn->setPosition( (m_pStart->x()+m_pEnd->x())/2.0f, + (m_pStart->y()+m_pEnd->y())/2.0f, + false ); + } +} + +KivioCollisionType KivioStraightConnector::checkForCollision( KoPoint *p, double threshold ) +{ + const double end_thresh = 4.0f; + + double px = p->x(); + double py = p->y(); + + KivioConnectorPoint *pPoint; + + int i = kctCustom + 1; + pPoint = m_pConnectorPoints->first(); + while( pPoint ) + { + if( px >= pPoint->x() - end_thresh && + px <= pPoint->x() + end_thresh && + py >= pPoint->y() - end_thresh && + py <= pPoint->y() + end_thresh ) + { + return (KivioCollisionType)i; + } + + i++; + pPoint = m_pConnectorPoints->next(); + } + + + if( collisionLine( m_pStart->x(), m_pStart->y(), + m_pEnd->x(), m_pEnd->y(), + px, py, + threshold ) ) + { + return kctBody; + } + + return kctNone; +} + +KivioStencil *KivioStraightConnector::duplicate() +{ + KivioStraightConnector *pStencil = new KivioStraightConnector(); + + copyBasicInto( pStencil ); + + // Copy the arrow head information + pStencil->setStartAHType( m_startAH->type() ); + pStencil->setStartAHWidth( m_startAH->width() ); + pStencil->setStartAHLength( m_startAH->length() ); + + pStencil->setEndAHType( m_endAH->type() ); + pStencil->setEndAHWidth( m_endAH->width() ); + pStencil->setEndAHLength( m_endAH->length() ); + + *(pStencil->protection()) = *m_pProtection; + *(pStencil->canProtect()) = *m_pCanProtect; + + return pStencil; +} + +void KivioStraightConnector::paint( KivioIntraStencilData *pData ) +{ + KivioPainter *painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + double x1, y1, x2, y2; + double vecX, vecY; + double len; + + + painter->setLineStyle(m_pLineStyle); + double lineWidth = m_pLineStyle->width(); + painter->setLineWidth(zoomHandler->zoomItY(lineWidth)); + + x1 = zoomHandler->zoomItX(m_pStart->x()); + x2 = zoomHandler->zoomItX(m_pEnd->x()); + + y1 = zoomHandler->zoomItY(m_pStart->y()); + y2 = zoomHandler->zoomItY(m_pEnd->y()); + + + // Calculate the direction vector from start -> end + vecX = m_pEnd->x() - m_pStart->x(); + vecY = m_pEnd->y() - m_pStart->y(); + + // Normalize the vector + len = sqrt( vecX*vecX + vecY*vecY ); + if( len ) + { + vecX /= len; + vecY /= len; + + // Move the endpoints by the cuts + x1 += vecX * zoomHandler->zoomItX(m_startAH->cut()); + y1 += vecY * zoomHandler->zoomItY(m_startAH->cut()); + + x2 -= vecX * zoomHandler->zoomItX(m_endAH->cut()); + y2 -= vecY * zoomHandler->zoomItY(m_endAH->cut()); + } + + + // Draw the line + painter->drawLine( x1, y1, x2, y2 ); + + + // Now draw the arrow heads + if( len ) + { + painter->setBGColor( m_pFillStyle->color() ); + + m_startAH->paint(painter, m_pStart->x(), m_pStart->y(), -vecX, -vecY, zoomHandler); + m_endAH->paint(painter, m_pEnd->x(), m_pEnd->y(), vecX, vecY, zoomHandler); + } + + // Text + drawText(pData); +} + +void KivioStraightConnector::paintOutline( KivioIntraStencilData *pData ) +{ + KivioPainter *painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + double x1, y1, x2, y2; + double vecX, vecY; + double len; + + + painter->setLineStyle(m_pLineStyle); + double lineWidth = m_pLineStyle->width(); + painter->setLineWidth(zoomHandler->zoomItY(lineWidth)); + + x1 = zoomHandler->zoomItX(m_pStart->x()); + x2 = zoomHandler->zoomItX(m_pEnd->x()); + + y1 = zoomHandler->zoomItY(m_pStart->y()); + y2 = zoomHandler->zoomItY(m_pEnd->y()); + + + // Calculate the direction vector from start -> end + vecX = m_pEnd->x() - m_pStart->x(); + vecY = m_pEnd->y() - m_pStart->y(); + + // Normalize the vector + len = sqrt( vecX*vecX + vecY*vecY ); + if( len ) + { + vecX /= len; + vecY /= len; + + // Move the endpoints by the cuts + x1 += vecX * zoomHandler->zoomItX(m_startAH->cut()); + y1 += vecY * zoomHandler->zoomItY(m_startAH->cut()); + + x2 -= vecX * zoomHandler->zoomItX(m_endAH->cut()); + y2 -= vecY * zoomHandler->zoomItY(m_endAH->cut()); + } + + + // Draw the line + painter->drawLine( x1, y1, x2, y2 ); + + + // Now draw the arrow heads + if( len ) + { + painter->setBGColor( m_pFillStyle->color() ); + + m_startAH->paint(painter, m_pStart->x(), m_pStart->y(), -vecX, -vecY, zoomHandler); + m_endAH->paint(painter, m_pEnd->x(), m_pEnd->y(), vecX, vecY, zoomHandler); + } + + // Text + // Don't paint text in outline mode as it makes moving harder + drawText(pData); +} + +bool KivioStraightConnector::saveCustom( QDomElement &e, QDomDocument &doc ) +{ + e.appendChild( saveArrowHeads(doc) ); + + return true; +} + +bool KivioStraightConnector::loadCustom( const QDomElement &e ) +{ + QDomNode node; + QString name; + + node = e.firstChild(); + while( !node.isNull() ) + { + name = node.nodeName(); + if( name == "KivioArrowHeads" ) + { + loadArrowHeads( node.toElement() ); + } + + node = node.nextSibling(); + } + + updateGeometry(); + + return true; +} + +QDomElement KivioStraightConnector::saveArrowHeads( QDomDocument &doc ) +{ + QDomElement e = doc.createElement("KivioArrowHeads"); + + e.appendChild( m_startAH->saveXML(doc) ); + e.appendChild( m_endAH->saveXML(doc) ); + + return e; +} + +bool KivioStraightConnector::loadArrowHeads( const QDomElement &e ) +{ + QDomNode node; + QString nodeName; + QDomElement arrowE; + bool first=true; + + node = e.firstChild(); + while( !node.isNull() ) + { + nodeName = node.nodeName(); + arrowE = node.toElement(); + + if( nodeName == "KivioArrowHead" ) + { + if( first==true ) + { + m_startAH->loadXML(arrowE); + + first = false; + } + else + { + m_endAH->loadXML(arrowE); + } + } + + node = node.nextSibling(); + } + + return true; +} + +bool KivioStraightConnector::hasTextBox() const +{ + return true; +} + +#include "straight_connector.moc" diff --git a/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.h b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.h new file mode 100644 index 00000000..9cc602a5 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.h @@ -0,0 +1,95 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef STRAIGHT_CONNECTOR_H +#define STRAIGHT_CONNECTOR_H + + +#include "kivio_arrowhead.h" +#include "kivio_connector_point.h" +#include "kivio_custom_drag_data.h" +#include "kivio_intra_stencil_data.h" +#include "kiviostencilfactory.h" +#include "kivio_point.h" +#include "kivio_stencil.h" + +class KivioPage; + +#include <qcolor.h> +#include <qdom.h> + +#include "kivio_1d_stencil.h" + + +class KivioStraightConnector : public Kivio1DStencil +{ + protected: + KivioArrowHead *m_startAH; + KivioArrowHead *m_endAH; + + bool loadArrowHeads( const QDomElement & ); + QDomElement saveArrowHeads( QDomDocument & ); + + public: + KivioStraightConnector(); + virtual ~KivioStraightConnector(); + + virtual void setStartPoint( double, double ); + virtual void setEndPoint( double, double ); + + virtual KivioCollisionType checkForCollision( KoPoint *, double ); + + virtual KivioStencil* duplicate(); + + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + + virtual bool loadCustom( const QDomElement & ); + virtual bool saveCustom( QDomElement &, QDomDocument & ); + + + virtual void setStartAHType( int i ) { m_startAH->setType(i); } + virtual void setStartAHWidth( double f ) { m_startAH->setWidth(f); } + virtual void setStartAHLength( double f ) { m_startAH->setLength(f); } + virtual void setEndAHType( int i ) { m_endAH->setType(i); } + virtual void setEndAHWidth( double f ) { m_endAH->setWidth(f); } + virtual void setEndAHLength( double f ) { m_endAH->setLength(f); } + + virtual int startAHType() { return m_startAH->type(); } + virtual double startAHWidth() { return m_startAH->width(); } + virtual double startAHLength() { return m_startAH->length(); } + virtual int endAHType() { return m_endAH->type(); } + virtual double endAHWidth() { return m_endAH->width(); } + virtual double endAHLength() { return m_endAH->length(); } + + virtual bool hasTextBox() const; +}; + +class KIVIOPLUGINS_EXPORT KivioConnectorFactory : public KivioStencilFactory +{ + Q_OBJECT + public: + KivioConnectorFactory(QObject *parent=0, const char* name=0, const QStringList& args = QStringList()); + KivioStencil *NewStencil(const QString& name); + KivioStencil *NewStencil(); + QPixmap *GetIcon(); + KivioStencilSpawnerInfo *GetSpawnerInfo(); +}; + +#endif + diff --git a/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.xpm b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.xpm new file mode 100644 index 00000000..ffe56ed7 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/straight_connector/straight_connector.xpm @@ -0,0 +1,41 @@ +/* XPM */ +static const char * straight_connector_xpm[] = { +"32 32 6 1", +" c None", +". c #F8FCF8", +"+ c #808080", +"@ c #FFFA00", +"# c #000000", +"$ c #29D82F", +"...............................+", +".+++++++++++++++++++++++++++++.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@#@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@#@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@#@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@#@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@#@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@#@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@#@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@#@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@#@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@#@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@#@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@#@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@#@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@#@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@#@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +"...............................+", +"++++++++++++++++++++++++++++++++"}; diff --git a/kivio/plugins/kivioconnectortool/tool_connector.cpp b/kivio/plugins/kivioconnectortool/tool_connector.cpp new file mode 100644 index 00000000..87ec4729 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/tool_connector.cpp @@ -0,0 +1,375 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * Copyright (C) 2003-2005 Peter Simonsson <psn@linux.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "tool_connector.h" + +#include <qcursor.h> +#include <kdebug.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <KoPoint.h> +#include <KoZoomHandler.h> +#include <klocale.h> +#include <KoGuides.h> + +#include "kivio_view.h" +#include "kivio_canvas.h" +#include "kivio_page.h" +#include "kivio_doc.h" +#include "kivio_factory.h" + +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner.h" +#include "kivio_custom_drag_data.h" +#include "kivio_layer.h" +#include "kivio_point.h" +#include "kivio_stencil.h" +#include "straight_connector.h" +#include "kivio_pluginmanager.h" +#include "kivio_1d_stencil.h" +#include "kiviopolylineconnector.h" +#include "polylineconnectorspawner.h" +#include "mousetoolaction.h" + +ConnectorTool::ConnectorTool( KivioView* parent ) : Kivio::MouseTool(parent, "Connector Mouse Tool") +{ + m_connectorAction = new Kivio::MouseToolAction(i18n("Straight Connector"), "kivio_connector", 0, + actionCollection(), "connector"); + connect(m_connectorAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + connect(m_connectorAction, SIGNAL(activated()), this, SLOT(activateStraight())); + connect(m_connectorAction, SIGNAL(doubleClicked()), this, SLOT(makePermanent())); + m_connectorAction->setExclusiveGroup("ConnectorTool"); + + m_polyLineAction = new Kivio::MouseToolAction(i18n("Polyline Connector"), "kivio_connector", 0, + actionCollection(), "polyLineConnector"); + connect(m_polyLineAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + connect(m_polyLineAction, SIGNAL(activated()), this, SLOT(activatePolyline())); + connect(m_connectorAction, SIGNAL(doubleClicked()), this, SLOT(makePermanent())); + m_polyLineAction->setExclusiveGroup("ConnectorTool"); + + m_permanent = false; + + m_type = StraightConnector; + m_mode = stmNone; + m_pDragData = 0; + + m_pConnectorCursor1 = new QCursor(BarIcon("kivio_connector_cursor1",KivioFactory::global()),2,2); + m_pConnectorCursor2 = new QCursor(BarIcon("kivio_connector_cursor2",KivioFactory::global()),2,2); +} + +ConnectorTool::~ConnectorTool() +{ + delete m_pConnectorCursor1; + delete m_pConnectorCursor2; + delete m_pDragData; + m_pDragData = 0; +} + + +/** + * Event delegation + * + * @param e The event to be identified and processed + * + */ +bool ConnectorTool::processEvent(QEvent* e) +{ + switch (e->type()) + { + case QEvent::MouseButtonPress: + mousePress( static_cast<QMouseEvent*>(e) ); + return true; + break; + + case QEvent::MouseButtonRelease: + mouseRelease( static_cast<QMouseEvent*>(e) ); + return true; + break; + + case QEvent::MouseMove: + mouseMove( static_cast<QMouseEvent*>(e) ); + return true; + break; + + default: + break; + } + + return false; +} + +void ConnectorTool::setActivated(bool a) +{ + if(a) { + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; + m_pStencil = 0; + m_pDragData = 0; + view()->canvasWidget()->setShowConnectorTargets(true); + view()->canvasWidget()->repaint(); + emit activated(this); + } else { + if(m_pStencil && (m_mode == stmDrawRubber) && (m_type == PolyLineConnector)) { + Kivio::PolyLineConnector* polyconnector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); + polyconnector->removeLastPoint(); + + if(polyconnector->pointCount() > 1) { + connector(view()->canvasWidget()->rect()); + } else { + view()->activePage()->unselectStencil(polyconnector); + view()->activePage()->curLayer()->takeStencil(polyconnector); + delete polyconnector; + polyconnector = 0; + } + + view()->canvasWidget()->guideLines().repaintAfterSnapping(); + } + + m_pStencil = 0; + delete m_pDragData; + m_pDragData = 0; + m_type = StraightConnector; + m_connectorAction->setChecked(false); + m_polyLineAction->setChecked(false); + m_permanent = false; + view()->setStatusBarInfo(""); + view()->canvasWidget()->setShowConnectorTargets(false); + view()->canvasWidget()->repaint(); + } +} + +void ConnectorTool::connector(QRect) +{ + if (!m_pStencil) + return; + + delete m_pDragData; + m_pDragData = 0; + + KivioDoc* doc = view()->doc(); + KivioPage* page = view()->activePage(); + + m_pStencil->searchForConnections(page, view()->zoomHandler()->unzoomItY(4)); + doc->updateView(page); +} + +void ConnectorTool::mousePress( QMouseEvent *e ) +{ + if(e->button() == LeftButton) { + bool ok = true; + if(!m_pStencil || (m_type == StraightConnector)) { + ok = startRubberBanding(e); + } else { + if(m_pStencil) { + Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); + KivioCanvas* canvas = view()->canvasWidget(); + KivioPage* pPage = canvas->activePage(); + bool hit = false; + KoPoint point = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit); + + if(!hit) { + point = canvas->snapToGrid(startPoint); + } + + if((m_mode == stmDrawRubber) && hit) { + endRubberBanding(e); + } else { + connector->addPoint(point); + } + } + } + + if(ok) { + m_mode = stmDrawRubber; + } else { + m_mode = stmNone; + } + } else if(e->button() == RightButton) { + if(m_type == PolyLineConnector) { + if(m_mode == stmDrawRubber) { + endRubberBanding(e); + } + + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; + } + } +} + + +/** + * Tests if we should start rubber banding (always returns true). + */ +bool ConnectorTool::startRubberBanding( QMouseEvent *e ) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KivioDoc* doc = view()->doc(); + KivioPage* pPage = canvas->activePage(); + QString spawnerId; + + if(m_type == StraightConnector) { + spawnerId = "Dave Marotti - Straight Connector"; + } else { + spawnerId = "Internal - PolyLine Connector"; + } + + KivioStencilSpawner* ss = doc->findInternalStencilSpawner(spawnerId); + + if(!ss) { + kdDebug(43000) << "ConnectorTool: Failed to find StencilSpawner!" << endl; + return false; + } + + // Create the stencil + m_pStencil = static_cast<Kivio1DStencil*>(ss->newStencil()); + + bool hit = false; + startPoint = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit); + + if(!hit) { + startPoint = canvas->snapToGrid(startPoint); + } + + + if(!m_pStencil) { + return false; + } + + m_pStencil->setTextFont(doc->defaultFont()); + + // Unselect everything, add the stencil to the page, and select it + pPage->unselectAllStencils(); + pPage->addStencil(m_pStencil); + pPage->selectStencil(m_pStencil); + // Get drag info ready + m_pDragData = new KivioCustomDragData(); + m_pDragData->page = pPage; + m_pDragData->x = startPoint.x(); + m_pDragData->y = startPoint.y(); + + if(m_type == StraightConnector) { + KivioStraightConnector* connector = static_cast<KivioStraightConnector*>(m_pStencil); + m_pDragData->id = kctCustom + 2; + + connector->setStartPoint(startPoint.x(), startPoint.y()); + connector->setEndPoint(startPoint.x() + 10.0, startPoint.y() + 10.0); + } else { + Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); + m_pDragData->id = kctCustom + 1; + connector->addPoint(startPoint); + connector->addPoint(startPoint); + } + + m_pStencil->customDrag(m_pDragData); + + canvas->repaint(); + canvas->setCursor(*m_pConnectorCursor2); + return true; +} + +void ConnectorTool::mouseMove( QMouseEvent * e ) +{ + switch( m_mode ) + { + case stmDrawRubber: + continueRubberBanding(e); + break; + + default: + break; + } +} + +void ConnectorTool::continueRubberBanding( QMouseEvent *e ) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KivioPage* pPage = view()->activePage(); + bool hit = false; + KoPoint endPoint = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit); + + if(!hit) { + endPoint = canvas->snapToGridAndGuides(endPoint); + } + + m_pDragData->x = endPoint.x(); + m_pDragData->y = endPoint.y(); + + if(m_type == StraightConnector) { + KivioStraightConnector* connector = static_cast<KivioStraightConnector*>(m_pStencil); + connector->setEndPoint(endPoint.x(), endPoint.y()); + + m_pDragData->id = kctCustom + 2; + } else { + Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); + m_pDragData->id = kctCustom + connector->pointCount(); + } + + m_pStencil->customDrag(m_pDragData); + m_pStencil->updateGeometry(); + canvas->repaint(); +} + +void ConnectorTool::mouseRelease( QMouseEvent *e ) +{ + if(m_type == StraightConnector) { + switch( m_mode ) + { + case stmDrawRubber: + endRubberBanding(e); + break; + } + + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; + } +} + +void ConnectorTool::endRubberBanding(QMouseEvent *) +{ + connector(view()->canvasWidget()->rect()); + m_pStencil = 0; + m_mode = stmNone; + view()->canvasWidget()->guideLines().repaintAfterSnapping(); + + if(!m_permanent) { + view()->pluginManager()->activateDefaultTool(); + } +} + +void ConnectorTool::activateStraight() +{ + m_type = StraightConnector; + m_connectorAction->setChecked(true); + m_polyLineAction->setChecked(false); +} + +void ConnectorTool::activatePolyline() +{ + m_type = PolyLineConnector; + m_connectorAction->setChecked(false); + m_polyLineAction->setChecked(true); + view()->setStatusBarInfo(i18n("Left mouse button to start drawing, right to end drawing.")); +} + +void ConnectorTool::makePermanent() +{ + m_permanent = true; +} + +#include "tool_connector.moc" diff --git a/kivio/plugins/kivioconnectortool/tool_connector.h b/kivio/plugins/kivioconnectortool/tool_connector.h new file mode 100644 index 00000000..d0bb8b01 --- /dev/null +++ b/kivio/plugins/kivioconnectortool/tool_connector.h @@ -0,0 +1,101 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * Copyright (C) 2003-2005 Peter Simonsson <psn@linux.se> + * + * 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 TOOL_CONNECTOR_H +#define TOOL_CONNECTOR_H + +#include "kivio_mousetool.h" +#include <KoPoint.h> + +class QMouseEvent; +class QCursor; + +namespace Kivio { + class MouseToolAction; +} + +class KivioView; +class KivioPage; +class Kivio1DStencil; +class KivioCustomDragData; + +class ConnectorTool : public Kivio::MouseTool +{ + Q_OBJECT + public: + ConnectorTool( KivioView* parent ); + ~ConnectorTool(); + + virtual bool processEvent(QEvent* e); + + void connector(QRect); + + public slots: + void setActivated(bool a); + + protected slots: + void activateStraight(); + void activatePolyline(); + + void makePermanent(); + + signals: + void operationDone(); + + protected: + void mousePress(QMouseEvent *); + void mouseMove(QMouseEvent *); + void mouseRelease(QMouseEvent *); + + bool startRubberBanding(QMouseEvent*); + void continueRubberBanding(QMouseEvent *); + void endRubberBanding(QMouseEvent *); + + QPoint m_startPoint, m_releasePoint; + + // Connector Tool Mode + enum + { + stmNone, + stmDrawRubber + }; + + enum { + StraightConnector, + PolyLineConnector + }; + + private: + int m_mode; // Flag to indicate that we are drawing a rubber band + int m_type; // Type of connector + QCursor* m_pConnectorCursor1; + QCursor* m_pConnectorCursor2; + Kivio1DStencil* m_pStencil; + KoPoint startPoint; + KivioCustomDragData* m_pDragData; + + Kivio::MouseToolAction* m_connectorAction; + Kivio::MouseToolAction* m_polyLineAction; + + bool m_permanent; +}; + +#endif + + diff --git a/kivio/plugins/kivioselecttool/Makefile.am b/kivio/plugins/kivioselecttool/Makefile.am new file mode 100644 index 00000000..a664c979 --- /dev/null +++ b/kivio/plugins/kivioselecttool/Makefile.am @@ -0,0 +1,30 @@ +SUBDIRS = select_pics +kde_module_LTLIBRARIES =libkivioselecttool.la + + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) +libkivioselecttool_la_METASOURCES = AUTO +libkivioselecttool_la_SOURCES = \ + plugin.cpp\ + tool_select.cpp +EXTRA_DIST = \ + plugin.cpp\ + plugin.h\ + kivioselecttool.desktop\ + tool_select.cpp\ + tool_select.h\ + kivioselecttool.rc +libkivioselecttool_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +libkivioselecttool_la_LIBADD = $(LIB_KOTEXT) $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +rc_DATA = kivioselecttool.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kivioselecttool.desktop +desktopdir = $(kde_servicesdir) + diff --git a/kivio/plugins/kivioselecttool/kivioselecttool.desktop b/kivio/plugins/kivioselecttool/kivioselecttool.desktop new file mode 100644 index 00000000..fc1c211c --- /dev/null +++ b/kivio/plugins/kivioselecttool/kivioselecttool.desktop @@ -0,0 +1,64 @@ +[Desktop Entry] +X-KDE-Library=libkivioselecttool +Name=SelectTool for Kivio +Name[af]=Kies gereedskap vir Kivio +Name[ar]=أداة انتقاء Kivio +Name[az]=Kivio üçün seçim vasitəsi +Name[bg]=Инструмент за маркиране за Kivio +Name[br]=Ostilh dibab evit Kivio +Name[bs]=Odaberi alat za kivio +Name[ca]=Eina selectora per a Kivio +Name[cs]=Výběrový nástroj pro Kivio +Name[cy]=ErfynDewis i Kivio +Name[da]=Vælgeværktøj for Kivio +Name[de]=Auswahlwerkzeug für Kivio +Name[el]=Εργαλείο επιλογής για το Kivio +Name[eo]=Elektilo por Kivio +Name[es]=Selector para Kivio +Name[et]=Kivio valimise tööriist +Name[eu]=Kivio-ren hautapenerako tresna +Name[fa]=برگزیدن ابزار برای Kivio +Name[fi]=Valintatyökalu Kivioon +Name[fr]=Outil sélection pour Kivio +Name[fy]=Seleksjeark foar Kivio +Name[gl]=Ferramenta de Selección para Kivio +Name[he]=כלי בחירה של Kivio +Name[hr]=Alat odabira za Kivio +Name[hu]=Kijelölő eszköz a Kivio-hoz +Name[id]=Pilih alat untuk Kivio +Name[is]=Valtól fyrir Kivio +Name[it]=Strumento di selezione per Kivio +Name[ja]=Kivio 選択ツール +Name[km]=ឧបករណ៍ជ្រើសសម្រាប់ Kivio +Name[lo]=ເຄື່ອງມືສຳລັບການເລືອກສຳລັບແຜນຜັງໄດອະແກຣມ K +Name[lt]=SelectTool skirtas Kivio +Name[lv]=Izvēles rīks priekš Kivio +Name[ms]=Pilih Alat bagi Kivio +Name[mt]=Għodda tal-Għażla għall-Kivio +Name[nb]=Merkingsverktøy for Kivio +Name[nds]=Utwahlwarktüüch för Kivio +Name[ne]=किभियोका लागि उपकरण चयन गर्नुहोस् +Name[nl]=Selecteergereedschap voor Kivio +Name[nn]=Merkingsverktøy for Kivio +Name[pl]=Narzędzie zaznaczenia dla Kivio +Name[pt]=Ferramenta de Selecção para o Kivio +Name[pt_BR]=Ferramenta de seleção para o Kivio +Name[ro]=Unealtă selecţie pentru Kivio +Name[ru]=SelectTool для Kivio +Name[se]=Kivio-merkenreaidu +Name[sk]=Nástroje pre výber pre Kivio +Name[sl]=Izbirno orodje za Kivio +Name[sr]=Алат за одабирање за Kivio +Name[sr@Latn]=Alat za odabiranje za Kivio +Name[sv]=Markeringsverktyg för Kivio +Name[ta]=Kivio தேர்வுசெய் கருவி +Name[tg]=Интихоби Асбоб барои Kivio +Name[th]=เครื่องมือการเลือกสำหรับแผนผังไดอะแกรม K +Name[tr]=Kivio için Seçim Aracı +Name[uk]=Засіб вибору для Kivio +Name[ven]=Nangani tshishumiswa tsha Kivio +Name[xh]=Khetha Isixhobo se Kivio +Name[zh_CN]=Kivio 选择工具 +Name[zh_TW]=Kivio 選擇工具 +Name[zu]=Khetha ithuluzi le Kivio +Type=Service diff --git a/kivio/plugins/kivioselecttool/kivioselecttool.rc b/kivio/plugins/kivioselecttool/kivioselecttool.rc new file mode 100644 index 00000000..73ee7f11 --- /dev/null +++ b/kivio/plugins/kivioselecttool/kivioselecttool.rc @@ -0,0 +1,18 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioSelectTool" library="libkivioselecttool" version="7"> + <MenuBar> + <Menu name="Tools"> + <Action name="select" /> + </Menu> + </MenuBar> + <ToolBar name="ToolsToolBar"> + <Action name="select" /> + </ToolBar> + + <Menu name="StencilPopup"> + <Action name="editText" /> + <Separator /> + <Action name="formatStencil" /> + <Action name="formatConnector" /> + </Menu> +</kpartgui> diff --git a/kivio/plugins/kivioselecttool/plugin.cpp b/kivio/plugins/kivioselecttool/plugin.cpp new file mode 100644 index 00000000..49e68cac --- /dev/null +++ b/kivio/plugins/kivioselecttool/plugin.cpp @@ -0,0 +1,58 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "plugin.h" +#include "tool_select.h" + +#include "kivio_view.h" + +#include <kinstance.h> +#include <kiconloader.h> + +/*************************************************** + * Factory + ***************************************************/ +K_EXPORT_COMPONENT_FACTORY( libkivioselecttool, SelectToolFactory ) + +KInstance* SelectToolFactory::s_global = 0; + +SelectToolFactory::SelectToolFactory( QObject* parent, const char* name ) +: KLibFactory( parent, name ) +{ + s_global = new KInstance("kivio"); +} + +SelectToolFactory::~SelectToolFactory() +{ + delete s_global; +} + +QObject* SelectToolFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject *obj = new SelectTool( (KivioView*)parent ); + return obj; +} + +KInstance* SelectToolFactory::global() +{ + return s_global; +} +#include "plugin.moc" diff --git a/kivio/plugins/kivioselecttool/plugin.h b/kivio/plugins/kivioselecttool/plugin.h new file mode 100644 index 00000000..4fbb6f20 --- /dev/null +++ b/kivio/plugins/kivioselecttool/plugin.h @@ -0,0 +1,44 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef SELECT_PLUGIN_H +#define SELECT_PLUGIN_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class SelectToolFactory : public KLibFactory +{ Q_OBJECT +public: + SelectToolFactory( QObject* parent = 0, const char* name = 0 ); + ~SelectToolFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + + static KInstance* global(); + +private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kivioselecttool/select_pics/Makefile.am b/kivio/plugins/kivioselecttool/select_pics/Makefile.am new file mode 100644 index 00000000..047eaaa2 --- /dev/null +++ b/kivio/plugins/kivioselecttool/select_pics/Makefile.am @@ -0,0 +1,13 @@ +#1########################################################!@#$ +#### Makefile.am generated automatically by KDEStudio #### +#### WARNING! All changes made in this part will be lost! #### +############################################################## + +kiviopicsdir = $(kde_datadir)/kivio/pics + +kiviopics_DATA = kivio_arrow.xpm +EXTRA_DIST = \ + kivio_arrow.xpm +############################################################## +#### END KDEStudio part #### +#2########################################################!@#$ diff --git a/kivio/plugins/kivioselecttool/select_pics/kivio_arrow.xpm b/kivio/plugins/kivioselecttool/select_pics/kivio_arrow.xpm new file mode 100644 index 00000000..a186ac92 --- /dev/null +++ b/kivio/plugins/kivioselecttool/select_pics/kivio_arrow.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static const char *magick[] = { +"16 16 6 1", +" c Gray0", +". c #868686", +"X c #939393", +"o c #aeaeae", +"O c #bbbbbb", +"+ c None", +"++++++++++++++++", +"++++ .o+++++++++", +"++++ .o++++++++", +"++++ .O+++++++", +"++++ .o++++++", +"++++ .++++++", +"++++ .+++++", +"++++ .++++", +"++++ .O+++++", +"++++ .o+++++", +"++++ ++ X+++++", +"+++++++ .o++++", +"++++++++ o++++", +"++++++++ .++++", +"++++++++++++++++", +"++++++++++++++++" +}; diff --git a/kivio/plugins/kivioselecttool/tool_select.cpp b/kivio/plugins/kivioselecttool/tool_select.cpp new file mode 100644 index 00000000..333416f9 --- /dev/null +++ b/kivio/plugins/kivioselecttool/tool_select.cpp @@ -0,0 +1,1261 @@ +/* + * 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. + */ +/************************************************************************************** + * + * The code for dragging and resizing stencils is all contained in this class. KivioCanvas + * is used only for drawing since it's a canvas. + * + */ + +#include "tool_select.h" + +#include "kivio_view.h" +#include "kivio_doc.h" +#include "kivio_canvas.h" +#include "kivio_page.h" + +#include "kivio_custom_drag_data.h" +#include "kivio_layer.h" +#include "kivio_stencil.h" + +#include <kactionclasses.h> +#include <kpopupmenu.h> +#include <kdebug.h> +#include <KoZoomHandler.h> +#include <KoPoint.h> +#include <klocale.h> +#include <KoGuides.h> +#include "kivio_command.h" + +#include <qwmatrix.h> + +#include "kivio_pluginmanager.h" + +SelectTool::SelectTool( KivioView* parent ) : Kivio::MouseTool(parent, "Selection Mouse Tool") +{ + view()->pluginManager()->setDefaultTool(this); + + KShortcut selectShortCut(Key_Space); + selectShortCut.setSeq(1, QKeySequence(Key_Escape)); + m_selectAction = new KRadioAction(i18n("&Select"), "select", selectShortCut, actionCollection(), "select"); + connect(m_selectAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + + m_textEditAction = new KAction(i18n("&Edit Text..."), "text", Key_F2, + this, SLOT(editStencilText()), actionCollection(), "editText"); + (void) new KAction(i18n("Format &Stencils && Connectors..."), 0, 0, view(), SLOT(stencilFormat()), + actionCollection(), "formatStencil"); + m_arrowHeadAction = new KAction(i18n("Format &Arrowheads..."), 0, 0, view(), SLOT(arrowHeadFormat()), + actionCollection(), "formatConnector"); + + m_mode = stmNone; + m_pResizingStencil = NULL; + m_pCustomDraggingStencil = NULL; + + m_lstOldGeometry.setAutoDelete(true); + + m_customDragID = 0; +} + +SelectTool::~SelectTool() +{ +} + + +/** + * Event delegation + * + * @param e The event to be identified and processed + * + */ +bool SelectTool::processEvent(QEvent* e) +{ + KivioCanvas* canvas = view()->canvasWidget(); + QMouseEvent *m; + + switch (e->type()) + { + case QEvent::MouseButtonDblClick: + m = (QMouseEvent *)e; + + if( m->button() == LeftButton ) { + leftDoubleClick(m->pos()); + } + + canvas->setFocus(); + return true; + break; + + case QEvent::MouseButtonPress: + m = (QMouseEvent *)e; + + if( m->button() == RightButton ) { + showPopupMenu(m->globalPos()); + } else if( m->button() == LeftButton ) { + if(m->state() & ControlButton) { + m_controlKey = true; + } else { + m_controlKey = false; + } + + mousePress( m->pos() ); + } + + canvas->setFocus(); + return true; + break; + + case QEvent::MouseButtonRelease: + mouseRelease( ((QMouseEvent *)e)->pos() ); + canvas->setFocus(); + return true; + break; + + case QEvent::MouseMove: + mouseMove( static_cast<QMouseEvent*>(e)); + return true; + break; + + case QEvent::KeyPress: + if((static_cast<QKeyEvent*>(e)->key() >= Key_Left) && (static_cast<QKeyEvent*>(e)->key() <= Key_Down)) { + keyPress(static_cast<QKeyEvent*>(e)); + return true; + } + break; + + default: + break; + } + + return false; +} + +void SelectTool::setActivated(bool a) +{ + if(a) { + m_selectAction->setChecked(true); + view()->canvasWidget()->unsetCursor(); + m_mode = stmNone; + emit activated(this); + } else if(m_selectAction->isChecked()) { + m_selectAction->setChecked(false); + view()->canvasWidget()->activePage()->setPaintSelected(true); + } +} + +/** + * Selects all stencils inside a given rect + */ +void SelectTool::select(const QRect &r) +{ + // Calculate the start and end clicks in terms of page coordinates + KoPoint startPoint = view()->canvasWidget()->mapFromScreen( QPoint( r.x(), r.y() ) ); + KoPoint releasePoint = view()->canvasWidget()->mapFromScreen( QPoint( r.x() + r.width(), r.y() + r.height() ) ); + + + double x, y, w, h; + + // Calculate the x,y position of the selection box + x = startPoint.x() < releasePoint.x() ? startPoint.x() : releasePoint.x(); + y = startPoint.y() < releasePoint.y() ? startPoint.y() : releasePoint.y(); + + // Calculate the w/h of the selection box + w = releasePoint.x() - startPoint.x(); + + if( w < 0.0 ) { + w *= -1.0; + } + + h = releasePoint.y() - startPoint.y(); + + if( h < 0.0 ) { + h *= -1.0; + } + + // Tell the page to select all stencils in this box + view()->activePage()->selectStencils( x, y, w, h ); +} + +void SelectTool::mousePress(const QPoint &pos) +{ + // Last point is used for undrawing at the last position and calculating the distance the mouse has moved + m_lastPoint = view()->canvasWidget()->mapFromScreen(pos); + m_origPoint = m_lastPoint; + + // Check if we nailed a custom drag point on a selected stencil + if( startCustomDragging(pos, true) ) + { + m_mode = stmCustomDragging; + return; + } + + // Check if we are resizing + if( startResizing(pos) ) + { + m_mode = stmResizing; + return; + } + + + // Check if we nailed a custom drag point on any other stencil + if( startCustomDragging(pos, false) ) + { + m_mode = stmCustomDragging; + return; + } + + // Check if we can drag a stencil + if( startDragging(pos, false) ) + { + m_mode = stmDragging; + return; + } + + // This should always be the last 'start' call since it always returns true + if( startRubberBanding(pos) ) + { + m_mode = stmDrawRubber; + return; + } +} + + +/** + * Tests if we should start rubber banding (always returns true). + */ +bool SelectTool::startRubberBanding(const QPoint &pos) +{ + KivioCanvas* canvas = view()->canvasWidget(); + // We didn't find a stencil, so unselect everything if we aren't holding the control key down + if( !m_controlKey ) + canvas->activePage()->unselectAllStencils(); + + canvas->startRectDraw( pos, KivioCanvas::Rubber ); + canvas->repaint(); + + return true; +} + + +/** + * Tests if we can start dragging a stencil. + */ +bool SelectTool::startDragging(const QPoint &pos, bool onlySelected) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KivioPage *pPage = canvas->activePage(); + KivioStencil *pStencil; + int colType; + + // Figure out how big 4 pixels is in terms of points + double threshold = view()->zoomHandler()->unzoomItY(4); + + KoPoint pagePoint = canvas->mapFromScreen( pos ); + + pStencil = pPage->checkForStencil( &pagePoint, &colType, threshold, onlySelected ); + + if( !pStencil ) + return false; + + canvas->setEnabled(false); + + if( pStencil->isSelected() ) + { + // If we are clicking an already selected stencil, and the control + // key down, then unselect this stencil + if( m_controlKey==true ) { + pPage->unselectStencil( pStencil ); + } + + // Otherwise, it means we are just moving + } + else + { + // Clicking a new stencil, and the control key is not down + if( !m_controlKey ) + pPage->unselectAllStencils(); + + pPage->selectStencil( pStencil ); + // Update the auto guidelines + view()->canvasWidget()->updateAutoGuideLines(); + } + + // Create a new painter object + canvas->beginUnclippedSpawnerPainter(); + + // Build the list of old geometry + KivioSelectDragData *pData; + m_lstOldGeometry.clear(); + pStencil = canvas->activePage()->selectedStencils()->first(); + + while( pStencil ) + { + pData = new KivioSelectDragData; + pData->rect = pStencil->rect(); + m_lstOldGeometry.append(pData); + + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + m_selectedRect = view()->activePage()->getRectForAllSelectedStencils(); + changeMouseCursor(pos); + // Set the mode + m_mode = stmDragging; + m_firstTime = true; + canvas->setEnabled(true); + return true; +} + +bool SelectTool::startCustomDragging(const QPoint &pos, bool selectedOnly ) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KivioPage *pPage = canvas->activePage(); + KivioStencil *pStencil; + int colType; + + KoPoint pagePoint = canvas->mapFromScreen( pos ); + + // Figure out how big 4 pixels is in terms of points + double threshold = view()->zoomHandler()->unzoomItY(4); + + pStencil = pPage->checkForStencil( &pagePoint, &colType, threshold, selectedOnly ); + + if( !pStencil || colType < kctCustom ) { + return false; + } + + + if(pStencil->isSelected()) { + // If we are clicking an already selected stencil, and the control + // key down, then unselect this stencil + if(m_controlKey) { + pPage->unselectStencil(pStencil); + } + } else { + // Clicking a new stencil, and the control key is not down + if(!m_controlKey) { + pPage->unselectAllStencils(); + } + + pPage->selectStencil( pStencil ); + } + + m_pCustomDraggingStencil = pStencil; + + // Set the mode + m_mode = stmCustomDragging; + + m_customDragID = colType; + m_customDragOrigPoint = pStencil->customIDPoint(m_customDragID); + + view()->canvasWidget()->setShowConnectorTargets(true); + view()->canvasWidget()->repaint(); + + // Create a new painter object + canvas->beginUnclippedSpawnerPainter(); + m_firstTime = true; + + return true; +} + +/** + * Tests if we can start resizing a stencil + */ +bool SelectTool::startResizing(const QPoint &pos) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint pagePoint = canvas->mapFromScreen(pos); + KivioSelectDragData *pData; + + double x = pagePoint.x(); + double y = pagePoint.y(); + + // Search selected stencils to see if we have a resizing point + KivioStencil *pStencil = canvas->activePage()->selectedStencils()->first(); + while( pStencil ) + { + m_resizeHandle = isOverResizeHandle(pStencil, x, y); + if( m_resizeHandle > 0 ) + { + switch( m_resizeHandle ) + { + case 1: // top left + m_origPoint.setCoords(pStencil->x(), pStencil->y()); + break; + + case 2: + m_origPoint.setCoords((pStencil->x() + pStencil->w()) / 2.0, pStencil->y()); + break; + + case 3: + m_origPoint.setCoords(pStencil->x() + pStencil->w(), pStencil->y()); + break; + + case 4: + m_origPoint.setCoords(pStencil->x() + pStencil->w(), (pStencil->y() + pStencil->h()) / 2.0); + break; + + case 5: + m_origPoint.setCoords(pStencil->x() + pStencil->w(), pStencil->y() + pStencil->h()); + break; + + case 6: + m_origPoint.setCoords((pStencil->x() + pStencil->w()) / 2.0, pStencil->y() + pStencil->h()); + break; + + case 7: + m_origPoint.setCoords(pStencil->x(), pStencil->y() + pStencil->h()); + break; + + case 8: + m_origPoint.setCoords(pStencil->x(), (pStencil->y() + pStencil->h()) / 2.0); + break; + } + + m_lstOldGeometry.clear(); + pData = new KivioSelectDragData; + pData->rect = pStencil->rect(); + m_lstOldGeometry.append(pData); + + m_pResizingStencil = pStencil; + + // Create a new painter object + canvas->beginUnclippedSpawnerPainter(); + m_firstTime = true; + + return true; + } + + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + return false; +} + + + +void SelectTool::mouseMove(QMouseEvent* e) +{ + QPoint pos = e->pos(); + bool ignoreGridGuides = e->state() & ShiftButton; + + switch( m_mode ) + { + case stmDrawRubber: + continueRubberBanding(pos); + break; + + case stmDragging: + continueDragging(pos, ignoreGridGuides); + break; + + case stmCustomDragging: + continueCustomDragging(pos); + break; + + case stmResizing: + continueResizing(pos, ignoreGridGuides); + break; + + default: + changeMouseCursor(pos); + break; + } + + m_lastPoint = view()->canvasWidget()->mapFromScreen(pos); +} + +void SelectTool::continueRubberBanding(const QPoint &pos) +{ + view()->canvasWidget()->continueRectDraw( pos, KivioCanvas::Rubber ); +} + + +/** + * Continues the dragging process of a stencil (moving) + * + * How does this work? Initially we create a list of all the original + * geometry of all the selected stencils. We use that to calculate delta + * movements and snap them to the grid. + */ +void SelectTool::continueDragging(const QPoint &pos, bool ignoreGridGuides) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint pagePoint = canvas->mapFromScreen( pos ); + + double dx = pagePoint.x() - m_origPoint.x(); + double dy = pagePoint.y() - m_origPoint.y(); + + bool snappedX; + bool snappedY; + + double newX, newY; + + // Undraw the old stencils + if(!m_firstTime) { + canvas->drawSelectedStencilsXOR(); + } else { + canvas->activePage()->setPaintSelected(false); + canvas->repaint(); + m_firstTime = false; + } + + // Translate to the new position + KoPoint p; + + newX = m_selectedRect.x() + dx; + newY = m_selectedRect.y() + dy; + + if(!ignoreGridGuides) { + // First attempt a snap-to-grid + p.setCoords(newX, newY); + + p = canvas->snapToGrid(p); + + newX = p.x(); + newY = p.y(); + + // Now the guides override the grid so we attempt to snap to them + // The bottom + p.setCoords(m_selectedRect.x() + dx + m_selectedRect.width(), m_selectedRect.y() + dy + m_selectedRect.height()); + p = canvas->snapToGuides(p, snappedX, snappedY); + + if(snappedX) { + newX = p.x() - m_selectedRect.width(); + } + + if(snappedY) { + newY = p.y() - m_selectedRect.height(); + } + + // The middle + p.setCoords(m_selectedRect.x() + dx + (m_selectedRect.width() / 2.0), + m_selectedRect.y() + dy + (m_selectedRect.height() / 2.0)); + p = canvas->snapToGuides(p, snappedX, snappedY); + + if(snappedX) { + newX = p.x() - (m_selectedRect.width() / 2.0); + } + + if(snappedY) { + newY = p.y() - (m_selectedRect.height() / 2.0); + } + + // The top + p.setCoords(m_selectedRect.x() + dx, m_selectedRect.y() + dy); + p = canvas->snapToGuides(p, snappedX, snappedY); + + if(snappedX) { + newX = p.x(); + } + + if(snappedY) { + newY = p.y(); + } + } + + dx = newX - m_selectedRect.x(); + dy = newY - m_selectedRect.y(); + + KivioSelectDragData *pData; + KivioStencil *pStencil = canvas->activePage()->selectedStencils()->first(); + pData = m_lstOldGeometry.first(); + + while( pStencil && pData ) + { + newX = pData->rect.x() + dx; + newY = pData->rect.y() + dy; + + if( pStencil->protection()->at( kpX ) == false ) { + pStencil->setX(newX); + } + if( pStencil->protection()->at( kpY ) == false ) { + pStencil->setY(newY); + } + + pData = m_lstOldGeometry.next(); + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + // Draw the stencils + canvas->drawSelectedStencilsXOR(); + view()->updateToolBars(); +} + +void SelectTool::continueCustomDragging(const QPoint &pos) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint pagePoint = canvas->mapFromScreen(pos); + bool hit = false; + + if(m_pCustomDraggingStencil->type() == kstConnector){ + pagePoint = canvas->activePage()->snapToTarget(pagePoint, 8.0, hit); + } + + if(!hit) { + pagePoint = canvas->snapToGridAndGuides( pagePoint ); + } + + KivioCustomDragData data; + data.page = canvas->activePage(); + data.dx = pagePoint.x() - m_lastPoint.x(); + data.dy = pagePoint.y() - m_lastPoint.y(); + data.x = pagePoint.x(); + data.y = pagePoint.y(); + data.id = m_customDragID; + data.scale = view()->zoomHandler()->zoomedResolutionY(); + + + if(m_pCustomDraggingStencil->type() != kstConnector){ + // Undraw the old stencils + if(!m_firstTime) { + canvas->drawStencilXOR(m_pCustomDraggingStencil); + } else { + m_pCustomDraggingStencil->setHidden(true); + canvas->repaint(); + m_firstTime = false; + } + } + + // Custom dragging can only occur on one stencil + if( m_pCustomDraggingStencil ) + m_pCustomDraggingStencil->customDrag( &data ); + + // Draw the stencils + if(m_pCustomDraggingStencil->type() != kstConnector){ + canvas->drawStencilXOR(m_pCustomDraggingStencil); + } else { + view()->canvasWidget()->repaint(); + } + + view()->updateToolBars(); +} + + +void SelectTool::continueResizing(const QPoint &pos, bool ignoreGridGuides) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint pagePoint = canvas->mapFromScreen(pos); + + if(!ignoreGridGuides) { + pagePoint = canvas->snapToGridAndGuides( pagePoint ); + } + + KivioSelectDragData *pData = m_lstOldGeometry.first(); + +/* QWMatrix m; + double w2 = m_pResizingStencil->w() / 2.0; + double h2 = m_pResizingStencil->h() / 2.0; + m.translate(m_pResizingStencil->x(), m_pResizingStencil->y()); + m.translate(m_pResizingStencil->pinPoint().x(), m_pResizingStencil->pinPoint().y()); + m.rotate(-m_pResizingStencil->rotation()); + m.translate(-m_pResizingStencil->pinPoint().x(), -m_pResizingStencil->pinPoint().y()); + m.translate(-m_pResizingStencil->x(), -m_pResizingStencil->y()); + m.invert(); + + double x = pagePoint.x() * m.m11() + pagePoint.y() * m.m21() + m.dx(); + double y = pagePoint.x() * m.m12() + pagePoint.y() * m.m22() + m.dy();*/ + + if( !pData ) + { + kdDebug(43000) << "SelectTool::continueResizing() - Original geometry not found" << endl; + return; + } + + double dx = pagePoint.x() - m_origPoint.x(); + double dy = pagePoint.y() - m_origPoint.y(); + + if((dx > 0) || (dy > 0) || (dx < 0) || (dy < 0)) { // Do we really need to redraw? + // Undraw the old outline + if(!m_firstTime) { + canvas->drawStencilXOR( m_pResizingStencil ); + } else { + m_pResizingStencil->setHidden(true); + canvas->repaint(); + m_firstTime = false; + } + + double sx = pData->rect.x(); + double sy = pData->rect.y(); + double sw = pData->rect.width(); + double sh = pData->rect.height(); + double ratio = sw / sh; + + switch( m_resizeHandle ) + { + case 1: // top left + if( m_pResizingStencil->protection()->testBit( kpWidth )==false && + m_pResizingStencil->protection()->testBit( kpHeight )==false ) + { + if((dx > dy) && (dx != 0)) { + dy = dx / ratio; + } else { + dx = dy * ratio; + } + + m_pResizingStencil->setX( sx + dx ); + m_pResizingStencil->setW( sw - dx ); + + m_pResizingStencil->setY( sy + dy ); + m_pResizingStencil->setH( sh - dy ); + } + break; + + case 2: // top + if( m_pResizingStencil->protection()->testBit( kpHeight )==false ) + { + m_pResizingStencil->setY( sy + dy ); + m_pResizingStencil->setH( sh - dy ); + } + break; + + case 3: // top right + if( m_pResizingStencil->protection()->testBit( kpHeight )==false && + m_pResizingStencil->protection()->testBit( kpWidth )==false ) + { + if((dx > dy) && (dx != 0)) { + dy = -(dx / ratio); + } else { + dx = -(dy * ratio); + } + + m_pResizingStencil->setY( sy + dy ); + m_pResizingStencil->setH( sh - dy ); + + m_pResizingStencil->setW( sw + dx ); + } + break; + + case 4: // right + if( m_pResizingStencil->protection()->testBit( kpWidth )==false ) + { + // see old kivio source when snaptogrid gets implemented + //setX( SnapToGrid(sx+sw+dx)-sx ) + m_pResizingStencil->setW( sw + dx ); + } + break; + + case 5: // bottom right + if( m_pResizingStencil->protection()->testBit( kpWidth )==false && + m_pResizingStencil->protection()->testBit( kpHeight )==false ) + { + if((dx > dy) && (dx != 0)) { + dy = dx / ratio; + } else { + dx = dy * ratio; + } + + m_pResizingStencil->setW( sw + dx ); + m_pResizingStencil->setH( sh + dy ); + } + break; + + case 6: // bottom + if( m_pResizingStencil->protection()->testBit( kpHeight )==false ) + { + m_pResizingStencil->setH( sh + dy ); + } + break; + + case 7: // bottom left + if( m_pResizingStencil->protection()->testBit( kpWidth )==false && + m_pResizingStencil->protection()->testBit( kpHeight )==false ) + { + if((dx > dy) && (dx != 0)) { + dy = -(dx / ratio); + } else { + dx = -(dy * ratio); + } + + m_pResizingStencil->setX( sx + dx ); + m_pResizingStencil->setW( sw - dx ); + + m_pResizingStencil->setH( sh + dy ); + } + break; + + case 8: // left + if( m_pResizingStencil->protection()->testBit( kpWidth )==false ) + { + KoPoint pinPoint = m_pResizingStencil->pinPoint(); + m_pResizingStencil->setPinPoint(KoPoint(pinPoint.x() - (dx / 2.0), pinPoint.y())); + m_pResizingStencil->setX( sx + dx ); + m_pResizingStencil->setW( sw - dx ); + } + break; + + default: + kdDebug(43000) << "SelectTool::continueResizing() - unknown resize handle: " << m_resizeHandle << endl; + break; + } + + canvas->drawStencilXOR( m_pResizingStencil ); + view()->updateToolBars(); + } +} + + +/** + * Change the mouse cursor based on what it is over. + */ +void SelectTool::changeMouseCursor(const QPoint &pos) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint pagePoint = canvas->mapFromScreen(pos); + KivioStencil *pStencil; + double threshold = view()->zoomHandler()->unzoomItY(4); + int cursorType; + + // Iterate through all the selected stencils + pStencil = canvas->activePage()->selectedStencils()->first(); + while( pStencil ) + { + cursorType = isOverResizeHandle(pStencil, pagePoint.x(), pagePoint.y()); + switch( cursorType ) + { + case 1: // top left + canvas->setCursor( sizeFDiagCursor ); + return; + + case 2: // top + canvas->setCursor( sizeVerCursor ); + return; + + case 3: // top right + canvas->setCursor( sizeBDiagCursor ); + return; + + case 4: // right + canvas->setCursor( sizeHorCursor ); + return; + + case 5: // bottom right + canvas->setCursor( sizeFDiagCursor ); + return; + + case 6: // bottom + canvas->setCursor( sizeVerCursor ); + return; + + case 7: // bottom left + canvas->setCursor( sizeBDiagCursor ); + return; + + case 8: // left + canvas->setCursor( sizeHorCursor ); + return; + + default: + if( pStencil->checkForCollision( &pagePoint, threshold )!= kctNone ) + { + canvas->setCursor( sizeAllCursor ); + return; + } + break; + + } + + + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + canvas->unsetCursor(); +} + + +/** + * Tests a box for a point. Used only by isOverResizeHandle(). + */ +#define RESIZE_BOX_TEST( x, y, bx, by ) \ +x >= bx-three_pixels && \ +x <= bx+three_pixels && \ +y >= by-three_pixels && \ +y <= by+three_pixels + +/** + * Tests if a point is over a stencils + */ +int SelectTool::isOverResizeHandle( KivioStencil *pStencil, const double x, const double y ) +{ + double three_pixels = 4.0; + + int available; + + QWMatrix m; + double w = pStencil->w(); + double h = pStencil->h(); + double w2 = pStencil->w() / 2.0; + double h2 = pStencil->h() / 2.0; + m.translate(pStencil->x(), pStencil->y()); + m.translate(w2, h2); + m.rotate(pStencil->rotation()); + m.translate(-w2, -h2); + + // FIXME: this needs to be optimized!!!! + KoPoint tl(0 * m.m11() + 0 * m.m21() + m.dx(), 0 * m.m12() + 0 * m.m22() + m.dy()); + KoPoint t(w2 * m.m11() + 0 * m.m21() + m.dx(), w2 * m.m12() + 0 * m.m22() + m.dy()); + KoPoint tr(w * m.m11() + 0 * m.m21() + m.dx(), w * m.m12() + 0 * m.m22() + m.dy()); + KoPoint r(w * m.m11() + h2 * m.m21() + m.dx(), w * m.m12() + h2 * m.m22() + m.dy()); + KoPoint br(w * m.m11() + h * m.m21() + m.dx(), w * m.m12() + h * m.m22() + m.dy()); + KoPoint b(w2 * m.m11() + h * m.m21() + m.dx(), w2 * m.m12() + h * m.m22() + m.dy()); + KoPoint bl(0 * m.m11() + h * m.m21() + m.dx(), 0 * m.m12() + h * m.m22() + m.dy()); + KoPoint l(0 * m.m11() + h2 * m.m21() + m.dx(), 0 * m.m12() + h2 * m.m22() + m.dy()); + + available = pStencil->resizeHandlePositions(); + + // Quick reject + if( !available ) + return 0; + + + // Top left + if( available & krhpNW && + RESIZE_BOX_TEST( x, y, tl.x(), tl.y() ) ) + return 1; + + // Top + if( available & krhpN && + RESIZE_BOX_TEST( x, y, t.x(), t.y() ) ) + return 2; + + // Top right + if( available & krhpNE && + RESIZE_BOX_TEST( x, y, tr.x(), tr.y() ) ) + return 3; + + // Right + if( available & krhpE && + RESIZE_BOX_TEST( x, y, r.x(), r.y() ) ) + return 4; + + // Bottom right + if( available & krhpSE && + RESIZE_BOX_TEST( x, y, br.x(), br.y() ) ) + return 5; + + // Bottom + if( available & krhpS && + RESIZE_BOX_TEST( x, y, b.x(), b.y() ) ) + return 6; + + // Bottom left + if( available & krhpSW && + RESIZE_BOX_TEST( x, y, bl.x(), bl.y() ) ) + return 7; + + // Left + if( available & krhpW && + RESIZE_BOX_TEST( x, y, l.x(), l.y() ) ) + return 8; + + // Nothing found + return 0; +} + + +void SelectTool::mouseRelease(const QPoint &pos) +{ + m_releasePoint = pos; + + switch( m_mode ) + { + case stmDrawRubber: + endRubberBanding(pos); + break; + + case stmCustomDragging: + endCustomDragging(pos); + break; + + case stmDragging: + endDragging(pos); + break; + + case stmResizing: + endResizing(pos); + break; + } + + m_mode = stmNone; + + view()->canvasWidget()->guideLines().repaintAfterSnapping(); + view()->doc()->updateView(view()->activePage()); +} + +void SelectTool::endRubberBanding(const QPoint &pos) +{ + KivioCanvas* canvas = view()->canvasWidget(); + // End the rubber-band drawing + canvas->endRectDraw(); + + KoPoint p = canvas->mapFromScreen(pos); + + // We can't select if the start and end points are the same + if( m_origPoint.x() != p.x() && m_origPoint.y() != p.y() ) + { + select(canvas->rect()); + } + + view()->updateToolBars(); +} + +void SelectTool::endDragging(const QPoint&) +{ + KivioCanvas* canvas = view()->canvasWidget(); + canvas->activePage()->setPaintSelected(true); + KMacroCommand *macro=new KMacroCommand( i18n("Move Stencil")); + KivioStencil *pStencil = canvas->activePage()->selectedStencils()->first(); + KivioSelectDragData *pData = m_lstOldGeometry.first(); + bool moved = false; + + while( pStencil && pData ) + { + if((pData->rect.x() != pStencil->rect().x()) || (pData->rect.y() != pStencil->rect().y())) { + KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Move Stencil"), + pStencil, pData->rect, pStencil->rect(), canvas->activePage()); + macro->addCommand( cmd); + + if(pStencil->type() == kstConnector) { + pStencil->searchForConnections(view()->activePage(), view()->zoomHandler()->unzoomItY(4)); + } + + moved = true; + } + + pData = m_lstOldGeometry.next(); + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + if(moved) { + canvas->doc()->addCommand( macro ); + } else { + delete macro; + } + + canvas->drawSelectedStencilsXOR(); + canvas->endUnclippedSpawnerPainter(); + // Clear the list of old geometry + m_lstOldGeometry.clear(); +} + +void SelectTool::endCustomDragging(const QPoint&) +{ + KivioCanvas* canvas = view()->canvasWidget(); + m_pCustomDraggingStencil->setHidden(false); + KivioCustomDragCommand* cmd = new KivioCustomDragCommand(i18n("Move Connector Point"), view()->activePage(), + m_pCustomDraggingStencil, m_customDragID, m_customDragOrigPoint, + m_pCustomDraggingStencil->customIDPoint(m_customDragID)); + view()->doc()->addCommand(cmd); + m_customDragID = 0; + KivioStencil *pStencil = canvas->activePage()->selectedStencils()->first(); + + while( pStencil ) + { + if(pStencil->type() == kstConnector) { + pStencil->searchForConnections(view()->activePage(), view()->zoomHandler()->unzoomItY(4)); + } + + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + canvas->endUnclippedSpawnerPainter(); + + canvas->setShowConnectorTargets(false); + canvas->repaint(); +} + +void SelectTool::endResizing(const QPoint&) +{ + KivioCanvas* canvas = view()->canvasWidget(); + m_pResizingStencil->setHidden(false); + KivioResizeStencilCommand * cmd = new KivioResizeStencilCommand( i18n("Resize Stencil"), + m_pResizingStencil, m_lstOldGeometry.first()->rect, m_pResizingStencil->rect(), view()->activePage()); + canvas->doc()->addCommand( cmd ); + // Undraw the last outline + canvas->drawStencilXOR( m_pResizingStencil ); + + if(m_pResizingStencil->type() == kstConnector) { + m_pResizingStencil->searchForConnections(view()->activePage(), view()->zoomHandler()->unzoomItY(4)); + } + + // Deallocate the painter object + canvas->endUnclippedSpawnerPainter(); + + // Set the class vars to nothing + m_pResizingStencil = NULL; + m_resizeHandle = 0; +} + +/** + * Shows the popupmenu at a given point. + */ +void SelectTool::showPopupMenu( const QPoint &pos ) +{ + KPopupMenu* menu = 0; + + if(view()->activePage()->selectedStencils()->count() < 1) { + menu = static_cast<KPopupMenu*>(view()->factory()->container("PagePopup", view())); + } else { + menu = static_cast<KPopupMenu*>(view()->factory()->container("StencilPopup", view())); + m_arrowHeadAction->setEnabled(view()->activePage()->checkForStencilTypeInSelection(kstConnector)); + + if(view()->activePage()->checkForTextBoxesInSelection()) { + m_textEditAction->setEnabled(true); + } else { + m_textEditAction->setEnabled(false); + } + } + + if(menu) { + m_lastPoint = view()->canvasWidget()->mapFromScreen(pos); + menu->popup(pos); + } else { + kdDebug(43000) << "What no popup! *ARGH*!" << endl; + } +} + + +/** + * Handles what happens when a left-button double click occurs. + * + * If there are no stencils selected, this function returns. Otherwise + * it launches the text tool on the selected stencils and switches back + * to this tool when it's done. + */ +void SelectTool::leftDoubleClick(const QPoint& pos) +{ + if( view()->activePage()->selectedStencils()->count() <= 0 ) + return; + + KoPoint pagePoint = view()->canvasWidget()->mapFromScreen(pos); + // Figure out how big 4 pixels is in terms of points + double threshold = view()->zoomHandler()->unzoomItY(4); + int colType; + KivioPage *page = view()->activePage(); + KivioStencil* stencil = page->checkForStencil( &pagePoint, &colType, threshold, false); + + if(stencil) { + // Locate the text tool. If not found, bail with an error + Kivio::Plugin *p = view()->pluginManager()->findPlugin("Text Mouse Tool"); + + if( !p ) + { + kdDebug(43000) << "SelectTool::leftDoubleClick() - unable to locate Text Tool" << endl; + return; + } + + static_cast<Kivio::MouseTool*>(p)->applyToolAction(stencil, pagePoint); + } +} + +void SelectTool::editText(QPtrList<KivioStencil>* stencils) +{ + // Locate the text tool. If not found, bail with an error + Kivio::Plugin *p = view()->pluginManager()->findPlugin("Text Mouse Tool"); + if( !p ) + { + kdDebug(43000) << "SelectTool::leftDoubleClick() - unable to locate Text Tool" << endl; + return; + } + + // Select the text tool (which makes the text dialog pop up) + static_cast<Kivio::MouseTool*>(p)->applyToolAction(stencils); +} + +void SelectTool::showProperties() +{ + //FIXME: This needs to be implemented ;) + if(view()->activePage()->selectedStencils()->count() == 0) { + view()->paperLayoutDlg(); + } +} + +void SelectTool::editStencilText() +{ + editText(view()->activePage()->selectedStencils()); +} + +void SelectTool::keyPress(QKeyEvent* e) +{ + KivioCanvas* canvas = view()->canvasWidget(); + + canvas->setEnabled(false); + + // Create a new painter object + canvas->beginUnclippedSpawnerPainter(); + + // Build the list of old geometry + KivioSelectDragData *pData; + m_lstOldGeometry.clear(); + KivioStencil* pStencil = canvas->activePage()->selectedStencils()->first(); + + while( pStencil ) + { + pData = new KivioSelectDragData; + pData->rect = pStencil->rect(); + m_lstOldGeometry.append(pData); + + + pStencil = canvas->activePage()->selectedStencils()->next(); + } + + m_selectedRect = view()->activePage()->getRectForAllSelectedStencils(); + // Set the mode + m_mode = stmDragging; + canvas->setEnabled(true); + m_origPoint = m_selectedRect.topLeft(); + KivioGridData gd = view()->doc()->grid(); + bool ignoreGridGuides = e->state() & ShiftButton; + double distX, distY; + + if(ignoreGridGuides || !view()->doc()->grid().isSnap) { + distX = view()->zoomHandler()->unzoomItX(1); + distY = view()->zoomHandler()->unzoomItY(1); + } else { + distX = gd.freq.width(); + distY = gd.freq.height(); + } + + switch(e->key()) { + case Key_Left: + continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x() - distX, + m_selectedRect.y())), ignoreGridGuides); + break; + case Key_Up: + continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x(), + m_selectedRect.y() - distY)), ignoreGridGuides); + break; + case Key_Right: + continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x() + distX, + m_selectedRect.y())), ignoreGridGuides); + break; + case Key_Down: + continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x(), + m_selectedRect.y() + distY)), ignoreGridGuides); + break; + default: + break; + } + + endDragging(QPoint()); + canvas->guideLines().repaintAfterSnapping(); + canvas->setFocus(); +} + +#include "tool_select.moc" diff --git a/kivio/plugins/kivioselecttool/tool_select.h b/kivio/plugins/kivioselecttool/tool_select.h new file mode 100644 index 00000000..6a6bd9b5 --- /dev/null +++ b/kivio/plugins/kivioselecttool/tool_select.h @@ -0,0 +1,135 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * Copyright (C) 2003-2005 Peter Simonsson <psn@linux.se> + * + * 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 TOOL_SELECT_H +#define TOOL_SELECT_H + +#include <qptrlist.h> +#include <KoPoint.h> +#include <KoRect.h> +#include "kivio_mousetool.h" + +class KivioView; +class KivioPage; +class QMouseEvent; +class QKeyEvent; +class KPopupMenu; +class KRadioAction; +class KAction; + +class KivioStencil; + +class KivioSelectDragData +{ + public: + KoRect rect; +}; + +enum { + stCut=1, + stCopy, + stPaste, + stSendToBack, + stBringToFront, + stGroup, + stUngroup +}; + +class SelectTool : public Kivio::MouseTool +{ + Q_OBJECT + public: + SelectTool( KivioView* parent ); + ~SelectTool(); + + virtual bool processEvent(QEvent* e); + + void select(const QRect&); + + public slots: + void setActivated(bool a); + + signals: + void operationDone(); + + protected slots: + void editText(QPtrList<KivioStencil>* stencils); + void showProperties(); + void editStencilText(); + + protected: + void mousePress(const QPoint&); + void mouseMove(QMouseEvent*); + void mouseRelease(const QPoint&); + void leftDoubleClick(const QPoint&); + + bool startResizing(const QPoint&); + bool startDragging(const QPoint&, bool); + bool startCustomDragging(const QPoint&, bool); + bool startRubberBanding(const QPoint&); + + void continueDragging(const QPoint&, bool ignoreGridGuides = false); + void continueCustomDragging(const QPoint&); + void continueResizing(const QPoint&, bool ignoreGridGuides = false); + void continueRubberBanding(const QPoint&); + + void endResizing(const QPoint&); + void endDragging(const QPoint&); + void endCustomDragging(const QPoint&); + void endRubberBanding(const QPoint&); + + void showPopupMenu(const QPoint&); + + void changeMouseCursor(const QPoint&); + int isOverResizeHandle( KivioStencil *pStencil, const double x, const double y ); + + void keyPress(QKeyEvent* e); + + QPoint m_startPoint, m_releasePoint; + KoPoint m_lastPoint; + KoPoint m_origPoint; + + // Select Tool Mode + enum { + stmNone, + stmDrawRubber, + stmDragging, + stmCustomDragging, + stmResizing + }; + + private: + int m_mode; // Flag to indicate that we are drawing a rubber band + KivioStencil *m_pResizingStencil; + KivioStencil *m_pCustomDraggingStencil; + int m_resizeHandle; + bool m_controlKey; + int m_customDragID; + QPtrList <KivioSelectDragData> m_lstOldGeometry; + KoRect m_selectedRect; + KoPoint m_customDragOrigPoint; + + KRadioAction* m_selectAction; + KAction* m_arrowHeadAction; + KAction* m_textEditAction; + + bool m_firstTime; +}; + +#endif diff --git a/kivio/plugins/kiviosmlconnector/Makefile.am b/kivio/plugins/kiviosmlconnector/Makefile.am new file mode 100644 index 00000000..ee352d9a --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/Makefile.am @@ -0,0 +1,24 @@ +SUBDIRS=. sml_connector +kde_module_LTLIBRARIES =libkiviosmlconnector.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + -I$(top_srcdir)/kivio/plugins/kiviosmlconnector/sml_connector \ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) + +METASOURCES = AUTO +libkiviosmlconnector_la_SOURCES = plugin.cpp tool_connector.cpp +libkiviosmlconnector_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +libkiviosmlconnector_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + + + +rc_DATA = kiviosmlconnector.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kiviosmlconnector.desktop +desktopdir = $(kde_servicesdir) + diff --git a/kivio/plugins/kiviosmlconnector/README b/kivio/plugins/kiviosmlconnector/README new file mode 100644 index 00000000..07f4bb31 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/README @@ -0,0 +1,16 @@ +DESIGN: + This plugin will create a connector from a path created from a series of points. At each point a handle will be placed, this includes connection points and control handles. + + Arrows are only available at the end points and only end points can connect to other shapes. + +Example SML: +<KivioConnector> + <Type data="Xor"/> + <Points> + <KivioPoint x="40" y="50" type="bezier"/> + <KivioPoint x="30" y="40" type="bezier"/> + <KivioPoint x="10" y="40" type="bezier"/> + <KivioPoint x="0" y="50" type="bezier"/> + </Points> +</KivioConnector +This will create an arc shaped connector with handles at the control points and handles at the end points diff --git a/kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop new file mode 100644 index 00000000..b835128a --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.desktop @@ -0,0 +1,50 @@ +[Desktop Entry] +X-KDE-Library=libkiviosmlconnector +Name=SML Based ConnectorTool for Kivio +Name[bg]=Инструмент базиран на SML за свързване за Kivio +Name[ca]=Eina de connexió per a Kivio basada en SML +Name[cs]=Spojovací nástroj pro Kivio (SML) +Name[cy]=ErfynCysylltu i Kivio, wedi'i Seilio ar SML +Name[da]=SML-baseret Connector-værktøj for Kivio +Name[de]=SML-basiertes Verbindungswerkzeug für Kivio +Name[el]=Εργαλείο σύνδεσης βασισμένο σε SML για το Kivio +Name[eo]=SML-bazita Konektilo por Kivio +Name[es]=Herramienta de conexión para Kivio basada en SML +Name[et]=Kivio SML-põhine ühenduste tööriist +Name[eu]=Kivio-ren SML-n oinarritutako konexiorako tresna +Name[fa]=ابزار اتصال بر اساس SML برای Kivio +Name[fi]=SML-pohjainen yhdistämistyökalu Kivioon +Name[fr]=Outil connexion, basé sur SML, pour Kivio +Name[fy]=SML-basearre ferbiningshelpprogramma foar Kivio +Name[gl]=Ferramenta de Conexón baseada en SML para Kivio +Name[he]=כלי חיבור מבוסס SML עבור Kivio +Name[hr]=Alat povezivanja za Kivio zasnovan na SML +Name[hu]=SML-alapú összekapcsoló eszköz a Kivióhoz +Name[is]=SML byggt tengitól fyrir Kivio +Name[it]=Strumento di connessione basato su SML per Kivio +Name[ja]=Kivio SML ベースのコネクタツール +Name[km]=ឧបករណ៍តភ្ជាប់ផ្អែកលើ SML សម្រាប់ Kivio +Name[lv]=SML bāzēts savienotājrīks priekš Kivio +Name[ms]=Alat Penyambung Berasaskan SML bagi Kivio +Name[nb]=SML-basert koblingsverktøy for Kivio +Name[nds]=Op SML opbuut Tokoppelwarktüüch för Kivio +Name[ne]=किभियोका लागि SML आधारित योजक +Name[nl]=SML-gebaseerd verbindingshulpprogramma voor Kivio +Name[nn]=SML-basert sambandsverktøy for Kivio +Name[pl]=Narzędzie łącznika oparte na SML dla Kivio +Name[pt]=Ferramenta de Ligação baseada em SML para o Kivio +Name[pt_BR]=Ferramenta SML Baseada em Conector para o Kivio +Name[ru]=Соединения SML для Kivio +Name[se]=SML-vuođđuduvvon oktavuohtareaidu Kivio várás +Name[sk]=Spojovací nástroj pre Kivio založený na SML +Name[sl]=Priključno orodje za Kivio na osnovi SML +Name[sr]=Алат за повезивање за Kivio заснован на SML-у +Name[sr@Latn]=Alat za povezivanje za Kivio zasnovan na SML-u +Name[sv]=SML-baserat kopplingsverktyg för Kivio +Name[ta]= SML Kivio இணைப்புக்கருவி +Name[tg]=SML Асбоби Пайвандкунаки База барои Kivio +Name[tr]=SML tabanlı Kivio Bağlantı Aracı +Name[uk]=З'єднання SML для Kivio +Name[zh_CN]=Kivio 基于 SML 的连接件工具 +Name[zh_TW]=Kivio SML式連接器工具 +Type=Service diff --git a/kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc new file mode 100644 index 00000000..fc70e42d --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/kiviosmlconnector.rc @@ -0,0 +1,8 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioSMLConnector" library="libkiviosmlconnector" version="2"> +<MenuBar> + <Menu name="Tools"> + <Action name="sml_connector"/> + </Menu> +</MenuBar> +</kpartgui> diff --git a/kivio/plugins/kiviosmlconnector/plugin.cpp b/kivio/plugins/kiviosmlconnector/plugin.cpp new file mode 100644 index 00000000..ee12cf17 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/plugin.cpp @@ -0,0 +1,58 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "plugin.h" +#include "tool_connector.h" + +#include "kivio_view.h" + +#include <kinstance.h> +#include <kiconloader.h> + +/*************************************************** + * Factory + ***************************************************/ +K_EXPORT_COMPONENT_FACTORY( libkiviosmlconnector, SMLConnectorFactory ) + +KInstance* SMLConnectorFactory::s_global = 0; + +SMLConnectorFactory::SMLConnectorFactory( QObject* parent, const char* name ) +: KLibFactory( parent, name ) +{ + s_global = new KInstance("kivio"); +} + +SMLConnectorFactory::~SMLConnectorFactory() +{ + delete s_global; +} + +QObject* SMLConnectorFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject *obj = new SMLConnector( (KivioView*)parent ); + return obj; +} + +KInstance* SMLConnectorFactory::global() +{ + return s_global; +} +#include "plugin.moc" diff --git a/kivio/plugins/kiviosmlconnector/plugin.h b/kivio/plugins/kiviosmlconnector/plugin.h new file mode 100644 index 00000000..530d8de8 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/plugin.h @@ -0,0 +1,44 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef SML_CONNECTOR_PLUGIN_H +#define SML_CONNECTOR_PLUGIN_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class SMLConnectorFactory : public KLibFactory +{ Q_OBJECT +public: + SMLConnectorFactory( QObject* parent = 0, const char* name = 0 ); + ~SMLConnectorFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + + static KInstance* global(); + +private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am b/kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am new file mode 100644 index 00000000..0b60c3f6 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/Makefile.am @@ -0,0 +1,23 @@ +kde_module_LTLIBRARIES =sml_connector.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) + +METASOURCES = AUTO + +sml_connector_la_SOURCES = sml_connector.cpp +sml_connector_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +sml_connector_la_LIBADD = $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +stencildir = $(kde_datadir)/kivio/autoloadStencils +stencil_DATA = sml_connector.xpm + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(stencildir) + rm -f $(DESTDIR)$(stencildir)/sml_connector.so + $(LN_S) $(kde_moduledir)/sml_connector.so $(DESTDIR)$(stencildir)/sml_connector.so + +uninstall-local: + rm -f $(DESTDIR)$(stencildir)/sml_connector.so diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp new file mode 100644 index 00000000..b6770700 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.cpp @@ -0,0 +1,434 @@ +/* +* Kivio - Visual Modelling and Flowcharting +* Copyright (C) 2000-2001 theKompany.com & Dave Marotti +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include <stdio.h> +#include <math.h> +#include "sml_connector.h" + +#include "kivio_common.h" +#include "kivio_connector_target.h" +#include "kivio_layer.h" +#include "kivio_line_style.h" +#include "kivio_page.h" +#include "kivio_painter.h" +#include "kivio_stencil.h" +#include "kivio_stencil_spawner.h" +#include "kivio_stencil_spawner_info.h" +#include "kivio_stencil_spawner_set.h" +#include "kivio_text_style.h" +#include "kivio_shape.h" +#include "kivio_shape_data.h" +#include "kivio_point.h" + +#include "tkmath.h" + +#include <qcolor.h> +#include <qpixmap.h> +#include <kdebug.h> +#include <KoZoomHandler.h> +#include <kiconloader.h> + +static KivioStencilSpawnerInfo sinfo = KivioStencilSpawnerInfo( "Ian Reinhart Geiser", "SML Connector", "SML Connector", "SML Based Connector", "0.1", "http://localhost/", "", "off" ); +#include <kgenericfactory.h> + +K_EXPORT_COMPONENT_FACTORY( sml_connector, KGenericFactory<KivioSMLConnectorFactory>( "KivioSMLConnectorFactory" ) ) + +KivioSMLConnectorFactory::KivioSMLConnectorFactory( QObject *parent, const char* name, const QStringList& args ) : + KivioStencilFactory( parent, name, args ) +{ + kdDebug(43000) << "new sml stencil factory: " << endl; +} + +KivioStencil *KivioSMLConnectorFactory::NewStencil( const QString& name ) +{ + return new KivioSMLConnector( name ); +} + +KivioStencil *KivioSMLConnectorFactory::NewStencil() +{ + return new KivioSMLConnector( "basic_line" ); +} + + +QPixmap *KivioSMLConnectorFactory::GetIcon() +{ + return & BarIcon( "SML_conn" ); +} + +KivioStencilSpawnerInfo *KivioSMLConnectorFactory::GetSpawnerInfo() +{ + return & sinfo; +} + +KivioSMLConnector::KivioSMLConnector( const QString &name ) + : Kivio1DStencil(), m_name( name ) +{ + + m_pStart->setPosition( 0.0f, 0.0f, false ); + m_pEnd->setPosition( 72.0f, 72.0f, false ); + + m_startAH = new KivioArrowHead(); + m_endAH = new KivioArrowHead(); + m_needsWidth = false; + m_needsText = true; + + m_pCanProtect->clearBit( kpAspect ); + m_pCanProtect->clearBit( kpWidth ); + m_pCanProtect->clearBit( kpHeight ); + m_pCanProtect->clearBit( kpX ); + m_pCanProtect->clearBit( kpY ); + + // This is a stencil of type connector + setType( kstConnector ); + + // We only have one shape, an open path. + //m_shape = new KivioShape(); + //m_shape->shapeData() ->setShapeType( KivioShapeData::kstOpenPath ); + loadPath( name ); +} + +KivioSMLConnector::~KivioSMLConnector() +{ + delete m_startAH; + delete m_endAH; +} + +void KivioSMLConnector::setStartPoint( double x, double y ) +{ + m_pStart->setPosition( x, y, false ); + m_pStart->disconnect(); + + if ( m_needsText ) + { + m_pTextConn->setPosition( ( m_pEnd->x() + m_pStart->x() ) / 2.0f, + ( m_pEnd->y() + m_pStart->y() ) / 2.0f, + false ); + } + + // Set list end point + m_pConnectorPoints ->first() ->setX( x ); + m_pConnectorPoints ->first() ->setY( y ); + +} + +void KivioSMLConnector::setEndPoint( double x, double y ) +{ + m_pEnd->setPosition( x, y, false ); + m_pEnd->disconnect(); + m_pConnectorPoints ->last() ->setX( x ); + m_pConnectorPoints ->last() ->setY( y ); +} + +KivioCollisionType KivioSMLConnector::checkForCollision( KivioPoint *p, double threshold ) +{ + const double end_thresh = 4.0f; + + double px = p->x(); + double py = p->y(); + + KivioConnectorPoint *pPoint; + + int i = kctCustom + 1; + pPoint = m_pConnectorPoints->first(); + while ( pPoint ) + { + if ( px >= pPoint->x() - end_thresh && + px <= pPoint->x() + end_thresh && + py >= pPoint->y() - end_thresh && + py <= pPoint->y() + end_thresh ) + { + return ( KivioCollisionType ) i; + } + + i++; + pPoint = m_pConnectorPoints->next(); + } + + + if ( collisionLine( m_pStart->x(), m_pStart->y(), + m_pEnd->x(), m_pEnd->y(), + px, py, + threshold ) ) + { + return kctBody; + } + + return kctNone; +} + +KivioStencil *KivioSMLConnector::duplicate() +{ + KivioSMLConnector * pStencil = new KivioSMLConnector( m_name ); + + + // TODO: Copy internal pointlist information? + + // Copy the arrow head information + pStencil->setStartAHType( m_startAH->type() ); + pStencil->setStartAHWidth( m_startAH->width() ); + pStencil->setStartAHLength( m_startAH->length() ); + + pStencil->setEndAHType( m_endAH->type() ); + pStencil->setEndAHWidth( m_endAH->width() ); + pStencil->setEndAHLength( m_endAH->length() ); + + *( pStencil->protection() ) = *m_pProtection; + *( pStencil->canProtect() ) = *m_pCanProtect; + + return pStencil; +} +/* +void KivioSMLConnector::drawOpenPath( KivioShape *pShape, KivioIntraStencilData *pData ) +{ + KivioPainter * painter; + KivioShapeData *pShapeData = pShape->shapeData(); + KivioPoint *pPoint, *pNewPoint; + QPtrList <KivioPoint> *pPointList = pShapeData->pointList(); + + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete( true ); + + pPoint = pPointList->first(); + while ( pPoint ) + { + pNewPoint = new KivioPoint( pData->zoomHandler->zoomItX( pPoint->x() ), + pData->zoomHandler->zoomItY( pPoint->y() ), + pPoint->pointType() ); + pNewPoints->append( pNewPoint ); + + pPoint = pPointList->next(); + } + + painter = pData->painter; + double lineWidth = pShapeData->lineStyle() ->width(); + painter->setLineWidth( pData->zoomHandler->zoomItY( lineWidth ) ); + painter->setFGColor( pShapeData->lineStyle() ->color() ); + + painter->drawOpenPath( pNewPoints ); + delete pNewPoints; +} +*/ +void KivioSMLConnector::paint( KivioIntraStencilData *pData ) +{ + KivioPainter * painter = pData->painter; + KoZoomHandler* zoomHandler = pData->zoomHandler; + double x1, y1, x2, y2; + double vecX, vecY; + double len; + + + painter->setFGColor( m_pLineStyle->color() ); + painter->setLineWidth( zoomHandler->zoomItY( m_pLineStyle->width() ) ); + + x1 = zoomHandler->zoomItX( m_pStart->x() ); + x2 = zoomHandler->zoomItX( m_pEnd->x() ); + + y1 = zoomHandler->zoomItY( m_pStart->y() ); + y2 = zoomHandler->zoomItY( m_pEnd->y() ); + + + // Calculate the direction vector from start -> end + vecX = m_pEnd->x() - m_pStart->x(); + vecY = m_pEnd->y() - m_pStart->y(); + + // Normalize the vector + len = sqrt( vecX * vecX + vecY * vecY ); + if ( len ) + { + vecX /= len; + vecY /= len; + + // Move the endpoints by the cuts + x1 += vecX * zoomHandler->zoomItX( m_startAH->cut() ); + y1 += vecY * zoomHandler->zoomItY( m_startAH->cut() ); + + x2 -= vecX * zoomHandler->zoomItX( m_endAH->cut() ); + y2 -= vecY * zoomHandler->zoomItY( m_endAH->cut() ); + } + + + // Build shape up from m_pConnectorPoints + + + QPtrList <KivioPoint> *pNewPoints = new QPtrList<KivioPoint>; + pNewPoints->setAutoDelete( true ); + + pNewPoints->append(new KivioPoint( zoomHandler->zoomItX( m_pStart->x() ), + zoomHandler->zoomItY( m_pStart->y() ))); + + KivioConnectorPoint *pPoint = m_PointList.first(); + while ( pPoint ) + { + KivioPoint *pNewPoint = new KivioPoint( zoomHandler->zoomItX( pPoint->x() ), + zoomHandler->zoomItY( pPoint->y() )); + pNewPoints->append( pNewPoint ); + + pPoint = m_PointList.next(); + } + + pNewPoints->append(new KivioPoint( zoomHandler->zoomItX( m_pEnd->x() ), + zoomHandler->zoomItY( m_pEnd->y() ))); + painter = pData->painter; + double lineWidth = m_pLineStyle ->width(); + painter->setLineWidth( zoomHandler->zoomItY( lineWidth ) ); + painter->setFGColor( m_pLineStyle ->color() ); + + painter->drawOpenPath( pNewPoints ); + delete pNewPoints; + + // Now draw the arrow heads + if ( len ) + { + painter->setBGColor( m_pFillStyle->color() ); + + m_startAH->paint( painter, m_pStart->x(), m_pStart->y(), -vecX, -vecY, zoomHandler ); + m_endAH->paint( painter, m_pEnd->x(), m_pEnd->y(), vecX, vecY, zoomHandler ); + } + + // TODO: Text + drawText( pData ); +} + +void KivioSMLConnector::paintOutline( KivioIntraStencilData *pData ) +{ + paint( pData ); +} + +bool KivioSMLConnector::saveCustom( QDomElement &e, QDomDocument &doc ) +{ + kdDebug(43000) << "Save custom " << endl; + e.appendChild( saveArrowHeads( doc ) ); + + //QDomElement type = m_shape->saveXML(doc); + KivioConnectorPoint *p = m_PointList.first(); + while ( p ) + { + QDomElement pt = p->saveXML( doc ); + e.appendChild( pt ); + p = m_PointList.next(); + } + return true; +} + +bool KivioSMLConnector::loadCustom( const QDomElement &e ) +{ + kdDebug(43000) << "Load custom " << endl; + QDomNode node; + QString name; + + node = e.firstChild(); + while ( !node.isNull() ) + { + name = node.nodeName(); + if ( name == "KivioArrowHeads" ) + { + loadArrowHeads( node.toElement() ); + } + else if ( name == "KivioShape" ) + { + //m_shape->loadXML(node.toElement()); + QDomNode pts = node.firstChild(); + while ( !pts.isNull() ) + { + KivioConnectorPoint * pt = new KivioConnectorPoint(); + pt->loadXML( pts.toElement() ); + m_pConnectorPoints->append( pt ); + m_PointList.append( pt ); + pts = pts.nextSibling(); + } + } + node = node.nextSibling(); + } + + updateGeometry(); + + return true; +} + +QDomElement KivioSMLConnector::saveArrowHeads( QDomDocument &doc ) +{ + QDomElement e = doc.createElement( "KivioArrowHeads" ); + + e.appendChild( m_startAH->saveXML( doc ) ); + e.appendChild( m_endAH->saveXML( doc ) ); + + return e; +} + +bool KivioSMLConnector::loadArrowHeads( const QDomElement &e ) +{ + QDomNode node; + QString nodeName; + QDomElement arrowE; + bool first = true; + + node = e.firstChild(); + while ( !node.isNull() ) + { + nodeName = node.nodeName(); + arrowE = node.toElement(); + + if ( nodeName == "KivioArrowHead" ) + { + if ( first == true ) + { + m_startAH->loadXML( arrowE ); + + first = false; + } + else + { + m_endAH->loadXML( arrowE ); + } + } + + node = node.nextSibling(); + } + + return true; +} + + +bool KivioSMLConnector::loadPath( const QString &file ) +{ + kdDebug(43000) << "Loading :" << file << endl; + + m_PointList.clear(); + m_PointList.append(m_pStart); + + KivioConnectorPoint *pt = new KivioConnectorPoint(this,false); + pt->setPosition(m_pStart->x()+10,m_pStart->y()+10,false); +// m_PointList.append( pt ); + m_pConnectorPoints->append(pt); + + pt = new KivioConnectorPoint(this,false); + pt->setPosition(m_pStart->x()+20,m_pStart->y()+20,false); + m_PointList.append( pt ); + m_pConnectorPoints->append(pt); + + pt = new KivioConnectorPoint(this,false); + pt->setPosition(m_pStart->x()+30,m_pStart->y()+30,false); + m_PointList.append( pt ); + m_pConnectorPoints->append(pt); + +// m_PointList.append(m_pEnd); + m_name = file; + return true; +} + +#include "sml_connector.moc" diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h new file mode 100644 index 00000000..4371ff8a --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.h @@ -0,0 +1,104 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef SML_CONNECTOR_H +#define SML_CONNECTOR_H + + +#include "kivio_arrowhead.h" +#include "kivio_connector_point.h" +#include "kivio_custom_drag_data.h" +#include "kivio_intra_stencil_data.h" +#include "kiviostencilfactory.h" +#include "kivio_text_style.h" +#include "kivio_point.h" +#include "kivio_stencil.h" + +class KivioPage; +class KivioShape; +#include <qstringlist.h> +#include <qcolor.h> +#include <qdom.h> + +#include "kivio_1d_stencil.h" + + +class KivioSMLConnector : public Kivio1DStencil +{ +private: + bool loadPath(const QString &file); + //void drawOpenPath( KivioShape *, KivioIntraStencilData * ); + KivioShape *m_shape; + QPtrList<KivioConnectorPoint> m_PointList; + + QString m_name; +protected: + + KivioArrowHead *m_startAH; + KivioArrowHead *m_endAH; + + bool loadArrowHeads( const QDomElement & ); + QDomElement saveArrowHeads( QDomDocument & ); + virtual bool loadCustom( const QDomElement & ); + virtual bool saveCustom( QDomElement &, QDomDocument & ); + +public: + KivioSMLConnector(const QString& name); + virtual ~KivioSMLConnector(); + + virtual void setStartPoint( double, double ); + virtual void setEndPoint( double, double ); + + virtual KivioCollisionType checkForCollision( KivioPoint *, double ); + + virtual KivioStencil* duplicate(); + + virtual void paint( KivioIntraStencilData * ); + virtual void paintOutline( KivioIntraStencilData * ); + + + + + virtual void setStartAHType( int i ) { m_startAH->setType(i); } + virtual void setStartAHWidth( double f ) { m_startAH->setWidth(f); } + virtual void setStartAHLength( double f ) { m_startAH->setLength(f); } + virtual void setEndAHType( int i ) { m_endAH->setType(i); } + virtual void setEndAHWidth( double f ) { m_endAH->setWidth(f); } + virtual void setEndAHLength( double f ) { m_endAH->setLength(f); } + + virtual int startAHType() { return m_startAH->type(); } + virtual double startAHWidth() { return m_startAH->width(); } + virtual double startAHLength() { return m_startAH->length(); } + virtual int endAHType() { return m_endAH->type(); } + virtual double endAHWidth() { return m_endAH->width(); } + virtual double endAHLength() { return m_endAH->length(); } + +}; + +class KivioSMLConnectorFactory : public KivioStencilFactory +{ + Q_OBJECT + public: + KivioSMLConnectorFactory(QObject *parent=0, const char* name=0, const QStringList& args = QStringList()); + KivioStencil *NewStencil(const QString& name); + KivioStencil *NewStencil(); + QPixmap *GetIcon(); + KivioStencilSpawnerInfo *GetSpawnerInfo(); +}; +#endif + diff --git a/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.xpm b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.xpm new file mode 100644 index 00000000..ffe56ed7 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/sml_connector/sml_connector.xpm @@ -0,0 +1,41 @@ +/* XPM */ +static const char * straight_connector_xpm[] = { +"32 32 6 1", +" c None", +". c #F8FCF8", +"+ c #808080", +"@ c #FFFA00", +"# c #000000", +"$ c #29D82F", +"...............................+", +".+++++++++++++++++++++++++++++.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@#$$#@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@####@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@#@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@#@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@#@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@#@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@#@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@#@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@#@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@#@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@#@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@#@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@#@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@#@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@#@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@#@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@#@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@#$$#@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@####@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +"...............................+", +"++++++++++++++++++++++++++++++++"}; diff --git a/kivio/plugins/kiviosmlconnector/tool_connector.cpp b/kivio/plugins/kiviosmlconnector/tool_connector.cpp new file mode 100644 index 00000000..ded38f13 --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/tool_connector.cpp @@ -0,0 +1,248 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "tool_connector.h" + +#include <qcursor.h> +#include <kdebug.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <KoPoint.h> +#include <KoZoomHandler.h> +#include <kactionclasses.h> +#include <klocale.h> + +#include "kivio_view.h" +#include "kivio_canvas.h" +#include "kivio_page.h" +#include "kivio_doc.h" +#include "kivio_factory.h" + +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner.h" +#include "kivio_custom_drag_data.h" +#include "kivio_layer.h" +#include "kivio_point.h" +#include "kivio_stencil.h" +#include "sml_connector.h" + +SMLConnector::SMLConnector( KivioView* view ) + : Kivio::MouseTool(view, "SMLConnector") +{ + m_connectorAction = new KToggleAction(i18n("Polyline Connector"), "", 0, + actionCollection(), "sml_connector"); + connect(m_connectorAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + + m_mode = stmNone; + + m_pConnectorCursor1 = new QCursor(BarIcon("kivio_connector_cursor1",KivioFactory::global()),2,2); + m_pConnectorCursor2 = new QCursor(BarIcon("kivio_connector_cursor2",KivioFactory::global()),2,2); +} + +SMLConnector::~SMLConnector() +{ + delete m_pConnectorCursor1; + delete m_pConnectorCursor2; +} + + +/** + * Event delegation + * + * @param e The event to be identified and processed + * + */ +bool SMLConnector::processEvent( QEvent* e ) +{ + switch (e->type()) + { + case QEvent::MouseButtonPress: + mousePress( (QMouseEvent*)e ); + return true; + break; + + case QEvent::MouseButtonRelease: + mouseRelease( (QMouseEvent*)e ); + return true; + break; + + case QEvent::MouseMove: + mouseMove( (QMouseEvent*)e ); + return true; + break; + + default: + break; + } + + return false; +} + +void SMLConnector::setActivated(bool a) +{ + m_connectorAction->setChecked(a); + + if(a) { + kdDebug(43000) << "SMLConnector activate" << endl; + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; + m_pStencil = 0; + m_pDragData = 0; + emit activated(this); + } else { + m_pStencil = 0; + delete m_pDragData; + m_pDragData = 0; + } +} + +void SMLConnector::connector(QRect) +{ + if (!m_pStencil) + return; + + delete m_pDragData; + m_pDragData = 0; + + KivioDoc* doc = view()->doc(); + KivioPage* page = view()->activePage(); + + if (m_pStencil->w() < 3.0 && m_pStencil->h() < 3.0) { + page->unselectAllStencils(); + page->selectStencil(m_pStencil); + page->deleteSelectedStencils(); + m_pStencil = 0; + doc->updateView(page); + return; + } + + m_pStencil->searchForConnections(page, view()->zoomHandler()->unzoomItY(4)); + doc->updateView(page); +} + +void SMLConnector::mousePress( QMouseEvent *e ) +{ + if(e->button() == RightButton) + { + return; + } + if( startRubberBanding( e ) ) + { + m_mode = stmDrawRubber; + } +} + + +/** + * Tests if we should start rubber banding (always returns true). + */ +bool SMLConnector::startRubberBanding( QMouseEvent *e ) +{ + KivioDoc* doc = view()->doc(); + KivioPage* pPage = view()->activePage(); + KivioCanvas* canvas = view()->canvasWidget(); + + startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() )); + + // Create the stencil + KivioStencilSpawner* ss = doc->findInternalStencilSpawner("SML Connector"); + + if (!ss) { + kdDebug(43000) << "SMLTool: Failed to find StencilSpawner!" << endl; + return false; + } + + startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() )); + + // Create the stencil + m_pStencil = (KivioSMLConnector*)ss->newStencil("basic_line"); + m_pStencil->setTextFont(doc->defaultFont()); + + // Unselect everything, add the stencil to the page, and select it + pPage->unselectAllStencils(); + pPage->addStencil(m_pStencil); + pPage->selectStencil(m_pStencil); + + // Get drag info ready + m_pDragData = new KivioCustomDragData(); + m_pDragData->page = pPage; + m_pDragData->x = startPoint.x(); + m_pDragData->y = startPoint.y(); + m_pDragData->id = kctCustom + 2; + + m_pStencil->setStartPoint(startPoint.x() + 10.0f, startPoint.y() + 10.0f); + m_pStencil->setEndPoint(startPoint.x(), startPoint.y()); + m_pStencil->customDrag(m_pDragData); + + + canvas->repaint(); + canvas->setCursor(*m_pConnectorCursor2); + return true; +} + +void SMLConnector::mouseMove( QMouseEvent * e ) +{ + switch( m_mode ) + { + case stmDrawRubber: + continueRubberBanding(e); + break; + + default: + break; + } +} + +void SMLConnector::continueRubberBanding( QMouseEvent *e ) +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoPoint endPoint = canvas->mapFromScreen( e->pos() ); + endPoint = canvas->snapToGrid(endPoint); + + m_pStencil->setStartPoint(endPoint.x(), endPoint.y()); + + + m_pDragData->x = endPoint.x(); + m_pDragData->y = endPoint.y(); + m_pDragData->id = kctCustom + 1; + m_pStencil->customDrag(m_pDragData); + + m_pStencil->updateGeometry(); + canvas->repaint(); +} + +void SMLConnector::mouseRelease( QMouseEvent *e ) +{ + switch( m_mode ) + { + case stmDrawRubber: + endRubberBanding(e); + break; + } + + view()->canvasWidget()->setCursor(*m_pConnectorCursor1); + m_mode = stmNone; +} + +void SMLConnector::endRubberBanding(QMouseEvent *) +{ + connector(view()->canvasWidget()->rect()); + m_pStencil = 0; +} + +#include "tool_connector.moc" diff --git a/kivio/plugins/kiviosmlconnector/tool_connector.h b/kivio/plugins/kiviosmlconnector/tool_connector.h new file mode 100644 index 00000000..aecb26db --- /dev/null +++ b/kivio/plugins/kiviosmlconnector/tool_connector.h @@ -0,0 +1,85 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef SML_TOOL_CONNECTOR_H +#define SML_TOOL_CONNECTOR_H + +#include "kivio_mousetool.h" +#include <KoPoint.h> + +class QMouseEvent; +class QCursor; + +class KToggleAction; + +class KivioView; +class KivioPage; +class KivioSMLConnector; +class KivioCustomDragData; + +class SMLConnector : public Kivio::MouseTool +{ Q_OBJECT +public: + SMLConnector( KivioView* view ); + ~SMLConnector(); + + virtual bool processEvent( QEvent* ); + + void connector(QRect); + +public slots: + virtual void setActivated(bool a); + +signals: + void operationDone(); + +protected: + void mousePress(QMouseEvent *); + void mouseMove(QMouseEvent *); + void mouseRelease(QMouseEvent *); + + bool startRubberBanding(QMouseEvent*); + void continueRubberBanding(QMouseEvent *); + void endRubberBanding(QMouseEvent *); + + + + QPoint m_startPoint, m_releasePoint; + + // Connector Tool Mode + enum + { + stmNone, + stmDrawRubber + }; + +private: + // Flag to indicate that we are drawing a rubber band + int m_mode; + QCursor* m_pConnectorCursor1; + QCursor* m_pConnectorCursor2; + KivioSMLConnector* m_pStencil; + KoPoint startPoint; + KivioCustomDragData* m_pDragData; + + KToggleAction* m_connectorAction; +}; + +#endif + + diff --git a/kivio/plugins/kiviotargettool/Makefile.am b/kivio/plugins/kiviotargettool/Makefile.am new file mode 100644 index 00000000..34f2b72a --- /dev/null +++ b/kivio/plugins/kiviotargettool/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) + +METASOURCES = AUTO + +kde_module_LTLIBRARIES = libkiviotargettool.la +libkiviotargettool_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +libkiviotargettool_la_LIBADD = $(LIB_KOTEXT) $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la +libkiviotargettool_la_SOURCES = kiviotargettool.cpp kiviotargettoolfactory.cpp + +noinst_HEADERS = kiviotargettool.h kiviotargettoolfactory.h + +rc_DATA = kiviotargettool.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kiviotargettool.desktop +desktopdir = $(kde_servicesdir) diff --git a/kivio/plugins/kiviotargettool/kiviotargettool.cpp b/kivio/plugins/kiviotargettool/kiviotargettool.cpp new file mode 100644 index 00000000..95958d2a --- /dev/null +++ b/kivio/plugins/kiviotargettool/kiviotargettool.cpp @@ -0,0 +1,113 @@ +/* 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 "kiviotargettool.h" + +#include <qcursor.h> + +#include <klocale.h> + +#include "kivio_stencil.h" +#include "kivio_view.h" +#include "kivio_canvas.h" +#include "kivio_page.h" +#include "kivio_doc.h" +#include "mousetoolaction.h" +#include "kivio_pluginmanager.h" +#include "kivio_command.h" + +namespace Kivio { + TargetTool::TargetTool(KivioView* parent) : MouseTool(parent, "Add Target Mouse Tool") + { + m_targetAction = new Kivio::MouseToolAction(i18n("Add Connector Target"), + "add_target", 0, actionCollection(), "addTargetTool"); + connect(m_targetAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + connect(m_targetAction, SIGNAL(doubleClicked()), this, SLOT(makePermanent())); + + m_permanent = false; + } + + TargetTool::~TargetTool() + { + } + + bool TargetTool::processEvent(QEvent* e) + { + if(e->type() == QEvent::MouseButtonPress) { + mousePress(static_cast<QMouseEvent*>(e)); + return true; + } else if(e->type() == QEvent::MouseMove) { + mouseMove(static_cast<QMouseEvent*>(e)); + return true; + } + + return false; + } + + void TargetTool::setActivated(bool a) + { + if(a) { + m_targetAction->setChecked(true); + emit activated(this); + } else if(m_targetAction->isChecked()) { + m_targetAction->setChecked(false); + m_permanent = false; + } + } + + void TargetTool::applyToolAction(KivioStencil* stencil, const KoPoint& pos) + { + KivioAddConnectorTargetCommand* command = new KivioAddConnectorTargetCommand(i18n("Add Connector Target"), view()->activePage(), stencil, pos); + command->execute(); + view()->doc()->addCommand(command); + } + + void TargetTool::mousePress(QMouseEvent* e) + { + KoPoint p = view()->canvasWidget()->mapFromScreen(e->pos()); + int colType; + KivioStencil* stencil = view()->canvasWidget()->activePage()->checkForStencil(&p, &colType, 0, false); + + if(stencil) { + applyToolAction(stencil, p); + + if(!m_permanent) { + view()->pluginManager()->activateDefaultTool(); + } + } + } + + void TargetTool::mouseMove(QMouseEvent* e) + { + KoPoint p = view()->canvasWidget()->mapFromScreen(e->pos()); + int colType; + + if(view()->canvasWidget()->activePage()->checkForStencil(&p, &colType, 0, false)) { + view()->canvasWidget()->setCursor(Qt::CrossCursor); + } else { + view()->canvasWidget()->setCursor(Qt::ForbiddenCursor); + } + } + + void TargetTool::makePermanent() + { + m_permanent = true; + } +} + +#include "kiviotargettool.moc" diff --git a/kivio/plugins/kiviotargettool/kiviotargettool.desktop b/kivio/plugins/kiviotargettool/kiviotargettool.desktop new file mode 100644 index 00000000..37c1a650 --- /dev/null +++ b/kivio/plugins/kiviotargettool/kiviotargettool.desktop @@ -0,0 +1,49 @@ +[Desktop Entry] +X-KDE-Library=libkiviotargettool +Name=Target Tool for Kivio +Name[bg]=Целеви инструмент за Kivio +Name[br]=Ostilh wenn evit Kivio +Name[ca]=Eina d'objectiu per a Kivio +Name[cy]=Erfyn Targed ar gyfer Kivio +Name[da]=Målværktøj for Kivio +Name[de]=Ziel-Werkzeug für Kivio +Name[el]=Εργαλείο προορισμού για το Kivio +Name[eo]=Celumilo por Kivio +Name[es]=Herramienta de objetivo para Kivio +Name[et]=Kivio sihtmärgi tööriist +Name[eu]=Kivio-ren helburu-tresna +Name[fa]=ابزار هدف برای Kivio +Name[fi]=Kivion kohdetyökalu +Name[fr]=Outil cible pour Kivio +Name[fy]=Targetark foar Kivio +Name[gl]=Ferramenta de Obxectivo para Kivio +Name[he]=כלי יעד של Kivio +Name[hr]=Alat cilja za Kivio +Name[hu]=Célkezelő eszköz a Kivióhoz +Name[it]=Strumento di destinazione per Kivio +Name[ja]=Kivio ターゲットツール +Name[km]=ឧបករណ៍គោលដៅសម្រាប់ Kivio +Name[lv]=Mērķa rīks priekš Kivio +Name[ms]=Alat Sasaran bagi Kivio +Name[nb]=Målverktøy for Kivio +Name[nds]=Teelwarktüüch för Kivio +Name[ne]=किभियोका लागि लक्ष्य उपकरण +Name[nl]=Targettool voor Kivio +Name[nn]=Målverktøy for Kivio +Name[pl]=Narzędzie wyboru elementu docelowego dla Kivio +Name[pt]=Ferramenta de Alvo para o Kivio +Name[pt_BR]=Ferramenta de Alvo para o Kivio +Name[ru]=Указатель Kivio +Name[se]=Kivio-ulbmilreaidu +Name[sk]=Cieľový nástroj pre Kivio +Name[sl]=Ciljno orodje za Kivio +Name[sr]=Циљни алат за Kivio +Name[sr@Latn]=Ciljni alat za Kivio +Name[sv]=Målverktyg för Kivio +Name[ta]=Kivio உரைக்கருவி +Name[tg]=Асбоби Алоқакунанда барои Kivio +Name[tr]=Kivio için Hedef Aracı +Name[uk]=Вказівник для Kivio +Name[zh_CN]=Kivio 目标工具 +Name[zh_TW]=Kivio 目標工具 +Type=Service diff --git a/kivio/plugins/kiviotargettool/kiviotargettool.h b/kivio/plugins/kiviotargettool/kiviotargettool.h new file mode 100644 index 00000000..5a1fb787 --- /dev/null +++ b/kivio/plugins/kiviotargettool/kiviotargettool.h @@ -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. +*/ +#ifndef KIVIOKIVIOTARGETTOOL_H +#define KIVIOKIVIOTARGETTOOL_H + +#include <KoPoint.h> + +#include "kivio_mousetool.h" + +class QMouseEvent; + +namespace Kivio { + class MouseToolAction; +} + +class KivioStencil; +class KivioView; + +namespace Kivio { + class TargetTool : public MouseTool + { + Q_OBJECT + public: + TargetTool(KivioView* parent); + ~TargetTool(); + + virtual bool processEvent(QEvent* e); + + public slots: + virtual void setActivated(bool); + virtual void applyToolAction(KivioStencil* stencil, const KoPoint& pos); + + protected slots: + void makePermanent(); + + protected: + void mousePress(QMouseEvent* e); + void mouseMove(QMouseEvent* e); + + private: + Kivio::MouseToolAction* m_targetAction; + bool m_permanent; + }; +} + +#endif diff --git a/kivio/plugins/kiviotargettool/kiviotargettool.rc b/kivio/plugins/kiviotargettool/kiviotargettool.rc new file mode 100644 index 00000000..2b47f973 --- /dev/null +++ b/kivio/plugins/kiviotargettool/kiviotargettool.rc @@ -0,0 +1,11 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioTextTool" library="libkiviotargettool" version="1"> + <MenuBar> + <Menu name="Tools"> + <Action name="addTargetTool"/> + </Menu> + </MenuBar> + <ToolBar name="ToolsToolBar"> + <Action name="addTargetTool"/> + </ToolBar> +</kpartgui> diff --git a/kivio/plugins/kiviotargettool/kiviotargettoolfactory.cpp b/kivio/plugins/kiviotargettool/kiviotargettoolfactory.cpp new file mode 100644 index 00000000..b80e9734 --- /dev/null +++ b/kivio/plugins/kiviotargettool/kiviotargettoolfactory.cpp @@ -0,0 +1,52 @@ +/* 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 "kiviotargettoolfactory.h" + +#include "kiviotargettool.h" + +K_EXPORT_COMPONENT_FACTORY( libkiviotargettool, KivioTargetToolFactory ) + +KInstance* KivioTargetToolFactory::s_global = 0; + +KivioTargetToolFactory::KivioTargetToolFactory(QObject *parent, const char *name) + : KLibFactory(parent, name) +{ + s_global = new KInstance("kivio"); +} + +KivioTargetToolFactory::~KivioTargetToolFactory() +{ + delete s_global; +} + +QObject* KivioTargetToolFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject *obj = new Kivio::TargetTool(static_cast<KivioView*>(parent)); + return obj; +} + +KInstance* KivioTargetToolFactory::global() +{ + return s_global; +} + +#include "kiviotargettoolfactory.moc" diff --git a/kivio/plugins/kiviotargettool/kiviotargettoolfactory.h b/kivio/plugins/kiviotargettool/kiviotargettoolfactory.h new file mode 100644 index 00000000..abe028ea --- /dev/null +++ b/kivio/plugins/kiviotargettool/kiviotargettoolfactory.h @@ -0,0 +1,45 @@ +/* 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 KIVIOTARGETTOOLFACTORY_H +#define KIVIOTARGETTOOLFACTORY_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class KivioTargetToolFactory : public KLibFactory +{ + Q_OBJECT + public: + KivioTargetToolFactory(QObject *parent = 0, const char *name = 0); + ~KivioTargetToolFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + + static KInstance* global(); + + private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kiviotexttool/Makefile.am b/kivio/plugins/kiviotexttool/Makefile.am new file mode 100644 index 00000000..fa355929 --- /dev/null +++ b/kivio/plugins/kiviotexttool/Makefile.am @@ -0,0 +1,38 @@ +kde_module_LTLIBRARIES =libkiviotexttool.la + + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) +libkiviotexttool_la_METASOURCES = AUTO +libkiviotexttool_la_SOURCES = \ + plugin.cpp\ + tool_text.cpp kivio_stenciltexteditorui.ui stenciltexteditor.cpp +EXTRA_DIST = \ + plugin.h\ + plugin.cpp\ + kiviotexttool.desktop\ + kiviotexttool.rc\ + tool_text.cpp\ + tool_text.h\ + kivio_text.xpm\ + kivio_text_cursor.xpm\ + Text.sml\ + Text.xpm +libkiviotexttool_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +libkiviotexttool_la_LIBADD =$(LIB_KOTEXT) $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +rc_DATA = kiviotexttool.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kiviotexttool.desktop +desktopdir = $(kde_servicesdir) + +kiviopics_DATA = kivio_text.xpm kivio_text_cursor.xpm +kiviopicsdir = $(kde_datadir)/kivio/pics + +stencil_DATA = Text.sml Text.xpm +stencildir = $(kde_datadir)/kivio/autoloadStencils diff --git a/kivio/plugins/kiviotexttool/Text.sml b/kivio/plugins/kiviotexttool/Text.sml new file mode 100644 index 00000000..2840bc81 --- /dev/null +++ b/kivio/plugins/kiviotexttool/Text.sml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<KivioShapeStencil creator="vi"> + <KivioSMLStencilSpawnerInfo> + <Author data="Landshark"/> + <Title data="Text"/> + <Id data="Dave Marotti - Text"/> + <Description data="Text"/> + <Version data="0.1"/> + <Web data="www.thekompany.com"/> + <Email data="lndshark@speakeasy.net"/> + <Copyright data="Copyright (C) 2000 theKompany.com & Dave Marotti. All rights reserved."/> + <AutoUpdate data="off"/> + </KivioSMLStencilSpawnerInfo> + <Dimensions w="72.0" h="36.0"/> + <KivioShape type="TextBox" name="Text" x="0.0" y="0.0" w="72.0" h="36.0"/> +</KivioShapeStencil> diff --git a/kivio/plugins/kiviotexttool/Text.xpm b/kivio/plugins/kiviotexttool/Text.xpm new file mode 100644 index 00000000..46f50d3c --- /dev/null +++ b/kivio/plugins/kiviotexttool/Text.xpm @@ -0,0 +1,70 @@ +/* XPM */ +static const char * Text_xpm[] = { +"32 32 35 1", +" c None", +". c #F8FCF8", +"+ c #808080", +"@ c #C0C0C0", +"# c #AAAAAA", +"$ c #404040", +"% c #6A6A6A", +"& c #000000", +"* c #151515", +"= c #2A2A2A", +"- c #555555", +"; c #424242", +"> c #959595", +", c #212121", +"' c #101010", +") c #848484", +"! c #A3A3A3", +"~ c #4C4C4C", +"{ c #878787", +"] c #1C1C1C", +"^ c #8E8E8E", +"/ c #525252", +"( c #9C9C9C", +"_ c #2D2D2D", +": c #B8B8B8", +"< c #5A5A5A", +"[ c #717171", +"} c #B1B1B1", +"| c #0E0E0E", +"1 c #474747", +"2 c #636363", +"3 c #393939", +"4 c #4B4B4B", +"5 c #3B3B3B", +"6 c #2F2F2F", +"...............................+", +".+++++++++++++++++++++++++++++.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@#$$$$$$$$$$$$$$$$$$%@@@@.+", +".+@@@@+&&&*$$*&&&&=$$*&&&+@@@@.+", +".+@@@@-&&;>>>,&&&&>>>>'&&)>!@@.+", +".+@@@@=&~+++{&&&&]++^>/&&++#@@.+", +".+@@@@&$(++(>&&&&=++@@@&_++:@@.+", +".+@@@>*#^+(@%&&&&-+^@@@$<++@@@.+", +".+@@@@@@+>@@$&&&&[+>@@@@@+>@@@.+", +".+@@@@@}{:@@*&&&|++#@@@@@>!@@@.+", +".+@@@@@@@@@#&&&&=++:@@@@@@@@@@.+", +".+@@@@@@@@@+&&&&1+{@@@@@@@@@@@.+", +".+@@@@@@@@@-&&&&2+>@@@@@@@@@@@.+", +".+@@@@@@@@@=&&&&++!@@@@@@@@@@@.+", +".+@@@@@@@@@&&&&]++}@@@@@@@@@@@.+", +".+@@@@@@@@>&&&&3++@@@@@@@@@@@@.+", +".+@@@@@@@@%&&&&-+^@@@@@@@@@@@@.+", +".+@@@@@@@@$&&&&[+(@@@@@@@@@@@@.+", +".+@@@@@@@@&&&&|++#@@@@@@@@@@@@.+", +".+@@@@@@@>&&&&]++:@@@@@@@@@@@@.+", +".+@@@@#+-*&&&&&]4#@@@@@@@@@@@@.+", +".+@@@@+$$$$5====6>@@@@@@@@@@@@.+", +".+@@@@@@:#({+++++^!:@@@@@@@@@@.+", +".+@@@@@@#>>>>>>>>>>}@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +".+@@@@@@@@@@@@@@@@@@@@@@@@@@@@.+", +"...............................+", +"++++++++++++++++++++++++++++++++"}; diff --git a/kivio/plugins/kiviotexttool/kivio_stenciltexteditorui.ui b/kivio/plugins/kiviotexttool/kivio_stenciltexteditorui.ui new file mode 100644 index 00000000..8a6f9ce6 --- /dev/null +++ b/kivio/plugins/kiviotexttool/kivio_stenciltexteditorui.ui @@ -0,0 +1,256 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>Kivio::StencilTextEditorUI</class> +<comment>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. +</comment> +<author>Copyright (C) 2005 Peter Simonsson</author> +<widget class="QWidget"> + <property name="name"> + <cstring>Kivio::StencilTextEditorUI</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>535</width> + <height>447</height> + </rect> + </property> + <property name="caption"> + <string>Kivio::StencilTextEditor</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QToolButton" row="0" column="2"> + <property name="name"> + <cstring>m_boldButton</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="toggleButton"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Bold</string> + </property> + </widget> + <widget class="KComboBox" row="0" column="1"> + <item> + <property name="text"> + <string>6</string> + </property> + </item> + <item> + <property name="text"> + <string>7</string> + </property> + </item> + <item> + <property name="text"> + <string>8</string> + </property> + </item> + <item> + <property name="text"> + <string>9</string> + </property> + </item> + <item> + <property name="text"> + <string>10</string> + </property> + </item> + <item> + <property name="text"> + <string>11</string> + </property> + </item> + <item> + <property name="text"> + <string>12</string> + </property> + </item> + <item> + <property name="text"> + <string>14</string> + </property> + </item> + <item> + <property name="text"> + <string>16</string> + </property> + </item> + <item> + <property name="text"> + <string>18</string> + </property> + </item> + <item> + <property name="text"> + <string>20</string> + </property> + </item> + <item> + <property name="text"> + <string>22</string> + </property> + </item> + <item> + <property name="text"> + <string>24</string> + </property> + </item> + <item> + <property name="text"> + <string>26</string> + </property> + </item> + <item> + <property name="text"> + <string>28</string> + </property> + </item> + <item> + <property name="text"> + <string>36</string> + </property> + </item> + <item> + <property name="text"> + <string>48</string> + </property> + </item> + <item> + <property name="text"> + <string>72</string> + </property> + </item> + <property name="name"> + <cstring>m_fontSizeCombo</cstring> + </property> + <property name="editable"> + <bool>true</bool> + </property> + </widget> + <widget class="KFontCombo" row="0" column="0"> + <property name="name"> + <cstring>m_fontCombo</cstring> + </property> + </widget> + <widget class="QToolButton" row="0" column="3"> + <property name="name"> + <cstring>m_italicsButton</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="toggleButton"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Italics</string> + </property> + </widget> + <widget class="QToolButton" row="0" column="4"> + <property name="name"> + <cstring>m_underLineButton</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="toggleButton"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Underline</string> + </property> + </widget> + <spacer row="0" column="8"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>110</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KColorButton" row="0" column="7"> + <property name="name"> + <cstring>m_textColorButton</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QToolButton" row="0" column="5"> + <property name="name"> + <cstring>m_hAlignButton</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="popupDelay"> + <number>0</number> + </property> + <property name="toolTip" stdset="0"> + <string>Horizontal Alignment</string> + </property> + </widget> + <widget class="QToolButton" row="0" column="6"> + <property name="name"> + <cstring>m_vAlignButton</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="popupDelay"> + <number>0</number> + </property> + <property name="toolTip" stdset="0"> + <string>Vertical Alignment</string> + </property> + </widget> + <widget class="KTextEdit" row="1" column="0" rowspan="1" colspan="9"> + <property name="name"> + <cstring>m_textArea</cstring> + </property> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<tabstops> + <tabstop>m_textArea</tabstop> + <tabstop>m_fontCombo</tabstop> + <tabstop>m_fontSizeCombo</tabstop> + <tabstop>m_textColorButton</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +<includehints> + <includehint>kcombobox.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kfontcombo.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>ktextedit.h</includehint> +</includehints> +</UI> diff --git a/kivio/plugins/kiviotexttool/kivio_text.xpm b/kivio/plugins/kiviotexttool/kivio_text.xpm new file mode 100644 index 00000000..c359937e --- /dev/null +++ b/kivio/plugins/kiviotexttool/kivio_text.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static const char *magick[] = { +/* columns rows colors chars-per-pixel */ +"16 16 3 1", +" c Black", +". c #808080", +"X c None", +/* pixels */ +"XXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXX", +"XXXXXXX XXXXXXXX", +"XXXXXX. .XXXXXXX", +"XXXXXX XXXXXXX", +"XXXXX. .XXXXXX", +"XXXXX X XXXXXX", +"XXXX. XX .XXXXX", +"XXXX XXXXX", +"XXX. XXXX .XXXX", +"XXX XXXX. XXXX", +"XX. XXXXX. .XXX", +"X XXX XX", +"XXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXX" +}; diff --git a/kivio/plugins/kiviotexttool/kivio_text_cursor.xpm b/kivio/plugins/kiviotexttool/kivio_text_cursor.xpm new file mode 100644 index 00000000..8c6e0eb5 --- /dev/null +++ b/kivio/plugins/kiviotexttool/kivio_text_cursor.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static const char *magick[] = { +/* columns rows colors chars-per-pixel */ +"16 16 3 1", +" c Black", +". c #808080", +"X c None", +/* pixels */ +"XX XXXXXXXXXXXXX", +"XX XXXXXXXXXXXXX", +" XX XXXXXXXX", +"XX XXX. .XXXXXXX", +"XX XXX XXXXXXX", +"XXXXX. .XXXXXX", +"XXXXX X XXXXXX", +"XXXX. XX .XXXXX", +"XXXX XXXXX", +"XXX. XXXX .XXXX", +"XXX XXXX. XXXX", +"XX. XXXXX. .XXX", +"X XXX XX", +"XXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXX" +}; diff --git a/kivio/plugins/kiviotexttool/kiviotexttool.desktop b/kivio/plugins/kiviotexttool/kiviotexttool.desktop new file mode 100644 index 00000000..85c8207f --- /dev/null +++ b/kivio/plugins/kiviotexttool/kiviotexttool.desktop @@ -0,0 +1,66 @@ +[Desktop Entry] +X-KDE-Library=libkiviotexttool +Name=TextTool for Kivio +Name[af]=Teks gereedskap vir Kivio +Name[ar]=أداة النّص لدى Kivio +Name[az]=Kivio üçün mətn vasitəsi +Name[bg]=Текстов инструмент за Kivio +Name[br]=Ostilh skrid evit Kivio +Name[bs]=Tekst alat za Kivio +Name[ca]=Eina de text per a Kivio +Name[cs]=Textový nástroj pro Kivio +Name[cy]=ErfynTestun i Kivio +Name[da]=Tekstværktøj for Kivio +Name[de]=Text-Werkzeug für Kivio +Name[el]=Εργαλείο κειμένου για το Kivio +Name[eo]=Tekstilo por Kivio +Name[es]=Herramienta de texto para Kivio +Name[et]=Kivio teksti tööriist +Name[eu]=Kivio-ren testu-tresna +Name[fa]=ابزار متن برای Kivio +Name[fi]=Tekstityökalu Kivioon +Name[fr]=Outil texte pour Kivio +Name[fy]=Tekstark foar Kivio +Name[gl]=Ferramenta de Texto para Kivio +Name[he]=כלי טקסט של Kivio +Name[hr]=Alat teksta za Kivio +Name[hu]=Szöveges eszköz a Kivióhoz +Name[id]=Editor Teks buat Kivio +Name[is]=Textatól fyrir Kivio +Name[it]=Strumento di testo per Kivio +Name[ja]=Kivio テキストツール +Name[km]=ឧបករណ៍អត្ថបទសម្រាប់ Kivio +Name[lo]=ເຄື່ຶຶຶືຶອງມືຂໍ້ຄວາມສຳລັບແຜນຜັງໄດອະແກຣມ K +Name[lt]=TextTool skirtas Kivio +Name[lv]=Teksta rīks priekš Kivio +Name[ms]=Alat Teks bagi Kivio +Name[mt]=Għodda tat-Test għall-Kivio +Name[nb]=Tekstverktøy for Kivio +Name[nds]=Textwarktüüch för Kivio +Name[ne]=किभियोका लागि पाठउपकरण +Name[nl]=Tekstgereedschap voor Kivio +Name[nn]=Tekstverktøy for Kivio +Name[pl]=Narzędzie tekstowe dla Kivio +Name[pt]=Ferramenta de Texto para o Kivio +Name[pt_BR]=Ferramenta de texto para o Kivio +Name[ro]=Unealtă text pentru Kivio +Name[ru]=Текстовая врезка для Kivio +Name[se]=Kivio-teakstareaidu +Name[sk]=Textový nástroj pre Kivio +Name[sl]=Besedilno orodje za Kivio +Name[sr]=Текстуални алат за Kivio +Name[sr@Latn]=Tekstualni alat za Kivio +Name[sv]=Textverktyg för Kivio +Name[ta]=Kivio உரைக்கருவி +Name[tg]=Матни Асбоб барои Kivio +Name[th]=เครื่องมือข้อความสำหรับแผนผังไดอะแกรม K +Name[tr]=Kivio için Metin Aracı +Name[uk]=Текстовий засіб для Kivio +Name[uz]=Kivio uchun matn vositasi +Name[uz@cyrillic]=Kivio учун матн воситаси +Name[ven]=Tshishumiswa tsha manwalwa tsha Kivio +Name[xh]=Isixhobo Sombhalo se Kivio +Name[zh_CN]=Kivio 文字工具 +Name[zh_TW]=Kivio 文字工具 +Name[zu]=Ithuluzi lokubhaliweyo le Kivio +Type=Service diff --git a/kivio/plugins/kiviotexttool/kiviotexttool.rc b/kivio/plugins/kiviotexttool/kiviotexttool.rc new file mode 100644 index 00000000..a9e6b9ab --- /dev/null +++ b/kivio/plugins/kiviotexttool/kiviotexttool.rc @@ -0,0 +1,11 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioTextTool" library="libkiviotexttool" version="4"> +<MenuBar> + <Menu name="Tools"> + <Action name="text"/> + </Menu> +</MenuBar> +<ToolBar name="ToolsToolBar"> + <Action name="text"/> +</ToolBar> +</kpartgui> diff --git a/kivio/plugins/kiviotexttool/plugin.cpp b/kivio/plugins/kiviotexttool/plugin.cpp new file mode 100644 index 00000000..456805a4 --- /dev/null +++ b/kivio/plugins/kiviotexttool/plugin.cpp @@ -0,0 +1,58 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "plugin.h" +#include "tool_text.h" + +#include "kivio_view.h" + +#include <kinstance.h> +#include <kiconloader.h> + +/*************************************************** + * Factory + ***************************************************/ +K_EXPORT_COMPONENT_FACTORY( libkiviotexttool, TextToolFactory ) + +KInstance* TextToolFactory::s_global = 0; + +TextToolFactory::TextToolFactory( QObject* parent, const char* name ) +: KLibFactory( parent, name ) +{ + s_global = new KInstance("kivio"); +} + +TextToolFactory::~TextToolFactory() +{ + delete s_global; +} + +QObject* TextToolFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject *obj = new TextTool( (KivioView*)parent ); + return obj; +} + +KInstance* TextToolFactory::global() +{ + return s_global; +} +#include "plugin.moc" diff --git a/kivio/plugins/kiviotexttool/plugin.h b/kivio/plugins/kiviotexttool/plugin.h new file mode 100644 index 00000000..18d4f41f --- /dev/null +++ b/kivio/plugins/kiviotexttool/plugin.h @@ -0,0 +1,44 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef TEXT_PLUGIN_H +#define TEXT_PLUGIN_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class TextToolFactory : public KLibFactory +{ Q_OBJECT +public: + TextToolFactory( QObject* parent = 0, const char* name = 0 ); + ~TextToolFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + + static KInstance* global(); + +private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kiviotexttool/stenciltexteditor.cpp b/kivio/plugins/kiviotexttool/stenciltexteditor.cpp new file mode 100644 index 00000000..9cf3a7e5 --- /dev/null +++ b/kivio/plugins/kiviotexttool/stenciltexteditor.cpp @@ -0,0 +1,190 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2005 Peter Simonsson <psn@linux.se> + * + * 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 "stenciltexteditor.h" + +#include <qtoolbutton.h> +#include <qfont.h> +#include <qcolor.h> +#include <qpopupmenu.h> + +#include <kiconloader.h> +#include <ktextedit.h> +#include <kfontcombo.h> +#include <kcolorbutton.h> +#include <kdebug.h> +#include <klocale.h> +#include <karrowbutton.h> + +#include "kivio_stenciltexteditorui.h" + +namespace Kivio { + +StencilTextEditor::StencilTextEditor(const QString& caption, QWidget *parent, const char *name) + : KDialogBase(parent, name, true, caption, KDialogBase::Ok|KDialogBase::Cancel) +{ + m_hAlign = -1; + m_vAlign = -1; + m_mainWidget = new StencilTextEditorUI(this); + setMainWidget(m_mainWidget); + + m_mainWidget->m_boldButton->setIconSet(SmallIconSet("text_bold", 16)); + m_mainWidget->m_italicsButton->setIconSet(SmallIconSet("text_italic", 16)); + m_mainWidget->m_underLineButton->setIconSet(SmallIconSet("text_under", 16)); + + QPopupMenu* menu = new QPopupMenu(m_mainWidget->m_hAlignButton, "hAlignMenu"); + menu->setCheckable(true); + menu->insertItem(SmallIconSet("text_left", 16), i18n("Align Left"), Qt::AlignLeft); + menu->insertItem(SmallIconSet("text_center", 16), i18n("Align Center"), Qt::AlignHCenter); + menu->insertItem(SmallIconSet("text_right", 16), i18n("Align Right"), Qt::AlignRight); + m_mainWidget->m_hAlignButton->setPopup(menu); + connect(menu, SIGNAL(activated(int)), this, SLOT(setHorizontalAlign(int))); + connect(m_mainWidget->m_hAlignButton, SIGNAL(clicked()), this, SLOT(showHAlignPopup())); + + menu = new QPopupMenu(m_mainWidget->m_vAlignButton, "hAlignMenu"); + menu->setCheckable(true); + menu->insertItem(SmallIconSet("align_top", 16), i18n("Align Top"), Qt::AlignTop); + menu->insertItem(SmallIconSet("align_vcenter", 16), i18n("Align Vertical Center"), Qt::AlignVCenter); + menu->insertItem(SmallIconSet("align_bottom", 16), i18n("Align Bottom"), Qt::AlignBottom); + m_mainWidget->m_vAlignButton->setPopup(menu); + connect(menu, SIGNAL(activated(int)), this, SLOT(setVerticalAlign(int))); + connect(m_mainWidget->m_vAlignButton, SIGNAL(clicked()), this, SLOT(showVAlignPopup())); + + connect(m_mainWidget->m_fontCombo, SIGNAL(activated(int)), this, SLOT(updateFormating())); + connect(m_mainWidget->m_fontSizeCombo, SIGNAL(activated(int)), this, SLOT(updateFormating())); + connect(m_mainWidget->m_boldButton, SIGNAL(clicked()), this, SLOT(updateFormating())); + connect(m_mainWidget->m_italicsButton, SIGNAL(clicked()), this, SLOT(updateFormating())); + connect(m_mainWidget->m_underLineButton, SIGNAL(clicked()), this, SLOT(updateFormating())); + connect(m_mainWidget->m_textColorButton, SIGNAL(clicked()), this, SLOT(updateFormating())); + + m_mainWidget->m_textArea->setFocus(); +} + +StencilTextEditor::~StencilTextEditor() +{ +} + +void StencilTextEditor::setFont(const QFont& font) +{ + m_mainWidget->m_textArea->setFont(font); + m_mainWidget->m_fontCombo->setCurrentFont(font.family()); + m_mainWidget->m_fontSizeCombo->setCurrentText(QString::number(font.pointSize())); + m_mainWidget->m_boldButton->setOn(font.bold()); + m_mainWidget->m_italicsButton->setOn(font.italic()); + m_mainWidget->m_underLineButton->setOn(font.underline()); +} + +void StencilTextEditor::setFontColor(const QColor& color) +{ + m_mainWidget->m_textArea->setPaletteForegroundColor(color); + m_mainWidget->m_textColorButton->setColor(color); +} + +void StencilTextEditor::setBackgroundColor(const QColor& color) +{ + m_mainWidget->m_textArea->setPaletteBackgroundColor(color); +} + +void StencilTextEditor::setHorizontalAlign(int flag) +{ + if(m_hAlign >= 0) { + m_mainWidget->m_hAlignButton->popup()->setItemChecked(m_hAlign, false); + } + + m_mainWidget->m_hAlignButton->popup()->setItemChecked(flag, true); + m_mainWidget->m_hAlignButton->setIconSet(*(m_mainWidget->m_hAlignButton->popup()->iconSet(flag))); + m_mainWidget->m_textArea->setAlignment(flag|verticalAlignment()); + m_hAlign = flag; +} + +void StencilTextEditor::setVerticalAlign(int flag) +{ + if(m_vAlign >= 0) { + m_mainWidget->m_vAlignButton->popup()->setItemChecked(m_vAlign, false); + } + + m_mainWidget->m_vAlignButton->popup()->setItemChecked(flag, true); + m_mainWidget->m_vAlignButton->setIconSet(*(m_mainWidget->m_vAlignButton->popup()->iconSet(flag))); + m_mainWidget->m_textArea->setAlignment(flag|horizontalAlignment()); + m_vAlign = flag; +} + +QFont StencilTextEditor::font() const +{ + QFont font; + font.setFamily(m_mainWidget->m_fontCombo->currentFont()); + font.setPointSize(m_mainWidget->m_fontSizeCombo->currentText().toInt()); + font.setBold(m_mainWidget->m_boldButton->isOn()); + font.setItalic(m_mainWidget->m_italicsButton->isOn()); + font.setUnderline(m_mainWidget->m_underLineButton->isOn()); + + return font; +} + +QColor StencilTextEditor::fontColor() const +{ + return m_mainWidget->m_textColorButton->color(); +} + +Qt::AlignmentFlags StencilTextEditor::horizontalAlignment() const +{ + return static_cast<Qt::AlignmentFlags>(m_hAlign); +} + +Qt::AlignmentFlags StencilTextEditor::verticalAlignment() const +{ + return static_cast<Qt::AlignmentFlags>(m_vAlign); +} + +void StencilTextEditor::setText(const QString& text) +{ + m_mainWidget->m_textArea->setText(text); +} + +QString StencilTextEditor::text() const +{ + return m_mainWidget->m_textArea->text(); +} + +void StencilTextEditor::updateFormating() +{ + m_mainWidget->m_textArea->setFont(font()); + + m_mainWidget->m_textArea->setPaletteForegroundColor(fontColor()); + + + m_mainWidget->m_textArea->selectAll(true); + m_mainWidget->m_textArea->setAlignment(horizontalAlignment()|verticalAlignment()); + m_mainWidget->m_textArea->selectAll(false); + + m_mainWidget->m_textArea->setFocus(); +} + +void StencilTextEditor::showHAlignPopup() +{ + m_mainWidget->m_hAlignButton->openPopup(); +} + +void StencilTextEditor::showVAlignPopup() +{ + m_mainWidget->m_vAlignButton->openPopup(); +} + +} + +#include "stenciltexteditor.moc" diff --git a/kivio/plugins/kiviotexttool/stenciltexteditor.h b/kivio/plugins/kiviotexttool/stenciltexteditor.h new file mode 100644 index 00000000..0c2a3b1a --- /dev/null +++ b/kivio/plugins/kiviotexttool/stenciltexteditor.h @@ -0,0 +1,72 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2005 Peter Simonsson <psn@linux.se> + * + * 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 KIVIOSTENCILTEXTEDITOR_H +#define KIVIOSTENCILTEXTEDITOR_H + +#include <kdialogbase.h> + +class QFont; +class QColor; + +namespace Kivio { + +class StencilTextEditorUI; + +/** + * Dialog for editing stencil text + */ +class StencilTextEditor : public KDialogBase +{ + Q_OBJECT + public: + StencilTextEditor(const QString& caption, QWidget *parent = 0, const char *name = 0); + ~StencilTextEditor(); + + void setFont(const QFont& font); + void setFontColor(const QColor& color); + void setBackgroundColor(const QColor& color); + + QFont font() const; + QColor fontColor() const; + Qt::AlignmentFlags horizontalAlignment() const; + Qt::AlignmentFlags verticalAlignment() const; + + void setText(const QString& text); + QString text() const; + + public slots: + void setHorizontalAlign(int flag); + void setVerticalAlign(int flag); + + protected slots: + void updateFormating(); + + void showHAlignPopup(); + void showVAlignPopup(); + + private: + StencilTextEditorUI* m_mainWidget; + + int m_hAlign; + int m_vAlign; +}; + +} + +#endif diff --git a/kivio/plugins/kiviotexttool/tool_text.cpp b/kivio/plugins/kiviotexttool/tool_text.cpp new file mode 100644 index 00000000..8b7e52e7 --- /dev/null +++ b/kivio/plugins/kiviotexttool/tool_text.cpp @@ -0,0 +1,439 @@ +/* + * 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 "tool_text.h" + +#include <qcursor.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <kdebug.h> +#include <KoPoint.h> +#include <klocale.h> +#include <KoZoomHandler.h> +#include <kinputdialog.h> + +#include "kivio_view.h" +#include "kivio_canvas.h" +#include "kivio_page.h" +#include "kivio_doc.h" + +#include "kivio_stencil_spawner_set.h" +#include "kivio_stencil_spawner.h" +#include "kivio_custom_drag_data.h" +#include "kivio_layer.h" +#include "kivio_point.h" +#include "kivio_stencil.h" +#include "kivio_factory.h" +#include "kivio_command.h" +#include "kivio_pluginmanager.h" +#include "mousetoolaction.h" +#include "stenciltexteditor.h" + + +TextTool::TextTool( KivioView* parent ) : Kivio::MouseTool(parent, "Text Mouse Tool") +{ + m_textAction = new Kivio::MouseToolAction( i18n("Text Tool"), "text", Key_F2, actionCollection(), "text" ); + connect(m_textAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + connect(m_textAction, SIGNAL(doubleClicked()), this, SLOT(makePermanent())); + + m_permanent = false; + m_mode = stmNone; + + QPixmap pix = BarIcon("kivio_text_cursor",KivioFactory::global()); + m_pTextCursor = new QCursor(pix,2,2); +} + +TextTool::~TextTool() +{ + delete m_pTextCursor; +} + + +/** + * Event delegation + * + * @param e The event to be identified and processed + * + */ +bool TextTool::processEvent(QEvent* e) +{ + switch (e->type()) + { + case QEvent::MouseButtonPress: + mousePress( (QMouseEvent*)e ); + return true; + break; + + case QEvent::MouseButtonRelease: + mouseRelease( (QMouseEvent*)e ); + return true; + break; + + case QEvent::MouseMove: + mouseMove( (QMouseEvent*)e ); + return true; + break; + + default: + break; + } + + return false; +} + +void TextTool::setActivated(bool a) +{ + if(a) { + emit activated(this); + m_textAction->setChecked(true); + view()->canvasWidget()->setCursor(*m_pTextCursor); + m_mode = stmNone; + } else { + m_textAction->setChecked(false); + m_permanent = false; + } +} + +void TextTool::text(QRect r) +{ + // Calculate the start and end clicks in terms of page coordinates + KoPoint startPoint = view()->canvasWidget()->mapFromScreen( QPoint( r.x(), r.y() ) ); + KoPoint releasePoint = view()->canvasWidget()->mapFromScreen( QPoint( r.x() + r.width(), r.y() + r.height() ) ); + + // Calculate the x,y position of the textion box + float x = startPoint.x() < releasePoint.x() ? startPoint.x() : releasePoint.x(); + float y = startPoint.y() < releasePoint.y() ? startPoint.y() : releasePoint.y(); + + // Calculate the w/h of the textion box + float w = releasePoint.x() - startPoint.x(); + + if( w < 0.0 ) { + w *= -1.0; + } + + float h = releasePoint.y() - startPoint.y(); + + if( h < 0.0 ) { + h *= -1.0; + } + + KivioDoc* doc = view()->doc(); + KivioPage* page = view()->activePage(); + + KivioStencilSpawner* ss = doc->findInternalStencilSpawner("Dave Marotti - Text"); + + if (!ss) { + return; + } + + KivioStencil* stencil = ss->newStencil(); + stencil->setType(kstText); + stencil->setPosition(x,y); + stencil->setDimensions(w,h); + stencil->setText(""); + stencil->setTextFont(doc->defaultFont()); + page->unselectAllStencils(); + page->addStencil(stencil); + page->selectStencil(stencil); + + doc->updateView(page); + + applyToolAction(page->selectedStencils()); + + if (stencil->text().isEmpty()) { + page->deleteSelectedStencils(); + doc->updateView(page); + } +} + +void TextTool::mousePress( QMouseEvent *e ) +{ + if(e->button() == LeftButton) { + KoPoint pagePoint = view()->canvasWidget()->mapFromScreen(e->pos()); + int colType; + KivioPage *page = view()->activePage(); + KivioStencil* stencil = page->checkForStencil( &pagePoint, &colType, 0.0, false); + + if(stencil) { + applyToolAction(stencil, pagePoint); + } else if(startRubberBanding(e)) { + m_mode = stmDrawRubber; + } + } +} + + +/** + * Tests if we should start rubber banding (always returns true). + */ +bool TextTool::startRubberBanding( QMouseEvent *e ) +{ + view()->canvasWidget()->startRectDraw( e->pos(), KivioCanvas::Rubber ); + view()->canvasWidget()->repaint(); + m_startPoint = e->pos(); + + return true; +} + +void TextTool::mouseMove( QMouseEvent * e ) +{ + switch( m_mode ) + { + case stmDrawRubber: + continueRubberBanding(e); + break; + + default: + break; + } +} + +void TextTool::continueRubberBanding( QMouseEvent *e ) +{ + view()->canvasWidget()->continueRectDraw( e->pos(), KivioCanvas::Rubber ); +} + +void TextTool::mouseRelease( QMouseEvent *e ) +{ + m_releasePoint = e->pos(); + + switch( m_mode ) + { + case stmDrawRubber: + endRubberBanding(e); + break; + } + + m_mode = stmNone; + + view()->canvasWidget()->repaint(); +} + +void TextTool::endRubberBanding(QMouseEvent */*e*/) +{ + // End the rubber-band drawing + view()->canvasWidget()->endRectDraw(); + QRect rect; + + if( m_startPoint != m_releasePoint ) { + rect = view()->canvasWidget()->rect(); + } else { // Behave a bit more sensible when clicking the canvas... + rect.setTopLeft(m_startPoint); + rect.setWidth(view()->zoomHandler()->zoomItX(100)); + rect.setHeight(view()->zoomHandler()->zoomItY(20)); + } + + text(rect); + + if(!m_permanent) { + view()->pluginManager()->activateDefaultTool(); + } +} + +void TextTool::applyToolAction(QPtrList<KivioStencil>* stencils) +{ + if(stencils->isEmpty()) { + return; + } + + KivioStencil* stencil = stencils->first(); + bool ok = false; + + while(stencil) { + if(stencil->hasTextBox()) { + ok = true; + break; + } + + stencil = stencils->next(); + } + + if(!ok) { + return; + } + + Kivio::StencilTextEditor editor(i18n("Edit Text"), view(), "StencilTextEditor"); + editor.setFont(stencil->textFont()); + editor.setFontColor(stencil->textColor()); + editor.setBackgroundColor(stencil->bgColor()); + editor.setText(stencil->text()); + editor.setHorizontalAlign(static_cast<Qt::AlignmentFlags>(stencil->hTextAlign())); + editor.setVerticalAlign(static_cast<Qt::AlignmentFlags>(stencil->vTextAlign())); + + if(editor.exec() == QDialog::Accepted) { + KMacroCommand* macroCmd = new KMacroCommand(i18n("Change Stencil Text and Formatting")); + bool changed = false; + QString text = editor.text(); + QFont font = editor.font(); + QColor textColor = editor.fontColor(); + int halignment = editor.horizontalAlignment(); + int valignment = editor.verticalAlignment(); + bool changeFont = (stencil->textFont() != font); + bool changeTextColor = (stencil->textColor() != textColor); + bool changeHAlignment = (stencil->hTextAlign() != halignment); + bool changeVAlignment = (stencil->vTextAlign() != valignment); + + + while( stencil ) + { + if(stencil->text() != text) + { + KivioChangeStencilTextCommand *cmd = new KivioChangeStencilTextCommand(i18n("Change Stencil Text"), + stencil, stencil->text(), text, view()->activePage()); + stencil->setText(text); + macroCmd->addCommand(cmd); + changed = true; + } + + if(changeFont && (stencil->textFont() != font)) { + KivioChangeStencilFontCommand* cmd = new KivioChangeStencilFontCommand(i18n("Change Stencil Font"), + view()->activePage(), stencil, stencil->textFont(), font); + stencil->setTextFont(font); + macroCmd->addCommand(cmd); + changed = true; + } + + if(changeTextColor && (stencil->textColor() != textColor)) { + KivioChangeStencilColorCommand* cmd = new KivioChangeStencilColorCommand(i18n("Change Stencil Text Color"), + view()->activePage(), stencil, stencil->textColor(), textColor, KivioChangeStencilColorCommand::CT_TEXTCOLOR); + stencil->setTextColor(textColor); + macroCmd->addCommand(cmd); + changed = true; + } + + if(changeHAlignment && (stencil->hTextAlign() != halignment)) { + KivioChangeStencilHAlignmentCommand* cmd = new KivioChangeStencilHAlignmentCommand( + i18n("Change Stencil Horizontal Alignment"), view()->activePage(), stencil, stencil->hTextAlign(), halignment); + stencil->setHTextAlign(halignment); + macroCmd->addCommand(cmd); + changed = true; + } + + if(changeVAlignment && (stencil->vTextAlign() != valignment)) { + KivioChangeStencilVAlignmentCommand* cmd = new KivioChangeStencilVAlignmentCommand( + i18n("Change Stencil Vertical Alignment"), view()->activePage(), stencil, stencil->vTextAlign(), valignment); + stencil->setVTextAlign(valignment); + macroCmd->addCommand(cmd); + changed = true; + } + + stencil = stencils->next(); + } + + if(changed) { + view()->doc()->addCommand(macroCmd); + view()->doc()->updateView(view()->activePage()); + } else { + delete macroCmd; + } + } +} + +void TextTool::applyToolAction(KivioStencil* stencil, const KoPoint& pos) +{ + if(!stencil) { + return; + } + + QString name = stencil->getTextBoxName(pos); + + if(name.isEmpty()) { + return; + } + + Kivio::StencilTextEditor editor(i18n("Edit Text"), view(), "StencilTextEditor"); + editor.setFont(stencil->textFont(name)); + editor.setFontColor(stencil->textColor(name)); + editor.setBackgroundColor(stencil->bgColor()); + editor.setText(stencil->text(name)); + editor.setHorizontalAlign(static_cast<Qt::AlignmentFlags>(stencil->hTextAlign(name))); + editor.setVerticalAlign(static_cast<Qt::AlignmentFlags>(stencil->vTextAlign(name))); + + if(editor.exec() == QDialog::Accepted) { + KMacroCommand* macroCmd = new KMacroCommand(i18n("Change Stencil Text and Formatting")); + bool changed = false; + QString text = editor.text(); + + if(stencil->text(name) != text) + { + KivioChangeStencilTextCommand *cmd = new KivioChangeStencilTextCommand(i18n("Change Stencil Text"), + stencil, stencil->text(name), text, view()->activePage(), name); + stencil->setText(text, name); + macroCmd->addCommand(cmd); + changed = true; + } + + QFont font = editor.font(); + + if(stencil->textFont(name) != font) { + KivioChangeStencilFontCommand* cmd = new KivioChangeStencilFontCommand(i18n("Change Stencil Font"), + view()->activePage(), stencil, stencil->textFont(name), font, name); + stencil->setTextFont(name, font); + macroCmd->addCommand(cmd); + changed = true; + } + + QColor textColor = editor.fontColor(); + + if(stencil->textColor(name) != textColor) { + KivioChangeStencilColorCommand* cmd = new KivioChangeStencilColorCommand(i18n("Change Stencil Text Color"), + view()->activePage(), stencil, stencil->textColor(name), textColor, + KivioChangeStencilColorCommand::CT_TEXTCOLOR, name); + stencil->setTextColor(name, textColor); + macroCmd->addCommand(cmd); + changed = true; + } + + int halignment = editor.horizontalAlignment(); + + if(stencil->hTextAlign(name) != halignment) { + KivioChangeStencilHAlignmentCommand* cmd = new KivioChangeStencilHAlignmentCommand( + i18n("Change Stencil Horizontal Alignment"), view()->activePage(), stencil, + stencil->hTextAlign(name), halignment, name); + stencil->setHTextAlign(name, halignment); + macroCmd->addCommand(cmd); + changed = true; + } + + int valignment = editor.verticalAlignment(); + + if(stencil->vTextAlign(name) != valignment) { + KivioChangeStencilVAlignmentCommand* cmd = new KivioChangeStencilVAlignmentCommand( + i18n("Change Stencil Vertical Alignment"), view()->activePage(), stencil, + stencil->vTextAlign(name), valignment, name); + stencil->setVTextAlign(name, valignment); + macroCmd->addCommand(cmd); + changed = true; + } + + if(changed) { + view()->doc()->addCommand(macroCmd); + view()->doc()->updateView(view()->activePage()); + } else { + delete macroCmd; + } + } +} + +void TextTool::makePermanent() +{ + m_permanent = true; +} + +#include "tool_text.moc" diff --git a/kivio/plugins/kiviotexttool/tool_text.h b/kivio/plugins/kiviotexttool/tool_text.h new file mode 100644 index 00000000..f5b0bb7b --- /dev/null +++ b/kivio/plugins/kiviotexttool/tool_text.h @@ -0,0 +1,88 @@ +/* + * 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 TOOL_TEXT_H +#define TOOL_TEXT_H + +#include "kivio_mousetool.h" +#include <koffice_export.h> +class QMouseEvent; +class QCursor; + +namespace Kivio { + class MouseToolAction; +} + +class KivioView; +class KivioPage; +class KoPoint; + +class KIVIO_EXPORT TextTool : public Kivio::MouseTool +{ + Q_OBJECT + public: + TextTool( KivioView* parent ); + ~TextTool(); + + virtual bool processEvent(QEvent* e); + + void text(QRect); + + public slots: + virtual void setActivated(bool a); + virtual void applyToolAction(QPtrList<KivioStencil>* stencils); + virtual void applyToolAction(KivioStencil* stencil, const KoPoint& pos); + + protected slots: + void makePermanent(); + + signals: + void operationDone(); + + protected: + void mousePress(QMouseEvent *); + void mouseMove(QMouseEvent *); + void mouseRelease(QMouseEvent *); + + bool startRubberBanding(QMouseEvent*); + void continueRubberBanding(QMouseEvent *); + void endRubberBanding(QMouseEvent *); + + + + QPoint m_startPoint, m_releasePoint; + + // Text Tool Mode + enum + { + stmNone, + stmDrawRubber + }; + + private: + // Flag to indicate that we are drawing a rubber band + int m_mode; + QCursor* m_pTextCursor; + Kivio::MouseToolAction* m_textAction; + bool m_permanent; +}; + +#endif + + diff --git a/kivio/plugins/kiviozoomtool/Makefile.am b/kivio/plugins/kiviozoomtool/Makefile.am new file mode 100644 index 00000000..8343f4d4 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/Makefile.am @@ -0,0 +1,29 @@ +SUBDIRS = zoom_pics +kde_module_LTLIBRARIES =libkiviozoomtool.la + +INCLUDES = -I$(top_srcdir)/kivio/kiviopart/config \ + -I$(top_builddir)/kivio/kiviopart/config \ + -I$(top_srcdir)/kivio/kiviopart\ + -I$(top_srcdir)/kivio/kiviopart/kiviosdk\ + -I$(top_srcdir)/kivio/kiviopart/tools\ + $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes) +libkiviozoomtool_la_METASOURCES = AUTO +libkiviozoomtool_la_SOURCES = \ + plugin.cpp\ + tool_zoom.cpp +EXTRA_DIST = \ + plugin.cpp\ + plugin.h\ + kiviozoomtool.desktop\ + kiviozoomtool.rc\ + tool_zoom.cpp\ + tool_zoom.h +libkiviozoomtool_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +libkiviozoomtool_la_LIBADD = $(LIB_KOTEXT) $(LIB_KOPAINTER) $(top_builddir)/kivio/kiviopart/libkiviocommon.la + +rc_DATA = kiviozoomtool.rc +rcdir = $(kde_datadir)/kivio/kpartplugins + +desktop_DATA = kiviozoomtool.desktop +desktopdir = $(kde_servicesdir) + diff --git a/kivio/plugins/kiviozoomtool/kiviozoomtool.desktop b/kivio/plugins/kiviozoomtool/kiviozoomtool.desktop new file mode 100644 index 00000000..0ec34d69 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/kiviozoomtool.desktop @@ -0,0 +1,66 @@ +[Desktop Entry] +X-KDE-Library=libkiviozoomtool +Name=ZoomTool for Kivio +Name[af]=Vergroting gereedskap vir Kivio +Name[ar]=أداة التّحجيم لدى Kivio +Name[az]=Kivio üçün böyütmə vasitəsi +Name[bg]=Инструмент за мащабиране за Kivio +Name[br]=Ostilh zoom evit Kivio +Name[bs]=Zoom alat za Kivio +Name[ca]=Eina d'apropament per a Kivio +Name[cs]=Lupa pro Kivio +Name[cy]=ErfynChwyddo i Kivio +Name[da]=Forstørrelsesværktøj for Kivio +Name[de]=Zoom-Werkzeug für Kivio +Name[el]=Εργαλείο εστίασης για το Kivio +Name[eo]=Grandigilo por Kivio +Name[es]=Ampliador para Kivio +Name[et]=Kivio suurenduse tööriist +Name[eu]=Kivio-ren zoom-tresna +Name[fa]=ابزار بزرگنمایی برای Kivio +Name[fi]=Suurennustyökalu Kivioon +Name[fr]=Outil zoom pour Kivio +Name[fy]=Zoom-ark foar Kivio +Name[gl]=Ferramenta de Ampliación para Kivio +Name[he]=כלי התקרבות של Kivio +Name[hr]=Alat uvećavanja za Kivio +Name[hu]=Nagyító eszköz a Kivióhoz +Name[id]=Alat Zoom untuk Kivio +Name[is]=Stækkunartól fyrir Kivio +Name[it]=Strumento di ingrandimento per Kivio +Name[ja]=Kivio ズームツール +Name[km]=ឧបករណ៍ពង្រីកសម្រាប់ Kivio +Name[lo]=ເຄື່ຶືອງມືຫຍໍ້/ຂະຫຍາຍສຳລັບແຜນຜັງໄດອະແກຣມ K +Name[lt]=ZoomTool skirtas Kivio +Name[lv]=Tālummaiņas rīks priekš Kivio +Name[ms]=Alat Zum bagi Kivio +Name[mt]=Għodda tat-Tkabbir għall-Kivio +Name[nb]=Skaleringsverktøy for Kivio +Name[nds]=Vergrötternwarktüüch för Kivio +Name[ne]=किभियोका लागि जूमउपकरण +Name[nl]=Zoomgereedschap voor Kivio +Name[nn]=Skaleringsverktøy for Kivio +Name[pl]=Narzędzie powiększania dla Kivio +Name[pt]=Ferramenta de Ampliação para o Kivio +Name[pt_BR]=Ferramenta de ampliação para o Kivio +Name[ro]=Unealtă scalare pentru Kivio +Name[ru]=Изменение масштаба для Kivio +Name[se]=Kivio-stuoridanreaidu +Name[sk]=Lupa pre Kivio +Name[sl]=Orodje za povečavo za Kivio +Name[sr]=Алат за зумирање за Kivio +Name[sr@Latn]=Alat za zumiranje za Kivio +Name[sv]=Zoomverktyg för Kivio +Name[ta]=Kivio அணுகுகருவி +Name[tg]=Асбоби Калонкунанда барои Kivio +Name[th]=เครื่องมือย่อ/ขยายสำหรับแผนผังไดอะแกรม K +Name[tr]=Kivio için Odaklama Aracı +Name[uk]=Засіб масштабування для Kivio +Name[uz]=Kivio uchun kattalashtirish vositasi +Name[uz@cyrillic]=Kivio учун катталаштириш воситаси +Name[ven]=Tshishumiswa tshau vhona tsha Kivio +Name[xh]=Sondeza Isixhobo se Kivio +Name[zh_CN]=Kivio 缩放工具 +Name[zh_TW]=Kivio 縮放工具 +Name[zu]=Ithuluzi Lokukhuphukisela ngaphezulu le Kivio +Type=Service diff --git a/kivio/plugins/kiviozoomtool/kiviozoomtool.rc b/kivio/plugins/kiviozoomtool/kiviozoomtool.rc new file mode 100644 index 00000000..3bc5a842 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/kiviozoomtool.rc @@ -0,0 +1,52 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" > +<kpartgui name="KivioZoomTool" library="libkiviozoomtool" version="8"> + <MenuBar> + <Menu name="View"> + <Separator/> + <Action name="viewZoom"/> + <Menu name="Zoom"><text>&Zoom Tool</text> + <Action name="zoomPlus"/> + <Action name="zoomMinus"/> + <Action name="zoomWidth"/> + <Action name="zoomHeight"/> + <Action name="zoomPage"/> + <Action name="zoomSelected"/> + <Action name="zoomAllObjects"/> + </Menu> + </Menu> + <Menu name="Tools"> + <Action name="zoom"/> + <Action name="pan"/> + </Menu> + </MenuBar> + <ToolBar name="ZoomToolBar" fullWidth="false" position="left" hidden="true"><text>Zoom Tool</text> + <Action name="zoomPlus"/> + <Action name="zoomMinus"/> + <Separator/> + <Action name="zoomWidth"/> + <Action name="zoomHeight"/> + <Action name="zoomPage"/> + <Separator/> + <Action name="zoomSelected"/> + <Action name="zoomAllObjects"/> + </ToolBar> + <ToolBar name="EditToolBar" fullWidth="false"><text>Edit</text> + <Separator/> + <Action name="viewZoom"/> + </ToolBar> + <ToolBar name="ToolsToolBar"> + <Action name="zoom"/> + <Action name="pan"/> + </ToolBar> + <Menu name="ZoomPopup"> + <Action name="zoomPlus"/> + <Action name="zoomMinus"/> + <Separator/> + <Action name="zoomWidth"/> + <Action name="zoomHeight"/> + <Action name="zoomPage"/> + <Separator/> + <Action name="zoomSelected"/> + <Action name="zoomAllObjects"/> + </Menu> +</kpartgui> diff --git a/kivio/plugins/kiviozoomtool/plugin.cpp b/kivio/plugins/kiviozoomtool/plugin.cpp new file mode 100644 index 00000000..af26c8da --- /dev/null +++ b/kivio/plugins/kiviozoomtool/plugin.cpp @@ -0,0 +1,58 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "plugin.h" +#include "tool_zoom.h" + +#include "kivio_view.h" + +#include <kinstance.h> +#include <kiconloader.h> + +/*************************************************** + * Factory + ***************************************************/ +K_EXPORT_COMPONENT_FACTORY( libkiviozoomtool, ZoomToolFactory ) + +KInstance* ZoomToolFactory::s_global = 0; + +ZoomToolFactory::ZoomToolFactory( QObject* parent, const char* name ) +: KLibFactory( parent, name ) +{ + s_global = new KInstance("kivio"); +} + +ZoomToolFactory::~ZoomToolFactory() +{ + delete s_global; +} + +QObject* ZoomToolFactory::createObject( QObject* parent, const char*, const char*, const QStringList& ) +{ + if ( !parent->inherits("KivioView") ) + return 0; + + QObject* obj = new ZoomTool( (KivioView*)parent ); + return obj; +} + +KInstance* ZoomToolFactory::global() +{ + return s_global; +} +#include "plugin.moc" diff --git a/kivio/plugins/kiviozoomtool/plugin.h b/kivio/plugins/kiviozoomtool/plugin.h new file mode 100644 index 00000000..e24fd094 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/plugin.h @@ -0,0 +1,43 @@ +/* + * 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 ZOOM_PLUGIN_H +#define ZOOM_PLUGIN_H + +#include <qstringlist.h> +#include <qobject.h> + +#include <klibloader.h> + +class KInstance; + +class ZoomToolFactory : public KLibFactory +{ Q_OBJECT +public: + ZoomToolFactory( QObject* parent = 0, const char* name = 0 ); + ~ZoomToolFactory(); + + virtual QObject* createObject( QObject* parent = 0, const char* name = 0, + const char* classname = "QObject", const QStringList &args = QStringList() ); + static KInstance* global(); + +private: + static KInstance* s_global; +}; + +#endif diff --git a/kivio/plugins/kiviozoomtool/tool_zoom.cpp b/kivio/plugins/kiviozoomtool/tool_zoom.cpp new file mode 100644 index 00000000..aa3e8a2d --- /dev/null +++ b/kivio/plugins/kiviozoomtool/tool_zoom.cpp @@ -0,0 +1,364 @@ +/* + * 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 "tool_zoom.h" +#include "kivio_view.h" +#include "kivio_page.h" +#include "kivio_canvas.h" +#include "kivio_factory.h" + +#include <kaction.h> +#include <kiconloader.h> +#include <klocale.h> +#include <kpopupmenu.h> +#include <ktoolbar.h> +#include <KoMainWindow.h> +#include <kdebug.h> +#include <KoZoomHandler.h> +#include <KoPoint.h> +#include <kstdaction.h> +#include <KoZoomAction.h> + +#include <qapplication.h> +#include <qcursor.h> + +ZoomTool::ZoomTool(KivioView* parent) : Kivio::MouseTool(parent, "Zoom Mouse Tool") +{ + m_zoomAction = new KRadioAction(i18n("&Zoom"), "viewmag", CTRL + ALT + Key_Z, actionCollection(), "zoom"); + m_zoomAction->setWhatsThis(i18n("By pressing this button you can zoom in on a specific area.")); + m_panAction = new KRadioAction(i18n("&Pan Document"), "kivio_zoom_hand", CTRL + ALT + Key_H, actionCollection(), "pan"); + m_panAction->setWhatsThis(i18n("You can drag the document by using the mouse.")); + m_zoomAction->setExclusiveGroup("zoomAction"); + m_panAction->setExclusiveGroup("zoomAction"); + connect(m_zoomAction,SIGNAL(activated()),SLOT(zoomActivated())); + connect(m_panAction,SIGNAL(activated()),SLOT(handActivated())); + connect(m_zoomAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + connect(m_panAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool))); + + KoZoomAction* viewZoom = new KoZoomAction(i18n("Zoom &Level"), "viewmag", 0, actionCollection(), "viewZoom" ); + viewZoom->setWhatsThis(i18n("This allows you to zoom in or out of a document. You can either choose one of the predefined zoomfactors or enter a new zoomfactor (in percent).")); + connect(viewZoom, SIGNAL(zoomChanged(const QString&)), parent, SLOT(viewZoom(const QString&))); + connect(parent, SIGNAL(zoomChanged(int)), viewZoom, SLOT(setZoom(int))); + + m_pPlus = KStdAction::zoomIn(this, SLOT(zoomPlus()), actionCollection(), "zoomPlus"); + m_pPlus->setWhatsThis(i18n("You can zoom in on the document by pressing this button.")); + + m_pMinus = KStdAction::zoomOut(this, SLOT(zoomMinus()), actionCollection(), "zoomMinus"); + m_pMinus->setWhatsThis(i18n("By pressing this button you can zoom out of the document.")); + + m_pZoomWidth = new KAction( i18n("Zoom Width"), "kivio_zoom_width", SHIFT+Key_F4, actionCollection(), "zoomWidth" ); + m_pZoomWidth->setWhatsThis(i18n("You can zoom the document that it fits into the window width.")); + connect(m_pZoomWidth,SIGNAL(activated()),SLOT(zoomWidth())); + + m_pZoomHeight = new KAction( i18n("Zoom Height"), "kivio_zoom_height", SHIFT+Key_F5, actionCollection(), "zoomHeight" ); + m_pZoomHeight->setWhatsThis(i18n("You can zoom the document that it fits into the window height.")); + connect(m_pZoomHeight,SIGNAL(activated()),SLOT(zoomHeight())); + + m_pZoomPage = new KAction( i18n("Zoom Page"), "kivio_zoom_page", SHIFT+Key_F6, actionCollection(), "zoomPage" ); + m_pZoomPage->setWhatsThis(i18n("The Zoom Page button shows the entire page.")); + connect(m_pZoomPage,SIGNAL(activated()),SLOT(zoomPage())); + + m_pZoomSelected = new KAction( i18n("Zoom Selected"), "kivio_zoom_selected", CTRL+Key_Y, actionCollection(), "zoomSelected" ); + m_pZoomSelected->setWhatsThis(i18n("By pressing this button you zoom in on the document, so that all <b>selected</b> objects are visible.")); + connect(m_pZoomSelected,SIGNAL(activated()),SLOT(zoomSelected())); + + m_pZoomAllObjects = new KAction( i18n("Zoom All Objects"), "kivio_zoom_allobject", 0, actionCollection(), "zoomAllObjects" ); + m_pZoomAllObjects->setWhatsThis(i18n("You are able to zoom in on the document, so that all objects are visible by pressing this button.")); + connect(m_pZoomAllObjects,SIGNAL(activated()),SLOT(zoomAllobjects())); + + QPixmap pix; + + pix = BarIcon("kivio_zoom_plus",KivioFactory::global()); + m_pPlusCursor = new QCursor(pix,pix.width()/2,pix.height()/2); + + pix = BarIcon("kivio_zoom_minus",KivioFactory::global()); + m_pMinusCursor = new QCursor(pix,pix.width()/2,pix.height()/2); + + pix = BarIcon("kivio_zoom_hand",KivioFactory::global()); + m_handCursor = new QCursor(pix,pix.width()/2,pix.height()/2); + + m_pMenu = 0; +} + +ZoomTool::~ZoomTool() +{ + delete m_pPlusCursor; + delete m_pMinusCursor; + delete m_handCursor; +} + +bool ZoomTool::processEvent(QEvent* e) +{ + KivioCanvas* canvas = view()->canvasWidget(); + + if(!m_bHandMode) { + switch(e->type()) { + case QEvent::KeyPress: + if (!m_bLockKeyboard && (static_cast<QKeyEvent*>(e)->key() == Key_Shift)) { + m_pCurrent = m_pMinus; + canvas->setCursor(*m_pMinusCursor); + return true; + } + break; + case QEvent::KeyRelease: + if (!m_bLockKeyboard && (static_cast<QKeyEvent*>(e)->key() == Key_Shift)) { + m_pCurrent = m_pPlus; + canvas->setCursor(*m_pPlusCursor); + return true; + } + break; + case QEvent::MouseButtonPress: + { + QMouseEvent* me = static_cast<QMouseEvent*>(e); + + if(me->button() == LeftButton) { + if(m_pCurrent == m_pMinus) { + m_pCurrent->activate(); + } else { + m_bLockKeyboard = true; + m_bDrawRubber = true; + canvas->startRectDraw(me->pos(), KivioCanvas::Rubber); + } + } else { + showPopupMenu(me->globalPos()); + } + + return true; + break; + } + case QEvent::MouseButtonRelease: + if(m_pCurrent == m_pPlus && m_bDrawRubber) { + canvas->endRectDraw(); + m_bDrawRubber = false; + m_bLockKeyboard = false; + zoomRect(canvas->rect()); + return true; + } + break; + case QEvent::MouseMove: + if (m_bDrawRubber) { + canvas->continueRectDraw(static_cast<QMouseEvent*>(e)->pos(), KivioCanvas::Rubber); + return true; + } + break; + default: + break; + } + } else { + switch(e->type()) { + case QEvent::MouseButtonPress: + isHandMousePressed = true; + mousePos = static_cast<QMouseEvent*>(e)->pos(); + return true; + break; + case QEvent::MouseButtonRelease: + isHandMousePressed = false; + return true; + break; + case QEvent::MouseMove: + if (isHandMousePressed) { + canvas->setUpdatesEnabled(false); + QPoint newPos = static_cast<QMouseEvent*>(e)->pos(); + mousePos -= newPos; + canvas->scrollDx(-mousePos.x()); + canvas->scrollDy(-mousePos.y()); + mousePos = newPos; + canvas->setUpdatesEnabled(true); + return true; + } + break; + default: + break; + } + } + + return false; +} + +void ZoomTool::setActivated(bool a) +{ + if(a) { + m_pCurrent = m_pPlus; + emit activated(this); + } else { + kdDebug(43000) << "ZoomTool DeActivate" << endl; + + m_pCurrent = 0L; + + m_zoomAction->setChecked(false); + m_panAction->setChecked(false); + view()->setStatusBarInfo(""); + + if (!view()->canvasWidget()->isUpdatesEnabled()) { + view()->canvasWidget()->setUpdatesEnabled(true); + } + } +} + +void ZoomTool::zoomActivated() +{ + view()->canvasWidget()->setCursor(*m_pPlusCursor); + m_bHandMode = false; + m_bDrawRubber = false; + m_bLockKeyboard = false; + m_zoomAction->setChecked(true); + m_panAction->setChecked(false); + view()->setStatusBarInfo(i18n("Hold Shift to zoom out.")); +} + +void ZoomTool::handActivated() +{ + view()->canvasWidget()->setCursor(*m_handCursor); + m_bHandMode = true; + isHandMousePressed = false; + m_zoomAction->setChecked(false); + m_panAction->setChecked(true); +} + +void ZoomTool::zoomPlus() +{ + KivioCanvas* canvas = view()->canvasWidget(); + canvas->zoomIn(QPoint(canvas->width()/2, canvas->height()/2)); + if(view()->zoomHandler()->zoom() >= 2000) + { + m_pPlus->setEnabled(false); + m_pMinus->setEnabled(true); + } + else + { + m_pPlus->setEnabled(true); + m_pMinus->setEnabled(true); + } +} + +void ZoomTool::zoomMinus() +{ + KivioCanvas* canvas = view()->canvasWidget(); + canvas->zoomOut(QPoint(canvas->width()/2, canvas->height()/2)); + if(view()->zoomHandler()->zoom() <= 25) + { + m_pMinus->setEnabled(false); + m_pPlus->setEnabled(true); + } + else + { + m_pMinus->setEnabled(true); + m_pPlus->setEnabled(true); + } +} + +void ZoomTool::zoomWidth() +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoZoomHandler zoom; + zoom.setZoomAndResolution(100, KoGlobal::dpiX(), + KoGlobal::dpiY()); + int cw = QMAX(10,canvas->width()-20); + KoPageLayout pl = canvas->activePage()->paperLayout(); + float w = zoom.zoomItX(pl.ptWidth); + float z = cw/w; + + canvas->setUpdatesEnabled(false); + view()->viewZoom(qRound(z * 100)); + canvas->setUpdatesEnabled(true); +} + +void ZoomTool::zoomHeight() +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoZoomHandler zoom; + zoom.setZoomAndResolution(100, KoGlobal::dpiX(), + KoGlobal::dpiY()); + int ch = QMAX(10,canvas->height()-20); + KoPageLayout pl = canvas->activePage()->paperLayout(); + float h = zoom.zoomItY(pl.ptHeight); + float zh = ch/h; + + canvas->setUpdatesEnabled(false); + view()->viewZoom(qRound(zh * 100)); + canvas->setUpdatesEnabled(true); +} + +void ZoomTool::zoomPage() +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoZoomHandler zoom; + zoom.setZoomAndResolution(100, KoGlobal::dpiX(), + KoGlobal::dpiY()); + int cw = QMAX(10,canvas->width()-20); + int ch = QMAX(10,canvas->height()-20); + + KoPageLayout pl = canvas->activePage()->paperLayout(); + float w = zoom.zoomItX(pl.ptWidth); + float h = zoom.zoomItY(pl.ptHeight); + + float z = QMIN(cw/w,ch/h); + + canvas->setUpdatesEnabled(false); + view()->viewZoom(qRound(z * 100)); + canvas->setUpdatesEnabled(true); +} + +void ZoomTool::showPopupMenu(const QPoint& p ) +{ + if(!m_pMenu) { + m_pMenu = static_cast<KPopupMenu*>(factory()->container("ZoomPopup", this)); + } + + if(m_pMenu) { + m_pMenu->popup(p); + } else { + kdDebug(43000) << "What no popup! *ARGH*!" << endl; + } +} + +void ZoomTool::zoomSelected() +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoRect r = canvas->activePage()->getRectForAllSelectedStencils(); + + if (!r.isNull() && r.isValid()) { + canvas->setVisibleArea(r); + } +} + +void ZoomTool::zoomAllobjects() +{ + KivioCanvas* canvas = view()->canvasWidget(); + KoRect r = canvas->activePage()->getRectForAllStencils(); + + if (!r.isNull() && r.isValid()) { + canvas->setVisibleArea(r); + } +} + +void ZoomTool::zoomRect(QRect r) +{ + KivioCanvas* canvas = view()->canvasWidget(); + + if (r.isEmpty()) { + canvas->zoomIn(r.topLeft()); + return; + } + + KoPoint p0 = canvas->mapFromScreen(r.topLeft()); + canvas->setVisibleArea(KoRect(p0.x(), p0.y(), view()->zoomHandler() + ->unzoomItX(r.width()), view()->zoomHandler()->unzoomItY(r.height()))); +} +#include "tool_zoom.moc" diff --git a/kivio/plugins/kiviozoomtool/tool_zoom.h b/kivio/plugins/kiviozoomtool/tool_zoom.h new file mode 100644 index 00000000..97c6ebcd --- /dev/null +++ b/kivio/plugins/kiviozoomtool/tool_zoom.h @@ -0,0 +1,92 @@ +/* + * 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 TOOL_ZOOM_H +#define TOOL_ZOOM_H + +#include "kivio_mousetool.h" + +class KivioView; +class KivioPage; +class KivioCanvas; +class KPopupMenu; + +class KRadioAction; +class KAction; + +class QCursor; + +class ZoomTool : public Kivio::MouseTool +{ + Q_OBJECT + public: + ZoomTool(KivioView* parent); + virtual ~ZoomTool(); + + virtual bool processEvent(QEvent* e); + + void zoomRect(QRect); + + public slots: + void zoomActivated(); + void handActivated(); + + void zoomPlus(); + void zoomMinus(); + void zoomWidth(); + void zoomHeight(); + void zoomPage(); + void zoomSelected(); + void zoomAllobjects(); + + virtual void setActivated(bool a); + + protected: + void showPopupMenu(const QPoint&); + + signals: + void operationDone(); + + private: + KRadioAction* m_zoomAction; + KRadioAction* m_panAction; + + KPopupMenu* m_pMenu; + + KAction* m_pMinus; + KAction* m_pPlus; + KAction* m_pZoomWidth; + KAction* m_pZoomHeight; + KAction* m_pZoomSelected; + KAction* m_pZoomPage; + KAction* m_pZoomAllObjects; + + KAction* m_pCurrent; + + QCursor* m_pPlusCursor; + QCursor* m_pMinusCursor; + QCursor* m_handCursor; + + bool m_bDrawRubber; + bool m_bHandMode; + bool isHandMousePressed; + bool m_bLockKeyboard; + QPoint mousePos; +}; + +#endif diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/Makefile.am b/kivio/plugins/kiviozoomtool/zoom_pics/Makefile.am new file mode 100644 index 00000000..904f6a19 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/Makefile.am @@ -0,0 +1,21 @@ +#1########################################################!@#$ +#### Makefile.am generated automatically by KDEStudio #### +#### WARNING! All changes made in this part will be lost! #### +############################################################## + +kiviopicsdir = $(kde_datadir)/kivio/pics + +kiviopics_DATA = kivio_zoom.xpm kivio_zoom_allobject.xpm kivio_zoom_hand.xpm kivio_zoom_height.xpm kivio_zoom_minus.xpm kivio_zoom_page.xpm kivio_zoom_plus.xpm kivio_zoom_selected.xpm kivio_zoom_width.xpm +EXTRA_DIST = \ + kivio_zoom.xpm\ + kivio_zoom_allobject.xpm\ + kivio_zoom_hand.xpm\ + kivio_zoom_height.xpm\ + kivio_zoom_minus.xpm\ + kivio_zoom_page.xpm\ + kivio_zoom_plus.xpm\ + kivio_zoom_selected.xpm\ + kivio_zoom_width.xpm +############################################################## +#### END KDEStudio part #### +#2########################################################!@#$ diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom.xpm new file mode 100644 index 00000000..6991464c --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static const char *magick[] = { +"16 16 16 1", +" c Gray0", +". c Gray5", +"X c Gray20", +"o c Gray42", +"O c #868686", +"+ c #939393", +"@ c Gray60", +"# c Gray63", +"$ c #aeaeae", +"% c #bbbbbb", +"& c Gray80", +"* c None", +"= c Gray84", +"- c #e4e4e4", +"; c #f1f1f1", +": c Gray100", +"****$ ##$****", +"**$ :;;: #$***", +"** :::;&;-= #$**", +"*$ ;&:::%&= ##$*", +"* :%&;:;&O%= #$*", +"* ;$%-;&$+O- #$*", +"* -@$%&$+Oo- #$*", +"* -#O$#+OoO- #$*", +"*$.=$OOOoO:X+$**", +"** ==#++O:% +$**", +"**$ &&=-X +$**", +"****$ * #$*", +"*********** #$", +"************ #", +"************* ", +"************** " +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_allobject.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_allobject.xpm new file mode 100644 index 00000000..09c918be --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_allobject.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static const char *magick[] = { +"16 16 6 1", +" c Gray0", +". c #939393", +"X c Gray63", +"o c #aeaeae", +"O c None", +"+ c Gray100", +"OOOX XXoOOOO", +"OX +++++ XoOOO", +"O ++ XoOO", +"X +++++ ++ XoOO", +" + +++++ +++ XoO", +" + ++++ +++ XoO", +" + +++ + +++ XoO", +" + +++ ++ XoO", +" +++ +++++ + XoO", +"X + .oOO", +"O +++++++++ .oOO", +"OX +++++ .oOO", +"OOOX O XoO", +"OOOOOOOOOOO XO", +"OOOOOOOOOOOO O", +"OOOOOOOOOOOOO O" +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_hand.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_hand.xpm new file mode 100644 index 00000000..57f04589 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_hand.xpm @@ -0,0 +1,35 @@ +/* XPM */ +static const char *magick[] = { +"16 16 15 1", +" c Gray0", +". c #434343", +"X c #5d5d5d", +"o c Gray42", +"O c #868686", +"+ c Gray60", +"@ c Gray63", +"# c #aeaeae", +"$ c #bbbbbb", +"% c Gray80", +"& c None", +"* c Gray84", +"= c #e4e4e4", +"- c #f1f1f1", +"; c Gray100", +"&&&&&&& X& &&&&", +"&&&&& *; =-X&&&", +"&&&&X;-X;$X;X O&", +"&&&& &; =; ;X=O&", +"&&&&& --X;X=;X;O", +"&&&&& $;X;=X;X;o", +"& &&& ; ;;X;X;.", +" =; && ;X=;&;-; ", +"& =; & ;;;;;;;; ", +"&& -; ;-;;-;-;= ", +"&& #;;;;=-=--=#o", +"&&& #-;;-;-;=$ &", +"&&&& @=;;;-=$+ &", +"&&&&& %--=%$+ &&", +"&&&&& $%**%$+ &&", +"&&&&&& &$&" +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_height.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_height.xpm new file mode 100644 index 00000000..9a26d049 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_height.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static const char *magick[] = { +"16 16 5 1", +" c Gray0", +". c Cyan", +"X c #868686", +"o c None", +"O c Gray100", +"oooooooooooooooo", +"o oo ooo", +" o OOOOOOOoooo", +"o oo OOOOOOOoooo", +"o oo OOOOOOOoooo", +"o oo OOO Ooooo", +"o oo OO .O. oooo", +"o oo O .O.O. ooo", +"o oo O O.O.O ooo", +"o oo O .O.O. ooo", +"o oo OO .O. Xooo", +"o oo OOO X Xoo", +"o oo OOOOOOOX Xo", +" o OOOOOOOoX X", +"o oo oX ", +"oooooooooooooooo" +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_minus.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_minus.xpm new file mode 100644 index 00000000..08c43531 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_minus.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static const char *magick[] = { +"16 16 6 1", +" c Gray0", +". c #939393", +"X c Gray63", +"o c #aeaeae", +"O c None", +"+ c Gray100", +"OOOOo XXoOOOO", +"OOo ++++ XoOOO", +"OO ++++++++ XoOO", +"Oo ++++++++ XXoO", +"O ++++++++++ XoO", +"O ++ ++ XoO", +"O ++ ++ XoO", +"O ++++++++++ XoO", +"Oo ++++++++ .oOO", +"OO ++++++++ .oOO", +"OOo ++++ .oOO", +"OOOOo O XoO", +"OOOOOOOOOOO Xo", +"OOOOOOOOOOOO X", +"OOOOOOOOOOOOO ", +"OOOOOOOOOOOOOO " +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_page.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_page.xpm new file mode 100644 index 00000000..ed3b9faa --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_page.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static const char *magick[] = { +"16 16 5 1", +" c Gray0", +". c Cyan", +"X c #868686", +"o c None", +"O c Gray100", +"oooooooooooooooo", +"o oo", +"o OOOOOOOOOOO oo", +"o OOOOOOOOOOO Xo", +"o OOO OOOOO Xo", +"o OO .O. OOOO Xo", +"o O .O.O. OOO Xo", +"o O O.O.O OOO Xo", +"o O .O.O. OOO Xo", +"o OO .O. XOOO Xo", +"o OOO X XOO Xo", +"o OOOOOOOX XO Xo", +"o OOOOOOOOX X Xo", +"o OOOOOOOOOX Xo", +"o OOOOOOOOOOO Xo", +"o Xo" +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_plus.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_plus.xpm new file mode 100644 index 00000000..ac92ed4a --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_plus.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static const char *magick[] = { +"16 16 6 1", +" c Gray0", +". c #939393", +"X c Gray63", +"o c #aeaeae", +"O c None", +"+ c Gray100", +"OOOo XXoOOOOO", +"Oo ++++ XoOOOO", +"O ++++++++ XoOOO", +"o +++ +++ XXoOO", +" ++++ ++++ XoOO", +" ++ ++ XoOO", +" ++ ++ XoOO", +" ++++ ++++ XoOO", +"o +++ +++ .oOOO", +"O ++++++++ .oOOO", +"Oo ++++ .oOOO", +"OOOo O XoOO", +"OOOOOOOOOO XoO", +"OOOOOOOOOOO XO", +"OOOOOOOOOOOO O", +"OOOOOOOOOOOOO O" +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_selected.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_selected.xpm new file mode 100644 index 00000000..3296852a --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_selected.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static const char *magick[] = { +"16 16 6 1", +" c Gray0", +". c #939393", +"X c Gray63", +"o c #aeaeae", +"O c None", +"+ c Gray100", +"OOOOX XXoOOO", +"OOX +++++ XoOO", +"OO +++++++++ XoO", +"OX + ++ ++ + XoO", +"O +++++++++++ Xo", +"O +++++++++++ Xo", +"O ++ +++++ ++ Xo", +"O +++++++++++ Xo", +"O +++++++++++ Xo", +"OX + ++ ++ + .oO", +"OO +++++++++ .oO", +"OOX +++++ .oO", +"OOOOX O Xo", +"OOOOOOOOOOOO X", +"OOOOOOOOOOOOO ", +"OOOOOOOOOOOOOO " +}; diff --git a/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_width.xpm b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_width.xpm new file mode 100644 index 00000000..42150a39 --- /dev/null +++ b/kivio/plugins/kiviozoomtool/zoom_pics/kivio_zoom_width.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static const char *magick[] = { +"16 16 5 1", +" c Gray0", +". c Cyan", +"X c #868686", +"o c None", +"O c Gray100", +"oo oooooooooo oo", +"o o", +"oo oooooooooo oo", +"oooooooooooooooo", +"o oooo", +"o OOOOOOOOO ooo", +"o OOOOOOOOO O oo", +"o OOOO OO o", +"o OOO .O. OOOO o", +"o OO .O.O. OOO o", +"o OO O.O.O OOO o", +"o OO .O.O. OOO o", +"o OOO .O. XOOO o", +"o OOOO X XOO o", +"o OOOOOOOOX XO o", +"o OOOOOOOOOX O o" +}; |