ctkConsole_p.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkConsole_p_h
  15. #define __ctkConsole_p_h
  16. // Qt includes
  17. #include <QTextEdit>
  18. #include <QPointer>
  19. // CTK includes
  20. #include "ctkConsole.h"
  21. #include "ctkWidgetsExport.h"
  22. class CTK_WIDGETS_EXPORT ctkConsolePrivate : public QTextEdit
  23. {
  24. Q_OBJECT
  25. Q_DECLARE_PUBLIC(ctkConsole);
  26. protected:
  27. ctkConsole* const q_ptr;
  28. public:
  29. ctkConsolePrivate(ctkConsole& object);
  30. void init();
  31. virtual void keyPressEvent(QKeyEvent* e);
  32. void switchToUserInputTextColor(QTextCursor* textCursorToUpdate = 0);
  33. /// Returns the end of the document
  34. int documentEnd() const;
  35. virtual void focusOutEvent(QFocusEvent *e);
  36. void updateCompleterIfVisible();
  37. /// If there is exactly 1 completion, insert it and hide the completer,
  38. /// else do nothing.
  39. void selectCompletion();
  40. void setCompleter(ctkConsoleCompleter* completer);
  41. void updateCompleter();
  42. /// Update the contents of the command buffer from the contents of the widget
  43. void updateCommandBuffer();
  44. /// Replace the contents of the command buffer, updating the display
  45. void replaceCommandBuffer(const QString& text);
  46. /// References the buffer where the current un-executed command is stored
  47. QString& commandBuffer();
  48. /// Implements command-execution
  49. void internalExecuteCommand();
  50. /// Writes the supplied text to the console
  51. void printString(const QString& text);
  52. /// Updates the current command.
  53. /// Unlike printMessage(), this will affect the current command being typed.
  54. void printCommand(const QString& cmd);
  55. /// Puts out an input accepting promp using either ps1 or ps2.
  56. /// ps2 will be used if MultilineStatement is True
  57. /// \sa ctkConsole::ps1(), ctkConsole::ps2()
  58. void promptForInput(const QString& indent = QString());
  59. /// Puts out an input accepting prompt.
  60. /// It is recommended that one uses prompt instead of printMessage() to print
  61. /// an input prompt since this call ensures that the prompt is shown on a new
  62. /// line.
  63. void prompt(const QString& text);
  64. /// Print welcome message
  65. virtual void printWelcomeMessage();
  66. public slots:
  67. /// Inserts the given completion string at the cursor. This will replace
  68. /// the current word that the cursor is touching with the given text.
  69. /// Determines the word using QTextCursor::StartOfWord, EndOfWord.
  70. void insertCompletion(const QString& text);
  71. /// Print a message
  72. /// \sa ctkConsole::outputTextColor
  73. void printOutputMessage(const QString& text);
  74. /// Print a message
  75. /// \sa ctkConsole::errorTextColor
  76. void printErrorMessage(const QString& text);
  77. public:
  78. /// A custom completer
  79. QPointer<ctkConsoleCompleter> Completer;
  80. /// Stores the beginning of the area of interactive input, outside which
  81. /// changes can't be made to the text edit contents
  82. int InteractivePosition;
  83. /// Indicates if the last statement processes was incomplete.
  84. bool MultilineStatement;
  85. /// Stores command-history, plus the current command buffer
  86. QStringList CommandHistory;
  87. /// Stores the current position in the command-history
  88. int CommandPosition;
  89. /// Prompt color
  90. QColor PromptColor;
  91. /// Output text color
  92. QColor OutputTextColor;
  93. /// Error ext color
  94. QColor ErrorTextColor;
  95. /// Command text color
  96. QColor CommandTextColor;
  97. /// Welcome text color
  98. QColor WelcomeTextColor;
  99. /// Primary prompt
  100. QString Ps1;
  101. /// Secondary prompt
  102. QString Ps2;
  103. ctkConsole::EditorHints EditorHints;
  104. };
  105. #endif