1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/****************************************************************
**
** Attal : Lords of Doom
**
** mapView.cpp
** subclass of QCanvasSprite that handles mouse event ...
**
** Version : $Id: mapView.cpp,v 1.4 2004/11/29 19:38:25 lusum Exp $
**
** Author(s) : Pascal Audoux - Cyrille Verrier
**
** Date : 08/08/2000
**
** Licence :
** 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, 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.
**
****************************************************************/
#include "mapView.h"
// generic include files
// include files for QT
// application specific includes
#include "libCommon/log.h"
#include "libClient/cell.h"
//#include "libClient/lord.h"
/** subclass of QCanvasSprite that handles mouse event ... */
MapView::MapView( Map * map, QWidget * parent, const char * name, WFlags f )
: QCanvasView( map, parent, name, f )
{
viewport()->setMouseTracking( true ) ;
_press = false;
}
/** handles mouse event */
void MapView::contentsMouseMoveEvent( QMouseEvent * event )
{
QCanvasItemList list = canvas()->collisions( event->pos() );
for( unsigned int i = 0; i < list.count(); i++ ) {
if( list[i]->rtti() == Cell::RTTI ) {
Cell * cell = (Cell *) list[i];
if( cell->hit( event->pos() ) ) {
//emit sig_mouseMoved( (Cell*) (_map->at( cell->getRow(), cell->getCol() ) ) );
emit sig_mouseMoved( cell->getParent() );
}
}
}
}
void MapView::contentsMousePressEvent( QMouseEvent * event )
{
QCanvasItemList list = canvas()->collisions( event->pos() );
for( unsigned int i = 0; i < list.count(); i++ ) {
if( list[i]->rtti() == Cell::RTTI ) {
Cell * cell = (Cell *) list[i];
if( ( cell->hit( event->pos() ) ) && ( cell->getParent() == cell ) ) {
if( event->button() == RightButton ) {
emit sig_mouseRightPressed( cell );
} else {
emit sig_mouseLeftPressed( cell );
}
}
}
}
_press = true;
}
void MapView::contentsMouseReleaseEvent( QMouseEvent * )
{
_press = false;
emit sig_mouseReleased();
}
void MapView::contentsMouseDoubleClickEvent( QMouseEvent * event )
{
contentsMousePressEvent( event );
contentsMouseReleaseEvent( event );
}
void MapView::goToPosition(Cell * cell)
{
if(cell){
this->center((int) cell->x(),(int) cell->y());
}
}
|