diff --git a/interface/resources/qml/dialogs/MessageDialog.qml b/interface/resources/qml/dialogs/MessageDialog.qml index 77056ec893..9809708c37 100644 --- a/interface/resources/qml/dialogs/MessageDialog.qml +++ b/interface/resources/qml/dialogs/MessageDialog.qml @@ -55,22 +55,7 @@ ModalWindow { if (!root) { return; } - switch (root.icon) { - case OriginalDialogs.StandardIcon.Information: - iconText = hifi.glyphs.info; - break; - case OriginalDialogs.StandardIcon.Question: - iconText = hifi.glyphs.question; - break; - case OriginalDialogs.StandardIcon.Warning: - iconText = hifi.glyphs.alert; - break; - case OriginalDialogs.StandardIcon.Critical: - iconText = hifi.glyphs.critical; - break; - default: - iconText = hifi.glyphs.noIcon; - } + iconText = hifi.glyphForIcon(root.icon); } Item { diff --git a/interface/resources/qml/dialogs/QueryDialog.qml b/interface/resources/qml/dialogs/QueryDialog.qml index 48adeaf074..5e02fa4859 100644 --- a/interface/resources/qml/dialogs/QueryDialog.qml +++ b/interface/resources/qml/dialogs/QueryDialog.qml @@ -47,14 +47,7 @@ ModalWindow { if (!root) { return; } - - switch (root.icon) { - case hifi.icons.placemark: - iconText = hifi.glyphs.placemark; - break; - default: - iconText = ""; - } + iconText = hifi.glyphForIcon(root.icon); } Item { diff --git a/interface/resources/qml/styles-uit/HifiConstants.qml b/interface/resources/qml/styles-uit/HifiConstants.qml index e0b6061833..b884793025 100644 --- a/interface/resources/qml/styles-uit/HifiConstants.qml +++ b/interface/resources/qml/styles-uit/HifiConstants.qml @@ -21,6 +21,31 @@ Item { readonly property alias buttons: buttons readonly property alias effects: effects + function glyphForIcon(icon) { + // Translates icon enum to glyph char. + var glyph; + switch (icon) { + case hifi.icons.information: + glyph = hifi.glyphs.info; + break; + case hifi.icons.question: + glyph = hifi.glyphs.question; + break; + case hifi.icons.warning: + glyph = hifi.glyphs.alert; + break; + case hifi.icons.critical: + glyph = hifi.glyphs.critical; + break; + case hifi.icons.placemark: + glyph = hifi.glyphs.placemark; + break; + default: + ch = hifi.glyphs.noIcon; + } + return glyph; + } + Item { id: colors @@ -163,7 +188,11 @@ Item { id: icons // Values per OffscreenUi::Icon readonly property int none: 0 - readonly property int placemark: 1 + readonly property int question: 1 + readonly property int information: 2 + readonly property int warning: 3 + readonly property int critical: 4 + readonly property int placemark: 5 } Item { diff --git a/interface/src/Bookmarks.cpp b/interface/src/Bookmarks.cpp index 479c21538b..913ff7e890 100644 --- a/interface/src/Bookmarks.cpp +++ b/interface/src/Bookmarks.cpp @@ -123,7 +123,7 @@ void Bookmarks::bookmarkLocation() { Menu* menubar = Menu::getInstance(); if (contains(bookmarkName)) { auto offscreenUi = DependencyManager::get(); - auto duplicateBookmarkMessage = offscreenUi->createMessageBox(QMessageBox::Warning, "Duplicate Bookmark", + auto duplicateBookmarkMessage = offscreenUi->createMessageBox(OffscreenUi::ICON_WARNING, "Duplicate Bookmark", "The bookmark name you entered already exists in your list.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); duplicateBookmarkMessage->setProperty("informativeText", "Would you like to overwrite it?"); diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 8412ac7f6d..ce7ea169f3 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -204,7 +204,7 @@ private slots: } }; -QQuickItem* OffscreenUi::createMessageBox(QMessageBox::Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { +QQuickItem* OffscreenUi::createMessageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QVariantMap map; map.insert("title", title); map.insert("text", text); @@ -232,12 +232,12 @@ int OffscreenUi::waitForMessageBoxResult(QQuickItem* messageBox) { } -QMessageBox::StandardButton OffscreenUi::messageBox(QMessageBox::Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { +QMessageBox::StandardButton OffscreenUi::messageBox(Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { if (QThread::currentThread() != thread()) { QMessageBox::StandardButton result = QMessageBox::StandardButton::NoButton; QMetaObject::invokeMethod(this, "messageBox", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QMessageBox::StandardButton, result), - Q_ARG(QMessageBox::Icon, icon), + Q_ARG(Icon, icon), Q_ARG(QString, title), Q_ARG(QString, text), Q_ARG(QMessageBox::StandardButtons, buttons), @@ -250,19 +250,19 @@ QMessageBox::StandardButton OffscreenUi::messageBox(QMessageBox::Icon icon, cons QMessageBox::StandardButton OffscreenUi::critical(const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { - return DependencyManager::get()->messageBox(QMessageBox::Icon::Critical, title, text, buttons, defaultButton); + return DependencyManager::get()->messageBox(OffscreenUi::Icon::ICON_CRITICAL, title, text, buttons, defaultButton); } QMessageBox::StandardButton OffscreenUi::information(const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { - return DependencyManager::get()->messageBox(QMessageBox::Icon::Information, title, text, buttons, defaultButton); + return DependencyManager::get()->messageBox(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()->messageBox(QMessageBox::Icon::Question, title, text, buttons, defaultButton); + return DependencyManager::get()->messageBox(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()->messageBox(QMessageBox::Icon::Warning, title, text, buttons, defaultButton); + return DependencyManager::get()->messageBox(OffscreenUi::Icon::ICON_WARNING, title, text, buttons, defaultButton); } diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index 7ccbe7b687..0188ac5365 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -41,11 +41,19 @@ public: QQuickItem* getDesktop(); QQuickItem* getToolWindow(); + enum Icon { + ICON_NONE = 0, + ICON_QUESTION, + ICON_INFORMATION, + ICON_WARNING, + ICON_CRITICAL, + ICON_PLACEMARK + }; // Message box compatibility - Q_INVOKABLE QMessageBox::StandardButton messageBox(QMessageBox::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); // Must be called from the main thread - QQuickItem* createMessageBox(QMessageBox::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 Q_INVOKABLE int waitForMessageBoxResult(QQuickItem* messageBox); @@ -95,11 +103,6 @@ public: // 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); - enum Icon { - ICON_NONE = 0, - ICON_PLACEMARK - }; - Q_INVOKABLE QVariant inputDialog(const Icon icon, const QString& title, const QString& label = QString(), const QVariant& current = QVariant()); QQuickItem* createInputDialog(const Icon icon, const QString& title, const QString& label, const QVariant& current); QVariant waitForInputDialogResult(QQuickItem* inputDialog); diff --git a/tests/ui/qml/main.qml b/tests/ui/qml/main.qml index 9f4df4e68f..273eb1df47 100644 --- a/tests/ui/qml/main.qml +++ b/tests/ui/qml/main.qml @@ -102,11 +102,11 @@ ApplicationWindow { var messageBox = desktop.messageBox({ title: "Set Avatar", text: "Would you like to use 'Albert' for your avatar?", - icon: OriginalDialogs.StandardIcon.Question, // Test question icon - //icon: OriginalDialogs.StandardIcon.Information, // Test informaton icon - //icon: OriginalDialogs.StandardIcon.Warning, // Test warning icon - //icon: OriginalDialogs.StandardIcon.Critical, // Test critical icon - //icon: OriginalDialogs.StandardIcon.NoIcon, // Test no icon + icon: hifi.icons.question, // Test question icon + //icon: hifi.icons.information, // Test informaton icon + //icon: hifi.icons.warning, // Test warning icon + //icon: hifi.icons.critical, // Test critical icon + //icon: hifi.icons.none, // Test no icon buttons: OriginalDialogs.StandardButton.Ok + OriginalDialogs.StandardButton.Cancel, defaultButton: OriginalDialogs.StandardButton.Ok }); @@ -121,7 +121,7 @@ ApplicationWindow { onClicked: { var messageBox = desktop.messageBox({ text: "Diagnostic cycle will be complete in 30 seconds", - icon: OriginalDialogs.StandardIcon.Critical, + icon: hifi.icons.critical, }); messageBox.selected.connect(function(button) { console.log("You clicked " + button) @@ -135,7 +135,7 @@ ApplicationWindow { desktop.messageBox({ informativeText: "Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds Diagnostic cycle will be complete in 30 seconds ", text: "Baloney", - icon: OriginalDialogs.StandardIcon.Warning, + icon: hifi.icons.warning, detailedText: "sakjd;laskj dksa;dl jka;lsd j;lkjas ;dlkaj s;dlakjd ;alkjda; slkjda; lkjda;lksjd ;alksjd; alksjd ;alksjd; alksjd; alksdjas;ldkjas;lkdja ;kj ;lkasjd; lkj as;dlka jsd;lka jsd;laksjd a" }); } @@ -169,7 +169,7 @@ ApplicationWindow { var queryBox = desktop.queryBox({ text: "Have you stopped beating your wife?", placeholderText: "Are you sure?", - // icon: OriginalDialogs.StandardIcon.Critical, + // icon: hifi.icons.critical, }); queryBox.selected.connect(function(result) { console.log("User responded with " + result);