qwt_event_pattern.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_event_pattern.h"
#include <qevent.h>
QwtEventPattern::QwtEventPattern()
: m_mousePattern( MousePatternCount )
, m_keyPattern( KeyPatternCount )
{
initKeyPattern();
initMousePattern( 3 );
}
QwtEventPattern::~QwtEventPattern()
{
}
void QwtEventPattern::initMousePattern( int numButtons )
{
m_mousePattern.resize( MousePatternCount );
switch ( numButtons )
{
case 1:
{
setMousePattern( MouseSelect1, Qt::LeftButton );
setMousePattern( MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
break;
}
case 2:
{
setMousePattern( MouseSelect1, Qt::LeftButton );
setMousePattern( MouseSelect2, Qt::RightButton );
setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
break;
}
default:
{
setMousePattern( MouseSelect1, Qt::LeftButton );
setMousePattern( MouseSelect2, Qt::RightButton );
setMousePattern( MouseSelect3, Qt::MiddleButton );
}
}
setMousePattern( MouseSelect4, m_mousePattern[MouseSelect1].button,
m_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
setMousePattern( MouseSelect5, m_mousePattern[MouseSelect2].button,
m_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
setMousePattern( MouseSelect6, m_mousePattern[MouseSelect3].button,
m_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
}
void QwtEventPattern::initKeyPattern()
{
m_keyPattern.resize( KeyPatternCount );
setKeyPattern( KeySelect1, Qt::Key_Return );
setKeyPattern( KeySelect2, Qt::Key_Space );
setKeyPattern( KeyAbort, Qt::Key_Escape );
setKeyPattern( KeyLeft, Qt::Key_Left );
setKeyPattern( KeyRight, Qt::Key_Right );
setKeyPattern( KeyUp, Qt::Key_Up );
setKeyPattern( KeyDown, Qt::Key_Down );
setKeyPattern( KeyRedo, Qt::Key_Plus );
setKeyPattern( KeyUndo, Qt::Key_Minus );
setKeyPattern( KeyHome, Qt::Key_Escape );
}
void QwtEventPattern::setMousePattern( MousePatternCode pattern,
Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
{
if ( pattern >= 0 && pattern < MousePatternCount )
{
m_mousePattern[ pattern ].button = button;
m_mousePattern[ pattern ].modifiers = modifiers;
}
}
void QwtEventPattern::setKeyPattern( KeyPatternCode pattern,
int key, Qt::KeyboardModifiers modifiers )
{
if ( pattern >= 0 && pattern < KeyPatternCount )
{
m_keyPattern[ pattern ].key = key;
m_keyPattern[ pattern ].modifiers = modifiers;
}
}
void QwtEventPattern::setMousePattern( const QVector< MousePattern >& pattern )
{
m_mousePattern = pattern;
}
void QwtEventPattern::setKeyPattern( const QVector< KeyPattern >& pattern )
{
m_keyPattern = pattern;
}
const QVector< QwtEventPattern::MousePattern >&
QwtEventPattern::mousePattern() const
{
return m_mousePattern;
}
const QVector< QwtEventPattern::KeyPattern >&
QwtEventPattern::keyPattern() const
{
return m_keyPattern;
}
QVector< QwtEventPattern::MousePattern >& QwtEventPattern::mousePattern()
{
return m_mousePattern;
}
QVector< QwtEventPattern::KeyPattern >& QwtEventPattern::keyPattern()
{
return m_keyPattern;
}
bool QwtEventPattern::mouseMatch( MousePatternCode code,
const QMouseEvent* event ) const
{
if ( code >= 0 && code < MousePatternCount )
return mouseMatch( m_mousePattern[ code ], event );
return false;
}
bool QwtEventPattern::mouseMatch( const MousePattern& pattern,
const QMouseEvent* event ) const
{
if ( event == NULL )
return false;
const MousePattern mousePattern( event->button(), event->modifiers() );
return mousePattern == pattern;
}
bool QwtEventPattern::keyMatch( KeyPatternCode code,
const QKeyEvent* event ) const
{
if ( code >= 0 && code < KeyPatternCount )
return keyMatch( m_keyPattern[ code ], event );
return false;
}
bool QwtEventPattern::keyMatch(
const KeyPattern& pattern, const QKeyEvent* event ) const
{
if ( event == NULL )
return false;
const KeyPattern keyPattern( event->key(), event->modifiers() );
return keyPattern == pattern;
}
QVector
Definition: qwt_clipper.h:23
QwtEventPattern::KeyPattern
A pattern for key events.
Definition: qwt_event_pattern.h:169
QwtEventPattern::MousePattern
A pattern for mouse events.
Definition: qwt_event_pattern.h:150
QwtEventPattern::setMousePattern
void setMousePattern(MousePatternCode, Qt::MouseButton button, Qt::KeyboardModifiers=Qt::NoModifier)
Definition: qwt_event_pattern.cpp:108
QwtEventPattern::QwtEventPattern
QwtEventPattern()
Definition: qwt_event_pattern.cpp:19
QwtEventPattern::mousePattern
const QVector< MousePattern > & mousePattern() const
Definition: qwt_event_pattern.cpp:151
QwtEventPattern::mouseMatch
bool mouseMatch(MousePatternCode, const QMouseEvent *) const
Compare a mouse event with an event pattern.
Definition: qwt_event_pattern.cpp:188
QwtEventPattern::~QwtEventPattern
virtual ~QwtEventPattern()
Destructor.
Definition: qwt_event_pattern.cpp:28
QwtEventPattern::keyPattern
const QVector< KeyPattern > & keyPattern() const
Definition: qwt_event_pattern.cpp:158
QwtEventPattern::keyMatch
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
Definition: qwt_event_pattern.cpp:234
QwtEventPattern::KeyPatternCode
KeyPatternCode
Symbolic keyboard input codes.
Definition: qwt_event_pattern.h:113
QwtEventPattern::KeyDown
@ KeyDown
Qt::Key_Down.
Definition: qwt_event_pattern.h:133
QwtEventPattern::KeyUp
@ KeyUp
Qt::Key_Up.
Definition: qwt_event_pattern.h:130
QwtEventPattern::KeyRedo
@ KeyRedo
Qt::Key_Plus.
Definition: qwt_event_pattern.h:136
QwtEventPattern::KeySelect1
@ KeySelect1
Qt::Key_Return.
Definition: qwt_event_pattern.h:115
QwtEventPattern::KeyHome
@ KeyHome
Qt::Key_Escape.
Definition: qwt_event_pattern.h:142
QwtEventPattern::KeyAbort
@ KeyAbort
Qt::Key_Escape.
Definition: qwt_event_pattern.h:121
QwtEventPattern::KeyRight
@ KeyRight
Qt::Key_Right.
Definition: qwt_event_pattern.h:127
QwtEventPattern::KeyUndo
@ KeyUndo
Qt::Key_Minus.
Definition: qwt_event_pattern.h:139
QwtEventPattern::KeyLeft
@ KeyLeft
Qt::Key_Left.
Definition: qwt_event_pattern.h:124
QwtEventPattern::KeyPatternCount
@ KeyPatternCount
Number of key patterns.
Definition: qwt_event_pattern.h:145
QwtEventPattern::KeySelect2
@ KeySelect2
Qt::Key_Space.
Definition: qwt_event_pattern.h:118
QwtEventPattern::initKeyPattern
void initKeyPattern()
Definition: qwt_event_pattern.cpp:81
QwtEventPattern::initMousePattern
void initMousePattern(int numButtons)
Definition: qwt_event_pattern.cpp:38
QwtEventPattern::MousePatternCode
MousePatternCode
Symbolic mouse input codes.
Definition: qwt_event_pattern.h:46
QwtEventPattern::MousePatternCount
@ MousePatternCount
Number of mouse patterns.
Definition: qwt_event_pattern.h:102
QwtEventPattern::MouseSelect1
@ MouseSelect1
Definition: qwt_event_pattern.h:54
QwtEventPattern::MouseSelect4
@ MouseSelect4
Definition: qwt_event_pattern.h:81
QwtEventPattern::MouseSelect3
@ MouseSelect3
Definition: qwt_event_pattern.h:72
QwtEventPattern::MouseSelect2
@ MouseSelect2
Definition: qwt_event_pattern.h:63
QwtEventPattern::MouseSelect5
@ MouseSelect5
Definition: qwt_event_pattern.h:90
QwtEventPattern::MouseSelect6
@ MouseSelect6
Definition: qwt_event_pattern.h:99
QwtEventPattern::setKeyPattern
void setKeyPattern(KeyPatternCode, int key, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
Definition: qwt_event_pattern.cpp:127