- Style fixes

- ScriptHightlighting qouting RegEx fix (  "hello" + " " + "world" // the text between two quote entities isn't red anymore )
This commit is contained in:
Thijs Wenker 2014-05-01 21:07:46 +02:00
parent a33c18c15d
commit 9667748156
7 changed files with 50 additions and 40 deletions

View file

@ -3461,7 +3461,7 @@ QString Application::getPreviousScriptLocation() {
return suggestedName; return suggestedName;
} }
void Application::setPreviousScriptLocation(QString previousScriptLocation) { void Application::setPreviousScriptLocation(const QString& previousScriptLocation) {
_previousScriptLocation = previousScriptLocation; _previousScriptLocation = previousScriptLocation;
QMutexLocker locker(&_settingsMutex); QMutexLocker locker(&_settingsMutex);
_settings->setValue("LastScriptLocation", _previousScriptLocation); _settings->setValue("LastScriptLocation", _previousScriptLocation);

View file

@ -126,7 +126,7 @@ public:
ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false); ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false);
void loadScripts(); void loadScripts();
QString getPreviousScriptLocation(); QString getPreviousScriptLocation();
void setPreviousScriptLocation(QString previousScriptLocation); void setPreviousScriptLocation(const QString& previousScriptLocation);
void storeSizeAndPosition(); void storeSizeAndPosition();
void clearScriptsBeforeRunning(); void clearScriptsBeforeRunning();
void saveScripts(); void saveScripts();

View file

@ -16,7 +16,7 @@ ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) :
QSyntaxHighlighter(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"); _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("/\\*"); _multiLineCommentBegin = QRegExp("/\\*");
_multiLineCommentEnd = QRegExp("\\*/"); _multiLineCommentEnd = QRegExp("\\*/");
_numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}"); _numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");

View file

@ -18,9 +18,9 @@ ScriptEditBox::ScriptEditBox(QWidget* parent) :
{ {
_scriptLineNumberArea = new ScriptLineNumberArea(this); _scriptLineNumberArea = new ScriptLineNumberArea(this);
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, &ScriptEditBox::blockCountChanged, this, &ScriptEditBox::updateLineNumberAreaWidth);
connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(updateLineNumberArea(QRect, int))); connect(this, &ScriptEditBox::updateRequest, this, &ScriptEditBox::updateLineNumberArea);
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); connect(this, &ScriptEditBox::cursorPositionChanged, this, &ScriptEditBox::highlightCurrentLine);
updateLineNumberAreaWidth(0); updateLineNumberAreaWidth(0);
highlightCurrentLine(); highlightCurrentLine();
@ -33,18 +33,18 @@ int ScriptEditBox::lineNumberAreaWidth() {
int max = qMax(1, blockCount()); int max = qMax(1, blockCount());
while (max >= BASE_TEN) { while (max >= BASE_TEN) {
max /= BASE_TEN; max /= BASE_TEN;
++digits; digits++;
} }
return SPACER_PIXELS + fontMetrics().width(QLatin1Char('H')) * digits; return SPACER_PIXELS + fontMetrics().width(QLatin1Char('H')) * digits;
} }
void ScriptEditBox::updateLineNumberAreaWidth(int) { void ScriptEditBox::updateLineNumberAreaWidth(int blockCount) {
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
} }
void ScriptEditBox::updateLineNumberArea(const QRect& rect, int dy) { void ScriptEditBox::updateLineNumberArea(const QRect& rect, int deltaY) {
if (dy) { if (deltaY) {
_scriptLineNumberArea->scroll(0, dy); _scriptLineNumberArea->scroll(0, deltaY);
} else { } else {
_scriptLineNumberArea->update(0, rect.y(), _scriptLineNumberArea->width(), rect.height()); _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) { void ScriptEditBox::resizeEvent(QResizeEvent* event) {
QPlainTextEdit::resizeEvent(e); QPlainTextEdit::resizeEvent(event);
QRect cr = contentsRect(); QRect localContentsRect = contentsRect();
_scriptLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); _scriptLineNumberArea->setGeometry(QRect(localContentsRect.left(), localContentsRect.top(), lineNumberAreaWidth(),
localContentsRect.height()));
} }
void ScriptEditBox::highlightCurrentLine() { void ScriptEditBox::highlightCurrentLine() {
@ -102,6 +103,6 @@ void ScriptEditBox::lineNumberAreaPaintEvent(QPaintEvent* event)
block = block.next(); block = block.next();
top = bottom; top = bottom;
bottom = top + (int) blockBoundingRect(block).height(); bottom = top + (int) blockBoundingRect(block).height();
++blockNumber; blockNumber++;
} }
} }

