File indexing completed on 2024-12-15 04:03:26
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 #define DEBUG_KP_TOOL_TEXT 0 0029 0030 0031 #include "tools/selection/text/kpToolText.h" 0032 #include "kpToolTextPrivate.h" 0033 0034 #include "kpLogCategories.h" 0035 0036 #include "document/kpDocument.h" 0037 #include "layers/selections/text/kpTextSelection.h" 0038 #include "views/kpView.h" 0039 #include "views/manager/kpViewManager.h" 0040 0041 0042 // private 0043 bool kpToolText::onSelectionToSelectText () const 0044 { 0045 kpView *v = viewManager ()->viewUnderCursor (); 0046 if (!v) { 0047 return false; 0048 } 0049 0050 return v->mouseOnSelectionToSelectText (currentViewPoint ()); 0051 } 0052 0053 0054 // private 0055 QString kpToolText::haventBegunDrawUserMessageSelectText () const 0056 { 0057 return i18n ("Left click to change cursor position."); 0058 } 0059 0060 // private 0061 void kpToolText::setCursorSelectText () 0062 { 0063 viewManager ()->setCursor (Qt::IBeamCursor); 0064 } 0065 0066 0067 // private 0068 void kpToolText::beginDrawSelectText () 0069 { 0070 #if DEBUG_KP_TOOL_TEXT 0071 qCDebug(kpLogTools) << "\t\tis select cursor pos"; 0072 #endif 0073 kpTextSelection *textSel = document ()->textSelection (); 0074 Q_ASSERT (textSel); 0075 0076 int newRow, newCol; 0077 0078 if (textSel->hasContent ()) 0079 { 0080 newRow = textSel->closestTextRowForPoint (currentPoint ()); 0081 newCol = textSel->closestTextColForPoint (currentPoint ()); 0082 } 0083 else 0084 { 0085 newRow = newCol = 0; 0086 } 0087 0088 #if DEBUG_KP_TOOL_TEXT 0089 qCDebug(kpLogTools) << "\t\t\told: row=" << viewManager ()->textCursorRow () 0090 << "col=" << viewManager ()->textCursorCol (); 0091 qCDebug(kpLogTools) << "\t\t\tnew: row=" << newRow << "col=" << newCol; 0092 #endif 0093 viewManager ()->setTextCursorPosition (newRow, newCol); 0094 } 0095 0096 0097 // protected virtual 0098 QVariant kpToolText::selectTextOperation (Operation op, 0099 const QVariant &data1, const QVariant &data2) 0100 { 0101 (void) data1; 0102 (void) data2; 0103 0104 0105 switch (op) 0106 { 0107 case HaventBegunDrawUserMessage: 0108 return haventBegunDrawUserMessageSelectText (); 0109 0110 case SetCursor: 0111 setCursorSelectText (); 0112 break; 0113 0114 case BeginDraw: 0115 beginDrawSelectText (); 0116 break; 0117 0118 case Draw: 0119 // Do nothing. 0120 break; 0121 0122 case Cancel: 0123 // Not called. REFACTOR: Change this? 0124 break; 0125 0126 case EndDraw: 0127 // Do nothing. 0128 break; 0129 0130 default: 0131 Q_ASSERT (!"Unhandled operation"); 0132 break; 0133 } 0134 0135 0136 return {}; 0137 }