From 966774815643251d941f7f179eb7eecba19a5a5f Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 1 May 2014 21:07:46 +0200 Subject: [PATCH] - Style fixes - ScriptHightlighting qouting RegEx fix ( "hello" + " " + "world" // the text between two quote entities isn't red anymore ) --- interface/src/Application.cpp | 2 +- interface/src/Application.h | 2 +- interface/src/ScriptHighlighting.cpp | 2 +- interface/src/ui/ScriptEditBox.cpp | 27 +++++++++--------- interface/src/ui/ScriptEditBox.h | 4 +-- interface/src/ui/ScriptEditorWidget.cpp | 37 +++++++++++++++---------- interface/src/ui/ScriptEditorWindow.cpp | 16 +++++------ 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index aa28d2768c..058408af66 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3461,7 +3461,7 @@ QString Application::getPreviousScriptLocation() { return suggestedName; } -void Application::setPreviousScriptLocation(QString previousScriptLocation) { +void Application::setPreviousScriptLocation(const QString& previousScriptLocation) { _previousScriptLocation = previousScriptLocation; QMutexLocker locker(&_settingsMutex); _settings->setValue("LastScriptLocation", _previousScriptLocation); diff --git a/interface/src/Application.h b/interface/src/Application.h index fb15019c19..9b613f7ed7 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -126,7 +126,7 @@ public: ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false); void loadScripts(); QString getPreviousScriptLocation(); - void setPreviousScriptLocation(QString previousScriptLocation); + void setPreviousScriptLocation(const QString& previousScriptLocation); void storeSizeAndPosition(); void clearScriptsBeforeRunning(); void saveScripts(); diff --git a/interface/src/ScriptHighlighting.cpp b/interface/src/ScriptHighlighting.cpp index 3d63ba55a8..125ab1e967 100644 --- a/interface/src/ScriptHighlighting.cpp +++ b/interface/src/ScriptHighlighting.cpp @@ -16,7 +16,7 @@ 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("\".*\""); + _qoutedTextRegex = QRegExp("\"[^\"]*(\"){0,1}"); _multiLineCommentBegin = QRegExp("/\\*"); _multiLineCommentEnd = QRegExp("\\*/"); _numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}"); diff --git a/interface/src/ui/ScriptEditBox.cpp b/interface/src/ui/ScriptEditBox.cpp index 4c2b6564ba..acabaa3c8f 100644 --- a/interface/src/ui/ScriptEditBox.cpp +++ b/interface/src/ui/ScriptEditBox.cpp @@ -18,9 +18,9 @@ ScriptEditBox::ScriptEditBox(QWidget* parent) : { _scriptLineNumberArea = new ScriptLineNumberArea(this); - connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); - connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(updateLineNumberArea(QRect, int))); - connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); + connect(this, &ScriptEditBox::blockCountChanged, this, &ScriptEditBox::updateLineNumberAreaWidth); + connect(this, &ScriptEditBox::updateRequest, this, &ScriptEditBox::updateLineNumberArea); + connect(this, &ScriptEditBox::cursorPositionChanged, this, &ScriptEditBox::highlightCurrentLine); updateLineNumberAreaWidth(0); highlightCurrentLine(); @@ -33,18 +33,18 @@ int ScriptEditBox::lineNumberAreaWidth() { int max = qMax(1, blockCount()); while (max >= BASE_TEN) { max /= BASE_TEN; - ++digits; + digits++; } return SPACER_PIXELS + fontMetrics().width(QLatin1Char('H')) * digits; } -void ScriptEditBox::updateLineNumberAreaWidth(int) { +void ScriptEditBox::updateLineNumberAreaWidth(int blockCount) { setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); } -void ScriptEditBox::updateLineNumberArea(const QRect& rect, int dy) { - if (dy) { - _scriptLineNumberArea->scroll(0, dy); +void ScriptEditBox::updateLineNumberArea(const QRect& rect, int deltaY) { + if (deltaY) { + _scriptLineNumberArea->scroll(0, deltaY); } else { _scriptLineNumberArea->update(0, rect.y(), _scriptLineNumberArea->width(), rect.height()); } @@ -54,11 +54,12 @@ void ScriptEditBox::updateLineNumberArea(const QRect& rect, int dy) { } } -void ScriptEditBox::resizeEvent(QResizeEvent* e) { - QPlainTextEdit::resizeEvent(e); +void ScriptEditBox::resizeEvent(QResizeEvent* event) { + QPlainTextEdit::resizeEvent(event); - QRect cr = contentsRect(); - _scriptLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); + QRect localContentsRect = contentsRect(); + _scriptLineNumberArea->setGeometry(QRect(localContentsRect.left(), localContentsRect.top(), lineNumberAreaWidth(), + localContentsRect.height())); } void ScriptEditBox::highlightCurrentLine() { @@ -102,6 +103,6 @@ void ScriptEditBox::lineNumberAreaPaintEvent(QPaintEvent* event) block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); - ++blockNumber; + blockNumber++; } } diff --git a/interface/src/ui/ScriptEditBox.h b/interface/src/ui/ScriptEditBox.h index ea00ec02b6..41d881b904 100644 --- a/interface/src/ui/ScriptEditBox.h +++ b/interface/src/ui/ScriptEditBox.h @@ -27,9 +27,9 @@ protected: void resizeEvent(QResizeEvent* event); private slots: - void updateLineNumberAreaWidth(int); + void updateLineNumberAreaWidth(int blockCount); void highlightCurrentLine(); - void updateLineNumberArea(const QRect&, int); + void updateLineNumberArea(const QRect& rect, int deltaY); private: QWidget* _scriptLineNumberArea; diff --git a/interface/src/ui/ScriptEditorWidget.cpp b/interface/src/ui/ScriptEditorWidget.cpp index 33e014ac07..07c6e72226 100644 --- a/interface/src/ui/ScriptEditorWidget.cpp +++ b/interface/src/ui/ScriptEditorWidget.cpp @@ -32,8 +32,10 @@ ScriptEditorWidget::ScriptEditorWidget() : { _scriptEditorWidgetUI->setupUi(this); - connect(_scriptEditorWidgetUI->scriptEdit->document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(scriptModified())); - connect(_scriptEditorWidgetUI->scriptEdit->document(), SIGNAL(contentsChanged()), this, SLOT(onScriptModified())); + connect(_scriptEditorWidgetUI->scriptEdit->document(), &QTextDocument::modificationChanged, this, + &ScriptEditorWidget::scriptModified); + connect(_scriptEditorWidgetUI->scriptEdit->document(), &QTextDocument::contentsChanged, this, + &ScriptEditorWidget::onScriptModified); // remove the title bar (see the Qt docs on setTitleBarWidget) setTitleBarWidget(new QWidget()); @@ -68,16 +70,19 @@ bool ScriptEditorWidget::setRunning(bool run) { return false; } // Clean-up old connections. - disconnect(this, SLOT(onScriptError(const QString&))); - disconnect(this, SLOT(onScriptPrint(const QString&))); + if (_scriptEngine != NULL) { + disconnect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); + disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); + disconnect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); + } if (run) { _scriptEngine = Application::getInstance()->loadScript(_currentScript, true); - connect(_scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged())); + connect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::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, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); + connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); } else { Application::getInstance()->stopScript(_currentScript); _scriptEngine = NULL; @@ -108,21 +113,25 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) { if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) { 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())); + QMessageBox::warning(this, tr("Interface"), tr("Cannot read script %1:\n%2.").arg(scriptPath) + .arg(file.errorString())); return; } QTextStream in(&file); _scriptEditorWidgetUI->scriptEdit->setPlainText(in.readAll()); setScriptFile(scriptPath); - disconnect(this, SLOT(onScriptError(const QString&))); - disconnect(this, SLOT(onScriptPrint(const QString&))); + if (_scriptEngine != NULL) { + disconnect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); + disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); + disconnect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); + } } else { QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); QNetworkReply* reply = networkManager->get(QNetworkRequest(url)); qDebug() << "Downloading included script at" << scriptPath; QEventLoop loop; - QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); loop.exec(); _scriptEditorWidgetUI->scriptEdit->setPlainText(reply->readAll()); if (!saveAs()) { @@ -132,9 +141,9 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) { _scriptEngine = Application::getInstance()->getScriptEngine(_currentScript); 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&))); + connect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); + connect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); + connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); } } diff --git a/interface/src/ui/ScriptEditorWindow.cpp b/interface/src/ui/ScriptEditorWindow.cpp index ec5070ac20..41732d18c6 100644 --- a/interface/src/ui/ScriptEditorWindow.cpp +++ b/interface/src/ui/ScriptEditorWindow.cpp @@ -37,17 +37,17 @@ ScriptEditorWindow::ScriptEditorWindow() : this->setWindowFlags(Qt::Tool); show(); addScriptEditorWidget("New script"); - connect(_loadMenu, SIGNAL(aboutToShow()), this, SLOT(loadMenuAboutToShow())); + connect(_loadMenu, &QMenu::aboutToShow, this, &ScriptEditorWindow::loadMenuAboutToShow); _ScriptEditorWindowUI->loadButton->setMenu(_loadMenu); _saveMenu->addAction("Save as..", this, SLOT(saveScriptAsClicked()), Qt::CTRL | Qt::SHIFT | Qt::Key_S); _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())); - connect(new QShortcut(QKeySequence("Ctrl+O"), this), SIGNAL(activated()), this, SLOT(loadScriptClicked())); - connect(new QShortcut(QKeySequence("F5"), this), SIGNAL(activated()), this, SLOT(toggleRunScriptClicked())); + connect(new QShortcut(QKeySequence("Ctrl+N"), this), &QShortcut::activated, this, &ScriptEditorWindow::newScriptClicked); + connect(new QShortcut(QKeySequence("Ctrl+S"), this), &QShortcut::activated, this,&ScriptEditorWindow::saveScriptClicked); + connect(new QShortcut(QKeySequence("Ctrl+O"), this), &QShortcut::activated, this, &ScriptEditorWindow::loadScriptClicked); + connect(new QShortcut(QKeySequence("F5"), this), &QShortcut::activated, this, &ScriptEditorWindow::toggleRunScriptClicked); } ScriptEditorWindow::~ScriptEditorWindow() { @@ -130,9 +130,9 @@ void ScriptEditorWindow::saveScriptAsClicked() { ScriptEditorWidget* ScriptEditorWindow::addScriptEditorWidget(QString title) { ScriptEditorWidget* newScriptEditorWidget = new ScriptEditorWidget(); - connect(newScriptEditorWidget, SIGNAL(scriptnameChanged()), this, SLOT(updateScriptNameOrStatus())); - connect(newScriptEditorWidget, SIGNAL(scriptModified()), this, SLOT(updateScriptNameOrStatus())); - connect(newScriptEditorWidget, SIGNAL(runningStateChanged()), this, SLOT(updateButtons())); + connect(newScriptEditorWidget, &ScriptEditorWidget::scriptnameChanged, this, &ScriptEditorWindow::updateScriptNameOrStatus); + connect(newScriptEditorWidget, &ScriptEditorWidget::scriptModified, this, &ScriptEditorWindow::updateScriptNameOrStatus); + connect(newScriptEditorWidget, &ScriptEditorWidget::runningStateChanged, this, &ScriptEditorWindow::updateButtons); _ScriptEditorWindowUI->tabWidget->addTab(newScriptEditorWidget, title); _ScriptEditorWindowUI->tabWidget->setCurrentWidget(newScriptEditorWidget); newScriptEditorWidget->setUpdatesEnabled(true);