QtBaseViewerKeyHandling.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS QtBaseViewer - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 #include "QtBaseViewer.hh"
00055 #include <QInputDialog>
00056 
00057 //== NAMESPACES ===============================================================
00058 
00059 namespace ACG {
00060 namespace QtWidgets {
00061 
00062 
00063 //== IMPLEMENTATION ==========================================================
00064 
00065 void QtBaseViewer::disableKeyHandling(bool _state ) {
00066   disableKeyHandling_ = _state;
00067 };
00068 
00069 //-----------------------------------------------------------------------------
00070 
00071 bool QtBaseViewer::keyHandlingState() {
00072   return disableKeyHandling_;
00073 };
00074 
00075 //-----------------------------------------------------------------------------
00076 
00077 void QtBaseViewer::glKeyReleaseEvent(QKeyEvent* _event) {
00078   _event->ignore();
00079 };
00080 
00081 //-----------------------------------------------------------------------------
00082 
00083 void QtBaseViewer::glKeyPressEvent(QKeyEvent* _event)
00084 {
00085   // Pass key event to parent widget without any handling
00086   if ( disableKeyHandling_ ) {
00087     _event->ignore();
00088     return;
00089   }
00090 
00091   bool handled(false);
00092 
00093 
00094   // CTRL + ALT events
00095   if ((_event->modifiers() & Qt::ControlModifier) &&
00096       (_event->modifiers() & Qt::AltModifier))
00097   {
00098 
00099     switch (_event->key())
00100     {
00101       // Stereo steeing: eye distance
00102       case Qt::Key_E:
00103       {
00104         bool save(glareaGrabbed_);
00105         bool ok(false);
00106 
00107         // release grabbing to process input dialog
00108         if(save) releaseGLArea();
00109 
00110         double val = QInputDialog::getDouble( this, "Eye Dist", "Eye Dist:",
00111                                               eyeDist_,
00112                                               0.0, 100.0, 10,
00113                                               &ok);
00114         // restore old setting
00115         if(save) grabGLArea();
00116 
00117         if (ok) {
00118           eyeDist_ = val;
00119           handled = true;
00120           updateGL();
00121         }
00122 
00123         break;
00124       }
00125 
00126 
00127       // Stereo setting: focal length
00128       case Qt::Key_F:
00129       {
00130         bool save(glareaGrabbed_);
00131         bool ok(false);
00132 
00133         // release grabbing to process input dialog
00134         if(save) releaseGLArea();
00135 
00136         double val = QInputDialog::getDouble( this, "Focal Dist", "Focal Dist:",
00137                                               focalDist_,
00138                                               0.0, 100.0, 10,
00139                                               &ok);
00140         //restore old setting
00141         if(save) grabGLArea();
00142 
00143         if (ok) {
00144           focalDist_ = val;
00145           handled = true;
00146           updateGL();
00147         }
00148         break;
00149       }
00150     }
00151   } else { // Normal events
00152 
00153     switch (_event->key())
00154     {
00155       // Lock / unlock update
00156       case Qt::Key_ScrollLock:
00157       {
00158         if (!updateLocked_) {
00159           lockUpdate();
00160           handled = true;
00161           std::cerr << "Display update locked\n";
00162 
00163         } else {
00164           unlockAndUpdate();
00165           handled = true;
00166           std::cerr << "Display update un-locked\n";
00167         }
00168         break;
00169       }
00170 
00171       case Qt::Key_Escape:
00172       {
00173         actionMode(lastActionMode_);
00174         handled = true;
00175         break;
00176       }
00177     }
00178   }
00179 
00180   // If the event has not been handled by the baseviewer, check for Key events from subclasses
00181   if(!handled) {
00182     handled = viewKeyPressEvent(_event);
00183   }
00184 
00185 
00186   // give event to application
00187   if (!handled) {
00188     _event->ignore();
00189     emit(signalKeyPressEvent(_event));
00190   }
00191 
00192 }
00193 
00194 
00195 
00196 
00197 //=============================================================================
00198 } // namespace QtWidgets
00199 } // namespace ACG
00200 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .