[ui] high-level log system to prompt message dialogs in UI

* add 'info', 'warning', 'error' Signals on root object Reconstruction
* create MessageDialogs when those signals are emitted
This commit is contained in:
Yann Lanthony 2018-04-13 22:21:48 +02:00 committed by Yann Lanthony
parent 0adc4d8cc6
commit f2089108aa
5 changed files with 132 additions and 0 deletions

View file

@ -0,0 +1,53 @@
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import MaterialIcons 2.2
Dialog {
id: root
property alias text: textLabel.text
property alias detailedText: detailedLabel.text
property alias helperText: helperLabel.text
property alias icon: iconLabel
x: parent.width/2 - width/2
y: parent.height/2 - height/2
modal: true
padding: 15
standardButtons: Dialog.Ok
RowLayout {
spacing: 12
// Icon
Label {
id: iconLabel
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
font.family: MaterialIcons.fontFamily
font.pointSize: 14
visible: text != ""
}
ColumnLayout {
// Text
spacing: 12
Label {
id: textLabel
font.bold: true
visible: text != ""
}
// Detailed text
Label {
id: detailedLabel
text: text
visible: text != ""
}
// Additional helper text
Label {
id: helperLabel
visible: text != ""
}
}
}
}

View file

@ -1,3 +1,4 @@
module Controls
FloatingPane 1.0 FloatingPane.qml
MessageDialog 1.0 MessageDialog.qml

View file

@ -0,0 +1,53 @@
import QtQuick 2.9
import MaterialIcons 2.2
import Controls 1.0
/**
* DialogsFactory is utility object to instantiate generic purpose Dialogs.
*/
QtObject {
readonly property string defaultErrorText: "An unexpected error has occured"
property Component infoDialog: Component {
MessageDialog {
title: "Info"
icon.text: MaterialIcons.info
visible: true
}
}
property Component warningDialog: Component {
MessageDialog {
title: "Warning"
icon {
text: MaterialIcons.warning
color: "#FF9800"
}
visible: true
}
}
property Component errorDialog: Component {
id: errorDialog
MessageDialog {
title: "Error"
icon {
text: MaterialIcons.error
color: "#F44336"
}
text: defaultErrorText
visible: true
}
}
function info(window) {
return infoDialog.createObject(window)
}
function warning(window) {
return warningDialog.createObject(window)
}
function error(window) {
return errorDialog.createObject(window)
}
}

View file

@ -191,6 +191,26 @@ ApplicationWindow {
}
}
DialogsFactory {
id: dialogsFactory
}
// Bind log messages to DialogsFactory
Connections {
target: _reconstruction
function createDialog(func, args)
{
var dialog = func(_window)
// Set text afterwards to avoid dialog sizing issues
dialog.title = args[0]
dialog.text = args[1]
dialog.detailedText = args[2]
}
onInfo: createDialog(dialogsFactory.info, arguments)
onWarning: createDialog(dialogsFactory.warning, arguments)
onError: createDialog(dialogsFactory.error, arguments)
}
Action {
id: undoAction

View file

@ -452,3 +452,8 @@ class Reconstruction(UIGraph):
sfmReport = Property(bool, lambda self: len(self._poses) > 0, notify=sfmReportChanged)
sfmAugmented = Signal(graph.Node, graph.Node)
# Signals to propagate high-level log messages
# Signal(title, text, detailedText)
error = Signal(str, str, str)
warning = Signal(str, str, str)
info = Signal(str, str, str)