File indexing completed on 2024-05-26 04:24:57

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 "kpToolText.h"
0032 #include "kpToolTextPrivate.h"
0033 #include "kpLogCategories.h"
0034 
0035 #include "environments/tools/selection/kpToolSelectionEnvironment.h"
0036 #include "commands/tools/selection/text/kpToolTextBackspaceCommand.h"
0037 #include "commands/tools/selection/text/kpToolTextDeleteCommand.h"
0038 #include "commands/tools/selection/text/kpToolTextEnterCommand.h"
0039 #include "commands/tools/selection/text/kpToolTextInsertCommand.h"
0040 #include "views/manager/kpViewManager.h"
0041 
0042 #include <KLocalizedString>
0043 
0044 // private
0045 void kpToolText::endTypingCommands ()
0046 {
0047     d->insertCommand = nullptr;
0048     d->enterCommand = nullptr;
0049 
0050     d->backspaceCommand = nullptr;
0051     d->backspaceWordCommand = nullptr;
0052 
0053     d->deleteCommand = nullptr;
0054     d->deleteWordCommand = nullptr;
0055 }
0056 
0057 
0058 // private
0059 void kpToolText::addNewBackspaceCommand (kpToolTextBackspaceCommand **cmd)
0060 {
0061     // TODO: why not endShapeInternal(); ditto for everywhere else in kpToolText*.cpp?
0062     if (hasBegunShape ())
0063     {
0064         endShape (currentPoint (), normalizedRect ());
0065     }
0066 
0067     giveContentIfNeeded ();
0068 
0069     *cmd = new kpToolTextBackspaceCommand (i18n ("Text: Backspace"),
0070         viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
0071         kpToolTextBackspaceCommand::DontAddBackspaceYet,
0072         environ ()->commandEnvironment ());
0073     addNeedingContentCommand (*cmd);
0074 }
0075 
0076 // private
0077 void kpToolText::addNewDeleteCommand (kpToolTextDeleteCommand **cmd)
0078 {
0079     if (hasBegunShape ())
0080     {
0081         endShape (currentPoint (), normalizedRect ());
0082     }
0083 
0084     giveContentIfNeeded ();
0085 
0086     *cmd = new kpToolTextDeleteCommand (i18n ("Text: Delete"),
0087         viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
0088         kpToolTextDeleteCommand::DontAddDeleteYet,
0089         environ ()->commandEnvironment ());
0090     addNeedingContentCommand (*cmd);
0091 }
0092 
0093 // private
0094 void kpToolText::addNewEnterCommand (kpToolTextEnterCommand **cmd)
0095 {
0096     if (hasBegunShape ())
0097     {
0098         endShape (currentPoint (), normalizedRect ());
0099     }
0100 
0101     giveContentIfNeeded ();
0102 
0103     *cmd = new kpToolTextEnterCommand (i18n ("Text: New Line"),
0104         viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
0105         kpToolTextEnterCommand::DontAddEnterYet,
0106         environ ()->commandEnvironment ());
0107     addNeedingContentCommand (*cmd);
0108 }
0109 
0110 // private
0111 void kpToolText::addNewInsertCommand (kpToolTextInsertCommand **cmd)
0112 {
0113     if (hasBegunShape ())
0114     {
0115         endShape (currentPoint (), normalizedRect ());
0116     }
0117 
0118     giveContentIfNeeded ();
0119 
0120     *cmd = new kpToolTextInsertCommand (i18n ("Text: Write"),
0121         viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
0122         QString (),
0123         environ ()->commandEnvironment ());
0124     addNeedingContentCommand (*cmd);
0125 }