/**
 * @internal Utility method to add line to path if line is non null.
 */
static void addLineToPath(const QLineF& line, QPainterPath &path)
{
    if (!line.isNull()) {
        path.moveTo(line.p1());
        path.lineTo(line.p2());
    }
}
Beispiel #2
0
QRect CurveTracker::trackerRect( const QFont &font ) const
{
    QRect r = QwtPlotPicker::trackerRect( font );
    
    // align r to the first curve

    const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
    if ( curves.size() > 0 )
    {
        QPointF pos = invTransform( trackerPosition() );

        const QLineF line = curveLineAt(    
            static_cast<const QwtPlotCurve *>( curves[0] ), pos.x() );
        if ( !line.isNull() )
        {
            const double curveY = line.pointAt(
                ( pos.x() - line.p1().x() ) / line.dx() ).y();

            pos.setY( curveY );
            pos = transform( pos );

            r.moveBottom( pos.y() );            
        }
    }

    return r;
}
Beispiel #3
0
/*!
  \fn qreal QLineF::angle(const QLineF &line) const

  \obsolete

  Returns the angle (in degrees) between this line and the given \a
  line, taking the direction of the lines into account. If the lines
  do not intersect within their range, it is the intersection point of
  the extended lines that serves as origin (see
  QLineF::UnboundedIntersection).

  \table
  \row
  \o \inlineimage qlinef-angle-identicaldirection.png
  \o \inlineimage qlinef-angle-oppositedirection.png
  \endtable

  When the lines are parallel, this function returns 0 if they have
  the same direction; otherwise it returns 180.

  \sa intersect()
*/
qreal QLineF::angle(const QLineF &l) const
{
    if (isNull() || l.isNull())
        return 0;
    qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());
    qreal rad = 0;
    // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)
    if (cos_line >= -1.0 && cos_line <= 1.0) rad = acos( cos_line );
    return rad * 360 / M_2PI;
}
Beispiel #4
0
QString CurveTracker::curveInfoAt( 
    const QwtPlotCurve *curve, const QPointF &pos ) const
{
    const QLineF line = curveLineAt( curve, pos.x() );
    if ( line.isNull() )
        return QString::null;

    QPointF p = line.pointAt(( pos.x() - line.p1().x() ) / line.dx());

    QString info( "<font color=""%1"">%2 / %3</font>" );
    return info.arg( curve->pen().color().name() ).arg( p.y() ).arg(p.x());
}
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);
		}
	}
}
Beispiel #6
0
QLineF GroupBox::positionToPoint(int pos) const
{
	QLineF result;
	foreach (const Box *box, boxes())
	{
		if (box->containsPos(pos))
		{
			result = box->positionToPoint(pos);
		}
	}
	if (!result.isNull())
		result.translate(x(), y());
	return result;
}
Beispiel #7
0
/*!
  \fn qreal QLineF::angleTo(const QLineF &line) const

  \since 4.4

  Returns the angle (in degrees) from this line to the given \a
  line, taking the direction of the lines into account. If the lines
  do not intersect within their range, it is the intersection point of
  the extended lines that serves as origin (see
  QLineF::UnboundedIntersection).

  The returned value represents the number of degrees you need to add
  to this line to make it have the same angle as the given \a line,
  going counter-clockwise.

  \sa intersect()
*/
qreal QLineF::angleTo(const QLineF &l) const
{
    if (isNull() || l.isNull())
        return 0;

    const qreal a1 = angle();
    const qreal a2 = l.angle();

    const qreal delta = a2 - a1;
    const qreal delta_normalized = delta < 0 ? delta + 360 : delta;

    if (qFuzzyCompare(delta, qreal(360)))
        return 0;
    else
        return delta_normalized;
}
static PyObject *meth_QLineF_isNull(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QLineF *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QLineF, &sipCpp))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->isNull();
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }
Beispiel #9
0
/*!
 * \fn Util::cullLine
 * Slice \a poly so that the segments that are left are those which remain inside \a rect.
 */
QList<QPolygonF> Util::cullLine(QPolygonF poly, QRectF rect)
{
    // When the plot is zoomed closer, drawing the line as a single poly
    // gets slower - weird and annoying. Therefore, here, the lines are "cut"
    // by the view frame so that excess segment aren't drawn.
    QList<QPolygonF> lines;
    QPointF latestPoint;
    QPolygonF latestPoly;
    bool starting = true;

    // If there's only 1 point, the forloop will not run
    if (poly.size() == 1) {
        if (rect.contains(poly[0])) {
            latestPoly << poly[0];
            lines << latestPoly;
        }
        return lines;
    }

    for (int i=0; i<poly.size() - 1; ++i) {
        QPointF p1 = poly[i], p2 = poly[i+1];
        QLineF l = rectSlice(p1, p2, rect);
        if (l.isNull()) continue;

        // Check if the line has been broken, or is starting
        if (l.p1() != latestPoint || starting) {
            // Throw the current poly in and start a new one
            if (latestPoly.length() > 0) {
                lines << latestPoly;
                latestPoly = QPolygonF();
            }
            starting = false;
            latestPoly << l.p1();
        }
        latestPoly << l.p2();
        latestPoint = l.p2();
    }

    // Need the final whole section
    lines << latestPoly;

    return lines;
}
Beispiel #10
0
void BezierCubicItem::controlPointMoved(int index)
{
    // solid move
    if (index == 0 || index == 2) {
        QLineF l = index == 0 ? m_l1->line() : m_l2->line();
        if (!l.isNull())
            m_cps[index + 1]->setPos(m_cps[index]->pos() + QPointF(l.dx(), l.dy()));
    }

    // update line
    if (index < 2)
        m_l1->setLine(QLineF(m_cps[0]->pos(), m_cps[1]->pos()));
    else
        m_l2->setLine(QLineF(m_cps[2]->pos(), m_cps[3]->pos()));

    // update path
    QPainterPath path(m_cps[0]->pos());
    path.cubicTo(m_cps[1]->pos(), m_cps[3]->pos(), m_cps[2]->pos());
    m_path->setPath(path);
    emit shapeChanged(path);
}