From 08d60c6a017217d7df8f46eeae9df7796d4dc9cd Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 24 Apr 2015 14:54:38 -0700 Subject: [PATCH] Fixing message dialog --- interface/resources/qml/AddressBarDialog.qml | 16 ++ interface/resources/qml/HifiMenu.qml | 4 +- interface/resources/qml/MessageDialog.qml | 155 +++++++++---------- interface/resources/qml/Root.qml | 4 + interface/resources/qml/TestRoot.qml | 21 +-- interface/resources/qml/controls/Dialog.qml | 2 +- interface/src/Application.cpp | 6 + interface/src/ui/LoginDialog.cpp | 4 +- libraries/ui/src/MessageDialog.cpp | 19 ++- libraries/ui/src/MessageDialog.h | 28 ++-- libraries/ui/src/OffscreenQmlDialog.h | 40 ++--- libraries/ui/src/OffscreenUi.cpp | 74 +++++---- libraries/ui/src/OffscreenUi.h | 20 +-- tests/ui/src/main.cpp | 18 +-- 14 files changed, 221 insertions(+), 190 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index d12737081e..8a2bc3e2b4 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -48,6 +48,7 @@ Dialog { helperText: "domain, location, @user, /x,y,z" anchors.margins: 8 onAccepted: { + event.accepted addressBarDialog.loadAddress(addressLine.text) } } @@ -71,5 +72,20 @@ Dialog { } } } + + Keys.onEscapePressed: { + enabled = false; + } + + function toggleOrGo() { + if (addressLine.text == "") { + enabled = false + } else { + addressBarDialog.loadAddress(addressLine.text) + } + } + + Keys.onReturnPressed: toggleOrGo() + Keys.onEnterPressed: toggleOrGo() } diff --git a/interface/resources/qml/HifiMenu.qml b/interface/resources/qml/HifiMenu.qml index d86821601a..1afa39c5d1 100644 --- a/interface/resources/qml/HifiMenu.qml +++ b/interface/resources/qml/HifiMenu.qml @@ -111,8 +111,8 @@ Hifi.HifiMenu { Border { SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active } x: root.models.length == 1 ? - (root.width / 2 - width / 2) : - root.columns[root.models.length - 2].x + 60; + (root.width / 2 - width / 2) : + root.columns[root.models.length - 2].x + 60; anchors.verticalCenter: parent.verticalCenter border.color: hifiPalette.hifiBlue color: sysPalette.window diff --git a/interface/resources/qml/MessageDialog.qml b/interface/resources/qml/MessageDialog.qml index 26fd30db27..315af8c6c9 100644 --- a/interface/resources/qml/MessageDialog.qml +++ b/interface/resources/qml/MessageDialog.qml @@ -1,43 +1,3 @@ -/***************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQuick.Dialogs module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -*****************************************************************************/ - import Hifi 1.0 as Hifi import QtQuick 2.2 import QtQuick.Controls 1.2 @@ -49,6 +9,7 @@ Dialog { property real spacing: 8 property real outerSpacing: 16 + destroyOnCloseButton: true destroyOnInvisible: true implicitHeight: content.implicitHeight + outerSpacing * 2 + 48 @@ -69,9 +30,13 @@ Dialog { content.buttonsRowImplicitWidth = outerSpacing + calcWidth + 48 } + Component.onCompleted: { + enabled = true + } + onEnabledChanged: { if (enabled) { - content.forceActiveFocus(); + root.forceActiveFocus(); } } @@ -87,37 +52,6 @@ Dialog { implicitWidth: Math.max(mainText.implicitWidth, buttonsRowImplicitWidth); property real buttonsRowImplicitWidth: Screen.pixelDensity * 50 - Keys.onPressed: { - console.log("Key press at content") - event.accepted = true - if (event.modifiers === Qt.ControlModifier) - switch (event.key) { - case Qt.Key_A: - console.log("Select All") - detailedText.selectAll() - break - case Qt.Key_C: - console.log("Copy") - detailedText.copy() - break - case Qt.Key_Period: - if (Qt.platform.os === "osx") - reject() - break - } else switch (event.key) { - case Qt.Key_Escape: - case Qt.Key_Back: - console.log("Rejecting") - reject() - break - case Qt.Key_Enter: - case Qt.Key_Return: - console.log("Accepting") - accept() - break - } - } - onImplicitWidthChanged: root.width = implicitWidth Component.onCompleted: { @@ -140,9 +74,46 @@ Dialog { Item { width: parent.width height: Math.max(icon.height, mainText.height + informativeText.height + root.spacing) - Image { + + FontAwesome { id: icon - source: content.standardIconSource + width: content.icon ? 48 : 0 + height: content.icon ? 48 : 0 + visible: content.icon ? true : false + font.pixelSize: 48 + verticalAlignment: Text.AlignTop + horizontalAlignment: Text.AlignLeft + color: iconColor() + text: iconSymbol() + + function iconSymbol() { + switch (content.icon) { + case Hifi.MessageDialog.Information: + return "\uF05A" + case Hifi.MessageDialog.Question: + return "\uF059" + case Hifi.MessageDialog.Warning: + return "\uF071" + case Hifi.MessageDialog.Critical: + return "\uF057" + default: + break; + } + return content.icon; + } + function iconColor() { + switch (content.icon) { + case Hifi.MessageDialog.Information: + case Hifi.MessageDialog.Question: + return "blue" + case Hifi.MessageDialog.Warning: + case Hifi.MessageDialog.Critical: + return "red" + default: + break + } + return "black" + } } Text { @@ -348,12 +319,38 @@ Dialog { } } ] - -/* - Rectangle { + } + Keys.onPressed: { + if (event.modifiers === Qt.ControlModifier) + switch (event.key) { + case Qt.Key_A: + event.accepted = true + detailedText.selectAll() + break + case Qt.Key_C: + event.accepted = true + detailedText.copy() + break + case Qt.Key_Period: + if (Qt.platform.os === "osx") { + event.accepted = true + content.reject() + } + break + } else switch (event.key) { + case Qt.Key_Escape: + case Qt.Key_Back: + event.accepted = true + content.reject() + break + + case Qt.Key_Enter: + case Qt.Key_Return: + console.log("Accepting"); + event.accepted = true + content.accept() + break } - Component.onCompleted: calculateImplicitWidth() - */ } } diff --git a/interface/resources/qml/Root.qml b/interface/resources/qml/Root.qml index b2db7d18bf..9b2e5af6b5 100644 --- a/interface/resources/qml/Root.qml +++ b/interface/resources/qml/Root.qml @@ -6,5 +6,9 @@ import QtQuick 2.3 Root { id: root anchors.fill: parent + + onParentChanged: { + forceActiveFocus(); + } } diff --git a/interface/resources/qml/TestRoot.qml b/interface/resources/qml/TestRoot.qml index 80f8c900e3..cb53d34ce2 100644 --- a/interface/resources/qml/TestRoot.qml +++ b/interface/resources/qml/TestRoot.qml @@ -6,21 +6,11 @@ import QtQuick.Controls 1.3 import "controls" Root { - id: root + id: root anchors.fill: parent - - onWidthChanged: { - console.log("Root width: " + width) + onParentChanged: { + forceActiveFocus(); } - onHeightChanged: { - console.log("Root height: " + height) - } - - Component.onCompleted: { - console.log("Completed root") - root.forceActiveFocus() - } - Button { id: messageBox anchors.right: createDialog.left @@ -34,7 +24,6 @@ Root { console.log("Bar") } } - Button { id: createDialog anchors.right: parent.right @@ -48,7 +37,7 @@ Root { } Keys.onPressed: { - console.log(event.key); - } + console.log("Key press root") + } } diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/Dialog.qml index 07162ad1d8..d722d5264a 100644 --- a/interface/resources/qml/controls/Dialog.qml +++ b/interface/resources/qml/controls/Dialog.qml @@ -17,7 +17,7 @@ Item { HifiPalette { id: hifiPalette } SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active } x: parent ? parent.width / 2 - width / 2 : 0 - y: parent ? parent.height / 2 - height / 2 : 0 + y: parent ? parent.height / 2 - height / 2 : 0 property int animationDuration: 400 property bool destroyOnInvisible: false diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5a8b3ecee9..4217bb75b8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -82,6 +82,7 @@ #include #include #include +#include #include @@ -1086,6 +1087,11 @@ void Application::keyPressEvent(QKeyEvent* event) { bool isKeypad = event->modifiers().testFlag(Qt::KeypadModifier); switch (event->key()) { break; + case Qt::Key_Enter: + case Qt::Key_Return: + Menu::getInstance()->triggerOption(MenuOption::AddressBar); + break; + case Qt::Key_L: if (isShifted && isMeta) { Menu::getInstance()->triggerOption(MenuOption::Log); diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 4df42c0f15..5726818b2d 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -37,7 +37,9 @@ void LoginDialog::toggleAction() { } else { // change the menu item to login loginAction->setText("Login"); - connect(loginAction, &QAction::triggered, &LoginDialog::show); + connect(loginAction, &QAction::triggered, [] { + LoginDialog::show(); + }); } } diff --git a/libraries/ui/src/MessageDialog.cpp b/libraries/ui/src/MessageDialog.cpp index c16f5653e5..89d6b69384 100644 --- a/libraries/ui/src/MessageDialog.cpp +++ b/libraries/ui/src/MessageDialog.cpp @@ -10,8 +10,7 @@ // #include "MessageDialog.h" -QML_DIALOG_DEF(MessageDialog) - +HIFI_QML_DEF(MessageDialog) MessageDialog::MessageDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) { _buttons = StandardButtons(Ok | Cancel); @@ -76,23 +75,23 @@ void MessageDialog::setStandardButtons(StandardButtons buttons) { } void MessageDialog::click(StandardButton button) { - click(static_cast(button), - static_cast( - QPlatformDialogHelper::buttonRole(static_cast(button)))); + // FIXME try to do it more like the standard dialog + click(StandardButton(button), ButtonRole::NoRole); } +QMessageBox::ButtonRole br; QUrl MessageDialog::standardIconSource() { switch (icon()) { - case QMessageDialogOptions::Information: + case Information: return QUrl("images/information.png"); break; - case QMessageDialogOptions::Warning: + case Warning: return QUrl("images/warning.png"); break; - case QMessageDialogOptions::Critical: + case Critical: return QUrl("images/critical.png"); break; - case QMessageDialogOptions::Question: + case Question: return QUrl("images/question.png"); break; default: @@ -109,7 +108,7 @@ MessageDialog::StandardButton MessageDialog::clickedButton() const { return _clickedButton; } -void MessageDialog::click(StandardButton button, QPlatformDialogHelper::ButtonRole) { +void MessageDialog::click(StandardButton button, ButtonRole) { _clickedButton = button; if (_resultCallback) { _resultCallback(QMessageBox::StandardButton(_clickedButton)); diff --git a/libraries/ui/src/MessageDialog.h b/libraries/ui/src/MessageDialog.h index 8b5a895068..d700754513 100644 --- a/libraries/ui/src/MessageDialog.h +++ b/libraries/ui/src/MessageDialog.h @@ -13,12 +13,11 @@ #define hifi_MessageDialog_h #include "OffscreenQmlDialog.h" -#include <5.4.1/QtGui/qpa/qplatformdialoghelper.h> class MessageDialog : public OffscreenQmlDialog { Q_OBJECT - QML_DIALOG_DECL + HIFI_QML_DECL private: Q_ENUMS(Icon) @@ -31,14 +30,23 @@ private: Q_PROPERTY(StandardButton clickedButton READ clickedButton NOTIFY buttonClicked) public: - enum Icon { - NoIcon = QMessageDialogOptions::NoIcon, - Information = QMessageDialogOptions::Information, - Warning = QMessageDialogOptions::Warning, - Critical = QMessageDialogOptions::Critical, - Question = QMessageDialogOptions::Question - }; + enum Icon { NoIcon, Information, Warning, Critical, Question }; + enum ButtonRole { + // keep this in sync with QDialogButtonBox::ButtonRole and QPlatformDialogHelper::ButtonRole + InvalidRole = -1, + AcceptRole, + RejectRole, + DestructiveRole, + ActionRole, + HelpRole, + YesRole, + NoRole, + ResetRole, + ApplyRole, + + NRoles + }; MessageDialog(QQuickItem *parent = 0); virtual ~MessageDialog(); @@ -76,7 +84,7 @@ signals: void reset(); protected slots: - virtual void click(StandardButton button, QPlatformDialogHelper::ButtonRole); + virtual void click(StandardButton button, ButtonRole); virtual void accept(); virtual void reject(); diff --git a/libraries/ui/src/OffscreenQmlDialog.h b/libraries/ui/src/OffscreenQmlDialog.h index 7b7c83ad65..b97bc1914f 100644 --- a/libraries/ui/src/OffscreenQmlDialog.h +++ b/libraries/ui/src/OffscreenQmlDialog.h @@ -13,7 +13,6 @@ #define hifi_OffscreenQmlDialog_h #include -#include <5.4.1/QtGui/qpa/qplatformdialoghelper.h> #include "OffscreenUi.h" @@ -57,25 +56,26 @@ public: virtual ~OffscreenQmlDialog(); enum StandardButton { - NoButton = QPlatformDialogHelper::NoButton, - Ok = QPlatformDialogHelper::Ok, - Save = QPlatformDialogHelper::Save, - SaveAll = QPlatformDialogHelper::SaveAll, - Open = QPlatformDialogHelper::Open, - Yes = QPlatformDialogHelper::Yes, - YesToAll = QPlatformDialogHelper::YesToAll, - No = QPlatformDialogHelper::No, - NoToAll = QPlatformDialogHelper::NoToAll, - Abort = QPlatformDialogHelper::Abort, - Retry = QPlatformDialogHelper::Retry, - Ignore = QPlatformDialogHelper::Ignore, - Close = QPlatformDialogHelper::Close, - Cancel = QPlatformDialogHelper::Cancel, - Discard = QPlatformDialogHelper::Discard, - Help = QPlatformDialogHelper::Help, - Apply = QPlatformDialogHelper::Apply, - Reset = QPlatformDialogHelper::Reset, - RestoreDefaults = QPlatformDialogHelper::RestoreDefaults, + // keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton + NoButton = 0x00000000, + Ok = 0x00000400, + Save = 0x00000800, + SaveAll = 0x00001000, + Open = 0x00002000, + Yes = 0x00004000, + YesToAll = 0x00008000, + No = 0x00010000, + NoToAll = 0x00020000, + Abort = 0x00040000, + Retry = 0x00080000, + Ignore = 0x00100000, + Close = 0x00200000, + Cancel = 0x00400000, + Discard = 0x00800000, + Help = 0x01000000, + Apply = 0x02000000, + Reset = 0x04000000, + RestoreDefaults = 0x08000000, NButtons }; Q_DECLARE_FLAGS(StandardButtons, StandardButton) diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 7b84bb763f..27c33cbae9 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -151,17 +151,18 @@ void OffscreenUi::setBaseUrl(const QUrl& baseUrl) { _qmlEngine->setBaseUrl(baseUrl); } -void OffscreenUi::load(const QUrl& qmlSource, std::function f) { +QObject* OffscreenUi::load(const QUrl& qmlSource, std::function f) { qDebug() << "Loading QML from URL " << qmlSource; _qmlComponent->loadUrl(qmlSource); - if (_qmlComponent->isLoading()) + if (_qmlComponent->isLoading()) { connect(_qmlComponent, &QQmlComponent::statusChanged, this, [this, f](QQmlComponent::Status){ finishQmlLoad(f); }); - else { - finishQmlLoad(f); + return nullptr; } + + return finishQmlLoad(f); } void OffscreenUi::requestUpdate() { @@ -177,14 +178,14 @@ void OffscreenUi::requestRender() { } } -void OffscreenUi::finishQmlLoad(std::function f) { +QObject* OffscreenUi::finishQmlLoad(std::function f) { disconnect(_qmlComponent, &QQmlComponent::statusChanged, this, 0); if (_qmlComponent->isError()) { QList errorList = _qmlComponent->errors(); foreach(const QQmlError &error, errorList) { qWarning() << error.url() << error.line() << error; } - return; + return nullptr; } QQmlContext * newContext = new QQmlContext(_qmlEngine, qApp); @@ -196,38 +197,41 @@ void OffscreenUi::finishQmlLoad(std::function f) { if (!_rootItem) { qFatal("Unable to finish loading QML root"); } - return; + return nullptr; } f(newContext, newObject); _qmlComponent->completeCreate(); + + // All quick items should be focusable QQuickItem* newItem = qobject_cast(newObject); - if (!newItem) { - qWarning("run: Not a QQuickItem"); - return; - delete newObject; - if (!_rootItem) { - qFatal("Unable to find root QQuickItem"); - } - return; + if (newItem) { + // Make sure we make items focusable (critical for + // supporting keyboard shortcuts) + newItem->setFlag(QQuickItem::ItemIsFocusScope, true); } - // Make sure we make items focusable (critical for - // supporting keyboard shortcuts) - newItem->setFlag(QQuickItem::ItemIsFocusScope, true); - if (!_rootItem) { - // The root item is ready. Associate it with the window. - _rootItem = newItem; - _rootItem->setParentItem(_quickWindow->contentItem()); - _rootItem->setSize(_quickWindow->renderTargetSize()); - _rootItem->forceActiveFocus(); - } else { + // If we already have a root, just set a couple of flags and the ancestry + if (_rootItem) { // Allow child windows to be destroyed from JS - QQmlEngine::setObjectOwnership(newItem, QQmlEngine::JavaScriptOwnership); - newItem->setParent(_rootItem); - newItem->setParentItem(_rootItem); + QQmlEngine::setObjectOwnership(newObject, QQmlEngine::JavaScriptOwnership); + newObject->setParent(_rootItem); + if (newItem) { + newItem->setParentItem(_rootItem); + } + return newObject; } + + if (!newItem) { + qFatal("Could not load object as root item"); + return nullptr; + } + // The root item is ready. Associate it with the window. + _rootItem = newItem; + _rootItem->setParentItem(_quickWindow->contentItem()); + _rootItem->setSize(_quickWindow->renderTargetSize()); + return _rootItem; } @@ -415,7 +419,9 @@ void OffscreenUi::show(const QUrl& url, const QString& name, std::functionfindChild(name); } - item->setEnabled(true); + if (item) { + item->setEnabled(true); + } } void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function f) { @@ -425,21 +431,25 @@ void OffscreenUi::toggle(const QUrl& url, const QString& name, std::functionfindChild(name); } - item->setEnabled(!item->isEnabled()); + if (item) { + item->setEnabled(!item->isEnabled()); + } } void OffscreenUi::messageBox(const QString& title, const QString& text, ButtonCallback callback, QMessageBox::Icon icon, QMessageBox::StandardButtons buttons) { - MessageDialog::show([=](QQmlContext*ctx, QObject*item) { - MessageDialog * pDialog = item->findChild(); + MessageDialog * pDialog{ nullptr }; + MessageDialog::show([&](QQmlContext*ctx, QObject*item) { + pDialog = item->findChild(); pDialog->setIcon((MessageDialog::Icon)icon); pDialog->setTitle(title); pDialog->setText(text); pDialog->setStandardButtons(MessageDialog::StandardButtons((int)buttons)); pDialog->setResultCallback(callback); }); + pDialog->setEnabled(true); } void OffscreenUi::information(const QString& title, const QString& text, diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index b58b4e59cb..bc27fc2195 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -38,9 +38,9 @@ private: \ static const QUrl QML; \ public: \ static void registerType(); \ - static void show(std::function f = [](QQmlContext*, QQuickItem*) {}); \ - static void toggle(std::function f = [](QQmlContext*, QQuickItem*) {}); \ - static void load(std::function f = [](QQmlContext*, QQuickItem*) {}); \ + static void show(std::function f = [](QQmlContext*, QQuickItem*) {}); \ + static void toggle(std::function f = [](QQmlContext*, QQuickItem*) {}); \ + static void load(std::function f = [](QQmlContext*, QQuickItem*) {}); \ private: #define HIFI_QML_DECL_LAMBDA \ @@ -62,16 +62,16 @@ private: qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ } \ \ - void x::show(std::function f) { \ + void x::show(std::function f) { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->show(QML, NAME, f); \ } \ \ - void x::toggle(std::function f) { \ + void x::toggle(std::function f) { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->toggle(QML, NAME, f); \ } \ - void x::load(std::function f) { \ + void x::load(std::function f) { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->load(QML, f); \ } @@ -122,9 +122,9 @@ public: virtual ~OffscreenUi(); void create(QOpenGLContext* context); void resize(const QSize& size); - void load(const QUrl& qmlSource, std::function f = [](QQmlContext*, QObject*) {}); - void load(const QString& qmlSourceFile, std::function f = [](QQmlContext*, QObject*) {}) { - load(QUrl(qmlSourceFile), f); + QObject* load(const QUrl& qmlSource, std::function f = [](QQmlContext*, QObject*) {}); + QObject* load(const QString& qmlSourceFile, std::function f = [](QQmlContext*, QObject*) {}) { + return load(QUrl(qmlSourceFile), f); } void show(const QUrl& url, const QString& name, std::function f = [](QQmlContext*, QObject*) {}); void toggle(const QUrl& url, const QString& name, std::function f = [](QQmlContext*, QObject*) {}); @@ -173,7 +173,7 @@ protected: private slots: void updateQuick(); - void finishQmlLoad(std::function f); + QObject* finishQmlLoad(std::function f); public slots: void requestUpdate(); diff --git a/tests/ui/src/main.cpp b/tests/ui/src/main.cpp index 4189282de1..0f7a66c0cd 100644 --- a/tests/ui/src/main.cpp +++ b/tests/ui/src/main.cpp @@ -185,18 +185,18 @@ public: QObject* menuObject = offscreenUi->getRootItem()->findChild("HifiMenu"); HifiMenu* menu = offscreenUi->getRootItem()->findChild(); menu->addMenu("", "File"); - menu->addMenuItem("File", "Quit", []{ + menu->addItem("File", "Quit", []{ QApplication::quit(); }); - menu->addCheckableMenuItem("File", "Toggle", false, [](bool toggled) { + menu->addCheckableItem("File", "Toggle", false, [](bool toggled) { qDebug() << "Toggle is " << toggled; }); menu->addMenu("", "Edit"); - menu->addMenuItem("Edit", "Undo"); - menu->addMenuItem("Edit", "Redo"); - menu->addMenuItem("Edit", "Copy"); - menu->addMenuItem("Edit", "Cut"); - menu->addMenuItem("Edit", "Paste"); + menu->addItem("Edit", "Undo"); + menu->addItem("Edit", "Redo"); + menu->addItem("Edit", "Copy"); + menu->addItem("Edit", "Cut"); + menu->addItem("Edit", "Paste"); menu->addMenu("", "Long Menu Name..."); #endif installEventFilter(offscreenUi.data()); @@ -255,8 +255,8 @@ protected: if (event->modifiers() & Qt::CTRL) { auto offscreenUi = DependencyManager::get(); HifiMenu * menu = offscreenUi->findChild(); - menu->addMenuItem("", "Test 3"); - menu->addMenuItem("File", "Test 3"); + menu->addItem("", "Test 3"); + menu->addItem("File", "Test 3"); } break; case Qt::Key_K: