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>
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions
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.
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.
31
#define DEBUG_KP_VIEW 0
32
#define DEBUG_KP_VIEW_RENDERER ((DEBUG_KP_VIEW && 1) || 0)
36
#include <kpViewPrivate.h>
43
#include <QMouseEvent>
49
//---------------------------------------------------------------------
51
// protected virtual [base QWidget]
52
void kpView::mouseMoveEvent (QMouseEvent *e)
54
#if DEBUG_KP_VIEW && 0
55
kDebug () << "kpView(" << objectName () << ")::mouseMoveEvent ("
56
<< e->x () << "," << e->y () << ")"
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
63
setHasMouse (rect ().contains (e->pos ()));
66
tool ()->mouseMoveEvent (e);
71
// protected virtual [base QWidget]
72
void kpView::mousePressEvent (QMouseEvent *e)
74
#if DEBUG_KP_VIEW && 0
75
kDebug () << "kpView(" << objectName () << ")::mousePressEvent ("
76
<< e->x () << "," << e->y () << ")"
83
tool ()->mousePressEvent (e);
88
//---------------------------------------------------------------------
90
// protected virtual [base QWidget]
91
void kpView::mouseReleaseEvent (QMouseEvent *e)
93
#if DEBUG_KP_VIEW && 0
94
kDebug () << "kpView(" << objectName () << ")::mouseReleaseEvent ("
95
<< e->x () << "," << e->y () << ")"
99
setHasMouse (rect ().contains (e->pos ()));
102
tool ()->mouseReleaseEvent (e);
107
//---------------------------------------------------------------------
109
// public virtual [base QWidget]
110
void kpView::wheelEvent (QWheelEvent *e)
113
tool ()->wheelEvent (e);
116
//---------------------------------------------------------------------
118
// protected virtual [base QWidget]
119
void kpView::keyPressEvent (QKeyEvent *e)
122
kDebug () << "kpView(" << objectName () << ")::keyPressEvent()" << e->text();
126
tool ()->keyPressEvent (e);
131
//---------------------------------------------------------------------
133
// protected virtual [base QWidget]
134
void kpView::keyReleaseEvent (QKeyEvent *e)
136
#if DEBUG_KP_VIEW && 0
137
kDebug () << "kpView(" << objectName () << ")::keyReleaseEvent()";
141
tool ()->keyReleaseEvent (e);
146
//---------------------------------------------------------------------
148
// protected virtual [base QWidget]
149
void kpView::inputMethodEvent (QInputMethodEvent *e)
151
#if DEBUG_KP_VIEW && 1
152
kDebug () << "kpView(" << objectName () << ")::inputMethodEvent()";
156
tool ()->inputMethodEvent (e);
160
// protected virtual [base QWidget]
161
bool kpView::event (QEvent *e)
164
kDebug () << "kpView::event() invoking kpTool::event()";
166
if (tool () && tool ()->viewEvent (e))
169
kDebug () << "\tkpView::event() - tool said eat event, ret true";
175
kDebug () << "\tkpView::event() - no tool or said false, call QWidget::event()";
177
return QWidget::event (e);
181
// protected virtual [base QWidget]
182
void kpView::focusInEvent (QFocusEvent *e)
184
#if DEBUG_KP_VIEW && 0
185
kDebug () << "kpView(" << objectName () << ")::focusInEvent()";
188
tool ()->focusInEvent (e);
191
// protected virtual [base QWidget]
192
void kpView::focusOutEvent (QFocusEvent *e)
194
#if DEBUG_KP_VIEW && 0
195
kDebug () << "kpView(" << objectName () << ")::focusOutEvent()";
198
tool ()->focusOutEvent (e);
202
// protected virtual [base QWidget]
203
void kpView::enterEvent (QEvent *e)
205
#if DEBUG_KP_VIEW && 0
206
kDebug () << "kpView(" << objectName () << ")::enterEvent()";
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.
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.
221
tool ()->enterEvent (e);
224
// protected virtual [base QWidget]
225
void kpView::leaveEvent (QEvent *e)
227
#if DEBUG_KP_VIEW && 0
228
kDebug () << "kpView(" << objectName () << ")::leaveEvent()";
233
tool ()->leaveEvent (e);
237
// protected virtual [base QWidget]
238
void kpView::dragEnterEvent (QDragEnterEvent *)
240
#if DEBUG_KP_VIEW && 1
241
kDebug () << "kpView(" << objectName () << ")::dragEnterEvent()";
247
// protected virtual [base QWidget]
248
void kpView::dragLeaveEvent (QDragLeaveEvent *)
250
#if DEBUG_KP_VIEW && 1
251
kDebug () << "kpView(" << objectName () << ")::dragLeaveEvent";
258
// protected virtual [base QWidget]
259
void kpView::resizeEvent (QResizeEvent *e)
261
#if DEBUG_KP_VIEW && 1
262
kDebug () << "kpView(" << objectName () << ")::resizeEvent("
264
<< " vs actual=" << size ()
265
<< ") old=" << e->oldSize () << endl;
268
QWidget::resizeEvent (e);
270
emit sizeChanged (width (), height ());
271
emit sizeChanged (size ());