/***************************************************************************
 *   Copyright (C) 2005 by Tavarez Arnaud Bakoula                          *
 *   tbakoula@yahoo.fr                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "dragmark.h"

#include <qevent.h>

/*!
 *  \class DragMark 
 *  \brief The DragMark class is a drag and drop object for
 *  transferring pieces.
 *
 *  With this class you can provide the construction of piece
 *  by a widget such as MarkSrc or Tick. So they know what
 *  is the state of the desired piece.
 */

/*!
 *  The type of information that the object can decode.
 */
const char* DragMark::type = "master/mark";

/*!
 *  Constructs the a pion drag object and sets its data to
 *  \a state. \a dragSource must be the drag source. \a name
 *  is the name of the object.
 */
DragMark::DragMark( uchar state, QWidget* dragSource, const char* name )
    :  QStoredDrag( type, dragSource, name )
{
    QByteArray data( 1 );
    data[0] = state;
    setEncodedData( data );
}

/*!
 *  Returns TRUE if the information in \a e can be decoded into a
 *  state.
 *  \sa decode()
 */
bool
DragMark::canDecode( QDragMoveEvent* e )
{
    return e->provides( type );
}
/*!
 *  Attempts to decode the dropped information in \a e into state.
 *  Returns TRUE if successful; otherwise returns FALSE.
 *  \sa canDecode()
 */
bool
DragMark::decode( QDropEvent* e, uint& state )
{
    QByteArray payload = e->encodedData( type );

    if ( payload.size() )
    {
      e->accept();
      state = (int) payload[0];
      return TRUE;
    }
    else
      return FALSE;
}
