void FwLinePrimitive::setLine(const QLine& line)
{
    if(line != this->line())
    {
        prepareGeometryChanged();
        setPos(line.p1());

        m_p2 = line.p2() - line.p1();

        if(line.y1() == line.y2())
        {
            m_orientation = Fw::O_Horizontal;
            m_lenght = m_p2.x() - pos().x();

        }
        else if(line.x1() == line.x2())
        {
            m_orientation = Fw::O_Vertical;
            m_lenght = m_p2.y() - pos().y();
        }
        else
        {
            m_orientation = Fw::O_Diagonal;
            m_lenght = qRound(QLineF(line).length());
        }
        update();
    }
}
Beispiel #2
0
// Draw connection lines between linking
// operators (to visualize dependencies).
void eGuiOpPage::_drawLinkLines(QPainter *painter)
{
    eASSERT(painter != eNULL);

    static const QPoint arrowPts[3] =
    {
        QPoint(0,            0),
        QPoint(-ARROW_SIZE,  ARROW_SIZE),
        QPoint(-ARROW_SIZE, -ARROW_SIZE)
    };

    painter->save();
    painter->setRenderHint(QPainter::HighQualityAntialiasing, true);
    painter->setPen(QColor(80, 90, 100));
    painter->setBrush(QBrush(QColor(120, 130, 140), Qt::SolidPattern));

    for (eU32 i=0; i<m_opPage->getOperatorCount(); i++)
    {
        const eIOperator *op = m_opPage->getOperatorByIndex(i);
        eASSERT(op != eNULL);

        for (eU32 j=0; j<op->getLinkingCount(); j++)
        {
            const eID linkingId = op->getLinkingOperator(j);
            const eIOperator *linkingOp = eDemoData::findOperator(linkingId);

            // Lies linking operator on same page?
            if (linkingOp && linkingOp->getOwnerPage() == m_opPage)
            {
                // Yes, so draw line between them.
                const QRect opRect = _getOperatorRect(op);
                const QRect linkingRect = _getOperatorRect(linkingOp);

                // Calculate nearest intersection point and
                // angle to rotate arrow.
                const QPoint nip = _getNearestIntersectionPoint(opRect, QLine(linkingRect.center(), opRect.center()));
                const QLine line(nip, linkingRect.center());
                const QPoint p = line.p1()-line.p2();
                const eF32 angle = eRadToDeg(eATan2(p.y(), p.x()));

                painter->drawLine(line);
                painter->save();
                painter->translate(line.p1().x(), line.p1().y());
                painter->rotate(angle);
                painter->drawConvexPolygon(arrowPts, 3);
                painter->restore();
            }
        }
    }

    painter->restore();
}
Beispiel #3
0
    void line(const QLine& line, Callback&& func)
    {
        // Sign of delta x/y
        int sx = line.dx() > 0 ? 1 : -1;
        int sy = line.dy() > 0 ? 1 : -1;
        // Value that determines whether to move on X or Y
        int error = 0;
        // Absolute value of delta x/y
        int deltaerry = line.dy() * sy;
        int deltaerrx = line.dx() * sx;

        QPoint point = line.p1();

        while ( point != line.p2() )
        {
            func(point);

            error += deltaerry;
            while ( error >= deltaerrx / 2 && point.y() != line.y2() )
            {
                func(point);
                point.setY(point.y() + sy);
                error -= deltaerrx;
            }

            if ( point.x() != line.x2() )
                point.setX(point.x() + sx);
        }

        func(point);
    }
Beispiel #4
0
QT_BEGIN_NAMESPACE

/*!
    \class QLine
    \inmodule QtCore
    \ingroup painting

    \brief The QLine class provides a two-dimensional vector using
    integer precision.

    A QLine describes a finite length line (or a line segment) on a
    two-dimensional surface. The start and end points of the line are
    specified using integer point accuracy for coordinates. Use the
    QLineF constructor to retrieve a floating point copy.

    \table
    \row
        \li \inlineimage qline-point.png
        \li \inlineimage qline-coordinates.png
    \endtable

    The positions of the line's start and end points can be retrieved
    using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The
    dx() and dy() functions return the horizontal and vertical
    components of the line. Use isNull() to determine whether the
    QLine represents a valid line or a null line.

    Finally, the line can be translated a given offset using the
    translate() function.

    \sa QLineF, QPolygon, QRect
*/

