area->setWidget(container); for (int i = 0; i < form.property("length").toInt32(); ++i) { QScriptValue item = form.property(i); if (item.property("button").toString() != "") { cancelButton = cancelButton || item.property("button").toString().toLower() == "cancel"; } else if (item.property("directory").toString() != "") { QString path = item.property("directory").toString(); QString title = item.property("title").toString(); if (title == "") { title = "Choose Directory"; } QString displayAsString = item.property("displayAs").toString(); QRegExp displayAs = QRegExp(displayAsString != "" ? jsRegExp2QtRegExp(displayAsString) : "^(.*)$"); QString validateAsString = item.property("validateAs").toString(); QRegExp validateAs = QRegExp(validateAsString != "" ? jsRegExp2QtRegExp(validateAsString) : ".*"); QString errorMessage = item.property("errorMessage").toString(); if (errorMessage == "") { errorMessage = "Invalid directory"; } QPushButton* directory = new QPushButton(displayAs.cap(1)); directory->setProperty("title", title); directory->setProperty("path", path); directory->setProperty("displayAs", displayAs); directory->setProperty("validateAs", validateAs); directory->setProperty("errorMessage", errorMessage); displayAs.indexIn(path); directory->setText(displayAs.cap(1) != "" ? displayAs.cap(1) : "."); directory->setMinimumWidth(200); _directories.push_back(directory); formLayout->addRow(new QLabel(item.property("label").toString()), directory); connect(directory, SIGNAL(clicked(bool)), SLOT(chooseDirectory())); } else if (item.property("type").toString() == "inlineButton") { QString buttonLabel = item.property("buttonLabel").toString(); QPushButton* inlineButton = new QPushButton(buttonLabel); inlineButton->setMinimumWidth(200); inlineButton->setProperty("name", item.property("name").toString()); formLayout->addRow(new QLabel(item.property("label").toString()), inlineButton); connect(inlineButton, SIGNAL(clicked(bool)), SLOT(inlineButtonClicked())); } else if (item.property("type").toString() == "header") { formLayout->addRow(new QLabel(item.property("label").toString())); } else if (item.property("options").isArray()) { QComboBox* combo = new QComboBox(); combo->setMinimumWidth(200); qint32 options_count = item.property("options").property("length").toInt32(); for (qint32 i = 0; i < options_count; i++) { combo->addItem(item.property("options").property(i).toString()); } _combos.push_back(combo); formLayout->addRow(new QLabel(item.property("label").toString()), combo); } else if (item.property("type").toString() == "checkbox") { QCheckBox* check = new QCheckBox(); check->setTristate(false); check->setCheckState(item.property("value").toString() == "true" ? Qt::Checked : Qt::Unchecked); _checks.push_back(check); formLayout->addRow(new QLabel(item.property("label").toString()), check); } else { QLineEdit* edit = new QLineEdit(item.property("value").toString()); edit->setMinimumWidth(200); int editIndex = _edits.size(); _edits.push_back(edit); item.setProperty("editIndex", editIndex); formLayout->addRow(new QLabel(item.property("label").toString()), edit); } } QDialogButtonBox* buttons = new QDialogButtonBox( QDialogButtonBox::Ok | (cancelButton ? QDialogButtonBox::Cancel : QDialogButtonBox::NoButton) ); connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); connect(buttons, SIGNAL(rejected()), editDialog, SLOT(reject())); layout->addWidget(buttons); return editDialog; } /// Display a prompt with a text box/// \param const QString& message message to display/// \param const QString& defaultText default text in the text box/// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise.QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const QString& defaultText) { QInputDialog promptDialog(Application::getInstance()->getWindow()); promptDialog.setWindowTitle(""); promptDialog.setLabelText(message); promptDialog.setTextValue(defaultText); promptDialog.setFixedSize(600, 200); if (promptDialog.exec() == QDialog::Accepted) { return QScriptValue(promptDialog.textValue()); } return QScriptValue::NullValue;} /// Display a file dialog. If `directory` is an invalid file or directory the browser will start at the current/// working directory./// \param const QString& title title of the window/// \param const QString& directory directory to start the file browser at/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QString& directory, const QString& nameFilter, QFileDialog::AcceptMode acceptMode) { // On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus // filename if the directory is valid. QString path = ""; QFileInfo fileInfo = QFileInfo(directory); if (fileInfo.isDir()) { fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); path = fileInfo.filePath(); } QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); fileDialog.setAcceptMode(acceptMode); QUrl fileUrl(directory); if (acceptMode == QFileDialog::AcceptSave) { fileDialog.setFileMode(QFileDialog::Directory); fileDialog.selectFile(fileUrl.fileName()); } if (fileDialog.exec()) { return QScriptValue(fileDialog.selectedFiles().first()); } return QScriptValue::NullValue;} /// Display a browse window for S3 models/// \param const QString& nameFilter filter to filter filenames/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`QScriptValue WindowScriptingInterface::showS3Browse(const QString& nameFilter) { ModelsBrowser browser(ENTITY_MODEL); if (nameFilter != "") { browser.setNameFilter(nameFilter); } QEventLoop loop; connect(&browser, &ModelsBrowser::selected, &loop, &QEventLoop::quit); QMetaObject::invokeMethod(&browser, "browse", Qt::QueuedConnection); loop.exec(); return browser.getSelectedFile();} int WindowScriptingInterface::getInnerWidth() { return Application::getInstance()->getWindow()->geometry().width();} int WindowScriptingInterface::getInnerHeight() { return Application::getInstance()->getWindow()->geometry().height();} int WindowScriptingInterface::getX() { return Application::getInstance()->getWindow()->x();} int WindowScriptingInterface::getY() { return Application::getInstance()->getWindow()->y();}Lines 501–665 of 665. Previous lines
area->setWidget(container); for (int i = 0; i < form.property("length").toInt32(); ++i) { QScriptValue item = form.property(i); if (item.property("button").toString() != "") { cancelButton = cancelButton || item.property("button").toString().toLower() == "cancel"; } else if (item.property("directory").toString() != "") { QString path = item.property("directory").toString(); QString title = item.property("title").toString(); if (title == "") { title = "Choose Directory"; } QString displayAsString = item.property("displayAs").toString(); QRegExp displayAs = QRegExp(displayAsString != "" ? jsRegExp2QtRegExp(displayAsString) : "^(.*)$"); QString validateAsString = item.property("validateAs").toString(); QRegExp validateAs = QRegExp(validateAsString != "" ? jsRegExp2QtRegExp(validateAsString) : ".*"); QString errorMessage = item.property("errorMessage").toString(); if (errorMessage == "") { errorMessage = "Invalid directory"; } QPushButton* directory = new QPushButton(displayAs.cap(1)); directory->setProperty("title", title); directory->setProperty("path", path); directory->setProperty("displayAs", displayAs); directory->setProperty("validateAs", validateAs); directory->setProperty("errorMessage", errorMessage); displayAs.indexIn(path); directory->setText(displayAs.cap(1) != "" ? displayAs.cap(1) : "."); directory->setMinimumWidth(200); _directories.push_back(directory); formLayout->addRow(new QLabel(item.property("label").toString()), directory); connect(directory, SIGNAL(clicked(bool)), SLOT(chooseDirectory())); } else if (item.property("type").toString() == "inlineButton") { QString buttonLabel = item.property("buttonLabel").toString(); QPushButton* inlineButton = new QPushButton(buttonLabel); inlineButton->setMinimumWidth(200); inlineButton->setProperty("name", item.property("name").toString()); formLayout->addRow(new QLabel(item.property("label").toString()), inlineButton); connect(inlineButton, SIGNAL(clicked(bool)), SLOT(inlineButtonClicked())); } else if (item.property("type").toString() == "header") { formLayout->addRow(new QLabel(item.property("label").toString())); } else if (item.property("options").isArray()) { QComboBox* combo = new QComboBox(); combo->setMinimumWidth(200); qint32 options_count = item.property("options").property("length").toInt32(); for (qint32 i = 0; i < options_count; i++) { combo->addItem(item.property("options").property(i).toString()); } _combos.push_back(combo); formLayout->addRow(new QLabel(item.property("label").toString()), combo); } else if (item.property("type").toString() == "checkbox") { QCheckBox* check = new QCheckBox(); check->setTristate(false); check->setCheckState(item.property("value").toString() == "true" ? Qt::Checked : Qt::Unchecked); _checks.push_back(check); formLayout->addRow(new QLabel(item.property("label").toString()), check); } else { QLineEdit* edit = new QLineEdit(item.property("value").toString()); edit->setMinimumWidth(200); int editIndex = _edits.size(); _edits.push_back(edit); item.setProperty("editIndex", editIndex); formLayout->addRow(new QLabel(item.property("label").toString()), edit); } } QDialogButtonBox* buttons = new QDialogButtonBox( QDialogButtonBox::Ok | (cancelButton ? QDialogButtonBox::Cancel : QDialogButtonBox::NoButton) ); connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); connect(buttons, SIGNAL(rejected()), editDialog, SLOT(reject())); layout->addWidget(buttons); return editDialog; } /// Display a prompt with a text box /// \param const QString& message message to display /// \param const QString& defaultText default text in the text box /// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const QString& defaultText) { QInputDialog promptDialog(Application::getInstance()->getWindow()); promptDialog.setWindowTitle(""); promptDialog.setLabelText(message); promptDialog.setTextValue(defaultText); promptDialog.setFixedSize(600, 200); if (promptDialog.exec() == QDialog::Accepted) { return QScriptValue(promptDialog.textValue()); } return QScriptValue::NullValue; } /// Display a file dialog. If `directory` is an invalid file or directory the browser will start at the current /// working directory. /// \param const QString& title title of the window /// \param const QString& directory directory to start the file browser at /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QString& directory, const QString& nameFilter, QFileDialog::AcceptMode acceptMode) { // On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus // filename if the directory is valid. QString path = ""; QFileInfo fileInfo = QFileInfo(directory); if (fileInfo.isDir()) { fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); path = fileInfo.filePath(); } QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); fileDialog.setAcceptMode(acceptMode); QUrl fileUrl(directory); if (acceptMode == QFileDialog::AcceptSave) { fileDialog.setFileMode(QFileDialog::Directory); fileDialog.selectFile(fileUrl.fileName()); } if (fileDialog.exec()) { return QScriptValue(fileDialog.selectedFiles().first()); } return QScriptValue::NullValue; } /// Display a browse window for S3 models /// \param const QString& nameFilter filter to filter filenames /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` QScriptValue WindowScriptingInterface::showS3Browse(const QString& nameFilter) { ModelsBrowser browser(ENTITY_MODEL); if (nameFilter != "") { browser.setNameFilter(nameFilter); } QEventLoop loop; connect(&browser, &ModelsBrowser::selected, &loop, &QEventLoop::quit); QMetaObject::invokeMethod(&browser, "browse", Qt::QueuedConnection); loop.exec(); return browser.getSelectedFile(); } int WindowScriptingInterface::getInnerWidth() { return Application::getInstance()->getWindow()->geometry().width(); } int WindowScriptingInterface::getInnerHeight() { return Application::getInstance()->getWindow()->geometry().height(); } int WindowScriptingInterface::getX() { return Application::getInstance()->getWindow()->x(); } int WindowScriptingInterface::getY() { return Application::getInstance()->getWindow()->y(); }