mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
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
This commit is contained in:
parent
c20db0e025
commit
89f0eb01fb
|
@ -11,6 +11,7 @@
|
|||
|
||||
// qt / kde includes
|
||||
#include <qcolor.h>
|
||||
#include <qevent.h>
|
||||
#include <qpainter.h>
|
||||
|
||||
// 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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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;
|
||||
AnnotatorEngine::EventType eventType;
|
||||
AnnotatorEngine::Button button;
|
||||
|
||||
// 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;
|
||||
// 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();
|
||||
|
|
|
@ -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;
|
||||
AnnotatorEngine::EventType eventType;
|
||||
AnnotatorEngine::Button button;
|
||||
|
||||
// figure out the event type and button
|
||||
AnnotatorEngine::decodeEvent( e, &eventType, &button );
|
||||
|
||||
// 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;
|
||||
static bool hasclicked = false;
|
||||
if ( eventType == AnnotatorEngine::Press )
|
||||
hasclicked = true;
|
||||
|
|
Loading…
Reference in a new issue