Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_event_pattern.h"
00011 #include <qevent.h>
00012
00019 QwtEventPattern::QwtEventPattern():
00020 d_mousePattern( MousePatternCount ),
00021 d_keyPattern( KeyPatternCount )
00022 {
00023 initKeyPattern();
00024 initMousePattern( 3 );
00025 }
00026
00028 QwtEventPattern::~QwtEventPattern()
00029 {
00030 }
00031
00038 void QwtEventPattern::initMousePattern( int numButtons )
00039 {
00040 d_mousePattern.resize( MousePatternCount );
00041
00042 switch ( numButtons )
00043 {
00044 case 1:
00045 {
00046 setMousePattern( MouseSelect1, Qt::LeftButton );
00047 setMousePattern( MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
00048 setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
00049 break;
00050 }
00051 case 2:
00052 {
00053 setMousePattern( MouseSelect1, Qt::LeftButton );
00054 setMousePattern( MouseSelect2, Qt::RightButton );
00055 setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
00056 break;
00057 }
00058 default:
00059 {
00060 setMousePattern( MouseSelect1, Qt::LeftButton );
00061 setMousePattern( MouseSelect2, Qt::RightButton );
00062 setMousePattern( MouseSelect3, Qt::MidButton );
00063 }
00064 }
00065
00066 setMousePattern( MouseSelect4, d_mousePattern[MouseSelect1].button,
00067 d_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
00068
00069 setMousePattern( MouseSelect5, d_mousePattern[MouseSelect2].button,
00070 d_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
00071
00072 setMousePattern( MouseSelect6, d_mousePattern[MouseSelect3].button,
00073 d_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
00074 }
00075
00081 void QwtEventPattern::initKeyPattern()
00082 {
00083 d_keyPattern.resize( KeyPatternCount );
00084
00085 setKeyPattern( KeySelect1, Qt::Key_Return );
00086 setKeyPattern( KeySelect2, Qt::Key_Space );
00087 setKeyPattern( KeyAbort, Qt::Key_Escape );
00088
00089 setKeyPattern( KeyLeft, Qt::Key_Left );
00090 setKeyPattern( KeyRight, Qt::Key_Right );
00091 setKeyPattern( KeyUp, Qt::Key_Up );
00092 setKeyPattern( KeyDown, Qt::Key_Down );
00093
00094 setKeyPattern( KeyRedo, Qt::Key_Plus );
00095 setKeyPattern( KeyUndo, Qt::Key_Minus );
00096 setKeyPattern( KeyHome, Qt::Key_Escape );
00097 }
00098
00108 void QwtEventPattern::setMousePattern( MousePatternCode pattern,
00109 Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
00110 {
00111 if ( pattern >= 0 && pattern < MousePatternCount )
00112 {
00113 d_mousePattern[ pattern ].button = button;
00114 d_mousePattern[ pattern ].modifiers = modifiers;
00115 }
00116 }
00117
00127 void QwtEventPattern::setKeyPattern( KeyPatternCode pattern,
00128 int key, Qt::KeyboardModifiers modifiers )
00129 {
00130 if ( pattern >= 0 && pattern < KeyPatternCount )
00131 {
00132 d_keyPattern[ pattern ].key = key;
00133 d_keyPattern[ pattern ].modifiers = modifiers;
00134 }
00135 }
00136
00138 void QwtEventPattern::setMousePattern( const QVector<MousePattern> &pattern )
00139 {
00140 d_mousePattern = pattern;
00141 }
00142
00144 void QwtEventPattern::setKeyPattern( const QVector<KeyPattern> &pattern )
00145 {
00146 d_keyPattern = pattern;
00147 }
00148
00150 const QVector<QwtEventPattern::MousePattern> &
00151 QwtEventPattern::mousePattern() const
00152 {
00153 return d_mousePattern;
00154 }
00155
00157 const QVector<QwtEventPattern::KeyPattern> &
00158 QwtEventPattern::keyPattern() const
00159 {
00160 return d_keyPattern;
00161 }
00162
00164 QVector<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern()
00165 {
00166 return d_mousePattern;
00167 }
00168
00170 QVector<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern()
00171 {
00172 return d_keyPattern;
00173 }
00174
00188 bool QwtEventPattern::mouseMatch( MousePatternCode code,
00189 const QMouseEvent *event ) const
00190 {
00191 if ( code >= 0 && code < MousePatternCount )
00192 return mouseMatch( d_mousePattern[ code ], event );
00193
00194 return false;
00195 }
00196
00211 bool QwtEventPattern::mouseMatch( const MousePattern &pattern,
00212 const QMouseEvent *event ) const
00213 {
00214 if ( event == NULL )
00215 return false;
00216
00217 const MousePattern mousePattern( event->button(), event->modifiers() );
00218 return mousePattern == pattern;
00219 }
00220
00234 bool QwtEventPattern::keyMatch( KeyPatternCode code,
00235 const QKeyEvent *event ) const
00236 {
00237 if ( code >= 0 && code < KeyPatternCount )
00238 return keyMatch( d_keyPattern[ code ], event );
00239
00240 return false;
00241 }
00242
00257 bool QwtEventPattern::keyMatch(
00258 const KeyPattern &pattern, const QKeyEvent *event ) const
00259 {
00260 if ( event == NULL )
00261 return false;
00262
00263 const KeyPattern keyPattern( event->key(), event->modifiers() );
00264 return keyPattern == pattern;
00265 }