Commit 03936b21 authored by Olivier Lagrasse's avatar Olivier Lagrasse

- Possibilite de revenir a la vue precedente lors de la selection a la

souris (et ceci plusieurs fois de suite). Mais le debordement de la pile 
(pour un nombre tres important de zoom) n'est pas encore gere. Peut etre 
une file ?...
parent 082d7664
......@@ -366,7 +366,7 @@ void Interface_graphic::on_export_file_triggered(){
void Interface_graphic::option_export_ok_pressed(){
// We have to save the option from _ui_time_selection_export and hide her if it is not do automatically
_ui_time_selection_export->hide();
QString filename = QFileDialog::getSaveFileName(this, tr("Export File"),
"",
tr("Images (*.svg)"));
......
......@@ -456,6 +456,55 @@ void Render_opengl::mousePressEvent(QMouseEvent * event){
Element_pos x_click, y_click;/* Store the OpenGL scene point where user had clicked */
Element_pos x_result;//, y_result;/* The click coordinates for the Data Structure. */
/* If a right click was triggered, just restore the previous zoom */
if( Qt::RightButton == event->button() ){
/* Just a special case: if a zoom box is currently drawing, the right click is used
to cancel the drawing */
if ( true == _mouse_pressed)
return;
/* if there is no previous zoom box registered, return */
if (true == _previous_selection.empty())
return;
/* restore the previous values */
_state_scale = _previous_selection.top().x_scale;
_y_state_scale = _previous_selection.top().y_scale;
_state_translate = _previous_selection.top().x_translate;
_y_state_translate = _previous_selection.top().y_translate;
/* remove the previous value */
_previous_selection.pop();
updateGL();
#ifdef DEBUG_MODE_RENDER_OPENGL_
/* if there is no previous zoom box registered, return */
if (true == _previous_selection.empty())
return;
cerr << __FILE__ << " l." << __LINE__ << ":" << endl;
cerr << _previous_selection.top().x_scale << " "
<< _previous_selection.top().y_scale << " "
<< _previous_selection.top().x_translate << " "
<< _previous_selection.top().y_translate << endl << endl;
#endif
/* Then, return */
return;
}
/* else, registered current X and Y mouse position to draw a zoom box */
_mouse_x = event->x();
_new_mouse_x = _mouse_x;
......@@ -523,18 +572,18 @@ void Render_opengl::mouseMoveEvent(QMouseEvent * event){
}
void Render_opengl::mouseReleaseEvent(QMouseEvent * /*event*/){
Element_pos x_middle_selection;
Element_pos y_middle_selection;
Element_pos x_scaled_middle_selection;
Element_pos y_scaled_middle_selection;
Element_pos x_distance_between_state_origin_and_render_middle;
Element_pos y_distance_between_state_origin_and_render_middle;
void Render_opengl::mouseReleaseEvent(QMouseEvent * event){
Element_pos invert_buf_x;
Element_pos invert_buf_y;
Selection_ selection_stack_buf;
/* If a right click was triggered, just restore the previous zoom */
if( Qt::RightButton == event->button() )
return;
if (_new_mouse_x < _mouse_x){
invert_buf_x = _mouse_x;
_mouse_x = _new_mouse_x;
......@@ -560,12 +609,46 @@ void Render_opengl::mouseReleaseEvent(QMouseEvent * /*event*/){
return;
}
/* Now, register this position which will be used by a right clic */
selection_stack_buf.x_scale = _state_scale;
selection_stack_buf.y_scale = _y_state_scale;
selection_stack_buf.x_translate = _state_translate;
selection_stack_buf.y_translate = _y_state_translate;
_previous_selection.push(selection_stack_buf);
#ifdef DEBUG_MODE_RENDER_OPENGL_
cerr << __FILE__ << " l." << __LINE__ << ":" << endl;
cerr << _previous_selection.top().x_scale << " "
<< _previous_selection.top().y_scale << " "
<< _previous_selection.top().x_translate << " "
<< _previous_selection.top().y_translate << endl << endl;
#endif
apply_zoom_box(_mouse_x, _new_mouse_x, _mouse_y, _new_mouse_y);
}
void Render_opengl::apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_pos y_min, Element_pos y_max){
Element_pos x_middle_selection;
Element_pos y_middle_selection;
Element_pos x_scaled_middle_selection;
Element_pos y_scaled_middle_selection;
Element_pos x_distance_between_state_origin_and_render_middle;
Element_pos y_distance_between_state_origin_and_render_middle;
/*
* Now, we try to zoom on the selection rectangle. To perform this, the left of the selection rectangle must be fit with the left
* of the render area. Idem for the right, the top and the bottom.
*
* Thus, we need to know the difference the scale between the rectangle width and height and the render area width and height.
* Results are given by the scale: _screen_width/(_new_mouse_x - _mouse_x) for the horizontal dimension.
* Results are given by the scale: _screen_width/(x_max - x_min) for the horizontal dimension.
*
* Then, our selection rectangle is scaled. Nevertheless, it should not be centered inside the render area. So, we work out
* the correct x and y translation to make both the render area middle and the selection rectangle middle fit.
......@@ -580,8 +663,8 @@ void Render_opengl::mouseReleaseEvent(QMouseEvent * /*event*/){
* Work out the horizontal middle of the selection area (the selection area width divide by 2 plus the x left coordinate)
* Note: mouse positions are converted to render area coordinate with the coeff _render_width/_screen_width.
*/
x_middle_selection = (_mouse_x + (_new_mouse_x - _mouse_x)/2 )*(_render_width/_screen_width);
y_middle_selection = (_mouse_y + (_new_mouse_y - _mouse_y)/2 )*(_render_height/_screen_height);
x_middle_selection = (x_min + (x_max - x_min)/2 )*(_render_width/_screen_width);
y_middle_selection = (y_min + (y_max - y_min)/2 )*(_render_height/_screen_height);
/*
......@@ -589,8 +672,8 @@ void Render_opengl::mouseReleaseEvent(QMouseEvent * /*event*/){
*
* Work out the new selection middle position after applying the scale.
*/
x_scaled_middle_selection = (x_middle_selection + _state_translate - _default_entity_x_translate)*(_screen_width/((_new_mouse_x - _mouse_x)));
y_scaled_middle_selection = (y_middle_selection - -_y_state_translate - _ruler_height )*(_screen_height/((_new_mouse_y - _mouse_y)));
x_scaled_middle_selection = (x_middle_selection + _state_translate - _default_entity_x_translate)*(_screen_width/((x_max - x_min)));
y_scaled_middle_selection = (y_middle_selection + _y_state_translate - _ruler_height )*(_screen_height/((y_max - y_min)));
/*
* 2nd step:
......@@ -616,12 +699,12 @@ void Render_opengl::mouseReleaseEvent(QMouseEvent * /*event*/){
/* NOTE: do not use replace_scale() because the translate will be also modified */
int buf;
_state_scale *= _screen_width/(_new_mouse_x - _mouse_x);
_state_scale *= _screen_width/(x_max - x_min);
buf = (int)100*_state_scale;
_core->launch_action(Interface_console::_STATE_ZOOM_BOX_VALUE, &buf);
_y_state_scale *= _screen_height/(_new_mouse_y - _mouse_y);
_y_state_scale *= _screen_height/(y_max - y_min);
_mouse_pressed = false;
updateGL();
......
......@@ -59,6 +59,31 @@ struct Arrow_{
};
/*!
* \brief Structure used to store selection coordinate information.
*/
struct Selection_{
/*!
* \brief x scale.
*/
Element_pos x_scale;
/*!
* \brief y scale.
*/
Element_pos y_scale;
/*!
* \brief x translation.
*/
Element_pos x_translate;
/*!
* \brief y translation.
*/
Element_pos y_translate;
};
/*!
* \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
*/
......@@ -90,6 +115,11 @@ protected:
* \brief Contains event informations.
*/
std::vector<Event_> _events;
/*!
* \brief Contains the previous selection coordinates.
*/
std::stack<Selection_> _previous_selection;
/*!
* \brief Contains the parent instance.
......@@ -590,6 +620,14 @@ public:
*/
void update_visible_interval_value();
/*!
* \brief Scale the current view to the zoom box shape.
* \param x_min the x minimum position.
* \param x_max the x maximum position.
* \param y_min the y minimum position.
* \param y_max the y maximum position.
*/
void apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_pos y_min, Element_pos y_max);
/***********************************
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment