![]() |
TinkerCell Core 1.0
TinkerCell's Core library providing all basic functionalities
|
00001 /**************************************************************************** 00002 00003 Copyright (c) 2008 Deepak Chandran 00004 Contact: Deepak Chandran (dchandran1@gmail.com) 00005 See COPYRIGHT.TXT 00006 00007 This file defines the output window, which is a text area where other tools can post messages or use as a 00008 scripting interface. 00009 00010 00011 ****************************************************************************/ 00012 00013 00014 #ifndef TINKERCELL_GENERICCOMMANDANDOUTPUTWINDOW_H 00015 #define TINKERCELL_GENERICCOMMANDANDOUTPUTWINDOW_H 00016 00017 #include <QtGui> 00018 #include <QColor> 00019 #include <QMainWindow> 00020 #include <QTextCursor> 00021 #include <QTextEdit> 00022 #include <QCompleter> 00023 #include <QSyntaxHighlighter> 00024 #include <QRegExp> 00025 #include <QCompleter> 00026 #include "DataTable.h" 00027 #include "Tool.h" 00028 #include "interpreters/InterpreterThread.h" 00029 00030 namespace Tinkercell 00031 { 00032 class MainWindow; 00033 class ConsoleWindow; 00037 class TINKERCELLCOREEXPORT CommandTextEdit : public QTextEdit 00038 { 00039 Q_OBJECT; 00040 public: 00041 00043 CommandTextEdit(MainWindow * parent=0); 00045 virtual bool isFrozen(); 00047 void setCompleter(QCompleter *c); 00049 QCompleter *completer() const; 00051 virtual QString lastError() const; 00053 virtual QString lastMessage() const; 00054 00055 signals: 00056 00058 void commandExecuted(const QString& command); 00060 void commandInterrupted(); 00061 00062 public slots: 00063 00065 virtual void eval(const QString&); 00067 virtual void error(const QString&); 00069 virtual void message(const QString&); 00071 virtual void clearText(); 00073 virtual void freeze(); 00075 virtual void unfreeze(); 00077 virtual void setFreeze (bool frozen=true); 00079 virtual void setBackgroundColor(const QColor&); 00081 virtual void setPlainTextColor(const QColor&); 00083 virtual void setOutputTextColor(const QColor&); 00085 virtual void setErrorTextColor(const QColor&); 00087 virtual void setTableTextColor(const QColor&); 00088 00089 protected: 00090 00092 QStringList historyStack; 00094 QStringList messagesStack; 00096 QStringList errorsStack; 00098 QString _lastError; 00100 QString _lastOutput; 00102 int currentHistoryIndex; 00104 int currentPosition; 00106 bool frozen; 00108 QTextCharFormat errorFormat; 00110 QTextCharFormat messageFormat; 00112 QTextCharFormat tableHeaderFormat; 00114 QTextCharFormat normalFormat; 00116 virtual void keyPressEvent ( QKeyEvent * event ); 00118 virtual void wheelEvent ( QWheelEvent * wheelEvent ); 00120 virtual void focusInEvent(QFocusEvent *e); 00121 00122 private slots: 00124 void insertCompletion(const QString &completion); 00125 00126 private: 00128 QString textUnderCursor() const; 00130 QCompleter *c; 00132 MainWindow * mainWindow; 00134 bool printValue(QTextCursor&, const QString&); 00136 void printHandleSummary(QTextCursor&, ItemHandle *); 00138 bool alreadyInsertedPrompt; 00139 00140 friend class ConsoleWindow; 00141 }; 00142 00146 class TINKERCELLCOREEXPORT ConsoleWindow : public Tool 00147 { 00148 Q_OBJECT 00149 00150 public: 00151 00153 static QString Prompt; 00154 00156 static QColor BackgroundColor; 00157 00159 static QColor PlainTextColor; 00160 00162 static QColor ErrorTextColor; 00163 00165 static QColor OutputTextColor; 00166 00168 static QColor TableTextColor; 00169 00171 ConsoleWindow(MainWindow * main = 0); 00172 00174 virtual CommandTextEdit * editor(); 00175 00177 virtual void setInterpreter(InterpreterThread * ); 00178 00180 InterpreterThread * interpreter() const; 00181 00183 virtual QString lastError() const; 00184 00186 virtual QString lastMessage() const; 00187 00188 public slots: 00190 virtual void eval(const QString&); 00192 virtual void message(const QString&); 00194 virtual void error(const QString&); 00196 virtual void printTable(const DataTable<qreal>& dataTable); 00198 virtual void printTable(const DataTable<QString>& dataTable); 00200 virtual void clear(); 00202 virtual void freeze(); 00204 virtual void unfreeze(); 00205 00206 signals: 00208 void commandExecuted(const QString& command); 00210 void commandInterrupted(); 00211 00212 protected: 00214 CommandTextEdit commandTextEdit; 00216 InterpreterThread * _interpreter; 00217 00218 }; 00219 } 00220 00221 #endif