qwt_event_pattern.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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  d_mousePattern( MousePatternCount ),
21  d_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::MidButton );
63  }
64  }
65 
67  d_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
68 
70  d_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
71 
73  d_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
74 }
75 
82 {
83  d_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  d_mousePattern[ pattern ].button = button;
114  d_mousePattern[ pattern ].modifiers = modifiers;
115  }
116 }
117 
128  int key, Qt::KeyboardModifiers modifiers )
129 {
130  if ( pattern >= 0 && pattern < KeyPatternCount )
131  {
132  d_keyPattern[ pattern ].key = key;
133  d_keyPattern[ pattern ].modifiers = modifiers;
134  }
135 }
136 
138 void QwtEventPattern::setMousePattern( const QVector<MousePattern> &pattern )
139 {
140  d_mousePattern = pattern;
141 }
142 
144 void QwtEventPattern::setKeyPattern( const QVector<KeyPattern> &pattern )
145 {
146  d_keyPattern = pattern;
147 }
148 
150 const QVector<QwtEventPattern::MousePattern> &
152 {
153  return d_mousePattern;
154 }
155 
157 const QVector<QwtEventPattern::KeyPattern> &
159 {
160  return d_keyPattern;
161 }
162 
164 QVector<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern()
165 {
166  return d_mousePattern;
167 }
168 
170 QVector<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern()
171 {
172  return d_keyPattern;
173 }
174 
189  const QMouseEvent *event ) const
190 {
191  if ( code >= 0 && code < MousePatternCount )
192  return mouseMatch( d_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( d_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 }
A pattern for mouse events.
QVector< KeyPattern > d_keyPattern
QVector< MousePattern > d_mousePattern
Number of mouse patterns.
A pattern for key events.
KeyPatternCode
Symbolic keyboard input codes.
void initMousePattern(int numButtons)
bool mouseMatch(MousePatternCode, const QMouseEvent *) const
Compare a mouse event with an event pattern.
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
const QVector< KeyPattern > & keyPattern() const
MousePatternCode
Symbolic mouse input codes.
void setMousePattern(MousePatternCode, Qt::MouseButton button, Qt::KeyboardModifiers=Qt::NoModifier)
const QVector< MousePattern > & mousePattern() const
void setKeyPattern(KeyPatternCode, int keyCode, Qt::KeyboardModifiers modifierCodes=Qt::NoModifier)
virtual ~QwtEventPattern()
Destructor.


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17