Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS QtBaseViewer - IMPLEMENTATION
55 //
56 //=============================================================================
57 
58 
59 //== INCLUDES =================================================================
60 
61 #include "QtBaseViewer.hh"
62 #include <QInputDialog>
63 
64 //== NAMESPACES ===============================================================
65 
66 namespace ACG {
67 namespace QtWidgets {
68 
69 
70 //== IMPLEMENTATION ==========================================================
71 
73  disableKeyHandling_ = _state;
74 };
75 
76 //-----------------------------------------------------------------------------
77 
79  return disableKeyHandling_;
80 };
81 
82 //-----------------------------------------------------------------------------
83 
84 void QtBaseViewer::glKeyReleaseEvent(QKeyEvent* _event) {
85  _event->ignore();
86 };
87 
88 //-----------------------------------------------------------------------------
89 
90 void QtBaseViewer::glKeyPressEvent(QKeyEvent* _event)
91 {
92  // Pass key event to parent widget without any handling
93  if ( disableKeyHandling_ ) {
94  _event->ignore();
95  return;
96  }
97 
98  bool handled(false);
99 
100 
101  // CTRL + ALT events
102  if ((_event->modifiers() & Qt::ControlModifier) &&
103  (_event->modifiers() & Qt::AltModifier))
104  {
105 
106  switch (_event->key())
107  {
108  // Stereo steeing: eye distance
109  case Qt::Key_E:
110  {
111  bool save(glareaGrabbed_);
112  bool ok(false);
113 
114  // release grabbing to process input dialog
115  if(save) releaseGLArea();
116 
117  double val = QInputDialog::getDouble( this, "Eye Dist", "Eye Dist:",
118  eyeDist_,
119  0.0, 100.0, 10,
120  &ok);
121  // restore old setting
122  if(save) grabGLArea();
123 
124  if (ok) {
125  eyeDist_ = val;
126  handled = true;
127  updateGL();
128  }
129 
130  break;
131  }
132 
133 
134  // Stereo setting: focal length
135  case Qt::Key_F:
136  {
137  bool save(glareaGrabbed_);
138  bool ok(false);
139 
140  // release grabbing to process input dialog
141  if(save) releaseGLArea();
142 
143  double val = QInputDialog::getDouble( this, "Focal Dist", "Focal Dist:",
144  focalDist_,
145  0.0, 100.0, 10,
146  &ok);
147  //restore old setting
148  if(save) grabGLArea();
149 
150  if (ok) {
151  focalDist_ = val;
152  handled = true;
153  updateGL();
154  }
155  break;
156  }
157  }
158  } else { // Normal events
159 
160  switch (_event->key())
161  {
162  // Lock / unlock update
163  case Qt::Key_ScrollLock:
164  {
165  if (!updateLocked_) {
166  lockUpdate();
167  handled = true;
168  std::cerr << "Display update locked\n";
169 
170  } else {
171  unlockAndUpdate();
172  handled = true;
173  std::cerr << "Display update un-locked\n";
174  }
175  break;
176  }
177 
178  case Qt::Key_Escape:
179  {
180  actionMode(lastActionMode_);
181  handled = true;
182  break;
183  }
184  }
185  }
186 
187  // If the event has not been handled by the baseviewer, check for Key events from subclasses
188  if(!handled) {
189  handled = viewKeyPressEvent(_event);
190  }
191 
192 
193  // give event to application
194  if (!handled) {
195  _event->ignore();
196  emit(signalKeyPressEvent(_event));
197  }
198 
199 }
200 
201 
202 
203 
204 //=============================================================================
205 } // namespace QtWidgets
206 } // namespace ACG
207 //=============================================================================
double focalDist_
Set eye distance for stereo.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
virtual void glKeyPressEvent(QKeyEvent *)
Get keyPress events from the glArea.
void disableKeyHandling(bool _state)
Enable or disable internal Key handling.
virtual void glKeyReleaseEvent(QKeyEvent *_event)
Get keyRelease events from the glArea.
void signalKeyPressEvent(QKeyEvent *)
Key Event received.
double eyeDist_
Set eye distance for stereo.
bool disableKeyHandling_
Enable or disable internal Key handling.
bool keyHandlingState()
get the current key handling state.
virtual bool viewKeyPressEvent(QKeyEvent *_event)=0
Handle key events in view mode.
virtual void updateGL()
Redraw scene. Triggers paint event for updating the view (cf. drawNow()).
ActionMode actionMode() const
get action mode