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

List:       kde-commits
Subject:    koffice/kspread
From:       Stefan Nikolaus <stefan.nikolaus () kdemail ! net>
Date:       2006-10-12 8:59:54
Message-ID: 1160643594.203589.7224.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 594770 by nikolaus:

Painting	Cache the border pens and associated values.


 M  +28 -3     Canvas.cpp  
 M  +112 -16   CellView.cpp  
 M  +13 -0     CellView.h  


--- trunk/koffice/kspread/Canvas.cpp #594769:594770
@@ -188,8 +188,6 @@
   installEventFilter( this ); // for TAB key processing, otherwise focus change
   setAcceptDrops( true );
   setAttribute(Qt::WA_InputMethodEnabled, true); // ensure using the InputMethod
-
-  setWindowFlags(Qt::WNoAutoErase);
 }
 
 Canvas::~Canvas()
@@ -672,7 +670,11 @@
 
   sheet->enableScrollBarUpdates( true );
 
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+  d->view->doc()->emitEndOperation();
+#else
   d->view->doc()->emitEndOperation( visibleCells() );
+#endif
 }
 
 void Canvas::slotScrollVert( int _value )
@@ -706,7 +708,11 @@
 
   sheet->enableScrollBarUpdates( true );
 
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+  d->view->doc()->emitEndOperation();
+#else
   d->view->doc()->emitEndOperation( visibleCells() );
+#endif
 }
 
 void Canvas::slotMaxColumn( int _max_column )
@@ -1532,7 +1538,7 @@
 #ifdef KSPREAD_CELL_WINDOW
     updateCellWindow();
 #endif
-
+#ifndef KSPREAD_CACHED_PAINTING_ATTRIBUTES
   // repaint whole visible region, if no cells are marked as dirty
   if (sheet->paintDirtyData().isEmpty())
   {
@@ -1573,6 +1579,7 @@
     QRect vr( QPoint(left_col, top_row), QPoint(right_col, bottom_row) );
     sheet->setRegionPaintDirty( vr );
   }
+#endif
   paintUpdates();
   event->accept();
 }
@@ -4057,6 +4064,22 @@
     for (Region::ConstIterator it(paintDirtyList.constBegin()); it != end; ++it)
     {
         QRect range = (*it)->rect() & visibleRect;
+
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+        int right  = range.right();
+        for ( int x = range.left(); x <= right; ++x )
+        {
+            int bottom = range.bottom();
+            for ( int y = range.top(); y <= bottom; ++y )
+            {
+                cell = sheet->cellAt( x, y );
+                cell->setFlag( Cell::Flag_PaintingDirty );
+            }
+        }
+    }
+
+        QRect range = visibleRect;
+#endif
         const double topPos = sheet->dblRowPos(range.top());
         const double leftPos = sheet->dblColumnPos(range.left());
         KoPoint dblCorner( leftPos - xOffset(), topPos - yOffset() );
@@ -4119,7 +4142,9 @@
             dblCorner.setY( topPos - yOffset() );
             dblCorner.setX( dblCorner.x() + sheet->columnFormat( x )->dblWidth() );
         }
+#ifndef KSPREAD_CACHED_PAINTING_ATTRIBUTES
     }
+#endif
 
     /* now paint the selection */
     //Nb.  No longer necessary to paint choose Selection.here as the cell reference highlight
--- trunk/koffice/kspread/CellView.cpp #594769:594770
@@ -77,6 +77,18 @@
   // flag indicating, that we need to recalculate the attributes
   bool dirty;
 #endif
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+  QPen leftBorderPen;
+  QPen rightBorderPen;
+  QPen topBorderPen;
+  QPen bottomBorderPen;
+  QPen goUpDiagonalPen;
+  QPen fallDiagonalPen;
+  uint leftBorderValue;
+  uint rightBorderValue;
+  uint topBorderValue;
+  uint bottomBorderValue;
+#endif
 
   // Position and dimension of displayed text.
   // Doc coordinate system; points; no zoom
@@ -124,6 +136,19 @@
     d->textY      = 0.0;
     d->textWidth  = 0.0;
     d->textHeight = 0.0;
+
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    d->leftBorderPen     = QPen( Qt::NoPen );
+    d->rightBorderPen    = QPen( Qt::NoPen );
+    d->topBorderPen      = QPen( Qt::NoPen );
+    d->bottomBorderPen   = QPen( Qt::NoPen );
+    d->goUpDiagonalPen   = QPen( Qt::NoPen );
+    d->fallDiagonalPen   = QPen( Qt::NoPen );
+    d->leftBorderValue   = 0;
+    d->rightBorderValue  = 0;
+    d->topBorderValue    = 0;
+    d->bottomBorderValue = 0;
+#endif
 }
 #endif
 
