/*! * Every time mouse was clicked it's position is stored in the prev_cursor_pos_ * Depending on current state and selected tool it creates new points or * starts new rects */ void ImageHolder::mousePressEvent(QMouseEvent *anEvent) { /* remembering coordinates of the click */ prev_cursor_pos_ = anEvent->pos() / scale_; QPoint pos = anEvent->pos() / scale_; if (anEvent->buttons() & Qt::LeftButton) { /* clearing the selected area if it is not confirmed */ if (NewSelection == state_ && BoundingBoxTool == tool_) { bounding_box_.rect.setRect(-1, -1, 0, 0); state_ = StandBy; } /* making new points for poly */ if (PolygonTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerPolygon(pos, &(polygon_.poly)); } /* starting new selection by click */ if (StandBy == state_ && NoTool != tool_ && -1 == focused_selection_) { state_ = NewSelection; emit selectionStarted(); polygon_.poly.clear(); if (PolygonTool == tool_) { polygon_.poly << prev_cursor_pos_; } } /* selecting a point */ selected_point_ = -1; repaint_needed_ = 1; if (-1 != hovered_point_.figureID && !list_polygon_->isEmpty() && PolyFigure == hovered_point_.figure && hovered_point_.figureID == focused_selection_) { selected_point_ = hovered_point_.pointID; } } if (repaint_needed_) { update(); repaint_needed_ = 0; } }
void Storage::mousePressEvent(QMouseEvent *anEvent) { /* запоминаем координаты клика */ prev_cursor_pos_ = anEvent->pos() / scale_; QPoint pos = anEvent->pos() / scale_; if (anEvent->buttons() & Qt::LeftButton) { /* очищаем выбранную область если она не была подтверждена(для прямоугольника) */ if (NewSelection == state_ && BoundingBoxTool == tool_) { rect.setCoordinates(QRect(-1, -1, 0, 0)); state_ = StandBy; } /* очищаем выбранную область если она не была подтверждена(для эллипса) */ if (NewSelection == state_ && EllipseTool == tool_) { ell.setCoordinates(QRect(-1, -1, 0, 0)); state_ = StandBy; } /* очищаем выбранную область если она не была подтверждена(для стрелы) */ if (NewSelection == state_ && ArrowTool == tool_) { arrow.setCoordinates(QLineF(-1, -1, -2, -2)); state_ = StandBy; } /* добавляем новые точки для многоугольника */ if (PolygonTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerPolygon(pos, poly); } /* начинаем выбирать новую область по клику */ if (StandBy == state_ && NoTool != tool_ /*&& -1 == focused_selection_*/) { state_ = NewSelection; // emit selectionStarted(); poly.setCoordinates(QPolygon()); if (PolygonTool == tool_) { poly.setCoordinates(poly.getCoordinates() << prev_cursor_pos_); // polygon_.poly << prev_cursor_pos_; } } /* выбираем точку */ // selected_point_ = -1; repaint_needed_ = 1; // if (-1 != hovered_point_.figureID && // !list_polygon_->isEmpty() && // PolyFigure == hovered_point_.figure && // hovered_point_.figureID == focused_selection_) // { // selected_point_ = hovered_point_.pointID; // } // } if (repaint_needed_) { update(); repaint_needed_ = 0; } }