spot
The shape is moved if the left-button of the mouse is clicked (and held down) and if the button Move shape is selected. The motion of the shape is identical of that of the mouse.
Implement the option allowing the user to select the mode Move shape by adding a button in WFrame. An icon is available in the directory data/icons: Move.bmp
Add a boolean data member m_moveShapeMode to Visu2D to know if the current mode is Moving a shape or not. This variable needs to be updated each time the user clicks on the corresponding button in WFrame.
Complete the Shape class with the following virtual method:
/** @brief Test if the shape is still within the visualization window after
* a move. If it is, then move it.
* @param dx: displacement along x
* @param dy: displacement along y
* @param w: width of the window
* @param h: height of the window
*/
virtual bool TestAndMove(int dx, int dy, int w, int h);
w and h give the limits of the image in data coordinates to test the translation being asked for doesn’t move the shape out of the visualization area (even just partially.) This method needs to be redefined for the polygon as the translation isn’t restricted to just that of the BoundingBox.
In the Visu2D class, add a method similar to GenerateShape() and complete it:
void Visu2D::MoveShape(int type, int xData, int yData)
{
switch (type) {
case PRESS:
// handle it
case MOVE:
// handle it
case RELEASE:
// handle it
}
update();
}
The method Selection::GetShape() returns – for the moment – the one shape falling into the selection. In the next project, it will return the current shape.
Modify the method:
void Visu2D::HandleMouse(int type, QMouseEvent *e);
to handle the mouse motion.