Commit c286c360 authored by Jan Möbius's avatar Jan Möbius

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5223 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
#== SYSTEM PART -- DON'T TOUCH ==============================================
include $(ACGMAKE)/Config
#==============================================================================
SUBDIRS = $(call find-subdirs)
PACKAGES := qt4 glut glew opengl x11 math ACG2 openmesh2
PROJ_LIBS =
MODULES := uic4compat moc4 cxx
#== SYSTEM PART -- DON'T TOUCH ==============================================
include $(ACGMAKE)/Rules
#==============================================================================
#include "FunctionList.hh"
#include <iostream>
FunctionList::FunctionList(QWidget *parent)
: QListWidget(parent)
{
}
void FunctionList::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
dragStartPosition_ = event->pos();
QListWidgetItem* item = itemAt(event->pos().x(), event->pos().y());
if (item)
currentFn_ = item->text();
else
currentFn_ = "";
}
QListWidget::mousePressEvent(event);
}
void FunctionList::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - dragStartPosition_).manhattanLength()
< QApplication::startDragDistance())
return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setText( currentFn_ );
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
void FunctionList::filter(QString _filter){
for (int i=0; i < count(); i++){
QString fnName = item(i)->text();
QString slotDescription;
QStringList params;
QStringList descriptions;
emit getDescription(fnName, slotDescription, params, descriptions);
if ( fnName.contains(_filter) || slotDescription.contains(_filter) )
item(i)->setHidden(false);
else
item(i)->setHidden(true);
}
}
void FunctionList::reset(){
for (int i=0; i < count(); i++)
item(i)->setHidden(false);
}
\ No newline at end of file
#include <QtGui>
class FunctionList : public QListWidget
{
Q_OBJECT
signals:
void getDescription(QString _function, QString& _description,
QStringList& _parameters, QStringList& _descriptions);
private:
QPoint dragStartPosition_;
QString currentFn_;
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
public:
FunctionList(QWidget *parent = 0);
void filter(QString _filter);
void reset();
};
################################################################################
#
################################################################################
include( $$TOPDIR/qmake/all.include )
Plugin()
DIRECTORIES = .
# Input
HEADERS += $$getFilesFromDir($$DIRECTORIES,*.hh)
SOURCES += $$getFilesFromDir($$DIRECTORIES,*.cc)
FORMS += $$getFilesFromDir($$DIRECTORIES,*.ui)
################################################################################
This diff is collapsed.
#ifndef SCRIPTINGPLUGIN_HH
#define SCRIPTINGPLUGIN_HH
#include <QObject>
#include <QMenuBar>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include "highLighter.hh"
#include "scriptingWidget.hh"
class ScriptingPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface, RPCInterface, LoggingInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(MenuInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(RPCInterface)
Q_INTERFACES(LoggingInterface)
signals:
void updateView();
void getScriptingEngine( QScriptEngine*& _engine );
void getAvailableFunctions( QStringList& _functions );
void log(Logtype _type, QString _message);
void log(QString _message);
void addMenu(QMenu* _menu, MenuType _type);
void getDescription(QString _function, QString& _description,
QStringList& _parameters, QStringList& _descriptions);
private slots:
void slotScriptInfo( QString _pluginName , QString _functionName );
void slotExecuteScript( QString _script );
void slotExecuteFileScript( QString _filename );
void slotLoadScript();
void slotSaveScript();
void slotSaveScriptAs();
void pluginsInitialized();
void noguiSupported( ) {} ;
public :
ScriptingPlugin();
QString name() { return (QString("Scripting")); };
QString description( ) { return (QString("Provides Scripting for OpenFlipper")); };
private slots :
void slotExecuteScriptButton();
void slotEnableSave();
void slotFunctionClicked(QListWidgetItem* _item);
void slotFunctionDoubleClicked(QListWidgetItem* _item);
void slotApplyFilter();
private:
QList< QLabel* > descriptionLabels_;
QVBoxLayout* descrLayout_;
//===========================================================================
/** @name Gui control from script
* @{ */
//===========================================================================
public slots:
void showScriptWidget();
void hideScriptWidget();
/** @} */
//===========================================================================
/** @name Interrupt script execution
* @{ */
//===========================================================================
public slots:
/** Stops script execution and opens a message windows.
* Execution continues, when the user clicks on a button
*/
void waitContinue( );
/** Stops script execution and opens a message windows.
* Execution continues, when the user clicks on a button
* Also allowing the user to set a message
*/
void waitContinue( QString _msg, int _x=-1, int _y=-1);
/// Sleeps for some seconds in script execution ( Gui will remain functional)
void sleep( int _seconds );
/// Sleeps for some mseconds in script execution ( Gui will remain functional)
void sleepmsecs( int _mseconds );
/// Marks the current time as the frame start ( Use wait sleepFrameLength to wait until _mseconds have passed since frameStart )
void frameStart( );
/// wait until _mseconds have passed since frameStart (if more time has passed, it will return immediatly)
void waitFrameEnd( int _mseconds );
/** @} */
private :
QString mangleScript( QString _input );
/// Counts mseconds since a frame start has occured
QTime frameTime_;
private :
ScriptWidget* scriptWidget_;
Highlighter* highlighterCurrent_;
Highlighter* highlighterLive_;
Highlighter* highlighterList_;
QString lastFile_;
public slots:
QString version() { return QString("1.0"); };
};
#endif //SCRIPTINGPLUGIN_HH
This diff is collapsed.
#include <QtGui>
#include "highLighter.hh"
Highlighter::Highlighter(QTextEdit *parent)
: QSyntaxHighlighter(parent)
{
// Set the basic format styles
keywordFormat_.setForeground(Qt::darkGreen);
keywordFormat_.setFontWeight(QFont::Bold);
pluginFormat_.setForeground(Qt::darkBlue);
pluginFormat_.setFontWeight(QFont::Bold);
functionFormat_.setForeground(Qt::darkYellow);
functionFormat_.setFontWeight(QFont::Bold);
typeFormat_.setForeground(Qt::darkMagenta);
typeFormat_.setFontWeight(QFont::Bold);
quotationFormat_.setForeground(Qt::darkRed);
listFormat_.setForeground(Qt::darkRed);
singleLineCommentFormat_.setForeground(Qt::red);
multiLineCommentFormat_.setForeground(Qt::red);
commentStartExpression_ = QRegExp("/\\*");
commentEndExpression_ = QRegExp("\\*/");
// Define basic keywords
keywordPatterns_ << "while" << "for" << "print" << "var";
// Types which are accepted by the scripting system
typePatterns_ << "int" << "Matrix4x4" << "QString" << "idList" << "bool" << "Vector" << "double";
update();
// classFormat.setFontWeight(QFont::Bold);
// classFormat.setForeground(Qt::darkMagenta);
// rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
// rule.format = classFormat;
// highlightingRules.append(rule);
//
// functionFormat.setFontItalic(true);
// functionFormat.setForeground(Qt::blue);
// rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
// rule.format = functionFormat;
// highlightingRules.append(rule);
//
}
void Highlighter::update() {
highlightingRules_.clear();
HighlightingRule rule;
// Create Rules for keywords
foreach (QString pattern, keywordPatterns_) {
rule.pattern = QRegExp("\\b" + pattern + "\\b" );
rule.format = keywordFormat_;
highlightingRules_.append(rule);
}
// Create Rules for plugins
foreach (QString pattern, pluginPatterns_ ) {
rule.pattern = QRegExp("\\b" + pattern + "\\b" );
rule.format = pluginFormat_;
highlightingRules_.append(rule);
}
// Create Rules for functions
foreach (QString pattern, functionPatterns_ ) {
rule.pattern = QRegExp("\\b" + pattern + "\\b" );
rule.format = functionFormat_;
highlightingRules_.append(rule);
}
// Create Rules for types
foreach (QString pattern, typePatterns_ ) {
rule.pattern = QRegExp("\\b" + pattern + "\\b" );
rule.format = typeFormat_;
highlightingRules_.append(rule);
}
// Rule for single line comments
rule.pattern = QRegExp("//[^\n]*");
rule.format = singleLineCommentFormat_;
highlightingRules_.append(rule);
// Rules for quotations
rule.pattern = QRegExp("\".*\"");
rule.format = quotationFormat_;
highlightingRules_.append(rule);
// Rules for Lists
rule.pattern = QRegExp("\\[.*\\]");
rule.format = listFormat_;
highlightingRules_.append(rule);
}
void Highlighter::highlightBlock(const QString &text)
{
foreach (HighlightingRule rule, highlightingRules_) {
QRegExp expression(rule.pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = text.indexOf(expression, index + length);
}
}
setCurrentBlockState(0);
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = text.indexOf(commentStartExpression_);
while (startIndex >= 0) {
int endIndex = text.indexOf(commentEndExpression_, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + commentEndExpression_.matchedLength();
}
setFormat(startIndex, commentLength, multiLineCommentFormat_);
startIndex = text.indexOf(commentStartExpression_, startIndex + commentLength);
}
}
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QHash>
#include <QTextCharFormat>
class QTextDocument;
class Highlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
Highlighter(QTextEdit *parent = 0);
// Updates the highlighter with the current rule set defined in the patterns
void update();
QStringList keywordPatterns_;
QStringList pluginPatterns_;
QStringList functionPatterns_;
QStringList typePatterns_;
protected:
void highlightBlock(const QString &text);
private:
struct HighlightingRule
{
QRegExp pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules_;
QRegExp commentStartExpression_;
QRegExp commentEndExpression_;
QTextCharFormat keywordFormat_;
QTextCharFormat pluginFormat_;
QTextCharFormat functionFormat_;
QTextCharFormat typeFormat_;
// QTextCharFormat classFormat;
QTextCharFormat singleLineCommentFormat_;
QTextCharFormat multiLineCommentFormat_;
QTextCharFormat quotationFormat_;
QTextCharFormat listFormat_;
// QTextCharFormat functionFormat;
};
#endif
#include "scriptingWidget.hh"
#include <QtGui>
ScriptWidget::ScriptWidget(QWidget *parent)
: QMainWindow(parent)
{
setupUi(this);
}
#include "ui_scriptingWidget.hh"
#include <QtGui>
class ScriptWidget : public QMainWindow, public Ui::ScriptWidget
{
Q_OBJECT
public:
ScriptWidget(QWidget *parent = 0);
};
<ui version="4.0" >
<class>ScriptWidget</class>
<widget class="QMainWindow" name="ScriptWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>895</width>
<height>969</height>
</rect>
</property>
<property name="windowTitle" >
<string>Script Editor</string>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QHBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Current Script</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QTextEdit" name="currentScript" >
<property name="enabled" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="executeButton" >
<property name="text" >
<string>Execute</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="currentIndex" >
<number>1</number>
</property>
<widget class="QWidget" name="tab" >
<attribute name="title" >
<string>Live View</string>
</attribute>
<layout class="QVBoxLayout" >
<item>
<widget class="QTextEdit" name="liveEdit" >
<property name="readOnly" >
<bool>true</bool>
</property>
<property name="textInteractionFlags" >
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2" >
<attribute name="title" >
<string>Function List</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QGroupBox" name="groupBox_2" >
<property name="title" >
<string>Filter</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLineEdit" name="filterEdit" />
</item>
<item>
<widget class="QPushButton" name="filterButton" >
<property name="text" >
<string>Filter</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resetButton" >
<property name="text" >
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="FunctionList" name="functionList" >
<property name="dragEnabled" >
<bool>true</bool>
</property>
<property name="dragDropMode" >
<enum>QAbstractItemView::DragOnly</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="description" >
<property name="title" >
<string> Description </string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>895</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile" >
<property name="title" >
<string>File</string>
</property>
<addaction name="actionLoad_Script" />
<addaction name="separator" />
<addaction name="actionSave_Script" />
<addaction name="actionSave_Script_As" />
<addaction name="separator" />
<addaction name="actionClose" />
</widget>
<addaction name="menuFile" />
</widget>
<widget class="QStatusBar" name="statusbar" />
<action name="actionScan_Directory" >
<property name="text" >
<string>Scan Directory</string>
</property>
</action>
<action name="actionCheck_Database" >
<property name="text" >
<string>Check Database</string>
</property>
</action>
<action name="actionLoad_Script" >
<property name="text" >
<string>Open</string>
</property>
</action>
<action name="actionSave_Script" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Save</string>
</property>
</action>
<action name="actionClose" >
<property name="text" >
<string>Close</string>
</property>
</action>
<action name="actionSave_Script_As" >
<property name="text" >
<string>Save As</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>