summaryrefslogtreecommitdiffstats
path: root/src/eventinfo.cpp
blob: 3a63c309de9d1cee76dffb0c1b2fdd54c213cf04 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   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 "eventinfo.h"
#include "itemdocument.h"
#include "itemview.h"


EventInfo::EventInfo()
{
	reset();
}


EventInfo::EventInfo( ItemView *itemView, TQEvent *e )
{
	Q_UNUSED(itemView);
	Q_UNUSED(e);
	reset();
}

EventInfo::EventInfo( ItemView *itemView, TQMouseEvent *e )
{
	pos = e->pos()/itemView->zoomLevel();
	globalPos = e->globalPos();
	isRightClick = e->button() == Qt::RightButton;
	ctrlPressed = e->state() & TQt::ControlButton;
	shiftPressed = e->state() & TQt::ShiftButton;
	altPressed = e->state() & TQt::AltButton;
	if ( ItemDocument * id = dynamic_cast<ItemDocument*>(itemView->document()) )
			qcanvasItemClickedOn = id->itemAtTop(pos);
	itemRtti = qcanvasItemClickedOn ? qcanvasItemClickedOn->rtti() : ItemDocument::RTTI::None;
	scrollDelta = 0;
	scrollOrientation = Qt::Vertical;
}


EventInfo::EventInfo( ItemView *itemView, TQWheelEvent *e )
{
	pos = e->pos()/itemView->zoomLevel();
	globalPos = e->globalPos();
	isRightClick = false;
	ctrlPressed = e->state() & TQt::ControlButton;
	shiftPressed = e->state() & TQt::ShiftButton;
	altPressed = e->state() & TQt::AltButton;
	if ( ItemDocument * id = dynamic_cast<ItemDocument*>(itemView->document()) )
		qcanvasItemClickedOn = id->itemAtTop(pos);
	itemRtti = qcanvasItemClickedOn ? qcanvasItemClickedOn->rtti() : ItemDocument::RTTI::None;
	scrollDelta = e->delta();
	scrollOrientation = e->orientation();
	
// 	kdDebug() << "scrollOrientation="<<scrollOrientation<<endl;
}


void EventInfo::reset()
{
	isRightClick = false;
	ctrlPressed = false;
	shiftPressed = false;
	altPressed = false;
	qcanvasItemClickedOn = 0l;
	itemRtti = ItemDocument::RTTI::None;
	scrollDelta = 0;
	scrollOrientation = Qt::Vertical;
}


TQMouseEvent *EventInfo::mousePressEvent( int dx, int dy ) const
{
	return new TQMouseEvent( TQEvent::MouseButtonPress,
							pos + TQPoint( dx, dy ),
							(isRightClick ? Qt::RightButton : Qt::LeftButton), 
							(isRightClick ? Qt::RightButton : Qt::LeftButton) |
									(ctrlPressed ? TQt::ControlButton : 0 ) |
									(shiftPressed ? TQt::ShiftButton : 0 ) |
									(altPressed ? TQt::AltButton : 0 ) );
}


TQMouseEvent *EventInfo::mouseReleaseEvent( int dx, int dy ) const
{
	return new TQMouseEvent( TQEvent::MouseButtonRelease,
							pos + TQPoint( dx, dy ),
							(isRightClick ? Qt::RightButton : Qt::LeftButton), 
							(isRightClick ? Qt::RightButton : Qt::LeftButton) |
									(ctrlPressed ? TQt::ControlButton : 0 ) |
									(shiftPressed ? TQt::ShiftButton : 0 ) |
									(altPressed ? TQt::AltButton : 0 ) );
}


TQMouseEvent *EventInfo::mouseDoubleClickEvent( int dx, int dy ) const
{
	return new TQMouseEvent( TQEvent::MouseButtonDblClick,
							pos + TQPoint( dx, dy ),
							(isRightClick ? Qt::RightButton : Qt::LeftButton), 
							(isRightClick ? Qt::RightButton : Qt::LeftButton) |
									(ctrlPressed ? TQt::ControlButton : 0 ) |
									(shiftPressed ? TQt::ShiftButton : 0 ) |
									(altPressed ? TQt::AltButton : 0 ) );
}


TQMouseEvent *EventInfo::mouseMoveEvent( int dx, int dy ) const
{
	return new TQMouseEvent( TQEvent::MouseMove,
							pos + TQPoint( dx, dy ),
							Qt::NoButton, 
							(ctrlPressed ? TQt::ControlButton : 0 ) |
									(shiftPressed ? TQt::ShiftButton : 0 ) |
									(altPressed ? TQt::AltButton : 0 ) );
}


TQWheelEvent *EventInfo::wheelEvent( int dx, int dy ) const
{
	return new TQWheelEvent( pos + TQPoint( dx, dy ),
							scrollDelta,
							(ctrlPressed ? TQt::ControlButton : 0 ) |
									(shiftPressed ? TQt::ShiftButton : 0 ) |
									(altPressed ? TQt::AltButton : 0 ),
							scrollOrientation );
}