Debian Codegraph @

src/Gui/Quarter/InputDevice.cpp

raw
1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 #ifdef _MSC_VER
34 #pragma warning(disable : 4267)
35 #endif
36
37 #include <QInputEvent>
38 #include <Inventor/events/SoEvents.h>
39
40 #include "devices/InputDevice.h"
41
42
43 using namespace SIM::Coin3D::Quarter;
44
45 /*!
46 \class SIM::Coin3D::Quarter::InputDevice InputDevice.h Quarter/devices/InputDevice.h
47
48 \brief The InputDevice class is the base class for devices such as
49 keyboard and mouse. It can be subclassed to support other devices.
50 */
51
52 InputDevice::InputDevice(QuarterWidget* quarter) :
53 quarter(quarter)
54 {
55 this->mousepos = SbVec2s(0, 0);
56 }
57
58 /*!
59 Sets the mouse position
60
61 \param[in] pos position of mouse in pixel coordinates
62 */
63 void
64 InputDevice::setMousePosition(const SbVec2s & pos)
65 {
66 this->mousepos = pos;
67 }
68
69 /*!
70 Sets the window size of the owning window
71
72 \param[in] size in pixels
73 */
74 void
75 InputDevice::setWindowSize(const SbVec2s & size)
76 {
77 this->windowsize = size;
78 }
79
80 /*!
81 Transforms a QEvent into an SoEvent
82
83 \param[in,out] SoEvent the transformed event
84 \param[in] QEvent incoming QEvent
85 */
86 void
87 InputDevice::setModifiers(SoEvent * soevent, const QInputEvent * qevent)
88 {
89 // FIXME: How do we get the time from the qevent? (20070306 frodo)
90 soevent->setTime(SbTime::getTimeOfDay());
91
92 // Note: On Mac OS X, the ControlModifier value corresponds to the
93 // Command keys on the Macintosh keyboard, and the MetaModifier
94 // value corresponds to the Control keys.
95 soevent->setShiftDown(qevent->modifiers() & Qt::ShiftModifier);
96 soevent->setAltDown(qevent->modifiers() & Qt::AltModifier);
97 soevent->setCtrlDown(qevent->modifiers() & Qt::ControlModifier);
98 }
99
100 /*!
101 \var InputDevice::mousepos
102
103 Holds the last known position of the mouse. This should be set even
104 for a keyboard event.
105 */
106
107 /*!
108 \var InputDevice::windowsize
109
110 Holds the size of the owning window
111 */
112
113 #undef PRIVATE