Пример #1
0
void StyledTextboxView::configureObject(void)
{
  QRectF rect;
  QPolygonF pol;
  QPointF pnt;

  this->__configureObject();
  fold->setBrush(box->brush());
  fold->setPen(box->pen());

  rect=box->boundingRect();
  pol=box->polygon();

  if(rect.height() < fold->boundingRect().height())
    rect.setHeight(fold->boundingRect().height() + (2 * VERT_SPACING));

  this->resizePolygon(pol, rect.width() + fold->boundingRect().width(), rect.height());

  pnt=pol.at(2);
  pol.remove(2);
  pol.insert(2, QPointF(pnt.x(), roundf(pnt.y() - fold->boundingRect().height())));
  pol.insert(3, QPointF(roundf(pnt.x() - fold->boundingRect().width()), pnt.y()));
  box->setPolygon(pol);

  rect=box->boundingRect();
  fold->setPos(rect.width() - fold->boundingRect().width(),
               rect.height() - fold->boundingRect().height());

  this->configureObjectShadow();
  this->configureObjectSelection();
}
Пример #2
0
void VLCStatsView::addValue( float value )
{
    value /= 1000;

    QPolygonF shape = totalbitrateShape->polygon();
    if ( shape.count() > ( STATS_LENGTH + 2 ) ) /* keep only STATS_LENGTH samples */
    {
        shape.remove( 1 );
        for(int i=1; i<( STATS_LENGTH + 2 ); i++)
            ( (QPointF &) shape.at(i) ).setX( i - 1 ); /*move back values*/
    }

    int count = shape.count();
    if ( count == 0 )
    {
        shape << QPointF( 0, 0 ); /* begin and close shape */
        shape << QPointF( count, 0 );
    }

    shape.insert( shape.end() - 1, QPointF( count, value ) );
    ( (QPointF &) shape.last() ).setX( count );
    totalbitrateShape->setPolygon( shape );

    addHistoryValue( value );

    QRectF maxsizes = scene()->itemsBoundingRect();
    maxsizes.setRight( STATS_LENGTH );
    fitInView( maxsizes ); /* fix viewport */
    drawRulers( maxsizes );
}
Пример #3
0
static PyObject *meth_QPolygonF_insert(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        int a0;
        const QPointF* a1;
        int a1State = 0;
        QPolygonF *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BiJ1", &sipSelf, sipType_QPolygonF, &sipCpp, &a0, sipType_QPointF, &a1, &a1State))
        {
            sipCpp->insert(a0,*a1);
            sipReleaseType(const_cast<QPointF *>(a1),sipType_QPointF,a1State);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QPolygonF, sipName_insert, doc_QPolygonF_insert);

    return NULL;
}
Пример #4
0
void VLCStatsView::addHistoryValue( float value )
{
    /* We keep a full history by creating virtual blocks for inserts, growing
       by power of 2 when no more space is available. At this time, we also
       free space by agregating the oldest values 2 by 2.
       Each shown value finally being a mean of blocksize samples.
    */
    bool doinsert = false;
    int next_blocksize = blocksize;
    QPolygonF shape = historyShape->polygon();
    int count = shape.count();
    if ( count == 0 )
    {
        shape << QPointF( 0, 0 ); /* begin and close shape */
        shape << QPointF( count, 0 );
    }

    valuesaccumulator += ( value / blocksize );
    valuesaccumulatorcount++;

    if ( valuesaccumulatorcount == blocksize )
    {
        valuesaccumulator = 0;
        valuesaccumulatorcount = 0;
        doinsert = true;
    }

    if ( doinsert )
    {
        if ( count > ( STATS_LENGTH + 2 ) )
        {
            float y = 0;
            y += ((QPointF &) shape.at( historymergepointer + 1 )).y();
            y += ((QPointF &) shape.at( historymergepointer + 2 )).y();
            y /= 2;

            /* merge */
            shape.remove( historymergepointer + 2 );
            ( (QPointF &) shape.at( historymergepointer + 1 ) ).setY( y );
            for(int i=historymergepointer +1; i<( STATS_LENGTH + 2 ); i++)
                ( (QPointF &) shape.at(i) ).setX( i - 1 ); /*move back values*/
            historymergepointer++;
            if ( historymergepointer > ( STATS_LENGTH - 1 ) )
            {
                historymergepointer = 0;
                next_blocksize = ( blocksize << 1 );
            }
        }

        shape.insert( shape.end() - 1, QPointF( count, value ) );
        ( (QPointF &) shape.last() ).setX( count );
    }
    else
        ( (QPointF &) shape.last() ).setX( count - 1 );

    historyShape->setPolygon( shape );

    blocksize = next_blocksize;
}
Пример #5
0
void point_insert(QPolygonF& p, size_t j, float l = 0.5) {
  size_t prev = j - 1;
  if(j == 0) {
    assert(p[p.size() - 1] == p[0]);
    prev = p.size() - 2;
  }

  QPointF newPoint = (1 - l) * p[prev] + l * p[j];
  p.insert(j, 1, newPoint);

  if(j == 0) {
    p[p.size() - 1] = p[0];
  }
}
Пример #6
0
void DialogFunction::onInsertPoint()
{
	QAction* pActionInsertPoint = static_cast<QAction*>(sender());
	const QPoint& point = pActionInsertPoint->data().toPoint();
	QwtArraySeriesData<QPointF>* pSeries = static_cast<QwtArraySeriesData<QPointF>*>(_pCurve->data());
	if (pSeries)
	{
		QPolygonF samples = pSeries->samples();
		QPointF newPoint;
		newPoint.setX(widgetPlot->invTransform(_pCurve->xAxis(), point.x()));
		newPoint.setY(widgetPlot->invTransform(_pCurve->yAxis(), point.y()));
		QPolygonF::iterator it = qLowerBound(samples.begin(), samples.end(), newPoint, boost::bind(&QPointF::x, _1) < boost::bind(&QPointF::x, _2));
		samples.insert(it, newPoint);
		_pCurve->setSamples(samples);
		widgetPlot->replot();
	}
}
Пример #7
0
void LineHandler::deleteLoop(QPolygonF &line, int startPos)
{
	for (int i = startPos; i < line.size() - 3; ++i) {
		bool isCut = false;
		for (int j = i + 2; j < line.size() - 1; ++j) {
			QPointF cut;
			if (QLineF(line[i], line[i + 1]).intersect(QLineF(line[j], line[j + 1]), &cut)
					== QLineF::BoundedIntersection)
			{
				if ((i != 0) || !((j == line.size() - 2)
						&& (QLineF(line.first(), line.last()).length() < (kvadratik * 2))))
				{
					QPainterPath path;
					QPainterPathStroker ps;
					ps.setWidth(kvadratik);
					for (int k = 0; k < line.size() - 1; ++k) {
						path.moveTo(line[k]);
						path.lineTo(line[k + 1]);
						if (ps.createStroke(path).contains(cut)) {
							line.insert(k + 1, cut);
							break;
						}
					}

					line.remove(i + 2, j - i);
					deleteLoop(line, i);
					isCut = true;
					break;
				}
			}
		}

		if (isCut) {
			break;
		}
	}
}
Пример #8
0
/**
 * Splits the selected segments by inserting new nodes in the middle. The
 * selected segments are defined by each pair of consecutive \a indexRanges.
 *
 * This method can deal with both polygons as well as polylines. For polygons,
 * pass <code>true</code> for \a closed.
 */
