libQGLViewer Version 2.6.4
|virtual void||checkIfGrabsMouse (int x, int y, const Camera *const camera)=0|
|bool||grabsMouse () const|
|void||setGrabsMouse (bool grabs)|
|bool||isInMouseGrabberPool () const|
|void||clearMouseGrabberPool (bool autoDelete=false)|
|static const QList< MouseGrabber * > &||MouseGrabberPool ()|
|virtual void||mousePressEvent (QMouseEvent *const event, Camera *const camera)|
|virtual void||mouseDoubleClickEvent (QMouseEvent *const event, Camera *const camera)|
|virtual void||mouseReleaseEvent (QMouseEvent *const event, Camera *const camera)|
|virtual void||mouseMoveEvent (QMouseEvent *const event, Camera *const camera)|
|virtual void||wheelEvent (QWheelEvent *const event, Camera *const camera)|
Abstract class for objects that grab mouse focus in a QGLViewer.
MouseGrabber are objects which react to the mouse cursor, usually when it hovers over them. This abstract class only provides an interface for all these objects: their actual behavior has to be defined in a derived class.
When a MouseGrabber grabsMouse(), it becomes the QGLViewer::mouseGrabber(). All the mouse events (mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), mouseDoubleClickEvent() and wheelEvent()) are then transmitted to the QGLViewer::mouseGrabber() instead of being normally processed. This continues while grabsMouse() (updated using checkIfGrabsMouse()) returns
If you want to (temporarily) disable a specific MouseGrabbers, you can remove it from this pool using removeFromMouseGrabberPool(). You can also disable a MouseGrabber in a specific QGLViewer using QGLViewer::setMouseGrabberIsEnabled().
In order to make MouseGrabber react to mouse events, mouse tracking has to be activated in the QGLViewer which wants to use MouseGrabbers:
QGLWidget::hasMouseTracking() to get the current state of this flag.
camera parameter of the different mouse event methods is a pointer to the QGLViewer::camera() of the QGLViewer that uses the MouseGrabber. It can be used to compute 2D to 3D coordinates conversion using Camera::projectedCoordinatesOf() and Camera::unprojectedCoordinatesOf().
Very complex behaviors can be implemented using this framework: auto-selected objects (no need to press a key to use them), automatic drop-down menus, 3D GUI, spinners using the wheelEvent(), and whatever your imagination creates. See the mouseGrabber example for an illustration.
Note that ManipulatedFrame are MouseGrabber: see the keyFrame example for an illustration. Every created ManipulatedFrame is hence present in the MouseGrabberPool() (note however that ManipulatedCameraFrame are not inserted).
Here is for instance a draft version of a MovableObject class. Instances of these class can freely be moved on screen using the mouse, as movable post-it-like notes:
Note that the different event callback methods are called only once the MouseGrabber grabsMouse().
Virtual destructor. Removes the MouseGrabber from the MouseGrabberPool().
Adds the MouseGrabber in the MouseGrabberPool().
Use removeFromMouseGrabberPool() to remove the MouseGrabber from the list, so that it is no longer tested with checkIfGrabsMouse() by the QGLViewer, and hence can no longer grab mouse focus. Use isInMouseGrabberPool() to know the current state of the MouseGrabber.
This is the core method of the MouseGrabber. It has to be overloaded in your derived class. Its goal is to update the grabsMouse() flag according to the mouse and MouseGrabber current positions, using setGrabsMouse().
grabsMouse() is usually set to
true when the mouse cursor is close enough to the MouseGrabber position. It should also be set to
false when the mouse cursor leaves this region in order to release the mouse focus.
y are the mouse cursor coordinates (Qt coordinate system: (0,0) corresponds to the upper left corner).
A typical implementation will look like:
Implemented in ManipulatedFrame.
|void clearMouseGrabberPool||(||bool||autoDelete = ||)|
Clears the MouseGrabberPool().
Use this method only if it is faster to clear the MouseGrabberPool() and then to add back a few MouseGrabbers than to remove each one independently. Use QGLViewer::setMouseTracking(false) instead if you want to disable mouse grabbing.
true, the MouseGrabbers of the MouseGrabberPool() are actually deleted (use this only if you're sure of what you do).
Returns a list containing pointers to all the active MouseGrabbers.
QPtrList<MouseGrabber>with Qt 3 and a
QList<MouseGrabber>with Qt 2.
Callback method called when the MouseGrabber grabsMouse() and the mouse is moved while a button is pressed.
This method will typically update the state of the MouseGrabber from the mouse displacement. See the mousePressEvent() documentation for details.
Callback method called when the MouseGrabber grabsMouse() and a mouse button is pressed.
The MouseGrabber will typically start an action or change its state when a mouse button is pressed. mouseMoveEvent() (called at each mouse displacement) will then update the MouseGrabber accordingly and mouseReleaseEvent() (called when the mouse button is released) will terminate this action.
event QMouseEvent::state() and QMouseEvent::button() to test the keyboard and button state and possibly change the MouseGrabber behavior accordingly.
QGLWidget::mousePressEvent() and the
QMouseEvent documentations for details.
Reimplemented in ManipulatedFrame.