libkdcraw from trunk : update internal LibRaw to 0.7.0-alpha4
[kdegraphics.git] / kolourpaint / views / kpView_Events.cpp
blobe16683cdef37c43cf8fa6190e8bcaa28545a4815
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 Copyright (c) 2005 Kazuki Ohta <mover@hct.zaq.ne.jp>
5 All rights reserved.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #define DEBUG_KP_VIEW 0
31 #define DEBUG_KP_VIEW_RENDERER ((DEBUG_KP_VIEW && 1) || 0)
34 #include <kpView.h>
35 #include <kpViewPrivate.h>
37 #include <QKeyEvent>
38 #include <QMouseEvent>
40 #include <kpTool.h>
43 // protected virtual [base QWidget]
44 void kpView::mouseMoveEvent (QMouseEvent *e)
46 #if DEBUG_KP_VIEW && 0
47 kDebug () << "kpView(" << objectName () << ")::mouseMoveEvent ("
48 << e->x () << "," << e->y () << ")"
49 << endl;
50 #endif
52 // TODO: This is wrong if you leaveEvent the mainView by mouseMoving on the
53 // mainView, landing on top of the thumbnailView cleverly put on top
54 // of the mainView.
55 setHasMouse (rect ().contains (e->pos ()));
57 if (tool ())
58 tool ()->mouseMoveEvent (e);
60 e->accept ();
63 // protected virtual [base QWidget]
64 void kpView::mousePressEvent (QMouseEvent *e)
66 #if DEBUG_KP_VIEW && 0
67 kDebug () << "kpView(" << objectName () << ")::mousePressEvent ("
68 << e->x () << "," << e->y () << ")"
69 << endl;
70 #endif
72 setHasMouse (true);
74 if (tool ())
75 tool ()->mousePressEvent (e);
77 e->accept ();
80 // protected virtual [base QWidget]
81 void kpView::mouseReleaseEvent (QMouseEvent *e)
83 #if DEBUG_KP_VIEW && 0
84 kDebug () << "kpView(" << objectName () << ")::mouseReleaseEvent ("
85 << e->x () << "," << e->y () << ")"
86 << endl;
87 #endif
89 setHasMouse (rect ().contains (e->pos ()));
91 if (tool ())
92 tool ()->mouseReleaseEvent (e);
94 e->accept ();
98 // public virtual [base QWidget]
99 void kpView::wheelEvent (QWheelEvent *e)
101 if (tool ())
102 tool ()->wheelEvent (e);
106 // protected virtual [base QWidget]
107 void kpView::keyPressEvent (QKeyEvent *e)
109 #if DEBUG_KP_VIEW && 0
110 kDebug () << "kpView(" << objectName () << ")::keyPressEvent()";
111 #endif
113 if (tool ())
114 tool ()->keyPressEvent (e);
116 e->accept ();
119 // protected virtual [base QWidget]
120 void kpView::keyReleaseEvent (QKeyEvent *e)
122 #if DEBUG_KP_VIEW && 0
123 kDebug () << "kpView(" << objectName () << ")::keyReleaseEvent()";
124 #endif
126 if (tool ())
127 tool ()->keyReleaseEvent (e);
129 e->accept ();
133 // COMPAT: Need to update InputMethod support.
134 #if 0
136 // private virtual
137 void kpView::imStartEvent (QIMEvent *e)
139 #if DEBUG_KP_VIEW && 1
140 kDebug () << "kpView(" << objectName () << ")::imStartEvent";
141 #endif
143 if (tool ())
144 tool ()->imStartEvent (e);
145 e->accept ();
148 // private virtual
149 void kpView::imComposeEvent (QIMEvent *e)
151 #if DEBUG_KP_VIEW && 1
152 kDebug () << "kpView(" << objectName () << ")::imComposeEvent";
153 #endif
155 if (tool ())
156 tool ()->imComposeEvent (e);
157 e->accept ();
160 // private virtual
161 void kpView::imEndEvent (QIMEvent *e)
163 #if DEBUG_KP_VIEW && 1
164 kDebug () << "kpView(" << objectName () << ")::imEndEvent";
165 #endif
167 if (tool ())
168 tool ()->imEndEvent (e);
169 e->accept ();
172 #endif // COMPAT
175 // protected virtual [base QWidget]
176 bool kpView::event (QEvent *e)
178 #if DEBUG_KP_VIEW
179 kDebug () << "kpView::event() invoking kpTool::event()";
180 #endif
181 if (tool () && tool ()->viewEvent (e))
183 #if DEBUG_KP_VIEW
184 kDebug () << "\tkpView::event() - tool said eat event, ret true";
185 #endif
186 return true;
189 #if DEBUG_KP_VIEW
190 kDebug () << "\tkpView::event() - no tool or said false, call QWidget::event()";
191 #endif
192 return QWidget::event (e);
196 // protected virtual [base QWidget]
197 void kpView::focusInEvent (QFocusEvent *e)
199 #if DEBUG_KP_VIEW && 0
200 kDebug () << "kpView(" << objectName () << ")::focusInEvent()";
201 #endif
202 if (tool ())
203 tool ()->focusInEvent (e);
206 // protected virtual [base QWidget]
207 void kpView::focusOutEvent (QFocusEvent *e)
209 #if DEBUG_KP_VIEW && 0
210 kDebug () << "kpView(" << objectName () << ")::focusOutEvent()";
211 #endif
212 if (tool ())
213 tool ()->focusOutEvent (e);
217 // protected virtual [base QWidget]
218 void kpView::enterEvent (QEvent *e)
220 #if DEBUG_KP_VIEW && 0
221 kDebug () << "kpView(" << objectName () << ")::enterEvent()";
222 #endif
224 // Don't call setHasMouse(true) as it displays the brush cursor (if
225 // active) when dragging open a menu and then dragging
226 // past the extents of the menu due to Qt sending us an EnterEvent.
227 // We're already covered by MouseMoveEvent anyway.
229 // But disabling this causes a more serious problem: RMB on a text
230 // box and Esc. We have no other reliable way to determine if the
231 // mouse is still above the view (user could have moved mouse out
232 // while RMB menu was up) and hence the cursor is not updated.
233 setHasMouse (true);
235 if (tool ())
236 tool ()->enterEvent (e);
239 // protected virtual [base QWidget]
240 void kpView::leaveEvent (QEvent *e)
242 #if DEBUG_KP_VIEW && 0
243 kDebug () << "kpView(" << objectName () << ")::leaveEvent()";
244 #endif
246 setHasMouse (false);
247 if (tool ())
248 tool ()->leaveEvent (e);
252 // protected virtual [base QWidget]
253 void kpView::dragEnterEvent (QDragEnterEvent *)
255 #if DEBUG_KP_VIEW && 1
256 kDebug () << "kpView(" << objectName () << ")::dragEnterEvent()";
257 #endif
259 setHasMouse (true);
262 // protected virtual [base QWidget]
263 void kpView::dragLeaveEvent (QDragLeaveEvent *)
265 #if DEBUG_KP_VIEW && 1
266 kDebug () << "kpView(" << objectName () << ")::dragLeaveEvent";
267 #endif
269 setHasMouse (false);
273 // protected virtual [base QWidget]
274 void kpView::resizeEvent (QResizeEvent *e)
276 #if DEBUG_KP_VIEW && 1
277 kDebug () << "kpView(" << objectName () << ")::resizeEvent("
278 << e->size ()
279 << " vs actual=" << size ()
280 << ") old=" << e->oldSize () << endl;
281 #endif
283 QWidget::resizeEvent (e);
285 emit sizeChanged (width (), height ());
286 emit sizeChanged (size ());