View file

@ -27,9 +27,9 @@ protected:
void resizeEvent(QResizeEvent* event); void resizeEvent(QResizeEvent* event);
private slots: private slots:
void updateLineNumberAreaWidth(int); void updateLineNumberAreaWidth(int blockCount);
void highlightCurrentLine(); void highlightCurrentLine();
void updateLineNumberArea(const QRect&, int); void updateLineNumberArea(const QRect& rect, int deltaY);
private: private:
QWidget* _scriptLineNumberArea; QWidget* _scriptLineNumberArea;

View file

@ -32,8 +32,10 @@ ScriptEditorWidget::ScriptEditorWidget() :
{ {
_scriptEditorWidgetUI->setupUi(this); _scriptEditorWidgetUI->setupUi(this);
connect(_scriptEditorWidgetUI->scriptEdit->document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(scriptModified())); connect(_scriptEditorWidgetUI->scriptEdit->document(), &QTextDocument::modificationChanged, this,
connect(_scriptEditorWidgetUI->scriptEdit->document(), SIGNAL(contentsChanged()), this, SLOT(onScriptModified())); &ScriptEditorWidget::scriptModified);
connect(_scriptEditorWidgetUI->scriptEdit->document(), &QTextDocument::contentsChanged, this,
&ScriptEditorWidget::onScriptModified);
// remove the title bar (see the Qt docs on setTitleBarWidget) // remove the title bar (see the Qt docs on setTitleBarWidget)
setTitleBarWidget(new QWidget()); setTitleBarWidget(new QWidget());
@ -68,16 +70,19 @@ bool ScriptEditorWidget::setRunning(bool run) {
return false; return false;
} }
// Clean-up old connections. // Clean-up old connections.
disconnect(this, SLOT(onScriptError(const QString&))); if (_scriptEngine != NULL) {
disconnect(this, SLOT(onScriptPrint(const QString&))); disconnect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged);
disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError);
disconnect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint);
}
if (run) { if (run) {
_scriptEngine = Application::getInstance()->loadScript(_currentScript, true); _scriptEngine = Application::getInstance()->loadScript(_currentScript, true);
connect(_scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged())); connect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged);
// Make new connections. // Make new connections.
connect(_scriptEngine, SIGNAL(errorMessage(const QString&)), this, SLOT(onScriptError(const QString&))); connect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError);
connect(_scriptEngine, SIGNAL(printedMessage(const QString&)), this, SLOT(onScriptPrint(const QString&))); connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint);
} else { } else {
Application::getInstance()->stopScript(_currentScript); Application::getInstance()->stopScript(_currentScript);
_scriptEngine = NULL; _scriptEngine = NULL;
@ -108,21 +113,25 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) {
if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) { if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
QFile file(scriptPath); QFile file(scriptPath);
if (!file.open(QFile::ReadOnly | QFile::Text)) { 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; return;
} }
QTextStream in(&file); QTextStream in(&file);
_scriptEditorWidgetUI->scriptEdit->setPlainText(in.readAll()); _scriptEditorWidgetUI->scriptEdit->setPlainText(in.readAll());
setScriptFile(scriptPath); setScriptFile(scriptPath);
disconnect(this, SLOT(onScriptError(const QString&))); if (_scriptEngine != NULL) {
disconnect(this, SLOT(onScriptPrint(const QString&))); disconnect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged);
disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError);
disconnect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint);
}
} else { } else {
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
QNetworkReply* reply = networkManager->get(QNetworkRequest(url)); QNetworkReply* reply = networkManager->get(QNetworkRequest(url));
qDebug() << "Downloading included script at" << scriptPath; qDebug() << "Downloading included script at" << scriptPath;
QEventLoop loop; QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec(); loop.exec();
_scriptEditorWidgetUI->scriptEdit->setPlainText(reply->readAll()); _scriptEditorWidgetUI->scriptEdit->setPlainText(reply->readAll());
if (!saveAs()) { if (!saveAs()) {
@ -132,9 +141,9 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) {
_scriptEngine = Application::getInstance()->getScriptEngine(_currentScript); _scriptEngine = Application::getInstance()->getScriptEngine(_currentScript);
if (_scriptEngine != NULL) { if (_scriptEngine != NULL) {
connect(_scriptEngine, SIGNAL(runningStateChanged()), this, SIGNAL(runningStateChanged())); connect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged);
connect(_scriptEngine, SIGNAL(errorMessage(const QString&)), this, SLOT(onScriptError(const QString&))); connect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError);
connect(_scriptEngine, SIGNAL(printedMessage(const QString&)), this, SLOT(onScriptPrint(const QString&))); connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint);
} }
} }

