Developer Documentation
ScriptingPlugin.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #ifndef SCRIPTINGPLUGIN_HH
45 #define SCRIPTINGPLUGIN_HH
46 
47 
53 
54 // Include the scripttools for qt script debugging if available
55 #ifdef QT_SCRIPTTOOLS_LIB
56  #include <QtScriptTools/QScriptEngineDebugger>
57 #endif
58 
59 #include "widgets/highLighter.hh"
60 #include "widgets/scriptingWidget.hh"
61 
62 #include <QObject>
63 #include <QMenuBar>
64 
66 {
67 Q_OBJECT
68 Q_INTERFACES(BaseInterface)
69 Q_INTERFACES(MenuInterface)
70 Q_INTERFACES(ScriptInterface)
71 Q_INTERFACES(RPCInterface)
72 Q_INTERFACES(LoggingInterface)
73 
74  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Scripting")
75 
76 signals:
77  void updateView();
78 
79  void getScriptingEngine( QScriptEngine*& _engine );
80  void getAvailableFunctions( QStringList& _functions );
81 
82  void log(Logtype _type, QString _message);
83  void log(QString _message);
84 
85  void getMenubarMenu (QString _name, QMenu *& _menu, bool _create);
86 
87  void getDescription(QString _function, QString& _description,
88  QStringList& _parameters, QStringList& _descriptions);
89 
90 private slots:
91 
92  void slotScriptInfo( QString _pluginName , QString _functionName );
93  void slotExecuteScript( QString _script );
94  void slotExecuteFileScript( QString _filename );
95 
96  void slotLoadScript();
97  void slotSaveScript();
98  void slotSaveScriptAs();
99  void pluginsInitialized();
100 
101  void noguiSupported( ) {} ;
102 
103 public :
104 
105  ScriptingPlugin();
106 
107  QString name() { return (QString(tr("Scripting"))); };
108  QString description( ) { return (QString(tr("Provides Scripting for OpenFlipper"))); };
109 
110 private slots :
111 
112  void slotExecuteScriptButton();
113 
118  void slotScriptChanged();
119 
120  void slotFunctionClicked(QListWidgetItem* _item);
121  void slotFunctionDoubleClicked(QListWidgetItem* _item);
122 
123  void slotApplyFilter();
124 
126  void slotHighlightError();
127 
129  void slotDebuggerButton();
130 
131 private:
132 
135 
137  QString lastError_;
138 
140  QTimer* errorTimer_;
141 
142  QList< QLabel* > descriptionLabels_;
143  QVBoxLayout* descrLayout_;
144 
145 //===========================================================================
148 //===========================================================================
149 
150 public slots:
151 
155  void showScriptWidget();
156 
160  void hideScriptWidget();
161 
166  void showScriptInEditor (QString _code);
167 
174  void slotLoadScript( QString _filename );
175 
179  void clearEditor();
180 
183 //===========================================================================
186 //===========================================================================
187 
188 public slots:
189 
193  void waitContinue( );
194 
199  void waitContinue( QString _msg, int _x=-1, int _y=-1);
200 
201 
203  void sleep( int _seconds );
204 
206  void sleepmsecs( int _mseconds );
207 
209  void frameStart( );
210 
212  void waitFrameEnd( int _mseconds );
213 
217 private :
218  QString mangleScript( QString _input );
219 
221  QElapsedTimer frameTime_;
222 
223 private :
224  ScriptWidget* scriptWidget_;
225 
226  QStatusBar* statusBar_;
227 
228  Highlighter* highlighterCurrent_;
229  Highlighter* highlighterLive_;
230  Highlighter* highlighterList_;
231 
232  QString lastFile_;
233 
237  QString scriptPath_;
238 
239  QAction* debuggerButton_;
240 
241 #ifdef ENABLE_SCRIPT_DEBUGGER
242  #ifdef QT_SCRIPTTOOLS_LIB
243  QScriptEngineDebugger* debugger_;
244  #endif
245 #endif
246 
247 
248 
249 public slots:
250  QString version() { return QString("1.0"); };
251 };
252 
253 #endif //SCRIPTINGPLUGIN_HH
254 
void hideScriptWidget()
Hide the script editor widget.
QString name()
Return a name for the plugin.
Interface for all plugins which provide entries to the main menubar.
void slotHighlightError()
Called when an error is detected when checking the syntax.
Logtype
Log types for Message Window.
void showScriptWidget()
Show the script editor widget.
void sleepmsecs(int _mseconds)
Sleeps for some mseconds in script execution ( Gui will remain functional)
int lastProblemLine_
Store the last line that contained an error.
Interface for all Plugins which do logging to the logging window of the framework.
void clearEditor()
Clear the editor window Clears the script editor window.
void waitFrameEnd(int _mseconds)
wait until _mseconds have passed since frameStart (if more time has passed, it will return immediatel...
void slotDebuggerButton()
Triggered by the debugger button.
void sleep(int _seconds)
Sleeps for some seconds in script execution ( Gui will remain functional)
Interface to call functions across plugins.
Definition: RPCInterface.hh:61
void frameStart()
Marks the current time as the frame start ( Use wait sleepFrameLength to wait until _mseconds have pa...
QElapsedTimer frameTime_
Counts mseconds since a frame start has occured.
QTimer * errorTimer_
Timer to wait until the user stopped typing before showing an error.
QString lastError_
Store the last error message.
QString description()
Return a description of what the plugin is doing.
Interface for all Plugins which provide scriptable Functions.
void showScriptInEditor(QString _code)
Show the given Code in the script editor.
void slotExecuteScript(QString _script)
Interface class from which all plugins have to be created.
void slotScriptChanged()
Called everytime the text in the scriptingwidget is changed by the user.