ctkConsole_p.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. typedef QTextEdit Superclass;
  31. void init();
  32. virtual void keyPressEvent(QKeyEvent* e);
  33. void switchToUserInputTextColor(QTextCursor* textCursorToUpdate = 0);
  34. /// Returns the end of the document
  35. int documentEnd() const;
  36. virtual void focusOutEvent(QFocusEvent *e);
  37. virtual void resizeEvent(QResizeEvent * e);
  38. /// Force the scrollbar to be all the way down
  39. void scrollToBottom();
  40. void updateCompleterIfVisible();
  41. /// If there is exactly 1 completion, insert it and hide the completer,
  42. /// else do nothing.
  43. void selectCompletion();
  44. void setCompleter(ctkConsoleCompleter* completer);
  45. void updateCompleter();
  46. /// Update the contents of the command buffer from the contents of the widget
  47. void updateCommandBuffer();
  48. /// Replace the contents of the command buffer, updating the display
  49. void replaceCommandBuffer(const QString& text);
  50. /// References the buffer where the current un-executed command is stored
  51. QString& commandBuffer();
  52. /// Implements command-execution
  53. void internalExecuteCommand();
  54. /// Writes the supplied text to the console
  55. void printString(const QString& text);
  56. /// Updates the current command.
  57. /// Unlike printMessage(), this will affect the current command being typed.
  58. void printCommand(const QString& cmd);
  59. /// Puts out an input accepting promp using either ps1 or ps2.
  60. /// ps2 will be used if MultilineStatement is True
  61. /// \sa ctkConsole::ps1(), ctkConsole::ps2()
  62. void promptForInput(const QString& indent = QString());
  63. /// Puts out an input accepting prompt.
  64. /// It is recommended that one uses prompt instead of printMessage() to print
  65. /// an input prompt since this call ensures that the prompt is shown on a new
  66. /// line.
  67. void prompt(const QString& text);
  68. /// Print welcome message
  69. virtual void printWelcomeMessage();
  70. public slots:
  71. /// Inserts the given completion string at the cursor. This will replace
  72. /// the current word that the cursor is touching with the given text.
  73. /// Determines the word using QTextCursor::StartOfWord, EndOfWord.
  74. void insertCompletion(const QString& text);
  75. /// Print a message
  76. /// \sa ctkConsole::outputTextColor
  77. void printOutputMessage(const QString& text);
  78. /// Print a message
  79. /// \sa ctkConsole::errorTextColor
  80. void printErrorMessage(const QString& text);
  81. /// Update the value of ScrollbarAtBottom given the current position of the scollbar
  82. void onScrollBarValueChanged(int value);
  83. public:
  84. /// A custom completer
  85. QPointer<ctkConsoleCompleter> Completer;
  86. /// Stores the beginning of the area of interactive input, outside which
  87. /// changes can't be made to the text edit contents
  88. int InteractivePosition;
  89. /// Indicates if the last statement processes was incomplete.
  90. bool MultilineStatement;
  91. /// Stores command-history, plus the current command buffer
  92. QStringList CommandHistory;
  93. /// Stores the current position in the command-history
  94. int CommandPosition;
  95. /// Prompt color
  96. QColor PromptColor;
  97. /// Output text color
  98. QColor OutputTextColor;
  99. /// Error text color
  100. QColor ErrorTextColor;
  101. /// Command text color
  102. QColor CommandTextColor;
  103. /// Welcome text color
  104. QColor WelcomeTextColor;
  105. /// Primary prompt
  106. QString Ps1;
  107. /// Secondary prompt
  108. QString Ps2;
  109. ctkConsole::EditorHints EditorHints;
  110. bool ScrollbarAtBottom;
  111. };
  112. #endif