Commit 19f22098 authored by Oliver Sander's avatar Oliver Sander

Mind the devicePixelRatio when drawing on-screen in presentation mode

Previously, when using a screen scaling factor larger than 1, the
drawings by mouse or stylus in presentation mode were slightly blocky.
The underlying cause was
a) a few integer types used for non-integer coordinates
b) the intermediate use of a QPixmap without the correct
   devicePixelRatio

Additionally, this patch uses a QPainterPath to draw the path,
rather than a sequence of individual lines.  This improves
the line quality a tiny bit, because the lines are properly
joined.

BUG: 384143

Differential Revision: https://phabricator.kde.org/D21836
parent 073f50ca
......@@ -170,16 +170,15 @@ void SmoothPath::paint( QPainter * painter, double xScale, double yScale ) const
painter->setPen( pen );
painter->setOpacity( opacity );
QPainterPath path;
QLinkedList<Okular::NormalizedPoint>::const_iterator pIt = points.begin(), pEnd = points.end();
Okular::NormalizedPoint pA = *pIt;
path.moveTo( QPointF( pIt->x * xScale, pIt->y * yScale ) );
++pIt;
for ( ; pIt != pEnd; ++pIt )
{
Okular::NormalizedPoint pB = *pIt;
painter->drawLine( (int)(pA.x * (double)xScale), (int)(pA.y * (double)yScale),
(int)(pB.x * (double)xScale), (int)(pB.y * (double)yScale) );
pA = pB;
path.lineTo( QPointF( pIt->x * xScale, pIt->y * yScale ) );
}
painter->drawPath(path);
}
}
......
......@@ -897,16 +897,21 @@ void PresentationWidget::paintEvent( QPaintEvent * pe )
const QRect & geom = m_frames[ m_frameIndex ]->geometry;
QPixmap pm( geom.size() );
const QSize pmSize( geom.width() * dpr, geom.height() * dpr );
QPixmap pm( pmSize );
pm.fill( Qt::transparent );
QPainter pmPainter( &pm );
pm.setDevicePixelRatio( dpr );
pmPainter.setRenderHints( QPainter::Antialiasing );
// Paint old paths
foreach ( const SmoothPath &drawing, m_frames[ m_frameIndex ]->drawings )
drawing.paint( &pmPainter, geom.width(), geom.height() );
drawing.paint( &pmPainter, pmSize.width(), pmSize.height() );
// Paint the path that is currently being drawn by the user
if ( m_drawingEngine && m_drawingRect.intersects( pe->rect() ) )
m_drawingEngine->paint( &pmPainter, geom.width(), geom.height(), m_drawingRect.intersected( pe->rect() ) );
m_drawingEngine->paint( &pmPainter, pmSize.width(), pmSize.height(), m_drawingRect.intersected( pe->rect() ) );
painter.setRenderHints( QPainter::Antialiasing );
painter.drawPixmap( geom.topLeft() , pm );
......@@ -1322,8 +1327,9 @@ QRect PresentationWidget::routeMouseDrawingEvent( QMouseEvent * e )
if ( eventType == AnnotatorEngine::Press )
hasclicked = true;
double nX = ( (double)e->x() - (double)geom.left() ) / (double)geom.width();
double nY = ( (double)e->y() - (double)geom.top() ) / (double)geom.height();
QPointF mousePos = e->localPos();
double nX = ( mousePos.x() - (double)geom.left() ) / (double)geom.width();
double nY = ( mousePos.y() - (double)geom.top() ) / (double)geom.height();
QRect ret;
bool isInside = nX >= 0 && nX < 1 && nY >= 0 && nY < 1;
......
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