mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 11:29:00 +02:00
Fixing message dialog
This commit is contained in:
parent
99a6e1f86c
commit
08d60c6a01
14 changed files with 221 additions and 190 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,9 @@ import QtQuick 2.3
|
|||
Root {
|
||||
id: root
|
||||
anchors.fill: parent
|
||||
|
||||
onParentChanged: {
|
||||
forceActiveFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#include <TextRenderer.h>
|
||||
#include <UserActivityLogger.h>
|
||||
#include <UUID.h>
|
||||
#include <MessageDialog.h>
|
||||
|
||||
#include <SceneScriptingInterface.h>
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<StandardButton>(button),
|
||||
static_cast<QPlatformDialogHelper::ButtonRole>(
|
||||
QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(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));
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define hifi_OffscreenQmlDialog_h
|
||||
|
||||
#include <QQuickItem>
|
||||
#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)
|
||||
|
|
|
@ -151,17 +151,18 @@ void OffscreenUi::setBaseUrl(const QUrl& baseUrl) {
|
|||
_qmlEngine->setBaseUrl(baseUrl);
|
||||
}
|
||||
|
||||
void OffscreenUi::load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> f) {
|
||||
QObject* OffscreenUi::load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> 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<void(QQmlContext*, QObject*)> f) {
|
||||
QObject* OffscreenUi::finishQmlLoad(std::function<void(QQmlContext*, QObject*)> f) {
|
||||
disconnect(_qmlComponent, &QQmlComponent::statusChanged, this, 0);
|
||||
if (_qmlComponent->isError()) {
|
||||
QList<QQmlError> 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<void(QQmlContext*, QObject*)> 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<QQuickItem*>(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::function<void(
|
|||
load(url, f);
|
||||
item = _rootItem->findChild<QQuickItem*>(name);
|
||||
}
|
||||
item->setEnabled(true);
|
||||
if (item) {
|
||||
item->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f) {
|
||||
|
@ -425,21 +431,25 @@ void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function<voi
|
|||
load(url, f);
|
||||
item = _rootItem->findChild<QQuickItem*>(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*>();
|
||||
MessageDialog * pDialog{ nullptr };
|
||||
MessageDialog::show([&](QQmlContext*ctx, QObject*item) {
|
||||
pDialog = item->findChild<MessageDialog*>();
|
||||
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,
|
||||
|
|
|
@ -38,9 +38,9 @@ private: \
|
|||
static const QUrl QML; \
|
||||
public: \
|
||||
static void registerType(); \
|
||||
static void show(std::function<void(QQmlContext*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
static void toggle(std::function<void(QQmlContext*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
static void load(std::function<void(QQmlContext*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
static void show(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
static void toggle(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
static void load(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
private:
|
||||
|
||||
#define HIFI_QML_DECL_LAMBDA \
|
||||
|
@ -62,16 +62,16 @@ private:
|
|||
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
|
||||
} \
|
||||
\
|
||||
void x::show(std::function<void(QQmlContext*, QQuickItem *)> f) { \
|
||||
void x::show(std::function<void(QQmlContext*, QObject*)> f) { \
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||
offscreenUi->show(QML, NAME, f); \
|
||||
} \
|
||||
\
|
||||
void x::toggle(std::function<void(QQmlContext*, QQuickItem *)> f) { \
|
||||
void x::toggle(std::function<void(QQmlContext*, QObject*)> f) { \
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||
offscreenUi->toggle(QML, NAME, f); \
|
||||
} \
|
||||
void x::load(std::function<void(QQmlContext*, QQuickItem *)> f) { \
|
||||
void x::load(std::function<void(QQmlContext*, QObject*)> f) { \
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||
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<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||
void load(const QString& qmlSourceFile, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}) {
|
||||
load(QUrl(qmlSourceFile), f);
|
||||
QObject* load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||
QObject* load(const QString& qmlSourceFile, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}) {
|
||||
return load(QUrl(qmlSourceFile), f);
|
||||
}
|
||||
void show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||
void toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||
|
@ -173,7 +173,7 @@ protected:
|
|||
|
||||
private slots:
|
||||
void updateQuick();
|
||||
void finishQmlLoad(std::function<void(QQmlContext*, QObject*)> f);
|
||||
QObject* finishQmlLoad(std::function<void(QQmlContext*, QObject*)> f);
|
||||
|
||||
public slots:
|
||||
void requestUpdate();
|
||||
|
|
|
@ -185,18 +185,18 @@ public:
|
|||
QObject* menuObject = offscreenUi->getRootItem()->findChild<QObject*>("HifiMenu");
|
||||
HifiMenu* menu = offscreenUi->getRootItem()->findChild<HifiMenu*>();
|
||||
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<OffscreenUi>();
|
||||
HifiMenu * menu = offscreenUi->findChild<HifiMenu*>();
|
||||
menu->addMenuItem("", "Test 3");
|
||||
menu->addMenuItem("File", "Test 3");
|
||||
menu->addItem("", "Test 3");
|
||||
menu->addItem("File", "Test 3");
|
||||
}
|
||||
break;
|
||||
case Qt::Key_K:
|
||||
|
|
Loading…
Reference in a new issue