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_PROPERTY(int cursorPosition READ cursorPosition)
80  Q_PROPERTY(int cursorColumn READ cursorColumn)
81  Q_PROPERTY(int cursorLine READ cursorLine)
82  Q_FLAGS(EditorHint EditorHints)
83  Q_PROPERTY(EditorHints editorHints READ editorHints WRITE setEditorHints)
84  Q_ENUMS(Qt::ScrollBarPolicy)
85  Q_PROPERTY(Qt::ScrollBarPolicy scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy)
86  Q_PROPERTY(QList<QKeySequence> completerShortcuts READ completerShortcuts WRITE setCompleterShortcuts)
87  Q_FLAGS(RunFileOption RunFileOptions)
88  Q_PROPERTY(RunFileOptions runFileOptions READ runFileOptions WRITE setRunFileOptions)
89 
90 public:
91 
93  {
94  NoHints = 0x00,
95  AutomaticIndentation = 0x01,
96  RemoveTrailingSpaces = 0x02,
97  SplitCopiedTextByLine = 0x4
98  };
99  Q_DECLARE_FLAGS(EditorHints, EditorHint)
100 
102  {
103  NoRunFileUserInterface = 0x00,
104  RunFileButton = 0x01,
105  RunFileShortcut = 0x02,
106  };
107  Q_DECLARE_FLAGS(RunFileOptions, RunFileOption)
108 
109  ctkConsole(QWidget* parentObject = 0);
110  typedef QWidget Superclass;
111  virtual ~ctkConsole();
112 
114  QTextCharFormat getFormat() const;
115 
117  void setFormat(const QTextCharFormat& Format);
118 
120  QFont shellFont() const;
121 
123  void setShellFont(const QFont& font);
124 
126  ctkConsoleCompleter* completer() const;
127 
129  void setCompleter(ctkConsoleCompleter* completer);
130 
131  QColor promptColor()const;
132 
134  void setPromptColor(const QColor& newColor);
135 
136  QColor outputTextColor()const;
137 
139  void setOutputTextColor(const QColor& newColor);
140 
141  QColor errorTextColor()const;
142 
144  void setErrorTextColor(const QColor& newColor);
145 
146  QColor stdinTextColor()const;
147 
149  void setStdinTextColor(const QColor& newColor);
150 
151  QColor commandTextColor()const;
152 
154  void setCommandTextColor(const QColor& newColor);
155 
156  QColor welcomeTextColor()const;
157 
159  void setWelcomeTextColor(const QColor& newColor);
160 
161  QColor backgroundColor()const;
162 
163  void setBackgroundColor(const QColor& newColor);
164 
165  EditorHints editorHints()const;
166 
168  void setEditorHints(const EditorHints& newEditorHints);
169 
170  Qt::ScrollBarPolicy scrollBarPolicy()const;
171 
173  void setScrollBarPolicy(const Qt::ScrollBarPolicy& newScrollBarPolicy);
174 
176  void printMessage(const QString& message, const QColor& color);
177 
179  virtual QString ps1() const;
180 
182  virtual void setPs1(const QString& newPs1);
183 
185  virtual QString ps2() const;
186 
188  virtual void setPs2(const QString& newPs2);
189 
192  int cursorPosition() const;
193 
196  int cursorColumn() const;
197 
200  int cursorLine() const;
201 
202  static QString stdInRedirectCallBack(void * callData);
203 
206  QList<QKeySequence> completerShortcuts()const;
207 
211  void setCompleterShortcuts(const QList<QKeySequence>& keys);
212 
216  void addCompleterShortcut(const QKeySequence& key);
217 
218  RunFileOptions runFileOptions()const;
219 
223  void setRunFileOptions(const RunFileOptions& newOptions);
224 
225 Q_SIGNALS:
226 
228  void aboutToExecute(const QString&);
229  void executed(const QString&);
230 
233  void cursorPositionChanged();
234 
235 public Q_SLOTS:
236 
238  virtual void clear();
239 
241  virtual void reset();
242 
245  virtual void exec(const QString&);
246 
249  virtual void runFile(const QString& filePath);
250 
254  virtual void runFile();
255 
257  virtual void printHelp();
258 
259 protected:
260 
262  QString readInputLine();
263 
265  virtual void executeCommand(const QString& Command);
266 
267 protected:
268  ctkConsole(ctkConsolePrivate * pimpl, QWidget* parentObject);
269 
270  QScopedPointer<ctkConsolePrivate> d_ptr;
271 
272 private:
273  Q_DECLARE_PRIVATE(ctkConsole);
274  Q_DISABLE_COPY(ctkConsole);
275 };
276 
278 
279 //-----------------------------------------------------------------------------
280 class CTK_WIDGETS_EXPORT ctkConsoleCompleter : public QCompleter
281 {
282 public:
283 
287  virtual void updateCompletionModel(const QString& str) = 0;
288 
291  virtual int cursorOffset(const QString& completion) = 0;
292 
295 
299  void setAutocompletePreferenceList(const QStringList& list);
300 
301 protected:
302 
304 };
305 
306 
307 #endif
QStringList autocompletePreferenceList()
Returns the autocomplete preference list.
virtual int cursorOffset(const QString &completion)=0
void setAutocompletePreferenceList(const QStringList &list)
QStringList AutocompletePreferenceList
Definition: ctkConsole.h:303
virtual void updateCompletionModel(const QString &str)=0
QWidget Superclass
Definition: ctkConsole.h:110
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkConsole::EditorHints)