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

List:       koffice-devel
Subject:    kpresenter patch: redrawing lines in draw mode
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2004-04-09 7:22:04
Message-ID: 200404090922.04526.t.zachmann () zagge ! de
[Download RAW message or body]

Hello all,

as I pointed out before the lines in the drawing mode are not repainted. So 
the lines are lost e.g. if you switch to a other desktop and back.

The attached patch corrects this behaviour. Please let me know what you think 
about it. I used a vector of QPointArrays to save the lines.

However if you only press the mouse button and release it I have a line with 2 
points and nothing gets drawn not even in the repaint event. Is this a 
problem of qt?

Have a nice day, and a Happy Easter,

Thorsten

["repaintlines.diff" (text/x-diff)]

Index: kprcanvas.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprcanvas.h,v
retrieving revision 1.153
diff -u -3 -p -r1.153 kprcanvas.h
--- kprcanvas.h	6 Apr 2004 06:52:55 -0000	1.153
+++ kprcanvas.h	9 Apr 2004 07:21:07 -0000
@@ -27,6 +27,8 @@
 #include <qpicture.h>
 #include <qvaluelist.h>
 #include <qpixmap.h>
+#include <qpointarray.h>
+#include <qvaluevector.h>
 
 #include <koRuler.h>
 #include <koQueryTrader.h>
@@ -683,7 +685,10 @@ private:
     bool mousePressed;
     bool drawContour;
     ModifyType modType;
-    unsigned int oldMx, oldMy;
+    /**
+     * Saves the last mouse position during mouse move events.
+     */
+    QPoint m_savedMousePos;
 
     KPObject *editNum;
 
@@ -700,6 +705,20 @@ private:
      * Used in drawing mode.
      */
     bool m_drawLineInDrawMode;
+    
+    /**
+     * Save the lines drawed in drawMode. 
+     * This is used for paint events.
+     * Used in drawing mode.
+     */
+    QValueVector<QPointArray> m_drawModeLines;
+
+    /**
+     * Index into the QPointArray for the next point of the line in draw mode.
+     * Used in drawing mode.
+     */
+    int m_drawModeLineIndex;
+    
     bool mouseSelectedObject;
     /// information about current step of the presentation
     PresStep m_step;