/*!
    \fn QLine::QLine()

    Constructs a null line.
*/

/*!
    \fn QLine::QLine(const QPoint &p1, const QPoint &p2)

    Constructs a line object that represents the line between \a p1 and
    \a p2.
*/

/*!
    \fn QLine::QLine(int x1, int y1, int x2, int y2)

    Constructs a line object that represents the line between (\a x1, \a y1) and
    (\a x2, \a y2).
*/

/*!
    \fn bool QLine::isNull() const

    Returns true if the line is not set up with valid start and end point;
    otherwise returns false.
*/

/*!
    \fn QPoint QLine::p1() const

    Returns the line's start point.

    \sa x1(), y1(), p2()
*/

/*!
    \fn QPoint QLine::p2() const

    Returns the line's end point.

    \sa x2(), y2(), p1()
*/

/*!
    \fn int QLine::x1() const

    Returns the x-coordinate of the line's start point.

    \sa p1()
*/

/*!
    \fn int QLine::y1() const

    Returns the y-coordinate of the line's start point.

    \sa p1()
*/

/*!
    \fn int QLine::x2() const

    Returns the x-coordinate of the line's end point.

    \sa p2()
*/

/*!
    \fn int QLine::y2() const

    Returns the y-coordinate of the line's end point.

    \sa p2()
*/

/*!
    \fn int QLine::dx() const

    Returns the horizontal component of the line's vector.

    \sa dy()
*/

/*!
    \fn int QLine::dy() const

    Returns the vertical component of the line's vector.

    \sa dx()
*/

/*!
    \fn bool QLine::operator!=(const QLine &line) const

    Returns true if the given \a line is not the same as \e this line.

    A line is different from another line if any of their start or
    end points differ, or the internal order of the points is different.
*/

/*!
    \fn bool QLine::operator==(const QLine &line) const

    Returns true if the given \a line is the same as \e this line.

    A line is identical to another line if the start and end points
    are identical, and the internal order of the points is the same.
*/

/*!
    \fn void QLine::translate(const QPoint &offset)

    Translates this line by the given \a offset.
*/

/*!
    \fn void QLine::translate(int dx, int dy)
    \overload

    Translates this line the distance specified by \a dx and \a dy.
*/

/*!
    \fn QLine QLine::translated(const QPoint &offset) const

    \since 4.4

    Returns this line translated by the given \a offset.
*/

/*!
    \fn QLine QLine::translated(int dx, int dy) const
    \overload
    \since 4.4

    Returns this line translated the distance specified by \a dx and \a dy.
*/


/*!
    \fn void QLine::setP1(const QPoint &p1)
    \since 4.4

    Sets the starting point of this line to \a p1.

    \sa setP2(), p1()
*/


/*!
    \fn void QLine::setP2(const QPoint &p2)
    \since 4.4

    Sets the end point of this line to \a p2.

    \sa setP1(), p2()
*/


/*!
    \fn void QLine::setPoints(const QPoint &p1, const QPoint &p2)
    \since 4.4

    Sets the start point of this line to \a p1 and the end point of this line to \a p2.

    \sa setP1(), setP2(), p1(), p2()
*/


/*!
    \fn void QLine::setLine(int x1, int y1, int x2, int y2)
    \since 4.4

    Sets this line to the start in \a x1, \a y1 and end in \a x2, \a y2.

    \sa setP1(), setP2(), p1(), p2()
*/



#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QLine &p)
{
    d << "QLine(" << p.p1() << ',' << p.p2() << ')';
    return d;
}
Beispiel #5
0
/*!
    \overload

    Creates and returns a QLine object that is a copy of the given \a
    line, mapped into the coordinate system defined by this matrix.
    Note that the transformed coordinates are rounded to the nearest
    integer.
*/
QLine QMatrix::map(const QLine &line) const
{
    return QLine(map(line.p1()), map(line.p2()));
}
template<> Q_INLINE_TEMPLATE QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress)
{
    return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
}
/**
 * @brief RequestInterface::paintEvent
 */