static QPolygonF splitPolygonSegments(const QPolygonF &polygon,
                                      const RangeSet<int> &indexRanges,
                                      bool closed)
{
    if (indexRanges.isEmpty())
        return polygon;

    const int n = polygon.size();

    QPolygonF result = polygon;

    RangeSet<int>::Range firstRange = indexRanges.begin();
    RangeSet<int>::Range it = indexRanges.end();
    // assert: firstRange != it

    if (closed) {
        RangeSet<int>::Range lastRange = it;
        --lastRange; // We know there is at least one range

        // Handle the case where the first and last nodes are selected
        if (firstRange.first() == 0 && lastRange.last() == n - 1) {
            const QPointF splitPoint = (result.first() + result.last()) / 2;
            result.append(splitPoint);
        }
    }

    do {
        --it;

        for (int i = it.last(); i > it.first(); --i) {
            const QPointF splitPoint = (result.at(i) + result.at(i - 1)) / 2;
            result.insert(i, splitPoint);
        }
    } while (it != firstRange);

    return result;
}
Пример #9
0
ViewerGL::Implementation::WipePolygonEnum
ViewerGL::Implementation::getWipePolygon(const RectD & texRectClipped,
                                         QPolygonF & polygonPoints,
                                         bool rightPlane) const
{
    ///Compute a second point on the plane separator line
    ///we don't really care how far it is from the center point, it just has to be on the line
    QPointF firstPoint, secondPoint;
    QPointF center;
    double angle;
    {
        QMutexLocker l(&wipeControlsMutex);
        center = wipeCenter;
        angle = wipeAngle;
    }

    ///extrapolate the line to the maximum size of the RoD so we're sure the line
    ///intersection algorithm works
    double maxSize = std::max(texRectClipped.x2 - texRectClipped.x1, texRectClipped.y2 - texRectClipped.y1) * 10000.;
    double xmax, ymax;

    xmax = std::cos(angle + M_PI_2) * maxSize;
    ymax = std::sin(angle + M_PI_2) * maxSize;

    firstPoint.setX(center.x() - xmax);
    firstPoint.setY(center.y() - ymax);
    secondPoint.setX(center.x() + xmax);
    secondPoint.setY(center.y() + ymax);

    QLineF inter(firstPoint, secondPoint);
    QLineF::IntersectType intersectionTypes[4];
    QPointF intersections[4];
    QLineF topEdge(texRectClipped.x1, texRectClipped.y2, texRectClipped.x2, texRectClipped.y2);
    QLineF rightEdge(texRectClipped.x2, texRectClipped.y2, texRectClipped.x2, texRectClipped.y1);
    QLineF bottomEdge(texRectClipped.x2, texRectClipped.y1, texRectClipped.x1, texRectClipped.y1);
    QLineF leftEdge(texRectClipped.x1, texRectClipped.y1, texRectClipped.x1, texRectClipped.y2);
    bool crossingTop = false, crossingRight = false, crossingLeft = false, crossingBtm = false;
    int validIntersectionsIndex[4];
    validIntersectionsIndex[0] = validIntersectionsIndex[1] = -1;
    int numIntersec = 0;
    intersectionTypes[0] = inter.intersect(topEdge, &intersections[0]);
    if (intersectionTypes[0] == QLineF::BoundedIntersection) {
        validIntersectionsIndex[numIntersec] = 0;
        crossingTop = true;
        ++numIntersec;
    }
    intersectionTypes[1] = inter.intersect(rightEdge, &intersections[1]);
    if (intersectionTypes[1]  == QLineF::BoundedIntersection) {
        validIntersectionsIndex[numIntersec] = 1;
        crossingRight = true;
        ++numIntersec;
    }
    intersectionTypes[2] = inter.intersect(bottomEdge, &intersections[2]);
    if (intersectionTypes[2]  == QLineF::BoundedIntersection) {
        validIntersectionsIndex[numIntersec] = 2;
        crossingBtm = true;
        ++numIntersec;
    }
    intersectionTypes[3] = inter.intersect(leftEdge, &intersections[3]);
    if (intersectionTypes[3]  == QLineF::BoundedIntersection) {
        validIntersectionsIndex[numIntersec] = 3;
        crossingLeft = true;
        ++numIntersec;
    }

    if ( (numIntersec != 0) && (numIntersec != 2) ) {
        ///Don't bother drawing the polygon, it is most certainly not visible in this case
        return ViewerGL::Implementation::eWipePolygonEmpty;
    }

    ///determine the orientation of the planes
    double crossProd  = ( secondPoint.x() - center.x() ) * ( texRectClipped.y1 - center.y() )
                        - ( secondPoint.y() - center.y() ) * ( texRectClipped.x1 - center.x() );
    if (numIntersec == 0) {
        ///the bottom left corner is on the left plane
        if ( (crossProd > 0) && ( (center.x() >= texRectClipped.x2) || (center.y() >= texRectClipped.y2) ) ) {
            ///the plane is invisible because the wipe handle is below or on the left of the texRectClipped
            return rightPlane ? ViewerGL::Implementation::eWipePolygonEmpty : ViewerGL::Implementation::eWipePolygonFull;
        }

        ///otherwise we draw the entire texture as usual
        return rightPlane ? ViewerGL::Implementation::eWipePolygonFull : ViewerGL::Implementation::eWipePolygonEmpty;
    } else {
        ///we have 2 intersects
        assert(validIntersectionsIndex[0] != -1 && validIntersectionsIndex[1] != -1);
        bool isBottomLeftOnLeftPlane = crossProd > 0;

        ///there are 6 cases
        if (crossingBtm && crossingLeft) {
            if ( (isBottomLeftOnLeftPlane && rightPlane) || (!isBottomLeftOnLeftPlane && !rightPlane) ) {
                //btm intersect is the first
                polygonPoints.insert(0, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x1, texRectClipped.y2) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x2, texRectClipped.y2) );
                polygonPoints.insert( 4, QPointF(texRectClipped.x2, texRectClipped.y1) );
                polygonPoints.insert(5, intersections[validIntersectionsIndex[0]]);
            } else {
                polygonPoints.insert(0, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x1, texRectClipped.y1) );
                polygonPoints.insert(3, intersections[validIntersectionsIndex[0]]);
            }
        } else if (crossingBtm && crossingTop) {
            if ( (isBottomLeftOnLeftPlane && rightPlane) || (!isBottomLeftOnLeftPlane && !rightPlane) ) {
                ///btm intersect is the second
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y2) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x2, texRectClipped.y1) );
                polygonPoints.insert(4, intersections[validIntersectionsIndex[1]]);
            } else {
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x1, texRectClipped.y2) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x1, texRectClipped.y1) );
                polygonPoints.insert(4, intersections[validIntersectionsIndex[1]]);
            }
        } else if (crossingBtm && crossingRight) {
            if ( (isBottomLeftOnLeftPlane && rightPlane) || (!isBottomLeftOnLeftPlane && !rightPlane) ) {
                ///btm intersect is the second
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y1) );
                polygonPoints.insert(3, intersections[validIntersectionsIndex[1]]);
            } else {
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y2) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x1, texRectClipped.y2) );
                polygonPoints.insert( 4, QPointF(texRectClipped.x1, texRectClipped.y1) );
                polygonPoints.insert(5, intersections[validIntersectionsIndex[1]]);
            }
        } else if (crossingLeft && crossingTop) {
            if ( (isBottomLeftOnLeftPlane && rightPlane) || (!isBottomLeftOnLeftPlane && !rightPlane) ) {
                ///left intersect is the second
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x1, texRectClipped.y2) );
                polygonPoints.insert(3, intersections[validIntersectionsIndex[1]]);
            } else {
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y2) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x2, texRectClipped.y1) );
                polygonPoints.insert( 4, QPointF(texRectClipped.x1, texRectClipped.y1) );
                polygonPoints.insert(5, intersections[validIntersectionsIndex[1]]);
            }
        } else if (crossingLeft && crossingRight) {
            if ( (isBottomLeftOnLeftPlane && rightPlane) || (!isBottomLeftOnLeftPlane && !rightPlane) ) {
                ///left intersect is the second
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert( 1, QPointF(texRectClipped.x1, texRectClipped.y2) );
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y2) );
                polygonPoints.insert(3, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert(4, intersections[validIntersectionsIndex[1]]);
            } else {
                polygonPoints.insert(0, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y1) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x1, texRectClipped.y1) );
                polygonPoints.insert(4, intersections[validIntersectionsIndex[1]]);
            }
        } else if (crossingTop && crossingRight) {
            if ( (isBottomLeftOnLeftPlane && rightPlane) || (!isBottomLeftOnLeftPlane && !rightPlane) ) {
                ///right is second
                polygonPoints.insert(0, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert( 1, QPointF(texRectClipped.x2, texRectClipped.y2) );
                polygonPoints.insert(2, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert(3, intersections[validIntersectionsIndex[0]]);
            } else {
                polygonPoints.insert(0, intersections[validIntersectionsIndex[0]]);
                polygonPoints.insert(1, intersections[validIntersectionsIndex[1]]);
                polygonPoints.insert( 2, QPointF(texRectClipped.x2, texRectClipped.y1) );
                polygonPoints.insert( 3, QPointF(texRectClipped.x1, texRectClipped.y1) );
                polygonPoints.insert( 4, QPointF(texRectClipped.x1, texRectClipped.y2) );
                polygonPoints.insert(5, intersections[validIntersectionsIndex[0]]);
            }
        } else {
            assert(false);
        }
    }

    return ViewerGL::Implementation::eWipePolygonPartial;
} // getWipePolygon
Пример #10
0
QPolygonF minigis::shiftPolygonDifficult(const QPolygonF &origin, qreal delta, bool closed)
{
    if (qFuzzyIsNull(delta))
        return origin;

    QPolygonF path = origin;

    QPolygonF norm;
    // ----------------- Поиск нормалей к оригинальному полигону
    int N = path.size();
    for (int i = 1; i < N; ++i) {
        QPointF vect = path.at(i) - path.at(i-1);
        double len = lengthR2(vect);
        if (qFuzzyIsNull(len)) {
            path.remove(i);
            --N;
            --i;
            continue;
        }
        vect /= len;
        norm.append(QPointF(vect.y() * delta, -vect.x() * delta));
    }
    // ----
    if (closed) {
        QPointF vect = path.first() - path.last();
        double len = lengthR2(vect);
        if (qFuzzyIsNull(len))
            path.remove(path.size() - 1);
        else {
            vect /= len;
            norm.append(QPointF(vect.y() * delta, -vect.x() * delta));
        }
    }
    // ------------------

    QVector<QLineF> lines;
    // -------------------------- Построение смещенных линий
    for (int i = 1; i < path.size(); ++i)
        lines.append(QLineF(path.at(i) + norm.at(i-1), path.at(i-1) + norm.at(i-1)));
    // ----
    if (closed)
        lines.append(QLineF(path.first() + norm.last(), path.last() + norm.last()));
    // ------------------

    QPolygonF shell;
    if (lines.isEmpty())
        return shell;

    // -------------------------- Построение смещенного полигона
    N = lines.size();
    for (int i = 1; i < N; ++i) {
        QPointF tmp;
        QLineF::IntersectType type = lines.at(i-1).intersect(lines.at(i), &tmp);
        qreal ang = lines.at(i-1).angleTo(lines.at(i));
        if (type != QLineF::NoIntersection)
            shell.append(tmp);
        else {
            if (qFuzzyCompare(ang, qreal(180)))
                shell.append(lines.at(i).p2() - 2 * norm.at(i));
            shell.append(lines.at(i).p2());
        }
    }
    // ----
    if (closed) {
        QPointF tmp;
        QLineF::IntersectType type = lines.last().intersect(lines.first(), &tmp);
        qreal ang = lines.last().angleTo(lines.first());
        if (type != QLineF::NoIntersection)
            shell.append(tmp);
        else {
            if (qFuzzyCompare(ang, qreal(180)))
                shell.append(lines.first().p2() - 2 * norm.first());
            shell.append(lines.first().p2());
        }
        shell.append(shell.first());
    }
    else {
        shell.prepend(lines.first().p2());
        shell.append(lines.last().p1());
    }
    // ------------------

    // -------------------------- обрезание острых углов
    int k  = 0;
    N = lines.size();
    for (int i = 1; i < N; ++i) {
        double ang = lines.at(i-1).angleTo(lines.at(i));

        bool first  = (120 < ang && ang < 180 && delta < 0) || (180 < ang && ang < 240 && delta > 0);
        bool second = (120 < ang && ang < 180 && delta > 0) || (180 < ang && ang < 240 && delta < 0);
        if (first) {
            int num = closed ? 1 : 0;
            QPointF v = shell.at(i + k - num) - path.at(i);
            v /= lengthR2(v);
            QPointF start = path.at(i) + v * qAbs(delta);
            QLineF tmp(start, start + QPointF(-v.y(), v.x()));
            QPointF a;
            if (tmp.intersect(lines.at(i  ), &a) != QLineF::NoIntersection)
                shell.replace(i + k - num, a);
            if (tmp.intersect(lines.at(i-1), &a) != QLineF::NoIntersection)
                shell.insert(i + k - num, a);
            ++k;
        }
        else if (second) {
            // TODO: cut corner
        }
    }
    // ----
    if (closed) {
        double ang = lines.last().angleTo(lines.first());

        int num = lines.size();
        int shellNum = (num + k - 1) % shell.size();
        bool first  = (120 < ang && ang < 180 && delta < 0) || (180 < ang && ang < 240 && delta > 0);
        bool second = (180 < ang && ang < 240 && delta < 0) || (120 < ang && ang < 180 && delta > 0);
        if (first) {
            QPointF v = shell.at(shellNum) - path.at(num % path.size());
            v /= lengthR2(v);
            QPointF start = path.at(num % path.size()) + v * qAbs(delta);
            QLineF tmp(start, start + QPointF(-v.y(), v.x()));
            QPointF a;
            if (tmp.intersect(lines.first(), &a) != QLineF::NoIntersection)
                shell.replace(shellNum, a);
            if (tmp.intersect(lines.last() , &a) != QLineF::NoIntersection)
                shell.insert(shellNum, a);
        }
        else if (second) {
            // TODO: cut corner
        }
    }
    // ------------------

    return shell;
}