예제 #1
0
void QB2Draw::DrawSolidPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color& /*unused*/) {
    if (painter==NULL) return; //Check the painter

    painter->setPen(Qt::white); //set the pen color
    painter->setBrush(Qt::transparent); //set the brush color
    QPolygon pol; //Calculate the polygon
    for (int i=0; i<vertexCount; i++) { //Add all points to polygon
        pol.insert(i,toQPoint(vertices[i]));
    }
    painter->drawPolygon(pol); //Draw the polygon
}
예제 #2
0
void QB2Draw::DrawPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color& /*unused*/) {
    if (painter==NULL) return; //Check the painter

    QPen pen;//Configure the pen
    pen.setBrush(Qt::white); //Set the pen color
    pen.setWidth(1); //Set pen width
    painter->setPen(pen); //Assign the pen
    painter->setBrush(Qt::transparent); //Set brush trasparent
    QPolygon pol; //Calculate the polygon
    for (int i=0; i<vertexCount; i++) { //Add all points to the polygon
        pol.insert(i,toQPoint(vertices[i]));
    }
    painter->drawPolyline(pol); //Draw the polyline
}
예제 #3
0
/*!
 * \see drawBoundingBoxes(QPainter *aPainter, QPen *aPen)
 * \see drawPolygons(QPainter *aPainter, QPen *aPen)
 *
 * It contains drawing of the confirmed and not confirmed selections either.
 */
void
ImageHolder::paintEvent(QPaintEvent *anEvent)
{
	QLabel::paintEvent(anEvent);

	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	//painter.setRenderHint(QPainter::SmoothPixmapTransform);
	QPen pen;

	if (NoTool != tool_) {
		pen.setWidth(1);
		pen.setColor(QColor(Qt::black));
		pen.setStyle(Qt::DashLine);
		painter.setPen(pen);

		if (BoundingBoxTool == tool_) {
			/* scaling */
			QRect bbox = bounding_box_.rect;
			QPoint bboxTopLeft = bbox.topLeft() * scale_;
			QPoint bboxBottomRight = bbox.bottomRight() * scale_;

			bbox.setTopLeft(bboxTopLeft);
			bbox.setBottomRight(bboxBottomRight);

			painter.drawRect(bbox);
		}
		else if (PolygonTool == tool_) {
			/* scaling */
			QPoint point;
			QPolygon poly = polygon_.poly;
			for (int i = 0; i < poly.size(); i++) {
				point.setX(poly.at(i).x());
				point.setY(poly.at(i).y());
				point *= scale_;
				poly.remove(i);
				poly.insert(i, point);
			}
			painter.drawPolygon(poly);
		}
	}

	/* drawing bounding boxes */
	drawBoundingBoxes(&painter, &pen);
	drawPolygons(&painter, &pen);
}
예제 #4
0
void Storage::paintEvent(QPaintEvent *anEvent)
{
    QLabel::paintEvent(anEvent);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    //painter.setRenderHint(QPainter::SmoothPixmapTransform);
    QPen pen;

    if (NoTool != tool_) {
        pen.setWidth(5);
        pen.setColor(QColor(Qt::white));
        pen.setStyle(Qt::DashLine);
        painter.setPen(pen);

        if (BoundingBoxTool == tool_) {
            /* с учётом масштаба */
            QRect bbox = rect.getCoordinates();
            QPoint bboxTopLeft = bbox.topLeft() * scale_;
            QPoint bboxBottomRight = bbox.bottomRight() * scale_;

            bbox.setTopLeft(bboxTopLeft);
            bbox.setBottomRight(bboxBottomRight);

            painter.drawRect(bbox);
        }
        else if (EllipseTool == tool_) {
            /* с учётом масштаба */
            QRect elli = ell.getCoordinates().normalized();
            QPoint ellTopLeft = elli.topLeft() * scale_;
            QPoint ellBottomRight = elli.bottomRight() * scale_;

            elli.setTopLeft(ellTopLeft);
            elli.setBottomRight(ellBottomRight);

            if(1 < elli.height() && 1 < elli.width() )
            {
                painter.drawEllipse(elli);
            }
//            painter.drawRect(ell);
        }
        else if (ArrowTool == tool_) {
            /* с учётом масштаба */
            QLineF line = arrow.getCoordinates();
            QPointF p1 = line.p1() * scale_;
            QPointF p2 = line.p2() * scale_;

            line.setP1(p1);
            line.setP2(p2);

            if(1 < line.length())
            {
                double angle = ::acos(line.dx() / line.length());
                qreal Pi = atan(1)*4;
                if (line.dy() >= 0)
                    angle = (Pi * 2) - angle;

                QPointF arrowP1 = line.p1() + QPointF(sin(angle + Pi / 3) * arrow_size_,
                                                cos(angle + Pi / 3) * arrow_size_);
                QPointF arrowP2 = line.p1() + QPointF(sin(angle + Pi - Pi / 3) * arrow_size_,
                                                cos(angle + Pi - Pi / 3) * arrow_size_);

                QPolygonF arrowTop;
                arrowTop.clear();
                arrowTop << line.p1() << arrowP1 << arrowP2;

                painter.drawLine(line);
                painter.drawPolygon(arrowTop);///111
                qDebug() << "arrowTop" << arrowTop;
                arrow_top_ = arrowTop;
            }

            }
        else if (PolygonTool == tool_) {
            /* с учётом масштаба */
            QPoint point;
            QPolygon pol = poly.getCoordinates();
            for (int i = 0; i < pol.size(); i++) {
                point.setX(pol.at(i).x());
                point.setY(pol.at(i).y());
                point *= scale_;
                pol.remove(i);
                pol.insert(i, point);
            }
            painter.drawPolygon(pol);
        }
    }

    /* рисуем фигуры */
    drawBoundingBoxes(&painter, &pen);
    drawPolygons(&painter, &pen);
    drawEllipses(&painter, &pen);
    drawArrows(&painter, &pen);
}
예제 #5
0
/*!
 * parameters of polygons may vary depending on whether poly is selected or not or
 * whether it's label is main or not.
 */