void RequestInterface::paintEvent(QPaintEvent *)
{
    setWindowTitle("NetworkBuilder");
    setWindowIcon(QIcon("../network-logo.jpg"));

    // reset errors messages
    errors.clear();

    // painter creation
    QPainter painter(this);

    // foreach building view
    for(unsigned int i = 0 ; i < buildingViews.size();i++)
    {
        BuildingView *currentBuildingView  = buildingViews[i];

        // take selected pen if view has been selected
        if(currentBuildingView == selectedBuildingView)
            painter.setPen(selectedPen);
        else
            painter.setPen(defaultPen);

        // draw the building
        painter.drawRect(*currentBuildingView);

        // add color
        bool isAdmin = currentBuildingView->getBuilding()->isAdmin();
        if(isAdmin)
            painter.fillRect(*currentBuildingView, buildingAdminColor);
        else
            painter.fillRect(*currentBuildingView, buildingColor);

        // add floors
        for(unsigned int j=0; j< currentBuildingView->getFloorViews().size(); j++)
        {
            FloorView* currentFloorView(currentBuildingView->getFloorViews()[j]);

            // take selected pen if view has been selected
            if(selectedFloor == currentFloorView)
                painter.setPen(selectedPen);
            else
                painter.setPen(defaultPen);

            // get floor coordonates
            QRect rect(currentBuildingView->x()+15, currentBuildingView->y()+ 15 + j * 90, 120,75);
            painter.drawRect(rect);

            // add color
            if(isAdmin)
                painter.fillRect(rect, floorAdminColor);
            else
                painter.fillRect(rect, floorColor);

            // add floor name
            painter.drawText(rect, Qt::AlignHCenter,currentFloorView->getName());

            // if all users are null set warning style and add an error in errors
            if(currentFloorView->getFloor()->isUsersNull())
            {
                painter.setFont(warningTextFont);
                painter.setPen(warningTextPen);
                errors.push_back(currentFloorView->getName().toStdString()+" in "+currentBuildingView->getName().toStdString()+ " doesn't have any user.");
            }

            // add floor users
            painter.drawText(rect, Qt::AlignBottom+Qt::AlignCenter, currentFloorView->getUsers());

            // reset pen and font
            painter.setFont(defaultFont);
            painter.setPen(defaultPen);
        }

        //add name
        painter.drawText(*currentBuildingView,Qt::AlignHCenter,currentBuildingView->getName());

        // if all users are null set warning style and add an error in errors
        if(currentBuildingView->getBuilding()->isUsersNull() && !currentBuildingView->getBuildingPanel()->isReadOnly())
        {
            painter.setFont(warningTextFont);
            painter.setPen(warningTextPen);
            errors.push_back(currentBuildingView->getName().toStdString()+" doesn't have any user.");
        }

        // add building users
        painter.drawText(*currentBuildingView, Qt::AlignBottom+Qt::AlignCenter, currentBuildingView->getUsers());

        // reset pen and font
        painter.setFont(defaultFont);
        painter.setPen(defaultPen);
    }

    // foreach b2b view, add it on the board
    for(unsigned int i = 0; i< b2bViews.size(); i++)
    {
        Building_BuildingView *currentB2bView = b2bViews[i];

        //check if the view is selected
        if(currentB2bView == selectedB2bView)
            painter.setPen(selectedPen);
        else
            painter.setPen(defaultPen);

        // get the line to draw
        // if there is an intersection between 2 building don't draw
        if(!currentB2bView->intersect())
        {
            // draw the line
            QLine line = currentB2bView->getLine();
            painter.drawLine(line);

            // find the middle of the line and right the distance
            // get the x average and the y average, offset 4 on y to place text above line
            QPoint mid((line.p2().x()+line.p1().x())/2, (line.p2().y()+line.p1().y())/2-4);

            // if distance == 0 set warning style and add an error
            double distance = currentB2bView->getB2b()->getDistance();
            if(distance == 0)
            {
                painter.setFont(warningTextFont);
                painter.setPen(warningTextPen);
                errors.push_back("Distance between "+ currentB2bView->getBuilding1()->getName().toStdString() +" and "+currentB2bView->getBuilding2()->getName().toStdString()+" can't be null.");
            }

            // draw distance
            painter.drawText(mid, currentB2bView->getDistance());

            // reset pen and style
            painter.setPen(defaultPen);
            painter.setFont(defaultFont);
        }
    }
    painter.end();
}
/**
 * @brief RequestInterface::mousePressEvent
 * @param event
 * find the current focus
 */
