[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-12-15 14:29:35
Message-ID: 1166192975.317763.10803.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 613874 by nikolaus:
Painting Fix the scrolling of right-to-left sheets.
The scroll offset is document dependent for a while: no need to
handle it different for the two layout directions, but the
horizontal scrollbar value has to.
M +24 -58 Canvas.cpp
M +1 -1 Canvas.h
M +4 -21 CellView.cpp
M +28 -7 SheetView.cpp
--- trunk/koffice/kspread/Canvas.cpp #613873:613874
@@ -535,42 +535,12 @@
// xpos is the position of the cell in the current window in unzoomed
// document coordinates.
- double xpos;
- if ( sheet->layoutDirection()==Sheet::LeftToRight )
- xpos = sheet->dblColumnPos( location.x() ) - xOffset();
- else
- xpos = unzoomedWidth - sheet->dblColumnPos( location.x() ) + xOffset();
+ double xpos = sheet->dblColumnPos( location.x() ) - xOffset();
double ypos = sheet->dblRowPos( location.y() ) - yOffset();
double minY = 40.0;
double maxY = unzoomedHeight - 40.0;
- if ( sheet->layoutDirection()==Sheet::RightToLeft ) {
- // Right to left sheet.
-
- double minX = unzoomedWidth - 100.0; // less than that, we scroll
- double maxX = 100.0; // more than that, we scroll
-
- // kDebug(36005) << "rtl2: XPos: " << xpos << ", min: " << minX << ", maxX: " << \
maxX << ", Offset: " << xOffset() << endl;
-
- // Do we need to scroll left?
- if ( xpos > minX )
- horzScrollBar()->setValue( (int) (horzScrollBar()->maximum() - xOffset() - \
xpos + minX ) );
-
- // Do we need to scroll right?
- else if ( xpos < maxX )
- {
- double horzScrollBarValue = xOffset() - xpos + maxX;
- double horzScrollBarValueMax = sheet->sizeMaxX() - unzoomedWidth;
-
- //We don't want to display any area > KS_colMax widths
- if ( horzScrollBarValue > horzScrollBarValueMax )
- horzScrollBarValue = horzScrollBarValueMax;
-
- horzScrollBar()->setValue( (int) (horzScrollBar()->maximum() - \
horzScrollBarValue ) );
- }
- }
- else {
// Left to right sheet.
double minX = 100.0; // less than that, we scroll
@@ -578,7 +548,12 @@
// Do we need to scroll left?
if ( xpos < minX )
- horzScrollBar()->setValue( (int) (xOffset() + xpos - minX ) );
+ {
+ if ( sheet->layoutDirection() == Sheet::LeftToRight )
+ horzScrollBar()->setValue( (int) (xOffset() + xpos - minX ) );
+ else
+ horzScrollBar()->setValue( (int) ( horzScrollBar()->maximum() - \
(xOffset() + xpos - minX ) ) ); + }
// Do we need to scroll right?
else if ( xpos > maxX )
@@ -590,9 +565,11 @@
if ( horzScrollBarValue > horzScrollBarValueMax )
horzScrollBarValue = horzScrollBarValueMax;
- horzScrollBar()->setValue( (int) horzScrollBarValue );
+ if ( sheet->layoutDirection() == Sheet::LeftToRight )
+ horzScrollBar()->setValue( (int) horzScrollBarValue );
+ else
+ horzScrollBar()->setValue( (int) ( horzScrollBar()->maximum() - \
horzScrollBarValue ) ); }
- }
#if 0
kDebug(36005) << "------------------------------------------------" << endl;
@@ -634,7 +611,7 @@
kDebug(36005) << "slotScrollHorz: value = " << _value << endl;
//kDebug(36005) << kBacktrace() << endl;
- if ( sheet->layoutDirection()==Sheet::RightToLeft )
+ if ( sheet->layoutDirection() == Sheet::RightToLeft )
_value = horzScrollBar()->maximum() - _value;
if ( _value < 0.0 ) {
@@ -653,8 +630,6 @@
// Relative movement
// NOTE Stefan: Always scroll by whole pixels, otherwise we'll get offsets.
int dx = qRound( d->view->doc()->zoomItX( d->xOffset - _value ) );
- if ( sheet->layoutDirection()==Sheet::RightToLeft )
- dx = -dx;
scroll( dx, 0 );
hBorderWidget()->scroll( dx, 0 );
@@ -1510,7 +1485,7 @@
QPainter painter(this);
painter.setClipRegion( event->region() );
- paintUpdates( painter, event->rect() );
+ paintUpdates( painter );
event->accept();
}
@@ -1750,19 +1725,8 @@
double ev_Width = d->view->doc()->unzoomItX( _ev->size().width() );
double ev_Height = d->view->doc()->unzoomItY( _ev->size().height() );
- // workaround to allow horizontal resizing and zoom changing when sheet
- // direction and interface direction don't match (e.g. an RTL sheet on an
- // LTR interface)
- if ( sheet->layoutDirection()==Sheet::RightToLeft && \
!QApplication::isRightToLeft() )
- {
- int dx = _ev->size().width() - _ev->oldSize().width();
- scroll(dx, 0);
- }
- else if ( sheet->layoutDirection()==Sheet::LeftToRight && \
QApplication::isRightToLeft() )
- {
- int dx = _ev->size().width() - _ev->oldSize().width();
- scroll(-dx, 0);
- }
+ int dx = _ev->size().width() - _ev->oldSize().width();
+ scroll(-dx, 0);
// If we rise horizontally, then check if we are still within the valid area \
(KS_colMax) if ( _ev->size().width() > _ev->oldSize().width() )
@@ -3691,7 +3655,7 @@
QRect Canvas::visibleCells() const
{
- return viewToCellCoordinates( QRectF( 0, 0, width(), height() ) );
+ return viewToCellCoordinates( rect() );
}
//---------------------------------------------
@@ -3700,7 +3664,7 @@
//
//---------------------------------------------
-void Canvas::paintUpdates( QPainter& painter, const QRectF& paintRect )
+void Canvas::paintUpdates( QPainter& painter )
{
register Sheet * const sheet = activeSheet();
if (!sheet)
@@ -3725,8 +3689,8 @@
painter.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing );
painter.scale( d->view->doc()->zoomedResolutionX(), \
d->view->doc()->zoomedResolutionY() );
- QRectF unzoomedRect = d->view->doc()->viewToDocument( paintRect );
- // unzoomedRect.translate( xOffset(), yOffset() );
+ QRectF paintRect = d->view->doc()->viewToDocument( rect() );
+// paintRect.translate( -xOffset(), -yOffset() );
#if 0
kDebug(36004)
@@ -3737,16 +3701,18 @@
/* paint any visible cell that has the paintDirty flag */
const QRect visibleRect = visibleCells();
+// kDebug() << "visibleCells: " << visibleRect << endl;
+// kDebug() << "offset: " << xOffset() << ", " << yOffset() << endl;
const QPointF topLeft( sheet->dblColumnPos(visibleRect.left()) - xOffset(),
sheet->dblRowPos(visibleRect.top()) - yOffset() );
view()->sheetView( sheet )->setPaintCellRange( visibleRect );
- view()->sheetView( sheet )->paintCells( d->view, painter, unzoomedRect, topLeft \
); + view()->sheetView( sheet )->paintCells( d->view, painter, paintRect, topLeft \
);
/* now paint the selection */
//Nb. No longer necessary to paint choose Selection.here as the cell reference \
highlight //stuff takes care of this anyway
- paintHighlightedRanges(painter, unzoomedRect);
- paintNormalMarker(painter, unzoomedRect);
+ paintHighlightedRanges(painter, paintRect);
+ paintNormalMarker(painter, paintRect);
//restore clip region with children area
// painter.restore();
--- trunk/koffice/kspread/Canvas.h #613873:613874
@@ -217,7 +217,7 @@
* Paints all visible cells that have a paint dirty flag set.
* @see paintEvent()
*/
- void paintUpdates( QPainter& painter, const QRectF& paintRect );
+ void paintUpdates( QPainter& painter );
/**
--- trunk/koffice/kspread/CellView.cpp #613873:613874
@@ -254,32 +254,12 @@
Q_ASSERT(cell->isDefault()
|| (((cellRef.x() == cell->column()) && (cellRef.y() == cell->row()))));
- double left = coordinate.x();
-
- // Handle right-to-left layout.
- // In an RTL sheet the cells have to be painted at their opposite horizontal
- // location on the canvas, meaning that column A will be the rightmost column
- // on screen, column B will be to the left of it and so on. Here we change
- // the horizontal coordinate at which we start painting the cell in case the
- // sheet's direction is RTL. We do this only if paintingObscured is 0,
- // otherwise the cell's painting location will flip back and forth in
- // consecutive calls to paintCell when painting obscured cells.
- if ( d->layoutDirection == Sheet::RightToLeft && paintingObscured == 0
- && view && view->canvasWidget() )
- {
- double dwidth = view->doc()->unzoomItXOld(view->canvasWidget()->width());
- left = dwidth - coordinate.x() - d->width;
- }
-
// See if this cell is merged or has overflown into neighbor cells.
// In that case, the width/height is greater than just the cell
// itself.
if (cell->d->hasExtra()) {
if (cell->mergedXCells() > 0 || cell->mergedYCells() > 0) {
// merged cell extends to the left if sheet is RTL
- if ( d->layoutDirection == Sheet::RightToLeft ) {
- left -= cell->extraWidth() - d->width;
- }
d->width += cell->extraWidth();
d->height += cell->extraHeight();
}
@@ -325,7 +305,10 @@
// If the rect of this cell doesn't intersect the rect that should
// be painted, we can skip the rest and return. (Note that we need
// to calculate `left' first before we can do this.)
- const QRectF cellRect( left, coordinate.y(), d->width, d->height );
+ const QRectF cellRect( d->layoutDirection == Sheet::RightToLeft
+ ? coordinate.x() - cell->extraWidth() - d->width
+ : coordinate.x(),
+ coordinate.y(), d->width, d->height );
if ( !cellRect.intersects( rect ) ) {
cell->clearFlag( Cell::Flag_PaintingCell );
return;
--- trunk/koffice/kspread/SheetView.cpp #613873:613874
@@ -92,12 +92,26 @@
void SheetView::paintCells( View* view, QPainter& painter, const QRectF& paintRect, \
const QPointF& topLeft ) {
QLinkedList<QPoint> mergedCellsPainted;
+// kDebug() << "paintRect: " << paintRect << endl;
+// kDebug() << "topLeft: " << topLeft << endl;
+ // 1. Paint the cell content, background, ... (except borders)
- // 1. Paint the cell content, background, ... (except borders)
- QPointF dblCorner( topLeft.x(), topLeft.y() );
+ // Handle right-to-left layout.
+ // In an RTL sheet the cells have to be painted at their opposite horizontal
+ // location on the canvas, meaning that column A will be the rightmost column
+ // on screen, column B will be to the left of it and so on. Here we change
+ // the horizontal coordinate at which we start painting the cell in case the
+ // sheet's direction is RTL. We do this only if paintingObscured is 0,
+ // otherwise the cell's painting location will flip back and forth in
+ // consecutive calls to paintCell when painting obscured cells.
+ const bool rightToLeft = sheet()->layoutDirection() == Sheet::RightToLeft;
+ QPointF dblCorner( rightToLeft ? paintRect.width() - topLeft.x() : topLeft.x(), \
topLeft.y() ); int right = d->visibleRect.right();
for ( int col = d->visibleRect.left(); col <= right; ++col )
{
+ if ( rightToLeft )
+ dblCorner.setX( dblCorner.x() - d->sheet->columnFormat( col \
)->dblWidth() ); +// kDebug() << "dblCorner: " << dblCorner << endl;
int bottom = d->visibleRect.bottom();
for ( int row = d->visibleRect.top(); row <= bottom; ++row )
{
@@ -108,14 +122,17 @@
dblCorner.setY( dblCorner.y() + d->sheet->rowFormat( row )->dblHeight() \
); }
dblCorner.setY( topLeft.y() );
- dblCorner.setX( dblCorner.x() + d->sheet->columnFormat( col )->dblWidth() );
+ if ( !rightToLeft )
+ dblCorner.setX( dblCorner.x() + d->sheet->columnFormat( col \
)->dblWidth() ); }
// 2. Paint the default borders
- dblCorner = QPointF( topLeft.x(), topLeft.y() );
+ dblCorner = QPointF( rightToLeft ? paintRect.width() - topLeft.x() : \
topLeft.x(), topLeft.y() ); right = d->visibleRect.right();
for ( int col = d->visibleRect.left(); col <= right; ++col )
{
+ if ( rightToLeft )
+ dblCorner.setX( dblCorner.x() - d->sheet->columnFormat( col \
)->dblWidth() ); int bottom = d->visibleRect.bottom();
for ( int row = d->visibleRect.top(); row <= bottom; ++row )
{
@@ -129,14 +146,17 @@
dblCorner.setY( dblCorner.y() + d->sheet->rowFormat( row )->dblHeight() \
); }
dblCorner.setY( topLeft.y() );
- dblCorner.setX( dblCorner.x() + d->sheet->columnFormat( col )->dblWidth() );
+ if ( !rightToLeft )
+ dblCorner.setX( dblCorner.x() + d->sheet->columnFormat( col \
)->dblWidth() ); }
// 3. Paint the custom borders, diagonal lines and page borders
- dblCorner = QPointF( topLeft.x(), topLeft.y() );
+ dblCorner = QPointF( rightToLeft ? paintRect.width() - topLeft.x() : \
topLeft.x(), topLeft.y() ); right = d->visibleRect.right();
for ( int col = d->visibleRect.left(); col <= right; ++col )
{
+ if ( rightToLeft )
+ dblCorner.setX( dblCorner.x() - d->sheet->columnFormat( col \
)->dblWidth() ); int bottom = d->visibleRect.bottom();
for ( int row = d->visibleRect.top(); row <= bottom; ++row )
{
@@ -147,7 +167,8 @@
dblCorner.setY( dblCorner.y() + d->sheet->rowFormat( row )->dblHeight() \
); }
dblCorner.setY( topLeft.y() );
- dblCorner.setX( dblCorner.x() + d->sheet->columnFormat( col )->dblWidth() );
+ if ( !rightToLeft )
+ dblCorner.setX( dblCorner.x() + d->sheet->columnFormat( col \
)->dblWidth() ); }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic