From 89f0eb01fbce99c3e950ee39c2306a59fb6ef5e8 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 18 Aug 2010 19:14:54 +0000 Subject: [PATCH] Factor out static methods for determining the event type and button when dealing with annotations Patch by Radu Voicilas svn path=/trunk/KDE/kdegraphics/okular/; revision=1165294 --- ui/annotationtools.cpp | 17 +++++++++++++++++ ui/annotationtools.h | 3 +++ ui/pageviewannotator.cpp | 19 +++++-------------- ui/presentationwidget.cpp | 19 ++++++------------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/ui/annotationtools.cpp b/ui/annotationtools.cpp index 4b5ef3bdf..cfa47b5b6 100644 --- a/ui/annotationtools.cpp +++ b/ui/annotationtools.cpp @@ -11,6 +11,7 @@ // qt / kde includes #include +#include #include // local includes @@ -29,6 +30,22 @@ AnnotatorEngine::AnnotatorEngine( const QDomElement & engineElement ) m_annotElement = annElement; } +void AnnotatorEngine::decodeEvent( const QMouseEvent * mouseEvent, EventType * eventType, Button * button ) +{ + *eventType = AnnotatorEngine::Press; + if ( mouseEvent->type() == QEvent::MouseMove ) + *eventType = AnnotatorEngine::Move; + else if ( mouseEvent->type() == QEvent::MouseButtonRelease ) + *eventType = AnnotatorEngine::Release; + + *button = AnnotatorEngine::None; + const Qt::MouseButtons buttonState = ( *eventType == AnnotatorEngine::Move ) ? mouseEvent->buttons() : mouseEvent->button(); + if ( buttonState == Qt::LeftButton ) + *button = AnnotatorEngine::Left; + else if ( buttonState == Qt::RightButton ) + *button = AnnotatorEngine::Right; +} + AnnotatorEngine::~AnnotatorEngine() { } diff --git a/ui/annotationtools.h b/ui/annotationtools.h index 27acea459..600de6c6d 100644 --- a/ui/annotationtools.h +++ b/ui/annotationtools.h @@ -16,6 +16,7 @@ #include "core/area.h" +class QMouseEvent; class QPainter; class PageViewItem; namespace Okular { @@ -47,6 +48,8 @@ class AnnotatorEngine void setItem( PageViewItem * item ) { m_item = item; } + static void decodeEvent( const QMouseEvent * mouseEvent, EventType * eventType, Button * button ); + protected: PageViewItem * item() { return m_item; } diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index c4d507b27..7edb0dc6a 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -711,20 +711,11 @@ QRect PageViewAnnotator::routeEvent( QMouseEvent * e, PageViewItem * item ) { if ( !item ) return QRect(); - // find out mouse event type - AnnotatorEngine::EventType eventType = AnnotatorEngine::Press; - if ( e->type() == QEvent::MouseMove ) - eventType = AnnotatorEngine::Move; - else if ( e->type() == QEvent::MouseButtonRelease ) - eventType = AnnotatorEngine::Release; - - // find out the pressed button - AnnotatorEngine::Button button = AnnotatorEngine::None; - Qt::MouseButtons buttonState = ( eventType == AnnotatorEngine::Move ) ? e->buttons() : e->button(); - if ( buttonState == Qt::LeftButton ) - button = AnnotatorEngine::Left; - else if ( buttonState == Qt::RightButton ) - button = AnnotatorEngine::Right; + AnnotatorEngine::EventType eventType; + AnnotatorEngine::Button button; + + // figure out the event type and button + AnnotatorEngine::decodeEvent( e, &eventType, &button ); // find out normalized mouse coords inside current item const QRect & itemRect = item->uncroppedGeometry(); diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index f818e5815..465f7b03b 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -1057,19 +1057,12 @@ QRect PresentationWidget::routeMouseDrawingEvent( QMouseEvent * e ) const QRect & geom = m_frames[ m_frameIndex ]->geometry; const Okular::Page * page = m_frames[ m_frameIndex ]->page; - AnnotatorEngine::EventType eventType = AnnotatorEngine::Press; - if ( e->type() == QEvent::MouseMove ) - eventType = AnnotatorEngine::Move; - else if ( e->type() == QEvent::MouseButtonRelease ) - eventType = AnnotatorEngine::Release; - - // find out the pressed button - AnnotatorEngine::Button button = AnnotatorEngine::None; - Qt::MouseButtons buttonState = ( eventType == AnnotatorEngine::Move ) ? e->buttons() : e->button(); - if ( buttonState == Qt::LeftButton ) - button = AnnotatorEngine::Left; - else if ( buttonState == Qt::RightButton ) - button = AnnotatorEngine::Right; + AnnotatorEngine::EventType eventType; + AnnotatorEngine::Button button; + + // figure out the event type and button + AnnotatorEngine::decodeEvent( e, &eventType, &button ); + static bool hasclicked = false; if ( eventType == AnnotatorEngine::Press ) hasclicked = true;