~ubuntu-branches/ubuntu/oneiric/kolourpaint/oneiric-proposed

« back to all changes in this revision

Viewing changes to views/kpView_Events.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 12:20:39 UTC
  • Revision ID: james.westby@ubuntu.com-20110710122039-a7bokz6isao1ldt2
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
   Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
 
4
   Copyright (c) 2005 Kazuki Ohta <mover@hct.zaq.ne.jp>
 
5
   Copyright (c) 2010 Tasuku Suzuki <stasuku@gmail.com>
 
6
   All rights reserved.
 
7
 
 
8
   Redistribution and use in source and binary forms, with or without
 
9
   modification, are permitted provided that the following conditions
 
10
   are met:
 
11
 
 
12
   1. Redistributions of source code must retain the above copyright
 
13
      notice, this list of conditions and the following disclaimer.
 
14
   2. Redistributions in binary form must reproduce the above copyright
 
15
      notice, this list of conditions and the following disclaimer in the
 
16
      documentation and/or other materials provided with the distribution.
 
17
 
 
18
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 
19
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
20
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
21
   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 
22
   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
23
   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
24
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
25
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
27
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
*/
 
29
 
 
30
 
 
31
#define DEBUG_KP_VIEW 0
 
32
#define DEBUG_KP_VIEW_RENDERER ((DEBUG_KP_VIEW && 1) || 0)
 
33
 
 
34
 
 
35
#include <kpView.h>
 
36
#include <kpViewPrivate.h>
 
37
 
 
38
#if DEBUG_KP_VIEW
 
39
#include <KDebug>
 
40
#endif
 
41
 
 
42
#include <QKeyEvent>
 
43
#include <QMouseEvent>
 
44
 
 
45
#include <kpTool.h>
 
46
 
 
47
#include <kdebug.h>
 
48
 
 
49
//---------------------------------------------------------------------
 
50
 
 
51
// protected virtual [base QWidget]
 
52
void kpView::mouseMoveEvent (QMouseEvent *e)
 
53
{
 
54
#if DEBUG_KP_VIEW && 0
 
55
    kDebug () << "kpView(" << objectName () << ")::mouseMoveEvent ("
 
56
               << e->x () << "," << e->y () << ")"
 
57
               << endl;
 
58
#endif
 
59
 
 
60
    // TODO: This is wrong if you leaveEvent the mainView by mouseMoving on the
 
61
    //       mainView, landing on top of the thumbnailView cleverly put on top
 
62
    //       of the mainView.
 
63
    setHasMouse (rect ().contains (e->pos ()));
 
64
 
 
65
    if (tool ())
 
66
        tool ()->mouseMoveEvent (e);
 
67
 
 
68
    e->accept ();
 
69
}
 
70
 
 
71
// protected virtual [base QWidget]
 
72
void kpView::mousePressEvent (QMouseEvent *e)
 
73
{
 
74
#if DEBUG_KP_VIEW && 0
 
75
    kDebug () << "kpView(" << objectName () << ")::mousePressEvent ("
 
76
               << e->x () << "," << e->y () << ")"
 
77
               << endl;
 
78
#endif
 
79
 
 
80
    setHasMouse (true);
 
81
 
 
82
    if (tool ())
 
83
        tool ()->mousePressEvent (e);
 
84
 
 
85
    e->accept ();
 
86
}
 
87
 
 
88
//---------------------------------------------------------------------
 
89
 
 
90
// protected virtual [base QWidget]
 
91
void kpView::mouseReleaseEvent (QMouseEvent *e)
 
92
{
 
93
#if DEBUG_KP_VIEW && 0
 
94
    kDebug () << "kpView(" << objectName () << ")::mouseReleaseEvent ("
 
95
               << e->x () << "," << e->y () << ")"
 
96
               << endl;
 
97
#endif
 
98
 
 
99
    setHasMouse (rect ().contains (e->pos ()));
 
100
 
 
101
    if (tool ())
 
102
        tool ()->mouseReleaseEvent (e);
 
103
 
 
104
    e->accept ();
 
105
}
 
106
 
 
107
//---------------------------------------------------------------------
 
108
 
 
109
// public virtual [base QWidget]
 
110
void kpView::wheelEvent (QWheelEvent *e)
 
111
{
 
112
    if (tool ())
 
113
        tool ()->wheelEvent (e);
 
114
}
 
115
 
 
116
//---------------------------------------------------------------------
 
117
 
 
118
// protected virtual [base QWidget]
 
119
void kpView::keyPressEvent (QKeyEvent *e)
 
120
{
 
121
#if DEBUG_KP_VIEW
 
122
    kDebug () << "kpView(" << objectName () << ")::keyPressEvent()" << e->text();
 
123
#endif
 
124
 
 
125
    if (tool ())
 
126
        tool ()->keyPressEvent (e);
 
127
 
 
128
    e->accept ();
 
129
}
 
130
 
 
131
//---------------------------------------------------------------------
 
132
 
 
133
// protected virtual [base QWidget]
 
134
void kpView::keyReleaseEvent (QKeyEvent *e)
 
135
{
 
136
#if DEBUG_KP_VIEW && 0
 
137
    kDebug () << "kpView(" << objectName () << ")::keyReleaseEvent()";
 
138
#endif
 
139
 
 
140
    if (tool ())
 
141
        tool ()->keyReleaseEvent (e);
 
142
 
 
143
    e->accept ();
 
144
}
 