Index: kprcanvas.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprcanvas.cc,v
retrieving revision 1.399
diff -u -3 -p -r1.399 kprcanvas.cc
--- kprcanvas.cc	6 Apr 2004 06:52:55 -0000	1.399
+++ kprcanvas.cc	9 Apr 2004 07:21:19 -0000
@@ -318,6 +318,16 @@ void KPrCanvas::paintEvent( QPaintEvent*
         {
             PresStep step( m_step.m_pageNumber, m_step.m_step, m_step.m_subStep, \
false, !goingBack );  drawPresPage( &bufPainter, crect, step );
+            if ( m_drawMode && m_drawModeLines.count() )
+            {
+                bufPainter.save();
+                bufPainter.setPen( m_view->kPresenterDoc()->presPen() );
+                for ( int i = 0; i < m_drawModeLines.count(); ++i )
+                {
+                  bufPainter.drawPolyline( m_drawModeLines[i] );
+                }
+                bufPainter.restore();
+            }
         }
 
         bufPainter.end();
@@ -609,8 +619,7 @@ void KPrCanvas::mousePressEvent( QMouseE
 
     KPObject *kpobject = 0;
 
-    oldMx = contentsPoint.x();
-    oldMy = contentsPoint.y();
+    m_savedMousePos = contentsPoint;
 
     QPoint rasterPoint=applyGrid( e->pos(), true );
 
@@ -1107,12 +1116,13 @@ void KPrCanvas::mousePressEvent( QMouseE
             setToolEditMode( TEM_MOUSE );
         }
     } else {
-        oldMx = e->x();
-        oldMy = e->y();
         if ( e->button() == LeftButton ) {
             if ( m_drawMode ) {
                 setCursor( KPresenterUtils::penCursor() );
                 m_drawLineInDrawMode = true;
+                m_drawModeLineIndex = 0;
+                m_drawModeLines.append( QPointArray() );
+                m_drawModeLines[m_drawModeLines.count() - 1].putPoints( \
m_drawModeLineIndex++, 1, e->x(), e->y() );  }
             else
                 m_view->screenNext();
@@ -1192,6 +1202,7 @@ void KPrCanvas::mouseReleaseEvent( QMous
 
     if ( m_drawMode ) {
         m_drawLineInDrawMode = false;
+        m_drawModeLines[m_drawModeLines.count() - 1].putPoints( \
m_drawModeLineIndex++, 1, contentsPoint.x(), contentsPoint.y() );  return;
     }
     bool state = m_view->kPresenterDoc()->snapToGrid();
@@ -1472,6 +1483,9 @@ void KPrCanvas::mouseReleaseEvent( QMous
 void KPrCanvas::mouseMoveEvent( QMouseEvent *e )
 {
     QPoint contentsPoint( e->pos().x()+diffx(), e->pos().y()+diffy() );
+    int oldMx = m_savedMousePos.x();
+    int oldMy = m_savedMousePos.y();
+    m_savedMousePos = contentsPoint;
     KoPoint docPoint = m_view->zoomHandler()->unzoomPoint( contentsPoint );
     if(m_currentTextObjectView)
     {
@@ -1579,9 +1593,6 @@ void KPrCanvas::mouseMoveEvent( QMouseEv
                     }
 
                     resizeObject( modType, mx - oldMx, my - oldMy );
-
-                    oldMx = e->x()+diffx();
-                    oldMy = e->y()+diffy();
                 }
             } break;
             case TEM_ZOOM : {
@@ -1928,9 +1939,8 @@ void KPrCanvas::mouseMoveEvent( QMouseEv
         p.begin( this );
         p.setPen( m_view->kPresenterDoc()->presPen() );
         p.drawLine( oldMx, oldMy, e->x(), e->y() );
-        oldMx = e->x();
-        oldMy = e->y();
         p.end();
+        m_drawModeLines[m_drawModeLines.count() - 1].putPoints( \
m_drawModeLineIndex++, 1, e->x(), e->y() );  }
 
     if ( !editMode && !m_drawMode && !m_presMenu->isVisible() && fillBlack )
@@ -3141,6 +3151,9 @@ bool KPrCanvas::pNext( bool )
 
     goingBack = false;
 
+    // clear drawed lines
+    m_drawModeLines.clear();
+
     //kdDebug(33001) << "\n-------\nKPrCanvas::pNext m_step =" << m_step.m_step << " \
m_subStep =" << m_step.m_subStep << endl;  
     // First try to go one sub-step further, if any object requires it
@@ -3309,6 +3322,9 @@ bool KPrCanvas::pPrev( bool /*manual*/ )
     goingBack = true;
     m_step.m_subStep = 0;
 
+    // clear drawed lines
+    m_drawModeLines.clear();
+
     if ( m_step.m_step > *m_pageEffectSteps.begin() ) {
         QValueList<int>::ConstIterator it = m_pageEffectSteps.find( m_step.m_step );
         m_step.m_step = *( --it );
@@ -4953,6 +4969,9 @@ void KPrCanvas::gotoPage( int pg )
 {
     int page = pg - 1;
     if ( page != m_step.m_pageNumber || m_step.m_step != *m_pageEffectSteps.begin() \
|| m_step.m_subStep != 0 ) { +        // clear drawed lines
+        m_drawModeLines.clear();
+
         m_step.m_pageNumber = page;
         kdDebug(33001) << "Page::gotoPage m_step.m_pageNumber =" << \
                m_step.m_pageNumber << endl;
         m_presentationSlidesIterator = m_presentationSlides.find( \
m_step.m_pageNumber + 1 );



_______________________________________________
koffice-devel mailing list
koffice-devel@mail.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