Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 260 files). Show all
Unified · Split
| @@ -14,7 +14,7 @@ · 13 unmodified lines | |||
| 14 | #include <QClipboard> | 14 | #include <QClipboard> |
| 15 | #include <QtCore/QDir> | 15 | #include <QtCore/QDir> |
| 16 | #include <QMessageBox> | 16 | #include <QMessageBox> |
| 17 | #include <QtScript/QScriptValue> | 17 | #include <ScriptValue.h> |
| 18 | #include <QtGui/QDesktopServices> | 18 | #include <QtGui/QDesktopServices> |
| 19 | #include <shared/QtHelpers.h> | 19 | #include <shared/QtHelpers.h> |
| 20 | #include <SettingHandle.h> | 20 | #include <SettingHandle.h> |
| @@ -76,8 +76,8 @@ WindowScriptingInterface::~WindowScriptingInterface() { · 55 unmodified lines | |||
| 76 | _messageBoxes.clear(); | 76 | _messageBoxes.clear(); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | QScriptValue WindowScriptingInterface::hasFocus() { | 79 | ScriptValuePointer WindowScriptingInterface::hasFocus() { |
| 80 | return qApp->hasFocus(); | 80 | return engine()->newValue(qApp->hasFocus()); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | void WindowScriptingInterface::setFocus() { | 83 | void WindowScriptingInterface::setFocus() { |
| @@ -96,28 +96,29 @@ void WindowScriptingInterface::raise() { · 12 unmodified lines | |||
| 96 | 96 | ||
| 97 | /// Display an alert box | 97 | /// Display an alert box |
| 98 | /// \param const QString& message message to display | 98 | /// \param const QString& message message to display |
| 99 | /// \return QScriptValue::UndefinedValue | 99 | /// \return ScriptValuePointer::UndefinedValue |
| 100 | void WindowScriptingInterface::alert(const QString& message) { | 100 | void WindowScriptingInterface::alert(const QString& message) { |
| 101 | OffscreenUi::asyncWarning("", message, QMessageBox::Ok, QMessageBox::Ok); | 101 | OffscreenUi::asyncWarning("", message, QMessageBox::Ok, QMessageBox::Ok); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | /// Display a confirmation box with the options 'Yes' and 'No' | 104 | /// Display a confirmation box with the options 'Yes' and 'No' |
| 105 | /// \param const QString& message message to display | 105 | /// \param const QString& message message to display |
| 106 | /// \return QScriptValue `true` if 'Yes' was clicked, `false` otherwise | 106 | /// \return ScriptValuePointer `true` if 'Yes' was clicked, `false` otherwise |
| 107 | QScriptValue WindowScriptingInterface::confirm(const QString& message) { | 107 | ScriptValuePointer WindowScriptingInterface::confirm(const QString& message) { |
| 108 | return QScriptValue((QMessageBox::Yes == OffscreenUi::question("", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes))); | 108 | return engine()->newValue((QMessageBox::Yes == OffscreenUi::question("", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes))); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | /// Display a prompt with a text box | 111 | /// Display a prompt with a text box |
| 112 | /// \param const QString& message message to display | 112 | /// \param const QString& message message to display |
| 113 | /// \param const QString& defaultText default text in the text box | 113 | /// \param const QString& defaultText default text in the text box |
| 114 | /// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. | 114 | /// \return ScriptValuePointer string text value in text box if the dialog was accepted, `null` otherwise. |
| 115 | QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { | 115 | ScriptValuePointer WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { |
| 116 | QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText); | 116 | QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText); |
| 117 | if (QScriptValue(result).equals("")) { | 117 | auto sResult = engine()->newValue(result); |
| 118 | return QScriptValue::NullValue; | 118 | if (sResult->equals(engine()->newValue(""))) { |
| 119 | return engine()->nullValue(); | ||
| 119 | } | 120 | } |
| 120 | return QScriptValue(result); | 121 | return sResult; |
| 121 | } | 122 | } |
| 122 | 123 | ||
| 123 | /// Display a prompt with a text box | 124 | /// Display a prompt with a text box |
| @@ -217,8 +218,8 @@ void WindowScriptingInterface::ensureReticleVisible() const { · 93 unmodified lines | |||
| 217 | /// working directory. | 218 | /// working directory. |
| 218 | /// \param const QString& title title of the window | 219 | /// \param const QString& title title of the window |
| 219 | /// \param const QString& directory directory to start the directory browser at | 220 | /// \param const QString& directory directory to start the directory browser at |
| 220 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | 221 | /// \return ScriptValuePointer file path as a string if one was selected, otherwise `ScriptValuePointer::NullValue` |
| 221 | QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | 222 | ScriptValuePointer WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { |
| 222 | ensureReticleVisible(); | 223 | ensureReticleVisible(); |
| 223 | QString path = directory; | 224 | QString path = directory; |
| 224 | if (path.isEmpty()) { | 225 | if (path.isEmpty()) { |
| @@ -231,7 +232,7 @@ QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QSt · 6 unmodified lines | |||
| 231 | if (!result.isEmpty()) { | 232 | if (!result.isEmpty()) { |
| 232 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | 233 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); |
| 233 | } | 234 | } |
| 234 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | 235 | return result.isEmpty() ? engine()->nullValue() : engine()->newValue(result); |
| 235 | } | 236 | } |
| 236 | 237 | ||
| 237 | /// Display a "browse to directory" dialog. If `directory` is an invalid file or directory the browser will start at the current | 238 | /// Display a "browse to directory" dialog. If `directory` is an invalid file or directory the browser will start at the current |
| @@ -261,8 +262,8 @@ void WindowScriptingInterface::browseDirAsync(const QString& title, const QStrin · 23 unmodified lines | |||
| 261 | /// \param const QString& title title of the window | 262 | /// \param const QString& title title of the window |
| 262 | /// \param const QString& directory directory to start the file browser at | 263 | /// \param const QString& directory directory to start the file browser at |
| 263 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | 264 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 264 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | 265 | /// \return ScriptValuePointer file path as a string if one was selected, otherwise `ScriptValuePointer::NullValue` |
| 265 | QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { | 266 | ScriptValuePointer WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { |
| 266 | ensureReticleVisible(); | 267 | ensureReticleVisible(); |
| 267 | QString path = directory; | 268 | QString path = directory; |
| 268 | if (path.isEmpty()) { | 269 | if (path.isEmpty()) { |
| @@ -275,7 +276,7 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin · 6 unmodified lines | |||
| 275 | if (!result.isEmpty()) { | 276 | if (!result.isEmpty()) { |
| 276 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | 277 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); |
| 277 | } | 278 | } |
| 278 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | 279 | return result.isEmpty() ? engine()->nullValue() : engine()->newValue(result); |
| 279 | } | 280 | } |
| 280 | 281 | ||
| 281 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current | 282 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current |
| @@ -308,8 +309,8 @@ void WindowScriptingInterface::browseAsync(const QString& title, const QString& · 26 unmodified lines | |||
| 308 | /// \param const QString& title title of the window | 309 | /// \param const QString& title title of the window |
| 309 | /// \param const QString& directory directory to start the file browser at | 310 | /// \param const QString& directory directory to start the file browser at |
| 310 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | 311 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 311 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | 312 | /// \return ScriptValuePointer file path as a string if one was selected, otherwise `ScriptValuePointer::NullValue` |
| 312 | QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { | 313 | ScriptValuePointer WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { |
| 313 | ensureReticleVisible(); | 314 | ensureReticleVisible(); |
| 314 | QString path = directory; | 315 | QString path = directory; |
| 315 | if (path.isEmpty()) { | 316 | if (path.isEmpty()) { |
| @@ -322,7 +323,7 @@ QScriptValue WindowScriptingInterface::save(const QString& title, const QString& · 6 unmodified lines | |||
| 322 | if (!result.isEmpty()) { | 323 | if (!result.isEmpty()) { |
| 323 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | 324 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); |
| 324 | } | 325 | } |
| 325 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | 326 | return result.isEmpty() ? engine()->nullValue() : engine()->newValue(result); |
| 326 | } | 327 | } |
| 327 | 328 | ||
| 328 | /// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current | 329 | /// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current |
| @@ -355,8 +356,8 @@ void WindowScriptingInterface::saveAsync(const QString& title, const QString& di · 26 unmodified lines | |||
| 355 | /// \param const QString& title title of the window | 356 | /// \param const QString& title title of the window |
| 356 | /// \param const QString& directory directory to start the asset browser at | 357 | /// \param const QString& directory directory to start the asset browser at |
| 357 | /// \param const QString& nameFilter filter to filter asset names by - see `QFileDialog` | 358 | /// \param const QString& nameFilter filter to filter asset names by - see `QFileDialog` |
| 358 | /// \return QScriptValue asset path as a string if one was selected, otherwise `QScriptValue::NullValue` | 359 | /// \return ScriptValuePointer asset path as a string if one was selected, otherwise `ScriptValuePointer::NullValue` |
| 359 | QScriptValue WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) { | 360 | ScriptValuePointer WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) { |
| 360 | ensureReticleVisible(); | 361 | ensureReticleVisible(); |
| 361 | QString path = directory; | 362 | QString path = directory; |
| 362 | if (path.isEmpty()) { | 363 | if (path.isEmpty()) { |
| @@ -372,7 +373,7 @@ QScriptValue WindowScriptingInterface::browseAssets(const QString& title, const · 9 unmodified lines | |||
| 372 | if (!result.isEmpty()) { | 373 | if (!result.isEmpty()) { |
| 373 | setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath()); | 374 | setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath()); |
| 374 | } | 375 | } |
| 375 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | 376 | return result.isEmpty() ? engine()->nullValue() : engine()->newValue(result); |
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | /// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid | 379 | /// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid |