File indexing completed on 2024-04-28 04:20:27

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 //
0029 // Tool reaction to all remaining events.
0030 //
0031 // 1. View events
0032 // 2. Non-view events
0033 //
0034 
0035 
0036 #define DEBUG_KP_TOOL 0
0037 
0038 
0039 #include "tools/kpTool.h"
0040 #include "kpToolPrivate.h"
0041 
0042 #include "kpLogCategories.h"
0043 
0044 #include "imagelib/kpColor.h"
0045 
0046 //---------------------------------------------------------------------
0047 
0048 //
0049 // 1. View Events
0050 //
0051 
0052 bool kpTool::viewEvent (QEvent *e)
0053 {
0054 #if DEBUG_KP_TOOL
0055     qCDebug(kpLogTools) << "kpTool<" << objectName ()
0056               << "," << this << ">::viewEvent(type=" << e->type ()
0057               << ") returning false" << endl;
0058 #else
0059     (void) e;
0060 #endif
0061 
0062     // Don't handle.
0063     return false;
0064 }
0065 
0066 //---------------------------------------------------------------------
0067 
0068 void kpTool::focusInEvent (QFocusEvent *)
0069 {
0070 }
0071 
0072 //---------------------------------------------------------------------
0073 
0074 void kpTool::focusOutEvent (QFocusEvent *)
0075 {
0076 #if DEBUG_KP_TOOL && 0
0077     qCDebug(kpLogTools) << "kpTool::focusOutEvent() beganDraw=" << d->beganDraw;
0078 #endif
0079 
0080     if (d->beganDraw) {
0081         endDrawInternal (d->currentPoint, normalizedRect ());
0082     }
0083 }
0084 
0085 //---------------------------------------------------------------------
0086 
0087 void kpTool::enterEvent (QEvent *)
0088 {
0089 #if DEBUG_KP_TOOL && 1
0090     qCDebug(kpLogTools) << "kpTool::enterEvent() beganDraw=" << d->beganDraw;
0091 #endif
0092 }
0093 
0094 //---------------------------------------------------------------------
0095 
0096 void kpTool::leaveEvent (QEvent *)
0097 {
0098 #if DEBUG_KP_TOOL && 1
0099     qCDebug(kpLogTools) << "kpTool::leaveEvent() beganDraw=" << d->beganDraw;
0100 #endif
0101 
0102     // if we haven't started drawing (e.g. dragging a rectangle)...
0103     if (!d->beganDraw)
0104     {
0105         d->currentPoint = KP_INVALID_POINT;
0106         d->currentViewPoint = KP_INVALID_POINT;
0107         hover (d->currentPoint);
0108     }
0109 }
0110 
0111 //---------------------------------------------------------------------
0112 //
0113 // 2. Non-view events
0114 //
0115 
0116 void kpTool::slotColorsSwappedInternal (const kpColor &newForegroundColor,
0117                                         const kpColor &newBackgroundColor)
0118 {
0119     if (careAboutColorsSwapped ())
0120     {
0121         slotColorsSwapped (newForegroundColor, newBackgroundColor);
0122         d->ignoreColorSignals = 2;
0123     }
0124     else {
0125         d->ignoreColorSignals = 0;
0126     }
0127 }
0128 
0129 //---------------------------------------------------------------------
0130 
0131 void kpTool::slotForegroundColorChangedInternal (const kpColor &color)
0132 {
0133     if (d->ignoreColorSignals > 0)
0134     {
0135     #if DEBUG_KP_TOOL && 1
0136         qCDebug(kpLogTools) << "kpTool::slotForegroundColorChangedInternal() ignoreColorSignals=" << d->ignoreColorSignals;
0137     #endif
0138         d->ignoreColorSignals--;
0139         return;
0140     }
0141 
0142     slotForegroundColorChanged (color);
0143 }
0144 
0145 //---------------------------------------------------------------------
0146 
0147 void kpTool::slotBackgroundColorChangedInternal (const kpColor &color)
0148 {
0149     if (d->ignoreColorSignals > 0)
0150     {
0151     #if DEBUG_KP_TOOL && 1
0152         qCDebug(kpLogTools) << "kpTool::slotBackgroundColorChangedInternal() ignoreColorSignals=" << d->ignoreColorSignals;
0153     #endif
0154         d->ignoreColorSignals--;
0155         return;
0156     }
0157 
0158     slotBackgroundColorChanged (color);
0159 }
0160 
0161 //---------------------------------------------------------------------
0162 
0163 void kpTool::slotColorSimilarityChangedInternal (double similarity, int processedSimilarity)
0164 {
0165     slotColorSimilarityChanged (similarity, processedSimilarity);
0166 }
0167 
0168 //---------------------------------------------------------------------