ScriptEdit.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef SCRIPTEDIT_H
00030 #define SCRIPTEDIT_H
00031
00032 #include "ScriptingEnv.h"
00033 #include "Script.h"
00034
00035 #include <QMenu>
00036 #include <QTextEdit>
00037
00038 class QAction;
00039 class QMenu;
00040 class QCompleter;
00041
00042 class SyntaxHighlighter;
00043
00050 class ScriptEdit: public QTextEdit, public scripted
00051 {
00052 Q_OBJECT
00053
00054 public:
00055 ScriptEdit(ScriptingEnv *env, QWidget *parent=0, const char *name=0);
00056 ~ScriptEdit();
00058 void customEvent(QEvent*);
00060 int lineNumber(int pos) const;
00061 bool error(){return d_error;};
00062
00063 void setCompleter(QCompleter *c);
00064 void setFileName(const QString& fn);
00065 void rehighlight();
00066 void redirectOutputTo(QTextEdit *);
00067
00068 public slots:
00069 void execute();
00070 void executeAll();
00071 void evaluate();
00072 void print();
00073 void print(QPrinter*);
00074 void exportPDF(const QString& fileName);
00075 QString save();
00076 QString exportASCII(const QString &file=QString::null);
00077 QString importASCII(const QString &file=QString::null);
00078 void insertFunction(const QString &);
00079 void insertFunction(QAction * action);
00080 void setContext(QObject *context) { myScript->setContext(context); }
00081 void scriptPrint(const QString&);
00082
00083 void updateIndentation();
00084 void setDirPath(const QString& path);
00085 void showFindDialog(bool replace = false);
00086 void replace(){showFindDialog(true);};
00087 bool find(const QString& searchString, QTextDocument::FindFlags flags, bool previous = false);
00088 void findNext();
00089 void findPrevious();
00090
00091 signals:
00092 void dirPathChanged(const QString& path);
00093 void error(const QString&, const QString&, int);
00094
00095 protected:
00096 virtual void contextMenuEvent(QContextMenuEvent *e);
00097 virtual void keyPressEvent(QKeyEvent *e);
00098 void focusInEvent(QFocusEvent *e);
00099
00100 private:
00101 void clearErrorHighlighting();
00102 void highlightErrorLine(int offset);
00103
00104 Script *myScript;
00105 QAction *actionExecute, *actionExecuteAll, *actionEval, *actionPrint, *actionImport, *actionSave, *actionExport;
00106 QAction *actionFind, *actionReplace, *actionFindNext, *actionFindPrevious;
00108 QMenu *functionsMenu;
00110 QTextCursor printCursor;
00111 QString scriptsDirPath;
00112
00114 QTextBlockFormat d_fmt_default;
00116 bool d_error;
00117 QString d_err_message;
00118
00119 QCompleter *d_completer;
00120 SyntaxHighlighter *d_highlighter;
00121 QString d_file_name;
00122 QString d_search_string;
00123 QTextDocument::FindFlags d_search_flags;
00124 QTextEdit *d_output_widget;
00125
00126 private slots:
00128
00132 void insertErrorMsg(const QString &message);
00133 void insertCompletion(const QString &completion);
00134 void matchParentheses();
00135
00136 private:
00137 QString textUnderCursor() const;
00138 bool matchLeftParenthesis(QTextBlock currentBlock, int index, int numRightParentheses);
00139 bool matchRightParenthesis(QTextBlock currentBlock, int index, int numLeftParentheses);
00140 void createParenthesisSelection(int pos);
00141 };
00142
00144 struct ParenthesisInfo
00145 {
00146 char character;
00147 int position;
00148 };
00149
00151 class TextBlockData : public QTextBlockUserData
00152 {
00153 public:
00154 TextBlockData(){};
00155
00156 QVector<ParenthesisInfo *> parentheses(){return m_parentheses;};
00157 void insert(ParenthesisInfo *info)
00158 {
00159 int i = 0;
00160 while (i < m_parentheses.size() &&
00161 info->position > m_parentheses.at(i)->position)
00162 ++i;
00163
00164 m_parentheses.insert(i, info);
00165 }
00166
00167 private:
00168 QVector<ParenthesisInfo *> m_parentheses;
00169 };
00170
00171 #endif