Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 238 files). Show all
Unified · Split
| @@ -10,12 +10,15 @@ · 9 unmodified lines | |||
| 10 | // | 10 | // |
| 11 | 11 | ||
| 12 | #include <QDir> | 12 | #include <QDir> |
| 13 | #include <QDialogButtonBox> | ||
| 13 | #include <QFileDialog> | 14 | #include <QFileDialog> |
| 14 | #include <QInputDialog> | 15 | #include <QInputDialog> |
| 15 | #include <QMessageBox> | 16 | #include <QMessageBox> |
| 17 | #include <QScriptValue> | ||
| 16 | 18 | ||
| 17 | #include "Application.h" | 19 | #include "Application.h" |
| 18 | #include "Menu.h" | 20 | #include "Menu.h" |
| 21 | #include "ui/ModelsBrowser.h" | ||
| 19 | 22 | ||
| 20 | #include "WindowScriptingInterface.h" | 23 | #include "WindowScriptingInterface.h" |
| 21 | 24 | ||
| @@ -24,6 +27,9 @@ WindowScriptingInterface* WindowScriptingInterface::getInstance() { · 2 unmodified lines | |||
| 24 | return &sharedInstance; | 27 | return &sharedInstance; |
| 25 | } | 28 | } |
| 26 | 29 | ||
| 30 | WindowScriptingInterface::WindowScriptingInterface() { | ||
| 31 | } | ||
| 32 | |||
| 27 | QScriptValue WindowScriptingInterface::alert(const QString& message) { | 33 | QScriptValue WindowScriptingInterface::alert(const QString& message) { |
| 28 | QScriptValue retVal; | 34 | QScriptValue retVal; |
| 29 | QMetaObject::invokeMethod(this, "showAlert", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QScriptValue, retVal), Q_ARG(const QString&, message)); | 35 | QMetaObject::invokeMethod(this, "showAlert", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QScriptValue, retVal), Q_ARG(const QString&, message)); |
| @@ -37,6 +43,14 @@ QScriptValue WindowScriptingInterface::confirm(const QString& message) { · 7 unmodified lines | |||
| 37 | return retVal; | 43 | return retVal; |
| 38 | } | 44 | } |
| 39 | 45 | ||
| 46 | QScriptValue WindowScriptingInterface::form(const QString& title, QScriptValue form) { | ||
| 47 | QScriptValue retVal; | ||
| 48 | QMetaObject::invokeMethod(this, "showForm", Qt::BlockingQueuedConnection, | ||
| 49 | Q_RETURN_ARG(QScriptValue, retVal), | ||
| 50 | Q_ARG(const QString&, title), Q_ARG(QScriptValue, form)); | ||
| 51 | return retVal; | ||
| 52 | } | ||
| 53 | |||
| 40 | QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { | 54 | QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { |
| 41 | QScriptValue retVal; | 55 | QScriptValue retVal; |
| 42 | QMetaObject::invokeMethod(this, "showPrompt", Qt::BlockingQueuedConnection, | 56 | QMetaObject::invokeMethod(this, "showPrompt", Qt::BlockingQueuedConnection, |
| @@ -62,6 +76,14 @@ QScriptValue WindowScriptingInterface::save(const QString& title, const QString& · 19 unmodified lines | |||
| 62 | return retVal; | 76 | return retVal; |
| 63 | } | 77 | } |
| 64 | 78 | ||
| 79 | QScriptValue WindowScriptingInterface::s3Browse(const QString& nameFilter) { | ||
| 80 | QScriptValue retVal; | ||
| 81 | QMetaObject::invokeMethod(this, "showS3Browse", Qt::BlockingQueuedConnection, | ||
| 82 | Q_RETURN_ARG(QScriptValue, retVal), | ||
| 83 | Q_ARG(const QString&, nameFilter)); | ||
| 84 | return retVal; | ||
| 85 | } | ||
| 86 | |||
| 65 | /// Display an alert box | 87 | /// Display an alert box |
| 66 | /// \param const QString& message message to display | 88 | /// \param const QString& message message to display |
| 67 | /// \return QScriptValue::UndefinedValue | 89 | /// \return QScriptValue::UndefinedValue |
| @@ -78,6 +100,73 @@ QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { · 10 unmodified lines | |||
| 78 | return QScriptValue(response == QMessageBox::Yes); | 100 | return QScriptValue(response == QMessageBox::Yes); |
| 79 | } | 101 | } |
| 80 | 102 | ||
| 103 | /// Display a form layout with an edit box | ||
| 104 | /// \param const QString& title title to display | ||
| 105 | /// \param const QScriptValue form to display (array containing labels and values) | ||
| 106 | /// \return QScriptValue result form (unchanged is dialog canceled) | ||
| 107 | QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptValue form) { | ||
| 108 | if (form.isArray() && form.property("length").toInt32() > 0) { | ||
| 109 | QDialog* editDialog = new QDialog(Application::getInstance()->getWindow()); | ||
| 110 | editDialog->setWindowTitle(title); | ||
| 111 | |||
| 112 | QVBoxLayout* layout = new QVBoxLayout(); | ||
| 113 | editDialog->setLayout(layout); | ||
| 114 | |||
| 115 | QScrollArea* area = new QScrollArea(); | ||
| 116 | layout->addWidget(area); | ||
| 117 | area->setWidgetResizable(true); | ||
| 118 | QWidget* container = new QWidget(); | ||
| 119 | QFormLayout* formLayout = new QFormLayout(); | ||
| 120 | container->setLayout(formLayout); | ||
| 121 | container->sizePolicy().setHorizontalStretch(1); | ||
| 122 | formLayout->setRowWrapPolicy(QFormLayout::DontWrapRows); | ||
| 123 | formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); | ||
| 124 | formLayout->setFormAlignment(Qt::AlignHCenter | Qt::AlignTop); | ||
| 125 | formLayout->setLabelAlignment(Qt::AlignLeft); | ||
| 126 | |||
| 127 | area->setWidget(container); | ||
| 128 | |||
| 129 | QVector<QLineEdit*> edits; | ||
| 130 | for (int i = 0; i < form.property("length").toInt32(); ++i) { | ||
| 131 | QScriptValue item = form.property(i); | ||
| 132 | edits.push_back(new QLineEdit(item.property("value").toString())); | ||
| 133 | formLayout->addRow(item.property("label").toString(), edits.back()); | ||
| 134 | } | ||
| 135 | QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok); | ||
| 136 | connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); | ||
| 137 | layout->addWidget(buttons); | ||
| 138 | |||
| 139 | if (editDialog->exec() == QDialog::Accepted) { | ||
| 140 | for (int i = 0; i < form.property("length").toInt32(); ++i) { | ||
| 141 | QScriptValue item = form.property(i); | ||
| 142 | QScriptValue value = item.property("value"); | ||
| 143 | bool ok = true; | ||
| 144 | if (value.isNumber()) { | ||
| 145 | value = edits.at(i)->text().toDouble(&ok); | ||
| 146 | } else if (value.isString()) { | ||
| 147 | value = edits.at(i)->text(); | ||
| 148 | } else if (value.isBool()) { | ||
| 149 | if (edits.at(i)->text() == "true") { | ||
| 150 | value = true; | ||
| 151 | } else if (edits.at(i)->text() == "false") { | ||
| 152 | value = false; | ||
| 153 | } else { | ||
| 154 | ok = false; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | if (ok) { | ||
| 158 | item.setProperty("value", value); | ||
| 159 | form.setProperty(i, item); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | delete editDialog; | ||
| 165 | } | ||
| 166 | |||
| 167 | return form; | ||
| 168 | } | ||
| 169 | |||
| 81 | /// Display a prompt with a text box | 170 | /// Display a prompt with a text box |
| 82 | /// \param const QString& message message to display | 171 | /// \param const QString& message message to display |
| 83 | /// \param const QString& defaultText default text in the text box | 172 | /// \param const QString& defaultText default text in the text box |
| @@ -88,11 +177,11 @@ QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const · 4 unmodified lines | |||
| 88 | promptDialog.setLabelText(message); | 177 | promptDialog.setLabelText(message); |
| 89 | promptDialog.setTextValue(defaultText); | 178 | promptDialog.setTextValue(defaultText); |
| 90 | promptDialog.setFixedSize(600, 200); | 179 | promptDialog.setFixedSize(600, 200); |
| 91 | 180 | ||
| 92 | if (promptDialog.exec() == QDialog::Accepted) { | 181 | if (promptDialog.exec() == QDialog::Accepted) { |
| 93 | return QScriptValue(promptDialog.textValue()); | 182 | return QScriptValue(promptDialog.textValue()); |
| 94 | } | 183 | } |
| 95 | 184 | ||
| 96 | return QScriptValue::NullValue; | 185 | return QScriptValue::NullValue; |
| 97 | } | 186 | } |
| 98 | 187 | ||
| @@ -113,7 +202,7 @@ QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QS · 14 unmodified lines | |||
| 113 | fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); | 202 | fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); |
| 114 | path = fileInfo.filePath(); | 203 | path = fileInfo.filePath(); |
| 115 | } | 204 | } |
| 116 | 205 | ||
| 117 | QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); | 206 | QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); |
| 118 | // fileDialog.setFileMode(QFileDialog::ExistingFile); | 207 | // fileDialog.setFileMode(QFileDialog::ExistingFile); |
| 119 | fileDialog.setAcceptMode(acceptMode); | 208 | fileDialog.setAcceptMode(acceptMode); |
| @@ -131,6 +220,22 @@ QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QS · 11 unmodified lines | |||
| 131 | return QScriptValue::NullValue; | 220 | return QScriptValue::NullValue; |
| 132 | } | 221 | } |
| 133 | 222 | ||
| 223 | /// Display a browse window for S3 models | ||
| 224 | /// \param const QString& nameFilter filter to filter filenames | ||
| 225 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | ||
| 226 | QScriptValue WindowScriptingInterface::showS3Browse(const QString& nameFilter) { | ||
| 227 | ModelsBrowser browser(ENTITY_MODEL); | ||
| 228 | if (nameFilter != "") { | ||
| 229 | browser.setNameFilter(nameFilter); | ||
| 230 | } | ||
| 231 | QEventLoop loop; | ||
| 232 | connect(&browser, &ModelsBrowser::selected, &loop, &QEventLoop::quit); | ||
| 233 | QMetaObject::invokeMethod(&browser, "browse", Qt::QueuedConnection); | ||
| 234 | loop.exec(); | ||
| 235 | |||
| 236 | return browser.getSelectedFile(); | ||
| 237 | } | ||
| 238 | |||
| 134 | int WindowScriptingInterface::getInnerWidth() { | 239 | int WindowScriptingInterface::getInnerWidth() { |
| 135 | return Application::getInstance()->getWindow()->geometry().width(); | 240 | return Application::getInstance()->getWindow()->geometry().width(); |
| 136 | } | 241 | } |