mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:24:00 +02:00
commit
be97bc23ef
14 changed files with 383 additions and 88 deletions
|
@ -171,7 +171,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
{
|
||||
// init GnuTLS for DTLS with domain-servers
|
||||
DTLSClientSession::globalInit();
|
||||
|
||||
|
||||
// read the ApplicationInfo.ini file for Name/Version/Domain information
|
||||
QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat);
|
||||
|
||||
|
@ -347,13 +347,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
// clear the scripts, and set out script to our default scripts
|
||||
clearScriptsBeforeRunning();
|
||||
loadScript("http://public.highfidelity.io/scripts/defaultScripts.js");
|
||||
|
||||
|
||||
QMutexLocker locker(&_settingsMutex);
|
||||
_settings->setValue("firstRun",QVariant(false));
|
||||
} else {
|
||||
// do this as late as possible so that all required subsystems are inialized
|
||||
loadScripts();
|
||||
|
||||
|
||||
QMutexLocker locker(&_settingsMutex);
|
||||
_previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString();
|
||||
}
|
||||
|
@ -371,11 +371,11 @@ Application::~Application() {
|
|||
|
||||
// make sure we don't call the idle timer any more
|
||||
delete idleTimer;
|
||||
|
||||
|
||||
_sharedVoxelSystem.changeTree(new VoxelTree);
|
||||
|
||||
|
||||
saveSettings();
|
||||
|
||||
|
||||
delete _voxelImporter;
|
||||
|
||||
// let the avatar mixer know we're out
|
||||
|
@ -408,14 +408,14 @@ Application::~Application() {
|
|||
delete _glWidget;
|
||||
|
||||
AccountManager::getInstance().destroy();
|
||||
|
||||
|
||||
DTLSClientSession::globalDeinit();
|
||||
}
|
||||
|
||||
void Application::saveSettings() {
|
||||
Menu::getInstance()->saveSettings();
|
||||
_rearMirrorTools->saveSettings(_settings);
|
||||
|
||||
|
||||
if (_voxelImporter) {
|
||||
_voxelImporter->saveSettings(_settings);
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ void Application::paintGL() {
|
|||
pushback = qMin(pushback, MAX_PUSHBACK * _myAvatar->getScale());
|
||||
const float BASE_PUSHBACK_FOCAL_LENGTH = 0.5f;
|
||||
pushbackFocalLength = BASE_PUSHBACK_FOCAL_LENGTH * _myAvatar->getScale();
|
||||
|
||||
|
||||
} else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
|
||||
_myCamera.setTightness(0.0f); // Camera is directly connected to head without smoothing
|
||||
_myCamera.setTargetPosition(_myAvatar->getUprightHeadPosition());
|
||||
|
@ -595,7 +595,7 @@ void Application::paintGL() {
|
|||
_myCamera.setDistance(MIRROR_FULLSCREEN_DISTANCE * _myAvatar->getScale());
|
||||
_myCamera.setTargetPosition(_myAvatar->getPosition() + glm::vec3(0, headHeight, 0));
|
||||
_myCamera.setTargetRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
|
||||
|
||||
|
||||
// if the head would intersect the near clip plane, we must push the camera out
|
||||
glm::vec3 relativePosition = glm::inverse(_myCamera.getTargetRotation()) *
|
||||
(eyePosition - _myCamera.getTargetPosition());
|
||||
|
@ -604,7 +604,7 @@ void Application::paintGL() {
|
|||
pushback = relativePosition.z + pushbackRadius - _myCamera.getDistance();
|
||||
pushbackFocalLength = _myCamera.getDistance();
|
||||
}
|
||||
|
||||
|
||||
// handle pushback, if any
|
||||
if (pushbackFocalLength > 0.0f) {
|
||||
const float PUSHBACK_DECAY = 0.5f;
|
||||
|
@ -1283,7 +1283,7 @@ void Application::timer() {
|
|||
if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) {
|
||||
sendPingPackets();
|
||||
}
|
||||
|
||||
|
||||
float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f;
|
||||
|
||||
_fps = (float)_frameCount / diffTime;
|
||||
|
@ -1684,7 +1684,7 @@ void Application::init() {
|
|||
connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
|
||||
connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
|
||||
connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
|
||||
|
||||
|
||||
// set up our audio reflector
|
||||
_audioReflector.setMyAvatar(getAvatar());
|
||||
_audioReflector.setVoxels(_voxels.getTree());
|
||||
|
@ -1693,7 +1693,7 @@ void Application::init() {
|
|||
|
||||
connect(getAudio(), &Audio::processInboundAudio, &_audioReflector, &AudioReflector::processInboundAudio,Qt::DirectConnection);
|
||||
connect(getAudio(), &Audio::processLocalAudio, &_audioReflector, &AudioReflector::processLocalAudio,Qt::DirectConnection);
|
||||
connect(getAudio(), &Audio::preProcessOriginalInboundAudio, &_audioReflector,
|
||||
connect(getAudio(), &Audio::preProcessOriginalInboundAudio, &_audioReflector,
|
||||
&AudioReflector::preProcessOriginalInboundAudio,Qt::DirectConnection);
|
||||
|
||||
// save settings when avatar changes
|
||||
|
@ -1827,7 +1827,7 @@ void Application::updateMyAvatarLookAtPosition() {
|
|||
if (tracker) {
|
||||
float eyePitch = tracker->getEstimatedEyePitch();
|
||||
float eyeYaw = tracker->getEstimatedEyeYaw();
|
||||
|
||||
|
||||
// deflect using Faceshift gaze data
|
||||
glm::vec3 origin = _myAvatar->getHead()->calculateAverageEyePosition();
|
||||
float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;
|
||||
|
@ -1914,7 +1914,7 @@ void Application::updateCamera(float deltaTime) {
|
|||
PerformanceWarning warn(showWarnings, "Application::updateCamera()");
|
||||
|
||||
if (!OculusManager::isConnected() && !TV3DManager::isConnected() &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::OffAxisProjection)) {
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::OffAxisProjection)) {
|
||||
FaceTracker* tracker = getActiveFaceTracker();
|
||||
if (tracker) {
|
||||
const float EYE_OFFSET_SCALE = 0.025f;
|
||||
|
@ -2469,7 +2469,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
|||
|
||||
// disable specular lighting for ground and voxels
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, NO_SPECULAR_COLOR);
|
||||
|
||||
|
||||
// draw the audio reflector overlay
|
||||
_audioReflector.render();
|
||||
|
||||
|
@ -2627,7 +2627,7 @@ void Application::displayOverlay() {
|
|||
const float LOG2_LOUDNESS_FLOOR = 11.f;
|
||||
float audioLevel = 0.f;
|
||||
float loudness = _audio.getLastInputLoudness() + 1.f;
|
||||
|
||||
|
||||
_trailingAudioLoudness = AUDIO_METER_AVERAGING * _trailingAudioLoudness + (1.f - AUDIO_METER_AVERAGING) * loudness;
|
||||
float log2loudness = log(_trailingAudioLoudness) / LOG2;
|
||||
|
||||
|
@ -2640,7 +2640,7 @@ void Application::displayOverlay() {
|
|||
audioLevel = AUDIO_METER_SCALE_WIDTH;
|
||||
}
|
||||
bool isClipping = ((_audio.getTimeSinceLastClip() > 0.f) && (_audio.getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME));
|
||||
|
||||
|
||||
if ((_audio.getTimeSinceLastClip() > 0.f) && (_audio.getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) {
|
||||
const float MAX_MAGNITUDE = 0.7f;
|
||||
float magnitude = MAX_MAGNITUDE * (1 - _audio.getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME);
|
||||
|
@ -3278,7 +3278,7 @@ void Application::loadScripts() {
|
|||
loadScript(string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QMutexLocker locker(&_settingsMutex);
|
||||
_settings->endArray();
|
||||
}
|
||||
|
@ -3359,7 +3359,7 @@ void Application::uploadFST(bool isHead) {
|
|||
thread->connect(uploader, SIGNAL(destroyed()), SLOT(quit()));
|
||||
thread->connect(thread, SIGNAL(finished()), SLOT(deleteLater()));
|
||||
uploader->connect(thread, SIGNAL(started()), SLOT(send()));
|
||||
|
||||
|
||||
thread->start();
|
||||
}
|
||||
|
||||
|
@ -3447,9 +3447,8 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
|||
return scriptEngine;
|
||||
}
|
||||
|
||||
void Application::loadDialog() {
|
||||
QString Application::getPreviousScriptLocation() {
|
||||
QString suggestedName;
|
||||
|
||||
if (_previousScriptLocation.isEmpty()) {
|
||||
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
// Temporary fix to Qt bug: http://stackoverflow.com/questions/16194475
|
||||
|
@ -3459,14 +3458,22 @@ void Application::loadDialog() {
|
|||
} else {
|
||||
suggestedName = _previousScriptLocation;
|
||||
}
|
||||
return suggestedName;
|
||||
}
|
||||
|
||||
QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName,
|
||||
void Application::setPreviousScriptLocation(const QString& previousScriptLocation) {
|
||||
_previousScriptLocation = previousScriptLocation;
|
||||
QMutexLocker locker(&_settingsMutex);
|
||||
_settings->setValue("LastScriptLocation", _previousScriptLocation);
|
||||
}
|
||||
|
||||
void Application::loadDialog() {
|
||||
|
||||
QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"),
|
||||
getPreviousScriptLocation(),
|
||||
tr("JavaScript Files (*.js)"));
|
||||
if (!fileNameString.isEmpty()) {
|
||||
_previousScriptLocation = fileNameString;
|
||||
QMutexLocker locker(&_settingsMutex);
|
||||
_settings->setValue("LastScriptLocation", _previousScriptLocation);
|
||||
|
||||
setPreviousScriptLocation(fileNameString);
|
||||
loadScript(fileNameString);
|
||||
}
|
||||
}
|
||||
|
@ -3603,7 +3610,7 @@ void Application::urlGoTo(int argc, const char * constArgv[]) {
|
|||
QString orientation = urlParts.count() > 2 ? urlParts[2] : QString();
|
||||
|
||||
Menu::goToDomain(domain);
|
||||
|
||||
|
||||
// goto either @user, #place, or x-xx,y-yy,z-zz
|
||||
// style co-ordinate.
|
||||
Menu::goTo(destination);
|
||||
|
|
|
@ -125,6 +125,8 @@ public:
|
|||
void restoreSizeAndPosition();
|
||||
ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false);
|
||||
void loadScripts();
|
||||
QString getPreviousScriptLocation();
|
||||
void setPreviousScriptLocation(const QString& previousScriptLocation);
|
||||
void storeSizeAndPosition();
|
||||
void clearScriptsBeforeRunning();
|
||||
void saveScripts();
|
||||
|
|
|
@ -16,12 +16,13 @@ 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}");
|
||||
_singleLineComment = QRegExp("//[^\n]*");
|
||||
_truefalseRegex = QRegExp("\\b(true|false)\\b");
|
||||
_alphacharRegex = QRegExp("[A-Za-z]");
|
||||
}
|
||||
|
||||
void ScriptHighlighting::highlightBlock(const QString& text) {
|
||||
|
@ -60,7 +61,19 @@ void ScriptHighlighting::formatComments(const QString& text) {
|
|||
int index = _singleLineComment.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = _singleLineComment.matchedLength();
|
||||
setFormat(index, length, Qt::lightGray);
|
||||
int quoted_index = _qoutedTextRegex.indexIn(text);
|
||||
bool valid = true;
|
||||
while (quoted_index >= 0 && valid) {
|
||||
int quoted_length = _qoutedTextRegex.matchedLength();
|
||||
if (quoted_index <= index && index <= (quoted_index + quoted_length)) {
|
||||
valid = false;
|
||||
}
|
||||
quoted_index = _qoutedTextRegex.indexIn(text, quoted_index + quoted_length);
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
setFormat(index, length, Qt::lightGray);
|
||||
}
|
||||
index = _singleLineComment.indexIn(text, index + length);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +91,9 @@ void ScriptHighlighting::formatNumbers(const QString& text){
|
|||
int index = _numberRegex.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = _numberRegex.matchedLength();
|
||||
setFormat(index, length, Qt::green);
|
||||
if (index == 0 || _alphacharRegex.indexIn(text, index - 1) != (index - 1)) {
|
||||
setFormat(index, length, Qt::green);
|
||||
}
|
||||
index = _numberRegex.indexIn(text, index + length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ protected:
|
|||
void formatTrueFalse(const QString& text);
|
||||
|
||||
private:
|
||||
QRegExp _alphacharRegex;
|
||||
QRegExp _keywordRegex;
|
||||
QRegExp _qoutedTextRegex;
|
||||
QRegExp _multiLineCommentBegin;
|
||||
|
|
108
interface/src/ui/ScriptEditBox.cpp
Normal file
108
interface/src/ui/ScriptEditBox.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
//
|
||||
// ScriptEditBox.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Thijs Wenker on 4/30/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "ScriptEditBox.h"
|
||||
#include "ScriptLineNumberArea.h"
|
||||
#include "Application.h"
|
||||
|
||||
ScriptEditBox::ScriptEditBox(QWidget* parent) :
|
||||
QPlainTextEdit(parent)
|
||||
{
|
||||
_scriptLineNumberArea = new ScriptLineNumberArea(this);
|
||||
|
||||
connect(this, &ScriptEditBox::blockCountChanged, this, &ScriptEditBox::updateLineNumberAreaWidth);
|
||||
connect(this, &ScriptEditBox::updateRequest, this, &ScriptEditBox::updateLineNumberArea);
|
||||
connect(this, &ScriptEditBox::cursorPositionChanged, this, &ScriptEditBox::highlightCurrentLine);
|
||||
|
||||
updateLineNumberAreaWidth(0);
|
||||
highlightCurrentLine();
|
||||
}
|
||||
|
||||
int ScriptEditBox::lineNumberAreaWidth() {
|
||||
int digits = 1;
|
||||
const int SPACER_PIXELS = 3;
|
||||
const int BASE_TEN = 10;
|
||||
int max = qMax(1, blockCount());
|
||||
while (max >= BASE_TEN) {
|
||||
max /= BASE_TEN;
|
||||
digits++;
|
||||
}
|
||||
return SPACER_PIXELS + fontMetrics().width(QLatin1Char('H')) * digits;
|
||||
}
|
||||
|
||||
void ScriptEditBox::updateLineNumberAreaWidth(int blockCount) {
|
||||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
||||
}
|
||||
|
||||
void ScriptEditBox::updateLineNumberArea(const QRect& rect, int deltaY) {
|
||||
if (deltaY) {
|
||||
_scriptLineNumberArea->scroll(0, deltaY);
|
||||
} else {
|
||||
_scriptLineNumberArea->update(0, rect.y(), _scriptLineNumberArea->width(), rect.height());
|
||||
}
|
||||
|
||||
if (rect.contains(viewport()->rect())) {
|
||||
updateLineNumberAreaWidth(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditBox::resizeEvent(QResizeEvent* event) {
|
||||
QPlainTextEdit::resizeEvent(event);
|
||||
|
||||
QRect localContentsRect = contentsRect();
|
||||
_scriptLineNumberArea->setGeometry(QRect(localContentsRect.left(), localContentsRect.top(), lineNumberAreaWidth(),
|
||||
localContentsRect.height()));
|
||||
}
|
||||
|
||||
void ScriptEditBox::highlightCurrentLine() {
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
|
||||
if (!isReadOnly()) {
|
||||
QTextEdit::ExtraSelection selection;
|
||||
|
||||
QColor lineColor = QColor(Qt::gray).lighter();
|
||||
|
||||
selection.format.setBackground(lineColor);
|
||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.clearSelection();
|
||||
extraSelections.append(selection);
|
||||
}
|
||||
|
||||
setExtraSelections(extraSelections);
|
||||
}
|
||||
|
||||
void ScriptEditBox::lineNumberAreaPaintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(_scriptLineNumberArea);
|
||||
painter.fillRect(event->rect(), Qt::lightGray);
|
||||
QTextBlock block = firstVisibleBlock();
|
||||
int blockNumber = block.blockNumber();
|
||||
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
|
||||
int bottom = top + (int) blockBoundingRect(block).height();
|
||||
|
||||
while (block.isValid() && top <= event->rect().bottom()) {
|
||||
if (block.isVisible() && bottom >= event->rect().top()) {
|
||||
QFont font = painter.font();
|
||||
font.setBold(this->textCursor().blockNumber() == block.blockNumber());
|
||||
painter.setFont(font);
|
||||
QString number = QString::number(blockNumber + 1);
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(0, top, _scriptLineNumberArea->width(), fontMetrics().height(),
|
||||
Qt::AlignRight, number);
|
||||
}
|
||||
|
||||
block = block.next();
|
||||
top = bottom;
|
||||
bottom = top + (int) blockBoundingRect(block).height();
|
||||
blockNumber++;
|
||||
}
|
||||
}
|
38
interface/src/ui/ScriptEditBox.h
Normal file
38
interface/src/ui/ScriptEditBox.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// ScriptEditBox.h
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Thijs Wenker on 4/30/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_ScriptEditBox_h
|
||||
#define hifi_ScriptEditBox_h
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
class ScriptEditBox : public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScriptEditBox(QWidget* parent = NULL);
|
||||
|
||||
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
||||
int lineNumberAreaWidth();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
private slots:
|
||||
void updateLineNumberAreaWidth(int blockCount);
|
||||
void highlightCurrentLine();
|
||||
void updateLineNumberArea(const QRect& rect, int deltaY);
|
||||
|
||||
private:
|
||||
QWidget* _scriptLineNumberArea;
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptEditBox_h
|
|
@ -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;
|
||||
|
@ -101,25 +106,44 @@ bool ScriptEditorWidget::saveFile(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()));
|
||||
return;
|
||||
QUrl url(scriptPath);
|
||||
|
||||
// if the scheme length is one or lower, maybe they typed in a file, let's try
|
||||
const int WINDOWS_DRIVE_LETTER_SIZE = 1;
|
||||
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()));
|
||||
return;
|
||||
}
|
||||
QTextStream in(&file);
|
||||
_scriptEditorWidgetUI->scriptEdit->setPlainText(in.readAll());
|
||||
setScriptFile(scriptPath);
|
||||
|
||||
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, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
_scriptEditorWidgetUI->scriptEdit->setPlainText(reply->readAll());
|
||||
if (!saveAs()) {
|
||||
static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent())->terminateCurrentTab();
|
||||
}
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
_scriptEditorWidgetUI->scriptEdit->setPlainText(in.readAll());
|
||||
|
||||
setScriptFile(scriptPath);
|
||||
|
||||
disconnect(this, SLOT(onScriptError(const QString&)));
|
||||
disconnect(this, SLOT(onScriptPrint(const QString&)));
|
||||
|
||||
_scriptEngine = Application::getInstance()->getScriptEngine(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,8 +152,15 @@ bool ScriptEditorWidget::save() {
|
|||
}
|
||||
|
||||
bool ScriptEditorWidget::saveAs() {
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save script"), QString(), tr("Javascript (*.js)"));
|
||||
return !fileName.isEmpty() ? saveFile(fileName) : false;
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save script"),
|
||||
Application::getInstance()->getPreviousScriptLocation(),
|
||||
tr("JavaScript Files (*.js)"));
|
||||
if (!fileName.isEmpty()) {
|
||||
Application::getInstance()->setPreviousScriptLocation(fileName);
|
||||
return saveFile(fileName);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditorWidget::setScriptFile(const QString& scriptPath) {
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define hifi_ScriptEditorWidget_h
|
||||
|
||||
#include <QDockWidget>
|
||||
#include "ScriptEditorWidget.h"
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
namespace Ui {
|
||||
|
|
|
@ -34,19 +34,20 @@ ScriptEditorWindow::ScriptEditorWindow() :
|
|||
_saveMenu(new QMenu)
|
||||
{
|
||||
_ScriptEditorWindowUI->setupUi(this);
|
||||
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() {
|
||||
|
@ -73,8 +74,11 @@ void ScriptEditorWindow::loadScriptMenu(const QString& scriptName) {
|
|||
}
|
||||
|
||||
void ScriptEditorWindow::loadScriptClicked() {
|
||||
QString scriptName = QFileDialog::getOpenFileName(this, tr("Interface"), QString(), tr("Javascript (*.js)"));
|
||||
QString scriptName = QFileDialog::getOpenFileName(this, tr("Interface"),
|
||||
Application::getInstance()->getPreviousScriptLocation(),
|
||||
tr("JavaScript Files (*.js)"));
|
||||
if (!scriptName.isEmpty()) {
|
||||
Application::getInstance()->setPreviousScriptLocation(scriptName);
|
||||
addScriptEditorWidget("loading...")->loadFile(scriptName);
|
||||
updateButtons();
|
||||
}
|
||||
|
@ -126,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);
|
||||
|
@ -198,3 +202,10 @@ void ScriptEditorWindow::updateScriptNameOrStatus() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditorWindow::terminateCurrentTab() {
|
||||
if (_ScriptEditorWindowUI->tabWidget->currentIndex() != -1) {
|
||||
_ScriptEditorWindowUI->tabWidget->removeTab(_ScriptEditorWindowUI->tabWidget->currentIndex());
|
||||
this->raise();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
ScriptEditorWindow();
|
||||
~ScriptEditorWindow();
|
||||
|
||||
void terminateCurrentTab();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
|
||||
|
|
28
interface/src/ui/ScriptLineNumberArea.cpp
Normal file
28
interface/src/ui/ScriptLineNumberArea.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// ScriptLineNumberArea.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Thijs Wenker on 4/30/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "ScriptLineNumberArea.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
ScriptLineNumberArea::ScriptLineNumberArea(ScriptEditBox* scriptEditBox) :
|
||||
QWidget(scriptEditBox)
|
||||
{
|
||||
_scriptEditBox = scriptEditBox;
|
||||
}
|
||||
|
||||
QSize ScriptLineNumberArea::sizeHint() {
|
||||
return QSize(_scriptEditBox->lineNumberAreaWidth(), 0);
|
||||
}
|
||||
|
||||
void ScriptLineNumberArea::paintEvent(QPaintEvent* event) {
|
||||
_scriptEditBox->lineNumberAreaPaintEvent(event);
|
||||
}
|
31
interface/src/ui/ScriptLineNumberArea.h
Normal file
31
interface/src/ui/ScriptLineNumberArea.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// ScriptLineNumberArea.h
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Thijs Wenker on 4/30/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_ScriptLineNumberArea_h
|
||||
#define hifi_ScriptLineNumberArea_h
|
||||
|
||||
#include <QWidget>
|
||||
#include "ScriptEditBox.h"
|
||||
|
||||
class ScriptLineNumberArea : public QWidget {
|
||||
|
||||
public:
|
||||
ScriptLineNumberArea(ScriptEditBox* scriptEditBox);
|
||||
QSize sizeHint();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
private:
|
||||
ScriptEditBox* _scriptEditBox;
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptLineNumberArea_h
|
|
@ -18,8 +18,8 @@
|
|||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>541</width>
|
||||
<height>238</height>
|
||||
<width>690</width>
|
||||
<height>328</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
|
@ -35,7 +35,7 @@
|
|||
<string>Edit Script</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="5,0,1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
|
@ -52,18 +52,18 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="scriptEdit">
|
||||
<widget class="ScriptEditBox" name="scriptEdit">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier</family>
|
||||
<pointsize>9</pointsize>
|
||||
<pointsize>-1</pointsize>
|
||||
<weight>50</weight>
|
||||
<italic>false</italic>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 9pt "Courier";</string>
|
||||
<string notr="true">font: 16px "Courier";</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -86,6 +86,9 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 13px "Helvetica","Arial","sans-serif";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Debug Log:</string>
|
||||
</property>
|
||||
|
@ -93,8 +96,20 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="onTheFlyCheckBox">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Helvetica,Arial,sans-serif</family>
|
||||
<pointsize>-1</pointsize>
|
||||
<weight>50</weight>
|
||||
<italic>false</italic>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 13px "Helvetica","Arial","sans-serif";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Run on the fly (Careful: Any valid change made to the code will run immediately)</string>
|
||||
<string>Run on the fly (Careful: Any valid change made to the code will run immediately) </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -115,17 +130,33 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="debugText">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 8pt "Courier";</string>
|
||||
<string notr="true">font: 15px "Courier";</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ScriptEditBox</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>ui/ScriptEditBox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<class>ScriptEditorWindow</class>
|
||||
<widget class="QWidget" name="ScriptEditorWindow">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
<enum>Qt::NonModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>706</width>
|
||||
<height>682</height>
|
||||
<width>780</width>
|
||||
<height>717</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
|
@ -29,16 +29,7 @@
|
|||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
Loading…
Reference in a new issue