145
 
 
146
//---------------------------------------------------------------------
 
147
 
 
148
// protected virtual [base QWidget]
 
149
void kpView::inputMethodEvent (QInputMethodEvent *e)
 
150
{
 
151
#if DEBUG_KP_VIEW && 1
 
152
    kDebug () << "kpView(" << objectName () << ")::inputMethodEvent()";
 
153
#endif
 
154
 
 
155
    if (tool ())
 
156
        tool ()->inputMethodEvent (e);
 
157
    e->accept ();
 
158
}
 
159
 
 
160
// protected virtual [base QWidget]
 
161
bool kpView::event (QEvent *e)
 
162
{
 
163
#if DEBUG_KP_VIEW
 
164
    kDebug () << "kpView::event() invoking kpTool::event()";
 
165
#endif
 
166
    if (tool () && tool ()->viewEvent (e))
 
167
    {
 
168
    #if DEBUG_KP_VIEW
 
169
        kDebug () << "\tkpView::event() - tool said eat event, ret true";
 
170
    #endif
 
171
        return true;
 
172
    }
 
173
 
 
174
#if DEBUG_KP_VIEW
 
175
    kDebug () << "\tkpView::event() - no tool or said false, call QWidget::event()";
 
176
#endif
 
177
    return QWidget::event (e);
 
178
}
 
179
 
 
180
 
 
181
// protected virtual [base QWidget]
 
182
void kpView::focusInEvent (QFocusEvent *e)
 
183
{
 
184
#if DEBUG_KP_VIEW && 0
 
185
    kDebug () << "kpView(" << objectName () << ")::focusInEvent()";
 
186
#endif
 
187
    if (tool ())
 
188
        tool ()->focusInEvent (e);
 
189
}
 
190
 
 
191
// protected virtual [base QWidget]
 
192
void kpView::focusOutEvent (QFocusEvent *e)
 
193
{
 
194
#if DEBUG_KP_VIEW && 0
 
195
    kDebug () << "kpView(" << objectName () << ")::focusOutEvent()";
 
196
#endif
 
197
    if (tool ())
 
198
        tool ()->focusOutEvent (e);
 
199
}
 
200
 
 
201
 
 
202
// protected virtual [base QWidget]
 
203
void kpView::enterEvent (QEvent *e)
 
204
{
 
205
#if DEBUG_KP_VIEW && 0
 
206
    kDebug () << "kpView(" << objectName () << ")::enterEvent()";
 
207
#endif
 
208
 
 
209
    // Don't call setHasMouse(true) as it displays the brush cursor (if
 
210
    // active) when dragging open a menu and then dragging
 
211
    // past the extents of the menu due to Qt sending us an EnterEvent.
 
212
    // We're already covered by MouseMoveEvent anyway.
 
213
    //
 
214
    // But disabling this causes a more serious problem: RMB on a text
 
215
    // box and Esc.  We have no other reliable way to determine if the
 
216
    // mouse is still above the view (user could have moved mouse out
 
217
    // while RMB menu was up) and hence the cursor is not updated.
 
218
    setHasMouse (true);
 
219
 
 
220
    if (tool ())
 
221
        tool ()->enterEvent (e);
 
222
}
 
223
 
 
224
// protected virtual [base QWidget]
 
225
void kpView::leaveEvent (QEvent *e)
 
226
{
 
227
#if DEBUG_KP_VIEW && 0
 
228
    kDebug () << "kpView(" << objectName () << ")::leaveEvent()";
 
229
#endif
 
230
 
 
231
    setHasMouse (false);
 
232
    if (tool ())
 
233
        tool ()->leaveEvent (e);
 
234
}
 
235
 
 
236
 
 
237
// protected virtual [base QWidget]
 
238
void kpView::dragEnterEvent (QDragEnterEvent *)
 
239
{
 
240
#if DEBUG_KP_VIEW && 1
 
241
    kDebug () << "kpView(" << objectName () << ")::dragEnterEvent()";
 
242
#endif
 
243
 
 
244
    setHasMouse (true);
 
245
}
 
246
 
 
247
// protected virtual [base QWidget]
 
248
void kpView::dragLeaveEvent (QDragLeaveEvent *)
 
249
{
 
250
#if DEBUG_KP_VIEW && 1
 
251
    kDebug () << "kpView(" << objectName () << ")::dragLeaveEvent";
 
252
#endif
 
253
 
 
254
    setHasMouse (false);
 
255
}
 
256
 
 
257
 
 
258
// protected virtual [base QWidget]
 
259
void kpView::resizeEvent (QResizeEvent *e)
 
260
{
 
261
#if DEBUG_KP_VIEW && 1
 
262
    kDebug () << "kpView(" << objectName () << ")::resizeEvent("
 
263
               << e->size ()
 
264
               << " vs actual=" << size ()
 
265
               << ") old=" << e->oldSize () << endl;
 
266
#endif
 
267
 
 
268
    QWidget::resizeEvent (e);
 
269
 
 
270
    emit sizeChanged (width (), height ());
 
271
    emit sizeChanged (size ());
 
272
}