Logo Search packages:      
Sourcecode: tagua version File versions  Download package

void Board::onMousePress ( const QPoint &  pos,
int  button 
) [virtual]

mouse press event

Definition at line 398 of file board.cpp.

References converter(), doMove(), m_drag_info, m_entity, m_premove_from, m_sprites, and selection.

                                                      {
  Point point = converter()->toLogical(pos);
  if (!m_sprites.valid(point))
      return;

  //BEGIN left click

  if (button == Qt::LeftButton) {
    if (m_entity.lock()->oneClickMoves()) {
      NormalUserMove m = m_entity.lock()->createMove(Point::invalid(), point);
      doMove(m);
    }
    else {
      shared_ptr<Sprite> piece = m_sprites[point].sprite();

      if (piece && m_entity.lock()->movable(point)) {
          cancelSelection();
          m_drag_info = DragInfoPtr(new DragInfo(point, pos, piece,
                            m_entity.lock()->validTurn(point)) );
          piece->raise();
      }

      // if selection is valid, (pre)move to point
      else if (selection != Point::invalid()) {
          piece = m_sprites[selection].sprite();
          Q_ASSERT(piece);
          NormalUserMove m = m_entity.lock()->createMove(selection, point);

          switch(m_entity.lock()->validTurn(selection)) {

            case Moving:
              doMove(m);
              cancelSelection();
              break;

            case Premoving:
              if (m_entity.lock()->testPremove(m)) {
                m_entity.lock()->addPremove(m);
                setPremove(m);
                cancelSelection();
              }
              break;

            default:
              break;
          }
      }
    }
  }

  //END left click

  //BEGIN right click

  else if (button == Qt::RightButton) {
    cancelSelection();
    if (point == m_premove_from || point == m_premove_to)
      cancelPremove();
    m_entity.lock()->handleRightClick(point);
  }

  //END right click
}


Generated by  Doxygen 1.6.0   Back to index