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 
0029 #ifndef KP_TOOL_TEXT_H
0030 #define KP_TOOL_TEXT_H
0031 
0032 
0033 #include "tools/selection/kpAbstractSelectionTool.h"
0034 
0035 
0036 class QKeyEvent;
0037 
0038 class kpColor;
0039 class kpTextStyle;
0040 
0041 class kpToolTextInsertCommand;
0042 class kpToolTextEnterCommand;
0043 class kpToolTextBackspaceCommand;
0044 class kpToolTextDeleteCommand;
0045 
0046 
0047 //
0048 // kpAbstractSelectionTool considers a drawing operation to be a mouse
0049 // drag that creates, moves or resize/scales a selection.
0050 //
0051 // kpToolText also considers any such drawing operation and alternatively,
0052 // any active text command (e.g. inserting text), to be the "current
0053 // shape".  kpTool's shape methods (e.g. hasBegunShape() and endShape())
0054 // have been overloaded to ensure that they operate on whatever operation
0055 // (drawing or text) is active.
0056 //
0057 // It is not possible to have a drawing command and text command active
0058 // simultaneously.  However, it is possible to have neither active.
0059 //
0060 // Text commands do not end until a different kind of key is pressed or
0061 // a drawing command commences.  For instance, if you were to
0062 // type a character of text, a kpToolTextInsertCommand would be added to
0063 // the command history but stays active so that future typed characters
0064 // would simply be added to this command.  As soon as the user presses
0065 // a different kind of key (e.g. arrow key, backspace) or drags the mouse,
0066 // the command is no longer kept active.
0067 //
0068 //
0069 // kpToolText implements a new drawing type, "SelectText", for moving the
0070 // text cursor to the clicked location.
0071 //
0072 //
0073 // As an exception to the standard kpAbstractSelectionTool behavior,
0074 // a single click -- with no dragging -- can be used to create a new text
0075 // box.
0076 //
0077 class kpToolText : public kpAbstractSelectionTool
0078 {
0079 Q_OBJECT
0080 
0081 public:
0082     kpToolText (kpToolSelectionEnvironment *environ, QObject *parent);
0083     ~kpToolText () override;
0084 
0085 
0086 //
0087 // Text Command Handling
0088 //
0089 
0090 private:
0091     /**
0092      * Indicates that no current text editing command is active.
0093      * You must call this, via endShape(), when ending the current command
0094      * (e.g. changing from backspacing to inserting text
0095      *  e.g.2. changing from moving/resizing to inserting text).
0096      *
0097      * It achieves this by zero'ing out all the d->.+Command pointers.
0098      * It does not delete the pointers as they should be owned by the
0099      * commandHistory().
0100      *
0101      * If you call this excessively, you will break up commands into many
0102      * smaller commands e.g. a text insertion command with 10 characters
0103      * might be split into 10 text insertion commands, each containing 1
0104      * character.
0105      */
0106     void endTypingCommands ();
0107 
0108 
0109     /**
0110      * Ends the current text editing command by eventually calling
0111      * endTypingCommands(), returns a new
0112      * kpToolTextBackspaceCommand and adds it to the commandHistory().
0113      *
0114      * @param cmd A Pointer to one of the d->backspace.*Command pointers.
0115      *            On function return, the pointed-to d->backspace.*Command
0116      *            pointer will point to a new kpToolTextBackspaceCommand.
0117      */
0118     void addNewBackspaceCommand (kpToolTextBackspaceCommand **cmd);
0119 
0120     /**
0121      * Ends the current text editing command by eventually calling
0122      * endTypingCommands(), returns a new
0123      * kpToolTextDeleteCommand and adds it to the commandHistory().
0124      *
0125      * @param cmd A Pointer to one of the d->delete.*Command pointers. On
0126      *            function return, the pointed-to d->delete.*Command pointer
0127      *            will point to a new kpToolTextDeleteCommand.
0128      */
0129     void addNewDeleteCommand (kpToolTextDeleteCommand **cmd);
0130 
0131     void addNewEnterCommand (kpToolTextEnterCommand **cmd);
0132 
0133     void addNewInsertCommand (kpToolTextInsertCommand **cmd);
0134 
0135 
0136 //
0137 // Drawing
0138 //
0139 
0140 protected:
0141     kpAbstractSelectionContentCommand *newGiveContentCommand () const override;
0142 
0143     QString nameOfCreateCommand () const override;
0144 
0145 
0146 protected:
0147     void setSelectionBorderForHaventBegunDraw () override;
0148 
0149 
0150 public:
0151     void begin () override;
0152     void end () override;
0153 
0154 
0155 public:
0156     bool hasBegunText () const;
0157     bool hasBegunShape () const override;
0158 
0159 
0160 //
0161 // Drawing - Beginning a Drag
0162 //
0163 
0164 protected:
0165     DrawType calculateDrawTypeInsideSelection () const override;
0166 
0167 
0168 public:
0169     void cancelShape () override;
0170 
0171 
0172 public:
0173     void endShape (const QPoint &thisPoint, const QRect &normalizedRect) override;
0174 
0175 
0176 //
0177 // Drawing - Operation Dispatching
0178 //
0179 
0180 protected:
0181     QVariant operation (DrawType drawType, Operation op,
0182         const QVariant &data1 = QVariant (), const QVariant &data2 = QVariant ()) override;
0183 
0184 
0185 //
0186 // Create
0187 //
0188 
0189 protected:
0190     QString haventBegunDrawUserMessageCreate () const override;
0191 
0192 
0193 protected:
0194     void setSelectionBorderForBeginDrawCreate () override;
0195 
0196 
0197 private:
0198     // Returns the suggested width/height of a click-created text box:
0199     //
0200     // <mouseStart> = starting X/Y of the entire drag
0201     // <mouseEnd> = current ending X/Y of the entire drag
0202     //
0203     // <preferredMin> = the preferred minimum width/height of the selection
0204     // <smallestMin> = the legal minimum width/height of the selection
0205     //
0206     // <docSize> = the width/height of the document
0207     int calcClickCreateDimension (int mouseStart, int mouseEnd,
0208         int preferredMin, int smallestMin,
0209         int docSize);
0210     bool shouldCreate (
0211         bool drawAcceptedAsDrag,
0212         const QPoint &accidentalDragAdjustedPoint,
0213         const kpTextStyle &textStyle,
0214         int *minimumWidthOut, int *minimumHeightOut,
0215         bool *newDragHasBegun);
0216 protected:
0217     bool drawCreateMoreSelectionAndUpdateStatusBar (
0218         bool drawAcceptedAsDrag,
0219         const QPoint &accidentalDragAdjustedPoint,
0220         const QRect &normalizedRectIn) override;
0221 
0222 
0223 //
0224 // Move
0225 //
0226 
0227 protected:
0228     QString haventBegunDrawUserMessageMove () const override;
0229 
0230 
0231 protected:
0232     void setSelectionBorderForBeginDrawMove () override;
0233 
0234 
0235 protected:
0236     QString nonSmearMoveCommandName () const override;
0237 
0238 
0239 //
0240 // Resize/Scale
0241 //
0242 
0243 protected:
0244     QString haventBegunDrawUserMessageResizeScale () const override;
0245 
0246 
0247 protected:
0248     void setSelectionBorderForBeginDrawResizeScale () override;
0249 
0250 
0251 //
0252 // Select Text
0253 //
0254 
0255 private:
0256     bool onSelectionToSelectText () const;
0257 
0258 
0259 private:
0260     QString haventBegunDrawUserMessageSelectText () const;
0261 
0262     void setCursorSelectText ();
0263 
0264 
0265 private:
0266     void beginDrawSelectText ();
0267 
0268 
0269 protected:
0270     virtual QVariant selectTextOperation (Operation op,
0271         const QVariant &data1 = QVariant (), const QVariant &data2 = QVariant ());
0272 
0273 
0274 //
0275 // User Changing Text Style Elements
0276 //
0277 
0278 protected:
0279     bool shouldChangeTextStyle () const;
0280 
0281     /**
0282      * Adds a kpToolTextChangeStyleCommand to commandHistory().
0283      *
0284      * Call this when an element of the text style changes (e.g. user
0285      * changes font size, boldness, color etc.).
0286      *
0287      * @param name Name of the command in the command history.
0288      * @param newTextStyle The new and current text style.
0289      * @param oldTextStyle The old and previous text style.
0290      *
0291      * You should only call this if shouldChangeTextStyle() returns true.
0292      */
0293     void changeTextStyle (const QString &name,
0294                           const kpTextStyle &newTextStyle,
0295                           const kpTextStyle &oldTextStyle);
0296 
0297 protected Q_SLOTS:
0298     void slotIsOpaqueChanged (bool isOpaque) override;
0299 
0300 
0301 protected:
0302     /**
0303      * Asks kpTool to call slotColorsSwapped() when the foreground and
0304      * background color are swapped.
0305      *
0306      * Re-implemented from kpTool.
0307      */
0308     bool careAboutColorsSwapped () const override { return true; }
0309 
0310 protected Q_SLOTS:
0311     void slotColorsSwapped (const kpColor &newForegroundColor,
0312                                     const kpColor &newBackgroundColor) override;
0313 
0314     void slotForegroundColorChanged (const kpColor &color) override;
0315     void slotBackgroundColorChanged (const kpColor &color) override;
0316     void slotColorSimilarityChanged (double, int) override;
0317 
0318 public Q_SLOTS:
0319     void slotFontFamilyChanged (const QString &fontFamily, const QString &oldFontFamily);
0320     void slotFontSizeChanged (int fontSize, int oldFontSize);
0321     void slotBoldChanged (bool isBold);
0322     void slotItalicChanged (bool isItalic);
0323     void slotUnderlineChanged (bool isUnderline);
0324     void slotStrikeThruChanged (bool isStrikeThru);
0325 
0326 
0327 //
0328 // Text Cursor Calculations (all static, no mutations)
0329 //
0330 
0331 protected:
0332     /**
0333      * @param textLines One or more lines of text.
0334      * @param cursorRow Current row of the cursor.
0335      * @param cursorCol Current column of the cursor.
0336      *
0337      * @returns whether the cursor is currently on a word character
0338      *          (not a space).
0339      */
0340     static bool CursorIsOnWordChar (const QList <QString> &textLines,
0341         int cursorRow, int cursorCol);
0342 
0343 
0344     /**
0345      * @param textLines One or more lines of text.
0346      * @param cursorRow Current row of the cursor.
0347      * @param cursorCol Current column of the cursor.
0348      *
0349      * @returns whether the given cursor position is at the start of
0350      *          textLines (on the first character of the first line)
0351      *          i.e. when moveCursorLeft() won't do anything.
0352      */
0353     static bool CursorIsAtStart (const QList <QString> &textLines,
0354         int cursorRow, int cursorCol);
0355 
0356     /**
0357      * @param textLines One or more lines of text.
0358      * @param cursorRow Current row of the cursor.
0359      * @param cursorCol Current column of the cursor.
0360      *
0361      * @returns whether the given cursor position is at the end of
0362      *          textLines (after the last character of the last line)
0363      *          i.e. when moveCursorRight() won't do anything.
0364      */
0365     static bool CursorIsAtEnd (const QList <QString> &textLines,
0366         int cursorRow, int cursorCol);
0367 
0368 
0369     /**
0370      * Moves the given cursor position one character to the left, if
0371      * this is possible (i.e. if not cursorIsAtStart()).  This may move the
0372      * cursor one line up.
0373      *
0374      * @param textLines One or more lines of text.
0375      * @param cursorRow Value-result parameter, initially containing
0376      *                  the current row of the cursor and modified on
0377      *                  return to indicate the new row.
0378      * @param cursorCol Value-result parameter, initially containing
0379      *                  the current column of the cursor and modified on
0380      *                  return to indicate the new column.
0381      */
0382     static void MoveCursorLeft (const QList <QString> &textLines,
0383         int *cursorRow, int *cursorCol);
0384 
0385     /**
0386      * Moves the given cursor position one character to the right, if
0387      * this is possible (i.e. if not cursorIsAtEnd()).  This may move the
0388      * cursor one line down.
0389      *
0390      * @param textLines One or more lines of text.
0391      * @param cursorRow Value-result parameter, initially containing
0392      *                  the current row of the cursor and modified on
0393      *                  return to indicate the new row.
0394      * @param cursorCol Value-result parameter, initially containing
0395      *                  the current column of the cursor and modified on
0396      *                  return to indicate the new column.
0397      */
0398     static void MoveCursorRight (const QList <QString> &textLines,
0399         int *cursorRow, int *cursorCol);
0400 
0401 
0402     /**
0403      * Moves the row and column values, representing the current cursor
0404      * location, to the start of the current word.  If the cursor is
0405      * on a space, it will move to the start of the previous word.
0406      *
0407      * This is normally used for a CTRL+Left or CTRL+Backspace behaviour.
0408      *
0409      * @param textLines One or more lines of text.
0410      * @param cursorRow Value-result parameter, initially containing
0411      *                  the current row of the cursor and modified on
0412      *                  return to indicate the new row.
0413      * @param cursorCol Value-result parameter, initially containing
0414      *                  the current column of the cursor and modified on
0415      *                  return to indicate the new column.
0416      *
0417      * @returns the number of times, it <b>attempted</b> to move left.
0418      *          Note: Attempting to moving left when cursorIsAtStart()
0419      *                may still be counted as a move.
0420      */
0421     static int MoveCursorToWordStart (const QList <QString> &textLines,
0422         int *cursorRow, int *cursorCol);
0423 
0424     /**
0425      * Moves the row and column values, representing the current cursor
0426      * location, to the start of the next word.  This is regardless of
0427      * whether the cursor starts on a space or not.
0428      *
0429      * This is normally used for a CTRL+Right or CTRL+Delete behaviour.
0430      *
0431      * @param textLines One or more lines of text.
0432      * @param cursorRow Value-result parameter, initially containing
0433      *                  the current row of the cursor and modified on
0434      *                  return to indicate the new row.
0435      * @param cursorCol Value-result parameter, initially containing
0436      *                  the current column of the cursor and modified on
0437      *                  return to indicate the new column.
0438      *
0439      * @returns the number of times, it <b>attempted</b> to move right.
0440      *          Note: Attempting to moving right when cursorIsAtEnd()
0441      *                may still be counted as a move.
0442      */
0443     static int MoveCursorToNextWordStart (const QList <QString> &textLines,
0444         int *cursorRow, int *cursorCol);
0445 
0446 
0447 //
0448 // Keyboard Events - Handling Arrow Keys
0449 //
0450 // These methods always:
0451 //
0452 // 1. Before doing anything, end the current shape (e.g. a text editing command or
0453 //    selection move command).  This is done for 2 reasons:
0454 //
0455 //    a) The user has interrupted the current command e.g. if I were to
0456 //       type some text, press an arrow key and then type text again, the two
0457 //       periods of text typing should be separate commands due to the arrow
0458 //       key interruption.
0459 //
0460 //    b) To simplify the code by avoiding interference with the current command
0461 //       esp. since commands do not expect the cursor to move in the middle.
0462 //
0463 // 2. Accept the event as it is always intended for the method.  This is even
0464 //    if the operation could not complete e.g. an attempt to move the cursor
0465 //    left when it is already at column 0.
0466 //
0467 protected:
0468     /**
0469      * Moves the text cursor up one character.  Accepts the key event @p e.
0470      *
0471      * If there was an active text editing or selection command, it ends it first.
0472      *
0473      * @param e Mutable key event information.
0474      * @param textLines One or more lines of text (convenience parameter).
0475      * @param cursorRow Current row of the cursor (convenience parameter).
0476      * @param cursorCol Current column of the cursor (convenience parameter).
0477      *
0478      * Called by keyPressEvent().
0479      */
0480     void handleUpKeyPress (QKeyEvent *e,
0481         const QList <QString> &textLines, int cursorRow, int cursorCol);
0482 
0483     /**
0484      * Moves the text cursor down one character.  Accepts the key event @p e.
0485      *
0486      * If there was an active text editing or selection command, it ends it first.
0487      *
0488      * @param e Mutable key event information.
0489      * @param textLines One or more lines of text (convenience parameter).
0490      * @param cursorRow Current row of the cursor (convenience parameter).
0491      * @param cursorCol Current column of the cursor (convenience parameter).
0492      *
0493      * Called by keyPressEvent().
0494      */
0495     void handleDownKeyPress (QKeyEvent *e,
0496         const QList <QString> &textLines, int cursorRow, int cursorCol);
0497 
0498     /**
0499      * Moves the text cursor left one character or if CTRL is held, one
0500      * word.  Accepts the key event @p e.
0501      *
0502      * If there was an active text editing or selection command, it ends it first.
0503      *
0504      * @param e Mutable key event information.
0505      * @param textLines One or more lines of text (convenience parameter).
0506      * @param cursorRow Current row of the cursor (convenience parameter).
0507      * @param cursorCol Current column of the cursor (convenience parameter).
0508      *
0509      * Called by keyPressEvent().
0510      */
0511     void handleLeftKeyPress (QKeyEvent *e,
0512         const QList <QString> &textLines, int cursorRow, int cursorCol);
0513 
0514     /**
0515      * Moves the text cursor right one character or if CTRL is held, one
0516      * word.  Accepts the key event @p e.
0517      *
0518      * If there was an active text editing or selection command, it ends it first.
0519      *
0520      * @param e Mutable key event information.
0521      * @param textLines One or more lines of text (convenience parameter).
0522      * @param cursorRow Current row of the cursor (convenience parameter).
0523      * @param cursorCol Current column of the cursor (convenience parameter).
0524      *
0525      * Called by keyPressEvent().
0526      */
0527     void handleRightKeyPress (QKeyEvent *e,
0528         const QList <QString> &textLines, int cursorRow, int cursorCol);
0529 
0530 
0531     /**
0532      * Moves the text cursor to the start of the line and if CTRL is held,
0533      * to the first line.  Accepts the key event @p e.
0534      *
0535      * If there was an active text editing or selection command, it ends it first.
0536      *
0537      * @param e Mutable key event information.
0538      * @param textLines One or more lines of text (convenience parameter).
0539      * @param cursorRow Current row of the cursor (convenience parameter).
0540      * @param cursorCol Current column of the cursor (convenience parameter).
0541      *
0542      * Called by keyPressEvent().
0543      */
0544     void handleHomeKeyPress (QKeyEvent *e,
0545         const QList <QString> &textLines, int cursorRow, int cursorCol);
0546 
0547     /**
0548      * Moves the text cursor to after the last character of the current
0549      * text line or if CTRL is held, after the last character of the last
0550      * line.  Accepts the key event @p e.
0551      *
0552      * If there was an active text editing or selection command, it ends it first.
0553      *
0554      * @param e Mutable key event information.
0555      * @param textLines One or more lines of text (convenience parameter).
0556      * @param cursorRow Current row of the cursor (convenience parameter).
0557      * @param cursorCol Current column of the cursor (convenience parameter).
0558      *
0559      * Called by keyPressEvent().
0560      */
0561     void handleEndKeyPress (QKeyEvent *e,
0562         const QList <QString> &textLines, int cursorRow, int cursorCol);
0563 
0564 
0565 //
0566 // Keyboard Events - Handling Typing Keys
0567 //
0568 // For each method, if the respective event was actually intended for the
0569 // method:
0570 //
0571 // 1. If the event will not be a NOP:
0572 //
0573 //        If the current command is not the same as what this method would produce,
0574 //        it starts a new one, ending the current one (using the addNew*Command()
0575 //        methods).  If the current command is the same, it simply extends the
0576 //        current command e.g. if the current command was a kpToolTextInsertCommand
0577 //        and the user typed another character of text, that character would just be
0578 //        added to that command.
0579 //
0580 // 2. Accept the event.  This is even if the operation could not complete e.g.
0581 //    an attempt backspace when the cursor is at column 0.
0582 //
0583 // If the event was not intended for the method (e.g. pressing CTRL, Caps Lock
0584 // or any other key that does not produce text, in handleTextTyped()), nothing
0585 // happens.
0586 //
0587 protected:
0588     /**
0589      * Backspaces and if the active text editing command is not
0590      * d->backspaceCommand, it calls addNewBackspaceCommand() on
0591      * d->backspaceCommand first.
0592      *
0593      * If CTRL is held, it backspaces to the start of the active word
0594      * and if the current text editing command was not
0595      * d->backspaceWordCommand, it calls addNewBackspaceCommand() on
0596      * d->backspaceWordCommand first.
0597      *
0598      * In this way, Backspace and CTRL+Backspace are separate entries
0599      * in the commandHistory().
0600      *
0601      * Accepts the key event @p e.
0602      *
0603      * @param e Mutable key event information.
0604      * @param textLines One or more lines of text (convenience parameter).
0605      * @param cursorRow Current row of the cursor (convenience parameter).
0606      * @param cursorCol Current column of the cursor (convenience parameter).
0607      *
0608      * Called by keyPressEvent().
0609      */
0610     void handleBackspaceKeyPress (QKeyEvent *e,
0611         const QList <QString> &textLines, int cursorRow, int cursorCol);
0612 
0613     /**
0614      * Deletes and if the active text editing command is not
0615      * d->deleteCommand, it calls addNewDeleteCommand() on
0616      * d->deleteCommand first.
0617      *
0618      * If CTRL is held, it deletes to the start of the next word
0619      * and if the active text editing command was not
0620      * d->deleteWordCommand, it calls addNewDeleteCommand() on
0621      * d->deleteWordCommand first.
0622      *
0623      * In this way, Delete and CTRL+Delete are separate entries
0624      * in the commandHistory().
0625      *
0626      * Accepts the key event @p e.
0627      *
0628      * @param e Mutable key event information.
0629      * @param textLines One or more lines of text (convenience parameter).
0630      * @param cursorRow Current row of the cursor (convenience parameter).
0631      * @param cursorCol Current column of the cursor (convenience parameter).
0632      *
0633      * Called by keyPressEvent().
0634      */
0635     void handleDeleteKeyPress (QKeyEvent *e,
0636         const QList <QString> &textLines, int cursorRow, int cursorCol);
0637 
0638 
0639     /**
0640      * Enters and if the active text editing command is not
0641      * d->enterCommand, it ends the command, constructs d->enterCommand adding
0642      * it to commandHistory(), first.
0643      *
0644      * Accepts the key event @p e.
0645      *
0646      * @param e Mutable key event information.
0647      * @param textLines One or more lines of text (convenience parameter).
0648      * @param cursorRow Current row of the cursor (convenience parameter).
0649      * @param cursorCol Current column of the cursor (convenience parameter).
0650      *
0651      * Called by keyPressEvent().
0652      */
0653     void handleEnterKeyPress (QKeyEvent *e,
0654         const QList <QString> &textLines, int cursorRow, int cursorCol);
0655 
0656 
0657     /**
0658      * Inserts the printable characters of e->text() and accepts the key
0659      * event @p e.  If the active text editing command is not
0660      * d->insertCommand, it ends the command, constructs d->insertCommand
0661      * adding it to commandHistory(), first.
0662      *
0663      * If e->text() does not contain any printable characters, it does not
0664      * do anything.  As a result, it would not accept the key event @e.
0665      * This printability restriction prevents control characters from being
0666      * typed when they should be trapped by a keyPressEvent() that is lower
0667      * in the call chain (for e.g. CTRL+Z for Undo).
0668      *
0669      * @param e Mutable key event information.
0670      * @param textLines One or more lines of text (convenience parameter).
0671      * @param cursorRow Current row of the cursor (convenience parameter).
0672      * @param cursorCol Current column of the cursor (convenience parameter).
0673      *
0674      * Called by keyPressEvent().
0675      */
0676     void handleTextTyped (QKeyEvent *e,
0677         const QList <QString> &textLines, int cursorRow, int cursorCol);
0678 
0679 
0680 //
0681 // Keyboard Events
0682 //
0683 
0684 protected:
0685     // Prevents actions with single letter/number shortcuts from eating
0686     // keystrokes while a text selection is active.  This is important
0687     // because the Tool Box actions default to single letter/number
0688     // shortcuts.
0689     bool viewEvent (QEvent *e) override;
0690 
0691     /**
0692      * Handles key press events.
0693      *
0694      * If the user is currently drawing/resizing something or if the
0695      * document doesn't have a text selection, it passes control to the
0696      * otherwise overridden kpAbstractSelectionTool::keyPressEvent().
0697      *
0698      * Else, for a recognised key it calls handle.*Press().  If a
0699      * recognised key was not pressed, it assumes that one or more text
0700      * characters was typed, and calls handleTextTyped().  If none of the
0701      * handle.*() methods call e->accept(), it passes control to the
0702      * otherwise overridden kpAbstractSelectionTool::keyPressEvent().
0703      *
0704      * @param e Mutable key event information.
0705      *
0706      * Re-implemented from kpAbstractSelectionTool.
0707      */
0708 
0709     void keyPressEvent (QKeyEvent *e) override;
0710 
0711 
0712 //
0713 // Input Method Text Entry
0714 //
0715 
0716 protected:
0717     void inputMethodEvent (QInputMethodEvent *e) override;
0718 
0719 
0720 private:
0721     struct kpToolTextPrivate * const d;
0722 };
0723 
0724 
0725 #endif  // KP_TOOL_TEXT_H