ctkConsole_p.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /// Returns the end of the document
  33. int documentEnd() const;
  34. void focusOutEvent(QFocusEvent *e);
  35. void updateCompleterIfVisible();
  36. /// If there is exactly 1 completion, insert it and hide the completer,
  37. /// else do nothing.
  38. void selectCompletion();
  39. void updateCompleter();
  40. /// Update the contents of the command buffer from the contents of the widget
  41. void updateCommandBuffer();
  42. /// Replace the contents of the command buffer, updating the display
  43. void replaceCommandBuffer(const QString& Text);
  44. /// References the buffer where the current un-executed command is stored
  45. QString& commandBuffer();
  46. /// Implements command-execution
  47. void internalExecuteCommand();
  48. void setCompleter(ctkConsoleCompleter* completer);
  49. /// Writes the supplied text to the console
  50. void printString(const QString& text);
  51. /// Updates the current command.
  52. /// Unlike printMessage(), this will affect the current command being typed.
  53. void printCommand(const QString& cmd);
  54. void promptForInput(const QString& indent = QString());
  55. /// Puts out an input accepting prompt.
  56. /// It is recommended that one uses prompt instead of printMessage() to print
  57. /// an input prompt since this call ensures that the prompt is shown on a new
  58. /// line.
  59. void prompt(const QString& text);
  60. public slots:
  61. /// Inserts the given completion string at the cursor. This will replace
  62. /// the current word that the cursor is touching with the given text.
  63. /// Determines the word using QTextCursor::StartOfWord, EndOfWord.
  64. void insertCompletion(const QString& text);
  65. void printOutputMessage(const QString& text);
  66. void printErrorMessage(const QString& text);
  67. public:
  68. /// A custom completer
  69. QPointer<ctkConsoleCompleter> Completer;
  70. /// Stores the beginning of the area of interactive input, outside which
  71. /// changes can't be made to the text edit contents
  72. int InteractivePosition;
  73. /// Indicates if the last statement processes was incomplete.
  74. bool MultilineStatement;
  75. /// Stores command-history, plus the current command buffer
  76. QStringList CommandHistory;
  77. /// Stores the current position in the command-history
  78. int CommandPosition;
  79. /// Prompt color
  80. QColor PromptColor;
  81. /// Output text color
  82. QColor OutputTextColor;
  83. /// Error ext color
  84. QColor ErrorTextColor;
  85. /// Command text color
  86. QColor CommandTextColor;
  87. /// Welcome text color
  88. QColor WelcomeTextColor;
  89. /// Primary prompt
  90. QString Ps1;
  91. /// Secondary prompt
  92. QString Ps2;
  93. };
  94. #endif