ctkConsoleWidget.h 4.3 KB

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