bool GraphicsViewPolylineInput_non_templated_base::mousePressEvent(QGraphicsSceneMouseEvent *event) { if( event->modifiers() ){ return false; } if( event->button() != ::Qt::RightButton && event->button() != ::Qt::LeftButton ){ return false; } polygon.push_back(event->scenePos()); if(path_item){ scene_->removeItem(path_item); delete path_item; path_item = NULL; } if( (event->button() == ::Qt::RightButton) || (polygon.size() == n_) ){ // call the virtual function generate_polygon(), that emit a // CGAL::Object containing a list of points generate_polygon(); polygon.clear(); if(b){ scene_->removeItem(b); delete b; b = NULL; } if(e){ scene_->removeItem(e); delete e; e = NULL; } return true; } if(event->button() == ::Qt::LeftButton){ QPainterPath qpp; qpp.addPolygon(polygon); path_item = new QGraphicsPathItem(qpp); path_item->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); scene_->addItem(path_item); return true; } return false; }
bool GUI::on_display_area_button_press_handler(GdkEventButton *event_button, Controller &controller) { if (button_zoom_pointer.get_active() ) { // This is in relationship with the button setting for mouse selection of zoom center. if ( controller.mouse_into_image && controller.mouse_curser_changed == 1 && event_button->button == 1 ) { // Settings the zoom center coordinates by mutiplying the coordinates from inside the image per factors: controller.mouse_zoom_center_x = static_cast<float>(controller.mouse_inside_image_x) * controller.factor_width ; controller.mouse_zoom_center_y = static_cast<float>(controller.mouse_inside_image_y) * controller.factor_height ; controller.process_after_applying() ; // We register current frame in vector<cv::Mat> for undo-redo. // It convert current_image_to_process as src to RGB(A) in dst current_image_to_display. set_img(controller.current_image_to_process, controller.current_image_to_display, controller) ; // It auto process conversion to RGB(A). // Reset cursor. main_window_gdk_window->set_cursor() ; // Reset control variables: controller.mouse_curser_changed = -1 ; controller.draw_offset = 0.0 ; if ( button_zoom_pointer.get_active() ) { // If button pressed, raise it. button_zoom_pointer.set_active(false) ; } } else if (event_button->button != 1) { // Reset cursor. main_window_gdk_window->set_cursor() ; controller.reset_zoom_center(controller.current_image_to_process) ; controller.mouse_curser_changed = -1 ; if ( button_zoom_pointer.get_active() ) { // If button pressed, raise it. button_zoom_pointer.set_active(false) ; } } } else if ( button_draw_rect.get_active() || button_draw_line.get_active() || button_draw_circle.get_active() || button_draw_ellipse.get_active() || button_draw_polygon.get_active() || button_draw_star.get_active() || button_draw_text.get_active() ) { if ( controller.mouse_into_image && controller.mouse_curser_changed == 1 && event_button->button == 1 ) { if ( (controller.drawning_status == -1) || (controller.drawning_status == 1) ) { // Getting the drawning coordinates onto the real (not resized) image by multiplying per factors: controller.mouse_draw_x1 = static_cast<float>(controller.mouse_inside_image_x) * controller.factor_width ; controller.mouse_draw_y1 = static_cast<float>(controller.mouse_inside_image_y) * controller.factor_height ; controller.drawning_status = 0 ; controller.saved_frame = controller.current_image_to_process.clone() ; if ( button_draw_line.get_active() ) { goto fake_mouse_1_button_press ; } if ( button_draw_text.get_active() ) { goto fake_mouse_1_button_press ; } return false ; } else if (controller.drawning_status == 0) { fake_mouse_1_button_press : // Getting the drawning coordinates onto the real (not resized) image by multiplying per factors: controller.mouse_draw_x2 = static_cast<float>(controller.mouse_inside_image_x) * controller.factor_width ; controller.mouse_draw_y2 = static_cast<float>(controller.mouse_inside_image_y) * controller.factor_height ; controller.drawning_status = 1 ; cv::Scalar color(draw_color.get_blue_u() >> 8, draw_color.get_green_u() >> 8, draw_color.get_red_u() >> 8, draw_color.get_alpha_u() >> 8) ; cv::Mat frame = controller.current_image_to_process.clone() ; if (button_draw_line.get_active() ) { if ( controller.polylines_points_nb == 0) { controller.polylines_start_rect = cv::Rect( cv::Point(controller.mouse_draw_x1-7, controller.mouse_draw_y1-7), cv::Size(15, 15) ) ; } controller.polylines.push_back( cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1)) ; controller.polylines_points_nb++ ; if ( controller.polylines_points_nb > 1) { if ( controller.polylines_start_rect.contains(cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1)) ) { draw_polylines(frame , controller.polylines, true, (draw_thickness < 0), color, (draw_thickness < 0) ? 0 : draw_thickness , draw_line_type) ; controller.polylines_points_nb = 0 ; controller.polylines.clear() ; controller.polylines.shrink_to_fit() ; } else { draw_polylines(frame , controller.polylines, false, false, color, (draw_thickness < 0) ? 0 : draw_thickness, draw_line_type) ; } } } else if (button_draw_rect.get_active()) { cv::Rect rect( cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), cv::Point(controller.mouse_draw_x2, controller.mouse_draw_y2) ) ; draw_rect(frame, rect, color, draw_thickness, draw_line_type) ; } else if (button_draw_circle.get_active() ) { const int radius = static_cast<int>(roundf( sqrtf(powf(static_cast<float>(controller.mouse_draw_x2)-static_cast<float>(controller.mouse_draw_x1), 2) + powf(static_cast<float>(controller.mouse_draw_y2)-static_cast<float>(controller.mouse_draw_y1), 2))) ) ; draw_circle(frame, cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), radius, color, draw_thickness, draw_line_type) ; } else if (button_draw_ellipse.get_active() ) { const int distance_x = abs(controller.mouse_draw_x1-controller.mouse_draw_x2) ; const int distance_y = abs(controller.mouse_draw_y1-controller.mouse_draw_y2) ; const cv::RotatedRect rot_rect(cv::Point2f( static_cast<float>(controller.mouse_draw_x1), static_cast<float>(controller.mouse_draw_y1) ), cv::Size(abs( distance_x * 2 ), abs( distance_y * 2 ) ), 0.0 ) ; draw_ellipse(frame, rot_rect, color, draw_thickness, draw_line_type) ; } else if (button_draw_polygon.get_active() && controller.config_draw_success == Gtk::RESPONSE_OK ) { const double radius = round( sqrt (pow(static_cast<double>(controller.mouse_draw_x2)-static_cast<double>(controller.mouse_draw_x1), 2) + pow(static_cast<double>(controller.mouse_draw_y2)-static_cast<double>(controller.mouse_draw_y1), 2)) ) ; vector<cv::Point> polygon ; double offset_correct = 0.0 ; if ((controller.polygon_edges > 4) && (controller.polygon_edges % 2 == 1)) { offset_correct = 360.0 / controller.polygon_edges / 2.0 / 2.0 ; } bool fill = false ; if ( ! controller.polygon_strikethrough && draw_thickness < 0 ) { fill = true ; } generate_polygon(controller.polygon_edges, radius, cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), polygon, controller.polygon_strikethrough, false, controller.polygon_offset + controller.draw_offset + offset_correct) ; draw_polylines(frame, polygon, true, fill, color, ((draw_thickness < 0) ? 0 : draw_thickness) , draw_line_type) ; } else if (button_draw_text.get_active() && controller.config_draw_success == Gtk::RESPONSE_OK ) { int italic_flags = (controller.put_text_is_italic) ? cv::FONT_ITALIC : 0 ; draw_text(frame, controller.put_text_string, cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), controller.put_text_font_face | italic_flags, controller.put_text_font_scale, color, ((draw_thickness < 0) ? 0 : draw_thickness), draw_line_type) ; controller.drawning_status = 1 ; } else if (button_draw_star.get_active() && controller.config_draw_success == Gtk::RESPONSE_OK ) { const double radius = round( sqrt (pow(static_cast<double>(controller.mouse_draw_x2)-static_cast<double>(controller.mouse_draw_x1), 2) + pow(static_cast<double>(controller.mouse_draw_y2)-static_cast<double>(controller.mouse_draw_y1), 2)) ) ; vector<cv::Point> star ; bool join_stroke = true ; bool fill = false ; if ( controller.star_correcting && (! controller.star_strokes) && (controller.star_pikes == 5 || controller.star_pikes == 6) ) { if ( ! controller.star_flower && ! controller.star_strikethrough && draw_thickness < 0 ) { fill = true ; } switch (controller.star_pikes) { case 5 : generate_pentagram(radius, cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), star, controller.star_strikethrough, controller.star_flower, (360.0 / 5.0 / 2.0 / 2.0) + controller.star_offset + controller.draw_offset ) ; break ; case 6 : generate_hexagram(radius, cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), star, controller.star_strikethrough, controller.star_flower, controller.star_offset + controller.draw_offset ) ; break ; } } else if ( ! controller.star_strokes) { if ( ! controller.star_flower && ! controller.star_strikethrough && ! controller.star_strokes && draw_thickness < 0 ) { fill = true ; } generate_star(controller.star_pikes , radius , cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), star, controller.star_strikethrough, controller.star_flower, controller.star_offset + controller.draw_offset + ((controller.star_pikes == 5) ? (360.0 / 5.0 / 2.0 / 2.0) : 0) ) ; } else { generate_polygon(controller.star_pikes, radius, cv::Point(controller.mouse_draw_x1, controller.mouse_draw_y1), star, false, true, controller.star_offset + controller.draw_offset ) ; join_stroke = false ; } draw_polylines(frame, star, join_stroke, fill, color, ((draw_thickness < 0) ? 0 : draw_thickness), draw_line_type) ; } // We register current frame in vector<cv::Mat> for undo-redo. controller.process_after_applying(frame) ; // It convert current_image_to_process as src to RGB(A) in dst current_image_to_display. set_img(frame, controller.current_image_to_display, controller) ; // It auto process conversion to RGB(A). frame.release() ; controller.saved_frame.release() ; controller.mouse_curser_changed = -1 ; return false ; } } else if (event_button->button == 3) {