void Storage::mouseMoveEvent(QMouseEvent *anEvent) { QPoint pos = anEvent->pos() / scale_; if (anEvent->pos().x() < 0) pos.setX(0); if (width() < anEvent->pos().x()) pos.setX(width() - 1); if (anEvent->pos().y() < 0) pos.setY(0); if (height() < anEvent->pos().y()) pos.setY(height() - 1); /* изменяем прямоугольник */ if ((anEvent->buttons() & Qt::LeftButton) && BoundingBoxTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerBoundBox(pos, prev_cursor_pos_, rect); } /* изменяем эллипс */ if ((anEvent->buttons() & Qt::LeftButton) && EllipseTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerEllipse(pos, prev_cursor_pos_, ell); } /* изменяем стрелу */ if ((anEvent->buttons() & Qt::LeftButton) && ArrowTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerArrow(pos, prev_cursor_pos_, arrow); } /* перемещаем последнюю точку(курсор) многоугольника до создания(точка зафиксирется кликом) новой */ if (PolygonTool == tool_ && NewSelection == state_ && (anEvent->buttons() & Qt::LeftButton)) { QPolygon tmp = poly.getCoordinates(); tmp.setPoint(tmp.count() - 1, pos); poly.setCoordinates(tmp); repaint_needed_ = 1; } // if (-1 != focused_selection_ && // !(anEvent->buttons() & Qt::LeftButton)) { // checkForPoints(&pos); // } //here now 2 /* изменяем многоульник */ // if (-1 != hovered_point_.figureID && // !list_polygon_->isEmpty() && // PolyFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton) && // hovered_point_.figureID == focused_selection_) // { // polygon_.poly.clear(); // polygon_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // Polygon *poly = list_polygon_->at(hovered_point_.figureID); // poly->poly.setPoint(hovered_point_.pointID, pos); // for(int i=0;i< list_polygon_->at(hovered_point_.figureID)->poly.count();++i) // { // if(i!=hovered_point_.pointID) // polygon_.poly << list_polygon_->at(hovered_point_.figureID)->poly.point(i); // else // polygon_.poly << pos; // } // qDebug() << "polygon_.poly =" << polygon_.poly; // repaint_needed_ = 1; // } /* изменяем прямоульник */ // if (-1 != hovered_point_.figureID && // !list_bounding_box_->isEmpty() && // RectFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton)) // { // bounding_box_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // bounding_box_.rect.setTopLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.topLeft()); // bounding_box_.rect.setTopRight(list_bounding_box_->at(hovered_point_.figureID)->rect.topRight()); // bounding_box_.rect.setBottomRight(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomRight()); // bounding_box_.rect.setBottomLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomLeft()); // BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID); // if (0 == hovered_point_.pointID) // { // rect->rect.setTopLeft(pos); // bounding_box_.rect.setTopLeft(pos); // qDebug() << "rect->rect.topLeft" << rect->rect.topLeft(); // } // else if (1 == hovered_point_.pointID) // { // rect->rect.setTopRight(pos); // bounding_box_.rect.setTopRight(pos); // qDebug() << "rect->rect.topRight" << rect->rect.topRight(); // } // else if (2 == hovered_point_.pointID) // { // rect->rect.setBottomRight(pos); // bounding_box_.rect.setBottomRight(pos); // qDebug() << "rect->rect.bottomRight" << rect->rect.bottomRight(); // } // else if (3 == hovered_point_.pointID) // { // rect->rect.setBottomLeft(pos); // bounding_box_.rect.setBottomLeft(pos); // qDebug() << "rect->rect.bottomLeft" << rect->rect.bottomLeft(); // } // repaint_needed_ = 1; // } // /* изменяем эллипс */ // if (-1 != hovered_point_.figureID && // !list_ellipse_->isEmpty() && // EllipseFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton)) // { // ellipse_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // ellipse_.rect.setTopLeft(list_ellipse_->at(hovered_point_.figureID)->rect.topLeft()); // ellipse_.rect.setTopRight(list_ellipse_->at(hovered_point_.figureID)->rect.topRight()); // ellipse_.rect.setBottomRight(list_ellipse_->at(hovered_point_.figureID)->rect.bottomRight()); // ellipse_.rect.setBottomLeft(list_ellipse_->at(hovered_point_.figureID)->rect.bottomLeft()); // Ellipse *ell = list_ellipse_->at(hovered_point_.figureID); // if (0 == hovered_point_.pointID) // { // ell->rect.setTopLeft(pos); // ellipse_.rect.setTopLeft(pos); // qDebug() << "rect->rect.topLeft" << ell->rect.topLeft(); // } // else if (1 == hovered_point_.pointID) // { // ell->rect.setTopRight(pos); // ellipse_.rect.setTopRight(pos); // qDebug() << "rect->rect.topRight" << ell->rect.topRight(); // } // else if (2 == hovered_point_.pointID) // { // ell->rect.setBottomRight(pos); // ellipse_.rect.setBottomRight(pos); // qDebug() << "rect->rect.bottomRight" << ell->rect.bottomRight(); // } // else if (3 == hovered_point_.pointID) // { // ell->rect.setBottomLeft(pos); // ellipse_.rect.setBottomLeft(pos); // qDebug() << "rect->rect.bottomLeft" << ell->rect.bottomLeft(); // } // repaint_needed_ = 1; // } // /* изменяем стрелу */ // if (-1 != hovered_point_.figureID && // !list_arrow_->isEmpty() && // ArrowFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton)) // { // arrow_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // arrow_.line.setP1(list_arrow_->at(hovered_point_.figureID)->line.p1()); // arrow_.line.setP2(list_arrow_->at(hovered_point_.figureID)->line.p2()); // Arrow *arrow = list_arrow_->at(hovered_point_.figureID); // if (0 == hovered_point_.pointID) // { // arrow->line.setP1(pos); // arrow_.line.setP1(pos); // qDebug() << "arrow->line.p1" << arrow->line.p1(); // } // else if (1 == hovered_point_.pointID) // { // arrow->line.setP2(pos); // arrow_.line.setP2(pos); // qDebug() << "arrow->line.p2" << arrow->line.p2(); // } // repaint_needed_ = 1; // } /* когда изображение слишком большое(необходима прокрутка) */ if ((anEvent->buttons() & Qt::MiddleButton) && (scroll_area_->size().height() < size().height() || scroll_area_->size().width() < size().width())) { QPoint globPos = mapToGlobal(pos); QPoint prev = mapToGlobal(prev_cursor_pos_); int horValue = scroll_area_->horizontalScrollBar()->value(); // scroll_area_->horizontalScrollBar() int verValue = scroll_area_->verticalScrollBar()->value(); QPoint delta = globPos - prev; prev_cursor_pos_ = pos; horValue += delta.x(); verValue += delta.y(); scroll_area_->horizontalScrollBar()->setValue(horValue); scroll_area_->verticalScrollBar()->setValue(verValue); } if (repaint_needed_) { update(); repaint_needed_ = 0; } }
/*! * With the help of this event all the mouse movements are being tracked. */ void ImageHolder::mouseMoveEvent(QMouseEvent *anEvent) { QPoint pos = anEvent->pos() / scale_; if (anEvent->pos().x() < 0) pos.setX(0); if (width() < anEvent->pos().x()) pos.setX(width() - 1); if (anEvent->pos().y() < 0) pos.setY(0); if (height() < anEvent->pos().y()) pos.setY(height() - 1); /* modifying rectangle */ if ((anEvent->buttons() & Qt::LeftButton) && BoundingBoxTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerBoundBox(pos, prev_cursor_pos_, &(bounding_box_.rect)); } /* moving last point of the poly during creating a new one */ if (PolygonTool == tool_ && NewSelection == state_ && (anEvent->buttons() & Qt::LeftButton)) { polygon_.poly.setPoint(polygon_.poly.count() - 1, pos); repaint_needed_ = 1; } if (-1 != focused_selection_ && !(anEvent->buttons() & Qt::LeftButton)) { checkForPoints(&pos); } /* editing polygons */ if (-1 != hovered_point_.figureID && !list_polygon_->isEmpty() && PolyFigure == hovered_point_.figure && (anEvent->buttons() & Qt::LeftButton) && hovered_point_.figureID == focused_selection_) { Polygon *poly = list_polygon_->at(hovered_point_.figureID); poly->poly.setPoint(hovered_point_.pointID, pos); repaint_needed_ = 1; } /* editing bounding boxes */ if (-1 != hovered_point_.figureID && !list_bounding_box_->isEmpty() && RectFigure == hovered_point_.figure && (anEvent->buttons() & Qt::LeftButton)) { BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID); if (0 == hovered_point_.pointID) rect->rect.setTopLeft(pos); else if (1 == hovered_point_.pointID) rect->rect.setTopRight(pos); else if (2 == hovered_point_.pointID) rect->rect.setBottomRight(pos); else if (3 == hovered_point_.pointID) rect->rect.setBottomLeft(pos); repaint_needed_ = 1; } /* moving image when it's too big */ if ((anEvent->buttons() & Qt::MiddleButton) && (scroll_area_->size().height() < size().height() || scroll_area_->size().width() < size().width())) { QPoint globPos = mapToGlobal(pos); QPoint prev = mapToGlobal(prev_cursor_pos_); int horValue = scroll_area_->horizontalScrollBar()->value(); int verValue = scroll_area_->verticalScrollBar()->value(); QPoint delta = globPos - prev; prev_cursor_pos_ = pos; horValue += delta.x(); verValue += delta.y(); scroll_area_->horizontalScrollBar()->setValue(horValue); scroll_area_->verticalScrollBar()->setValue(verValue); } if (repaint_needed_) { update(); repaint_needed_ = 0; } }