Changeset 1333 for trunk


Ignore:
Timestamp:
Aug 19, 2010, 5:33:35 PM (14 years ago)
Author:
garnier
Message:

shorcuts better implementation, Mouse move volume follow mouse position

Location:
trunk/source/visualization/OpenGL
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/visualization/OpenGL/History

    r1324 r1333  
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     2019th August 2010  Laurent Garnier
     21- Better way to hold Meta Keys and shortcuts
    1922
    202323th June 2010  Laurent Garnier
  • trunk/source/visualization/OpenGL/include/G4OpenGLQtViewer.hh

    r1332 r1333  
    120120  void moveScene(float, float, float,bool);
    121121  void FinishView();
     122#if QT_VERSION < 0x040000
     123  void updateKeyModifierState(Qt::ButtonState);
     124#else
     125  void updateKeyModifierState(Qt::KeyboardModifiers);
     126#endif
    122127
    123128
     
    202207  G4double fXRot;
    203208  G4double fYRot;
     209  bool fNoKeyPress;
     210  bool fAltKeyPress;
     211  bool fControlKeyPress;
     212  bool fShiftKeyPress;
    204213
    205214signals:
  • trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r1332 r1333  
    244244  ,fXRot(0)
    245245  ,fYRot(0)
     246  ,fNoKeyPress(true)
     247  ,fAltKeyPress(false)
     248  ,fControlKeyPress(false)
     249  ,fShiftKeyPress(false)
    246250{
    247251
     
    950954 */
    951955void G4OpenGLQtViewer::showShortcuts() {
     956  G4cout << "========= Mouse Shortcuts =========" << G4endl;
    952957  if (fMouseAction == STYLE1) {  // rotate
    953958    G4cout << "Click and move mouse to rotate volume " << G4endl;
     959    G4cout << "ALT + Click and move mouse to rotate volume (View Direction)" << G4endl;
     960    G4cout << "CTRL + Click and zoom mouse to zoom in/out" << G4endl;
     961    G4cout << "SHIFT + Click and zoommove camera point of view" << G4endl;
    954962  } else  if (fMouseAction == STYLE2) { //move
    955963    G4cout << "Move camera point of view with mouse" << G4endl;
     
    12281236  SetNeedKernelVisit (true);
    12291237  updateQWidget();
    1230 
    12311238}
    12321239
     
    14461453{
    14471454#if QT_VERSION < 0x040000
    1448   if ((event->button() & Qt::LeftButton)
    1449       && !((event->state() & Qt::ShiftButton)
    1450            || (event->state() & Qt::ControlButton)
    1451            || (event->state() & Qt::AltButton)
    1452            || (event->state() & Qt::MetaButton))) {
    1453 #else
    1454   if ((event->buttons() & Qt::LeftButton)
    1455       && !((event->modifiers() & Qt::ShiftModifier)
    1456            || (event->modifiers() & Qt::ControlModifier)
    1457            || (event->modifiers() & Qt::AltModifier)
    1458            || (event->modifiers() & Qt::MetaModifier))) {
     1455  if (event->button() & Qt::LeftButton) {
     1456#else
     1457  if (event->buttons() & Qt::LeftButton) {
    14591458#endif
    14601459    fWindow->setMouseTracking(true);
     
    14951494          }
    14961495        }
    1497       if (((((float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
    1498           ((((float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
     1496        if (((((float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
     1497            ((((float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
    14991498          correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
    15001499          if (delta.y() <0 ) {
     
    15021501          }
    15031502        }
     1503               
     1504        // Check Qt Versions for META Keys
     1505               
     1506        // Click and move mouse to rotate volume
     1507        // ALT + Click and move mouse to rotate volume (View Direction)
     1508        // SHIFT + Click and move camera point of view
     1509        // CTRL + Click and zoom mouse to zoom in/out
    15041510
    15051511        if (fMouseAction == STYLE1) {  // rotate
    1506           rotateQtScene(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor);
     1512#ifdef G4DEBUG_VIS_OGL
     1513          printf("G4OpenGLQtViewer:: ___________________________________\n");
     1514          printf("G4OpenGLQtViewer:: mouse move\n");
     1515#endif
     1516          if (fNoKeyPress) {
     1517#ifdef G4DEBUG_VIS_OGL
     1518            printf("G4OpenGLQtViewer:: rotate normal\n");
     1519#endif
     1520            rotateQtScene(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor);
     1521          } else if (fAltKeyPress) {
     1522#ifdef G4DEBUG_VIS_OGL
     1523            printf("G4OpenGLQtViewer:: rotate view\n");
     1524#endif
     1525            rotateQtSceneInViewDirection(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor);
     1526          }
     1527         
    15071528        } else if (fMouseAction == STYLE2) {  // move
    15081529          moveScene(-((float)delta.x())/correctionFactor,-((float)delta.y())/correctionFactor,0,true);
     
    15431564#endif
    15441565
     1566#if QT_VERSION < 0x040000
     1567  updateKeyModifierState(event->state());
     1568#else
     1569  updateKeyModifierState(event->modifiers());
     1570#endif
     1571
    15451572  if (fAutoMove) {
    15461573    return;
     
    15561583  if (fMouseAction == STYLE1) {  // rotate
    15571584    if (mButtons & Qt::LeftButton) {
    1558       rotateQtScene(deltaX,deltaY);
     1585#ifdef G4DEBUG_VIS_OGL
     1586      printf("G4OpenGLQtViewer:: ___________________________________\n");
     1587      printf("G4OpenGLQtViewer:: mouse move %f %f\n",((float)deltaX),((float)deltaY));
     1588#endif
     1589      if (fNoKeyPress) {
     1590#ifdef G4DEBUG_VIS_OGL
     1591        printf("G4OpenGLQtViewer:: rotate normal\n");
     1592#endif
     1593        rotateQtScene(((float)deltaX),((float)deltaY));
     1594      } else if (fAltKeyPress) {
     1595#ifdef G4DEBUG_VIS_OGL
     1596        printf("G4OpenGLQtViewer:: rotate view\n");
     1597#endif
     1598        rotateQtSceneInViewDirection(((float)deltaX),((float)deltaY));
     1599      } else if (fShiftKeyPress) {
     1600        unsigned int sizeWin;
     1601        sizeWin = getWinWidth();
     1602        if (getWinHeight() < getWinWidth()) {
     1603          sizeWin = getWinHeight();
     1604        }
     1605
     1606        // L.Garnier : 08/2010 100 is the good value, but don't ask me why !
     1607        float factor = ((float)100/(float)sizeWin) ;
     1608        moveScene(-(float)deltaX*factor,-(float)deltaY*factor,0,false);
     1609      } else if (fControlKeyPress) {
     1610#ifdef G4DEBUG_VIS_OGL
     1611        printf("G4OpenGLQtViewer:: zoom\n");
     1612#endif
     1613        fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY)));
     1614      }
    15591615    }
    15601616  } else if (fMouseAction == STYLE2) {  // move
     
    18141870
    18151871
    1816 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
     1872 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
    18171873{
    18181874  if (fHoldKeyEvent)
     
    18211877  fHoldKeyEvent = true;
    18221878
    1823   bool NothingPress = false;
    1824   bool AltPress = false;
    1825   bool ControlPress = false;
    1826   bool ShiftPress = false;
    1827 
    1828   // Check Qt Versions for META Keys
    1829 
    1830 #if QT_VERSION < 0x040000
    1831   if (event->state() & Qt::NoButton ) {
    1832         NothingPress = true;
    1833   }
    1834   if (event->state() & Qt::AltButton ) {
    1835         AltPress = true;
    1836   }
    1837   if (event->state() & Qt::ShiftButton ) {
    1838         ShiftPress = true;
    1839   }
    1840   if (event->state() & Qt::ControlButton ) {
    1841         ControlPress = true;
    1842   }
    1843 #else
    1844   if (event->modifiers() & Qt::NoModifier ) {
    1845     NothingPress = true;
    1846   }
    1847   if (event->modifiers() & Qt::AltModifier ) {
    1848     AltPress = true;
    1849   }
    1850   if (event->modifiers() & Qt::ShiftModifier ) {
    1851     ShiftPress = true;
    1852   }
    1853   if (event->modifiers() & Qt::ControlModifier ) {
    1854     ControlPress = true;
    1855   }
    1856 #endif
    1857 
     1879 
    18581880  // with no modifiers
    18591881#if QT_VERSION < 0x040000
    1860   if (NothingPress) {
    1861 #else
    1862   if ((NothingPress) || (event->modifiers() == Qt::KeypadModifier )) {
     1882  updateKeyModifierState(event->state());
     1883  if (fNoKeyPress) {
     1884#else
     1885  updateKeyModifierState(event->modifiers());
     1886  if ((fNoKeyPress) || (event->modifiers() == Qt::KeypadModifier )) {
    18631887#endif
    18641888    if (event->key() == Qt::Key_Down) { // go down
     
    19171941
    19181942  // Shift Modifier
    1919   if (ShiftPress) {
     1943  if (fShiftKeyPress) {
    19201944    if (event->key() == Qt::Key_Down) { // rotate phi
    19211945      rotateQtScene(0,-fDeltaRotation);
     
    19331957  // Alt Modifier
    19341958  }
    1935   if ((AltPress)) {
     1959  if ((fAltKeyPress)) {
    19361960    if (event->key() == Qt::Key_Down) { // rotate phi
    19371961      rotateQtSceneInViewDirection(0,-fDeltaRotation);
     
    19591983  // Control Modifier OR Command on MAC
    19601984  }
    1961   if ((ControlPress)) {
     1985  if ((fControlKeyPress)) {
    19621986    if (event->key() == Qt::Key_Plus) {
    19631987      fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
     
    19731997}
    19741998 
     1999
     2000#if QT_VERSION < 0x040000
     2001void  G4OpenGLQtViewer::updateKeyModifierState(Qt::ButtonState modifier) {
     2002#else
     2003void  G4OpenGLQtViewer::updateKeyModifierState(Qt::KeyboardModifiers modifier) {
     2004#endif
     2005  // Check Qt Versions for META Keys
     2006   
     2007  fNoKeyPress = true;
     2008  fAltKeyPress = false;
     2009  fShiftKeyPress = false;
     2010  fControlKeyPress = false;
     2011 
     2012#if QT_VERSION < 0x040000
     2013  if (modifier & Qt::AltButton ) {
     2014    fAltKeyPress = true;
     2015    fNoKeyPress = false;
     2016  }
     2017  if (modifier & Qt::ShiftButton ) {
     2018    fShiftKeyPress = true;
     2019    fNoKeyPress = false;
     2020  }
     2021  if (modifier & Qt::ControlButton ) {
     2022    fControlKeyPress = true;
     2023    fNoKeyPress = false;
     2024  }
     2025#else
     2026#ifdef G4DEBUG_VIS_OGL
     2027  printf("G4OpenGLQtViewer:: ________________Key Press\n");
     2028#endif
     2029  if (modifier & Qt::AltModifier ) {
     2030    fAltKeyPress = true;
     2031    fNoKeyPress = false;
     2032#ifdef G4DEBUG_VIS_OGL
     2033    printf("G4OpenGLQtViewer:: ________________ALT\n");
     2034#endif
     2035  }
     2036  if (modifier & Qt::ShiftModifier ) {
     2037    fShiftKeyPress = true;
     2038    fNoKeyPress = false;
     2039#ifdef G4DEBUG_VIS_OGL
     2040    printf("G4OpenGLQtViewer:: ________________Shift\n");
     2041#endif
     2042  }
     2043  if (modifier & Qt::ControlModifier ) {
     2044    fControlKeyPress = true;
     2045    fNoKeyPress = false;
     2046#ifdef G4DEBUG_VIS_OGL
     2047    printf("G4OpenGLQtViewer:: ________________Control\n");
     2048#endif
     2049  }
     2050#endif
     2051}
     2052
    19752053
    19762054/** Stop the video. Check all parameters and enable encoder button if all is ok.
Note: See TracChangeset for help on using the changeset viewer.