ctkConsole.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
  53. {
  54. Q_OBJECT
  55. Q_PROPERTY(QColor promptColor READ promptColor WRITE setPromptColor)
  56. Q_PROPERTY(QColor outputTextColor READ outputTextColor WRITE setOutputTextColor)
  57. Q_PROPERTY(QColor errorTextColor READ errorTextColor WRITE setErrorTextColor)
  58. Q_PROPERTY(QColor commandTextColor READ commandTextColor WRITE setCommandTextColor)
  59. Q_PROPERTY(QColor welcomeTextColor READ welcomeTextColor WRITE setWelcomeTextColor)
  60. public:
  61. ctkConsole(QWidget* parentObject = 0);
  62. virtual ~ctkConsole();
  63. /// Returns the current formatting that will be used by printMessage()
  64. QTextCharFormat getFormat() const;
  65. /// Sets formatting that will be used by printMessage()
  66. void setFormat(const QTextCharFormat& Format);
  67. /// Set a completer for this console
  68. void setCompleter(ctkConsoleCompleter* completer);
  69. QColor promptColor()const;
  70. /// \sa promptColor()
  71. void setPromptColor(const QColor& newColor);
  72. QColor outputTextColor()const;
  73. /// \sa outputTextColor()
  74. void setOutputTextColor(const QColor& newColor);
  75. QColor errorTextColor()const;
  76. /// \sa errorTextColor()
  77. void setErrorTextColor(const QColor& newColor);
  78. QColor commandTextColor()const;
  79. /// \sa commandTextColor()
  80. void setCommandTextColor(const QColor& newColor);
  81. QColor welcomeTextColor()const;
  82. /// \sa welcomeTextColor()
  83. void setWelcomeTextColor(const QColor& newColor);
  84. /// Prints text on the console
  85. void printMessage(const QString& message, const QColor& color);
  86. signals:
  87. /// This signal emitted before and after a command is executed
  88. void executing(bool);
  89. public slots:
  90. /// Clears the contents of the console
  91. virtual void clear();
  92. protected:
  93. /// Called whenever the user enters a command
  94. virtual void executeCommand(const QString& Command);
  95. protected:
  96. ctkConsole(ctkConsolePrivate * pimpl, QWidget* parentObject);
  97. QScopedPointer<ctkConsolePrivate> d_ptr;
  98. private:
  99. Q_DECLARE_PRIVATE(ctkConsole);
  100. Q_DISABLE_COPY(ctkConsole);
  101. };
  102. //-----------------------------------------------------------------------------
  103. class CTK_WIDGETS_EXPORT ctkConsoleCompleter : public QCompleter
  104. {
  105. public:
  106. /// Update the completion model given a string. The given string
  107. /// is the current console text between the cursor and the start of
  108. /// the line.
  109. virtual void updateCompletionModel(const QString& str) = 0;
  110. };
  111. #endif