mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-15 19:39:17 +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"
|
helperText: "domain, location, @user, /x,y,z"
|
||||||
anchors.margins: 8
|
anchors.margins: 8
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
|
event.accepted
|
||||||
addressBarDialog.loadAddress(addressLine.text)
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 Hifi 1.0 as Hifi
|
||||||
import QtQuick 2.2
|
import QtQuick 2.2
|
||||||
import QtQuick.Controls 1.2
|
import QtQuick.Controls 1.2
|
||||||
|
@ -49,6 +9,7 @@ Dialog {
|
||||||
property real spacing: 8
|
property real spacing: 8
|
||||||
property real outerSpacing: 16
|
property real outerSpacing: 16
|
||||||
|
|
||||||
|
|
||||||
destroyOnCloseButton: true
|
destroyOnCloseButton: true
|
||||||
destroyOnInvisible: true
|
destroyOnInvisible: true
|
||||||
implicitHeight: content.implicitHeight + outerSpacing * 2 + 48
|
implicitHeight: content.implicitHeight + outerSpacing * 2 + 48
|
||||||
|
@ -69,9 +30,13 @@ Dialog {
|
||||||
content.buttonsRowImplicitWidth = outerSpacing + calcWidth + 48
|
content.buttonsRowImplicitWidth = outerSpacing + calcWidth + 48
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
enabled = true
|
||||||
|
}
|
||||||
|
|
||||||
onEnabledChanged: {
|
onEnabledChanged: {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
content.forceActiveFocus();
|
root.forceActiveFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,37 +52,6 @@ Dialog {
|
||||||
implicitWidth: Math.max(mainText.implicitWidth, buttonsRowImplicitWidth);
|
implicitWidth: Math.max(mainText.implicitWidth, buttonsRowImplicitWidth);
|
||||||
property real buttonsRowImplicitWidth: Screen.pixelDensity * 50
|
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
|
onImplicitWidthChanged: root.width = implicitWidth
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
@ -140,9 +74,46 @@ Dialog {
|
||||||
Item {
|
Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: Math.max(icon.height, mainText.height + informativeText.height + root.spacing)
|
height: Math.max(icon.height, mainText.height + informativeText.height + root.spacing)
|
||||||
Image {
|
|
||||||
|
FontAwesome {
|
||||||
id: icon
|
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 {
|
Text {
|
||||||
|
@ -348,12 +319,38 @@ Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
/*
|
|
||||||
Rectangle {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Component.onCompleted: calculateImplicitWidth()
|
|
||||||
*/
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,9 @@ import QtQuick 2.3
|
||||||
Root {
|
Root {
|
||||||
id: root
|
id: root
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
onParentChanged: {
|
||||||
|
forceActiveFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,19 +8,9 @@ import "controls"
|
||||||
Root {
|
Root {
|
||||||
id: root
|
id: root
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
onParentChanged: {
|
||||||
onWidthChanged: {
|
forceActiveFocus();
|
||||||
console.log("Root width: " + width)
|
|
||||||
}
|
}
|
||||||
onHeightChanged: {
|
|
||||||
console.log("Root height: " + height)
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
console.log("Completed root")
|
|
||||||
root.forceActiveFocus()
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
id: messageBox
|
id: messageBox
|
||||||
anchors.right: createDialog.left
|
anchors.right: createDialog.left
|
||||||
|
@ -34,7 +24,6 @@ Root {
|
||||||
console.log("Bar")
|
console.log("Bar")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
id: createDialog
|
id: createDialog
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
@ -48,7 +37,7 @@ Root {
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onPressed: {
|
Keys.onPressed: {
|
||||||
console.log(event.key);
|
console.log("Key press root")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
#include <TextRenderer.h>
|
#include <TextRenderer.h>
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
#include <MessageDialog.h>
|
||||||
|
|
||||||
#include <SceneScriptingInterface.h>
|
#include <SceneScriptingInterface.h>
|
||||||
|
|
||||||
|
@ -1086,6 +1087,11 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
bool isKeypad = event->modifiers().testFlag(Qt::KeypadModifier);
|
bool isKeypad = event->modifiers().testFlag(Qt::KeypadModifier);
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
break;
|
break;
|
||||||
|
case Qt::Key_Enter:
|
||||||
|
case Qt::Key_Return:
|
||||||
|
Menu::getInstance()->triggerOption(MenuOption::AddressBar);
|
||||||
|
break;
|
||||||
|
|
||||||
case Qt::Key_L:
|
case Qt::Key_L:
|
||||||
if (isShifted && isMeta) {
|
if (isShifted && isMeta) {
|
||||||
Menu::getInstance()->triggerOption(MenuOption::Log);
|
Menu::getInstance()->triggerOption(MenuOption::Log);
|
||||||
|
|
|
@ -37,7 +37,9 @@ void LoginDialog::toggleAction() {
|
||||||
} else {
|
} else {
|
||||||
// change the menu item to login
|
// change the menu item to login
|
||||||
loginAction->setText("Login");
|
loginAction->setText("Login");
|
||||||
connect(loginAction, &QAction::triggered, &LoginDialog::show);
|
connect(loginAction, &QAction::triggered, [] {
|
||||||
|
LoginDialog::show();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
//
|
//
|
||||||
#include "MessageDialog.h"
|
#include "MessageDialog.h"
|
||||||
|
|
||||||
QML_DIALOG_DEF(MessageDialog)
|
HIFI_QML_DEF(MessageDialog)
|
||||||
|
|
||||||
|
|
||||||
MessageDialog::MessageDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) {
|
MessageDialog::MessageDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) {
|
||||||
_buttons = StandardButtons(Ok | Cancel);
|
_buttons = StandardButtons(Ok | Cancel);
|
||||||
|
@ -76,23 +75,23 @@ void MessageDialog::setStandardButtons(StandardButtons buttons) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageDialog::click(StandardButton button) {
|
void MessageDialog::click(StandardButton button) {
|
||||||
click(static_cast<StandardButton>(button),
|
// FIXME try to do it more like the standard dialog
|
||||||
static_cast<QPlatformDialogHelper::ButtonRole>(
|
click(StandardButton(button), ButtonRole::NoRole);
|
||||||
QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(button))));
|
|
||||||
}
|
}
|
||||||
|
QMessageBox::ButtonRole br;
|
||||||
|
|
||||||
QUrl MessageDialog::standardIconSource() {
|
QUrl MessageDialog::standardIconSource() {
|
||||||
switch (icon()) {
|
switch (icon()) {
|
||||||
case QMessageDialogOptions::Information:
|
case Information:
|
||||||
return QUrl("images/information.png");
|
return QUrl("images/information.png");
|
||||||
break;
|
break;
|
||||||
case QMessageDialogOptions::Warning:
|
case Warning:
|
||||||
return QUrl("images/warning.png");
|
return QUrl("images/warning.png");
|
||||||
break;
|
break;
|
||||||
case QMessageDialogOptions::Critical:
|
case Critical:
|
||||||
return QUrl("images/critical.png");
|
return QUrl("images/critical.png");
|
||||||
break;
|
break;
|
||||||
case QMessageDialogOptions::Question:
|
case Question:
|
||||||
return QUrl("images/question.png");
|
return QUrl("images/question.png");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -109,7 +108,7 @@ MessageDialog::StandardButton MessageDialog::clickedButton() const {
|
||||||
return _clickedButton;
|
return _clickedButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageDialog::click(StandardButton button, QPlatformDialogHelper::ButtonRole) {
|
void MessageDialog::click(StandardButton button, ButtonRole) {
|
||||||
_clickedButton = button;
|
_clickedButton = button;
|
||||||
if (_resultCallback) {
|
if (_resultCallback) {
|
||||||
_resultCallback(QMessageBox::StandardButton(_clickedButton));
|
_resultCallback(QMessageBox::StandardButton(_clickedButton));
|
||||||
|
|
|
@ -13,12 +13,11 @@
|
||||||
#define hifi_MessageDialog_h
|
#define hifi_MessageDialog_h
|
||||||
|
|
||||||
#include "OffscreenQmlDialog.h"
|
#include "OffscreenQmlDialog.h"
|
||||||
#include <5.4.1/QtGui/qpa/qplatformdialoghelper.h>
|
|
||||||
|
|
||||||
class MessageDialog : public OffscreenQmlDialog
|
class MessageDialog : public OffscreenQmlDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_DIALOG_DECL
|
HIFI_QML_DECL
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_ENUMS(Icon)
|
Q_ENUMS(Icon)
|
||||||
|
@ -31,14 +30,23 @@ private:
|
||||||
Q_PROPERTY(StandardButton clickedButton READ clickedButton NOTIFY buttonClicked)
|
Q_PROPERTY(StandardButton clickedButton READ clickedButton NOTIFY buttonClicked)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Icon {
|
enum Icon { NoIcon, Information, Warning, Critical, Question };
|
||||||
NoIcon = QMessageDialogOptions::NoIcon,
|
|
||||||
Information = QMessageDialogOptions::Information,
|
|
||||||
Warning = QMessageDialogOptions::Warning,
|
|
||||||
Critical = QMessageDialogOptions::Critical,
|
|
||||||
Question = QMessageDialogOptions::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);
|
MessageDialog(QQuickItem *parent = 0);
|
||||||
virtual ~MessageDialog();
|
virtual ~MessageDialog();
|
||||||
|
@ -76,7 +84,7 @@ signals:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void click(StandardButton button, QPlatformDialogHelper::ButtonRole);
|
virtual void click(StandardButton button, ButtonRole);
|
||||||
virtual void accept();
|
virtual void accept();
|
||||||
virtual void reject();
|
virtual void reject();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#define hifi_OffscreenQmlDialog_h
|
#define hifi_OffscreenQmlDialog_h
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <5.4.1/QtGui/qpa/qplatformdialoghelper.h>
|
|
||||||
|
|
||||||
#include "OffscreenUi.h"
|
#include "OffscreenUi.h"
|
||||||
|
|
||||||
|
@ -57,25 +56,26 @@ public:
|
||||||
virtual ~OffscreenQmlDialog();
|
virtual ~OffscreenQmlDialog();
|
||||||
|
|
||||||
enum StandardButton {
|
enum StandardButton {
|
||||||
NoButton = QPlatformDialogHelper::NoButton,
|
// keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton
|
||||||
Ok = QPlatformDialogHelper::Ok,
|
NoButton = 0x00000000,
|
||||||
Save = QPlatformDialogHelper::Save,
|
Ok = 0x00000400,
|
||||||
SaveAll = QPlatformDialogHelper::SaveAll,
|
Save = 0x00000800,
|
||||||
Open = QPlatformDialogHelper::Open,
|
SaveAll = 0x00001000,
|
||||||
Yes = QPlatformDialogHelper::Yes,
|
Open = 0x00002000,
|
||||||
YesToAll = QPlatformDialogHelper::YesToAll,
|
Yes = 0x00004000,
|
||||||
No = QPlatformDialogHelper::No,
|
YesToAll = 0x00008000,
|
||||||
NoToAll = QPlatformDialogHelper::NoToAll,
|
No = 0x00010000,
|
||||||
Abort = QPlatformDialogHelper::Abort,
|
NoToAll = 0x00020000,
|
||||||
Retry = QPlatformDialogHelper::Retry,
|
Abort = 0x00040000,
|
||||||
Ignore = QPlatformDialogHelper::Ignore,
|
Retry = 0x00080000,
|
||||||
Close = QPlatformDialogHelper::Close,
|
Ignore = 0x00100000,
|
||||||
Cancel = QPlatformDialogHelper::Cancel,
|
Close = 0x00200000,
|
||||||
Discard = QPlatformDialogHelper::Discard,
|
Cancel = 0x00400000,
|
||||||
Help = QPlatformDialogHelper::Help,
|
Discard = 0x00800000,
|
||||||
Apply = QPlatformDialogHelper::Apply,
|
Help = 0x01000000,
|
||||||
Reset = QPlatformDialogHelper::Reset,
|
Apply = 0x02000000,
|
||||||
RestoreDefaults = QPlatformDialogHelper::RestoreDefaults,
|
Reset = 0x04000000,
|
||||||
|
RestoreDefaults = 0x08000000,
|
||||||
NButtons
|
NButtons
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
|
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
|
||||||
|
|
|
@ -151,17 +151,18 @@ void OffscreenUi::setBaseUrl(const QUrl& baseUrl) {
|
||||||
_qmlEngine->setBaseUrl(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;
|
qDebug() << "Loading QML from URL " << qmlSource;
|
||||||
_qmlComponent->loadUrl(qmlSource);
|
_qmlComponent->loadUrl(qmlSource);
|
||||||
if (_qmlComponent->isLoading())
|
if (_qmlComponent->isLoading()) {
|
||||||
connect(_qmlComponent, &QQmlComponent::statusChanged, this,
|
connect(_qmlComponent, &QQmlComponent::statusChanged, this,
|
||||||
[this, f](QQmlComponent::Status){
|
[this, f](QQmlComponent::Status){
|
||||||
finishQmlLoad(f);
|
finishQmlLoad(f);
|
||||||
});
|
});
|
||||||
else {
|
return nullptr;
|
||||||
finishQmlLoad(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return finishQmlLoad(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenUi::requestUpdate() {
|
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);
|
disconnect(_qmlComponent, &QQmlComponent::statusChanged, this, 0);
|
||||||
if (_qmlComponent->isError()) {
|
if (_qmlComponent->isError()) {
|
||||||
QList<QQmlError> errorList = _qmlComponent->errors();
|
QList<QQmlError> errorList = _qmlComponent->errors();
|
||||||
foreach(const QQmlError &error, errorList) {
|
foreach(const QQmlError &error, errorList) {
|
||||||
qWarning() << error.url() << error.line() << error;
|
qWarning() << error.url() << error.line() << error;
|
||||||
}
|
}
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QQmlContext * newContext = new QQmlContext(_qmlEngine, qApp);
|
QQmlContext * newContext = new QQmlContext(_qmlEngine, qApp);
|
||||||
|
@ -196,38 +197,41 @@ void OffscreenUi::finishQmlLoad(std::function<void(QQmlContext*, QObject*)> f) {
|
||||||
if (!_rootItem) {
|
if (!_rootItem) {
|
||||||
qFatal("Unable to finish loading QML root");
|
qFatal("Unable to finish loading QML root");
|
||||||
}
|
}
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
f(newContext, newObject);
|
f(newContext, newObject);
|
||||||
_qmlComponent->completeCreate();
|
_qmlComponent->completeCreate();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// All quick items should be focusable
|
||||||
|
QQuickItem* newItem = qobject_cast<QQuickItem*>(newObject);
|
||||||
|
if (newItem) {
|
||||||
// Make sure we make items focusable (critical for
|
// Make sure we make items focusable (critical for
|
||||||
// supporting keyboard shortcuts)
|
// supporting keyboard shortcuts)
|
||||||
newItem->setFlag(QQuickItem::ItemIsFocusScope, true);
|
newItem->setFlag(QQuickItem::ItemIsFocusScope, true);
|
||||||
if (!_rootItem) {
|
}
|
||||||
|
|
||||||
|
// 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(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.
|
// The root item is ready. Associate it with the window.
|
||||||
_rootItem = newItem;
|
_rootItem = newItem;
|
||||||
_rootItem->setParentItem(_quickWindow->contentItem());
|
_rootItem->setParentItem(_quickWindow->contentItem());
|
||||||
_rootItem->setSize(_quickWindow->renderTargetSize());
|
_rootItem->setSize(_quickWindow->renderTargetSize());
|
||||||
_rootItem->forceActiveFocus();
|
return _rootItem;
|
||||||
} else {
|
|
||||||
// Allow child windows to be destroyed from JS
|
|
||||||
QQmlEngine::setObjectOwnership(newItem, QQmlEngine::JavaScriptOwnership);
|
|
||||||
newItem->setParent(_rootItem);
|
|
||||||
newItem->setParentItem(_rootItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -415,7 +419,9 @@ void OffscreenUi::show(const QUrl& url, const QString& name, std::function<void(
|
||||||
load(url, f);
|
load(url, f);
|
||||||
item = _rootItem->findChild<QQuickItem*>(name);
|
item = _rootItem->findChild<QQuickItem*>(name);
|
||||||
}
|
}
|
||||||
|
if (item) {
|
||||||
item->setEnabled(true);
|
item->setEnabled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f) {
|
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);
|
load(url, f);
|
||||||
item = _rootItem->findChild<QQuickItem*>(name);
|
item = _rootItem->findChild<QQuickItem*>(name);
|
||||||
}
|
}
|
||||||
|
if (item) {
|
||||||
item->setEnabled(!item->isEnabled());
|
item->setEnabled(!item->isEnabled());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenUi::messageBox(const QString& title, const QString& text,
|
void OffscreenUi::messageBox(const QString& title, const QString& text,
|
||||||
ButtonCallback callback,
|
ButtonCallback callback,
|
||||||
QMessageBox::Icon icon,
|
QMessageBox::Icon icon,
|
||||||
QMessageBox::StandardButtons buttons) {
|
QMessageBox::StandardButtons buttons) {
|
||||||
MessageDialog::show([=](QQmlContext*ctx, QObject*item) {
|
MessageDialog * pDialog{ nullptr };
|
||||||
MessageDialog * pDialog = item->findChild<MessageDialog*>();
|
MessageDialog::show([&](QQmlContext*ctx, QObject*item) {
|
||||||
|
pDialog = item->findChild<MessageDialog*>();
|
||||||
pDialog->setIcon((MessageDialog::Icon)icon);
|
pDialog->setIcon((MessageDialog::Icon)icon);
|
||||||
pDialog->setTitle(title);
|
pDialog->setTitle(title);
|
||||||
pDialog->setText(text);
|
pDialog->setText(text);
|
||||||
pDialog->setStandardButtons(MessageDialog::StandardButtons((int)buttons));
|
pDialog->setStandardButtons(MessageDialog::StandardButtons((int)buttons));
|
||||||
pDialog->setResultCallback(callback);
|
pDialog->setResultCallback(callback);
|
||||||
});
|
});
|
||||||
|
pDialog->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenUi::information(const QString& title, const QString& text,
|
void OffscreenUi::information(const QString& title, const QString& text,
|
||||||
|
|
|
@ -38,9 +38,9 @@ private: \
|
||||||
static const QUrl QML; \
|
static const QUrl QML; \
|
||||||
public: \
|
public: \
|
||||||
static void registerType(); \
|
static void registerType(); \
|
||||||
static void show(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*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
static void toggle(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||||
static void load(std::function<void(QQmlContext*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
static void load(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#define HIFI_QML_DECL_LAMBDA \
|
#define HIFI_QML_DECL_LAMBDA \
|
||||||
|
@ -62,16 +62,16 @@ private:
|
||||||
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
|
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>(); \
|
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||||
offscreenUi->show(QML, NAME, f); \
|
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>(); \
|
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||||
offscreenUi->toggle(QML, NAME, f); \
|
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>(); \
|
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||||
offscreenUi->load(QML, f); \
|
offscreenUi->load(QML, f); \
|
||||||
}
|
}
|
||||||
|
@ -122,9 +122,9 @@ public:
|
||||||
virtual ~OffscreenUi();
|
virtual ~OffscreenUi();
|
||||||
void create(QOpenGLContext* context);
|
void create(QOpenGLContext* context);
|
||||||
void resize(const QSize& size);
|
void resize(const QSize& size);
|
||||||
void load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
QObject* 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*) {}) {
|
QObject* load(const QString& qmlSourceFile, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}) {
|
||||||
load(QUrl(qmlSourceFile), f);
|
return load(QUrl(qmlSourceFile), f);
|
||||||
}
|
}
|
||||||
void show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
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*) {});
|
void toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||||
|
@ -173,7 +173,7 @@ protected:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateQuick();
|
void updateQuick();
|
||||||
void finishQmlLoad(std::function<void(QQmlContext*, QObject*)> f);
|
QObject* finishQmlLoad(std::function<void(QQmlContext*, QObject*)> f);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void requestUpdate();
|
void requestUpdate();
|
||||||
|
|
|
@ -185,18 +185,18 @@ public:
|
||||||
QObject* menuObject = offscreenUi->getRootItem()->findChild<QObject*>("HifiMenu");
|
QObject* menuObject = offscreenUi->getRootItem()->findChild<QObject*>("HifiMenu");
|
||||||
HifiMenu* menu = offscreenUi->getRootItem()->findChild<HifiMenu*>();
|
HifiMenu* menu = offscreenUi->getRootItem()->findChild<HifiMenu*>();
|
||||||
menu->addMenu("", "File");
|
menu->addMenu("", "File");
|
||||||
menu->addMenuItem("File", "Quit", []{
|
menu->addItem("File", "Quit", []{
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
});
|
});
|
||||||
menu->addCheckableMenuItem("File", "Toggle", false, [](bool toggled) {
|
menu->addCheckableItem("File", "Toggle", false, [](bool toggled) {
|
||||||
qDebug() << "Toggle is " << toggled;
|
qDebug() << "Toggle is " << toggled;
|
||||||
});
|
});
|
||||||
menu->addMenu("", "Edit");
|
menu->addMenu("", "Edit");
|
||||||
menu->addMenuItem("Edit", "Undo");
|
menu->addItem("Edit", "Undo");
|
||||||
menu->addMenuItem("Edit", "Redo");
|
menu->addItem("Edit", "Redo");
|
||||||
menu->addMenuItem("Edit", "Copy");
|
menu->addItem("Edit", "Copy");
|
||||||
menu->addMenuItem("Edit", "Cut");
|
menu->addItem("Edit", "Cut");
|
||||||
menu->addMenuItem("Edit", "Paste");
|
menu->addItem("Edit", "Paste");
|
||||||
menu->addMenu("", "Long Menu Name...");
|
menu->addMenu("", "Long Menu Name...");
|
||||||
#endif
|
#endif
|
||||||
installEventFilter(offscreenUi.data());
|
installEventFilter(offscreenUi.data());
|
||||||
|
@ -255,8 +255,8 @@ protected:
|
||||||
if (event->modifiers() & Qt::CTRL) {
|
if (event->modifiers() & Qt::CTRL) {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
HifiMenu * menu = offscreenUi->findChild<HifiMenu*>();
|
HifiMenu * menu = offscreenUi->findChild<HifiMenu*>();
|
||||||
menu->addMenuItem("", "Test 3");
|
menu->addItem("", "Test 3");
|
||||||
menu->addMenuItem("File", "Test 3");
|
menu->addItem("File", "Test 3");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::Key_K:
|
case Qt::Key_K:
|
||||||
|
|
Loading…
Reference in a new issue