1
/**************************************************************************\
2
* Copyright (c) Kongsberg Oil & Gas Technologies AS
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are
9
* Redistributions of source code must retain the above copyright notice,
10
* this list of conditions and the following disclaimer.
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.
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.
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
\**************************************************************************/
34
Adjust how QuarterWidget reacts to alt key events
37
#include <QCoreApplication>
41
#include "InteractionMode.h"
42
#include "QuarterWidget.h"
45
using namespace SIM::Coin3D::Quarter;
47
InteractionMode::InteractionMode(QuarterWidget * quarterwidget)
48
: QObject(quarterwidget)
50
this->quarterwidget = quarterwidget;
51
this->altkeydown = false;
52
this->prevcursor = QCursor();
54
this->quarterwidget->getSoEventManager()->getNavigationState();
56
this->isenabled = true;
59
InteractionMode::~InteractionMode()
65
InteractionMode::setEnabled(bool yes)
67
this->isenabled = yes;
71
InteractionMode::enabled() const
73
return this->isenabled;
77
InteractionMode::setOn(bool on)
79
if (!this->isenabled) {
83
SoEventManager * eventmanager = this->quarterwidget->getSoEventManager();
86
this->altkeydown = true;
87
this->prevnavstate = eventmanager->getNavigationState();
88
this->prevcursor = this->quarterwidget->cursor();
89
this->quarterwidget->setCursor(this->quarterwidget->stateCursor("interact"));
90
eventmanager->setNavigationState(SoEventManager::NO_NAVIGATION);
92
this->altkeydown = false;
93
this->quarterwidget->setCursor(this->prevcursor);
94
eventmanager->setNavigationState(this->prevnavstate);
99
InteractionMode::on() const
101
return this->altkeydown;
105
InteractionMode::eventFilter(QObject * obj, QEvent * event)
107
if (!this->isenabled) {
111
assert(obj == this->quarterwidget);
113
switch (event->type()) {
114
case QEvent::KeyPress:
115
return this->keyPressEvent(dynamic_cast<QKeyEvent *>(event));
116
case QEvent::KeyRelease:
117
return this->keyReleaseEvent(dynamic_cast<QKeyEvent *>(event));
118
case QEvent::FocusOut:
119
return this->focusOutEvent(dynamic_cast<QFocusEvent *>(event));
121
return QObject::eventFilter(obj, event);
126
when alt is pressed, override navigation and allow scenegraph to
127
process events so draggers and manipulators works
130
InteractionMode::keyPressEvent(QKeyEvent * event)
133
!(event->key() == Qt::Key_Alt) ||
134
!(event->modifiers() & Qt::AltModifier)) {
143
InteractionMode::keyReleaseEvent(QKeyEvent * event)
145
if (!event || !(event->key() == Qt::Key_Alt)) {
154
if we lose focus while alt is down, send an alt-release event
157
InteractionMode::focusOutEvent(QFocusEvent * event)
160
if (this->altkeydown) {
161
QKeyEvent keyevent(QEvent::KeyRelease, Qt::Key_Alt, Qt::NoModifier);
162
return QCoreApplication::sendEvent(this->quarterwidget, &keyevent);