Developer Documentation

QtBaseViewerKeyHandling.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44
45
46 //=============================================================================
47 //
48 // CLASS QtBaseViewer - IMPLEMENTATION
49 //
50 //=============================================================================
51
52
53 //== INCLUDES =================================================================
54
55 #include "QtBaseViewer.hh"
56 #include <QInputDialog>
57
58 //== NAMESPACES ===============================================================
59
60 namespace ACG {
61 namespace QtWidgets {
62
63
64 //== IMPLEMENTATION ==========================================================
65
66 void QtBaseViewer::disableKeyHandling(bool _state ) {
67 disableKeyHandling_ = _state;
68 };
69
70 //-----------------------------------------------------------------------------
71
72 bool QtBaseViewer::keyHandlingState() {
73 return disableKeyHandling_;
74 };
75
76 //-----------------------------------------------------------------------------
77
78 void QtBaseViewer::glKeyReleaseEvent(QKeyEvent* _event) {
79 _event->ignore();
80 };
81
82 //-----------------------------------------------------------------------------
83
84 void QtBaseViewer::glKeyPressEvent(QKeyEvent* _event)
85 {
86 // Pass key event to parent widget without any handling
87 if ( disableKeyHandling_ ) {
88 _event->ignore();
89 return;
90 }
91
92 bool handled(false);
93
94
95 // CTRL + ALT events
96 if ((_event->modifiers() & Qt::ControlModifier) &&
97 (_event->modifiers() & Qt::AltModifier))
98 {
99
100 switch (_event->key())
101 {
102 // Stereo steeing: eye distance
103 case Qt::Key_E:
104 {
105 bool save(glareaGrabbed_);
106 bool ok(false);
107
108 // release grabbing to process input dialog
109 if(save) releaseGLArea();
110
111 double val = QInputDialog::getDouble( this, "Eye Dist", "Eye Dist:",
112 eyeDist_,
113 0.0, 100.0, 10,
114 &ok);
115 // restore old setting
116 if(save) grabGLArea();
117
118 if (ok) {
119 eyeDist_ = val;
120 handled = true;
121 updateGL();
122 }
123
124 break;
125 }
126
127
128 // Stereo setting: focal length
129 case Qt::Key_F:
130 {
131 bool save(glareaGrabbed_);
132 bool ok(false);
133
134 // release grabbing to process input dialog
135 if(save) releaseGLArea();
136
137 double val = QInputDialog::getDouble( this, "Focal Dist", "Focal Dist:",
138 focalDist_,
139 0.0, 100.0, 10,
140 &ok);
141 //restore old setting
142 if(save) grabGLArea();
143
144 if (ok) {
145 focalDist_ = val;
146 handled = true;
147 updateGL();
148 }
149 break;
150 }
151 }
152 } else { // Normal events
153
154 switch (_event->key())
155 {
156 // Lock / unlock update
157 case Qt::Key_ScrollLock:
158 {
159 if (!updateLocked_) {
160 lockUpdate();
161 handled = true;
162 std::cerr << "Display update locked\n";
163
164 } else {
165 unlockAndUpdate();
166 handled = true;
167 std::cerr << "Display update un-locked\n";
168 }
169 break;
170 }
171
172 case Qt::Key_Escape:
173 {
174 actionMode(lastActionMode_);
175 handled = true;
176 break;
177 }
178 }
179 }
180
181 // If the event has not been handled by the baseviewer, check for Key events from subclasses
182 if(!handled) {
183 handled = viewKeyPressEvent(_event);
184 }
185
186
187 // give event to application
188 if (!handled) {
189 _event->ignore();
190 emit(signalKeyPressEvent(_event));
191 }
192
193 }
194
195
196
197
198 //=============================================================================
199 } // namespace QtWidgets
200 } // namespace ACG
201 //=============================================================================
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::QtWidgets::QtBaseViewer::eyeDist_
double eyeDist_
Set eye distance for stereo.
Definition: QtBaseViewer.hh:959
ACG::QtWidgets::QtBaseViewer::unlockAndUpdate
virtual void unlockAndUpdate()
Definition: QtBaseViewer.cc:427
ACG::QtWidgets::QtBaseViewer::glKeyReleaseEvent
virtual void glKeyReleaseEvent(QKeyEvent *_event)
Get keyRelease events from the glArea.
Definition: QtBaseViewerKeyHandling.cc:78
ACG::QtWidgets::QtBaseViewer::focalDist_
double focalDist_
Set eye distance for stereo.
Definition: QtBaseViewer.hh:959
ACG::QtWidgets::QtBaseViewer::glKeyPressEvent
virtual void glKeyPressEvent(QKeyEvent *)
Get keyPress events from the glArea.
Definition: QtBaseViewerKeyHandling.cc:84
ACG::QtWidgets::QtBaseViewer::disableKeyHandling
void disableKeyHandling(bool _state)
Enable or disable internal Key handling.
Definition: QtBaseViewerKeyHandling.cc:66
ACG::QtWidgets::QtBaseViewer::signalKeyPressEvent
void signalKeyPressEvent(QKeyEvent *)
Key Event received.
ACG::QtWidgets::QtBaseViewer::updateGL
virtual void updateGL()
Redraw scene. Triggers paint event for updating the view (cf. drawNow()).
Definition: QtBaseViewer.cc:781
ACG::QtWidgets::QtBaseViewer::actionMode
ActionMode actionMode() const
get action mode
Definition: QtBaseViewer.hh:384
ACG::QtWidgets::QtBaseViewer::viewKeyPressEvent
virtual bool viewKeyPressEvent(QKeyEvent *_event)=0
Handle key events in view mode.
ACG::QtWidgets::QtBaseViewer::keyHandlingState
bool keyHandlingState()
get the current key handling state.
Definition: QtBaseViewerKeyHandling.cc:72
ACG::QtWidgets::QtBaseViewer::lockUpdate
virtual void lockUpdate()
Definition: QtBaseViewer.cc:413
ACG::QtWidgets::QtBaseViewer::disableKeyHandling_
bool disableKeyHandling_
Enable or disable internal Key handling.
Definition: QtBaseViewer.hh:1018