void ScaleSceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
    QPen pen;
    pen.setColor(Qt::black);
    pen.setWidth(5);

    int baseY = 560;
    int offset =5;

    QLineF line;
    line.setLine(302, baseY, 498, baseY);
    pen.setWidth(2);
    painter->drawLine(line);

    line.setLine(300, baseY - offset, 300, baseY + offset);
    painter->drawLine(line);
    line.setLine(400, baseY - offset, 400, baseY + offset);
    painter->drawLine(line);
    line.setLine(500, baseY - offset, 500, baseY + offset);
    painter->drawLine(line);

    painter->drawText(300, baseY - 20, QObject::tr("0"));
    painter->drawText(400, baseY - 20, QObject::tr("1"));
    painter->drawText(500, baseY - 20, QObject::tr("2 m"));
}
void WordContainer::setDistanceAndDirectionToMoveFromArea()
{
    //sets line to move on, from position on Sentence Area to the starting position of WC
    QLineF line;
    line.setLine(this->x(),this->y(),startPosition.x(), startPosition.y());
    angleToMove = -1* line.angle();
}
void WordContainer::setDistanceAndDirectionToMoveToArea()
{
    //sets line to move on, from starting position of WC to position on Sencence Area
    QLineF line;
    line.setLine(this->x(),this->y(),nextContainerPositionInSentenceArea->x(), nextContainerPositionInSentenceArea->y());
    angleToMove = -1* line.angle();
}
Esempio n. 4
0
void CBelarusPattern::genGrowLine(int attempts)
{
    while (attempts > 0) {
        attempts --;
        QLineF line;
        QPoint base = m_growPoints.at(qrand() % m_growPoints.count());
        int growDirection = qrand() % 2;
        int lineLength = qrand() % 3 + 3;
        if (growDirection == 0) { // Horizontnal
            int shiftX = 0;
            int x1 = 0;
            if (base.x() + lineLength > m_bricks.size()) {
                shiftX = base.x() + lineLength - m_bricks.size();
            }
            x1 = base.x() - shiftX;
            line.setLine(x1, base.y(), x1 + (lineLength - 1), base.y());
        } else {                  // Vertical
            int shiftY = 0;
            int y1 = 0;
            if (base.y() + lineLength > m_bricks.size()) {
                shiftY = base.y() + lineLength - m_bricks.size();
            }
            y1 = base.y() - shiftY;
            line.setLine(base.x(), y1, base.x(), y1 + (lineLength - 1));
        }

//        if (!checkGrowMerging(line))
//            continue;

        CBricks bricks = m_bricks;
        bricks.fillLine(line);
        if (!bricks.hasCluster(2, 2)) {
            m_bricks.fillLine(line);
            m_growLines.append(line);
            //qDebug() << line.p1().x() << line.p1().y() << line.p2().x() << line.p2().y();
            //m_bricks.show();
            return;
        }
    }
}
Esempio n. 5
0
void tst_QLine::testSet()
{
    {
        QLine l;
        l.setP1(QPoint(1, 2));
        l.setP2(QPoint(3, 4));

        QCOMPARE(l.x1(), 1);
        QCOMPARE(l.y1(), 2);
        QCOMPARE(l.x2(), 3);
        QCOMPARE(l.y2(), 4);

        l.setPoints(QPoint(5, 6), QPoint(7, 8));
        QCOMPARE(l.x1(), 5);
        QCOMPARE(l.y1(), 6);
        QCOMPARE(l.x2(), 7);
        QCOMPARE(l.y2(), 8);

        l.setLine(9, 10, 11, 12);
        QCOMPARE(l.x1(), 9);
        QCOMPARE(l.y1(), 10);
        QCOMPARE(l.x2(), 11);
        QCOMPARE(l.y2(), 12);
    }

    {
        QLineF l;
        l.setP1(QPointF(1, 2));
        l.setP2(QPointF(3, 4));

        QCOMPARE(l.x1(), 1.0);
        QCOMPARE(l.y1(), 2.0);
        QCOMPARE(l.x2(), 3.0);
        QCOMPARE(l.y2(), 4.0);

        l.setPoints(QPointF(5, 6), QPointF(7, 8));
        QCOMPARE(l.x1(), 5.0);
        QCOMPARE(l.y1(), 6.0);
        QCOMPARE(l.x2(), 7.0);
        QCOMPARE(l.y2(), 8.0);

        l.setLine(9.0, 10.0, 11.0, 12.0);
        QCOMPARE(l.x1(), 9.0);
        QCOMPARE(l.y1(), 10.0);
        QCOMPARE(l.x2(), 11.0);
        QCOMPARE(l.y2(), 12.0);
    }

}
Esempio n. 6
0
void Storage::triggerArrow(
    const QPoint &aNewPos,
    const QPoint &anOldPos,
    Arrow &aNewArrow
    )
{
    QLineF aNewLine;
    aNewLine.setLine(
             anOldPos.x(),
             anOldPos.y(),
             aNewPos.x(),
             aNewPos.y()
    );
    aNewArrow.setCoordinates(aNewLine);
    state_ = NewSelection;
    repaint_needed_ = 1;
}
Esempio n. 7
0
void QTrain::move()
{
	QLineF line;

	if( move_duration >= 1 )
		return;

	int railIndex = change->railNo - 1;

	QPointF wb_point( 0, 0 ), start_point( 0, 0 ), end_point( 0, 0 );
	if( route->getSections()[index-1].getBlock().whatIsIt() == WorldBlock::STATION )
	{
		wb_point.setX( route->getSections()[index-1].getBlock().getStation().getPosX() );
		wb_point.setY( route->getSections()[index-1].getBlock().getStation().getPosY() );
	}
	if( route->getSections()[index-1].getBlock().whatIsIt() == WorldBlock::JUNCT )
	{
		wb_point.setX( route->getSections()[index-1].getBlock().getJunction().getPosX() );
		wb_point.setY( route->getSections()[index-1].getBlock().getJunction().getPosY() );
	}
	QLineF line1( wb_point, track->start_points[railIndex] );
	QLineF line2( wb_point, track->end_points[railIndex] );
	if( line1.length() < line2.length() )
	{
		start_point = track->start_points[railIndex];
		end_point = track->end_points[railIndex];
	}
	else
	{
		start_point = track->end_points[railIndex];
		end_point = track->start_points[railIndex];
	}

	line.setLine( start_point.x(), start_point.y(), end_point.x(), end_point.y() );

	qreal dx = end_point.x() - start_point.x();
	qreal dy = end_point.y() - start_point.y();
	move_duration += move_part;

	if( move_duration >= 1 )
		return;
	else
		moveBy( dx * move_part, dy * move_part );
}
Esempio n. 8
0
    /**
     * Determine the approximate closest points of two polygons.
     * @param self  First QPolygonF.
     * @param other Second QPolygonF.
     * @return  QLineF::p1() returns point of \a self;
     *          QLineF::p2() returns point of \a other.
     */
    QLineF closestPoints(const QPolygonF& self, const QPolygonF& other)
    {
        const QRectF& selfRect = self.boundingRect();
        const QRectF& otherRect = other.boundingRect();
        Uml::Region::Enum region = findRegion(selfRect, otherRect);
        if (region == Uml::Region::Center)
            return QLineF();
        if (self.size() < 3 || other.size() < 3)
            return QLineF();
        QLineF result;
        const int selfLastIndex  = self.size()  - 1 - (int)self.isClosed();
        const int otherLastIndex = other.size() - 1 - (int)other.isClosed();
        QPointF selfPoint(self.at(selfLastIndex));
        QPointF otherPoint(other.at(otherLastIndex));
        QLineF selfLine, otherLine;
        int i;

        switch (region) {

        case Uml::Region::North:
            // Find other's line with largest Y values
            otherLine = findLine(other, Y, Largest, selfRect);
            // Find own line with smallest Y values
            selfLine = findLine(self, Y, Smallest, otherRect);
            // Use the middle value of the X values
            result.setLine(middle(selfLine.p2().x(), selfLine.p1().x()), selfLine.p1().y(),
                           middle(otherLine.p2().x(), otherLine.p1().x()), otherLine.p1().y());
            break;

        case Uml::Region::South:
            // Find other's line with smallest Y values
            otherLine = findLine(other, Y, Smallest, selfRect);
            // Find own line with largest Y values
            selfLine = findLine(self, Y, Largest, otherRect);
            // Use the middle value of the X values
            result.setLine(middle(selfLine.p2().x(), selfLine.p1().x()), selfLine.p1().y(),
                           middle(otherLine.p2().x(), otherLine.p1().x()), otherLine.p1().y());
            break;

        case Uml::Region::West:
            // Find other's line with largest X values
            otherLine = findLine(other, X, Largest, selfRect);
            // Find own line with smallest X values
            selfLine = findLine(self, X, Smallest, otherRect);
            // Use the middle value of the Y values
            result.setLine(selfLine.p1().x(), middle(selfLine.p2().y(), selfLine.p1().y()),
                           otherLine.p1().x(), middle(otherLine.p2().y(), otherLine.p1().y()));
            break;

        case Uml::Region::East:
            // Find other's line with smallest X values
            otherLine = findLine(other, X, Smallest, selfRect);
            // Find own line with largest X values
            selfLine = findLine(self, X, Largest, otherRect);
            // Use the middle value of the Y values
            result.setLine(selfLine.p1().x(), middle(selfLine.p2().y(), selfLine.p1().y()),
                           otherLine.p1().x(), middle(otherLine.p2().y(), otherLine.p1().y()));
            break;

        case Uml::Region::NorthWest:
            // Find other's point with largest X and largest Y value
            for (i = 0; i < otherLastIndex; ++i) {
                QPointF current(other.at(i));
                if (current.x() + current.y() >= otherPoint.x() + otherPoint.y()) {
                    otherPoint = current;
                }
            }
            // Find own point with smallest X and smallest Y value
            for (i = 0; i < selfLastIndex; ++i) {
                QPointF current(self.at(i));
                if (current.x() + current.y() <= selfPoint.x() + selfPoint.y()) {
                    selfPoint = current;
                }
            }
            result.setPoints(selfPoint, otherPoint);
            break;

        case Uml::Region::SouthWest:
            // Find other's point with largest X and smallest Y value
            for (i = 0; i < otherLastIndex; ++i) {
                QPointF current(other.at(i));
                if (current.x() >= otherPoint.x() && current.y() <= otherPoint.y()) {
                    otherPoint = current;
                }
            }
            // Find own point with smallest X and largest Y value
            for (i = 0; i < selfLastIndex; ++i) {
                QPointF current(self.at(i));
                if (current.x() <= selfPoint.x() && current.y() >= selfPoint.y()) {
                    selfPoint = current;
                }
            }
            result.setPoints(selfPoint, otherPoint);
            break;

        case Uml::Region::NorthEast:
            // Find other's point with smallest X and largest Y value
            for (i = 0; i < otherLastIndex; ++i) {
                QPointF current(other.at(i));
                if (current.x() <= otherPoint.x() && current.y() >= otherPoint.y()) {
                    otherPoint = current;
                }
            }
            // Find own point with largest X and smallest Y value
            for (i = 0; i < selfLastIndex; ++i) {
                QPointF current(self.at(i));
                if (current.x() >= selfPoint.x() && current.y() <= selfPoint.y()) {
                    selfPoint = current;
                }
            }
            result.setPoints(selfPoint, otherPoint);
            break;

        case Uml::Region::SouthEast:
            // Find other's point with smallest X and smallest Y value
            for (i = 0; i < otherLastIndex; ++i) {
                QPointF current(other.at(i));
                if (current.x() + current.y() <= otherPoint.x() + otherPoint.y()) {
                    otherPoint = current;
                }
            }
            // Find own point with largest X and largest Y value
            for (i = 0; i < selfLastIndex; ++i) {
                QPointF current(self.at(i));
                if (current.x() + current.y() >= selfPoint.x() + selfPoint.y()) {
                    selfPoint = current;
                }
            }
            result.setPoints(selfPoint, otherPoint);
            break;

        default:
            // Error
            break;
        }

        return result;
    }