From 3a383f64fd569a863c43de63ee000a353f8c7d3b Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Thu, 7 Jun 2012 15:48:53 +0200 Subject: [PATCH] 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 --- ui/annotationtools.cpp | 30 ++++++++++++++++++++++++++++-- ui/annotationtools.h | 14 ++++++++++++++ ui/presentationwidget.cpp | 26 ++++++++++++++++++-------- ui/presentationwidget.h | 6 +++--- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/ui/annotationtools.cpp b/ui/annotationtools.cpp index cfa47b5b6..40fa6fe6b 100644 --- a/ui/annotationtools.cpp +++ b/ui/annotationtools.cpp @@ -50,6 +50,10 @@ AnnotatorEngine::~AnnotatorEngine() { } +SmoothPath::SmoothPath( const QLinkedList &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::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) ); +} + diff --git a/ui/annotationtools.h b/ui/annotationtools.h index 600de6c6d..7107042e0 100644 --- a/ui/annotationtools.h +++ b/ui/annotationtools.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "core/area.h" @@ -64,6 +65,17 @@ class AnnotatorEngine PageViewItem * m_item; }; +class SmoothPath +{ + public: + SmoothPath( const QLinkedList &points, const QPen &pen ); + void paint( QPainter * painter, double xScale, double yScale ) const; + + private: + const QLinkedList 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 diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index 61d2b7f57..e9fb74260 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -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 ) diff --git a/ui/presentationwidget.h b/ui/presentationwidget.h index 126985eb5..20dbcbb8a 100644 --- a/ui/presentationwidget.h +++ b/ui/presentationwidget.h @@ -14,6 +14,7 @@ #include #include #include +#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;