Beispiel #1
1
QGraphicsItem* CGraphicsPolylineItem::createItem()
{
	QGraphicsPathItem* pItem = new QGraphicsPathItem(m_Parent);
	drawPen(pItem);
	QPainterPath path;
	QPolygonF d;
	QStringList lstPath = GET_VALUE(d).split(' ');
	int iCount = lstPath.size();
	for (int j = 0; j < iCount; j++)
	{
		QStringList lstPoint = lstPath[j].split(',');
		d.append(QPointF(lstPoint[0].toDouble(), lstPoint[1].toDouble()));
		lstPoint.clear();
	}
	if (d.count() > 0)
	{
		path.moveTo(d[0]);
	}
	for (int i = 1; i < d.count() ; i++)
	{
		path.lineTo(d[i]);
	}
	pItem->setPath(path);
	return pItem;
}
Beispiel #2
0
void TableTitleView::resizeTitle(float width, float height)
{
	QPolygonF pol;
	pol=box->polygon();

	if(pol.isEmpty())
	{
		pol.append(QPointF(0.0f,0.0f));
		pol.append(QPointF(1.0f,0.0f));
		pol.append(QPointF(1.0f,1.0f));
		pol.append(QPointF(0.0f,1.0f));
	}

	this->resizePolygon(pol, width, height);
	box->setPolygon(pol);

	if(schema_name->text()==" ")
		obj_name->setPos((box->boundingRect().width() - obj_name->boundingRect().width())/2.0f, VERT_SPACING);
	else
	{
		schema_name->setPos((box->boundingRect().width() - (schema_name->boundingRect().width() + obj_name->boundingRect().width()))/2.0f, VERT_SPACING);
		obj_name->setPos(schema_name->pos().x() + schema_name->boundingRect().width(), VERT_SPACING);
		obj_name->setPos(schema_name->pos().x() + schema_name->boundingRect().width(), VERT_SPACING);
	}

	this->bounding_rect.setTopLeft(this->pos());
	this->bounding_rect.setSize(QSizeF(box->boundingRect().width(), box->boundingRect().height()));
}
Beispiel #3
0
void UMLGeneralizationLine::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * parent )
{
	QPolygonF head;
	head.append( QPointF( 0.0, 0.0 ) );
	head.append( QPointF( cos( PI / 6 ), -sin( PI / 6 ) ) );
	head.append( QPointF( cos( -PI / 6 ), -sin( -PI / 6 ) ) );

	QPainterPath path;
	path.addPolygon( head );

	QTransform transform;
	transform.translate( this->line().p2().x(), this->line().p2().y() );
	transform.scale( ARROW_HEAD_SIZE, ARROW_HEAD_SIZE );
	transform.rotate( 180.0 - this->line().angle() );

	QTransform backup( painter->transform() );
	painter->setTransform( transform, true );
	painter->fillPath( path, QColor( "blue" ) );
	painter->setPen( this->pen() );
	painter->drawPolygon( head );
	painter->setTransform( backup );

	qreal triangleHeight = ::sqrt( 3.0 ) / 2.0;
	QPointF realP2( transform.map( QLineF( QPointF( 0.0, 0.0 ), QPointF( triangleHeight, 0.0 ) ) ).p2() );
	painter->drawLine( this->line().p1(), realP2 );

}
Beispiel #4
0
QGraphicsItem* CGraphicsDiamondItem::createItem()
{
	QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent);

	drawPen(pItem);
	drawBrush(pItem);

	qreal x;
	qreal y;
	qreal w;
	qreal h;

	x = GET_VALUE(x).toFloat();
	y = GET_VALUE(y).toFloat();
	w = GET_VALUE(w).toFloat();
	h = GET_VALUE(h).toFloat();

	QPolygonF d;
	d.append(QPointF(x + w/2,y));
	d.append(QPointF(x + w,y + h/2));
	d.append(QPointF(x + w/2,y + h));
	d.append(QPointF(x,y + h/2));
	pItem->setPolygon(d);

	return pItem;
}
Beispiel #5
0
void CreateObjectTool::startNewMapObject(const QPointF &pos,
                                         ObjectGroup *objectGroup)
{
    Q_ASSERT(!mNewMapObjectItem);

    MapObject *newMapObject = new MapObject;
    newMapObject->setPosition(pos);

    if (mMode == CreatePolygon || mMode == CreatePolyline) {
        MapObject::Shape shape = mMode == CreatePolygon ? MapObject::Polygon
                                                        : MapObject::Polyline;
        QPolygonF polygon;
        polygon.append(QPointF());
        newMapObject->setPolygon(polygon);
        newMapObject->setShape(shape);

        polygon.append(QPointF()); // The last point is connected to the mouse
        mOverlayPolygonObject->setPolygon(polygon);
        mOverlayPolygonObject->setShape(shape);
        mOverlayPolygonObject->setPosition(pos);

        mOverlayPolygonItem = new MapObjectItem(mOverlayPolygonObject,
                                                mapDocument());
        mapScene()->addItem(mOverlayPolygonItem);
    }

    objectGroup->addObject(newMapObject);

    mNewMapObjectItem = new MapObjectItem(newMapObject, mapDocument());
    mapScene()->addItem(mNewMapObjectItem);
}
Beispiel #6
0
nmc::DkRotatingRect DkPolyRect::toRotatingRect() const {

	if (empty())
		return nmc::DkRotatingRect();

	// find the largest rectangle
	std::vector<cv::Point> largeRect = toCvPoints();

	cv::RotatedRect rect = cv::minAreaRect(largeRect);

	// convert to corners
	nmc::DkVector xVec = nmc::DkVector(rect.size.width * 0.5f, 0);
	xVec.rotate(-rect.angle*DK_DEG2RAD);

	nmc::DkVector yVec = nmc::DkVector(0, rect.size.height * 0.5f);
	yVec.rotate(-rect.angle*DK_DEG2RAD);

	QPolygonF poly;
	poly.append(nmc::DkVector(rect.center - xVec + yVec).toQPointF());
	poly.append(nmc::DkVector(rect.center + xVec + yVec).toQPointF());
	poly.append(nmc::DkVector(rect.center + xVec - yVec).toQPointF());
	poly.append(nmc::DkVector(rect.center - xVec - yVec).toQPointF());

	nmc::DkRotatingRect rr;
	rr.setPoly(poly);

	return rr;
}
void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
	if (!shouldCalculateStuff(topLeft, bottomRight))
		return;

	QPolygonF p;
	p.append(QPointF(hAxis->posAtValue(0), vAxis->posAtValue(0)));
	plot_data *entry = dataModel->data().entry;
	for (int i = 0, count = dataModel->rowCount(); i < count; i++, entry++) {
		if (entry->in_deco && entry->stopdepth) {
			p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth))));
		} else {
			p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
		}
	}
	setPolygon(p);
	QLinearGradient pat(0, p.boundingRect().top(), 0, p.boundingRect().bottom());
	// does the user want the ceiling in "surface color" or in red?
	if (prefs.redceiling) {
		pat.setColorAt(0, getColor(CEILING_SHALLOW));
		pat.setColorAt(1, getColor(CEILING_DEEP));
	} else {
		pat.setColorAt(0, getColor(BACKGROUND_TRANS));
		pat.setColorAt(1, getColor(BACKGROUND_TRANS));
	}
	setPen(QPen(QBrush(Qt::NoBrush), 0));
	setBrush(pat);
}
Beispiel #8
0
// ============================================================================
/// Converts polygon into set of triangles.
QList<QPolygonF> triangulatePolygon( const QPolygonF& polygon )
{
	QList<QPolygonF> triangles;
	if ( polygon.size() < 3 )
	{
		qDebug("Can't create shape from polygon with less than 3 vertices!");
		return triangles;
	}
	if ( polygon.size() == 3 )
	{
		triangles.append( polygon );
		return triangles;
	}
	//qDebug("Triangulating polygon with %d vertices", polygon.size() );
	// triangulate here
	// create GPC polygon from QPolygonF
	gpc_vertex_list	vertexList;
	gpc_polygon		gpcpolygon;
	vertexList.num_vertices	= polygon.size();
	vertexList.vertex		= new gpc_vertex[ polygon.size() ];
	
	for( int i = 0; i < vertexList.num_vertices; i++ )
	{
		vertexList.vertex[i].x = polygon[i].x();
		vertexList.vertex[i].y = polygon[i].y();
	}
	
	gpcpolygon.num_contours		= 1;
	gpcpolygon.hole				= NULL;
	gpcpolygon.contour			 = &vertexList;
	
	// request triangles
	gpc_tristrip tristrip;
	
	gpc_polygon_to_tristrip( &gpcpolygon, &tristrip );
	
	// create triangles from tristrups
	for( int s = 0; s < tristrip.num_strips; s++ )
	{
		gpc_vertex_list& strip	= tristrip.strip[s];
		int numTriangles		= strip.num_vertices - 2;
		for ( int t = 0; t < numTriangles; t++ )
		{
			QPolygonF triangle;
			triangle.append( QPointF( strip.vertex[t].x,	strip.vertex[t].y ) );
			triangle.append( QPointF( strip.vertex[t+1].x,	strip.vertex[t+1].y ) );
			triangle.append( QPointF( strip.vertex[t+2].x,	strip.vertex[t+2].y ) );
			
			triangles.append( triangle );
		}
	}
	
	// release polygon
	delete[] vertexList.vertex;
	gpc_free_tristrip( &tristrip );
	
	//qDebug("%d triangles created", triangles.size() );
	
	return triangles;
}
Beispiel #9
0
void BaseTableView::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
	/* Case the table itself is not selected shows the child selector
		at mouse position */
	if(!this->isSelected())
	{
		QList<QGraphicsItem *> items;
		float cols_height, item_idx, ext_height=0;
		QRectF rect, rect1;

		items.append(columns->childItems());

		if(!hide_ext_attribs)
		{
			items.append(ext_attribs->childItems());
			ext_height=ext_attribs->boundingRect().height();
		}

		//Calculates the default item height
		cols_height=roundf((columns->boundingRect().height() + ext_height) / static_cast<float>(items.size()));

		//Calculates the item index based upon the mouse position
		rect=this->mapRectToItem(title, title->boundingRect());
		item_idx=(event->pos().y() - rect.bottom()) / cols_height;

		//If the index is invalid clears the selection
		if(item_idx < 0 || item_idx >= items.size())
		{
			this->hoverLeaveEvent(event);
			this->setToolTip(this->table_tooltip);
		}
		else if(!items.isEmpty())
		{
			QPolygonF pol;
			BaseObjectView *item=dynamic_cast<TableObjectView *>(items[item_idx]);

			//Configures the selection with the item's dimension
			if(obj_selection->boundingRect().height()!=item->boundingRect().height())
			{
				pol.append(QPointF(0.0f,0.0f));
				pol.append(QPointF(1.0f,0.0f));
				pol.append(QPointF(1.0f,1.0f));
				pol.append(QPointF(0.0f,1.0f));
				this->resizePolygon(pol, title->boundingRect().width() - (2.5 * HORIZ_SPACING),
														item->boundingRect().height());
				obj_selection->setPolygon(pol);
			}

			//Sets the selection position as same as item's position
			rect1=this->mapRectToItem(item, item->boundingRect());
			obj_selection->setVisible(true);
			obj_selection->setPos(QPointF(title->pos().x() + HORIZ_SPACING,-rect1.top()));

			//Stores the selected child object
			sel_child_obj=dynamic_cast<TableObject *>(item->getSourceObject());
			this->setToolTip(item->toolTip());
		}
	}
}
void HgTransformedQuad::getTransformedPoints(QPolygonF& poly) const
{
    poly.clear();
    poly.append(mTransformedPoints[0].toPointF());
    poly.append(mTransformedPoints[1].toPointF());
    poly.append(mTransformedPoints[2].toPointF());
    poly.append(mTransformedPoints[3].toPointF());
}
void DiveProfileItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
	if(!shouldCalculateStuff(topLeft, bottomRight))
		return;

	AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
	if (polygon().isEmpty())
		return;

	show_reported_ceiling = prefs.profile_dc_ceiling;
	reported_ceiling_in_red = prefs.profile_red_ceiling;

	/* Show any ceiling we may have encountered */
	if (prefs.profile_dc_ceiling && !prefs.profile_red_ceiling) {
		QPolygonF p = polygon();
		plot_data *entry = dataModel->data().entry + dataModel->rowCount()-1;
		for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) {
			if (!entry->in_deco) {
				/* not in deco implies this is a safety stop, no ceiling */
				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
			} else if (entry->stopdepth < entry->depth) {
				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->stopdepth)));
			} else {
				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)));
			}
		}
		setPolygon(p);
	}

		// This is the blueish gradient that the Depth Profile should have.
	// It's a simple QLinearGradient with 2 stops, starting from top to bottom.
	QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
	pat.setColorAt(1, getColor(DEPTH_BOTTOM));
	pat.setColorAt(0, getColor(DEPTH_TOP));
	setBrush(QBrush(pat));

	int last = -1;
	for (int i = 0, count  = dataModel->rowCount(); i < count; i++) {

		struct plot_data *entry = dataModel->data().entry+i;
		if (entry->depth < 2000)
			continue;

		if ((entry == entry->max[2]) && entry->depth / 100 != last) {
			plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignBottom, getColor(SAMPLE_DEEP));
			last = entry->depth / 100;
		}

		if ((entry == entry->min[2]) && entry->depth / 100 != last) {
			plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignTop, getColor(SAMPLE_SHALLOW));
			last = entry->depth / 100;
		}

		if (entry->depth != last)
			last = -1;
	}
}
Beispiel #12
0
QPainterPath Edge::shape() const
{
   QPainterPath path ;
   QPolygonF poly;
   poly.append(tarP_-(QPointF(2,2)));
   poly.append(tarP_+(QPointF(2,2)));
   poly.append(srcP_-(QPointF(2,2)));
   poly.append(srcP_+(QPointF(2,2)));
   path.addPolygon(poly);
   return path;
}
Beispiel #13
0
void GraphScaled::triangleAddQPolygonF(QList<V_Triangle> triangle,QList<QPolygonF> &polygon){
    V_Triangle v;
    for(int i = 0;i<triangle.length();i++){
        v = triangle.at(i);
        QPolygonF p = QPolygonF();
        p.append(QPoint(v.x1,v.y1));
        p.append(QPoint(v.x2,v.y2));
        p.append(QPoint(v.x3,v.y3));
        polygon.append(p);
    }
}
Beispiel #14
0
QPolygonF QGVEdge::toBox(const QLineF &line) const
{
    QLineF n = line.normalVector();
    QPointF o(n.dx() * 0.5, n.dy() * 0.5);

    QPolygonF polygon;
    polygon.append(line.p1() + o);
    polygon.append(line.p2() + o);
    polygon.append(line.p2() - o);
    polygon.append(line.p1() - o);
    return polygon;
}
QPainterPath CopyFilterGUIConnectionItem::shape() const
{
	QLineF l = line();

	QPainterPath path;
	path.setFillRule(Qt::WindingFill);
	double length = line().length();
	if (length > 0)
	{
		double offset = min(length, maxArrowSize);
		QLineF unit = l.unitVector();
		QLineF normal = l.normalVector().unitVector();
		QPointF v(unit.dx(), unit.dy());
		QPointF n(normal.dx(), normal.dy());
		QPointF p2 = l.p2();

		QPointF p3 = p2 - v * offset + 0.5 * n * offset;
		QPointF p4 = p2 - v * offset - 0.5 * n * offset;
		QPolygonF polygon;
		polygon.append(p4);
		polygon.append(p3);
		polygon.append(p2);
		path.addPolygon(polygon);

		QPolygonF polygon2;
		QPointF p1 = l.p1();
		polygon2.append(p2 + 3 * n);
		polygon2.append(p2 - 2 * n);
		polygon2.append(p1 - 2 * n);
		polygon2.append(p1 + 3 * n);
		path.addPolygon(polygon2);

		if (factor != 1.0 || isDecibel)
		{
			QFont font;
			font.setPixelSize(10);
			QPointF center = (l.p1() + l.p2()) / 2;
			QString text = QString("%1").arg(factor);
			if (isDecibel)
				text += " dB";

			QFontMetrics fontMetrics(font);
			QSizeF size = fontMetrics.size(0, text);
			size += QSizeF(2, 0);
			QRectF rect;
			rect.setSize(size);
			rect.moveCenter(center);
			path.addRoundedRect(rect.adjusted(-0.5, 0.5, 0.5, 0.5), 3, 3);
		}
	}

	return path;
}
Beispiel #16
0
void QARehabFileControlWidget::loadSVGFiles(void)
{
    QGraphicsScene * scene = this->scene();
    scene->setSceneRect(0, 0, this->width(), this->height());
    scene->setBackgroundBrush(QBrush(QColor(100, 100, 100, 255)));

    containerRect = new QGraphicsRectItem(0, 0, this->width(), this->height());
    containerRect->setPen(Qt::NoPen);
    containerRect->setBrush(QBrush(QColor(200, 200, 200, 50), Qt::CrossPattern));

    QPolygonF polygon;
    polygon.append(QPointF(80, 0));
    polygon.append(QPointF(0, 80));
    polygon.append(QPointF(400, 80));
    polygon.append(QPointF(320, 0));
    itemBtContainer = new QGraphicsPolygonItem(polygon, containerRect);
    itemBtContainer->setPen(Qt::NoPen);
    itemBtContainer->setBrush(QBrush(QColor(200, 200, 200, 100)));

    svgRestart = new QSVGInteractiveItem(":/svg/restart.svg", itemBtContainer);

    svgPlayPause = new QSVGInteractiveItem(":/svg/play.svg", itemBtContainer);
    svgPlayPause->setCheckable(true);

    svgKinectMaximize = new QSVGInteractiveItem(":/svg/maximize.svg", itemBtContainer);
    svgKinectMaximize->setCheckable(true);

    itemTimeline = new QGraphicsRectItem(0, 0, this->width() - 160, 5, containerRect);
    itemTimeline->setPen(Qt::NoPen);
    itemTimeline->setBrush(QBrush(QColor(200, 200, 255, 200)));

    itemCuttingInterval = new QGraphicsRectItem(0, 0, this->width() - 160, 20, containerRect);
    itemCuttingInterval->setPen(Qt::NoPen);
    itemCuttingInterval->setBrush(QBrush(QColor(100, 200, 0, 100)));

    svgLeftSelector = new QSVGInteractiveItem(":/svg/intervalLeft.svg", containerRect);
    svgRightSelector = new QSVGInteractiveItem(":/svg/intervalRight.svg", containerRect);

    QFont font("Verdana", 8);
    itemTXModelLeftValue = new QGraphicsSimpleTextItem("Left", this->svgLeftSelector);
    itemTXModelLeftValue->setFont(font);
    itemTXModelLeftValue->setPen(Qt::NoPen);
    itemTXModelLeftValue->setBrush(QBrush(QColor(200, 200, 200, 200)));
    itemTXModelRightValue = new QGraphicsSimpleTextItem("Right", this->svgRightSelector);
    itemTXModelRightValue->setFont(font);
    itemTXModelRightValue->setPen(Qt::NoPen);
    itemTXModelRightValue->setBrush(QBrush(QColor(200, 200, 200, 200)));
    itemTXModelRightValue->setText(QString::number(this->model.rightValue));
    itemTXModelLeftValue->setText(QString::number(this->model.leftValue));

    scene->addItem(containerRect);
}
void ArrowItem::paint(QPainter *painter) {
  painter->drawLine(line());

  QBrush b = brush();
  b.setStyle(Qt::SolidPattern);
  b.setColor(pen().color());
  setBrush(b);

  start.clear();
  end.clear();
  if (_startArrowHead) {
    qreal deltax = view()->scaledFontSize(_startArrowScale, *painter->device())*0.5; // in points
    deltax *= painter->device()->logicalDpiX()/72.0; // convert to 'pixels'.
    qreal theta = atan2(qreal(line().y2() - line().y1()), qreal(line().x2() - line().x1())) - M_PI / 2.0;
    qreal sina = sin(theta);
    qreal cosa = cos(theta);
    qreal yin = sqrt(3.0) * deltax;
    qreal x1, y1, x2, y2;
    QMatrix m(cosa, sina, -sina, cosa, 0.0, 0.0);

    m.map( deltax, yin, &x1, &y1);
    m.map(-deltax, yin, &x2, &y2);

    QPolygonF pts;
    pts.append(line().p1());
    pts.append(line().p1() + QPointF(x1, y1));
    pts.append(line().p1() + QPointF(x2, y2));
    painter->drawPolygon(pts);
    start = pts;
  }

  if (_endArrowHead) {
    qreal deltax = view()->scaledFontSize(_endArrowScale, *painter->device())*0.5;
    deltax *= painter->device()->logicalDpiX()/72.0; // convert points to 'pixels'.
    qreal theta = atan2(qreal(line().y1() - line().y2()), qreal(line().x1() - line().x2())) - M_PI / 2.0;
    qreal sina = sin(theta);
    qreal cosa = cos(theta);
    qreal yin = sqrt(3.0) * deltax;
    qreal x1, y1, x2, y2;
    QMatrix m(cosa, sina, -sina, cosa, 0.0, 0.0);

    m.map( deltax, yin, &x1, &y1);
    m.map(-deltax, yin, &x2, &y2);

    QPolygonF pts;
    pts.append(line().p2());
    pts.append(line().p2() + QPointF(x1, y1));
    pts.append(line().p2() + QPointF(x2, y2));
    painter->drawPolygon(pts);
    end = pts;
  }
}
Beispiel #18
0
QPolygonF Mesh::toPolygon() const
{
    QPolygonF polygon;
    for (int i=0; i<nColumns(); i++)
        polygon.append(getVertex2d(i, 0));
    for (int i=0; i<nRows(); i++)
        polygon.append(getVertex2d(nColumns()-1, i));
    for (int i=nColumns()-1; i>=0; i--)
        polygon.append(getVertex2d(i, nRows()-1));
    for (int i=nRows()-1; i>=1; i--)
        polygon.append(getVertex2d(0, i));
    return polygon;
}
Beispiel #19
0
QPolygonF QGVEdge::toArrow(const QLineF &line) const
{
    QLineF n = line.normalVector();
    QPointF o(n.dx() / 3.0, n.dy() / 3.0);

    //Only support normal arrow type
    QPolygonF polygon;
    polygon.append(line.p1() + o);
    polygon.append(line.p2());
    polygon.append(line.p1() - o);

    return polygon;
}
void CopyFilterGUIConnectionItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
	QLineF l = line();
	if (!l.isNull())
	{
		painter->setBrush(Qt::black);
		if (isSelected())
		{
			painter->setBrush(Qt::blue);
			painter->setPen(QPen(Qt::blue, 1.5));
		}
		painter->drawLine(line());

		double length = line().length();
		double offset = min(length, maxArrowSize);
		QLineF unit = l.unitVector();
		QLineF normal = l.normalVector().unitVector();
		QPointF v(unit.dx(), unit.dy());
		QPointF n(normal.dx(), normal.dy());
		QPointF p2 = l.p2();

		QPointF p3 = p2 - v * offset + 0.5 * n * offset;
		QPointF p4 = p2 - v * offset - 0.5 * n * offset;
		QPolygonF polygon;
		polygon.append(p2);
		polygon.append(p3);
		polygon.append(p4);

		painter->drawPolygon(polygon);

		if (factor != 1.0 || isDecibel)
		{
			QFont font = painter->font();
			font.setPixelSize(10);
			painter->setFont(font);
			QPointF center = (l.p1() + l.p2()) / 2;
			QString text = QString("%1").arg(factor);
			if (isDecibel)
				text += " dB";

			QSizeF size = painter->fontMetrics().size(0, text);
			size += QSizeF(2, 0);
			QRectF rect;
			rect.setSize(size);
			rect.moveCenter(center);
			painter->setBrush(Qt::white);
			painter->drawRoundedRect(rect.adjusted(-0.5, 0.5, 0.5, 0.5), 3, 3);
			painter->drawText(rect, Qt::AlignCenter, text);
		}
	}
}
StyledTextboxView::StyledTextboxView(Textbox *txtbox, bool override_style) : TextboxView(txtbox, override_style)
{
  QPolygonF pol;

  pol.append(QPointF(0,0));
  pol.append(QPointF(20,0));
  pol.append(QPointF(0,20));

  fold=new QGraphicsPolygonItem;
  this->addToGroup(fold);
  fold->setPolygon(pol);

  this->configureObject();
}
void painterUtils::drawRectangleGraph(QPainter &qp ,int const &startPos,
                                      int const &width,int const &height,
                                      std::vector<float>  &data,
                                      QColor &lineColor , QColor &bodyColor)


