From koffice-devel Fri Aug 18 14:41:32 2006 From: Thorsten Zachmann Date: Fri, 18 Aug 2006 14:41:32 +0000 To: koffice-devel Subject: Re: Shapes and Tools Message-Id: <200608181641.33337.t.zachmann () zagge ! de> X-MARC-Message: https://marc.info/?l=koffice-devel&m=115591201411264 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_dGd5EYoDO13CQH5" --Boundary-00=_dGd5EYoDO13CQH5 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thursday 17 August 2006 11:40, Jan Hambrecht wrote: > Hi... > > I yesterday started to work on a path tool to edit a KoPathShape. great. I have also started a tool that allready works partly I have attached it to the email (The files are named KoPolyTool but it is a KoShapeTool). Maybe you can use parts of it. However your patch to fix the bounding box problem of the path shape broke it. I also have a fix for that that reverts your changed and fixes it differently. One reason I did this is that with your patch it was not so easily possible to work with my tool as it would mean you have to constantly set the position of the shape if the top left corner is changed. I solved this problem by adding a normalize method which should be used to make the bounding box start at 0,0 after the object is created or changed. I have also attached this patch. I think we need at least two tools one for creating a path shape (not e special case like a rectangular or a circle) and one for editing them. I allready talked to Kenneth Wimer to asked him what artist needs for editing path objects. We agreed that I will send a request to the artists list when I'm back from my holidays. So they can comment on what kind of tools and so on they need for editing path objects and how the tools should work. Just to let you know. I'm in holiday at the moment and won't have access to a computer for a week or so. Have a nice day, and greetings from Poland Thorsten --Boundary-00=_dGd5EYoDO13CQH5 Content-Type: text/x-diff; charset="iso-8859-1"; name="shape.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="shape.diff" Index: KoPathShape.cpp =================================================================== --- KoPathShape.cpp (revision 573433) +++ KoPathShape.cpp (working copy) @@ -131,7 +131,7 @@ void KoPathShape::paint( QPainter &paint { applyConversion( painter, converter ); QPainterPath path( outline() ); - + painter.setBrush( background() ); painter.drawPath( path ); //paintDebug( painter ); @@ -183,7 +183,7 @@ void KoPathShape::paintDebug( QPainter & qDebug() << "nop = " << i; } -const QPainterPath KoPathShape::getPath( const QPointF &position ) const +const QPainterPath KoPathShape::KoPathShape::outline() const { QList::const_iterator pathIt( m_points.begin() ); QPainterPath path; @@ -197,7 +197,7 @@ const QPainterPath KoPathShape::getPath( if ( ( *it )->properties() & KoPathPoint::StartSubpath ) { //qDebug() << "moveTo" << ( *it )->point(); - path.moveTo( ( *it )->point() - position ); + path.moveTo( ( *it )->point() ); } else if ( activeCP || ( *it )->properties() & KoPathPoint::HasControlPoint1 ) { @@ -205,14 +205,14 @@ const QPainterPath KoPathShape::getPath( // << "lastPoint->controlPoint2()" << lastPoint->controlPoint2() // << "lastPoint->point()" << lastPoint->point() << ( *it )->controlPoint1(); - path.cubicTo( (activeCP ? lastPoint->controlPoint2() : lastPoint->point() ) - position - , ( ( *it )->properties() & KoPathPoint::HasControlPoint1 ? ( *it )->controlPoint1() : ( *it )->point() ) - position - , ( *it )->point() - position ); + path.cubicTo( activeCP ? lastPoint->controlPoint2() : lastPoint->point() + , ( *it )->properties() & KoPathPoint::HasControlPoint1 ? ( *it )->controlPoint1() : ( *it )->point() + , ( *it )->point() ); } else { //qDebug() << "lineTo" << ( *it )->point(); - path.lineTo( ( *it )->point() - position ); + path.lineTo( ( *it )->point() ); } if ( ( *it )->properties() & KoPathPoint::CloseSubpath ) { @@ -234,16 +234,10 @@ const QPainterPath KoPathShape::getPath( return path; } -const QPainterPath KoPathShape::KoPathShape::outline() const -{ - QPainterPath originalPath( getPath( QPointF( 0, 0 ) ) ); - return getPath( originalPath.boundingRect().topLeft() ); -} - QRectF KoPathShape::boundingRect() const { QRectF bb( outline().boundingRect() ); - //qDebug() << "KoPathShape::boundingRect = " << bb; + qDebug() << "KoPathShape::boundingRect = " << bb; return transformationMatrix( 0 ).mapRect( bb ); } @@ -321,6 +315,14 @@ void KoPathShape::close() firstPoint->setProperties( firstPoint->properties() | KoPathPoint::CanHaveControlPoint1 ); } +void KoPathShape::normalize() +{ + QPointF tl( outline().boundingRect().topLeft() ); + QMatrix matrix; + matrix.translate( -tl.x(), -tl.y() ); + map( matrix ); +} + void KoPathShape::map( const QMatrix &matrix ) { QList::iterator pathIt( m_points.begin() ); Index: KoPathShape.h =================================================================== --- KoPathShape.h (revision 573430) +++ KoPathShape.h (working copy) @@ -295,6 +295,8 @@ public: */ void update() {} + void normalize(); + protected: void map( const QMatrix &matrix ); @@ -302,8 +304,6 @@ protected: void paintDebug( QPainter &painter ); - const QPainterPath getPath( const QPointF &position ) const; - /// a KoSubpath contains a path from a moveTo until a close or a new moveTo typedef QList KoSubpath; QList m_points; Index: KoPathShapeFactory.cpp =================================================================== --- KoPathShapeFactory.cpp (revision 573430) +++ KoPathShapeFactory.cpp (working copy) @@ -23,6 +23,8 @@ #include +#include + KoPathShapeFactory::KoPathShapeFactory(QObject *parent, const QStringList&) : KoShapeFactory(parent, "KoPathShape", i18n("A simple path shape")) { @@ -34,6 +36,8 @@ KoShape * KoPathShapeFactory::createDefa path->moveTo( QPointF( 0, 10 ) ); path->curveTo( QPointF( 0, 20 ), QPointF( 5, 20 ), QPointF( 5, 10 ) ); path->curveTo( QPointF( 5, 0 ), QPointF( 10, 0 ), QPointF( 10, 10 ) ); + path->normalize(); + qDebug() << "KoPathShapeFactory" << path->position() << path->outline().boundingRect().topLeft(); path->setBorder( new KoLineBorder( 1.0 ) ); return path; } --Boundary-00=_dGd5EYoDO13CQH5 Content-Type: application/x-tgz; name="KoShapeTool.tar.gz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="KoShapeTool.tar.gz" H4sIANTQ5UQAA+1X3XPaOBDPM3/FTjtzAxlCbPI1A2nmCA0tU5IQINfJvXSELWJdjeWTBTl60/vb byXZxiYkZFqaJ+9DYna1v/3QaqX9xPvcX4w492tOGO78ErKQjg8P1X/75MjSv23zW4tOrJMd2zo8 Pq6fHB7U6zuWXa8f2Dtg/Rp38jSLJBEAO/LbpnVURK/h0OvS/i6MPBbBhPkU8H9IhAQ+AelR+PT+ AkLB/6KOLAFAm4cLwe49CeV2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odi0N9BQB8g06nWFhAaSfbHLF/2qDJgV7xpc5/jp1WF+tFRNf4P qkTWwU35nI74eo8V7e/ngkQnU1Vs2U+qmmCnX3wSYU4iVHuc2ukX05f2zmYhXgrUdLFcdeNtwYL7 AT6SzDl7slDec7zFaBsvsq9bKJdVtMcdZntloQjvD4q35qMetqwMa8n8WdefOW6XWAxbSF8Ks5XD 9ha5dr7/xZr4YMN3QYRu/AY3stHo0Yk817xYOb8t67cGbyUpuK8Z9tNb9IMFm6gum6BuAG8prpu8 2McN5bM1354/r88UzgALGF8fW6idLNKv69Uvb2MY8g/Pf9nX6BbHyhxtmP/rx3bdzP/4ZrbsI5z/ 7eOjg2L+fw0q5v9i/i/m/9ed/9PZ38GrLMq+pps5Vt9cG0te3KmhYYrYiYdnNQsbRkPfCC8YvM3V MWdCzjC9uck5nhT1Jfpj43IW4aUjUnNF5cWP5VXFze/DVY0XPQyaJeyEEjshddMkJ7sGu7nHa2bz lCRzpRv5jf7uLF8yODM0f+IKL6igggoqqKCCCiqooIIKKqigggp6lv4Hm5NK0AAoAAA= --Boundary-00=_dGd5EYoDO13CQH5 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ koffice-devel mailing list koffice-devel@kde.org https://mail.kde.org/mailman/listinfo/koffice-devel --Boundary-00=_dGd5EYoDO13CQH5--