source: ntrip/trunk/BNC/qwt/qwt_event_pattern.cpp@ 10541

Last change on this file since 10541 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 6.6 KB
RevLine 
[4271]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
13/*!
14 Constructor
15
16 \sa MousePatternCode, KeyPatternCode
17*/
18
19QwtEventPattern::QwtEventPattern():
20 d_mousePattern( MousePatternCount ),
21 d_keyPattern( KeyPatternCount )
22{
23 initKeyPattern();
24 initMousePattern( 3 );
25}
26
27//! Destructor
28QwtEventPattern::~QwtEventPattern()
29{
30}
31
32/*!
33 Set default mouse patterns, depending on the number of mouse buttons
34
35 \param numButtons Number of mouse buttons ( <= 3 )
36 \sa MousePatternCode
37*/
38void QwtEventPattern::initMousePattern( int numButtons )
39{
40 d_mousePattern.resize( MousePatternCount );
41
42 switch ( numButtons )
43 {
44 case 1:
45 {
46 setMousePattern( MouseSelect1, Qt::LeftButton );
[8127]47 setMousePattern( MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
48 setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
[4271]49 break;
50 }
51 case 2:
52 {
53 setMousePattern( MouseSelect1, Qt::LeftButton );
54 setMousePattern( MouseSelect2, Qt::RightButton );
[8127]55 setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
[4271]56 break;
57 }
58 default:
59 {
60 setMousePattern( MouseSelect1, Qt::LeftButton );
61 setMousePattern( MouseSelect2, Qt::RightButton );
62 setMousePattern( MouseSelect3, Qt::MidButton );
63 }
64 }
[8127]65
66 setMousePattern( MouseSelect4, d_mousePattern[MouseSelect1].button,
67 d_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
68
69 setMousePattern( MouseSelect5, d_mousePattern[MouseSelect2].button,
70 d_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
71
72 setMousePattern( MouseSelect6, d_mousePattern[MouseSelect3].button,
73 d_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
[4271]74}
75
76/*!
77 Set default mouse patterns.
78
79 \sa KeyPatternCode
80*/
81void QwtEventPattern::initKeyPattern()
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
99/*!
100 Change one mouse pattern
101
102 \param pattern Index of the pattern
103 \param button Button
[8127]104 \param modifiers Keyboard modifiers
[4271]105
106 \sa QMouseEvent
107*/
[9383]108void QwtEventPattern::setMousePattern( MousePatternCode pattern,
[8127]109 Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
[4271]110{
[8127]111 if ( pattern >= 0 && pattern < MousePatternCount )
[4271]112 {
[8127]113 d_mousePattern[ pattern ].button = button;
114 d_mousePattern[ pattern ].modifiers = modifiers;
[4271]115 }
116}
117
118/*!
119 Change one key pattern
120
121 \param pattern Index of the pattern
122 \param key Key
[8127]123 \param modifiers Keyboard modifiers
[4271]124
125 \sa QKeyEvent
126*/
[9383]127void QwtEventPattern::setKeyPattern( KeyPatternCode pattern,
[8127]128 int key, Qt::KeyboardModifiers modifiers )
[4271]129{
[8127]130 if ( pattern >= 0 && pattern < KeyPatternCount )
[4271]131 {
[8127]132 d_keyPattern[ pattern ].key = key;
133 d_keyPattern[ pattern ].modifiers = modifiers;
[4271]134 }
135}
136
137//! Change the mouse event patterns
138void QwtEventPattern::setMousePattern( const QVector<MousePattern> &pattern )
139{
140 d_mousePattern = pattern;
141}
142
143//! Change the key event patterns
144void QwtEventPattern::setKeyPattern( const QVector<KeyPattern> &pattern )
145{
146 d_keyPattern = pattern;
147}
148
[8127]149//! \return Mouse pattern
[4271]150const QVector<QwtEventPattern::MousePattern> &
151QwtEventPattern::mousePattern() const
152{
153 return d_mousePattern;
154}
155
[8127]156//! \return Key pattern
[4271]157const QVector<QwtEventPattern::KeyPattern> &
158QwtEventPattern::keyPattern() const
159{
160 return d_keyPattern;
161}
162
[8127]163//! \return Mouse pattern
[4271]164QVector<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern()
165{
166 return d_mousePattern;
167}
168
[8127]169//! \return Key pattern
[4271]170QVector<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern()
171{
172 return d_keyPattern;
173}
174
175/*!
176 \brief Compare a mouse event with an event pattern.
177
178 A mouse event matches the pattern when both have the same button
179 value and in the state value the same key flags(Qt::KeyButtonMask)
180 are set.
181
[8127]182 \param code Index of the event pattern
[4271]183 \param event Mouse event
184 \return true if matches
185
186 \sa keyMatch()
187*/
[9383]188bool QwtEventPattern::mouseMatch( MousePatternCode code,
[4271]189 const QMouseEvent *event ) const
190{
[8127]191 if ( code >= 0 && code < MousePatternCount )
192 return mouseMatch( d_mousePattern[ code ], event );
[4271]193
[8127]194 return false;
[4271]195}
196
197/*!
198 \brief Compare a mouse event with an event pattern.
199
200 A mouse event matches the pattern when both have the same button
201 value and in the state value the same key flags(Qt::KeyButtonMask)
202 are set.
203
204 \param pattern Mouse event pattern
205 \param event Mouse event
206 \return true if matches
207
208 \sa keyMatch()
209*/
210
211bool QwtEventPattern::mouseMatch( const MousePattern &pattern,
212 const QMouseEvent *event ) const
213{
[8127]214 if ( event == NULL )
[4271]215 return false;
216
[8127]217 const MousePattern mousePattern( event->button(), event->modifiers() );
218 return mousePattern == pattern;
[4271]219}
220
221/*!
222 \brief Compare a key event with an event pattern.
223
224 A key event matches the pattern when both have the same key
225 value and in the state value the same key flags (Qt::KeyButtonMask)
226 are set.
227
[8127]228 \param code Index of the event pattern
[4271]229 \param event Key event
230 \return true if matches
231
232 \sa mouseMatch()
233*/
[9383]234bool QwtEventPattern::keyMatch( KeyPatternCode code,
[4271]235 const QKeyEvent *event ) const
236{
[8127]237 if ( code >= 0 && code < KeyPatternCount )
238 return keyMatch( d_keyPattern[ code ], event );
[4271]239
[8127]240 return false;
[4271]241}
242
243/*!
244 \brief Compare a key event with an event pattern.
245
246 A key event matches the pattern when both have the same key
247 value and in the state value the same key flags (Qt::KeyButtonMask)
248 are set.
249
250 \param pattern Key event pattern
251 \param event Key event
252 \return true if matches
253
254 \sa mouseMatch()
255*/
256
257bool QwtEventPattern::keyMatch(
258 const KeyPattern &pattern, const QKeyEvent *event ) const
259{
[8127]260 if ( event == NULL )
[4271]261 return false;
262
[8127]263 const KeyPattern keyPattern( event->key(), event->modifiers() );
264 return keyPattern == pattern;
[4271]265}
Note: See TracBrowser for help on using the repository browser.