summaryrefslogtreecommitdiffstats
path: root/knights/challenge_graph_view.cpp
blob: b28b3f383ab3e61f2896cf675f921d94acd1cbd6 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/***************************************************************************
                  challenge_graph_view.cpp  -  description
                             -------------------
    begin                : Mon Jan 7 2002
    copyright            : (C) 2003 by Eric Faccer
    email                : e.faccer@qut.edu.au
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <string>
#include <tqpoint.h>
#include <tqstring.h>

#include "challenge_graph_view.moc"

#include "challenge_graph.h"
#include "challenge_rectangle.h"

///////////////////////////////////////
//
//	Challenge_Graph_View::Constructor
//
///////////////////////////////////////
Challenge_Graph_View::Challenge_Graph_View(TQCanvas& c, TQWidget * parent,const char* name, WFlags f, TQLabel *qsb)
 : TQCanvasView(&c,parent,name,f), canvas(c), statusbar(qsb)
{
	setHScrollBarMode( TQScrollView::AlwaysOff );
	setVScrollBarMode( TQScrollView::AlwaysOff );

	if ( parent )
		parent->installEventFilter( this );
	TQScrollView::viewport()->setMouseTracking(true);
}
///////////////////////////////////////
//
//	Challenge_Graph_View::Destructor
//
///////////////////////////////////////
Challenge_Graph_View::~Challenge_Graph_View()
{
}
///////////////////////////////////////
//
//	Challenge_Graph_View::contentsMousePressEvent
//
///////////////////////////////////////
void Challenge_Graph_View::contentsMousePressEvent(TQMouseEvent* e)
{
	TQCanvasItemList l = canvas.collisions(e->pos());
	TQCanvasItemList::Iterator it = l.begin();
	for(; it != l.end(); ++it )
	{
		Challenge_Rectangle *cr = dynamic_cast<Challenge_Rectangle *>(*it);
		Challenge_Game *g = cr->getGame();
		if( e->button() == TQt::LeftButton )
			emit leftClick( g->id() );
		if( e->button() == TQt::RightButton )
			emit rightClick( g, e->globalPos() );
		return;
	}
	if( e->button() == TQt::RightButton )
		emit rightClick( NULL, e->globalPos() ); // We need to catch all right clicks
}
///////////////////////////////////////
//
//	Challenge_Graph_View::reset
//
///////////////////////////////////////
void Challenge_Graph_View::reset()
{
	TQCanvasItemList list = canvas.allItems();
	TQCanvasItemList::Iterator it = list.begin();
	for(; it != list.end(); ++it )
	{
		Challenge_Rectangle *cr = dynamic_cast<Challenge_Rectangle *>(*it);
		Challenge_Game *g = cr->getGame();
		delete g;
		if ( *it )
			delete *it;
	}
}
///////////////////////////////////////
//
//	Challenge_Graph_View::contentsMouseMoveEvent
//
///////////////////////////////////////
void Challenge_Graph_View::contentsMouseMoveEvent(TQMouseEvent* e)
{
	TQString match;
	TQCanvasItemList l = canvas.collisions(e->pos());
	TQCanvasItemList::Iterator it = l.begin();
	for(; it!=l.end(); ++it)
	{
		Challenge_Rectangle *cr = dynamic_cast<Challenge_Rectangle *>(*it);
		Challenge_Game *g = cr->getGame();

		match = i18n( " Name: %1 Rating: %2 Match Type: %3 %4 Base Time: %5 Increment: %6" )
								.arg( g->_player ).arg( g->rating() ).arg( g->_match_type ).arg( g->_is_rated )
								.arg( g->clock() ).arg( g->increment() );
		break;
	}
	statusbar->setText( match );
}