void RequestInterface::mousePressEvent(QMouseEvent *event)
{
    // reset selected view pointers
    selectedBuildingView = 0;
    selectedB2bView = 0;
    selectedFloor = 0;

    // reset panel to default
    formPanel->setWidget(defaultPanel);

    // check if the user select a building or a floor
    for(unsigned int i = 0 ; i < buildingViews.size();i++)
    {
        BuildingView *currentBuildingView = buildingViews[i];
        //check first floors
        for(unsigned int j =0; j < currentBuildingView->getFloorViews().size(); j++)
        {
            QRect rect(currentBuildingView->x()+15, currentBuildingView->y()+ 15 + j * 90, 120,75);
            if(rect.contains(event->pos()))
            {
                // select the floor and add the panel
                selectedFloor = currentBuildingView->getFloorViews()[j];
                formPanel->setWidget(selectedFloor->getFloorPanel());
                break;
            }
        }

        // if no floor has been selected
        if(selectedFloor==0 && buildingViews[i]->contains(event->pos()))
        {
            // select the building and add the panel
            selectedBuildingView = buildingViews[i];
            formPanel->setWidget(selectedBuildingView->getBuildingPanel());
            break;
        }
    }

    // check if the user select a link b2b if no location has been selected
    if(selectedBuildingView==0 && selectedFloor == 0)
    {
        bool selected = false;
        for(unsigned int i= 0; i< b2bViews.size(); i++)
        {
            // get the line
            QLine line = b2bViews[i]->getLine();
            //event coordonates
            int ex=event->x();
            int ey=event->y();

            // split vertical line and other cases
            // ex = line.p1().x() = line.p2().x() with SELECT_MARGIN of error
            // line.p1().y() < ey < line.p2().y() or line.p2().y() < ey < line.p1().y() with SELECT_MARGIN of error
            if(line.p2().x()==line.p1().x())
            {
                if(line.p1().x()-SELECT_MARGIN <= ex && ex <= line.p1().x()+SELECT_MARGIN && ((line.p1().y()-SELECT_MARGIN <= ey && line.p2().y()+SELECT_MARGIN>= ey) || (line.p2().y()-SELECT_MARGIN <= ey && line.p1().y()+SELECT_MARGIN>= ey)))
                {
                    selected=true;
                }
            }
            else
            {
                // calculate line equation y = la * x + lb
                float la = float(line.p2().y()-line.p1().y())/float(line.p2().x()-line.p1().x());
                float lb = float(line.p1().y()-la*line.p1().x());
                // calculate y coordonate on the line for x=ex
                float ly = la*ex+lb;

                // check if ly and ey are close
                if(ly-SELECT_MARGIN<=ey && ey<=ly+SELECT_MARGIN)
                {
                    selected =true;
                }
            }
            if(selected)
            {
                // select the b2b and add the panel
                selectedB2bView = b2bViews[i];
                formPanel->setWidget(selectedB2bView->getB2bPanel());
                break;
            }
        }
    }

    // update draw
    update();
}
QLine MathUtils::rotateQLine(QLine &line, qint32 angle)
{
    QLine newLine(MathUtils::rotatePoint(line.p1(), angle).toPoint(),
               MathUtils::rotatePoint(line.p2(), angle).toPoint());
    return newLine;
}