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

View file

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

View file

@ -74,10 +74,10 @@ void LocationBookmarks::teleportToBookmark() {
}
void LocationBookmarks::addBookmark() {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, [=] (QVariant response) {
disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, nullptr);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
ModalDialogListener* dlg = OffscreenUi::getTextAsync(OffscreenUi::ICON_PLACEMARK, "Bookmark Location", "Name", QString());
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
auto bookmarkName = response.toString();
bookmarkName = bookmarkName.trimmed().replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " ");
@ -89,8 +89,6 @@ void LocationBookmarks::addBookmark() {
QString bookmarkAddress = addressManager->currentAddress().toString();
Bookmarks::addBookmarkToFile(bookmarkName, bookmarkAddress);
});
OffscreenUi::getTextAsync(OffscreenUi::ICON_PLACEMARK, "Bookmark Location", "Name", QString());
}
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";
void ATPAssetMigrator::loadEntityServerFile() {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString filename) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, nullptr);
ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(_dialogParent, tr("Select an entity-server content file to migrate"),
QString(), tr("Entity-Server Content (*.gz)"));
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& filename = response.toString();
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (!filename.isEmpty()) {
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"\
" 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>();
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) {
if (QMessageBox::Yes == static_cast<QMessageBox::StandardButton>(answer.toInt())) {
// try to open the file at the given 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 \"No\" to be prompted for each discovered asset."
};
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
if (answer == QMessageBox::Yes) {
ModalDialogListener* migrationConfirmDialog1 = OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE,
"Would you like to migrate the following resource?\n" + migrationURL.toString(),
QMessageBox::Yes | QMessageBox::No, 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;
migrateResources(migrationURL, jsonValue, isModelURL);
} else {
QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
if (answer == QMessageBox::Yes) {
ModalDialogListener* migrationConfirmDialog2 = OffscreenUi::asyncQuestion(_dialogParent, MESSAGE_BOX_TITLE, COMPLETE_MIGRATION_TEXT,
QMessageBox::Yes | QMessageBox::No, 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);
} else {
_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;
}
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) {
@ -333,8 +329,9 @@ bool ATPAssetMigrator::wantsToMigrateResource(const QUrl& url) {
void ATPAssetMigrator::saveEntityServerFile() {
// show a dialog to ask the user where they want to save the file
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString saveName) {
ModalDialogListener* dlg = OffscreenUi::getSaveFileNameAsync(_dialogParent, "Save Migrated Entities File");
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& saveName = response.toString();
QFile saveFile { saveName };
if (saveFile.open(QIODevice::WriteOnly)) {
@ -369,9 +366,6 @@ void ATPAssetMigrator::saveEntityServerFile() {
// reset after the attempted save, success or fail
reset();
});
OffscreenUi::getSaveFileNameAsync(_dialogParent, "Save Migrated Entities File");
}
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& defaultText default text in the text box
void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse,
this, [=] (QVariant result) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse,
this, nullptr);
ModalDialogListener* dlg = OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText);
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant result) {
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
emit promptTextChanged(result.toString());
});
OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText);
}
CustomPromptResult WindowScriptingInterface::customPrompt(const QVariant& config) {
@ -221,19 +218,15 @@ void WindowScriptingInterface::browseDirAsync(const QString& title, const QStrin
#ifndef Q_OS_WIN
path = fixupPathForMac(directory);
#endif
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, [=] (QString result) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, nullptr);
ModalDialogListener* dlg = OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& result = response.toString();
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (!result.isEmpty()) {
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
}
emit browseDirChanged(result);
});
OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
}
/// \param const QString& title title of the window
@ -270,19 +263,17 @@ void WindowScriptingInterface::browseAsync(const QString& title, const QString&
#ifndef Q_OS_WIN
path = fixupPathForMac(directory);
#endif
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, [=] (QString result) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, nullptr);
ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& result = response.toString();
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (!result.isEmpty()) {
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
}
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
@ -321,19 +312,17 @@ void WindowScriptingInterface::saveAsync(const QString& title, const QString& di
#ifndef Q_OS_WIN
path = fixupPathForMac(directory);
#endif
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, [=] (QString result) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
this, nullptr);
ModalDialogListener* dlg = OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter);
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& result = response.toString();
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (!result.isEmpty()) {
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
}
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
@ -379,19 +368,15 @@ void WindowScriptingInterface::browseAssetsAsync(const QString& title, const QSt
path = path + "/";
}
auto offscreenUi = DependencyManager::get<OffscreenUi>();
connect(offscreenUi.data(), &OffscreenUi::assetDialogResponse,
this, [=] (QString result) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
disconnect(offscreenUi.data(), &OffscreenUi::assetDialogResponse,
this, nullptr);
ModalDialogListener* dlg = OffscreenUi::getOpenAssetNameAsync(nullptr, title, path, nameFilter);
connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
const QString& result = response.toString();
disconnect(dlg, &ModalDialogListener::response, this, nullptr);
if (!result.isEmpty()) {
setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath());
}
emit assetsDirChanged(result);
});
OffscreenUi::getOpenAssetNameAsync(nullptr, title, path, nameFilter);
}
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 {
Q_OBJECT
@ -211,7 +172,7 @@ private slots:
_result = button;
_finished = true;
auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->response(static_cast<QMessageBox::StandardButton>(_result.toInt()));
emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
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)));
}
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()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "asyncMessageBox",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(Icon, icon),
Q_ARG(QString, title),
Q_ARG(QString, text),
Q_ARG(QMessageBox::StandardButtons, buttons),
Q_ARG(QMessageBox::StandardButton, defaultButton));
return ret;
}
MessageBoxListener* messageBoxListener = new MessageBoxListener(createMessageBox(icon, title, text, buttons, defaultButton));
QObject* modalDialog = qobject_cast<QObject*>(messageBoxListener);
_modalDialogListeners.push_back(modalDialog);
return messageBoxListener;
}
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);
}
void OffscreenUi::asyncCritical(const QString& title, const QString& text,
ModalDialogListener* OffscreenUi::asyncCritical(const QString& title, const QString& text,
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) {
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::StandardButtons buttons, QMessageBox::StandardButton 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) {
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::StandardButtons buttons, QMessageBox::StandardButton 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) {
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:
void onSelected(const QVariant& result) {
_result = result;
auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->inputDialogResponse(_result);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
_finished = true;
disconnect(_dialog);
@ -394,17 +362,17 @@ QVariant OffscreenUi::getCustomInfo(const Icon icon, const QString& title, const
return result;
}
void OffscreenUi::getTextAsync(const Icon icon, const QString& title, const QString& label, const QString& text) {
DependencyManager::get<OffscreenUi>()->inputDialogAsync(icon, title, label, text);
ModalDialogListener* OffscreenUi::getTextAsync(const Icon icon, const QString& title, const QString& label, const QString& 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) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
auto inputDialog = offscreenUi->createInputDialog(icon, title, label, current);
if (!inputDialog) {
return;
return nullptr;
}
inputDialog->setProperty("items", items);
inputDialog->setProperty("editable", editable);
@ -412,11 +380,11 @@ void OffscreenUi::getItemAsync(const Icon icon, const QString& title, const QStr
InputDialogListener* inputDialogListener = new InputDialogListener(inputDialog);
offscreenUi->getModalDialogListeners().push_back(qobject_cast<QObject*>(inputDialogListener));
return;
return inputDialogListener;
}
void OffscreenUi::getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config) {
DependencyManager::get<OffscreenUi>()->customInputDialog(icon, title, config);
ModalDialogListener* OffscreenUi::getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config) {
return DependencyManager::get<OffscreenUi>()->customInputDialogAsync(icon, title, config);
}
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));
}
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()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "inputDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(Icon, icon),
Q_ARG(QString, title),
Q_ARG(QString, label),
Q_ARG(QVariant, current));
return;
return ret;
}
InputDialogListener* inputDialogListener = new InputDialogListener(createInputDialog(icon, title, label, current));
QObject* inputDialog = qobject_cast<QObject*>(inputDialogListener);
_modalDialogListeners.push_back(inputDialog);
return inputDialogListener;
}
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;
}
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()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "customInputDialogAsync",
Q_ARG(Icon, icon),
Q_ARG(QString, title),
Q_ARG(QVariantMap, config));
return;
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(Icon, icon),
Q_ARG(QString, title),
Q_ARG(QVariantMap, config));
return ret;
}
InputDialogListener* inputDialogListener = new InputDialogListener(createCustomInputDialog(icon, title, config));
QObject* inputDialog = qobject_cast<QObject*>(inputDialogListener);
_modalDialogListeners.push_back(inputDialog);
return;
return inputDialogListener;
}
void OffscreenUi::togglePinned() {
@ -655,6 +628,7 @@ void OffscreenUi::createDesktop(const QUrl& url) {
#endif
load(url, [=](QQmlContext* context, QObject* newObject) {
Q_UNUSED(context)
_desktop = static_cast<QQuickItem*>(newObject);
getSurfaceContext()->setContextProperty("desktop", _desktop);
_toolWindow = _desktop->findChild<QQuickItem*>("ToolWindow");
@ -703,7 +677,7 @@ private slots:
_result = file;
_finished = true;
auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->fileDialogResponse(_result.toUrl().toLocalFile());
emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
disconnect(_dialog);
}
@ -740,7 +714,7 @@ QString OffscreenUi::fileDialog(const QVariantMap& properties) {
return result.toUrl().toLocalFile();
}
void OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
ModalDialogListener* OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
QVariant buildDialogResult;
bool invokeResult;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
@ -759,14 +733,14 @@ void OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
if (!invokeResult) {
qWarning() << "Failed to create file open dialog";
return;
return nullptr;
}
FileDialogListener* fileDialogListener = new FileDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult));
QObject* fileModalDialog = qobject_cast<QObject*>(fileDialogListener);
_modalDialogListeners.push_back(fileModalDialog);
return;
return fileDialogListener;
}
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);
}
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()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "fileOpenDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption),
Q_ARG(QString, dir),
Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options));
return;
return ret;
}
// 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("filter", filter);
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) {
@ -835,15 +811,17 @@ QString OffscreenUi::fileSaveDialog(const QString& caption, const QString& dir,
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()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "fileSaveDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption),
Q_ARG(QString, dir),
Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options));
return;
return ret;
}
// FIXME support returning the selected filter... somehow?
@ -879,15 +857,17 @@ QString OffscreenUi::existingDirectoryDialog(const QString& caption, const QStri
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()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "existingDirectoryDialogAsync",
Q_ARG(QString, caption),
Q_ARG(QString, dir),
Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options));
return;
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption),
Q_ARG(QString, dir),
Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options));
return ret;
}
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) {
Q_UNUSED(ignored)
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);
}
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);
}
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);
}
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);
}
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);
}
@ -939,7 +925,7 @@ class AssetDialogListener : public ModalDialogListener {
void onSelectedAsset(QVariant asset) {
_result = asset;
auto offscreenUi = DependencyManager::get<OffscreenUi>();
emit offscreenUi->assetDialogResponse(_result.toUrl().toLocalFile());
emit response(_result);
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
_finished = true;
disconnect(_dialog);
@ -978,7 +964,7 @@ QString OffscreenUi::assetDialog(const QVariantMap& properties) {
return result.toUrl().toString();
}
void OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
ModalDialogListener *OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
// ATP equivalent of fileDialog().
QVariant buildDialogResult;
bool invokeResult;
@ -998,13 +984,13 @@ void OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
if (!invokeResult) {
qWarning() << "Failed to create asset open dialog";
return;
return nullptr;
}
AssetDialogListener* assetDialogListener = new AssetDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult));
QObject* assetModalDialog = qobject_cast<QObject*>(assetDialogListener);
_modalDialogListeners.push_back(assetModalDialog);
return;
return assetDialogListener;
}
QList<QObject *> &OffscreenUi::getModalDialogListeners() {
@ -1034,16 +1020,18 @@ QString OffscreenUi::assetOpenDialog(const QString& caption, const QString& dir,
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().
if (QThread::currentThread() != thread()) {
ModalDialogListener* ret;
BLOCKING_INVOKE_METHOD(this, "assetOpenDialogAsync",
Q_RETURN_ARG(ModalDialogListener*, ret),
Q_ARG(QString, caption),
Q_ARG(QString, dir),
Q_ARG(QString, filter),
Q_ARG(QString*, selectedFilter),
Q_ARG(QFileDialog::Options, options));
return;
return ret;
}
// 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) {
// ATP equivalent of getOpenFileName().
Q_UNUSED(ignored)
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().
Q_UNUSED(ignored)
return DependencyManager::get<OffscreenUi>()->assetOpenDialogAsync(caption, dir, filter, selectedFilter, options);
}
@ -1104,5 +1094,31 @@ unsigned int OffscreenUi::getMenuUserDataId() const {
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"
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 {
Q_OBJECT
@ -71,7 +92,7 @@ public:
// Message box compatibility
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
QQuickItem* createMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
// Must be called from the main thread
@ -89,12 +110,12 @@ public:
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
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::StandardButton defaultButton = QMessageBox::NoButton) {
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::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncInformation(title, text, buttons, defaultButton);
@ -106,7 +127,7 @@ public:
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::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncQuestion(title, text, buttons, defaultButton);
@ -117,7 +138,7 @@ public:
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
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::StandardButton defaultButton = QMessageBox::NoButton) {
return asyncWarning(title, text, buttons, defaultButton);
@ -129,53 +150,55 @@ public:
static QMessageBox::StandardButton information(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
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::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::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton question(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
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::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton warning(const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
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::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 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 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 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 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
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
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
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 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 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 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* createCustomInputDialog(const Icon icon, const QString& title, const QVariantMap& config);
QVariant waitForInputDialogResult(QQuickItem* inputDialog);
@ -194,13 +217,13 @@ public:
}
// 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,
Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone) {
return getTextAsync(OffscreenUi::ICON_NONE, title, label, text);
}
// 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,
Qt::InputMethodHints inputMethodHints = Qt::ImhNone) {
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 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 void 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 void getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config);
static ModalDialogListener* getTextAsync(const Icon icon, const QString & title, const QString & label, const QString & text = QString());
static ModalDialogListener* getItemAsync(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true);
static ModalDialogListener* getCustomInfoAsync(const Icon icon, const QString& title, const QVariantMap& config);
unsigned int getMenuUserDataId() const;
QList<QObject *> &getModalDialogListeners();
signals:
void showDesktop();
void response(QMessageBox::StandardButton response);
void fileDialogResponse(QString response);
void assetDialogResponse(QString response);
void inputDialogResponse(QVariant response);
// void response(QMessageBox::StandardButton response);
// void fileDialogResponse(QString response);
// void assetDialogResponse(QString response);
// void inputDialogResponse(QVariant response);
public slots:
void removeModalDialog(QObject* modal);
private:
QString fileDialog(const QVariantMap& properties);
void fileDialogAsync(const QVariantMap &properties);
ModalDialogListener *fileDialogAsync(const QVariantMap &properties);
QString assetDialog(const QVariantMap& properties);
void assetDialogAsync(const QVariantMap& properties);
ModalDialogListener* assetDialogAsync(const QVariantMap& properties);
QQuickItem* _desktop { nullptr };
QQuickItem* _toolWindow { nullptr };