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

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

mouse release event

Definition at line 462 of file board.cpp.

References clearTags(), converter(), doMove(), enqueue(), lastSelection, m_drag_info, m_entity, and m_sprites.

                                                        {
  Point point = converter()->toLogical(pos);

  //BEGIN left click

  if (button == Qt::LeftButton) {

    if (m_drag_info) {
//      Q_ASSERT(m_drag_info->piece);
      Q_ASSERT(m_drag_info->sprite);
      bool moved = false;

      // remove valid move highlighting
      clearTags("validmove");

      // toggle selection if the piece didn't move
      if (m_drag_info->from == point) {
        if (lastSelection == point)
          cancelSelection();
        else
          setSelection(point);
      }

      else  {
        NormalUserMove m = m_entity.lock()->createMove(m_drag_info->from, point);
        if (!m_sprites.valid(point))
          m.to = Point::invalid();

        switch(m_entity.lock()->validTurn(m_drag_info->from)) {

          case Moving:
            if (doMove(m))
              moved = true;
            break;

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

          default:
            break;
        }
      }

      shared_ptr<Sprite> s = m_sprites[m_drag_info->from].sprite();
      if (!moved && s && s->pos() != converter()->toReal(m_drag_info->from)) {
        Q_ASSERT(s);
        QPoint real = converter()->toReal(m_drag_info->from);
        if( (point == m_drag_info->from) ? 0/* !m_anim_movement*/ : 0 /* !m_anim_fade*/) //BROKEN
          enqueue(shared_ptr<Animation>(new InstantAnimation(s, real)));
        else if (point == m_drag_info->from)
          enqueue(shared_ptr<Animation>(new MovementAnimation(s, real)));
        else
          enqueue(shared_ptr<Animation>(new TeleportAnimation(s, s->pos(), real)));
      }

      m_drag_info = DragInfoPtr();
    }
  }

  //END left button
}


Generated by  Doxygen 1.6.0   Back to index