View file

@ -37,17 +37,17 @@ ScriptEditorWindow::ScriptEditorWindow() :
this->setWindowFlags(Qt::Tool); this->setWindowFlags(Qt::Tool);
show(); show();
addScriptEditorWidget("New script"); addScriptEditorWidget("New script");
connect(_loadMenu, SIGNAL(aboutToShow()), this, SLOT(loadMenuAboutToShow())); connect(_loadMenu, &QMenu::aboutToShow, this, &ScriptEditorWindow::loadMenuAboutToShow);
_ScriptEditorWindowUI->loadButton->setMenu(_loadMenu); _ScriptEditorWindowUI->loadButton->setMenu(_loadMenu);
_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);
_ScriptEditorWindowUI->saveButton->setMenu(_saveMenu); _ScriptEditorWindowUI->saveButton->setMenu(_saveMenu);
connect(new QShortcut(QKeySequence("Ctrl+N"), this), SIGNAL(activated()), this, SLOT(newScriptClicked())); connect(new QShortcut(QKeySequence("Ctrl+N"), this), &QShortcut::activated, this, &ScriptEditorWindow::newScriptClicked);
connect(new QShortcut(QKeySequence("Ctrl+S"), this), SIGNAL(activated()), this, SLOT(saveScriptClicked())); connect(new QShortcut(QKeySequence("Ctrl+S"), this), &QShortcut::activated, this,&ScriptEditorWindow::saveScriptClicked);
connect(new QShortcut(QKeySequence("Ctrl+O"), this), SIGNAL(activated()), this, SLOT(loadScriptClicked())); connect(new QShortcut(QKeySequence("Ctrl+O"), this), &QShortcut::activated, this, &ScriptEditorWindow::loadScriptClicked);
connect(new QShortcut(QKeySequence("F5"), this), SIGNAL(activated()), this, SLOT(toggleRunScriptClicked())); connect(new QShortcut(QKeySequence("F5"), this), &QShortcut::activated, this, &ScriptEditorWindow::toggleRunScriptClicked);
} }
ScriptEditorWindow::~ScriptEditorWindow() { ScriptEditorWindow::~ScriptEditorWindow() {
@ -130,9 +130,9 @@ void ScriptEditorWindow::saveScriptAsClicked() {
ScriptEditorWidget* ScriptEditorWindow::addScriptEditorWidget(QString title) { ScriptEditorWidget* ScriptEditorWindow::addScriptEditorWidget(QString title) {
ScriptEditorWidget* newScriptEditorWidget = new ScriptEditorWidget(); ScriptEditorWidget* newScriptEditorWidget = new ScriptEditorWidget();
connect(newScriptEditorWidget, SIGNAL(scriptnameChanged()), this, SLOT(updateScriptNameOrStatus())); connect(newScriptEditorWidget, &ScriptEditorWidget::scriptnameChanged, this, &ScriptEditorWindow::updateScriptNameOrStatus);
connect(newScriptEditorWidget, SIGNAL(scriptModified()), this, SLOT(updateScriptNameOrStatus())); connect(newScriptEditorWidget, &ScriptEditorWidget::scriptModified, this, &ScriptEditorWindow::updateScriptNameOrStatus);
connect(newScriptEditorWidget, SIGNAL(runningStateChanged()), this, SLOT(updateButtons())); connect(newScriptEditorWidget, &ScriptEditorWidget::runningStateChanged, this, &ScriptEditorWindow::updateButtons);
_ScriptEditorWindowUI->tabWidget->addTab(newScriptEditorWidget, title); _ScriptEditorWindowUI->tabWidget->addTab(newScriptEditorWidget, title);
_ScriptEditorWindowUI->tabWidget->setCurrentWidget(newScriptEditorWidget); _ScriptEditorWindowUI->tabWidget->setCurrentWidget(newScriptEditorWidget);
newScriptEditorWidget->setUpdatesEnabled(true); newScriptEditorWidget->setUpdatesEnabled(true);