ScriptEdit.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : ScriptEdit.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief, Knut Franke
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr, knut.franke*gmx.de
00007     Description          : Scripting classes
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
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 
00048 class ScriptEdit: public QTextEdit, public scripted
00049 {
00050   Q_OBJECT
00051 
00052   public:
00053     ScriptEdit(ScriptingEnv *env, QWidget *parent=0, const char *name=0);
00055     void customEvent(QEvent*);
00057     int lineNumber(int pos) const;
00058     bool error(){return d_error;};
00059 
00060     void setCompleter(QCompleter *c);
00061 
00062   public slots:
00063     void execute();
00064     void executeAll();
00065     void evaluate();
00066     void print();
00067     void exportPDF(const QString& fileName);
00068     QString exportASCII(const QString &file=QString::null);
00069     QString importASCII(const QString &file=QString::null);
00070     void insertFunction(const QString &);
00071     void insertFunction(QAction * action);
00072     void setContext(QObject *context) { myScript->setContext(context); }
00073     void scriptPrint(const QString&);
00074     void updateIndentation();
00075     void setDirPath(const QString& path);
00076 
00077   signals:
00078     void dirPathChanged(const QString& path);
00079 
00080   protected:
00081     virtual void contextMenuEvent(QContextMenuEvent *e);
00082     virtual void keyPressEvent(QKeyEvent *e);
00083     void focusInEvent(QFocusEvent *e);
00084 
00085   private:
00086     Script *myScript;
00087     QAction *actionExecute, *actionExecuteAll, *actionEval, *actionPrint, *actionImport, *actionExport;
00089     QMenu *functionsMenu;
00091     QTextCursor printCursor;
00092     QString scriptsDirPath;
00093 
00095     QTextBlockFormat d_fmt_default;
00097     QTextBlockFormat d_fmt_success;
00099     QTextBlockFormat d_fmt_failure;
00101     bool d_error;
00103     bool d_changing_fmt;
00104 
00105     QCompleter *d_completer;
00106 
00107   private slots:
00109 
00113     void insertErrorMsg(const QString &message);
00115     void handleContentsChange(int position, int chars_removed, int chars_added);
00116 
00117     void insertCompletion(const QString &completion);
00118 
00119   private:
00120     QString textUnderCursor() const;
00121 };
00122 
00123 #endif

Generated on Sun Jun 15 21:32:19 2008 for QtiPlot by  doxygen 1.5.6