Commit 8e1d9aa4 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid

Fix page boundary gradients on scaled displays

The code that draws a thin gradient at the right and bottom
boundaries of a page implicitly assumed that the display was
not scaled, i.e., that logical pixel where identical to
physical pixels.  Nobody really noticed because that gradient
was so thin.  Anyway, this patch fixes the gradient for
scaled displays.

I considered using a QLinearGradient, but decided against it:
The code would have been longer, and the manual code in the
patch can exploit the fact that all lines are horizontal
or vertical.  Therefore, expensive scan-conversion can be
avoided.
parent a0bd9c4d
...@@ -3549,6 +3549,15 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p ) ...@@ -3549,6 +3549,15 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p )
QRect checkRect = contentsRect; QRect checkRect = contentsRect;
checkRect.adjust( -3, -3, 1, 1 ); checkRect.adjust( -3, -3, 1, 1 );
// Method to linearly interpolate between black (=(0,0,0), omitted) and the background color
auto interpolateColor = [&backColor]( double t )
{
return QColor( t*backColor.red(), t*backColor.green(), t*backColor.blue() );
};
// width of the shadow in device pixels
static const int shadowWidth = 2*dpr;
// iterate over all items painting a black outline and a simple bottom/right gradient // iterate over all items painting a black outline and a simple bottom/right gradient
for ( const PageViewItem * item : qAsConst( d->items ) ) for ( const PageViewItem * item : qAsConst( d->items ) )
{ {
...@@ -3563,7 +3572,7 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p ) ...@@ -3563,7 +3572,7 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p )
p->save(); p->save();
p->translate( itemGeometry.left(), itemGeometry.top() ); p->translate( itemGeometry.left(), itemGeometry.top() );
// draw the page outline (black border and 2px bottom-right shadow) // draw the page outline (black border and bottom-right shadow)
if ( !itemGeometry.contains( contentsRect ) ) if ( !itemGeometry.contains( contentsRect ) )
{ {
int itemWidth = itemGeometry.width(); int itemWidth = itemGeometry.width();
...@@ -3577,15 +3586,15 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p ) ...@@ -3577,15 +3586,15 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p )
p->drawRect( outline ); p->drawRect( outline );
// draw bottom/right gradient // draw bottom/right gradient
static const int levels = 2; for ( int i = 1; i <= shadowWidth; i++ )
int r = backColor.red() / (levels + 2) + 6,
g = backColor.green() / (levels + 2) + 6,
b = backColor.blue() / (levels + 2) + 6;
for ( int i = 0; i < levels; i++ )
{ {
p->setPen( QColor( r * (i+2), g * (i+2), b * (i+2) ) ); pen.setColor( interpolateColor( double(i)/( shadowWidth+1 ) ) );
p->drawLine( i, i + itemHeight + 1, i + itemWidth + 1, i + itemHeight + 1 ); p->setPen( pen );
p->drawLine( i + itemWidth + 1, i, i + itemWidth + 1, i + itemHeight ); QPointF left( (i-1)/dpr, itemHeight + i/dpr );
QPointF up( itemWidth + i/dpr, (i-1)/dpr );
QPointF corner( itemWidth + i/dpr, itemHeight + i/dpr);
p->drawLine( left, corner );
p->drawLine( up, corner );
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment