mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Style
This commit is contained in:
parent
0e28ff2fcd
commit
c1ed38f4de
6 changed files with 147 additions and 131 deletions
|
@ -15,16 +15,16 @@
|
|||
ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) :
|
||||
QSyntaxHighlighter(parent)
|
||||
{
|
||||
keywordRegex = QRegExp("\\b(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)\\b");
|
||||
qoutedTextRegex = QRegExp("\".*\"");
|
||||
multiLineCommentBegin = QRegExp("/\\*");
|
||||
multiLineCommentEnd = QRegExp("\\*/");
|
||||
numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
|
||||
singleLineComment = QRegExp("//[^\n]*");
|
||||
truefalseRegex = QRegExp("\\b(true|false)\\b");
|
||||
_keywordRegex = QRegExp("\\b(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)\\b");
|
||||
_qoutedTextRegex = QRegExp("\".*\"");
|
||||
_multiLineCommentBegin = QRegExp("/\\*");
|
||||
_multiLineCommentEnd = QRegExp("\\*/");
|
||||
_numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
|
||||
_singleLineComment = QRegExp("//[^\n]*");
|
||||
_truefalseRegex = QRegExp("\\b(true|false)\\b");
|
||||
}
|
||||
|
||||
void ScriptHighlighting::highlightBlock(const QString &text) {
|
||||
void ScriptHighlighting::highlightBlock(const QString& text) {
|
||||
this->highlightKeywords(text);
|
||||
this->formatNumbers(text);
|
||||
this->formatTrueFalse(text);
|
||||
|
@ -32,62 +32,64 @@ void ScriptHighlighting::highlightBlock(const QString &text) {
|
|||
this->formatComments(text);
|
||||
}
|
||||
|
||||
void ScriptHighlighting::highlightKeywords(const QString &text) {
|
||||
int index = keywordRegex.indexIn(text);
|
||||
void ScriptHighlighting::highlightKeywords(const QString& text) {
|
||||
int index = _keywordRegex.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = keywordRegex.matchedLength();
|
||||
int length = _keywordRegex.matchedLength();
|
||||
setFormat(index, length, Qt::blue);
|
||||
index = keywordRegex.indexIn(text, index + length);
|
||||
index = _keywordRegex.indexIn(text, index + length);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptHighlighting::formatComments(const QString &text) {
|
||||
void ScriptHighlighting::formatComments(const QString& text) {
|
||||
|
||||
setCurrentBlockState(BlockStateClean);
|
||||
|
||||
int start = (previousBlockState() != BlockStateInMultiComment) ? text.indexOf(multiLineCommentBegin) : 0;
|
||||
int start = (previousBlockState() != BlockStateInMultiComment) ? text.indexOf(_multiLineCommentBegin) : 0;
|
||||
|
||||
while (start > -1) {
|
||||
int end = text.indexOf(multiLineCommentEnd, start);
|
||||
int length = (end == -1 ? text.length() : (end + multiLineCommentEnd.matchedLength())) - start;
|
||||
int end = text.indexOf(_multiLineCommentEnd, start);
|
||||
int length = (end == -1 ? text.length() : (end + _multiLineCommentEnd.matchedLength())) - start;
|
||||
setFormat(start, length, Qt::lightGray);
|
||||
start = text.indexOf(multiLineCommentBegin, start + length);
|
||||
if (end == -1) setCurrentBlockState(BlockStateInMultiComment);
|
||||
start = text.indexOf(_multiLineCommentBegin, start + length);
|
||||
if (end == -1) {
|
||||
setCurrentBlockState(BlockStateInMultiComment);
|
||||
}
|
||||
}
|
||||
|
||||
int index = singleLineComment.indexIn(text);
|
||||
int index = _singleLineComment.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = singleLineComment.matchedLength();
|
||||
int length = _singleLineComment.matchedLength();
|
||||
setFormat(index, length, Qt::lightGray);
|
||||
index = singleLineComment.indexIn(text, index + length);
|
||||
index = _singleLineComment.indexIn(text, index + length);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptHighlighting::formatQoutedText(const QString &text){
|
||||
int index = qoutedTextRegex.indexIn(text);
|
||||
void ScriptHighlighting::formatQoutedText(const QString& text){
|
||||
int index = _qoutedTextRegex.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = qoutedTextRegex.matchedLength();
|
||||
int length = _qoutedTextRegex.matchedLength();
|
||||
setFormat(index, length, Qt::red);
|
||||
index = qoutedTextRegex.indexIn(text, index + length);
|
||||
index = _qoutedTextRegex.indexIn(text, index + length);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptHighlighting::formatNumbers(const QString &text){
|
||||
int index = numberRegex.indexIn(text);
|
||||
void ScriptHighlighting::formatNumbers(const QString& text){
|
||||
int index = _numberRegex.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = numberRegex.matchedLength();
|
||||
int length = _numberRegex.matchedLength();
|
||||
setFormat(index, length, Qt::green);
|
||||
index = numberRegex.indexIn(text, index + length);
|
||||
index = _numberRegex.indexIn(text, index + length);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptHighlighting::formatTrueFalse(const QString text){
|
||||
int index = truefalseRegex.indexIn(text);
|
||||
void ScriptHighlighting::formatTrueFalse(const QString& text){
|
||||
int index = _truefalseRegex.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = truefalseRegex.matchedLength();
|
||||
int length = _truefalseRegex.matchedLength();
|
||||
QFont* font = new QFont(this->document()->defaultFont());
|
||||
font->setBold(true);
|
||||
setFormat(index, length, *font);
|
||||
index = truefalseRegex.indexIn(text, index + length);
|
||||
index = _truefalseRegex.indexIn(text, index + length);
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ class ScriptHighlighting : public QSyntaxHighlighter {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScriptHighlighting(QTextDocument* parent = 0);
|
||||
ScriptHighlighting(QTextDocument* parent = NULL);
|
||||
|
||||
enum BlockState {
|
||||
BlockStateClean,
|
||||
|
@ -31,16 +31,16 @@ protected:
|
|||
void formatComments(const QString& text);
|
||||
void formatQoutedText(const QString& text);
|
||||
void formatNumbers(const QString& text);
|
||||
void formatTrueFalse(const QString text);
|
||||
void formatTrueFalse(const QString& text);
|
||||
|
||||
private:
|
||||
QRegExp keywordRegex;
|
||||
QRegExp qoutedTextRegex;
|
||||
QRegExp multiLineCommentBegin;
|
||||
QRegExp multiLineCommentEnd;
|
||||
QRegExp numberRegex;
|
||||
QRegExp singleLineComment;
|
||||
QRegExp truefalseRegex;
|
||||
QRegExp _keywordRegex;
|
||||
QRegExp _qoutedTextRegex;
|
||||
QRegExp _multiLineCommentBegin;
|
||||
QRegExp _multiLineCommentEnd;
|
||||
QRegExp _numberRegex;
|
||||
QRegExp _singleLineComment;
|
||||
QRegExp _truefalseRegex;
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptHighlighting_h
|
||||
|
|
|
@ -27,40 +27,39 @@
|
|||
#include "ScriptHighlighting.h"
|
||||
|
||||
ScriptEditorWidget::ScriptEditorWidget() :
|
||||
ui(new Ui::ScriptEditorWidget)
|
||||
_scriptEditorWidgetUI(new Ui::ScriptEditorWidget),
|
||||
_scriptEngine(NULL)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
_scriptEditorWidgetUI->setupUi(this);
|
||||
|
||||
scriptEngine = NULL;
|
||||
|
||||
connect(ui->scriptEdit->document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(scriptModified()));
|
||||
connect(ui->scriptEdit->document(), SIGNAL(contentsChanged()), this, SLOT(onScriptModified()));
|
||||
connect(_scriptEditorWidgetUI->scriptEdit->document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(scriptModified()));
|
||||
connect(_scriptEditorWidgetUI->scriptEdit->document(), SIGNAL(contentsChanged()), this, SLOT(onScriptModified()));
|
||||
|
||||
// remove the title bar (see the Qt docs on setTitleBarWidget)
|
||||
setTitleBarWidget(new QWidget());
|
||||
QFontMetrics fm(this->ui->scriptEdit->font());
|
||||
this->ui->scriptEdit->setTabStopWidth(fm.width('0') * 4);
|
||||
ScriptHighlighting* highlighting = new ScriptHighlighting(this->ui->scriptEdit->document());
|
||||
QTimer::singleShot(0, this->ui->scriptEdit, SLOT(setFocus()));
|
||||
QFontMetrics fm(_scriptEditorWidgetUI->scriptEdit->font());
|
||||
_scriptEditorWidgetUI->scriptEdit->setTabStopWidth(fm.width('0') * 4);
|
||||
ScriptHighlighting* highlighting = new ScriptHighlighting(_scriptEditorWidgetUI->scriptEdit->document());
|
||||
QTimer::singleShot(0, _scriptEditorWidgetUI->scriptEdit, SLOT(setFocus()));
|
||||
}
|
||||
|
||||
ScriptEditorWidget::~ScriptEditorWidget() {
|
||||
delete ui;
|
||||
delete _scriptEditorWidgetUI;
|
||||
}
|
||||
|
||||
void ScriptEditorWidget::onScriptModified() {
|
||||
if(ui->onTheFlyCheckBox->isChecked() && isRunning()) {
|
||||
if(_scriptEditorWidgetUI->onTheFlyCheckBox->isChecked() && isRunning()) {
|
||||
setRunning(false);
|
||||
setRunning(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptEditorWidget::isModified() {
|
||||
return ui->scriptEdit->document()->isModified();
|
||||
return _scriptEditorWidgetUI->scriptEdit->document()->isModified();
|
||||
}
|
||||
|
||||
bool ScriptEditorWidget::isRunning() {
|
||||
return (scriptEngine != NULL) ? scriptEngine->isRunning() : false;
|
||||
return (_scriptEngine != NULL) ? _scriptEngine->isRunning() : false;
|
||||
}
|
||||
|
||||
bool ScriptEditorWidget::setRunning(bool run) {
|
||||
|
@ -72,15 +71,15 @@ bool ScriptEditorWidget::setRunning(bool run) {
|
|||
disconnect(this, SLOT(onScriptPrint(const QString&)));
|
||||
|
||||
if (run) {
|
||||
scriptEngine = Application::getInstance()->loadScript(this->currentScript, false);
|
||||
connect(scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged()));
|
||||
_scriptEngine = Application::getInstance()->loadScript(_currentScript, false);
|
||||
connect(_scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged()));
|
||||
|
||||
// Make new connections.
|
||||
connect(scriptEngine, SIGNAL(errorMessage(const QString&)), this, SLOT(onScriptError(const QString&)));
|
||||
connect(scriptEngine, SIGNAL(printedMessage(const QString&)), this, SLOT(onScriptPrint(const QString&)));
|
||||
connect(_scriptEngine, SIGNAL(errorMessage(const QString&)), this, SLOT(onScriptError(const QString&)));
|
||||
connect(_scriptEngine, SIGNAL(printedMessage(const QString&)), this, SLOT(onScriptPrint(const QString&)));
|
||||
} else {
|
||||
Application::getInstance()->stopScript(this->currentScript);
|
||||
scriptEngine = NULL;
|
||||
Application::getInstance()->stopScript(_currentScript);
|
||||
_scriptEngine = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -88,18 +87,19 @@ bool ScriptEditorWidget::setRunning(bool run) {
|
|||
bool ScriptEditorWidget::saveFile(const QString &scriptPath) {
|
||||
QFile file(scriptPath);
|
||||
if (!file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, tr("Interface"), tr("Cannot write script %1:\n%2.").arg(scriptPath).arg(file.errorString()));
|
||||
QMessageBox::warning(this, tr("Interface"), tr("Cannot write script %1:\n%2.").arg(scriptPath)
|
||||
.arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out << ui->scriptEdit->toPlainText();
|
||||
out << _scriptEditorWidgetUI->scriptEdit->toPlainText();
|
||||
|
||||
setScriptFile(scriptPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptEditorWidget::loadFile(const QString &scriptPath) {
|
||||
void ScriptEditorWidget::loadFile(const QString& scriptPath) {
|
||||
QFile file(scriptPath);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, tr("Interface"), tr("Cannot read script %1:\n%2.").arg(scriptPath).arg(file.errorString()));
|
||||
|
@ -107,23 +107,23 @@ void ScriptEditorWidget::loadFile(const QString &scriptPath) {
|
|||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
ui->scriptEdit->setPlainText(in.readAll());
|
||||
_scriptEditorWidgetUI->scriptEdit->setPlainText(in.readAll());
|
||||
|
||||
setScriptFile(scriptPath);
|
||||
|
||||
disconnect(this, SLOT(onScriptError(const QString&)));
|
||||
disconnect(this, SLOT(onScriptPrint(const QString&)));
|
||||
|
||||
scriptEngine = Application::getInstance()->getScriptEngine(scriptPath);
|
||||
if (scriptEngine != NULL) {
|
||||
connect(scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged()));
|
||||
connect(scriptEngine, SIGNAL(errorMessage(const QString&)), this, SLOT(onScriptError(const QString&)));
|
||||
connect(scriptEngine, SIGNAL(printedMessage(const QString&)), this, SLOT(onScriptPrint(const QString&)));
|
||||
_scriptEngine = Application::getInstance()->getScriptEngine(scriptPath);
|
||||
if (_scriptEngine != NULL) {
|
||||
connect(_scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged()));
|
||||
connect(_scriptEngine, SIGNAL(errorMessage(const QString&)), this, SLOT(onScriptError(const QString&)));
|
||||
connect(_scriptEngine, SIGNAL(printedMessage(const QString&)), this, SLOT(onScriptPrint(const QString&)));
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptEditorWidget::save() {
|
||||
return currentScript.isEmpty() ? saveAs() : saveFile(currentScript);
|
||||
return _currentScript.isEmpty() ? saveAs() : saveFile(_currentScript);
|
||||
}
|
||||
|
||||
bool ScriptEditorWidget::saveAs() {
|
||||
|
@ -132,25 +132,27 @@ bool ScriptEditorWidget::saveAs() {
|
|||
}
|
||||
|
||||
void ScriptEditorWidget::setScriptFile(const QString& scriptPath) {
|
||||
currentScript = scriptPath;
|
||||
ui->scriptEdit->document()->setModified(false);
|
||||
_currentScript = scriptPath;
|
||||
_scriptEditorWidgetUI->scriptEdit->document()->setModified(false);
|
||||
setWindowModified(false);
|
||||
|
||||
emit scriptnameChanged();
|
||||
}
|
||||
|
||||
bool ScriptEditorWidget::questionSave() {
|
||||
if (ui->scriptEdit->document()->isModified()) {
|
||||
QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Interface"), tr("The script has been modified.\nDo you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
|
||||
if (_scriptEditorWidgetUI->scriptEdit->document()->isModified()) {
|
||||
QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Interface"),
|
||||
tr("The script has been modified.\nDo you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard |
|
||||
QMessageBox::Cancel, QMessageBox::Save);
|
||||
return button == QMessageBox::Save ? save() : (button == QMessageBox::Cancel ? false : true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptEditorWidget::onScriptError(const QString& message) {
|
||||
ui->debugText->appendPlainText("ERROR: "+ message);
|
||||
_scriptEditorWidgetUI->debugText->appendPlainText("ERROR: " + message);
|
||||
}
|
||||
|
||||
void ScriptEditorWidget::onScriptPrint(const QString& message) {
|
||||
ui->debugText->appendPlainText("> "+message);
|
||||
_scriptEditorWidgetUI->debugText->appendPlainText("> " + message);
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
#include "ScriptEngine.h"
|
||||
|
||||
namespace Ui {
|
||||
class ScriptEditorWidget;
|
||||
class ScriptEditorWidget;
|
||||
}
|
||||
|
||||
class ScriptEditorWidget : public QDockWidget {
|
||||
|
@ -36,7 +36,8 @@ public:
|
|||
bool save();
|
||||
bool saveAs();
|
||||
bool questionSave();
|
||||
const QString getScriptName() const { return currentScript; };
|
||||
const QString getScriptName() const { return _currentScript; };
|
||||
|
||||
signals:
|
||||
void runningStateChanged();
|
||||
void scriptnameChanged();
|
||||
|
@ -48,9 +49,9 @@ private slots:
|
|||
void onScriptModified();
|
||||
|
||||
private:
|
||||
Ui::ScriptEditorWidget* ui;
|
||||
ScriptEngine* scriptEngine;
|
||||
QString currentScript;
|
||||
Ui::ScriptEditorWidget* _scriptEditorWidgetUI;
|
||||
ScriptEngine* _scriptEngine;
|
||||
QString _currentScript;
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptEditorWidget_h
|
||||
|
|
|
@ -29,19 +29,19 @@
|
|||
#include "FlowLayout.h"
|
||||
|
||||
ScriptEditorWindow::ScriptEditorWindow() :
|
||||
ui(new Ui::ScriptEditorWindow)
|
||||
_ScriptEditorWindowUI(new Ui::ScriptEditorWindow),
|
||||
_loadMenu(new QMenu),
|
||||
_saveMenu(new QMenu)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
_ScriptEditorWindowUI->setupUi(this);
|
||||
show();
|
||||
addScriptEditorWidget("New script");
|
||||
loadMenu = new QMenu();
|
||||
connect(loadMenu, SIGNAL(aboutToShow()), this, SLOT(loadMenuAboutToShow()));
|
||||
ui->loadButton->setMenu(loadMenu);
|
||||
connect(_loadMenu, SIGNAL(aboutToShow()), this, SLOT(loadMenuAboutToShow()));
|
||||
_ScriptEditorWindowUI->loadButton->setMenu(_loadMenu);
|
||||
|
||||
saveMenu = new QMenu();
|
||||
saveMenu->addAction("Save as..", this, SLOT(saveScriptAsClicked()), Qt::CTRL|Qt::SHIFT|Qt::Key_S);
|
||||
_saveMenu->addAction("Save as..", this, SLOT(saveScriptAsClicked()), Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
|
||||
ui->saveButton->setMenu(saveMenu);
|
||||
_ScriptEditorWindowUI->saveButton->setMenu(_saveMenu);
|
||||
|
||||
connect(new QShortcut(QKeySequence("Ctrl+N"), this), SIGNAL(activated()), this, SLOT(newScriptClicked()));
|
||||
connect(new QShortcut(QKeySequence("Ctrl+S"), this), SIGNAL(activated()), this, SLOT(saveScriptClicked()));
|
||||
|
@ -50,19 +50,21 @@ ScriptEditorWindow::ScriptEditorWindow() :
|
|||
}
|
||||
|
||||
ScriptEditorWindow::~ScriptEditorWindow() {
|
||||
delete ui;
|
||||
delete _ScriptEditorWindowUI;
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::setRunningState(bool run) {
|
||||
if (ui->tabWidget->currentIndex() != -1) {
|
||||
((ScriptEditorWidget*)ui->tabWidget->currentWidget())->setRunning(run);
|
||||
if (_ScriptEditorWindowUI->tabWidget->currentIndex() != -1) {
|
||||
static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->currentWidget())->setRunning(run);
|
||||
}
|
||||
this->updateButtons();
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::updateButtons() {
|
||||
ui->toggleRunButton->setEnabled(ui->tabWidget->currentIndex() != -1);
|
||||
ui->toggleRunButton->setIcon(ui->tabWidget->currentIndex() != -1 && ((ScriptEditorWidget*)ui->tabWidget->currentWidget())->isRunning() ? QIcon("../resources/icons/stop-script.svg"):QIcon("../resources/icons/start-script.svg"));
|
||||
_ScriptEditorWindowUI->toggleRunButton->setEnabled(_ScriptEditorWindowUI->tabWidget->currentIndex() != -1);
|
||||
_ScriptEditorWindowUI->toggleRunButton->setIcon(_ScriptEditorWindowUI->tabWidget->currentIndex() != -1 &&
|
||||
static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->currentWidget())->isRunning() ?
|
||||
QIcon("../resources/icons/stop-script.svg") : QIcon("../resources/icons/start-script.svg"));
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::loadScriptMenu(const QString& scriptName) {
|
||||
|
@ -79,21 +81,21 @@ void ScriptEditorWindow::loadScriptClicked() {
|
|||
}
|
||||
|
||||
void ScriptEditorWindow::loadMenuAboutToShow() {
|
||||
loadMenu->clear();
|
||||
_loadMenu->clear();
|
||||
QStringList runningScripts = Application::getInstance()->getRunningScripts();
|
||||
if (runningScripts.count() > 0) {
|
||||
QSignalMapper* signalMapper = new QSignalMapper(this);
|
||||
foreach (const QString& runningScript, runningScripts) {
|
||||
QAction* runningScriptAction = new QAction(runningScript, loadMenu);
|
||||
QAction* runningScriptAction = new QAction(runningScript, _loadMenu);
|
||||
connect(runningScriptAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
||||
signalMapper->setMapping(runningScriptAction, runningScript);
|
||||
loadMenu->addAction(runningScriptAction);
|
||||
_loadMenu->addAction(runningScriptAction);
|
||||
}
|
||||
connect(signalMapper, SIGNAL(mapped(const QString &)), this, SLOT(loadScriptMenu(const QString &)));
|
||||
connect(signalMapper, SIGNAL(mapped(const QString &)), this, SLOT(loadScriptMenu(const QString&)));
|
||||
} else {
|
||||
QAction* naAction = new QAction("(no running scripts)",loadMenu);
|
||||
QAction* naAction = new QAction("(no running scripts)", _loadMenu);
|
||||
naAction->setDisabled(true);
|
||||
loadMenu->addAction(naAction);
|
||||
_loadMenu->addAction(naAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,19 +104,22 @@ void ScriptEditorWindow::newScriptClicked() {
|
|||
}
|
||||
|
||||
void ScriptEditorWindow::toggleRunScriptClicked() {
|
||||
this->setRunningState(!(ui->tabWidget->currentIndex() !=-1 && ((ScriptEditorWidget*)ui->tabWidget->currentWidget())->isRunning()));
|
||||
this->setRunningState(!(_ScriptEditorWindowUI->tabWidget->currentIndex() !=-1
|
||||
&& static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->currentWidget())->isRunning()));
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::saveScriptClicked() {
|
||||
if (ui->tabWidget->currentIndex() != -1) {
|
||||
ScriptEditorWidget* currentScriptWidget = (ScriptEditorWidget*)ui->tabWidget->currentWidget();
|
||||
if (_ScriptEditorWindowUI->tabWidget->currentIndex() != -1) {
|
||||
ScriptEditorWidget* currentScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget
|
||||
->currentWidget());
|
||||
currentScriptWidget->save();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::saveScriptAsClicked() {
|
||||
if (ui->tabWidget->currentIndex() != -1) {
|
||||
ScriptEditorWidget* currentScriptWidget = (ScriptEditorWidget*)ui->tabWidget->currentWidget();
|
||||
if (_ScriptEditorWindowUI->tabWidget->currentIndex() != -1) {
|
||||
ScriptEditorWidget* currentScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget
|
||||
->currentWidget());
|
||||
currentScriptWidget->saveAs();
|
||||
}
|
||||
}
|
||||
|
@ -124,8 +129,8 @@ ScriptEditorWidget* ScriptEditorWindow::addScriptEditorWidget(QString title) {
|
|||
connect(newScriptEditorWidget, SIGNAL(scriptnameChanged()), this, SLOT(updateScriptNameOrStatus()));
|
||||
connect(newScriptEditorWidget, SIGNAL(scriptModified()), this, SLOT(updateScriptNameOrStatus()));
|
||||
connect(newScriptEditorWidget, SIGNAL(runningStateChanged()), this, SLOT(updateButtons()));
|
||||
ui->tabWidget->addTab(newScriptEditorWidget, title);
|
||||
ui->tabWidget->setCurrentWidget(newScriptEditorWidget);
|
||||
_ScriptEditorWindowUI->tabWidget->addTab(newScriptEditorWidget, title);
|
||||
_ScriptEditorWindowUI->tabWidget->setCurrentWidget(newScriptEditorWidget);
|
||||
newScriptEditorWidget->setUpdatesEnabled(true);
|
||||
newScriptEditorWidget->adjustSize();
|
||||
return newScriptEditorWidget;
|
||||
|
@ -133,13 +138,14 @@ ScriptEditorWidget* ScriptEditorWindow::addScriptEditorWidget(QString title) {
|
|||
|
||||
void ScriptEditorWindow::tabSwitched(int tabIndex) {
|
||||
this->updateButtons();
|
||||
if (ui->tabWidget->currentIndex() != -1) {
|
||||
ScriptEditorWidget* currentScriptWidget = (ScriptEditorWidget*)ui->tabWidget->currentWidget();
|
||||
QString modifiedStar = (currentScriptWidget->isModified()?"*":"");
|
||||
if (_ScriptEditorWindowUI->tabWidget->currentIndex() != -1) {
|
||||
ScriptEditorWidget* currentScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget
|
||||
->currentWidget());
|
||||
QString modifiedStar = (currentScriptWidget->isModified() ? "*" : "");
|
||||
if (currentScriptWidget->getScriptName().length() > 0) {
|
||||
this->setWindowTitle("Script Editor ["+currentScriptWidget->getScriptName()+modifiedStar+"]");
|
||||
this->setWindowTitle("Script Editor [" + currentScriptWidget->getScriptName() + modifiedStar + "]");
|
||||
} else {
|
||||
this->setWindowTitle("Script Editor [New script"+modifiedStar+"]");
|
||||
this->setWindowTitle("Script Editor [New script" + modifiedStar + "]");
|
||||
}
|
||||
} else {
|
||||
this->setWindowTitle("Script Editor");
|
||||
|
@ -147,21 +153,25 @@ void ScriptEditorWindow::tabSwitched(int tabIndex) {
|
|||
}
|
||||
|
||||
void ScriptEditorWindow::tabCloseRequested(int tabIndex) {
|
||||
ScriptEditorWidget* closingScriptWidget = (ScriptEditorWidget*)ui->tabWidget->widget(tabIndex);
|
||||
ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget
|
||||
->widget(tabIndex));
|
||||
if(closingScriptWidget->questionSave()) {
|
||||
ui->tabWidget->removeTab(tabIndex);
|
||||
_ScriptEditorWindowUI->tabWidget->removeTab(tabIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::closeEvent(QCloseEvent *event) {
|
||||
bool unsaved_docs_warning = false;
|
||||
for (int i = 0; i < ui->tabWidget->count(); i++ && !unsaved_docs_warning){
|
||||
if(((ScriptEditorWidget*)ui->tabWidget->widget(i))->isModified()){
|
||||
for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){
|
||||
if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){
|
||||
unsaved_docs_warning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!unsaved_docs_warning || QMessageBox::warning(this, tr("Interface"), tr("There are some unsaved scripts, are you sure you want to close the editor? Changes will be lost!"), QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Discard) {
|
||||
if (!unsaved_docs_warning || QMessageBox::warning(this, tr("Interface"),
|
||||
tr("There are some unsaved scripts, are you sure you want to close the editor? Changes will be lost!"),
|
||||
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Discard) {
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
|
@ -172,19 +182,19 @@ void ScriptEditorWindow::updateScriptNameOrStatus() {
|
|||
ScriptEditorWidget* source = (ScriptEditorWidget*)QObject::sender();
|
||||
QString modifiedStar = (source->isModified()?"*":"");
|
||||
if (source->getScriptName().length() > 0) {
|
||||
for (int i = 0; i < ui->tabWidget->count(); i++){
|
||||
if (ui->tabWidget->widget(i) == source) {
|
||||
ui->tabWidget->setTabText(i,modifiedStar+QFileInfo(source->getScriptName()).fileName());
|
||||
ui->tabWidget->setTabToolTip(i, source->getScriptName());
|
||||
for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){
|
||||
if (_ScriptEditorWindowUI->tabWidget->widget(i) == source) {
|
||||
_ScriptEditorWindowUI->tabWidget->setTabText(i,modifiedStar + QFileInfo(source->getScriptName()).fileName());
|
||||
_ScriptEditorWindowUI->tabWidget->setTabToolTip(i, source->getScriptName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ui->tabWidget->currentWidget() == source) {
|
||||
if (_ScriptEditorWindowUI->tabWidget->currentWidget() == source) {
|
||||
if (source->getScriptName().length() > 0) {
|
||||
this->setWindowTitle("Script Editor ["+source->getScriptName()+modifiedStar+"]");
|
||||
this->setWindowTitle("Script Editor [" + source->getScriptName() + modifiedStar + "]");
|
||||
} else {
|
||||
this->setWindowTitle("Script Editor [New script"+modifiedStar+"]");
|
||||
this->setWindowTitle("Script Editor [New script" + modifiedStar + "]");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
#include "ScriptEditorWidget.h"
|
||||
|
||||
namespace Ui {
|
||||
class ScriptEditorWindow;
|
||||
class ScriptEditorWindow;
|
||||
}
|
||||
|
||||
class ScriptEditorWindow : public QWidget {
|
||||
|
@ -26,12 +26,13 @@ public:
|
|||
~ScriptEditorWindow();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void closeEvent(QCloseEvent* event);
|
||||
|
||||
private:
|
||||
Ui::ScriptEditorWindow* ui;
|
||||
QMenu* loadMenu;
|
||||
QMenu* saveMenu;
|
||||
Ui::ScriptEditorWindow* _ScriptEditorWindowUI;
|
||||
QMenu* _loadMenu;
|
||||
QMenu* _saveMenu;
|
||||
|
||||
ScriptEditorWidget* addScriptEditorWidget(QString title);
|
||||
void setRunningState(bool run);
|
||||
void setScriptName(const QString& scriptName);
|
||||
|
|
Loading…
Reference in a new issue