mirror of
https://github.com/overte-org/overte.git
synced 2025-04-13 11:43:24 +02:00
Adding first pass at message box
This commit is contained in:
parent
a9d65f168b
commit
8269b9925b
15 changed files with 740 additions and 71 deletions
|
@ -6,9 +6,13 @@ import QtQuick.Controls.Styles 1.3
|
|||
Button {
|
||||
SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
|
||||
text: "Text"
|
||||
width: 128
|
||||
height: 64
|
||||
style: ButtonStyle {
|
||||
padding {
|
||||
top: 8
|
||||
left: 12
|
||||
right: 12
|
||||
bottom: 8
|
||||
}
|
||||
background: CustomBorder {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
|
359
interface/resources/qml/MessageDialog.qml
Normal file
359
interface/resources/qml/MessageDialog.qml
Normal file
|
@ -0,0 +1,359 @@
|
|||
/*****************************************************************************
|
||||
**
|
||||
** 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
|
||||
import QtQuick.Window 2.1
|
||||
import QtQuick.Dialogs 1.2
|
||||
|
||||
CustomDialog {
|
||||
id: root
|
||||
property real spacing: 8
|
||||
property real outerSpacing: 16
|
||||
|
||||
destroyOnCloseButton: true
|
||||
destroyOnInvisible: true
|
||||
implicitHeight: content.implicitHeight + outerSpacing * 2 + 48
|
||||
implicitWidth: Math.min(200, Math.max(mainText.implicitWidth, content.buttonsRowImplicitWidth) + outerSpacing * 2);
|
||||
|
||||
onImplicitHeightChanged: root.height = implicitHeight
|
||||
onImplicitWidthChanged: root.width = implicitWidth
|
||||
|
||||
SystemPalette { id: palette }
|
||||
|
||||
function calculateImplicitWidth() {
|
||||
if (buttons.visibleChildren.length < 2)
|
||||
return;
|
||||
var calcWidth = 0;
|
||||
for (var i = 0; i < buttons.visibleChildren.length; ++i) {
|
||||
calcWidth += Math.max(100, buttons.visibleChildren[i].implicitWidth) + root.spacing
|
||||
}
|
||||
content.buttonsRowImplicitWidth = outerSpacing + calcWidth + 48
|
||||
}
|
||||
|
||||
onEnabledChanged: {
|
||||
if (enabled) {
|
||||
content.forceActiveFocus();
|
||||
}
|
||||
}
|
||||
|
||||
Hifi.MessageDialog {
|
||||
id: content
|
||||
clip: true
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: parent.topMargin + root.outerSpacing
|
||||
anchors.leftMargin: parent.margins + root.outerSpacing
|
||||
anchors.rightMargin: parent.margins + root.outerSpacing
|
||||
anchors.bottomMargin: parent.margins + root.outerSpacing
|
||||
implicitHeight: contentColumn.implicitHeight + outerSpacing * 2
|
||||
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: {
|
||||
root.title = title
|
||||
}
|
||||
|
||||
onTitleChanged: {
|
||||
root.title = title
|
||||
}
|
||||
|
||||
Column {
|
||||
id: contentColumn
|
||||
spacing: root.outerSpacing
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Math.max(icon.height, mainText.height + informativeText.height + root.spacing)
|
||||
Image {
|
||||
id: icon
|
||||
source: content.standardIconSource
|
||||
}
|
||||
|
||||
Text {
|
||||
id: mainText
|
||||
anchors {
|
||||
left: icon.right
|
||||
leftMargin: root.spacing
|
||||
right: parent.right
|
||||
}
|
||||
text: content.text
|
||||
font.pointSize: 14
|
||||
font.weight: Font.Bold
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
Text {
|
||||
id: informativeText
|
||||
anchors {
|
||||
left: icon.right
|
||||
right: parent.right
|
||||
top: mainText.bottom
|
||||
leftMargin: root.spacing
|
||||
topMargin: root.spacing
|
||||
}
|
||||
text: content.informativeText
|
||||
font.pointSize: 14
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Flow {
|
||||
id: buttons
|
||||
spacing: root.spacing
|
||||
layoutDirection: Qt.RightToLeft
|
||||
width: parent.width
|
||||
CustomButton {
|
||||
id: okButton
|
||||
text: qsTr("OK")
|
||||
onClicked: content.click(StandardButton.Ok)
|
||||
visible: content.standardButtons & StandardButton.Ok
|
||||
}
|
||||
CustomButton {
|
||||
id: openButton
|
||||
text: qsTr("Open")
|
||||
onClicked: content.click(StandardButton.Open)
|
||||
visible: content.standardButtons & StandardButton.Open
|
||||
}
|
||||
CustomButton {
|
||||
id: saveButton
|
||||
text: qsTr("Save")
|
||||
onClicked: content.click(StandardButton.Save)
|
||||
visible: content.standardButtons & StandardButton.Save
|
||||
}
|
||||
CustomButton {
|
||||
id: saveAllButton
|
||||
text: qsTr("Save All")
|
||||
onClicked: content.click(StandardButton.SaveAll)
|
||||
visible: content.standardButtons & StandardButton.SaveAll
|
||||
}
|
||||
CustomButton {
|
||||
id: retryButton
|
||||
text: qsTr("Retry")
|
||||
onClicked: content.click(StandardButton.Retry)
|
||||
visible: content.standardButtons & StandardButton.Retry
|
||||
}
|
||||
CustomButton {
|
||||
id: ignoreButton
|
||||
text: qsTr("Ignore")
|
||||
onClicked: content.click(StandardButton.Ignore)
|
||||
visible: content.standardButtons & StandardButton.Ignore
|
||||
}
|
||||
CustomButton {
|
||||
id: applyButton
|
||||
text: qsTr("Apply")
|
||||
onClicked: content.click(StandardButton.Apply)
|
||||
visible: content.standardButtons & StandardButton.Apply
|
||||
}
|
||||
CustomButton {
|
||||
id: yesButton
|
||||
text: qsTr("Yes")
|
||||
onClicked: content.click(StandardButton.Yes)
|
||||
visible: content.standardButtons & StandardButton.Yes
|
||||
}
|
||||
CustomButton {
|
||||
id: yesAllButton
|
||||
text: qsTr("Yes to All")
|
||||
onClicked: content.click(StandardButton.YesToAll)
|
||||
visible: content.standardButtons & StandardButton.YesToAll
|
||||
}
|
||||
CustomButton {
|
||||
id: noButton
|
||||
text: qsTr("No")
|
||||
onClicked: content.click(StandardButton.No)
|
||||
visible: content.standardButtons & StandardButton.No
|
||||
}
|
||||
CustomButton {
|
||||
id: noAllButton
|
||||
text: qsTr("No to All")
|
||||
onClicked: content.click(StandardButton.NoToAll)
|
||||
visible: content.standardButtons & StandardButton.NoToAll
|
||||
}
|
||||
CustomButton {
|
||||
id: discardButton
|
||||
text: qsTr("Discard")
|
||||
onClicked: content.click(StandardButton.Discard)
|
||||
visible: content.standardButtons & StandardButton.Discard
|
||||
}
|
||||
CustomButton {
|
||||
id: resetButton
|
||||
text: qsTr("Reset")
|
||||
onClicked: content.click(StandardButton.Reset)
|
||||
visible: content.standardButtons & StandardButton.Reset
|
||||
}
|
||||
CustomButton {
|
||||
id: restoreDefaultsButton
|
||||
text: qsTr("Restore Defaults")
|
||||
onClicked: content.click(StandardButton.RestoreDefaults)
|
||||
visible: content.standardButtons & StandardButton.RestoreDefaults
|
||||
}
|
||||
CustomButton {
|
||||
id: cancelButton
|
||||
text: qsTr("Cancel")
|
||||
onClicked: content.click(StandardButton.Cancel)
|
||||
visible: content.standardButtons & StandardButton.Cancel
|
||||
}
|
||||
CustomButton {
|
||||
id: abortButton
|
||||
text: qsTr("Abort")
|
||||
onClicked: content.click(StandardButton.Abort)
|
||||
visible: content.standardButtons & StandardButton.Abort
|
||||
}
|
||||
CustomButton {
|
||||
id: closeButton
|
||||
text: qsTr("Close")
|
||||
onClicked: content.click(StandardButton.Close)
|
||||
visible: content.standardButtons & StandardButton.Close
|
||||
}
|
||||
CustomButton {
|
||||
id: moreButton
|
||||
text: qsTr("Show Details...")
|
||||
onClicked: content.state = (content.state === "" ? "expanded" : "")
|
||||
visible: content.detailedText.length > 0
|
||||
}
|
||||
CustomButton {
|
||||
id: helpButton
|
||||
text: qsTr("Help")
|
||||
onClicked: content.click(StandardButton.Help)
|
||||
visible: content.standardButtons & StandardButton.Help
|
||||
}
|
||||
onVisibleChildrenChanged: root.calculateImplicitWidth()
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: details
|
||||
width: parent.width
|
||||
implicitHeight: detailedText.implicitHeight + root.spacing
|
||||
height: 0
|
||||
clip: true
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
top: contentColumn.bottom
|
||||
topMargin: root.spacing
|
||||
leftMargin: root.outerSpacing
|
||||
rightMargin: root.outerSpacing
|
||||
}
|
||||
|
||||
Flickable {
|
||||
id: flickable
|
||||
contentHeight: detailedText.height
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: root.spacing
|
||||
anchors.bottomMargin: root.outerSpacing
|
||||
TextEdit {
|
||||
id: detailedText
|
||||
text: content.detailedText
|
||||
width: details.width
|
||||
wrapMode: Text.WordWrap
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "expanded"
|
||||
PropertyChanges {
|
||||
target: details
|
||||
height: root.height - contentColumn.height - root.spacing - root.outerSpacing
|
||||
}
|
||||
PropertyChanges {
|
||||
target: content
|
||||
implicitHeight: contentColumn.implicitHeight + root.spacing * 2 +
|
||||
detailedText.implicitHeight + root.outerSpacing * 2
|
||||
}
|
||||
PropertyChanges {
|
||||
target: moreButton
|
||||
text: qsTr("Hide Details")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
/*
|
||||
Rectangle {
|
||||
|
||||
}
|
||||
Component.onCompleted: calculateImplicitWidth()
|
||||
*/
|
||||
}
|
||||
}
|
BIN
interface/resources/qml/images/critical.png
Normal file
BIN
interface/resources/qml/images/critical.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 253 B |
BIN
interface/resources/qml/images/information.png
Normal file
BIN
interface/resources/qml/images/information.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 B |
BIN
interface/resources/qml/images/question.png
Normal file
BIN
interface/resources/qml/images/question.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 B |
BIN
interface/resources/qml/images/warning.png
Normal file
BIN
interface/resources/qml/images/warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 224 B |
|
@ -85,6 +85,7 @@
|
|||
#include <UserActivityLogger.h>
|
||||
#include <UUID.h>
|
||||
#include <OAuthNetworkAccessManager.h>
|
||||
#include <MessageDialog.h>
|
||||
|
||||
#include <SceneScriptingInterface.h>
|
||||
|
||||
|
@ -762,11 +763,10 @@ void Application::initializeUi() {
|
|||
AddressBarDialog::registerType();
|
||||
LoginDialog::registerType();
|
||||
MarketplaceDialog::registerType();
|
||||
MessageDialog::registerType();
|
||||
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
offscreenUi->create(_glWidget->context()->contextHandle());
|
||||
offscreenUi->qmlEngine()->setNetworkAccessManagerFactory(new OAuthFactory());
|
||||
offscreenUi->qmlEngine()->networkAccessManager();
|
||||
offscreenUi->resize(_glWidget->size());
|
||||
offscreenUi->setProxyWindow(_window->windowHandle());
|
||||
offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
|
||||
|
|
|
@ -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,40 +10,20 @@
|
|||
|
||||
#include "Application.h"
|
||||
#include "MarketplaceDialog.h"
|
||||
|
||||
|
||||
#include <QWebEnginePage>
|
||||
|
||||
#include "DependencyManager.h"
|
||||
|
||||
QML_DIALOG_DEF(MarketplaceDialog)
|
||||
|
||||
|
||||
MarketplaceDialog::MarketplaceDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) {
|
||||
this->
|
||||
}
|
||||
|
||||
bool MarketplaceDialog::navigationRequested(const QString & url) {
|
||||
qDebug() << url;
|
||||
if (Application::getInstance()->canAcceptURL(url)) {
|
||||
qDebug() << "Trying to send url to the app";
|
||||
if (Application::getInstance()->acceptURL(url)) {
|
||||
qDebug() << "Sent url to the app";
|
||||
return false; // we handled it, so QWebPage doesn't need to handle it
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//https://metaverse.highfidelity.com/marketplace
|
||||
|
||||
//
|
||||
//bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) {
|
||||
// QString urlString = request.url().toString();
|
||||
// if (Application::getInstance()->canAcceptURL(urlString)) {
|
||||
// if (Application::getInstance()->acceptURL(urlString)) {
|
||||
// return false; // we handled it, so QWebPage doesn't need to handle it
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
//}
|
142
libraries/render-utils/src/MessageDialog.cpp
Normal file
142
libraries/render-utils/src/MessageDialog.cpp
Normal file
|
@ -0,0 +1,142 @@
|
|||
//
|
||||
//
|
||||
// MessageDialog.cpp
|
||||
//
|
||||
// Created by Bradley Austin Davis on 2015/04/14
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "MessageDialog.h"
|
||||
|
||||
QML_DIALOG_DEF(MessageDialog)
|
||||
|
||||
|
||||
MessageDialog::MessageDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) {
|
||||
_buttons = StandardButtons(Ok | Cancel);
|
||||
}
|
||||
|
||||
MessageDialog::~MessageDialog() {
|
||||
}
|
||||
|
||||
QString MessageDialog::text() const {
|
||||
return _text;
|
||||
}
|
||||
|
||||
QString MessageDialog::informativeText() const {
|
||||
return _informativeText;
|
||||
}
|
||||
|
||||
QString MessageDialog::detailedText() const {
|
||||
return _detailedText;
|
||||
}
|
||||
|
||||
MessageDialog::Icon MessageDialog::icon() const {
|
||||
return _icon;
|
||||
}
|
||||
|
||||
void MessageDialog::setVisible(bool v) {
|
||||
OffscreenQmlDialog::setVisible(v);
|
||||
}
|
||||
|
||||
void MessageDialog::setText(const QString &arg) {
|
||||
if (arg != _text) {
|
||||
_text = arg;
|
||||
emit textChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDialog::setInformativeText(const QString &arg) {
|
||||
if (arg != _informativeText) {
|
||||
_informativeText = arg;
|
||||
emit informativeTextChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDialog::setDetailedText(const QString &arg) {
|
||||
if (arg != _detailedText) {
|
||||
_detailedText = arg;
|
||||
emit detailedTextChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDialog::setIcon(MessageDialog::Icon icon) {
|
||||
if (icon != _icon) {
|
||||
_icon = icon;
|
||||
emit iconChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDialog::setStandardButtons(StandardButtons buttons) {
|
||||
if (buttons != _buttons) {
|
||||
_buttons = buttons;
|
||||
emit standardButtonsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDialog::click(StandardButton button) {
|
||||
click(static_cast<StandardButton>(button),
|
||||
static_cast<QPlatformDialogHelper::ButtonRole>(
|
||||
QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(button))));
|
||||
}
|
||||
|
||||
QUrl MessageDialog::standardIconSource() {
|
||||
switch (icon()) {
|
||||
case QMessageDialogOptions::Information:
|
||||
return QUrl("images/information.png");
|
||||
break;
|
||||
case QMessageDialogOptions::Warning:
|
||||
return QUrl("images/warning.png");
|
||||
break;
|
||||
case QMessageDialogOptions::Critical:
|
||||
return QUrl("images/critical.png");
|
||||
break;
|
||||
case QMessageDialogOptions::Question:
|
||||
return QUrl("images/question.png");
|
||||
break;
|
||||
default:
|
||||
return QUrl();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog::StandardButtons MessageDialog::standardButtons() const {
|
||||
return _buttons;
|
||||
}
|
||||
|
||||
MessageDialog::StandardButton MessageDialog::clickedButton() const {
|
||||
return _clickedButton;
|
||||
}
|
||||
|
||||
void MessageDialog::click(StandardButton button, QPlatformDialogHelper::ButtonRole) {
|
||||
_clickedButton = button;
|
||||
if (_resultCallback) {
|
||||
_resultCallback(QMessageBox::StandardButton(_clickedButton));
|
||||
}
|
||||
hide();
|
||||
}
|
||||
|
||||
void MessageDialog::accept() {
|
||||
// enter key is treated like OK
|
||||
if (_clickedButton == NoButton)
|
||||
_clickedButton = Ok;
|
||||
if (_resultCallback) {
|
||||
_resultCallback(QMessageBox::StandardButton(_clickedButton));
|
||||
}
|
||||
OffscreenQmlDialog::accept();
|
||||
}
|
||||
|
||||
void MessageDialog::reject() {
|
||||
// escape key is treated like cancel
|
||||
if (_clickedButton == NoButton)
|
||||
_clickedButton = Cancel;
|
||||
if (_resultCallback) {
|
||||
_resultCallback(QMessageBox::StandardButton(_clickedButton));
|
||||
}
|
||||
OffscreenQmlDialog::reject();
|
||||
}
|
||||
|
||||
void MessageDialog::setResultCallback(OffscreenUi::ButtonCallback callback) {
|
||||
_resultCallback = callback;
|
||||
}
|
98
libraries/render-utils/src/MessageDialog.h
Normal file
98
libraries/render-utils/src/MessageDialog.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// MessageDialog.h
|
||||
//
|
||||
// Created by Bradley Austin Davis on 2015/04/14
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef hifi_MessageDialog_h
|
||||
#define hifi_MessageDialog_h
|
||||
|
||||
#include "OffscreenQmlDialog.h"
|
||||
#include <5.4.1/QtGui/qpa/qplatformdialoghelper.h>
|
||||
|
||||
class MessageDialog : public OffscreenQmlDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_DIALOG_DECL
|
||||
|
||||
private:
|
||||
Q_ENUMS(Icon)
|
||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||
Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText NOTIFY informativeTextChanged)
|
||||
Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText NOTIFY detailedTextChanged)
|
||||
Q_PROPERTY(Icon icon READ icon WRITE setIcon NOTIFY iconChanged)
|
||||
Q_PROPERTY(QUrl standardIconSource READ standardIconSource NOTIFY iconChanged)
|
||||
Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged)
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
MessageDialog(QQuickItem *parent = 0);
|
||||
virtual ~MessageDialog();
|
||||
|
||||
QString text() const;
|
||||
QString informativeText() const;
|
||||
QString detailedText() const;
|
||||
Icon icon() const;
|
||||
|
||||
public slots:
|
||||
virtual void setVisible(bool v);
|
||||
void setText(const QString &arg);
|
||||
void setInformativeText(const QString &arg);
|
||||
void setDetailedText(const QString &arg);
|
||||
void setIcon(Icon icon);
|
||||
void setStandardButtons(StandardButtons buttons);
|
||||
void setResultCallback(OffscreenUi::ButtonCallback callback);
|
||||
void click(StandardButton button);
|
||||
QUrl standardIconSource();
|
||||
StandardButtons standardButtons() const;
|
||||
StandardButton clickedButton() const;
|
||||
|
||||
signals:
|
||||
void textChanged();
|
||||
void informativeTextChanged();
|
||||
void detailedTextChanged();
|
||||
void iconChanged();
|
||||
void standardButtonsChanged();
|
||||
void buttonClicked();
|
||||
void discard();
|
||||
void help();
|
||||
void yes();
|
||||
void no();
|
||||
void apply();
|
||||
void reset();
|
||||
|
||||
protected slots:
|
||||
virtual void click(StandardButton button, QPlatformDialogHelper::ButtonRole);
|
||||
virtual void accept();
|
||||
virtual void reject();
|
||||
|
||||
private:
|
||||
QString _title;
|
||||
QString _text;
|
||||
QString _informativeText;
|
||||
QString _detailedText;
|
||||
Icon _icon{ Information };
|
||||
StandardButtons _buttons;
|
||||
StandardButton _clickedButton{ NoButton };
|
||||
OffscreenUi::ButtonCallback _resultCallback;
|
||||
};
|
||||
|
||||
#endif // hifi_MessageDialog_h
|
||||
|
||||
|
||||
|
||||
|
|
@ -13,6 +13,30 @@
|
|||
OffscreenQmlDialog::OffscreenQmlDialog(QQuickItem* parent)
|
||||
: QQuickItem(parent) { }
|
||||
|
||||
OffscreenQmlDialog::~OffscreenQmlDialog() {
|
||||
}
|
||||
|
||||
void OffscreenQmlDialog::hide() {
|
||||
static_cast<QQuickItem*>(parent())->setEnabled(false);
|
||||
}
|
||||
|
||||
QString OffscreenQmlDialog::title() const {
|
||||
return _title;
|
||||
}
|
||||
|
||||
void OffscreenQmlDialog::setTitle(const QString &arg) {
|
||||
if (arg != _title) {
|
||||
_title = arg;
|
||||
emit titleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void OffscreenQmlDialog::accept() {
|
||||
hide();
|
||||
emit accepted();
|
||||
}
|
||||
|
||||
void OffscreenQmlDialog::reject() {
|
||||
hide();
|
||||
emit rejected();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#define hifi_OffscreenQmlDialog_h
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <5.4.1/QtGui/qpa/qplatformdialoghelper.h>
|
||||
|
||||
#include "OffscreenUi.h"
|
||||
|
||||
#define QML_DIALOG_DECL \
|
||||
|
@ -21,8 +23,8 @@ private: \
|
|||
static const QUrl QML; \
|
||||
public: \
|
||||
static void registerType(); \
|
||||
static void show(); \
|
||||
static void toggle(); \
|
||||
static void show(std::function<void(QQmlContext*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
static void toggle(std::function<void(QQmlContext*, QQuickItem *)> f = [](QQmlContext*, QQuickItem*) {}); \
|
||||
private:
|
||||
|
||||
#define QML_DIALOG_DEF(x) \
|
||||
|
@ -33,24 +35,70 @@ private:
|
|||
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
|
||||
} \
|
||||
\
|
||||
void x::show() { \
|
||||
void x::show(std::function<void(QQmlContext*, QQuickItem *)> f) { \
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||
offscreenUi->show(QML, NAME); \
|
||||
offscreenUi->show(QML, NAME, f); \
|
||||
} \
|
||||
\
|
||||
void x::toggle() { \
|
||||
void x::toggle(std::function<void(QQmlContext*, QQuickItem *)> f) { \
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
|
||||
offscreenUi->toggle(QML, NAME); \
|
||||
offscreenUi->toggle(QML, NAME, f); \
|
||||
}
|
||||
|
||||
class OffscreenQmlDialog : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
||||
Q_ENUMS(StandardButton)
|
||||
Q_FLAGS(StandardButtons)
|
||||
|
||||
public:
|
||||
OffscreenQmlDialog(QQuickItem* parent = nullptr);
|
||||
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,
|
||||
NButtons
|
||||
};
|
||||
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
|
||||
|
||||
protected:
|
||||
void hide();
|
||||
virtual void accept();
|
||||
virtual void reject();
|
||||
|
||||
public:
|
||||
QString title() const;
|
||||
void setTitle(const QString &arg);
|
||||
|
||||
signals:
|
||||
void accepted();
|
||||
void rejected();
|
||||
void titleChanged();
|
||||
|
||||
private:
|
||||
QString _title;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(OffscreenQmlDialog::StandardButtons)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <QOpenGLDebugLogger>
|
||||
#include <QGLWidget>
|
||||
#include <QtQml>
|
||||
#include "MessageDialog.h"
|
||||
|
||||
// Time between receiving a request to render the offscreen UI actually triggering
|
||||
// the render. Could possibly be increased depending on the framerate we expect to
|
||||
|
@ -140,13 +141,15 @@ void OffscreenUi::setBaseUrl(const QUrl& baseUrl) {
|
|||
_qmlEngine->setBaseUrl(baseUrl);
|
||||
}
|
||||
|
||||
void OffscreenUi::load(const QUrl& qmlSource, std::function<void(QQmlContext*)> f) {
|
||||
void OffscreenUi::load(const QUrl& qmlSource, std::function<void(QQmlContext*, QQuickItem*)> f) {
|
||||
qDebug() << "Loading QML from URL " << qmlSource;
|
||||
_qmlComponent->loadUrl(qmlSource);
|
||||
if (_qmlComponent->isLoading()) {
|
||||
connect(_qmlComponent, &QQmlComponent::statusChanged, this, []{});
|
||||
} else {
|
||||
finishQmlLoad();
|
||||
if (_qmlComponent->isLoading())
|
||||
connect(_qmlComponent, &QQmlComponent::statusChanged, this, [this, f] {
|
||||
finishQmlLoad(f);
|
||||
});
|
||||
else {
|
||||
finishQmlLoad(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,7 +166,7 @@ void OffscreenUi::requestRender() {
|
|||
}
|
||||
}
|
||||
|
||||
void OffscreenUi::finishQmlLoad() {
|
||||
void OffscreenUi::finishQmlLoad(std::function<void(QQmlContext*, QQuickItem*)> f) {
|
||||
disconnect(_qmlComponent, &QQmlComponent::statusChanged, this, &OffscreenUi::finishQmlLoad);
|
||||
if (_qmlComponent->isError()) {
|
||||
QList<QQmlError> errorList = _qmlComponent->errors();
|
||||
|
@ -197,7 +200,7 @@ void OffscreenUi::finishQmlLoad() {
|
|||
// Make sure we make items focusable (critical for
|
||||
// supporting keyboard shortcuts)
|
||||
newItem->setFlag(QQuickItem::ItemIsFocusScope, true);
|
||||
|
||||
f(_qmlEngine->contextForObject(newItem), newItem);
|
||||
if (!_rootItem) {
|
||||
// The root item is ready. Associate it with the window.
|
||||
_rootItem = newItem;
|
||||
|
@ -390,54 +393,62 @@ void OffscreenUi::setProxyWindow(QWindow* window) {
|
|||
_renderControl->_renderWindow = window;
|
||||
}
|
||||
|
||||
void OffscreenUi::show(const QUrl& url, const QString& name) {
|
||||
void OffscreenUi::show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QQuickItem *)> f) {
|
||||
QQuickItem* item = _rootItem->findChild<QQuickItem*>(name);
|
||||
// First load?
|
||||
if (!item) {
|
||||
load(url);
|
||||
load(url, f);
|
||||
return;
|
||||
}
|
||||
item->setEnabled(true);
|
||||
}
|
||||
|
||||
void OffscreenUi::toggle(const QUrl& url, const QString& name) {
|
||||
void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QQuickItem *)> f) {
|
||||
QQuickItem* item = _rootItem->findChild<QQuickItem*>(name);
|
||||
// First load?
|
||||
if (!item) {
|
||||
load(url);
|
||||
load(url, f);
|
||||
return;
|
||||
}
|
||||
item->setEnabled(!item->isEnabled());
|
||||
}
|
||||
|
||||
void OffscreenUi::messageBox(const QString& title, const QString& text,
|
||||
ButtonCallback callback,
|
||||
QMessageBox::Icon icon,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
ButtonCallback f) {
|
||||
QMessageBox::StandardButtons buttons) {
|
||||
MessageDialog::show([=](QQmlContext*ctx, QQuickItem*item) {
|
||||
MessageDialog * pDialog = item->findChild<MessageDialog*>();
|
||||
pDialog->setIcon((MessageDialog::Icon)icon);
|
||||
pDialog->setTitle(title);
|
||||
pDialog->setText(text);
|
||||
pDialog->setStandardButtons(MessageDialog::StandardButtons((int)buttons));
|
||||
pDialog->setResultCallback(callback);
|
||||
});
|
||||
}
|
||||
|
||||
void OffscreenUi::information(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
ButtonCallback callback) {
|
||||
callback(QMessageBox::information(nullptr, title, text, buttons));
|
||||
ButtonCallback callback,
|
||||
QMessageBox::StandardButtons buttons) {
|
||||
messageBox(title, text, callback, (QMessageBox::Icon)MessageDialog::Information, buttons);
|
||||
}
|
||||
|
||||
void OffscreenUi::question(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
ButtonCallback callback) {
|
||||
callback(QMessageBox::question(nullptr, title, text, buttons));
|
||||
ButtonCallback callback,
|
||||
QMessageBox::StandardButtons buttons) {
|
||||
messageBox(title, text, callback, (QMessageBox::Icon)MessageDialog::Question, buttons);
|
||||
}
|
||||
|
||||
void OffscreenUi::warning(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
ButtonCallback callback) {
|
||||
callback(QMessageBox::warning(nullptr, title, text, buttons));
|
||||
ButtonCallback callback,
|
||||
QMessageBox::StandardButtons buttons) {
|
||||
messageBox(title, text, callback, (QMessageBox::Icon)MessageDialog::Warning, buttons);
|
||||
}
|
||||
|
||||
void OffscreenUi::critical(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
ButtonCallback callback) {
|
||||
callback(QMessageBox::critical(nullptr, title, text, buttons));
|
||||
ButtonCallback callback,
|
||||
QMessageBox::StandardButtons buttons) {
|
||||
messageBox(title, text, callback, (QMessageBox::Icon)MessageDialog::Critical, buttons);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -59,12 +59,12 @@ public:
|
|||
virtual ~OffscreenUi();
|
||||
void create(QOpenGLContext* context);
|
||||
void resize(const QSize& size);
|
||||
void load(const QUrl& qmlSource, std::function<void(QQmlContext*)> f = [](QQmlContext*) {});
|
||||
void load(const QString& qmlSourceFile, std::function<void(QQmlContext*)> f = [](QQmlContext*) {}) {
|
||||
void load(const QUrl& qmlSource, std::function<void(QQmlContext*)> f = [](QQmlContext*, QQuickItem*) {});
|
||||
void load(const QString& qmlSourceFile, std::function<void(QQmlContext*)> f = [](QQmlContext*, QQuickItem*) {}) {
|
||||
load(QUrl(qmlSourceFile), f);
|
||||
}
|
||||
void show(const QUrl& url, const QString& name);
|
||||
void toggle(const QUrl& url, const QString& name);
|
||||
void show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QQuickItem*)> f = [](QQmlContext*, QQuickItem*) {}));
|
||||
void toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QQuickItem*)> f = [](QQmlContext*, QQuickItem*) {}));
|
||||
void setBaseUrl(const QUrl& baseUrl);
|
||||
void addImportPath(const QString& path);
|
||||
QQmlContext* qmlContext();
|
||||
|
@ -86,31 +86,32 @@ public:
|
|||
static ButtonCallback NO_OP_CALLBACK;
|
||||
|
||||
static void messageBox(const QString& title, const QString& text,
|
||||
static void messageBox(const QString &title, const QString &text,
|
||||
ButtonCallback f,
|
||||
QMessageBox::Icon icon,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
ButtonCallback f);
|
||||
QMessageBox::StandardButtons buttons);
|
||||
|
||||
static void information(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
ButtonCallback callback = NO_OP_CALLBACK);
|
||||
ButtonCallback callback = NO_OP_CALLBACK,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok);
|
||||
|
||||
static void question(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No),
|
||||
ButtonCallback callback = [](QMessageBox::StandardButton) {});
|
||||
ButtonCallback callback = NO_OP_CALLBACK,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No));
|
||||
|
||||
static void warning(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
ButtonCallback callback = [](QMessageBox::StandardButton) {});
|
||||
ButtonCallback callback = NO_OP_CALLBACK,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok);
|
||||
|
||||
static void critical(const QString& title, const QString& text,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
ButtonCallback callback = [](QMessageBox::StandardButton) {});
|
||||
ButtonCallback callback = NO_OP_CALLBACK,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok);
|
||||
|
||||
protected:
|
||||
|
||||
private slots:
|
||||
void updateQuick();
|
||||
void finishQmlLoad();
|
||||
void finishQmlLoad(std::function<void(QQmlContext*, QQuickItem *)> f);
|
||||
|
||||
public slots:
|
||||
void requestUpdate();
|
||||
|
|
Loading…
Reference in a new issue