ctkConsole.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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
  50. class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
  51. {
  52. Q_OBJECT
  53. Q_PROPERTY(QColor promptColor READ promptColor WRITE setPromptColor)
  54. Q_PROPERTY(QColor outputTextColor READ outputTextColor WRITE setOutputTextColor)
  55. Q_PROPERTY(QColor errorTextColor READ errorTextColor WRITE setErrorTextColor)
  56. Q_PROPERTY(QColor commandTextColor READ commandTextColor WRITE setCommandTextColor)
  57. Q_PROPERTY(QColor welcomeTextColor READ welcomeTextColor WRITE setWelcomeTextColor)
  58. Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor)
  59. Q_PROPERTY(QString ps1 READ ps1 WRITE setPs1)
  60. Q_PROPERTY(QString ps2 READ ps2 WRITE setPs2)
  61. Q_FLAGS(EditorHint EditorHints)
  62. Q_PROPERTY(EditorHints editorHints READ editorHints WRITE setEditorHints)
  63. Q_ENUMS(Qt::ScrollBarPolicy)
  64. Q_PROPERTY(Qt::ScrollBarPolicy scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy)
  65. public:
  66. enum EditorHint
  67. {
  68. NoHints = 0x00,
  69. AutomaticIndentation = 0x01, /*!< Align cursor based an indentation of the previous command */
  70. RemoveTrailingSpaces = 0x02, /*!< Remove trailing spaces of the entered command */
  71. SplitCopiedTextByLine = 0x4 /*!< Copied text is split by lines and each one is executed (expected the last one) */
  72. };
  73. Q_DECLARE_FLAGS(EditorHints, EditorHint)
  74. ctkConsole(QWidget* parentObject = 0);
  75. typedef QWidget Superclass;
  76. virtual ~ctkConsole();
  77. /// Returns the current formatting that will be used by printMessage()
  78. QTextCharFormat getFormat() const;
  79. /// Sets formatting that will be used by printMessage()
  80. void setFormat(const QTextCharFormat& Format);
  81. /// Set a completer for this console
  82. void setCompleter(ctkConsoleCompleter* completer);
  83. QColor promptColor()const;
  84. /// \sa promptColor()
  85. void setPromptColor(const QColor& newColor);
  86. QColor outputTextColor()const;
  87. /// \sa outputTextColor()
  88. void setOutputTextColor(const QColor& newColor);
  89. QColor errorTextColor()const;
  90. /// \sa errorTextColor()
  91. void setErrorTextColor(const QColor& newColor);
  92. QColor commandTextColor()const;
  93. /// \sa commandTextColor()
  94. void setCommandTextColor(const QColor& newColor);
  95. QColor welcomeTextColor()const;
  96. /// \sa welcomeTextColor()
  97. void setWelcomeTextColor(const QColor& newColor);
  98. QColor textBackgroundColor()const;
  99. void setTextBackgroundColor(const QColor& newColor);
  100. EditorHints editorHints()const;
  101. /// \sa editorHints()
  102. void setEditorHints(const EditorHints& newEditorHints);
  103. Qt::ScrollBarPolicy scrollBarPolicy()const;
  104. /// \sa scrollBarPolicy()
  105. void setScrollBarPolicy(const Qt::ScrollBarPolicy& newScrollBarPolicy);
  106. /// Prints text on the console
  107. void printMessage(const QString& message, const QColor& color);
  108. /// Returns the string used as primary prompt
  109. virtual QString ps1() const;
  110. /// Set the string used as primary prompt
  111. virtual void setPs1(const QString& newPs1);
  112. /// Returns the string used as secondary prompt
  113. virtual QString ps2() const;
  114. /// Set the string used as secondary prompt
  115. virtual void setPs2(const QString& newPs2);
  116. signals:
  117. /// This signal emitted before and after a command is executed
  118. void executing(bool);
  119. public slots:
  120. /// Clears the contents of the console
  121. virtual void clear();
  122. /// Clears the contents of the console and display welcome message
  123. virtual void reset();
  124. protected:
  125. /// Called whenever the user enters a command
  126. virtual void executeCommand(const QString& Command);
  127. protected:
  128. ctkConsole(ctkConsolePrivate * pimpl, QWidget* parentObject);
  129. QScopedPointer<ctkConsolePrivate> d_ptr;
  130. private:
  131. Q_DECLARE_PRIVATE(ctkConsole);
  132. Q_DISABLE_COPY(ctkConsole);
  133. };
  134. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkConsole::EditorHints);
  135. //-----------------------------------------------------------------------------
  136. class CTK_WIDGETS_EXPORT ctkConsoleCompleter : public QCompleter
  137. {
  138. public:
  139. /// Update the completion model given a string. The given string
  140. /// is the current console text between the cursor and the start of
  141. /// the line.
  142. virtual void updateCompletionModel(const QString& str) = 0;
  143. };
  144. #endif