Пример #1
0
void PixmapButton::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
    if(!isVisible())
        return;
    m_pressed = true;
    setPixmap(m_pressedPixmap);
    update();
    Q_EMIT clickOn();
}
Пример #2
0
void MindToolBar::setupUi()
{
    m_itemList = new QListView();
    connect(m_itemList, SIGNAL(pressed(QModelIndex)),this,SLOT(clickOn(QModelIndex)));
    m_itemList->setModel(m_model);

    m_edgeList = new QListView();
    connect(m_edgeList, SIGNAL(pressed(QModelIndex)),this,SLOT(clickOnEdge(QModelIndex)));
    m_edgeList->setModel(m_edgeModel);

    m_geoList = new QListView();
    connect(m_geoList, SIGNAL(pressed(QModelIndex)),this,SLOT(clickOnCommon(QModelIndex)));
    m_geoList->setModel(m_commonModel);

    QVBoxLayout* layout = new QVBoxLayout(this);



    //QHBoxLayout* buttonlayout = new QHBoxLayout();
    /// @todo add icons to push button
    m_handleItem= new QPushButton(tr("Handle"));
    m_handleItem->setCheckable(true);
    layout->addWidget(m_handleItem);



    m_addBreak= new QPushButton(tr("Add Break"));
    m_addBreak->setCheckable(true);
    m_delBreak= new QPushButton(tr("Delete Break"));
    m_delBreak->setCheckable(true);
    layout->addWidget(m_addBreak);
    layout->addWidget(m_delBreak);



    layout->addWidget(new QLabel(tr("Shape:"),this));
    layout->addWidget(m_geoList);

    layout->addWidget(new QLabel(tr("Edge:"),this));
    layout->addWidget(m_edgeList);

    layout->addWidget(new QLabel(tr("Node:"),this));
    layout->addWidget(m_itemList);

    QHBoxLayout* buttonlayout2 = new QHBoxLayout();
    m_addItem= new QPushButton(tr("Add Item"));
    m_addItem->setCheckable(true);
    m_delItem= new QPushButton(tr("Delete Item"));
    m_delItem->setCheckable(true);
    buttonlayout2->addWidget(m_addItem);
    buttonlayout2->addWidget(m_delItem);

    layout->addLayout(buttonlayout2);



    //m_group->addButton(m_arrow);
    m_group->addButton(m_handleItem);
    m_group->addButton(m_delBreak);
    m_group->addButton(m_addBreak);
    m_group->setExclusive(false);


    connect(m_handleItem,SIGNAL(pressed()),this,SLOT(chooseTool()));
    connect(m_addBreak,SIGNAL(pressed()),this,SLOT(chooseTool()));
    connect(this,SIGNAL(currentToolChanged(MindToolBar::MINDTOOL)),this, SLOT(currentToolHasChanged(MindToolBar::MINDTOOL)));
   // connect(m_arrow,SIGNAL(pressed()),this,SLOT(chooseTool()));



}
Пример #3
0
int GameScreen::update (sf::RenderWindow &app)
{
	int nextScreen = myID;
	float elapsedTime = app.GetFrameTime();

	sf::Event event;
	while (app.GetEvent(event)) // Boucle des évènements en attente
	{
		if (event.Type == sf::Event::Closed)
		{
			return EXIT;
		}
		else if(m_iHandler->testEvent(event, "Quit"))
		{
			return EXIT;
		}
		else if (event.Type == sf::Event::MouseMoved)
		{
			sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseMove.X, event.MouseMove.Y, &ConfigOptions::getView());
			m_cursor.moveOnSquare(BoardAlignedSprite::toSquares(mouseCoords), false);
		}
		else if(m_iHandler->testEvent(event, "Up"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, -1);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(m_iHandler->testEvent(event, "Left"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(-1, 0);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(m_iHandler->testEvent(event, "Down"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, 1);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(m_iHandler->testEvent(event, "Right"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(1, 0);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(playerHasHand())
		{
			if(m_iHandler->testEvent(event, "Save"))
			{
				m_game.saveToFile(BACKUP_FILE);
			}
			else if(m_iHandler->testEvent(event, "Load"))
			{
				m_game.loadFromFile(BACKUP_FILE);
				refreshAll();
			}
			else if (m_iHandler->testEvent(event, "LClick"))
			{
				sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
				sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
				if(isValid(s))
					clickOn(s);
				else if(!m_game.hasStarted())
				{
					PieceType type = m_placementUI.click(mouseCoords);
					if(type == NB_PIECES) //end of turn
						tryAndEndTurn();
					else
						m_selectedType = type;
				}
			}
			if (m_iHandler->testEvent(event, "Choose"))
			{
				sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition());
				if(isValid(s))
					clickOn(s);
			}
			else if (m_iHandler->testEvent(event, "RClick"))
			{
				sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
				sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
				if(!m_game.hasStarted())
					remove(s);
			}
			else if (m_iHandler->testEvent(event, "EndTurn"))
			{
				tryAndEndTurn();
			}
			else if (event.Type == sf::Event::MouseWheelMoved)
			{
				if(event.MouseWheel.Delta > 0)
				{
					m_selectedType = m_placementUI.goUp();
				}
				else
				{
					m_selectedType = m_placementUI.goDown();
				}
			}
			else if (m_iHandler->testEvent(event, "Rabbit"))
			{
				selectPieceType(RABBIT);
			}
			else if (m_iHandler->testEvent(event, "Cat"))
			{
				selectPieceType(CAT);
			}
			else if (m_iHandler->testEvent(event, "Dog"))
			{
				selectPieceType(DOG);
			}
			else if (m_iHandler->testEvent(event, "Horse"))
			{
				selectPieceType(HORSE);
			}
			else if (m_iHandler->testEvent(event, "Camel"))
			{
				selectPieceType(CAMEL);
			}
			else if (m_iHandler->testEvent(event, "Elephant"))
			{
				selectPieceType(ELEPHANT);
			}
		} //end of if(playerHasHand)
		else if(isOver() && m_victorySign.GetColor().a == 255 && (m_iHandler->testEvent(event, "EndTurn") || m_iHandler->testEvent(event, "Choose") || m_iHandler->testEvent(event, "LClick")))
		{
			//if we do something after the match ends, remove the victory sign
			m_victorySign.SetColor(sf::Color(255,255,255,0));
		}

	} //end of event loop

	m_turnSign.update(elapsedTime);
	m_cursor.update(elapsedTime);
	for(std::map<PiecePtr, PieceSprite>::iterator it = m_pieces.begin(); it != m_pieces.end(); ++it)
		it->second.update(elapsedTime);

	//removing pieces that have finished disappearing
	for (auto it = m_disappearingPieces.begin(); it != m_disappearingPieces.end(); ) //++it done below if necessary
	{
		PiecePtr p = *it;
		if (m_pieces[p].hasDisappeared())
		{
			m_pieces.erase(p);
			it = m_disappearingPieces.erase(it); //gives it the value of the next element, thus no need to increase it again
		}
		else
			++it;
	}

	if(isOver()) //manages the appearance of the victory sign
	{
		int alpha = m_victorySign.GetColor().a;
		if(alpha > 0 && alpha < 255) //0 means it's disappeared already
		{
			alpha += (int) (elapsedTime * VICT_APP_SPD * 255);
			if(alpha > 255)
				alpha = 255;
			m_victorySign.SetColor(sf::Color(255,255,255,alpha));
		}
	}

	return nextScreen;
}