Store and render presentation drawings at UI level instead of involving core.

This prevents spurious annotation warnings from being shown in
presentation mode.
BUG: 300938
This commit is contained in:
Fabio D'Urso 2012-06-07 15:48:53 +02:00
parent c8bc6dabeb
commit 3a383f64fd
4 changed files with 63 additions and 13 deletions

View file

@ -50,6 +50,10 @@ AnnotatorEngine::~AnnotatorEngine()
{
}
SmoothPath::SmoothPath( const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen )
: points ( points ), pen ( pen )
{
}
/** SmoothPathEngine */
SmoothPathEngine::SmoothPathEngine( const QDomElement & engineElement )
@ -112,12 +116,20 @@ QRect SmoothPathEngine::event( EventType type, Button button, double nX, double
}
void SmoothPathEngine::paint( QPainter * painter, double xScale, double yScale, const QRect & /*clipRect*/ )
{
// use engine's color for painting
const SmoothPath path( points, QPen(m_engineColor, 1) );
// draw the path
path.paint( painter, xScale, yScale );
}
void SmoothPath::paint( QPainter * painter, double xScale, double yScale ) const
{
// draw SmoothPaths with at least 2 points
if ( points.count() > 1 )
{
// use engine's color for painting
painter->setPen( QPen( m_engineColor, 1 ) );
painter->setPen( pen );
QLinkedList<Okular::NormalizedPoint>::const_iterator pIt = points.begin(), pEnd = points.end();
Okular::NormalizedPoint pA = *pIt;
@ -173,3 +185,17 @@ QList< Okular::Annotation* > SmoothPathEngine::end()
return QList< Okular::Annotation* >() << ann;
}
SmoothPath SmoothPathEngine::endSmoothPath()
{
m_creationCompleted = false;
double width = 1;
if ( m_annotElement.hasAttribute( "width" ) )
width = m_annotElement.attribute( "width" ).toDouble();
QColor color( m_annotElement.hasAttribute( "color" ) ?
m_annotElement.attribute( "color" ) : m_engineColor );
return SmoothPath( points, QPen(color, width) );
}

View file

@ -12,6 +12,7 @@
#include <qdom.h>
#include <qlinkedlist.h>
#include <qpen.h>
#include <qrect.h>
#include "core/area.h"
@ -64,6 +65,17 @@ class AnnotatorEngine
PageViewItem * m_item;
};
class SmoothPath
{
public:
SmoothPath( const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen );
void paint( QPainter * painter, double xScale, double yScale ) const;
private:
const QLinkedList<Okular::NormalizedPoint> points;
const QPen pen;
};
/** @short SmoothPathEngine */
class SmoothPathEngine
: public AnnotatorEngine
@ -75,7 +87,9 @@ class SmoothPathEngine
void paint( QPainter * painter, double xScale, double yScale, const QRect & /*clipRect*/ );
// These are two alternative ways to get the resulting path. Don't call them both!
QList< Okular::Annotation* > end();
SmoothPath endSmoothPath();
private:
// data

View file

@ -266,7 +266,6 @@ PresentationWidget::~PresentationWidget()
disconnect( drawingAct, 0, this, 0 );
if ( drawingAct->isChecked() )
drawingAct->toggle();
m_document->removePageAnnotations( m_document->viewport().pageNumber, m_currentPageDrawings );
delete m_drawingEngine;
// delete frames
@ -526,15 +525,17 @@ void PresentationWidget::mouseReleaseEvent( QMouseEvent * e )
(void)r;
if ( m_drawingEngine->creationCompleted() )
{
QList< Okular::Annotation * > annots = m_drawingEngine->end();
// add drawing to current page
m_currentPageDrawings << m_drawingEngine->endSmoothPath();
// manually disable and re-enable the pencil mode, so we can do
// cleaning of the actual drawer and create a new one just after
// that - that gives continuous drawing
togglePencilMode( false );
togglePencilMode( true );
foreach( Okular::Annotation * ann, annots )
m_document->addPageAnnotation( m_frameIndex, ann );
m_currentPageDrawings << annots;
// schedule repaint
update();
}
return;
}
@ -660,12 +661,21 @@ void PresentationWidget::paintEvent( QPaintEvent * pe )
// copy the rendered pixmap to the screen
painter.drawPixmap( r.topLeft(), m_lastRenderedPixmap, r );
}
if ( m_drawingEngine && m_drawingRect.intersects( pe->rect() ) )
// paint drawings
if ( m_frameIndex != -1 )
{
const QRect & geom = m_frames[ m_frameIndex ]->geometry;
painter.save();
painter.translate( geom.topLeft() );
m_drawingEngine->paint( &painter, geom.width(), geom.height(), m_drawingRect.intersect( pe->rect() ) );
painter.setRenderHints( QPainter::Antialiasing );
foreach ( const SmoothPath &drawing, m_currentPageDrawings )
drawing.paint( &painter, geom.width(), geom.height() );
if ( m_drawingEngine && m_drawingRect.intersects( pe->rect() ) )
m_drawingEngine->paint( &painter, geom.width(), geom.height(), m_drawingRect.intersect( pe->rect() ) );
painter.restore();
}
painter.end();
@ -1356,8 +1366,8 @@ void PresentationWidget::togglePencilMode( bool on )
void PresentationWidget::clearDrawings()
{
m_document->removePageAnnotations( m_frameIndex, m_currentPageDrawings );
m_currentPageDrawings.clear();
update();
}
void PresentationWidget::screenResized( int screen )

View file

@ -14,6 +14,7 @@
#include <qpixmap.h>
#include <qstringlist.h>
#include <qwidget.h>
#include "ui/annotationtools.h"
#include "core/area.h"
#include "core/observer.h"
#include "core/pagetransition.h"
@ -23,7 +24,6 @@ class QToolBar;
class QTimer;
class KActionCollection;
class KSelectAction;
class AnnotatorEngine;
struct PresentationFrame;
class PresentationSearchBar;
@ -104,8 +104,8 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver
QRect m_overlayGeometry;
const Okular::Action * m_pressedLink;
bool m_handCursor;
QList< Okular::Annotation * > m_currentPageDrawings;
AnnotatorEngine * m_drawingEngine;
QLinkedList< SmoothPath > m_currentPageDrawings;
SmoothPathEngine * m_drawingEngine;
QRect m_drawingRect;
int m_screen;
int m_screenInhibitCookie;