CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkConsole.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 /*=========================================================================
21 
22  Program: ParaView
23 
24  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
25  All rights reserved.
26 
27  ParaView is a free software; you can redistribute it and/or modify it
28  under the terms of the ParaView license version 1.2.
29 
30  See http://www.paraview.org/paraview/project/license.html for the full ParaView license.
31  A copy of this license can be obtained by contacting
32  Kitware Inc.
33  28 Corporate Drive
34  Clifton Park, NY 12065
35  USA
36 
37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
41 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
46 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 
49 =========================================================================*/
50 
51 #ifndef __ctkConsole_h
52 #define __ctkConsole_h
53 
54 // Qt includes
55 #include <QWidget>
56 #include <QTextCharFormat>
57 #include <QCompleter>
58 
59 // CTK includes
60 #include "ctkWidgetsExport.h"
61 
62 class ctkConsolePrivate;
64 
67 class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
68 {
69  Q_OBJECT
70  Q_PROPERTY(QColor promptColor READ promptColor WRITE setPromptColor)
71  Q_PROPERTY(QColor outputTextColor READ outputTextColor WRITE setOutputTextColor)
72  Q_PROPERTY(QColor errorTextColor READ errorTextColor WRITE setErrorTextColor)
73  Q_PROPERTY(QColor stdinTextColor READ stdinTextColor WRITE setStdinTextColor)
74  Q_PROPERTY(QColor commandTextColor READ commandTextColor WRITE setCommandTextColor)
75  Q_PROPERTY(QColor welcomeTextColor READ welcomeTextColor WRITE setWelcomeTextColor)
76  Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
77  Q_PROPERTY(QString ps1 READ ps1 WRITE setPs1)
78  Q_PROPERTY(QString ps2 READ ps2 WRITE setPs2)
79  Q_FLAGS(EditorHint EditorHints)
80  Q_PROPERTY(EditorHints editorHints READ editorHints WRITE setEditorHints)
81  Q_ENUMS(Qt::ScrollBarPolicy)
82  Q_PROPERTY(Qt::ScrollBarPolicy scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy)
83  Q_PROPERTY(QList<QKeySequence> completerShortcuts READ completerShortcuts WRITE setCompleterShortcuts)
84  Q_FLAGS(RunFileOption RunFileOptions)
85  Q_PROPERTY(RunFileOptions runFileOptions READ runFileOptions WRITE setRunFileOptions)
86 
87 public:
88 
90  {
91  NoHints = 0x00,
92  AutomaticIndentation = 0x01,
93  RemoveTrailingSpaces = 0x02,
94  SplitCopiedTextByLine = 0x4
95  };
96  Q_DECLARE_FLAGS(EditorHints, EditorHint)
97 
99  {
100  NoRunFileUserInterface = 0x00,
101  RunFileButton = 0x01,
102  RunFileShortcut = 0x02,
103  };
104  Q_DECLARE_FLAGS(RunFileOptions, RunFileOption)
105 
106  ctkConsole(QWidget* parentObject = 0);
107  typedef QWidget Superclass;
108  virtual ~ctkConsole();
109 
111  QTextCharFormat getFormat() const;
112 
114  void setFormat(const QTextCharFormat& Format);
115 
117  QFont shellFont() const;
118 
120  void setShellFont(const QFont& font);
121 
123  ctkConsoleCompleter* completer() const;
124 
126  void setCompleter(ctkConsoleCompleter* completer);
127 
128  QColor promptColor()const;
129 
131  void setPromptColor(const QColor& newColor);
132 
133  QColor outputTextColor()const;
134 
136  void setOutputTextColor(const QColor& newColor);
137 
138  QColor errorTextColor()const;
139 
141  void setErrorTextColor(const QColor& newColor);
142 
143  QColor stdinTextColor()const;
144 
146  void setStdinTextColor(const QColor& newColor);
147 
148  QColor commandTextColor()const;
149 
151  void setCommandTextColor(const QColor& newColor);
152 
153  QColor welcomeTextColor()const;
154 
156  void setWelcomeTextColor(const QColor& newColor);
157 
158  QColor backgroundColor()const;
159 
160  void setBackgroundColor(const QColor& newColor);
161 
162  EditorHints editorHints()const;
163 
165  void setEditorHints(const EditorHints& newEditorHints);
166 
167  Qt::ScrollBarPolicy scrollBarPolicy()const;
168 
170  void setScrollBarPolicy(const Qt::ScrollBarPolicy& newScrollBarPolicy);
171 
173  void printMessage(const QString& message, const QColor& color);
174 
176  virtual QString ps1() const;
177 
179  virtual void setPs1(const QString& newPs1);
180 
182  virtual QString ps2() const;
183 
185  virtual void setPs2(const QString& newPs2);
186 
187  static QString stdInRedirectCallBack(void * callData);
188 
191  QList<QKeySequence> completerShortcuts()const;
192 
196  void setCompleterShortcuts(const QList<QKeySequence>& keys);
197 
201  void addCompleterShortcut(const QKeySequence& key);
202 
203  RunFileOptions runFileOptions()const;
204 
208  void setRunFileOptions(const RunFileOptions& newOptions);
209 
210 Q_SIGNALS:
211 
213  void aboutToExecute(const QString&);
214  void executed(const QString&);
215 
216 public Q_SLOTS:
217 
219  virtual void clear();
220 
222  virtual void reset();
223 
226  virtual void exec(const QString&);
227 
230  virtual void runFile(const QString& filePath);
231 
235  virtual void runFile();
236 
238  virtual void printHelp();
239 
240 protected:
241 
243  QString readInputLine();
244 
246  virtual void executeCommand(const QString& Command);
247 
248 protected:
249  ctkConsole(ctkConsolePrivate * pimpl, QWidget* parentObject);
250 
251  QScopedPointer<ctkConsolePrivate> d_ptr;
252 
253 private:
254  Q_DECLARE_PRIVATE(ctkConsole);
255  Q_DISABLE_COPY(ctkConsole);
256 };
257 
258 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkConsole::EditorHints);
259 
260 //-----------------------------------------------------------------------------
261 class CTK_WIDGETS_EXPORT ctkConsoleCompleter : public QCompleter
262 {
263 public:
264 
268  virtual void updateCompletionModel(const QString& str) = 0;
269 
271  QStringList autocompletePreferenceList();
272 
276  void setAutocompletePreferenceList(const QStringList& list);
277 
278 protected:
279 
281 };
282 
283 
284 #endif
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkConsole::EditorHints)
QStringList AutocompletePreferenceList
Definition: ctkConsole.h:280
QScopedPointer< ctkConsolePrivate > d_ptr
Definition: ctkConsole.h:251
QWidget Superclass
Definition: ctkConsole.h:107