} 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 { 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–620 of 620. Previous lines
} 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 { 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(); }