Esempio n. 1
0
void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){
    QGraphicsItem *activeItem = itemAt(event->scenePos().x(),event->scenePos().y(),transform);

    if (activeItem != 0 and ((CustomItem*)activeItem)->isClickable()){
        QGraphicsItem *selection = itemAt(event->scenePos().x(),event->scenePos().y(),transform);

        if(((CustomItem*)selection)->getName() == std::string("Dot")){
            selectionActive = true;
            selectedDot = ((Dot*)selection);
        }
    }
    else{
        if (event->button() == Qt::LeftButton){
            QGraphicsItem *newDot = new Dot(event->scenePos(),dotRadius,Qt::white);
            addItem(newDot);
            connectToNearest(((Dot*)newDot));
            totalCost = calculateCost();
            emit costChanged(totalCost);
        }
        else{
            QGraphicsItem *newDot = new Dot(event->scenePos(),dotRadius,Qt::red);
            addItem(newDot);
            ((Dot*)newDot)->makeCenter();
            centersPointers.append(((Dot*)newDot));
            updateConnections();
            totalCost = calculateCost();
            emit costChanged(totalCost);
        }
    }
    update(QRectF(-50,-50,1000,1000));
}
Esempio n. 2
0
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent * event){
    if (selectionActive){
        selectedDot->setPos(event->scenePos());
        if (selectedDot->isCenter()){
            updateConnections();
        }
        else{
            removeItem(((QGraphicsItem*)selectedDot->getConnection()));
            connectToNearest(selectedDot);
        }        
        totalCost = calculateCost();
        emit costChanged(totalCost);
        update(QRectF(-50,-50,1000,1000));
    }
}
Esempio n. 3
0
void GraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event){
    QGraphicsItem *selection = itemAt(event->scenePos().x(),event->scenePos().y(),transform);

    if(((CustomItem*)selection)->getName() == std::string("Dot")){
        if(((Dot*)selection)->isCenter()){
            removeCenter(((Dot*)selection));
            updateConnections();
        }
        else{
            removeItem((QGraphicsItem*)((Dot*)selection)->getConnection());
            removeItem(selection);
        }
        totalCost = calculateCost();
        emit costChanged(totalCost);
        update(QRectF(-50,-50,1000,1000));
    }
}
Esempio n. 4
0
void MenuItem::fireCostChanged() {
    costChanged(cost());
    marginChanged(margin());
}
Esempio n. 5
0
void Cost::setCost(double cost)
{
    _cost = cost;
    emit costChanged();
}