Rework all c++ calls

This commit is contained in:
vladest 2017-09-16 22:04:53 +02:00
parent 5b033e021a
commit 3ceeb0d83e
7 changed files with 257 additions and 255 deletions

View file

@ -6146,13 +6146,13 @@ bool Application::askToSetAvatarUrl(const QString& url) {
bool agreeToLicense = true; // assume true bool agreeToLicense = true; // assume true
//create set avatar callback //create set avatar callback
auto setAvatar = [=] (QString url, QString modelName) { auto setAvatar = [=] (QString url, QString modelName) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Set Avatar",
"Would you like to use '" + modelName + "' for your avatar?",
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) { bool ok = (QMessageBox::Ok == static_cast<QMessageBox::StandardButton>(answer.toInt()));
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
bool ok = (QMessageBox::Ok == answer);
if (ok) { if (ok) {
getMyAvatar()->useFullAvatarURL(url, modelName); getMyAvatar()->useFullAvatarURL(url, modelName);
emit fullAvatarURLChanged(url, modelName); emit fullAvatarURLChanged(url, modelName);
@ -6160,9 +6160,6 @@ bool Application::askToSetAvatarUrl(const QString& url) {
qCDebug(interfaceapp) << "Declined to use the avatar: " << url; qCDebug(interfaceapp) << "Declined to use the avatar: " << url;
} }
}); });
OffscreenUi::asyncQuestion("Set Avatar",
"Would you like to use '" + modelName + "' for your avatar?",
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
}; };
if (!modelLicense.isEmpty()) { if (!modelLicense.isEmpty()) {
@ -6170,12 +6167,13 @@ bool Application::askToSetAvatarUrl(const QString& url) {
const int MAX_CHARACTERS_PER_LINE = 90; const int MAX_CHARACTERS_PER_LINE = 90;
modelLicense = simpleWordWrap(modelLicense, MAX_CHARACTERS_PER_LINE); modelLicense = simpleWordWrap(modelLicense, MAX_CHARACTERS_PER_LINE);
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Avatar Usage License",
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=, &agreeToLicense] (QMessageBox::StandardButton answer) { modelLicense + "\nDo you agree to these terms?",
auto offscreenUi = DependencyManager::get<OffscreenUi>(); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr); QObject::connect(dlg, &ModalDialogListener::response, this, [=, &agreeToLicense] (QVariant answer) {
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
agreeToLicense = (answer == QMessageBox::Yes); agreeToLicense = (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes);
if (agreeToLicense) { if (agreeToLicense) {
switch (modelType) { switch (modelType) {
case FSTReader::HEAD_AND_BODY_MODEL: { case FSTReader::HEAD_AND_BODY_MODEL: {
@ -6192,10 +6190,6 @@ bool Application::askToSetAvatarUrl(const QString& url) {
//auto offscreenUi = DependencyManager::get<OffscreenUi>(); //auto offscreenUi = DependencyManager::get<OffscreenUi>();
}); });
OffscreenUi::asyncQuestion("Avatar Usage License",
modelLicense + "\nDo you agree to these terms?",
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
} else { } else {
setAvatar(url, modelName); setAvatar(url, modelName);
} }
@ -6215,23 +6209,21 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
shortName = shortName.mid(startIndex, endIndex - startIndex); shortName = shortName.mid(startIndex, endIndex - startIndex);
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); QString message = "Would you like to run this script:\n" + shortName;
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) { ModalDialogListener* dlg = OffscreenUi::asyncQuestion(getWindow(), "Run Script", message,
QMessageBox::Yes | QMessageBox::No);
QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
const QString& fileName = scriptFilenameOrURL; const QString& fileName = scriptFilenameOrURL;
if (answer == QMessageBox::Yes) { if (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes) {
qCDebug(interfaceapp) << "Chose to run the script: " << fileName; qCDebug(interfaceapp) << "Chose to run the script: " << fileName;
DependencyManager::get<ScriptEngines>()->loadScript(fileName); DependencyManager::get<ScriptEngines>()->loadScript(fileName);
} else { } else {
qCDebug(interfaceapp) << "Declined to run the script: " << scriptFilenameOrURL; qCDebug(interfaceapp) << "Declined to run the script: " << scriptFilenameOrURL;
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
}); });
QString message = "Would you like to run this script:\n" + shortName;
OffscreenUi::asyncQuestion(getWindow(), "Run Script", message, QMessageBox::Yes | QMessageBox::No);
return true; return true;
} }
@ -6268,11 +6260,14 @@ bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
name = nameValue.toString(); name = nameValue.toString();
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto avatarAttachmentConfirmationTitle = tr("Avatar Attachment Confirmation");
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) { auto avatarAttachmentConfirmationMessage = tr("Would you like to wear '%1' on your avatar?").arg(name);
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::asyncQuestion(avatarAttachmentConfirmationTitle,
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr); avatarAttachmentConfirmationMessage,
if (answer == QMessageBox::Yes) { QMessageBox::Ok | QMessageBox::Cancel);
QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes) {
// add attachment to avatar // add attachment to avatar
auto myAvatar = getMyAvatar(); auto myAvatar = getMyAvatar();
assert(myAvatar); assert(myAvatar);
@ -6285,12 +6280,6 @@ bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
qCDebug(interfaceapp) << "User declined to wear the avatar attachment: " << url; qCDebug(interfaceapp) << "User declined to wear the avatar attachment: " << url;
} }
}); });
auto avatarAttachmentConfirmationTitle = tr("Avatar Attachment Confirmation");
auto avatarAttachmentConfirmationMessage = tr("Would you like to wear '%1' on your avatar?").arg(name);
OffscreenUi::asyncQuestion(avatarAttachmentConfirmationTitle,
avatarAttachmentConfirmationMessage,
QMessageBox::Ok | QMessageBox::Cancel);
} else { } else {
// json parse error // json parse error
auto avatarAttachmentParseErrorString = tr("Error parsing attachment JSON from url: \"%1\""); auto avatarAttachmentParseErrorString = tr("Error parsing attachment JSON from url: \"%1\"");
@ -6933,17 +6922,17 @@ void Application::openUrl(const QUrl& url) const {
void Application::loadDialog() { void Application::loadDialog() {
auto scriptEngines = DependencyManager::get<ScriptEngines>(); auto scriptEngines = DependencyManager::get<ScriptEngines>();
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"),
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString response) { getPreviousScriptLocation(),
auto offscreenUi = DependencyManager::get<OffscreenUi>(); tr("JavaScript Files (*.js)"));
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, nullptr); connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
const QString& response = answer.toString();
if (!response.isEmpty() && QFile(response).exists()) { if (!response.isEmpty() && QFile(response).exists()) {
setPreviousScriptLocation(QFileInfo(response).absolutePath()); setPreviousScriptLocation(QFileInfo(response).absolutePath());
DependencyManager::get<ScriptEngines>()->loadScript(response, true, false, false, true); // Don't load from cache DependencyManager::get<ScriptEngines>()->loadScript(response, true, false, false, true); // Don't load from cache
} }
}); });
OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"), getPreviousScriptLocation(),
tr("JavaScript Files (*.js)"));
} }
QString Application::getPreviousScriptLocation() { QString Application::getPreviousScriptLocation() {
@ -6956,10 +6945,9 @@ void Application::setPreviousScriptLocation(const QString& location) {
} }
void Application::loadScriptURLDialog() const { void Application::loadScriptURLDialog() const {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getTextAsync(OffscreenUi::ICON_NONE, "Open and Run Script", "Script URL");
connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, [=] (QVariant response) { connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, nullptr); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
const QString& newScript = response.toString(); const QString& newScript = response.toString();
if (QUrl(newScript).scheme() == "atp") { if (QUrl(newScript).scheme() == "atp") {
OffscreenUi::asyncWarning("Error Loading Script", "Cannot load client script over ATP"); OffscreenUi::asyncWarning("Error Loading Script", "Cannot load client script over ATP");
@ -6967,7 +6955,6 @@ void Application::loadScriptURLDialog() const {
DependencyManager::get<ScriptEngines>()->loadScript(newScript.trimmed()); DependencyManager::get<ScriptEngines>()->loadScript(newScript.trimmed());
} }
}); });
OffscreenUi::getTextAsync(OffscreenUi::ICON_NONE, "Open and Run Script", "Script URL");
} }
void Application::loadLODToolsDialog() { void Application::loadLODToolsDialog() {

View file

@ -106,10 +106,9 @@ void AvatarBookmarks::changeToBookmarkedAvatar() {
} }
void AvatarBookmarks::addBookmark() { void AvatarBookmarks::addBookmark() {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getTextAsync(OffscreenUi::ICON_PLACEMARK, "Bookmark Avatar", "Name", QString());
connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, [=] (QVariant response) { connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, nullptr); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
auto bookmarkName = response.toString(); auto bookmarkName = response.toString();
bookmarkName = bookmarkName.trimmed().replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " "); bookmarkName = bookmarkName.trimmed().replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " ");
if (bookmarkName.length() == 0) { if (bookmarkName.length() == 0) {
@ -130,7 +129,7 @@ void AvatarBookmarks::addBookmark() {
Bookmarks::addBookmarkToFile(bookmarkName, *bookmark); Bookmarks::addBookmarkToFile(bookmarkName, *bookmark);
}); });
OffscreenUi::getTextAsync(OffscreenUi::ICON_PLACEMARK, "Bookmark Avatar", "Name", QString());
} }
void AvatarBookmarks::addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& bookmark) { void AvatarBookmarks::addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& bookmark) {

View file

@ -74,10 +74,10 @@ void LocationBookmarks::teleportToBookmark() {
} }
void LocationBookmarks::addBookmark() { void LocationBookmarks::addBookmark() {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getTextAsync(OffscreenUi::ICON_PLACEMARK, "Bookmark Location", "Name", QString());
connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, [=] (QVariant response) {
disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, nullptr); connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
auto bookmarkName = response.toString(); auto bookmarkName = response.toString();
bookmarkName = bookmarkName.trimmed().replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " "); bookmarkName = bookmarkName.trimmed().replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " ");
@ -89,8 +89,6 @@ void LocationBookmarks::addBookmark() {
QString bookmarkAddress = addressManager->currentAddress().toString(); QString bookmarkAddress = addressManager->currentAddress().toString();
Bookmarks::addBookmarkToFile(bookmarkName, bookmarkAddress); Bookmarks::addBookmarkToFile(bookmarkName, bookmarkAddress);
}); });
OffscreenUi::getTextAsync(OffscreenUi::ICON_PLACEMARK, "Bookmark Location", "Name", QString());
} }
void LocationBookmarks::addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& address) { void LocationBookmarks::addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& address) {

View file

@ -42,10 +42,12 @@ static const QString COMPOUND_SHAPE_URL_KEY = "compoundShapeURL";
static const QString MESSAGE_BOX_TITLE = "ATP Asset Migration"; static const QString MESSAGE_BOX_TITLE = "ATP Asset Migration";
void ATPAssetMigrator::loadEntityServerFile() { void ATPAssetMigrator::loadEntityServerFile() {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(_dialogParent, tr("Select an entity-server content file to migrate"),
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString filename) { QString(), tr("Entity-Server Content (*.gz)"));
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, nullptr); connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& filename = response.toString();
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
qCDebug(asset_migrator) << "Selected filename for ATP asset migration: " << filename; qCDebug(asset_migrator) << "Selected filename for ATP asset migration: " << filename;
@ -85,13 +87,12 @@ void ATPAssetMigrator::loadEntityServerFile() {
" current asset-server\nand then save a new entity-server file with the ATP URLs.\n\nAre you ready to"\ " current asset-server\nand then save a new entity-server file with the ATP URLs.\n\nAre you ready to"\
" continue?\n\nMake sure you are connected to the right domain." " continue?\n\nMake sure you are connected to the right domain."
}; };
ModalDialogListener* migrationConfirmDialog = OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE, MIGRATION_CONFIRMATION_TEXT,
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QObject::connect(migrationConfirmDialog, &ModalDialogListener::response, this, [=] (QVariant answer) {
QObject::disconnect(migrationConfirmDialog, &ModalDialogListener::response, this, nullptr);
auto offscreenUi = DependencyManager::get<OffscreenUi>(); if (QMessageBox::Yes == static_cast<QMessageBox::StandardButton>(answer.toInt())) {
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
if (QMessageBox::Yes == answer) {
// try to open the file at the given filename // try to open the file at the given filename
QFile modelsFile { filename }; QFile modelsFile { filename };
@ -148,31 +149,31 @@ void ATPAssetMigrator::loadEntityServerFile() {
"Select \"Yes\" to upload all discovered assets to the current asset-server immediately.\n"\ "Select \"Yes\" to upload all discovered assets to the current asset-server immediately.\n"\
"Select \"No\" to be prompted for each discovered asset." "Select \"No\" to be prompted for each discovered asset."
}; };
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* migrationConfirmDialog1 = OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE,
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) { "Would you like to migrate the following resource?\n" + migrationURL.toString(),
auto offscreenUi = DependencyManager::get<OffscreenUi>(); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
if (answer == QMessageBox::Yes) { QObject::connect(migrationConfirmDialog1, &ModalDialogListener::response, this, [=] (QVariant answer) {
QObject::disconnect(migrationConfirmDialog1, &ModalDialogListener::response, this, nullptr);
if (static_cast<QMessageBox::StandardButton>(answer.toInt()) ==
QMessageBox::Yes) {
wantsCompleteMigration = true; wantsCompleteMigration = true;
migrateResources(migrationURL, jsonValue, isModelURL); migrateResources(migrationURL, jsonValue, isModelURL);
} else { } else {
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) { ModalDialogListener* migrationConfirmDialog2 = OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE, COMPLETE_MIGRATION_TEXT,
auto offscreenUi = DependencyManager::get<OffscreenUi>(); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
if (answer == QMessageBox::Yes) { QObject::connect(migrationConfirmDialog2, &ModalDialogListener::response, this, [=] (QVariant answer) {
QObject::disconnect(migrationConfirmDialog2, &ModalDialogListener::response, this, nullptr);
if (static_cast<QMessageBox::StandardButton>(answer.toInt()) ==
QMessageBox::Yes) {
migrateResources(migrationURL, jsonValue, isModelURL); migrateResources(migrationURL, jsonValue, isModelURL);
} else { } else {
_ignoredUrls.insert(migrationURL); _ignoredUrls.insert(migrationURL);
} }
}); });
OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE,
"Would you like to migrate the following resource?\n" + migrationURL.toString(),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
} }
}); });
OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE, COMPLETE_MIGRATION_TEXT,
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
hasAskedForCompleteMigration = true; hasAskedForCompleteMigration = true;
} }
if (wantsCompleteMigration) { if (wantsCompleteMigration) {
@ -194,13 +195,8 @@ void ATPAssetMigrator::loadEntityServerFile() {
} }
} }
}); });
OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE, MIGRATION_CONFIRMATION_TEXT,
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
} }
}); });
OffscreenUi::getOpenFileNameAsync(_dialogParent, tr("Select an entity-server content file to migrate"),
QString(), tr("Entity-Server Content (*.gz)"));
} }
void ATPAssetMigrator::migrateResource(ResourceRequest* request) { void ATPAssetMigrator::migrateResource(ResourceRequest* request) {
@ -333,8 +329,9 @@ bool ATPAssetMigrator::wantsToMigrateResource(const QUrl& url) {
void ATPAssetMigrator::saveEntityServerFile() { void ATPAssetMigrator::saveEntityServerFile() {
// show a dialog to ask the user where they want to save the file // show a dialog to ask the user where they want to save the file
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getSaveFileNameAsync(_dialogParent, "Save Migrated Entities File");
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString saveName) { connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& saveName = response.toString();
QFile saveFile { saveName }; QFile saveFile { saveName };
if (saveFile.open(QIODevice::WriteOnly)) { if (saveFile.open(QIODevice::WriteOnly)) {
@ -369,9 +366,6 @@ void ATPAssetMigrator::saveEntityServerFile() {
// reset after the attempted save, success or fail // reset after the attempted save, success or fail
reset(); reset();
}); });
OffscreenUi::getSaveFileNameAsync(_dialogParent, "Save Migrated Entities File");
} }
void ATPAssetMigrator::reset() { void ATPAssetMigrator::reset() {

View file

@ -127,16 +127,13 @@ QScriptValue WindowScriptingInterface::prompt(const QString& message, const QStr
/// \param const QString& message message to display /// \param const QString& message message to display
/// \param const QString& defaultText default text in the text box /// \param const QString& defaultText default text in the text box
void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) { void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText);
connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, connect(dlg, &ModalDialogListener::response, this, [=] (QVariant result) {
this, [=] (QVariant result) { disconnect(dlg, &ModalDialogListener::response, this, nullptr);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse,
this, nullptr);
emit promptTextChanged(result.toString()); emit promptTextChanged(result.toString());
}); });
OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText);
} }
CustomPromptResult WindowScriptingInterface::customPrompt(const QVariant& config) { CustomPromptResult WindowScriptingInterface::customPrompt(const QVariant& config) {
@ -221,19 +218,15 @@ void WindowScriptingInterface::browseDirAsync(const QString& title, const QStrin
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
path = fixupPathForMac(directory); path = fixupPathForMac(directory);
#endif #endif
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
this, [=] (QString result) { const QString& result = response.toString();
auto offscreenUi = DependencyManager::get<OffscreenUi>(); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, nullptr);
if (!result.isEmpty()) { if (!result.isEmpty()) {
setPreviousBrowseLocation(QFileInfo(result).absolutePath()); setPreviousBrowseLocation(QFileInfo(result).absolutePath());
} }
emit browseDirChanged(result); emit browseDirChanged(result);
}); });
OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
} }
/// \param const QString& title title of the window /// \param const QString& title title of the window
@ -270,19 +263,17 @@ void WindowScriptingInterface::browseAsync(const QString& title, const QString&
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
path = fixupPathForMac(directory); path = fixupPathForMac(directory);
#endif #endif
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
this, [=] (QString result) { const QString& result = response.toString();
auto offscreenUi = DependencyManager::get<OffscreenUi>(); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, nullptr);
if (!result.isEmpty()) { if (!result.isEmpty()) {
setPreviousBrowseLocation(QFileInfo(result).absolutePath()); setPreviousBrowseLocation(QFileInfo(result).absolutePath());
} }
emit openFileChanged(result); emit openFileChanged(result);
}); });
OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
} }
/// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current /// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current
@ -321,19 +312,17 @@ void WindowScriptingInterface::saveAsync(const QString& title, const QString& di
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
path = fixupPathForMac(directory); path = fixupPathForMac(directory);
#endif #endif
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter);
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
this, [=] (QString result) { const QString& result = response.toString();
auto offscreenUi = DependencyManager::get<OffscreenUi>(); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, nullptr);
if (!result.isEmpty()) { if (!result.isEmpty()) {
setPreviousBrowseLocation(QFileInfo(result).absolutePath()); setPreviousBrowseLocation(QFileInfo(result).absolutePath());
} }
emit saveFileChanged(result); emit saveFileChanged(result);
}); });
OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter);
} }
/// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid /// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid
@ -379,19 +368,15 @@ void WindowScriptingInterface::browseAssetsAsync(const QString& title, const QSt
path = path + "/"; path = path + "/";
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); ModalDialogListener* dlg = OffscreenUi::getOpenAssetNameAsync(nullptr, title, path, nameFilter);
connect(offscreenUi.data(), &OffscreenUi::assetDialogResponse, connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
this, [=] (QString result) { const QString& result = response.toString();
auto offscreenUi = DependencyManager::get<OffscreenUi>(); disconnect(dlg, &ModalDialogListener::response, this, nullptr);
disconnect(offscreenUi.data(), &OffscreenUi::assetDialogResponse,
this, nullptr);
if (!result.isEmpty()) { if (!result.isEmpty()) {
setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath()); setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath());
} }
emit assetsDirChanged(result); emit assetsDirChanged(result);
}); });
OffscreenUi::getOpenAssetNameAsync(nullptr, title, path, nameFilter);
} }
void WindowScriptingInterface::showAssetServer(const QString& upload) { void WindowScriptingInterface::showAssetServer(const QString& upload) {

View file

@ -151,45 +151,6 @@ bool OffscreenUi::isVisible(const QString& name) {
} }
} }
class ModalDialogListener : public QObject {
Q_OBJECT
friend class OffscreenUi;
protected:
ModalDialogListener(QQuickItem* dialog) : _dialog(dialog) {
if (!dialog) {
_finished = true;
return;
}
connect(_dialog, SIGNAL(destroyed()), this, SLOT(onDestroyed()));
}
~ModalDialogListener() {
if (_dialog) {
disconnect(_dialog);
}
}
virtual QVariant waitForResult() {
while (!_finished) {
QCoreApplication::processEvents();
}
return _result;
}
protected slots:
void onDestroyed() {
_finished = true;
disconnect(_dialog);
_dialog = nullptr;
}
protected:
QQuickItem* _dialog;
bool _finished { false };
QVariant _result;
};
class MessageBoxListener : public ModalDialogListener { class MessageBoxListener : public ModalDialogListener {
Q_OBJECT Q_OBJECT
@ -211,7 +172,7 @@ private slots:
_result = button; _result = button;
_finished = true; _finished = true;
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->response(static_cast<QMessageBox::StandardButton>(_result.toInt())); emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this)); offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
disconnect(_dialog); disconnect(_dialog);
} }
@ -272,19 +233,23 @@ QMessageBox::StandardButton OffscreenUi::messageBox(Icon icon, const QString& ti
return static_cast<QMessageBox::StandardButton>(waitForMessageBoxResult(createMessageBox(icon, title, text, buttons, defaultButton))); return static_cast<QMessageBox::StandardButton>(waitForMessageBoxResult(createMessageBox(icon, title, text, buttons, defaultButton)));
} }
void OffscreenUi::asyncMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { ModalDialogListener* OffscreenUi::asyncMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "asyncMessageBox", BLOCKING_INVOKE_METHOD(this, "asyncMessageBox",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(Icon, icon), Q_ARG(Icon, icon),
Q_ARG(QString, title), Q_ARG(QString, title),
Q_ARG(QString, text), Q_ARG(QString, text),
Q_ARG(QMessageBox::StandardButtons, buttons), Q_ARG(QMessageBox::StandardButtons, buttons),
Q_ARG(QMessageBox::StandardButton, defaultButton)); Q_ARG(QMessageBox::StandardButton, defaultButton));
return ret;
} }
MessageBoxListener* messageBoxListener = new MessageBoxListener(createMessageBox(icon, title, text, buttons, defaultButton)); MessageBoxListener* messageBoxListener = new MessageBoxListener(createMessageBox(icon, title, text, buttons, defaultButton));
QObject* modalDialog = qobject_cast<QObject*>(messageBoxListener); QObject* modalDialog = qobject_cast<QObject*>(messageBoxListener);
_modalDialogListeners.push_back(modalDialog); _modalDialogListeners.push_back(modalDialog);
return messageBoxListener;
} }
QMessageBox::StandardButton OffscreenUi::critical(const QString& title, const QString& text, QMessageBox::StandardButton OffscreenUi::critical(const QString& title, const QString& text,
@ -296,31 +261,34 @@ QMessageBox::StandardButton OffscreenUi::information(const QString& title, const
return DependencyManager::get<OffscreenUi>()->messageBox(OffscreenUi::Icon::ICON_INFORMATION, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->messageBox(OffscreenUi::Icon::ICON_INFORMATION, title, text, buttons, defaultButton);
} }
void OffscreenUi::asyncCritical(const QString& title, const QString& text, ModalDialogListener* OffscreenUi::asyncCritical(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_CRITICAL, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_CRITICAL, title, text, buttons, defaultButton);
} }
void OffscreenUi::asyncInformation(const QString& title, const QString& text, ModalDialogListener* OffscreenUi::asyncInformation(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_INFORMATION, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_INFORMATION, title, text, buttons, defaultButton);
} }
QMessageBox::StandardButton OffscreenUi::question(const QString& title, const QString& text, QMessageBox::StandardButton OffscreenUi::question(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
return DependencyManager::get<OffscreenUi>()->messageBox(OffscreenUi::Icon::ICON_QUESTION, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->messageBox(OffscreenUi::Icon::ICON_QUESTION, title, text, buttons, defaultButton);
} }
void OffscreenUi::asyncQuestion(const QString& title, const QString& text,
ModalDialogListener *OffscreenUi::asyncQuestion(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_QUESTION, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_QUESTION, title, text, buttons, defaultButton);
} }
QMessageBox::StandardButton OffscreenUi::warning(const QString& title, const QString& text, QMessageBox::StandardButton OffscreenUi::warning(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
return DependencyManager::get<OffscreenUi>()->messageBox(OffscreenUi::Icon::ICON_WARNING, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->messageBox(OffscreenUi::Icon::ICON_WARNING, title, text, buttons, defaultButton);
} }
void OffscreenUi::asyncWarning(const QString& title, const QString& text,
ModalDialogListener* OffscreenUi::asyncWarning(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_WARNING, title, text, buttons, defaultButton); return DependencyManager::get<OffscreenUi>()->asyncMessageBox(OffscreenUi::Icon::ICON_WARNING, title, text, buttons, defaultButton);
} }
@ -338,8 +306,8 @@ class InputDialogListener : public ModalDialogListener {
private slots: private slots:
void onSelected(const QVariant& result) { void onSelected(const QVariant& result) {
_result = result; _result = result;
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->inputDialogResponse(_result); emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this)); offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
_finished = true; _finished = true;
disconnect(_dialog); disconnect(_dialog);
@ -394,17 +362,17 @@ QVariant OffscreenUi::getCustomInfo(const Icon icon, const QString& title, const
return result; return result;
} }
void OffscreenUi::getTextAsync(const Icon icon, const QString& title, const QString& label, const QString& text) { ModalDialogListener* OffscreenUi::getTextAsync(const Icon icon, const QString& title, const QString& label, const QString& text) {
DependencyManager::get<OffscreenUi>()->inputDialogAsync(icon, title, label, text); return DependencyManager::get<OffscreenUi>()->inputDialogAsync(icon, title, label, text);
} }
void OffscreenUi::getItemAsync(const Icon icon, const QString& title, const QString& label, const QStringList& items, ModalDialogListener* OffscreenUi::getItemAsync(const Icon icon, const QString& title, const QString& label, const QStringList& items,
int current, bool editable) { int current, bool editable) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUi = DependencyManager::get<OffscreenUi>();
auto inputDialog = offscreenUi->createInputDialog(icon, title, label, current); auto inputDialog = offscreenUi->createInputDialog(icon, title, label, current);
if (!inputDialog) { if (!inputDialog) {
return; return nullptr;
} }
inputDialog->setProperty("items", items); inputDialog->setProperty("items", items);
inputDialog->setProperty("editable", editable); inputDialog->setProperty("editable", editable);
@ -412,11 +380,11 @@ void OffscreenUi::getItemAsync(const Icon icon, const QString& title, const QStr
InputDialogListener* inputDialogListener = new InputDialogListener(inputDialog); InputDialogListener* inputDialogListener = new InputDialogListener(inputDialog);
offscreenUi->getModalDialogListeners().push_back(qobject_cast<QObject*>(inputDialogListener)); offscreenUi->getModalDialogListeners().push_back(qobject_cast<QObject*>(inputDialogListener));
return; return inputDialogListener;
} }
void OffscreenUi::getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config) { ModalDialogListener* OffscreenUi::getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config) {
DependencyManager::get<OffscreenUi>()->customInputDialog(icon, title, config); return DependencyManager::get<OffscreenUi>()->customInputDialogAsync(icon, title, config);
} }
QVariant OffscreenUi::inputDialog(const Icon icon, const QString& title, const QString& label, const QVariant& current) { QVariant OffscreenUi::inputDialog(const Icon icon, const QString& title, const QString& label, const QVariant& current) {
@ -434,19 +402,22 @@ QVariant OffscreenUi::inputDialog(const Icon icon, const QString& title, const Q
return waitForInputDialogResult(createInputDialog(icon, title, label, current)); return waitForInputDialogResult(createInputDialog(icon, title, label, current));
} }
void OffscreenUi::inputDialogAsync(const Icon icon, const QString& title, const QString& label, const QVariant& current) { ModalDialogListener* OffscreenUi::inputDialogAsync(const Icon icon, const QString& title, const QString& label, const QVariant& current) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "inputDialogAsync", BLOCKING_INVOKE_METHOD(this, "inputDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(Icon, icon), Q_ARG(Icon, icon),
Q_ARG(QString, title), Q_ARG(QString, title),
Q_ARG(QString, label), Q_ARG(QString, label),
Q_ARG(QVariant, current)); Q_ARG(QVariant, current));
return; return ret;
} }
InputDialogListener* inputDialogListener = new InputDialogListener(createInputDialog(icon, title, label, current)); InputDialogListener* inputDialogListener = new InputDialogListener(createInputDialog(icon, title, label, current));
QObject* inputDialog = qobject_cast<QObject*>(inputDialogListener); QObject* inputDialog = qobject_cast<QObject*>(inputDialogListener);
_modalDialogListeners.push_back(inputDialog); _modalDialogListeners.push_back(inputDialog);
return inputDialogListener;
} }
QVariant OffscreenUi::customInputDialog(const Icon icon, const QString& title, const QVariantMap& config) { QVariant OffscreenUi::customInputDialog(const Icon icon, const QString& title, const QVariantMap& config) {
@ -469,19 +440,21 @@ QVariant OffscreenUi::customInputDialog(const Icon icon, const QString& title, c
return result; return result;
} }
void OffscreenUi::customInputDialogAsync(const Icon icon, const QString& title, const QVariantMap& config) { ModalDialogListener* OffscreenUi::customInputDialogAsync(const Icon icon, const QString& title, const QVariantMap& config) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "customInputDialogAsync", BLOCKING_INVOKE_METHOD(this, "customInputDialogAsync",
Q_ARG(Icon, icon), Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, title), Q_ARG(Icon, icon),
Q_ARG(QVariantMap, config)); Q_ARG(QString, title),
return; Q_ARG(QVariantMap, config));
return ret;
} }
InputDialogListener* inputDialogListener = new InputDialogListener(createCustomInputDialog(icon, title, config)); InputDialogListener* inputDialogListener = new InputDialogListener(createCustomInputDialog(icon, title, config));
QObject* inputDialog = qobject_cast<QObject*>(inputDialogListener); QObject* inputDialog = qobject_cast<QObject*>(inputDialogListener);
_modalDialogListeners.push_back(inputDialog); _modalDialogListeners.push_back(inputDialog);
return; return inputDialogListener;
} }
void OffscreenUi::togglePinned() { void OffscreenUi::togglePinned() {
@ -655,6 +628,7 @@ void OffscreenUi::createDesktop(const QUrl& url) {
#endif #endif
load(url, [=](QQmlContext* context, QObject* newObject) { load(url, [=](QQmlContext* context, QObject* newObject) {
Q_UNUSED(context)
_desktop = static_cast<QQuickItem*>(newObject); _desktop = static_cast<QQuickItem*>(newObject);
getSurfaceContext()->setContextProperty("desktop", _desktop); getSurfaceContext()->setContextProperty("desktop", _desktop);
_toolWindow = _desktop->findChild<QQuickItem*>("ToolWindow"); _toolWindow = _desktop->findChild<QQuickItem*>("ToolWindow");
@ -703,7 +677,7 @@ private slots:
_result = file; _result = file;
_finished = true; _finished = true;
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->fileDialogResponse(_result.toUrl().toLocalFile()); emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this)); offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
disconnect(_dialog); disconnect(_dialog);
} }
@ -740,7 +714,7 @@ QString OffscreenUi::fileDialog(const QVariantMap& properties) {
return result.toUrl().toLocalFile(); return result.toUrl().toLocalFile();
} }
void OffscreenUi::fileDialogAsync(const QVariantMap& properties) { ModalDialogListener* OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
QVariant buildDialogResult; QVariant buildDialogResult;
bool invokeResult; bool invokeResult;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
@ -759,14 +733,14 @@ void OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
if (!invokeResult) { if (!invokeResult) {
qWarning() << "Failed to create file open dialog"; qWarning() << "Failed to create file open dialog";
return; return nullptr;
} }
FileDialogListener* fileDialogListener = new FileDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult)); FileDialogListener* fileDialogListener = new FileDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult));
QObject* fileModalDialog = qobject_cast<QObject*>(fileDialogListener); QObject* fileModalDialog = qobject_cast<QObject*>(fileDialogListener);
_modalDialogListeners.push_back(fileModalDialog); _modalDialogListeners.push_back(fileModalDialog);
return; return fileDialogListener;
} }
QString OffscreenUi::fileOpenDialog(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) { QString OffscreenUi::fileOpenDialog(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
@ -791,15 +765,17 @@ QString OffscreenUi::fileOpenDialog(const QString& caption, const QString& dir,
return fileDialog(map); return fileDialog(map);
} }
void OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "fileOpenDialogAsync", BLOCKING_INVOKE_METHOD(this, "fileOpenDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption), Q_ARG(QString, caption),
Q_ARG(QString, dir), Q_ARG(QString, dir),
Q_ARG(QString, filter), Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter), Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options)); Q_ARG(QFileDialog::Options, options));
return; return ret;
} }
// FIXME support returning the selected filter... somehow? // FIXME support returning the selected filter... somehow?
@ -808,7 +784,7 @@ void OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString& dir
map.insert("dir", QUrl::fromLocalFile(dir)); map.insert("dir", QUrl::fromLocalFile(dir));
map.insert("filter", filter); map.insert("filter", filter);
map.insert("options", static_cast<int>(options)); map.insert("options", static_cast<int>(options));
fileDialogAsync(map); return fileDialogAsync(map);
} }
QString OffscreenUi::fileSaveDialog(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) { QString OffscreenUi::fileSaveDialog(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
@ -835,15 +811,17 @@ QString OffscreenUi::fileSaveDialog(const QString& caption, const QString& dir,
return fileDialog(map); return fileDialog(map);
} }
void OffscreenUi::fileSaveDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::fileSaveDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "fileSaveDialogAsync", BLOCKING_INVOKE_METHOD(this, "fileSaveDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption), Q_ARG(QString, caption),
Q_ARG(QString, dir), Q_ARG(QString, dir),
Q_ARG(QString, filter), Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter), Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options)); Q_ARG(QFileDialog::Options, options));
return; return ret;
} }
// FIXME support returning the selected filter... somehow? // FIXME support returning the selected filter... somehow?
@ -879,15 +857,17 @@ QString OffscreenUi::existingDirectoryDialog(const QString& caption, const QStri
return fileDialog(map); return fileDialog(map);
} }
void OffscreenUi::existingDirectoryDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::existingDirectoryDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "existingDirectoryDialogAsync", BLOCKING_INVOKE_METHOD(this, "existingDirectoryDialogAsync",
Q_ARG(QString, caption), Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, dir), Q_ARG(QString, caption),
Q_ARG(QString, filter), Q_ARG(QString, dir),
Q_ARG(QString*, selectedFilter), Q_ARG(QString, filter),
Q_ARG(QFileDialog::Options, options)); Q_ARG(QString*, selectedFilter),
return; Q_ARG(QFileDialog::Options, options));
return ret;
} }
QVariantMap map; QVariantMap map;
@ -900,26 +880,32 @@ void OffscreenUi::existingDirectoryDialogAsync(const QString& caption, const QSt
} }
QString OffscreenUi::getOpenFileName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { QString OffscreenUi::getOpenFileName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->fileOpenDialog(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->fileOpenDialog(caption, dir, filter, selectedFilter, options);
} }
void OffscreenUi::getOpenFileNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::getOpenFileNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->fileOpenDialogAsync(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->fileOpenDialogAsync(caption, dir, filter, selectedFilter, options);
} }
QString OffscreenUi::getSaveFileName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { QString OffscreenUi::getSaveFileName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->fileSaveDialog(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->fileSaveDialog(caption, dir, filter, selectedFilter, options);
} }
void OffscreenUi::getSaveFileNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::getSaveFileNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->fileSaveDialogAsync(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->fileSaveDialogAsync(caption, dir, filter, selectedFilter, options);
} }
QString OffscreenUi::getExistingDirectory(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { QString OffscreenUi::getExistingDirectory(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->existingDirectoryDialog(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->existingDirectoryDialog(caption, dir, filter, selectedFilter, options);
} }
void OffscreenUi::getExistingDirectoryAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::getExistingDirectoryAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->existingDirectoryDialogAsync(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->existingDirectoryDialogAsync(caption, dir, filter, selectedFilter, options);
} }
@ -939,7 +925,7 @@ class AssetDialogListener : public ModalDialogListener {
void onSelectedAsset(QVariant asset) { void onSelectedAsset(QVariant asset) {
_result = asset; _result = asset;
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->assetDialogResponse(_result.toUrl().toLocalFile()); emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this)); offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
_finished = true; _finished = true;
disconnect(_dialog); disconnect(_dialog);
@ -978,7 +964,7 @@ QString OffscreenUi::assetDialog(const QVariantMap& properties) {
return result.toUrl().toString(); return result.toUrl().toString();
} }
void OffscreenUi::assetDialogAsync(const QVariantMap& properties) { ModalDialogListener *OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
// ATP equivalent of fileDialog(). // ATP equivalent of fileDialog().
QVariant buildDialogResult; QVariant buildDialogResult;
bool invokeResult; bool invokeResult;
@ -998,13 +984,13 @@ void OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
if (!invokeResult) { if (!invokeResult) {
qWarning() << "Failed to create asset open dialog"; qWarning() << "Failed to create asset open dialog";
return; return nullptr;
} }
AssetDialogListener* assetDialogListener = new AssetDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult)); AssetDialogListener* assetDialogListener = new AssetDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult));
QObject* assetModalDialog = qobject_cast<QObject*>(assetDialogListener); QObject* assetModalDialog = qobject_cast<QObject*>(assetDialogListener);
_modalDialogListeners.push_back(assetModalDialog); _modalDialogListeners.push_back(assetModalDialog);
return; return assetDialogListener;
} }
QList<QObject *> &OffscreenUi::getModalDialogListeners() { QList<QObject *> &OffscreenUi::getModalDialogListeners() {
@ -1034,16 +1020,18 @@ QString OffscreenUi::assetOpenDialog(const QString& caption, const QString& dir,
return assetDialog(map); return assetDialog(map);
} }
void OffscreenUi::assetOpenDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::assetOpenDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
// ATP equivalent of fileOpenDialog(). // ATP equivalent of fileOpenDialog().
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "assetOpenDialogAsync", BLOCKING_INVOKE_METHOD(this, "assetOpenDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption), Q_ARG(QString, caption),
Q_ARG(QString, dir), Q_ARG(QString, dir),
Q_ARG(QString, filter), Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter), Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options)); Q_ARG(QFileDialog::Options, options));
return; return ret;
} }
// FIXME support returning the selected filter... somehow? // FIXME support returning the selected filter... somehow?
@ -1057,11 +1045,13 @@ void OffscreenUi::assetOpenDialogAsync(const QString& caption, const QString& di
QString OffscreenUi::getOpenAssetName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { QString OffscreenUi::getOpenAssetName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
// ATP equivalent of getOpenFileName(). // ATP equivalent of getOpenFileName().
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->assetOpenDialog(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->assetOpenDialog(caption, dir, filter, selectedFilter, options);
} }
void OffscreenUi::getOpenAssetNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { ModalDialogListener* OffscreenUi::getOpenAssetNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
// ATP equivalent of getOpenFileName(). // ATP equivalent of getOpenFileName().
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->assetOpenDialogAsync(caption, dir, filter, selectedFilter, options); return DependencyManager::get<OffscreenUi>()->assetOpenDialogAsync(caption, dir, filter, selectedFilter, options);
} }
@ -1104,5 +1094,31 @@ unsigned int OffscreenUi::getMenuUserDataId() const {
return _vrMenu->_userDataId; return _vrMenu->_userDataId;
} }
#include "OffscreenUi.moc" ModalDialogListener::ModalDialogListener(QQuickItem *dialog) : _dialog(dialog) {
if (!dialog) {
_finished = true;
return;
}
connect(_dialog, SIGNAL(destroyed()), this, SLOT(onDestroyed()));
}
ModalDialogListener::~ModalDialogListener() {
if (_dialog) {
disconnect(_dialog);
}
}
QVariant ModalDialogListener::waitForResult() {
while (!_finished) {
QCoreApplication::processEvents();
}
return _result;
}
void ModalDialogListener::onDestroyed() {
_finished = true;
disconnect(_dialog);
_dialog = nullptr;
}
#include "OffscreenUi.moc"