@@ -141,6 +166,25 @@
     return d->cell;
 }
 
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+void CellView::update()
+{
+    Cell* const cell = this->cell();
+    kDebug(36004) << "updating painting attributes for " << cell->name() << endl;
+    d->leftBorderPen     = cell->effLeftBorderPen     ( cell->column(), cell->row() );
+    d->rightBorderPen    = cell->effRightBorderPen    ( cell->column(), cell->row() );
+    d->topBorderPen      = cell->effTopBorderPen      ( cell->column(), cell->row() );
+    d->bottomBorderPen   = cell->effBottomBorderPen   ( cell->column(), cell->row() );
+    d->goUpDiagonalPen   = cell->effGoUpDiagonalPen   ( cell->column(), cell->row() );
+    d->fallDiagonalPen   = cell->effFallDiagonalPen   ( cell->column(), cell->row() );
+    d->leftBorderValue   = cell->effLeftBorderValue   ( cell->column(), cell->row() );
+    d->rightBorderValue  = cell->effRightBorderValue  ( cell->column(), cell->row() );
+    d->topBorderValue    = cell->effTopBorderValue    ( cell->column(), cell->row() );
+    d->bottomBorderValue = cell->effBottomBorderValue ( cell->column(), cell->row() );
+    cell->clearFlag( Cell::Flag_PaintingDirty );
+}
+#endif
+
 double CellView::textWidth() const
 {
   return d->textWidth;
@@ -289,6 +333,13 @@
             selected = false;
     }
 
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    // Need to update the painting attributes cache?
+    //
+    if ( !cell()->isDefault() && ( d->dirty || cell()->testFlag( Cell::Flag_PaintingDirty ) ) )
+        update();
+#endif
+
     // Need to make a new layout ?
     //
     // FIXME: We have already used (at least) extraWidth/Height above,
@@ -635,10 +686,17 @@
 
     CellView::Borders paintBorder = CellView::NoBorder;
 
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    QPen leftPen  ( d->leftBorderPen );
+    QPen rightPen ( d->rightBorderPen );
+    QPen topPen   ( d->topBorderPen );
+    QPen bottomPen( d->bottomBorderPen );
+#else
     QPen rightPen( cell->effRightBorderPen( col, row ) );
     QPen leftPen( cell->effLeftBorderPen( col, row ) );
     QPen topPen( cell->effTopBorderPen( col, row ) );
     QPen bottomPen( cell->effBottomBorderPen( col, row ) );
+#endif
 
     // Paint border if outermost cell or if the pen is more "worth"
     // than the border pen of the cell on the other side of the
