qwt_event_pattern.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_event_pattern.h"
11 #include <qevent.h>
12 
20  : m_mousePattern( MousePatternCount )
21  , m_keyPattern( KeyPatternCount )
22 {
24  initMousePattern( 3 );
25 }
26 
29 {
30 }
31 
38 void QwtEventPattern::initMousePattern( int numButtons )
39 {
41 
42  switch ( numButtons )
43  {
44  case 1:
45  {
46  setMousePattern( MouseSelect1, Qt::LeftButton );
47  setMousePattern( MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
48  setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
49  break;
50  }
51  case 2:
52  {
53  setMousePattern( MouseSelect1, Qt::LeftButton );
54  setMousePattern( MouseSelect2, Qt::RightButton );
55  setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
56  break;
57  }
58  default:
59  {
60  setMousePattern( MouseSelect1, Qt::LeftButton );
61  setMousePattern( MouseSelect2, Qt::RightButton );
62  setMousePattern( MouseSelect3, Qt::MiddleButton );
63  }
64  }
65 
67  m_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
68 
70  m_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
71 
73  m_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
74 }
75 
82 {
83  m_keyPattern.resize( KeyPatternCount );
84 
85  setKeyPattern( KeySelect1, Qt::Key_Return );
86  setKeyPattern( KeySelect2, Qt::Key_Space );
87  setKeyPattern( KeyAbort, Qt::Key_Escape );
88 
89  setKeyPattern( KeyLeft, Qt::Key_Left );
90  setKeyPattern( KeyRight, Qt::Key_Right );
91  setKeyPattern( KeyUp, Qt::Key_Up );
92  setKeyPattern( KeyDown, Qt::Key_Down );
93 
94  setKeyPattern( KeyRedo, Qt::Key_Plus );
95  setKeyPattern( KeyUndo, Qt::Key_Minus );
96  setKeyPattern( KeyHome, Qt::Key_Escape );
97 }
98 
109  Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
110 {
111  if ( pattern >= 0 && pattern < MousePatternCount )
112  {
113  m_mousePattern[ pattern ].button = button;
114  m_mousePattern[ pattern ].modifiers = modifiers;
115  }
116 }
117 
128  int key, Qt::KeyboardModifiers modifiers )
129 {
130  if ( pattern >= 0 && pattern < KeyPatternCount )
131  {
132  m_keyPattern[ pattern ].key = key;
133  m_keyPattern[ pattern ].modifiers = modifiers;
134  }
135 }
136 
139 {
140  m_mousePattern = pattern;
141 }
142 
145 {
146  m_keyPattern = pattern;
147 }
148 
152 {
153  return m_mousePattern;
154 }
155 
159 {
160  return m_keyPattern;
161 }
162 
165 {
166  return m_mousePattern;
167 }
168 
171 {
172  return m_keyPattern;
173 }
174 
189  const QMouseEvent* event ) const
190 {
191  if ( code >= 0 && code < MousePatternCount )
192  return mouseMatch( m_mousePattern[ code ], event );
193 
194  return false;
195 }
196 
212  const QMouseEvent* event ) const
213 {
214  if ( event == NULL )
215  return false;
216 
217  const MousePattern mousePattern( event->button(), event->modifiers() );
218  return mousePattern == pattern;
219 }
220 
235  const QKeyEvent* event ) const
236 {
237  if ( code >= 0 && code < KeyPatternCount )
238  return keyMatch( m_keyPattern[ code ], event );
239 
240  return false;
241 }
242 
258  const KeyPattern& pattern, const QKeyEvent* event ) const
259 {
260  if ( event == NULL )
261  return false;
262 
263  const KeyPattern keyPattern( event->key(), event->modifiers() );
264  return keyPattern == pattern;
265 }
QwtEventPattern::KeySelect2
@ KeySelect2
Qt::Key_Space.
Definition: qwt_event_pattern.h:118
QwtEventPattern::MouseSelect5
@ MouseSelect5
Definition: qwt_event_pattern.h:90
QwtEventPattern::m_mousePattern
QVector< MousePattern > m_mousePattern
Definition: qwt_event_pattern.h:220
QwtEventPattern::MouseSelect6
@ MouseSelect6
Definition: qwt_event_pattern.h:99
QwtEventPattern::keyMatch
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
Definition: qwt_event_pattern.cpp:234
QwtEventPattern::mousePattern
const QVector< MousePattern > & mousePattern() const
Definition: qwt_event_pattern.cpp:151
QwtEventPattern::setMousePattern
void setMousePattern(MousePatternCode, Qt::MouseButton button, Qt::KeyboardModifiers=Qt::NoModifier)
Definition: qwt_event_pattern.cpp:108
QwtEventPattern::KeyRedo
@ KeyRedo
Qt::Key_Plus.
Definition: qwt_event_pattern.h:136
QVector
Definition: qwt_clipper.h:23
QwtEventPattern::setKeyPattern
void setKeyPattern(KeyPatternCode, int key, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
Definition: qwt_event_pattern.cpp:127
QwtEventPattern::~QwtEventPattern
virtual ~QwtEventPattern()
Destructor.
Definition: qwt_event_pattern.cpp:28
QwtEventPattern::m_keyPattern
QVector< KeyPattern > m_keyPattern
Definition: qwt_event_pattern.h:221
QwtEventPattern::QwtEventPattern
QwtEventPattern()
Definition: qwt_event_pattern.cpp:19
QwtEventPattern::KeyDown
@ KeyDown
Qt::Key_Down.
Definition: qwt_event_pattern.h:133
QwtEventPattern::MouseSelect1
@ MouseSelect1
Definition: qwt_event_pattern.h:54
QwtEventPattern::mouseMatch
bool mouseMatch(MousePatternCode, const QMouseEvent *) const
Compare a mouse event with an event pattern.
Definition: qwt_event_pattern.cpp:188
QwtEventPattern::MousePatternCode
MousePatternCode
Symbolic mouse input codes.
Definition: qwt_event_pattern.h:45
QwtEventPattern::initKeyPattern
void initKeyPattern()
Definition: qwt_event_pattern.cpp:81
QwtEventPattern::KeyRight
@ KeyRight
Qt::Key_Right.
Definition: qwt_event_pattern.h:127
QwtEventPattern::MousePatternCount
@ MousePatternCount
Number of mouse patterns.
Definition: qwt_event_pattern.h:102
QwtEventPattern::KeyAbort
@ KeyAbort
Qt::Key_Escape.
Definition: qwt_event_pattern.h:121
QwtEventPattern::KeyHome
@ KeyHome
Qt::Key_Escape.
Definition: qwt_event_pattern.h:142
QwtEventPattern::MouseSelect2
@ MouseSelect2
Definition: qwt_event_pattern.h:63
QwtEventPattern::KeyPatternCount
@ KeyPatternCount
Number of key patterns.
Definition: qwt_event_pattern.h:145
qwt_event_pattern.h
QwtEventPattern::KeyPattern
A pattern for key events.
Definition: qwt_event_pattern.h:168
QwtEventPattern::MouseSelect3
@ MouseSelect3
Definition: qwt_event_pattern.h:72
QwtEventPattern::MouseSelect4
@ MouseSelect4
Definition: qwt_event_pattern.h:81
QwtEventPattern::keyPattern
const QVector< KeyPattern > & keyPattern() const
Definition: qwt_event_pattern.cpp:158
QwtEventPattern::KeyPatternCode
KeyPatternCode
Symbolic keyboard input codes.
Definition: qwt_event_pattern.h:112
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::initMousePattern
void initMousePattern(int numButtons)
Definition: qwt_event_pattern.cpp:38
QwtEventPattern::KeyUp
@ KeyUp
Qt::Key_Up.
Definition: qwt_event_pattern.h:130
QwtEventPattern::KeySelect1
@ KeySelect1
Qt::Key_Return.
Definition: qwt_event_pattern.h:115
QwtEventPattern::MousePattern
A pattern for mouse events.
Definition: qwt_event_pattern.h:149


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45