ctkConsole_p.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. void keyPressEvent(QKeyEvent* e);
  32. void switchToUserInputTextColor();
  33. /// Returns the end of the document
  34. int documentEnd() const;
  35. 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. public slots:
  65. /// Inserts the given completion string at the cursor. This will replace
  66. /// the current word that the cursor is touching with the given text.
  67. /// Determines the word using QTextCursor::StartOfWord, EndOfWord.
  68. void insertCompletion(const QString& text);
  69. /// Print a message
  70. /// \sa ctkConsole::outputTextColor
  71. void printOutputMessage(const QString& text);
  72. /// Print a message
  73. /// \sa ctkConsole::errorTextColor
  74. void printErrorMessage(const QString& text);
  75. public:
  76. /// A custom completer
  77. QPointer<ctkConsoleCompleter> Completer;
  78. /// Stores the beginning of the area of interactive input, outside which
  79. /// changes can't be made to the text edit contents
  80. int InteractivePosition;
  81. /// Indicates if the last statement processes was incomplete.
  82. bool MultilineStatement;
  83. /// Stores command-history, plus the current command buffer
  84. QStringList CommandHistory;
  85. /// Stores the current position in the command-history
  86. int CommandPosition;
  87. /// Prompt color
  88. QColor PromptColor;
  89. /// Output text color
  90. QColor OutputTextColor;
  91. /// Error ext color
  92. QColor ErrorTextColor;
  93. /// Command text color
  94. QColor CommandTextColor;
  95. /// Welcome text color
  96. QColor WelcomeTextColor;
  97. /// Primary prompt
  98. QString Ps1;
  99. /// Secondary prompt
  100. QString Ps2;
  101. ctkConsole::EditorHints EditorHints;
  102. };
  103. #endif