///// keyPressEvent /////////////////////////////////////////////////////////// void GLView::keyPressEvent(QKeyEvent* e) /// Overridden from QGlWidget::mousepressEvent. Handles key presses. /// \arg <left> : rotate left /// \arg <right> : rotate right /// \arg <up> : rotate up /// \arg <down> : rotate down /// \arg <shift>+<left> : rotate counterclockwise /// \arg <shift>+<right>: rotate clockwise /// \arg <shift>+<up> : zoom in /// \arg <shift>+<down> : zoom out /// \arg <ctrl>+<left> : translate left /// \arg <ctrl>+<right> : translate right /// \arg <ctrl>+<up> : translate up /// \arg <ctrl>+<down> : translate down /// \arg <ctrl>+<shift>+<left>: change internal coordinate of selection (smaller). Implementation in GLMoleculeView. /// \arg <ctrl>+<shift>+<right>: change internal coordinate of selection (larger). Implementation in GLMoleculeView. { switch(e->key()) { case Qt::Key_Left : if(e->modifiers() & Qt::ShiftModifier) zRot = 5.0f; // rotate counterclockwise else if(e->modifiers() & Qt::ControlModifier) translateXY(-5, 0); else yRot = -5.0f; // rotate left break; case Qt::Key_Up : if(e->modifiers() & Qt::ShiftModifier) translateZ(-5); else if(e->modifiers() & Qt::ControlModifier) translateXY(0, -5); else xRot = -5.0f; // rotate up break; case Qt::Key_Right : if(e->modifiers() & Qt::ShiftModifier) zRot = -5.0f; // rotate clockwise else if(e->modifiers() & Qt::ControlModifier) translateXY(5, 0); else yRot = 5.0f; // rotate right break; case Qt::Key_Down : if(e->modifiers() & Qt::ShiftModifier) translateZ(5); else if(e->modifiers() & Qt::ControlModifier) translateXY(0, 5); else xRot = 5.0f; // rotate down break; default: e->ignore(); return; } setModified(); updateGL(); }
void GLWidget::mouseMoveEvent(QMouseEvent *event) { if (event->buttons() == Qt::LeftButton) { rotateY(2.5*(event->x() - clickPointL.x())); clickPointL = event->pos(); } if (event->buttons() == Qt::RightButton) { translateXY( 0.01 *(event->x() - clickPointR.x()), -0.01*(event->y() - clickPointR.y())); clickPointR = event->pos(); } }
///// mouseMoveEvent ////////////////////////////////////////////////////////// void GLView::mouseMoveEvent(QMouseEvent* e) /// Overridden from QGlWidget::mouseMoveEvent. Handles left mouse button drags. { if(e->modifiers() & Qt::LeftButton) // only track mousemoves for the left button { QPoint newPosition = e->pos(); // the mouse moved from mousePosition to newPosition if(e->modifiers() & Qt::ShiftModifier) // shift has precedence over control { ///// LEFTBUTTON + SHIFT ///// up/down movement: zooming (z-translation) ///// left/right movement: z-rotation ///// decoupled if(abs(newPosition.y() - mousePosition.y()) > abs(newPosition.x() - mousePosition.x())) translateZ(newPosition.y() - mousePosition.y()); else zRot = -180.0f * static_cast<float>(newPosition.x() - mousePosition.x()) / static_cast<float>(width()); // z-rotation of entire system } else if(e->modifiers() & Qt::ControlModifier) { ///// LEFTBUTTON + CONTROL ///// up/down movement: y-translation ///// left/right movement: x-translation ///// coupled translateXY(newPosition.x() - mousePosition.x(), newPosition.y() - mousePosition.y()); } else { ///// LEFTBUTTON ONLY ///// up/down movement: x-rotation ///// left/right movement: y-rotation yRot = 180.0f * static_cast<float>(newPosition.x() - mousePosition.x()) / static_cast<float>(width()); xRot = 180.0f * static_cast<float>(newPosition.y() - mousePosition.y()) / static_cast<float>(height()); } setModified(); mousePosition = newPosition; updateGL(); startingClick = false; } else e->ignore(); }