compile
[kdegraphics.git] / kolourpaint / tools / selection / text / kpToolText_Commands.cpp
blobd87ab573268f4dc1563e9e3e746e1876b0e3ee26
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #define DEBUG_KP_TOOL_TEXT 0
31 #include <kpToolText.h>
32 #include <kpToolTextPrivate.h>
34 #include <kdebug.h>
35 #include <klocale.h>
37 #include <kpToolSelectionEnvironment.h>
38 #include <kpToolTextBackspaceCommand.h>
39 #include <kpToolTextDeleteCommand.h>
40 #include <kpToolTextEnterCommand.h>
41 #include <kpToolTextInsertCommand.h>
42 #include <kpViewManager.h>
45 // private
46 void kpToolText::endTypingCommands ()
48 d->insertCommand = 0;
49 d->enterCommand = 0;
51 d->backspaceCommand = 0;
52 d->backspaceWordCommand = 0;
54 d->deleteCommand = 0;
55 d->deleteWordCommand = 0;
59 // private
60 void kpToolText::addNewBackspaceCommand (kpToolTextBackspaceCommand **cmd)
62 // TODO: why not endShapeInternal(); ditto for everywhere else in kpToolText*.cpp?
63 if (hasBegunShape ())
65 endShape (currentPoint (), normalizedRect ());
68 giveContentIfNeeded ();
70 *cmd = new kpToolTextBackspaceCommand (i18n ("Text: Backspace"),
71 viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
72 kpToolTextBackspaceCommand::DontAddBackspaceYet,
73 environ ()->commandEnvironment ());
74 addNeedingContentCommand (*cmd);
77 // private
78 void kpToolText::addNewDeleteCommand (kpToolTextDeleteCommand **cmd)
80 if (hasBegunShape ())
82 endShape (currentPoint (), normalizedRect ());
85 giveContentIfNeeded ();
87 *cmd = new kpToolTextDeleteCommand (i18n ("Text: Delete"),
88 viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
89 kpToolTextDeleteCommand::DontAddDeleteYet,
90 environ ()->commandEnvironment ());
91 addNeedingContentCommand (*cmd);
94 // private
95 void kpToolText::addNewEnterCommand (kpToolTextEnterCommand **cmd)
97 if (hasBegunShape ())
99 endShape (currentPoint (), normalizedRect ());
102 giveContentIfNeeded ();
104 *cmd = new kpToolTextEnterCommand (i18n ("Text: New Line"),
105 viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
106 kpToolTextEnterCommand::DontAddEnterYet,
107 environ ()->commandEnvironment ());
108 addNeedingContentCommand (*cmd);
111 // private
112 void kpToolText::addNewInsertCommand (kpToolTextInsertCommand **cmd)
114 if (hasBegunShape ())
116 endShape (currentPoint (), normalizedRect ());
119 giveContentIfNeeded ();
121 *cmd = new kpToolTextInsertCommand (i18n ("Text: Write"),
122 viewManager ()->textCursorRow (), viewManager ()->textCursorCol (),
123 QString (),
124 environ ()->commandEnvironment ());
125 addNeedingContentCommand (*cmd);