ctkConsole.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. /*=========================================================================
  15. Program: ParaView
  16. Module: $RCSfile$
  17. Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
  18. All rights reserved.
  19. ParaView is a free software; you can redistribute it and/or modify it
  20. under the terms of the ParaView license version 1.2.
  21. See License_v1.2.txt for the full ParaView license.
  22. A copy of this license can be obtained by contacting
  23. Kitware Inc.
  24. 28 Corporate Drive
  25. Clifton Park, NY 12065
  26. USA
  27. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. =========================================================================*/
  39. #ifndef __ctkConsole_h
  40. #define __ctkConsole_h
  41. // Qt includes
  42. #include <QWidget>
  43. #include <QTextCharFormat>
  44. #include <QCompleter>
  45. // CTK includes
  46. #include "ctkWidgetsExport.h"
  47. class ctkConsolePrivate;
  48. class ctkConsoleCompleter;
  49. /// Qwidget that provides an interactive console - you can send text to the
  50. /// console by calling printString() and receive user input by connecting to the
  51. /// executeCommand() slot.
  52. ///
  53. /// \sa pqPythonShell, pqOutputWindow
  54. class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
  55. {
  56. Q_OBJECT
  57. public:
  58. ctkConsole(QWidget* parentObject = 0);
  59. virtual ~ctkConsole();
  60. /// Returns the current formatting that will be used by printString
  61. QTextCharFormat getFormat() const;
  62. /// Sets formatting that will be used by printString
  63. void setFormat(const QTextCharFormat& Format);
  64. /// Set a completer for this console widget
  65. void setCompleter(ctkConsoleCompleter* completer);
  66. signals:
  67. /// Signal emitted whenever the user enters a command
  68. void executeCommand(const QString& Command);
  69. public slots:
  70. /// Writes the supplied text to the console
  71. void printString(const QString& Text);
  72. /// Updates the current command. Unlike printString, this will affect the
  73. /// current command being typed.
  74. void printCommand(const QString& cmd);
  75. /// Clears the contents of the console
  76. void clear();
  77. /// Puts out an input accepting prompt.
  78. /// It is recommended that one uses prompt instead of printString() to print
  79. /// an input prompt since this call ensures that the prompt is shown on a new
  80. /// line.
  81. void prompt(const QString& text);
  82. /// Inserts the given completion string at the cursor. This will replace
  83. /// the current word that the cursor is touching with the given text.
  84. /// Determines the word using QTextCursor::StartOfWord, EndOfWord.
  85. void insertCompletion(const QString& text);
  86. protected:
  87. QScopedPointer<ctkConsolePrivate> d_ptr;
  88. private:
  89. Q_DECLARE_PRIVATE(ctkConsole);
  90. Q_DISABLE_COPY(ctkConsole);
  91. void internalExecuteCommand(const QString& Command);
  92. };
  93. //-----------------------------------------------------------------------------
  94. class CTK_WIDGETS_EXPORT ctkConsoleCompleter : public QCompleter
  95. {
  96. public:
  97. /// Update the completion model given a string. The given string
  98. /// is the current console text between the cursor and the start of
  99. /// the line.
  100. virtual void updateCompletionModel(const QString& str) = 0;
  101. };
  102. #endif