Skip to content

Commit

Permalink
add error message box
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Feb 29, 2024
1 parent 53e8784 commit 9b84b6f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/util/qopenhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ void QOpenHD::show_toast(QString message,bool long_toast)
emit signal_toast_add(message,long_toast);
}

void QOpenHD::show_error_message(QString message)
{

}

void QOpenHD::set_busy_for_milliseconds(int milliseconds,QString reason)
{
set_is_busy(true);
Expand Down
5 changes: 5 additions & 0 deletions app/util/qopenhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class QOpenHD : public QObject
//
Q_INVOKABLE void show_toast(QString message,bool long_toast=false);
L_RO_PROP(QString,version_string,set_version_string,"2.5.4-evo-alpha");
//
// Shows a message popup to the user that needs to be clicked away - use sparingly
//
Q_INVOKABLE void show_error_message(QString message);
L_RO_PROP(QString,error_message_text,set_error_message_text,"");
// Notify that something is going on for a specified amount of time
public:
Q_INVOKABLE void set_busy_for_milliseconds(int milliseconds,QString reason);
Expand Down
4 changes: 3 additions & 1 deletion qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ ApplicationWindow {
WorkaroundMessageBox{
id: workaroundmessagebox
}

ErrorMessageBox{
id: errorMessageBox
}
CardToast{
id: card_toast
m_text: _qopenhd.toast_text
Expand Down
1 change: 1 addition & 0 deletions qml/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,6 @@
<file>ui/elements/NewSpinBox.qml</file>
<file>ui/elements/NewSlider.qml</file>
<file>ui/sidebar/InfoElement2.qml</file>
<file>ui/elements/ErrorMessageBox.qml</file>
</qresource>
</RCC>
63 changes: 63 additions & 0 deletions qml/ui/elements/ErrorMessageBox.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import QtQuick 2.12
import QtQuick.Controls 2.12

import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.0

import Qt.labs.settings 1.0

import OpenHD 1.0

// We need this one to display popup messages to the user on platforms that don't support
// QMessageBox (e.g. eglfs) since QMessageBox wants to open a new window
// TODO make me less dirty / hacky
// See the corrseponding .cpp class for more info
Card {
id: errorMessageBox
width: 360
height: 340
z: 20.0
anchors.centerIn: parent
cardName: qsTr("ERROR")
cardNameColor: "red"
visible: _qopenhd.error_message_text!==""
cardBody: ScrollView {
contentHeight: errorMessageBox_text.height
contentWidth: errorMessageBox_text.width
ScrollBar.vertical.interactive: true
height: 200
width: 350
clip:true
anchors.centerIn: parent.Center
Text {
id: errorMessageBox_text
width: 320
text: _qopenhd.error_message_text
leftPadding: 12
rightPadding: 12
font.pixelSize: 14
wrapMode: Text.WordWrap
}
}
hasFooter: true
cardFooter: Item {
anchors.fill: parent
Button {
width: 140
height: 48
anchors.right: parent.right
anchors.rightMargin: 12
anchors.bottom: parent.bottom
anchors.bottomMargin: 6
font.pixelSize: 14
font.capitalization: Font.MixedCase
Material.accent: Material.Green
highlighted: true
text: qsTr("Okay")
onPressed: {
_qopenhd.show_error_message("")
hudOverlayGrid.regain_focus()
}
}
}
}

0 comments on commit 9b84b6f

Please sign in to comment.