Exemple #1
0
void GraphicsView::moveRobotAbs(QPointF position, int durationInMs)
{
    //position += robot->torso->boundingRect().topLeft(); // move the robot's center
    QRectF rect = sceneRect();
    if(position.x() < rect.left())
        position.setX(rect.left());
    if(position.x() > rect.right())
        position.setX(rect.right());
    if(position.y() < rect.top())
        position.setY(rect.top());
    if(position.y() > rect.bottom())
        position.setY(rect.bottom());

    if(durationInMs < 0)
    {
        double offset = (robot->pos() - position).manhattanLength();
        offset = offset * 2000.0 / 500.0; // a 500 pixel travel takes 2 seconds
        durationInMs = qRound(offset);
    }

    if(durationInMs > 5)
    {
        QPropertyAnimation *anim = new QPropertyAnimation(robot, "pos");
        anim->setEndValue(position);
        anim->setDuration(durationInMs);
        connect(anim, SIGNAL(finished()), SIGNAL(movementFinished()));
        anim->start(QAbstractAnimation::DeleteWhenStopped);
    }
    else
    {
        robot->setPos(position);
        emit movementFinished();
    }
}
Exemple #2
0
void TutorialUnit::setScene(GraphicsView *scene)
{
    mScene = scene;
    connect(this, SIGNAL(moveRel(QPointF,int)), scene, SLOT(moveRobotRel(QPointF,int)));
    connect(this, SIGNAL(moveAbs(QPointF,int)), scene, SLOT(moveRobotAbs(QPointF,int)));
    connect(this, SIGNAL(rotateAbs(double,int)), scene, SLOT(rotateRobotAbs(double,int)));
    connect(this, SIGNAL(rotateRel(double,int)), scene, SLOT(rotateRobotRel(double,int)));
    connect(this, SIGNAL(setGripperState(bool)), scene, SLOT(setGripperState(bool)));
    connect(this, SIGNAL(resetScene(bool)), scene, SLOT(reset(bool)));
    connect(scene, SIGNAL(movementFinished()), SLOT(onMovementFinished()));
    connect(scene, SIGNAL(positionUpdate(QPointF,qreal)), this, SIGNAL(positionUpdated(QPointF,qreal)));
}
Exemple #3
0
void GraphicsView::rotateRobotAbs(double angle, int durationInMs)
{
    if(durationInMs < 0)
    {
        double offset = abs(angle-robot->rotation());
        offset = offset * 1000.0 / 180.0; // a 180 degree rotation takes 1 seconds
        durationInMs = qRound(offset);
    }
    if(durationInMs > 5)
    {
        QPropertyAnimation *anim = new QPropertyAnimation(robot, "rotation");
        anim->setEndValue(angle);
        anim->setDuration(durationInMs);
        connect(anim, SIGNAL(finished()), SIGNAL(movementFinished()));
        anim->start(QAbstractAnimation::DeleteWhenStopped);
    }
    else
    {
        robot->setRotation(angle);
        emit movementFinished();
    }
}
void NetToolBox::init()
{
    m_containment = containment();
    Q_ASSERT(m_containment);

    m_icon = KIcon("plasma");
    m_closeIcon = KIcon("dialog-close");
    m_iconSize = QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
    m_animHighlightFrame = 0;
    m_hovering = false;
    m_showing = false;
    m_location = Plasma::BottomEdge;
    m_newToolsPosition = 0;

    setZValue(9000);
    resize(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
    setAcceptHoverEvents(true);

    m_toolContainer = new ToolContainer(this);
    m_toolContainer->hide();
    m_toolContainer->setFlag(QGraphicsWidget::ItemStacksBehindParent);
    m_toolContainerLayout = new QGraphicsLinearLayout(m_toolContainer);
    m_toolContainerLayout->addStretch();

    m_background = new Plasma::Svg(this);
    m_background->setImagePath("widgets/toolbox");
    m_background->setContainsMultipleImages(true);
    setLocation(Plasma::BottomEdge);

    m_containment->installEventFilter(this);
    connect(m_containment, SIGNAL(geometryChanged()), this, SLOT(containmentGeometryChanged()));
    containmentGeometryChanged();

    slideAnim = Plasma::Animator::create(Plasma::Animator::SlideAnimation, this);
    slideAnim->setProperty("movementDirection", Plasma::Animation::MoveAny);
    connect(slideAnim, SIGNAL(stateChanged(QAbstractAnimation::State,
                        QAbstractAnimation::State)),
                this, SLOT(onMovement(QAbstractAnimation::State,QAbstractAnimation::State)));
    connect(slideAnim, SIGNAL(finished()), this, SLOT(movementFinished()));

    anim = new QPropertyAnimation(this, "highlight", this);
    anim->setDuration(250);
    anim->setStartValue(0);
    anim->setEndValue(1);
}
Exemple #5
0
void GraphicsView::setGripperState(bool open)
{
    robot->setGripper(open);
    foreach(Circle* object, objects)
    {
        if(open)
        {
            if(object->parentItem() == robot)
            {
                QPointF pos = object->mapToScene(QPointF(0, 0));
                object->setParentItem(0);
                object->setPos(pos);
            }
        }
        else if(robot->lowerRightArmItem->collidesWithItem(object) || robot->lowerRightLegItem->collidesWithItem(object))
        {
            object->setParentItem(robot);
            object->setPos(70,0);
            break;
        }
    }
    emit movementFinished();
}