Esempio n. 1
0
void DiagramDrawItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
	// left click
	if ((e -> buttons() & Qt::LeftButton)&&(mySelPoint>-1)) {
		QPointF mouse_point = onGrid(e -> pos());
#ifdef DEBUG
		std::cout << "Corner: " << mySelPoint << std::endl;
		std::cout << "mouse: " << mouse_point.x() << "/" << mouse_point.y() << std::endl;
		std::cout << "pos2: " << myPos2.x() << "/" << myPos2.y() << std::endl;
#endif
		prepareGeometryChange();
		switch (mySelPoint) {
			case 0:
				myPos2=myPos2-mouse_point;
				setPos(mapToScene(mouse_point));
				break;
			case 1:
				setPos(pos().x(),mapToScene(mouse_point).y());
				myPos2.setY(myPos2.y()-mouse_point.y());
				break;
			case 2:
				myPos2.setX(mouse_point.x());
				setPos(pos().x(),mapToScene(mouse_point).y());
				myPos2.setY(myPos2.y()-mouse_point.y());
				break;
			case 3:
				myPos2.setX(mouse_point.x());
				break;
			case 6:
				myPos2.setX(mouse_point.x());
				myPos2.setY(mouse_point.y());
				break;
			case 5:
				myPos2.setY(mouse_point.y());
				break;
			case 4:
				myPos2.setY(mouse_point.y());
				setPos(mapToScene(mouse_point).x(),pos().y());
				myPos2.setX(myPos2.x()-mouse_point.x());
				break;
			case 7:
				setPos(mapToScene(mouse_point).x(),pos().y());
				myPos2.setX(myPos2.x()-mouse_point.x());
				break;
			default:
				break;
		}
		myPolygon=createPath();
		setPolygon(myPolygon);
	}
	else
	DiagramItem::mouseMoveEvent(e);
}
Esempio n. 2
0
double TechTreeObj::cost( const std::vector< std::shared_ptr<Building> > &vecBuildings, const Grid &grid ) const
{
    std::vector< std::shared_ptr<Building> > onGrid( vecBuildings.size() );

    auto it = std::copy_if( vecBuildings.begin(),
                            vecBuildings.end(),
                            onGrid.begin(),
    [](const std::shared_ptr<Building> &b) {
        return b->isOnGrid();
    } );
    onGrid.resize( std::distance( onGrid.begin(), it ) );

    auto max =  std::max_element( onGrid.begin(),
                                  onGrid.end(),
                                  [](const std::shared_ptr<Building> &b1, const std::shared_ptr<Building> &b2)
    {
        return b1->getTreedepth() < b2->getTreedepth();
    } );

    return (*max)->getTreedepth();
}