void
ImageHolder::drawPolygons(
	QPainter *aPainter,
	QPen *aPen
) const
{
	if (0 == list_polygon_)
	{
		return;
		/* NOTREACHED */
	}

	Qt::PenStyle penStyle = Qt::SolidLine;
	/* default width is hardcoded */
	int width = 2;
	/* drawing all the polygons */
	for (int i = 0; i < list_polygon_->size(); i++) {
		penStyle = Qt::SolidLine;
		int labelID = list_polygon_->at(i)->label_ID_;

		/* setting color for the label of current bbox */
		if (labelID < list_label_color_->count())
			aPen->setColor(QColor(list_label_color_->at(labelID)));
		/* in case there is no color for such label */
		else
			aPen->setColor(QColor(Qt::white));

		/* checking whether labeled area is of main object or not */
		if (labelID == *main_label_)
			width = 3;
		else
			width = 2;

		/* changing the line style and width if current area is selected(focused) */
		if (PolyFigure == focused_selection_type_ &&
			focused_selection_ == i) {
			penStyle = Qt::DotLine;
			width = 3;
		}

		QPoint point;
		QPolygon poly = list_polygon_->at(i)->poly;
		for (int j = 0; j < poly.size(); j++) {
			point.setX(poly.at(j).x());
			point.setY(poly.at(j).y());
			/* scaling */
			point *= scale_;
			poly.remove(j);
			poly.insert(j, point);

			/* in case if it's focused */
			if (focused_selection_ == i &&
				focused_selection_type_ == PolyFigure) {
				QPen circPen;
				circPen.setWidth(2);
				circPen.setStyle(Qt::SolidLine);
				circPen.setColor(aPen->color());
				aPainter->setPen(circPen);
				/* filling the point if it is hovered */
				if ((j == hovered_point_.pointID &&
					i == hovered_point_.figureID &&
					PolyFigure == hovered_point_.figure) ||
					j == selected_point_) {
					QBrush brush;
					brush.setColor(aPen->color());
					brush.setStyle(Qt::SolidPattern);
					aPainter->setBrush(brush);
				}
				aPainter->drawEllipse(point, point_radius_, point_radius_);
				aPainter->setBrush(Qt::NoBrush);
			}
		}

		aPen->setWidth(width);
		aPen->setStyle(penStyle);
		aPainter->setPen(*aPen);

		aPainter->drawPolygon(poly);
		/* drawing label IDs of these polygons */
		QString labelIDText =
			QString("%1").arg(labelID);
		QRect rect = poly.boundingRect();
		int x = rect.center().x();
		int y = rect.center().y();

		aPainter->drawText(
			x,
			y,
			20,
			20,
			Qt::AlignHCenter,
			labelIDText
			);
	}

}