{
    //Get the size of the data
    int cacheSize = data.size();
    //Calculating the step size between each sample of the data (uniform distribution)
    float step = float(width-3)/(cacheSize-1);

    //Setup the colors
    qp.setPen(lineColor);
    qp.setBrush(bodyColor);

    //Create a polygon shape
    QPolygonF poly;
    int x,y;
    //Fill in the points to the polygon
    //Remeber that the height is relative to top left corner so needs to be reversed
    for( int i =0; i<cacheSize;i++)
    {
        if (i==0)
        {
            //The first one is the base , same value of the x but with minimum height value
            poly.append(QPoint( startPos+(i*step+2),height-1));
        }

        //Init to min height value
        y = (height-1);
        //convert data in range 0-1 and use it to multiply the height  ( with a small offset)
        y -= (data[i]/100*(height-5));
        //Init value to start position
        x = startPos;
        //Add the correct positon based on the number of steps taken ( plus  a small offset)
        x +=(i*step+2);
        //Append the point
        poly.append(QPoint(x,y));
        if(i== cacheSize -1)
        {
         //append last point
         poly.append(QPoint(x,height-1));
        }
    }
    //Draw the polygon
    qp.drawPolygon(poly);


}
Beispiel #23
0
QGraphicsItem* CGraphicsTriangleItem::createItem()
{
	QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent);

	drawPen(pItem);
	drawBrush(pItem);

	QPolygonF d;
	d.append(QPointF(-GET_VALUE(w).toDouble()/2,GET_VALUE(h).toDouble()/2));
	d.append(QPointF(GET_VALUE(w).toDouble()/2,GET_VALUE(h).toDouble()/2));
	d.append(QPointF(0,-GET_VALUE(h).toDouble()/2));
	pItem->setPolygon(d);

	return pItem;
}
Beispiel #24
0
void SCgNode::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    /* need to rebuild that code to more flexible.
       Just for example make drawers class for different types.
     */

    QRectF boundRect = boundingRect();

    if (!mIsContentVisible)
    {
        painter->save();
        SCgAlphabet::getInstance().paintNode(painter, mColor, boundRect, mConstType, mStructType);
        painter->restore();

        if (isContentData())
        {
            QBrush brush(QColor(128, 0, 255), Qt::SolidPattern);
            painter->setBrush(brush);

            painter->drawRect(boundRect.right() - 5, boundRect.bottom() - 5, 5, 5);
        }
    }else
    {
        QPen pen(mColor);
        pen.setWidthF(3.f);
        painter->setPen(pen);
        painter->drawRect(boundRect.adjusted(2, 2, -2, -2));
    }

    SCgObject::paint(painter, option, widget);

    // draw content corner
    if (mIsContentVisible)
    {
        QRectF rc = boundRect.adjusted(2, 2, -2, -2);
        QPolygonF polygon;
        polygon.append(rc.topLeft());
        polygon.append(QPointF(rc.left() + 10, rc.top()));
        polygon.append(QPointF(rc.left(), rc.top() + 10));

        QPainterPath path;
        path.addPolygon(polygon);
        path.closeSubpath();

        painter->fillPath(path, QBrush(mColor));

    }
}
Beispiel #25
0
void TextboxView::configureObject(void)
{
	Textbox *txtbox=dynamic_cast<Textbox *>(this->getSourceObject());
	QTextCharFormat fmt=font_config[ParsersAttributes::GLOBAL];
	QFont font;
	QPolygonF polygon;

	polygon.append(QPointF(0.0f,0.0f));
	polygon.append(QPointF(1.0f,0.0f));
	polygon.append(QPointF(1.0f,1.0f));
	polygon.append(QPointF(0.0f,1.0f));

	//The textbox view must be at the bottom of objects stack (Z = 0)
	box->setZValue(0);
	text->setZValue(1);

	if(!override_style)
	{
		box->setBrush(this->getFillStyle(BaseObject::getSchemaName(OBJ_TEXTBOX)));
		box->setPen(this->getBorderStyle(BaseObject::getSchemaName(OBJ_TEXTBOX)));

		font=fmt.font();
		font.setItalic(txtbox->getTextAttribute(Textbox::ITALIC_TXT));
		font.setBold(txtbox->getTextAttribute(Textbox::BOLD_TXT));
		font.setUnderline(txtbox->getTextAttribute(Textbox::UNDERLINE_TXT));
		font.setPointSizeF(txtbox->getFontSize());

		text->setFont(font);
		text->setBrush(txtbox->getTextColor());
	}

	text->setText(Utf8String::create(txtbox->getComment()));
	text->setPos(HORIZ_SPACING, VERT_SPACING);
	this->resizePolygon(polygon, roundf(text->boundingRect().width() + (2 * HORIZ_SPACING)),
											roundf(text->boundingRect().height() + (2* VERT_SPACING)));
	box->setPos(0,0);
	box->setPolygon(polygon);

	protected_icon->setPos(box->boundingRect().right() - (protected_icon->boundingRect().width() + 2 * HORIZ_SPACING),
												 box->boundingRect().bottom()- (protected_icon->boundingRect().height() + 2 * VERT_SPACING));

	this->bounding_rect.setTopLeft(box->boundingRect().topLeft());
	this->bounding_rect.setBottomRight(box->boundingRect().bottomRight());

	BaseObjectView::__configureObject();
	BaseObjectView::configureObjectShadow();
	BaseObjectView::configureObjectSelection();
}
Beispiel #26
0
YigModField::YigModField(YigSynthGraphic *synthGraphic, float param, qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent) :
    QGraphicsEllipseItem( x, y, width, height, parent ),
    modArc(this),
    yigAttractor(this),
    modTriangle(this)
{
    //createModCircle();
    parentGraphic = synthGraphic;
    setTransformOriginPoint(boundingRect().width()/2, boundingRect().height()/2);
    rotationAngle = param * 360;
    setRotation(fmod(rotationAngle+180, 360));
    transformOriginPoint();
    updateParameter(fmod((rotationAngle+180), 360)/360);
    modTriangle.setZValue(99);
    QPolygonF modPolygon;
    modPolygon.append(QPointF(0, 0));
    modPolygon.append(QPointF(5, 15));
    modPolygon.append(QPointF(-5, 15));
    modPolygon.translate(width/2, 0);
    modTriangle.setPolygon(modPolygon);
    QPen modPen(Qt::NoPen);
    modTriangle.setPen(modPen);
    QColor modColor(YigColorKit::background2);
    modColor.setAlpha(200);
    QBrush modBrush(modColor);
    modTriangle.setBrush(modBrush);
    // Mod amount
    /*
    modElectron = new QGraphicsEllipseItem(0, 0, 25, 25, this);
    modElectron->moveBy(0, (boundingRect().width()/2) - 3);
    modElectron->setFlag( QGraphicsItem::ItemIsSelectable, false );
    modElectron->setFlag( QGraphicsItem::ItemIsMovable, false );
    modElectron->setCacheMode( QGraphicsItem::ItemCoordinateCache );
    QColor modColor(YigColorKit::background2);
    modColor.setAlpha(200);
    modElectron->setPen(QPen(modColor));
    modColor.setAlpha(20);
    modElectron->setBrush(modColor);*/

    /*
    QColor modFill(YigColorKit::background2);
    modFill.setAlpha(100);
    QColor modOutline(YigColorKit::background2);
    modOutline.setAlpha(220);
    modArc.setBrush(modFill);
    modArc.setPen(Qt::NoPen);*/
    //redrawArc();
}
Beispiel #27
0
int Polygon::append(lua_State * L) //  ( const T & )
{
	QPolygonF* obj = ValueInstaller2<QPolygonF>::check( L, 1 );
	QPointF* p = ValueInstaller2<QPointF>::check( L, 2 );
	obj->append( *p );
	return 0;
}
Beispiel #28
0
void QChain::cutCircle(Circle circle) {
  if (m_vertices.size() == 0) return;
  circle.setCenter(circle.pos());

  QPainterPath cr;
  cr.addEllipse(circle.x - circle.r, circle.y - circle.r, 2 * circle.r,
                2 * circle.r);

  QPolygonF polygon;
  for (QPointF p : m_vertices) polygon.append(p);
  QPainterPath chain;
  chain.addPolygon(polygon);

  if (!chain.intersects(cr)) return;

  chain = chain.subtracted(cr);

  for (const QPolygonF &poly : chain.toSubpathPolygons()) {
    std::vector<Vector2d> pts(poly.begin(), poly.end() - 1);

    if (std::fabs(Geometry::area(pts.begin(), pts.end())) > 5.f) {
      auto chain = std::make_unique<QChain>(world());
      chain->setVertices(std::vector<QPointF>(pts.begin(), pts.end()));
      chain->initializeLater(world());

      world()->itemSet()->addBody(std::move(chain));
    }
  }

  m_vertices.clear();
  destroyLater();
}
Beispiel #29
0
void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
	// We don't have enougth data to calculate things, quit.
	if (!shouldCalculateStuff(topLeft, bottomRight))
		return;
	AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
	// Add 2 points to close the polygon.
	QPolygonF poly = polygon();
	if (poly.isEmpty())
		return;
	QPointF p1 = poly.first();
	QPointF p2 = poly.last();

	poly.prepend(QPointF(p1.x(), vAxis->posAtValue(0)));
	poly.append(QPointF(p2.x(), vAxis->posAtValue(0)));
	setPolygon(poly);

	QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
	pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
	pat.setColorAt(1, getColor(CALC_CEILING_DEEP));
	setPen(QPen(QBrush(Qt::NoBrush), 0));
	setBrush(pat);

	gradientFactor->setX(poly.boundingRect().width() / 2 + poly.boundingRect().x());
	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
	if (plannerModel->isPlanner()) {
		struct diveplan &diveplan = plannerModel->getDiveplan();
		gradientFactor->setText(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh));
	} else {
		gradientFactor->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh));
	}
}
Beispiel #30
0
// ============================================================================
// Gets polygon from editor points
QPolygonF EditorPolygon::polygon() const
{
	QPolygonF p;
	foreach( EditorPoint* pEP, _points )
	{
		p.append( pEP->pos() );
	}