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 *
* [email protected] *
* *
* 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, QEvent *e )
{
Q_UNUSED(itemView);
Q_UNUSED(e);
reset();
}
EventInfo::EventInfo( ItemView *itemView, QMouseEvent *e )
{
pos = e->pos()/itemView->zoomLevel();
globalPos = e->globalPos();
isRightClick = e->button() == Qt::RightButton;
ctrlPressed = e->state() & QMouseEvent::ControlButton;
shiftPressed = e->state() & QMouseEvent::ShiftButton;
altPressed = e->state() & QMouseEvent::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, QWheelEvent *e )
{
pos = e->pos()/itemView->zoomLevel();
globalPos = e->globalPos();
isRightClick = false;
ctrlPressed = e->state() & QMouseEvent::ControlButton;
shiftPressed = e->state() & QMouseEvent::ShiftButton;
altPressed = e->state() & QMouseEvent::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;
}
QMouseEvent *EventInfo::mousePressEvent( int dx, int dy ) const
{
return new QMouseEvent( QEvent::MouseButtonPress,
pos + QPoint( dx, dy ),
(isRightClick ? Qt::RightButton : Qt::LeftButton),
(isRightClick ? Qt::RightButton : Qt::LeftButton) |
(ctrlPressed ? Qt::ControlButton : 0 ) |
(shiftPressed ? Qt::ShiftButton : 0 ) |
(altPressed ? Qt::AltButton : 0 ) );
}
QMouseEvent *EventInfo::mouseReleaseEvent( int dx, int dy ) const
{
return new QMouseEvent( QEvent::MouseButtonRelease,
pos + QPoint( dx, dy ),
(isRightClick ? Qt::RightButton : Qt::LeftButton),
(isRightClick ? Qt::RightButton : Qt::LeftButton) |
(ctrlPressed ? Qt::ControlButton : 0 ) |
(shiftPressed ? Qt::ShiftButton : 0 ) |
(altPressed ? Qt::AltButton : 0 ) );
}
QMouseEvent *EventInfo::mouseDoubleClickEvent( int dx, int dy ) const
{
return new QMouseEvent( QEvent::MouseButtonDblClick,
pos + QPoint( dx, dy ),
(isRightClick ? Qt::RightButton : Qt::LeftButton),
(isRightClick ? Qt::RightButton : Qt::LeftButton) |
(ctrlPressed ? Qt::ControlButton : 0 ) |
(shiftPressed ? Qt::ShiftButton : 0 ) |
(altPressed ? Qt::AltButton : 0 ) );
}
QMouseEvent *EventInfo::mouseMoveEvent( int dx, int dy ) const
{
return new QMouseEvent( QEvent::MouseMove,
pos + QPoint( dx, dy ),
Qt::NoButton,
(ctrlPressed ? Qt::ControlButton : 0 ) |
(shiftPressed ? Qt::ShiftButton : 0 ) |
(altPressed ? Qt::AltButton : 0 ) );
}
QWheelEvent *EventInfo::wheelEvent( int dx, int dy ) const
{
return new QWheelEvent( pos + QPoint( dx, dy ),
scrollDelta,
(ctrlPressed ? Qt::ControlButton : 0 ) |
(shiftPressed ? Qt::ShiftButton : 0 ) |
(altPressed ? Qt::AltButton : 0 ),
scrollOrientation );
}
|