File indexing completed on 2024-05-05 04:21:20

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    Copyright (c) 2005 Kazuki Ohta <mover@hct.zaq.ne.jp>
0005    Copyright (c) 2010 Tasuku Suzuki <stasuku@gmail.com>
0006    All rights reserved.
0007 
0008    Redistribution and use in source and binary forms, with or without
0009    modification, are permitted provided that the following conditions
0010    are met:
0011 
0012    1. Redistributions of source code must retain the above copyright
0013       notice, this list of conditions and the following disclaimer.
0014    2. Redistributions in binary form must reproduce the above copyright
0015       notice, this list of conditions and the following disclaimer in the
0016       documentation and/or other materials provided with the distribution.
0017 
0018    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0019    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0020    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0021    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0022    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0023    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0024    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0025    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0026    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0027    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0028 */
0029 
0030 
0031 #define DEBUG_KP_VIEW 0
0032 #define DEBUG_KP_VIEW_RENDERER ((DEBUG_KP_VIEW && 1) || 0)
0033 
0034 
0035 #include "views/kpView.h"
0036 #include "kpViewPrivate.h"
0037 
0038 #if DEBUG_KP_VIEW
0039 #include "kpLogCategories.h"
0040 #endif
0041 
0042 #include <QKeyEvent>
0043 #include <QMouseEvent>
0044 
0045 #include "tools/kpTool.h"
0046 
0047 //---------------------------------------------------------------------
0048 
0049 // protected virtual [base QWidget]
0050 void kpView::mouseMoveEvent (QMouseEvent *e)
0051 {
0052 #if DEBUG_KP_VIEW && 0
0053     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::mouseMoveEvent ("
0054                << e->x () << "," << e->y () << ")"
0055                << endl;
0056 #endif
0057 
0058     // TODO: This is wrong if you leaveEvent the mainView by mouseMoving on the
0059     //       mainView, landing on top of the thumbnailView cleverly put on top
0060     //       of the mainView.
0061     setHasMouse (rect ().contains (e->pos ()));
0062 
0063     if (tool ()) {
0064         tool ()->mouseMoveEvent (e);
0065     }
0066 
0067     e->accept ();
0068 }
0069 
0070 // protected virtual [base QWidget]
0071 void kpView::mousePressEvent (QMouseEvent *e)
0072 {
0073 #if DEBUG_KP_VIEW && 0
0074     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::mousePressEvent ("
0075                << e->x () << "," << e->y () << ")"
0076                << endl;
0077 #endif
0078 
0079     setHasMouse (true);
0080 
0081     if (tool ()) {
0082         tool ()->mousePressEvent (e);
0083     }
0084 
0085     e->accept ();
0086 }
0087 
0088 //---------------------------------------------------------------------
0089 
0090 // protected virtual [base QWidget]
0091 void kpView::mouseReleaseEvent (QMouseEvent *e)
0092 {
0093 #if DEBUG_KP_VIEW && 0
0094     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::mouseReleaseEvent ("
0095                << e->x () << "," << e->y () << ")"
0096                << endl;
0097 #endif
0098 
0099     setHasMouse (rect ().contains (e->pos ()));
0100 
0101     if (tool ()) {
0102         tool ()->mouseReleaseEvent (e);
0103     }
0104 
0105     e->accept ();
0106 }
0107 
0108 //---------------------------------------------------------------------
0109 
0110 // public virtual [base QWidget]
0111 void kpView::wheelEvent (QWheelEvent *e)
0112 {
0113     if (tool ()) {
0114         tool ()->wheelEvent (e);
0115     }
0116 }
0117 
0118 //---------------------------------------------------------------------
0119 
0120 // protected virtual [base QWidget]
0121 void kpView::keyPressEvent (QKeyEvent *e)
0122 {
0123 #if DEBUG_KP_VIEW
0124     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::keyPressEvent()" << e->text();
0125 #endif
0126 
0127     if (tool ()) {
0128         tool ()->keyPressEvent (e);
0129     }
0130 
0131     e->accept ();
0132 }
0133 
0134 //---------------------------------------------------------------------
0135 
0136 // protected virtual [base QWidget]
0137 void kpView::keyReleaseEvent (QKeyEvent *e)
0138 {
0139 #if DEBUG_KP_VIEW && 0
0140     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::keyReleaseEvent()";
0141 #endif
0142 
0143     if (tool ()) {
0144         tool ()->keyReleaseEvent (e);
0145     }
0146 
0147     e->accept ();
0148 }
0149 
0150 //---------------------------------------------------------------------
0151 
0152 // protected virtual [base QWidget]
0153 void kpView::inputMethodEvent (QInputMethodEvent *e)
0154 {
0155 #if DEBUG_KP_VIEW && 1
0156     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::inputMethodEvent()";
0157 #endif
0158 
0159     if (tool ()) {
0160         tool ()->inputMethodEvent (e);
0161     }
0162     e->accept ();
0163 }
0164 
0165 // protected virtual [base QWidget]
0166 bool kpView::event (QEvent *e)
0167 {
0168 #if DEBUG_KP_VIEW
0169     qCDebug(kpLogViews) << "kpView::event() invoking kpTool::event()";
0170 #endif
0171     if (tool () && tool ()->viewEvent (e))
0172     {
0173     #if DEBUG_KP_VIEW
0174         qCDebug(kpLogViews) << "\tkpView::event() - tool said eat event, ret true";
0175     #endif
0176         return true;
0177     }
0178 
0179 #if DEBUG_KP_VIEW
0180     qCDebug(kpLogViews) << "\tkpView::event() - no tool or said false, call QWidget::event()";
0181 #endif
0182     return QWidget::event (e);
0183 }
0184 
0185 
0186 // protected virtual [base QWidget]
0187 void kpView::focusInEvent (QFocusEvent *e)
0188 {
0189 #if DEBUG_KP_VIEW && 0
0190     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::focusInEvent()";
0191 #endif
0192     if (tool ()) {
0193         tool ()->focusInEvent (e);
0194     }
0195 }
0196 
0197 // protected virtual [base QWidget]
0198 void kpView::focusOutEvent (QFocusEvent *e)
0199 {
0200 #if DEBUG_KP_VIEW && 0
0201     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::focusOutEvent()";
0202 #endif
0203     if (tool ()) {
0204         tool ()->focusOutEvent (e);
0205     }
0206 }
0207 
0208 
0209 // protected virtual [base QWidget]
0210 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0211 void kpView::enterEvent (QEnterEvent *e)
0212 #else
0213 void kpView::enterEvent (QEvent *e)
0214 #endif
0215 {
0216 #if DEBUG_KP_VIEW && 0
0217     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::enterEvent()";
0218 #endif
0219 
0220     // Don't call setHasMouse(true) as it displays the brush cursor (if
0221     // active) when dragging open a menu and then dragging
0222     // past the extents of the menu due to Qt sending us an EnterEvent.
0223     // We're already covered by MouseMoveEvent anyway.
0224     //
0225     // But disabling this causes a more serious problem: RMB on a text
0226     // box and Esc.  We have no other reliable way to determine if the
0227     // mouse is still above the view (user could have moved mouse out
0228     // while RMB menu was up) and hence the cursor is not updated.
0229     setHasMouse (true);
0230 
0231     if (tool ()) {
0232         tool ()->enterEvent (e);
0233     }
0234 }
0235 
0236 // protected virtual [base QWidget]
0237 void kpView::leaveEvent (QEvent *e)
0238 {
0239 #if DEBUG_KP_VIEW && 0
0240     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::leaveEvent()";
0241 #endif
0242 
0243     setHasMouse (false);
0244     if (tool ()) {
0245         tool ()->leaveEvent (e);
0246     }
0247 }
0248 
0249 
0250 // protected virtual [base QWidget]
0251 void kpView::dragEnterEvent (QDragEnterEvent *)
0252 {
0253 #if DEBUG_KP_VIEW && 1
0254     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::dragEnterEvent()";
0255 #endif
0256 
0257     setHasMouse (true);
0258 }
0259 
0260 // protected virtual [base QWidget]
0261 void kpView::dragLeaveEvent (QDragLeaveEvent *)
0262 {
0263 #if DEBUG_KP_VIEW && 1
0264     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::dragLeaveEvent";
0265 #endif
0266 
0267     setHasMouse (false);
0268 }
0269 
0270 
0271 // protected virtual [base QWidget]
0272 void kpView::resizeEvent (QResizeEvent *e)
0273 {
0274 #if DEBUG_KP_VIEW && 1
0275     qCDebug(kpLogViews) << "kpView(" << objectName () << ")::resizeEvent("
0276                << e->size ()
0277                << " vs actual=" << size ()
0278                << ") old=" << e->oldSize () << endl;
0279 #endif
0280 
0281     QWidget::resizeEvent (e);
0282 
0283     Q_EMIT sizeChanged (width (), height ());
0284     Q_EMIT sizeChanged (size ());
0285 }