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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef SCRIPTINGPLUGIN_HH
51 #define SCRIPTINGPLUGIN_HH
52 
53 #include <QObject>
54 #include <QMenuBar>
55 
62 
63 // Include the scripttools for qt script debugging if available
64 #ifdef QT_SCRIPTTOOLS_LIB
65  #include <QtScriptTools/QScriptEngineDebugger>
66 #endif
67 
68 #include "highLighter.hh"
69 #include "scriptingWidget.hh"
70 
71 
72 
74 {
75 Q_OBJECT
76 Q_INTERFACES(BaseInterface)
77 Q_INTERFACES(MenuInterface)
78 Q_INTERFACES(ScriptInterface)
79 Q_INTERFACES(RPCInterface)
80 Q_INTERFACES(LoggingInterface)
81 
82 #if QT_VERSION >= 0x050000
83  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Scripting")
84 #endif
85 
86 signals:
87  void updateView();
88 
89  void getScriptingEngine( QScriptEngine*& _engine );
90  void getAvailableFunctions( QStringList& _functions );
91 
92  void log(Logtype _type, QString _message);
93  void log(QString _message);
94 
95  void getMenubarMenu (QString _name, QMenu *& _menu, bool _create);
96 
97  void getDescription(QString _function, QString& _description,
98  QStringList& _parameters, QStringList& _descriptions);
99 
100 private slots:
101 
102  void slotScriptInfo( QString _pluginName , QString _functionName );
103  void slotExecuteScript( QString _script );
104  void slotExecuteFileScript( QString _filename );
105 
106  void slotLoadScript();
107  void slotSaveScript();
108  void slotSaveScriptAs();
109  void pluginsInitialized();
110 
111  void noguiSupported( ) {} ;
112 
113 public :
114 
115  ScriptingPlugin();
116 
117  QString name() { return (QString(tr("Scripting"))); };
118  QString description( ) { return (QString(tr("Provides Scripting for OpenFlipper"))); };
119 
120 private slots :
121 
122  void slotExecuteScriptButton();
123 
128  void slotScriptChanged();
129 
130  void slotFunctionClicked(QListWidgetItem* _item);
131  void slotFunctionDoubleClicked(QListWidgetItem* _item);
132 
133  void slotApplyFilter();
134 
136  void slotHighlightError();
137 
139  void slotDebuggerButton();
140 
141 private:
142 
145 
147  QString lastError_;
148 
150  QTimer* errorTimer_;
151 
152  QList< QLabel* > descriptionLabels_;
153  QVBoxLayout* descrLayout_;
154 
155 //===========================================================================
158 //===========================================================================
159 
160 public slots:
161 
165  void showScriptWidget();
166 
170  void hideScriptWidget();
171 
176  void showScriptInEditor (QString _code);
177 
184  void slotLoadScript( QString _filename );
185 
189  void clearEditor();
190 
193 //===========================================================================
196 //===========================================================================
197 
198 public slots:
199 
203  void waitContinue( );
204 
209  void waitContinue( QString _msg, int _x=-1, int _y=-1);
210 
211 
213  void sleep( int _seconds );
214 
216  void sleepmsecs( int _mseconds );
217 
219  void frameStart( );
220 
222  void waitFrameEnd( int _mseconds );
223 
227 private :
228  QString mangleScript( QString _input );
229 
231  QTime frameTime_;
232 
233 private :
234  ScriptWidget* scriptWidget_;
235 
236  QStatusBar* statusBar_;
237 
238  Highlighter* highlighterCurrent_;
239  Highlighter* highlighterLive_;
240  Highlighter* highlighterList_;
241 
242  QString lastFile_;
243 
247  QString scriptPath_;
248 
249  QAction* debuggerButton_;
250 
251 #ifdef ENABLE_SCRIPT_DEBUGGER
252  #ifdef QT_SCRIPTTOOLS_LIB
253  QScriptEngineDebugger* debugger_;
254  #endif
255 #endif
256 
257 
258 
259 public slots:
260  QString version() { return QString("1.0"); };
261 };
262 
263 #endif //SCRIPTINGPLUGIN_HH
264 
QTime frameTime_
Counts mseconds since a frame start has occured.
void hideScriptWidget()
Hide the script editor widget.
void frameStart()
Marks the current time as the frame start ( Use wait sleepFrameLength to wait until _mseconds have pa...
Logtype
Log types for Message Window.
Interface for all Plugins which provide scriptable Functions.
Interface class from which all plugins have to be created.
void slotHighlightError()
Called when an error is detected when checking the syntax.
void showScriptInEditor(QString _code)
Show the given Code in the script editor.
Interface for all Plugins which do logging to the logging window of the framework.
void sleepmsecs(int _mseconds)
Sleeps for some mseconds in script execution ( Gui will remain functional)
QTimer * errorTimer_
Timer to wait until the user stopped typing before showing an error.
int lastProblemLine_
Store the last line that contained an error.
void showScriptWidget()
Show the script editor widget.
Interface for all plugins which provide entries to the main menubar.
void slotScriptChanged()
Called everytime the text in the scriptingwidget is changed by the user.
QString name()
Return a name for the plugin.
void sleep(int _seconds)
Sleeps for some seconds in script execution ( Gui will remain functional)
void clearEditor()
Clear the editor window Clears the script editor window.
void slotDebuggerButton()
Triggered by the debugger button.
void slotExecuteScript(QString _script)
QString lastError_
Store the last error message.
QString description()
Return a description of what the plugin is doing.
Interface to call functions across plugins.
Definition: RPCInterface.hh:71
void waitFrameEnd(int _mseconds)
wait until _mseconds have passed since frameStart (if more time has passed, it will return immediatel...