@@ -653,11 +711,19 @@
     else if ( col == regionRight )
     {
         paintBorder |= CellView::RightBorder;
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+        if ( d->rightBorderValue
+#else
         if ( cell->effRightBorderValue( col, row )
+#endif
                 < sheet->cellAt( col + 1, row )->effLeftBorderValue( col + 1, row ) )
             rightPen = sheet->cellAt( col + 1, row )->effLeftBorderPen( col + 1, row );
     }
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    else if ( d->rightBorderValue
+#else
     else if ( cell->effRightBorderValue( col, row )
+#endif
                 < sheet->cellAt( col + 1, row )->effLeftBorderValue( col + 1, row ) )
     {
         paintBorder |= CellView::RightBorder;
@@ -673,11 +739,19 @@
     else if ( row == regionBottom )
     {
         paintBorder |= CellView::BottomBorder;
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+        if ( d->bottomBorderValue
+#else
         if ( cell->effBottomBorderValue( col, row )
+#endif
                 < sheet->cellAt( col, row + 1 )->effTopBorderValue( col, row + 1) )
             bottomPen = sheet->cellAt( col, row + 1 )->effTopBorderPen( col, row + 1 );
     }
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    else if ( d->bottomBorderValue
+#else
     else if ( cell->effBottomBorderValue( col, row )
+#endif
                 < sheet->cellAt( col, row + 1 )->effTopBorderValue( col, row + 1) )
     {
         paintBorder |= CellView::BottomBorder;
@@ -692,11 +766,19 @@
     else if ( col == regionLeft )
     {
         paintBorder |= CellView::LeftBorder;
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+        if ( d->leftBorderValue
+#else
         if ( cell->effLeftBorderValue( col, row )
+#endif
                 < sheet->cellAt( col - 1, row )->effRightBorderValue( col - 1, row ) )
             leftPen = sheet->cellAt( col - 1, row )->effRightBorderPen( col - 1, row );
     }
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    else if ( d->leftBorderValue
+#else
     else if ( cell->effLeftBorderValue( col, row )
+#endif
                 < sheet->cellAt( col - 1, row )->effRightBorderValue( col - 1, row ) )
     {
         paintBorder |= CellView::LeftBorder;
@@ -711,11 +793,19 @@
     else if ( row == regionTop )
     {
         paintBorder |= CellView::TopBorder;
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+        if ( d->topBorderValue
+#else
         if ( cell->effTopBorderValue( col, row )
+#endif
                 < sheet->cellAt( col, row - 1 )->effBottomBorderValue( col, row - 1 ) )
             topPen = sheet->cellAt( col, row - 1 )->effBottomBorderPen( col, row - 1 );
     }
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    else if ( d->topBorderValue
+#else
     else if ( cell->effTopBorderValue( col, row )
+#endif
                 < sheet->cellAt( col, row - 1 )->effBottomBorderValue( col, row - 1 ) )
     {
         paintBorder |= CellView::TopBorder;
@@ -949,7 +1039,6 @@
                                 QColor& backgroundColor )
 {
   // disable antialiasing
-  painter.save();
   painter.setRenderHint( QPainter::Antialiasing, false );
 
   // Handle printers separately.
@@ -996,7 +1085,7 @@
   }
 
   // restore antialiasing
-  painter.restore();
+  painter.setRenderHint( QPainter::Antialiasing, true );
 }
 
 
@@ -1008,10 +1097,9 @@
                                     QPen const & rightPen, QPen const & /*bottomPen*/,
                                     QPen const & leftPen, QPen const & topPen )
 {
-    Q_UNUSED(cellRef)
+    Q_UNUSED(cellRef);
 
     // disable antialiasing
-    painter.save();
     painter.setRenderHint( QPainter::Antialiasing, false );
 
     /*
@@ -1272,8 +1360,8 @@
     }
 #endif
 
-  // restore antialiasing
-    painter.restore();
+    // restore antialiasing
+    painter.setRenderHint( QPainter::Antialiasing, true );
 }
 
 
@@ -2197,18 +2285,26 @@
 void CellView::paintCellDiagonalLines( QPainter& painter, const QRectF &cellRect,
                                        const QPoint &cellRef )
 {
-  if ( cell()->isPartOfMerged() )
-    return;
+    if ( cell()->isPartOfMerged() )
+        return;
 
-  if ( cell()->effFallDiagonalPen( cellRef.x(), cellRef.y() ).style() != Qt::NoPen ) {
-    painter.setPen( cell()->effFallDiagonalPen( cellRef.x(), cellRef.y() ) );
-    painter.drawLine( QLineF( cellRect.x(), cellRect.y(), cellRect.right(), cellRect.bottom() ) );
-  }
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    QPen fallDiagonalPen( d->fallDiagonalPen );
+    QPen goUpDiagonalPen( d->goUpDiagonalPen );
+#else
+    QPen fallDiagonalPen( cell()->effFallDiagonalPen( cellRef.x(), cellRef.y() ) );
+    QPen goUpDiagonalPen( cell()->effGoUpDiagonalPen( cellRef.x(), cellRef.y() ) );
+#endif
 
-  if ( cell()->effGoUpDiagonalPen( cellRef.x(), cellRef.y() ).style() != Qt::NoPen ) {
-    painter.setPen( cell()->effGoUpDiagonalPen( cellRef.x(), cellRef.y() ) );
-    painter.drawLine( QLineF( cellRect.x(), cellRect.bottom(), cellRect.right(), cellRect.y() ) );
-  }
+    if ( fallDiagonalPen.style() != Qt::NoPen ) {
+        painter.setPen( fallDiagonalPen );
+        painter.drawLine( QLineF( cellRect.x(), cellRect.y(), cellRect.right(), cellRect.bottom() ) );
+    }
+
+    if ( goUpDiagonalPen.style() != Qt::NoPen ) {
+        painter.setPen( goUpDiagonalPen );
+        painter.drawLine( QLineF( cellRect.x(), cellRect.bottom(), cellRect.right(), cellRect.y() ) );
+    }
 }
 
 
--- trunk/koffice/kspread/CellView.h #594769:594770
@@ -40,6 +40,7 @@
 // KOffice
 #include <KoPoint.h>
 
+#define KSPREAD_CACHED_PAINTING_ATTRIBUTES
 #define KSPREAD_CELL_WINDOW
 
 class QRectF;
@@ -50,6 +51,11 @@
 class Sheet;
 class View;
 
+/**
+ * \class CellView
+ * The CellView class is responsible for the painting of the cell.
+ * For each visible Cell exists a CellView.
+ */
 class CellView
 {
 public:
@@ -74,6 +80,13 @@
      */
     Cell* cell() const;
 
+#ifdef KSPREAD_CACHED_PAINTING_ATTRIBUTES
+    /**
+     * Updates the cached painting attributes.
+     */
+    void update();
+#endif
+
   /**
    * \ingroup Painting
    * Paints the cell.
[prev in list] [next in list] [prev in thread] [next in thread] 

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