View file

@ -30,6 +30,27 @@ class VrMenu;
#define OFFSCREEN_VISIBILITY_PROPERTY "shown" #define OFFSCREEN_VISIBILITY_PROPERTY "shown"
class ModalDialogListener : public QObject {
Q_OBJECT
friend class OffscreenUi;
protected:
ModalDialogListener(QQuickItem* dialog);
virtual ~ModalDialogListener();
virtual QVariant waitForResult();
signals:
void response(const QVariant& value);
protected slots:
void onDestroyed();
protected:
QQuickItem* _dialog;
bool _finished { false };
QVariant _result;
};
class OffscreenUi : public OffscreenQmlSurface, public Dependency { class OffscreenUi : public OffscreenQmlSurface, public Dependency {
Q_OBJECT Q_OBJECT
@ -71,7 +92,7 @@ public:
// Message box compatibility // Message box compatibility
Q_INVOKABLE QMessageBox::StandardButton messageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton); Q_INVOKABLE QMessageBox::StandardButton messageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
Q_INVOKABLE void asyncMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton); Q_INVOKABLE ModalDialogListener* asyncMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
// Must be called from the main thread // Must be called from the main thread
QQuickItem* createMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton); QQuickItem* createMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
// Must be called from the main thread // Must be called from the main thread
@ -89,12 +110,12 @@ public:
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) { QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
return information(title, text, buttons, defaultButton); return information(title, text, buttons, defaultButton);
} }
static void asyncCritical(void* ignored, const QString& title, const QString& text, static ModalDialogListener* asyncCritical(void* ignored, const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) { QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncCritical(title, text, buttons, defaultButton); return asyncCritical(title, text, buttons, defaultButton);
} }
static void asyncInformation(void* ignored, const QString& title, const QString& text, static ModalDialogListener* asyncInformation(void* ignored, const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) { QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncInformation(title, text, buttons, defaultButton); return asyncInformation(title, text, buttons, defaultButton);
@ -106,7 +127,7 @@ public:
return question(title, text, buttons, defaultButton); return question(title, text, buttons, defaultButton);
} }
static void asyncQuestion(void* ignored, const QString& title, const QString& text, static ModalDialogListener* asyncQuestion(void* ignored, const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) { QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncQuestion(title, text, buttons, defaultButton); return asyncQuestion(title, text, buttons, defaultButton);
@ -117,7 +138,7 @@ public:
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) { QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
return warning(title, text, buttons, defaultButton); return warning(title, text, buttons, defaultButton);
} }
static void asyncWarning(void* ignored, const QString& title, const QString& text, static ModalDialogListener* asyncWarning(void* ignored, const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) { QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncWarning(title, text, buttons, defaultButton); return asyncWarning(title, text, buttons, defaultButton);
@ -129,53 +150,55 @@ public:
static QMessageBox::StandardButton information(const QString& title, const QString& text, static QMessageBox::StandardButton information(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static void asyncCritical(const QString& title, const QString& text, static ModalDialogListener* asyncCritical(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static void asyncInformation(const QString& title, const QString& text, static ModalDialogListener *asyncInformation(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton question(const QString& title, const QString& text, static QMessageBox::StandardButton question(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static void asyncQuestion (const QString& title, const QString& text, static ModalDialogListener* asyncQuestion (const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton warning(const QString& title, const QString& text, static QMessageBox::StandardButton warning(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static void asyncWarning(const QString& title, const QString& text, static ModalDialogListener *asyncWarning(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
Q_INVOKABLE QString fileOpenDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE QString fileOpenDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE void fileOpenDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE ModalDialogListener* fileOpenDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE QString fileSaveDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE QString fileSaveDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE void fileSaveDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE ModalDialogListener* fileSaveDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE QString existingDirectoryDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE QString existingDirectoryDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE void existingDirectoryDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE ModalDialogListener* existingDirectoryDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE QString assetOpenDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE QString assetOpenDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE void assetOpenDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); Q_INVOKABLE ModalDialogListener* assetOpenDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
// Compatibility with QFileDialog::getOpenFileName // Compatibility with QFileDialog::getOpenFileName
static QString getOpenFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static QString getOpenFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
static void getOpenFileNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static ModalDialogListener* getOpenFileNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
// Compatibility with QFileDialog::getSaveFileName // Compatibility with QFileDialog::getSaveFileName
static QString getSaveFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static QString getSaveFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
static void getSaveFileNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static ModalDialogListener* getSaveFileNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
// Compatibility with QFileDialog::getExistingDirectory // Compatibility with QFileDialog::getExistingDirectory
static QString getExistingDirectory(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static QString getExistingDirectory(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
static void getExistingDirectoryAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static ModalDialogListener* getExistingDirectoryAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
static QString getOpenAssetName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static QString getOpenAssetName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
static void getOpenAssetNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0); static ModalDialogListener* getOpenAssetNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
Q_INVOKABLE QVariant inputDialog(const Icon icon, const QString& title, const QString& label = QString(), const QVariant& current = QVariant()); Q_INVOKABLE QVariant inputDialog(const Icon icon, const QString& title, const QString& label = QString(), const QVariant& current = QVariant());
Q_INVOKABLE void inputDialogAsync(const Icon icon, const QString& title, const QString& label = QString(), const QVariant& current = QVariant()); Q_INVOKABLE ModalDialogListener* inputDialogAsync(const Icon icon, const QString& title, const QString& label = QString(), const QVariant& current = QVariant());
Q_INVOKABLE QVariant customInputDialog(const Icon icon, const QString& title, const QVariantMap& config); Q_INVOKABLE QVariant customInputDialog(const Icon icon, const QString& title, const QVariantMap& config);
Q_INVOKABLE void customInputDialogAsync(const Icon icon, const QString& title, const QVariantMap& config); Q_INVOKABLE ModalDialogListener* customInputDialogAsync(const Icon icon, const QString& title, const QVariantMap& config);
QQuickItem* createInputDialog(const Icon icon, const QString& title, const QString& label, const QVariant& current); QQuickItem* createInputDialog(const Icon icon, const QString& title, const QString& label, const QVariant& current);
QQuickItem* createCustomInputDialog(const Icon icon, const QString& title, const QVariantMap& config); QQuickItem* createCustomInputDialog(const Icon icon, const QString& title, const QVariantMap& config);
QVariant waitForInputDialogResult(QQuickItem* inputDialog); QVariant waitForInputDialogResult(QQuickItem* inputDialog);
@ -194,13 +217,13 @@ public:
} }
// Compatibility with QInputDialog::getText // Compatibility with QInputDialog::getText
static void getTextAsync(void* ignored, const QString & title, const QString & label, static ModalDialogListener* getTextAsync(void* ignored, const QString & title, const QString & label,
QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0,
Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone) { Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone) {
return getTextAsync(OffscreenUi::ICON_NONE, title, label, text); return getTextAsync(OffscreenUi::ICON_NONE, title, label, text);
} }
// Compatibility with QInputDialog::getItem // Compatibility with QInputDialog::getItem
static void getItemAsync(void *ignored, const QString & title, const QString & label, const QStringList & items, static ModalDialogListener* getItemAsync(void *ignored, const QString & title, const QString & label, const QStringList & items,
int current = 0, bool editable = true, bool * ok = 0, Qt::WindowFlags flags = 0, int current = 0, bool editable = true, bool * ok = 0, Qt::WindowFlags flags = 0,
Qt::InputMethodHints inputMethodHints = Qt::ImhNone) { Qt::InputMethodHints inputMethodHints = Qt::ImhNone) {
return getItemAsync(OffscreenUi::ICON_NONE, title, label, items, current, editable); return getItemAsync(OffscreenUi::ICON_NONE, title, label, items, current, editable);
@ -209,27 +232,27 @@ public:
static QString getText(const Icon icon, const QString & title, const QString & label, const QString & text = QString(), bool * ok = 0); static QString getText(const Icon icon, const QString & title, const QString & label, const QString & text = QString(), bool * ok = 0);
static QString getItem(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true, bool * ok = 0); static QString getItem(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true, bool * ok = 0);
static QVariant getCustomInfo(const Icon icon, const QString& title, const QVariantMap& config, bool* ok = 0); static QVariant getCustomInfo(const Icon icon, const QString& title, const QVariantMap& config, bool* ok = 0);
static void getTextAsync(const Icon icon, const QString & title, const QString & label, const QString & text = QString()); static ModalDialogListener* getTextAsync(const Icon icon, const QString & title, const QString & label, const QString & text = QString());
static void getItemAsync(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true); static ModalDialogListener* getItemAsync(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true);
static void getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config); static ModalDialogListener* getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config);
unsigned int getMenuUserDataId() const; unsigned int getMenuUserDataId() const;
QList<QObject *> &getModalDialogListeners(); QList<QObject *> &getModalDialogListeners();
signals: signals:
void showDesktop(); void showDesktop();
void response(QMessageBox::StandardButton response); // void response(QMessageBox::StandardButton response);
void fileDialogResponse(QString response); // void fileDialogResponse(QString response);
void assetDialogResponse(QString response); // void assetDialogResponse(QString response);
void inputDialogResponse(QVariant response); // void inputDialogResponse(QVariant response);
public slots: public slots:
void removeModalDialog(QObject* modal); void removeModalDialog(QObject* modal);
private: private:
QString fileDialog(const QVariantMap& properties); QString fileDialog(const QVariantMap& properties);
void fileDialogAsync(const QVariantMap &properties); ModalDialogListener *fileDialogAsync(const QVariantMap &properties);
QString assetDialog(const QVariantMap& properties); QString assetDialog(const QVariantMap& properties);
void assetDialogAsync(const QVariantMap& properties); ModalDialogListener* assetDialogAsync(const QVariantMap& properties);
QQuickItem* _desktop { nullptr }; QQuickItem* _desktop { nullptr };
QQuickItem* _toolWindow { nullptr }; QQuickItem* _toolWindow { nullptr };