[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: Shapes and Tools
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2006-08-18 14:41:32
Message-ID: 200608181641.33337.t.zachmann () zagge ! de
[Download RAW message or body]

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


["shape.diff" (text/x-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<KoSubpath>::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<KoSubpath>::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<KoPathPoint *> KoSubpath;
     QList<KoSubpath> m_points;
Index: KoPathShapeFactory.cpp
===================================================================
--- KoPathShapeFactory.cpp	(revision 573430)
+++ KoPathShapeFactory.cpp	(working copy)
@@ -23,6 +23,8 @@
 
 #include <klocale.h>
 
+#include <QDebug>
+
 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;
 }


["KoShapeTool.tar.gz" (application/x-tgz)]

_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic