Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/text/kpToolText_KeyboardEvents_HandleTypingKeys.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
56 | #if DEBUG_KP_TOOL_TEXT | 56 | #if DEBUG_KP_TOOL_TEXT | ||
57 | qCDebug(kpLogTools) << "\tbackspace pressed"; | 57 | qCDebug(kpLogTools) << "\tbackspace pressed"; | ||
58 | #endif | 58 | #endif | ||
59 | 59 | | |||
60 | if (!textLines.isEmpty ()) | 60 | if (!textLines.isEmpty ()) | ||
61 | { | 61 | { | ||
62 | if ((e->modifiers () & Qt::ControlModifier) == 0) | 62 | if ((e->modifiers () & Qt::ControlModifier) == 0) | ||
63 | { | 63 | { | ||
64 | if (!d->backspaceCommand) | 64 | if (!d->backspaceCommand) { | ||
65 | addNewBackspaceCommand (&d->backspaceCommand); | 65 | addNewBackspaceCommand (&d->backspaceCommand); | ||
66 | } | ||||
66 | 67 | | |||
67 | d->backspaceCommand->addBackspace (); | 68 | d->backspaceCommand->addBackspace (); | ||
68 | } | 69 | } | ||
69 | else | 70 | else | ||
70 | { | 71 | { | ||
71 | if (!d->backspaceWordCommand) | 72 | if (!d->backspaceWordCommand) { | ||
72 | addNewBackspaceCommand (&d->backspaceWordCommand); | 73 | addNewBackspaceCommand (&d->backspaceWordCommand); | ||
74 | } | ||||
73 | 75 | | |||
74 | const int numMoves = MoveCursorToWordStart (textLines, | 76 | const int numMoves = MoveCursorToWordStart (textLines, | ||
75 | &cursorRow, &cursorCol); | 77 | &cursorRow, &cursorCol); | ||
76 | 78 | | |||
77 | viewManager ()->setQueueUpdates (); | 79 | viewManager ()->setQueueUpdates (); | ||
78 | { | 80 | { | ||
79 | for (int i = 0; i < numMoves; i++) | 81 | for (int i = 0; i < numMoves; i++) { | ||
80 | d->backspaceWordCommand->addBackspace (); | 82 | d->backspaceWordCommand->addBackspace (); | ||
81 | } | 83 | } | ||
84 | } | ||||
82 | viewManager ()->restoreQueueUpdates (); | 85 | viewManager ()->restoreQueueUpdates (); | ||
83 | 86 | | |||
84 | Q_ASSERT (cursorRow == viewManager ()->textCursorRow ()); | 87 | Q_ASSERT (cursorRow == viewManager ()->textCursorRow ()); | ||
85 | Q_ASSERT (cursorCol == viewManager ()->textCursorCol ()); | 88 | Q_ASSERT (cursorCol == viewManager ()->textCursorCol ()); | ||
86 | } | 89 | } | ||
87 | } | 90 | } | ||
88 | 91 | | |||
89 | e->accept (); | 92 | e->accept (); | ||
90 | } | 93 | } | ||
91 | 94 | | |||
92 | //--------------------------------------------------------------------- | 95 | //--------------------------------------------------------------------- | ||
93 | 96 | | |||
94 | // protected | 97 | // protected | ||
95 | void kpToolText::handleDeleteKeyPress (QKeyEvent *e, | 98 | void kpToolText::handleDeleteKeyPress (QKeyEvent *e, | ||
96 | const QList <QString> & textLines, int cursorRow, int cursorCol) | 99 | const QList <QString> & textLines, int cursorRow, int cursorCol) | ||
97 | { | 100 | { | ||
98 | #if DEBUG_KP_TOOL_TEXT | 101 | #if DEBUG_KP_TOOL_TEXT | ||
99 | qCDebug(kpLogTools) << "\tdelete pressed"; | 102 | qCDebug(kpLogTools) << "\tdelete pressed"; | ||
100 | #endif | 103 | #endif | ||
101 | 104 | | |||
102 | if (!textLines.isEmpty ()) | 105 | if (!textLines.isEmpty ()) | ||
103 | { | 106 | { | ||
104 | if ((e->modifiers () & Qt::ControlModifier) == 0) | 107 | if ((e->modifiers () & Qt::ControlModifier) == 0) | ||
105 | { | 108 | { | ||
106 | if (!d->deleteCommand) | 109 | if (!d->deleteCommand) { | ||
107 | addNewDeleteCommand (&d->deleteCommand); | 110 | addNewDeleteCommand (&d->deleteCommand); | ||
111 | } | ||||
108 | 112 | | |||
109 | d->deleteCommand->addDelete (); | 113 | d->deleteCommand->addDelete (); | ||
110 | } | 114 | } | ||
111 | else | 115 | else | ||
112 | { | 116 | { | ||
113 | if (!d->deleteWordCommand) | 117 | if (!d->deleteWordCommand) { | ||
114 | addNewDeleteCommand (&d->deleteWordCommand); | 118 | addNewDeleteCommand (&d->deleteWordCommand); | ||
119 | } | ||||
115 | 120 | | |||
116 | // We don't want to know the cursor pos of the next word start | 121 | // We don't want to know the cursor pos of the next word start | ||
117 | // as delete should keep cursor in same pos. | 122 | // as delete should keep cursor in same pos. | ||
118 | int cursorRowThrowAway = cursorRow, | 123 | int cursorRowThrowAway = cursorRow, | ||
119 | cursorColThrowAway = cursorCol; | 124 | cursorColThrowAway = cursorCol; | ||
120 | const int numMoves = MoveCursorToNextWordStart (textLines, | 125 | const int numMoves = MoveCursorToNextWordStart (textLines, | ||
121 | &cursorRowThrowAway, &cursorColThrowAway); | 126 | &cursorRowThrowAway, &cursorColThrowAway); | ||
122 | 127 | | |||
123 | viewManager ()->setQueueUpdates (); | 128 | viewManager ()->setQueueUpdates (); | ||
124 | { | 129 | { | ||
125 | for (int i = 0; i < numMoves; i++) | 130 | for (int i = 0; i < numMoves; i++) { | ||
126 | d->deleteWordCommand->addDelete (); | 131 | d->deleteWordCommand->addDelete (); | ||
127 | } | 132 | } | ||
133 | } | ||||
128 | viewManager ()->restoreQueueUpdates (); | 134 | viewManager ()->restoreQueueUpdates (); | ||
129 | 135 | | |||
130 | // Assert unchanged as delete should keep cursor in same pos. | 136 | // Assert unchanged as delete should keep cursor in same pos. | ||
131 | Q_ASSERT (cursorRow == viewManager ()->textCursorRow ()); | 137 | Q_ASSERT (cursorRow == viewManager ()->textCursorRow ()); | ||
132 | Q_ASSERT (cursorCol == viewManager ()->textCursorCol ()); | 138 | Q_ASSERT (cursorCol == viewManager ()->textCursorCol ()); | ||
133 | } | 139 | } | ||
134 | } | 140 | } | ||
135 | 141 | | |||
136 | e->accept (); | 142 | e->accept (); | ||
137 | } | 143 | } | ||
138 | 144 | | |||
139 | //--------------------------------------------------------------------- | 145 | //--------------------------------------------------------------------- | ||
140 | 146 | | |||
141 | // protected | 147 | // protected | ||
142 | void kpToolText::handleEnterKeyPress (QKeyEvent *e, | 148 | void kpToolText::handleEnterKeyPress (QKeyEvent *e, | ||
143 | const QList <QString> & /*textLines*/, int /*cursorRow*/, int /*cursorCol*/) | 149 | const QList <QString> & /*textLines*/, int /*cursorRow*/, int /*cursorCol*/) | ||
144 | { | 150 | { | ||
145 | #if DEBUG_KP_TOOL_TEXT | 151 | #if DEBUG_KP_TOOL_TEXT | ||
146 | qCDebug(kpLogTools) << "\tenter pressed"; | 152 | qCDebug(kpLogTools) << "\tenter pressed"; | ||
147 | #endif | 153 | #endif | ||
148 | 154 | | |||
149 | // It's OK for <textLines> to be empty. | 155 | // It's OK for <textLines> to be empty. | ||
150 | 156 | | |||
151 | if (!d->enterCommand) | 157 | if (!d->enterCommand) { | ||
152 | addNewEnterCommand (&d->enterCommand); | 158 | addNewEnterCommand (&d->enterCommand); | ||
159 | } | ||||
153 | 160 | | |||
154 | d->enterCommand->addEnter (); | 161 | d->enterCommand->addEnter (); | ||
155 | 162 | | |||
156 | e->accept (); | 163 | e->accept (); | ||
157 | } | 164 | } | ||
158 | 165 | | |||
159 | //--------------------------------------------------------------------- | 166 | //--------------------------------------------------------------------- | ||
160 | 167 | | |||
161 | // protected | 168 | // protected | ||
162 | void kpToolText::handleTextTyped (QKeyEvent *e, | 169 | void kpToolText::handleTextTyped (QKeyEvent *e, | ||
163 | const QList <QString> & /*textLines*/, int /*cursorRow*/, int /*cursorCol*/) | 170 | const QList <QString> & /*textLines*/, int /*cursorRow*/, int /*cursorCol*/) | ||
164 | { | 171 | { | ||
165 | #if DEBUG_KP_TOOL_TEXT | 172 | #if DEBUG_KP_TOOL_TEXT | ||
166 | qCDebug(kpLogTools) << "\ttext=" << e->text(); | 173 | qCDebug(kpLogTools) << "\ttext=" << e->text(); | ||
167 | #endif | 174 | #endif | ||
168 | QString usableText; | 175 | QString usableText; | ||
169 | for (int i = 0; i < e->text ().length (); i++) | 176 | for (int i = 0; i < e->text ().length (); i++) | ||
170 | { | 177 | { | ||
171 | if (e->text ().at (i).isPrint ()) | 178 | if (e->text ().at (i).isPrint ()) { | ||
172 | usableText += e->text ().at (i); | 179 | usableText += e->text ().at (i); | ||
173 | } | 180 | } | ||
181 | } | ||||
174 | #if DEBUG_KP_TOOL_TEXT | 182 | #if DEBUG_KP_TOOL_TEXT | ||
175 | qCDebug(kpLogTools) << "\tusableText=" << usableText; | 183 | qCDebug(kpLogTools) << "\tusableText=" << usableText; | ||
176 | #endif | 184 | #endif | ||
177 | 185 | | |||
178 | if (usableText.isEmpty ()) | 186 | if (usableText.isEmpty ()) | ||
179 | { | 187 | { | ||
180 | // Don't end the current shape nor accept the event -- the event | 188 | // Don't end the current shape nor accept the event -- the event | ||
181 | // wasn't for us. | 189 | // wasn't for us. | ||
182 | return; | 190 | return; | ||
183 | } | 191 | } | ||
184 | 192 | | |||
185 | // --- It's OK for <textLines> to be empty. --- | 193 | // --- It's OK for <textLines> to be empty. --- | ||
186 | 194 | | |||
187 | if (!d->insertCommand) | 195 | if (!d->insertCommand) { | ||
188 | addNewInsertCommand (&d->insertCommand); | 196 | addNewInsertCommand (&d->insertCommand); | ||
197 | } | ||||
189 | 198 | | |||
190 | d->insertCommand->addText (usableText); | 199 | d->insertCommand->addText (usableText); | ||
191 | 200 | | |||
192 | e->accept (); | 201 | e->accept (); | ||
193 | } | 202 | } |