Enroute Flight Navigation
A navigation app for VFR pilots
Notification.h
1/***************************************************************************
2 * Copyright (C) 2023-2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QObject>
24#include <QQmlEngine>
25
26#include "units/Timespan.h"
27
28using namespace Qt::Literals::StringLiterals;
29
30namespace Notifications {
31
42
43class Notification : public QObject
44{
45 Q_OBJECT
46 QML_ELEMENT
47
48public:
50 enum Importance : quint8 {
51 Info = 1<<1,
53 Warning = 1<<3,
55 Alert = 1<<5
56 };
57 Q_ENUM(Importance);
58
69 Q_ENUM(TextBodyAction);
70
71
72 //
73 // Constructors and destructors
74 //
75
76public:
88 explicit Notification(
89 QString _title,
91 QObject* parent = nullptr);
92
93 // Standard constructor, required by QML
94 explicit Notification(QObject* parent = nullptr);
95
97 ~Notification() override = default;
98
99 //
100 // PROPERTIES
101 //
102
109 Q_PROPERTY(QString button1Text READ button1Text WRITE setButton1Text NOTIFY button1TextChanged)
110
111
117 Q_PROPERTY(QString button2Text READ button2Text WRITE setButton2Text NOTIFY button2TextChanged)
118
124 Q_PROPERTY(Notifications::Notification::Importance importance READ importance CONSTANT)
125
133 Q_PROPERTY(Units::Timespan reactionTime READ reactionTime WRITE setReactionTime NOTIFY reactionTimeChanged)
134
141 Q_PROPERTY(QString spokenText READ spokenText WRITE setSpokenText NOTIFY spokenTextChanged)
142
147 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
148
155
161 Q_PROPERTY(QString title READ title CONSTANT)
162
163
164 //
165 // Getter Methods
166 //
167
172 [[nodiscard]] QString button1Text() const { return m_button1Text; }
173
178 [[nodiscard]] QString button2Text() const { return m_button2Text; }
179
184 [[nodiscard]] Notifications::Notification::Importance importance() const { return m_importance; }
185
190 [[nodiscard]] Units::Timespan reactionTime() const { return m_reactionTime; }
191
196 [[nodiscard]] QString spokenText() const;
197
202 [[nodiscard]] QString text() const { return m_text; }
203
208 [[nodiscard]] Notifications::Notification::TextBodyAction textBodyAction() const { return m_textBodyAction; }
209
214 [[nodiscard]] QString title() const { return m_title; }
215
216
217
218 //
219 // Setter Methods
220 //
221
226 void setButton1Text(const QString& newButton1Text);
227
232 void setButton2Text(const QString& newButton2Text);
233
238 void setReactionTime(Units::Timespan newReactionTime);
239
244 void setSpokenText(const QString& newSpokenText);
245
250 void setText(const QString& newText);
251
257
258
259 //
260 // Methods
261 //
262
270 Q_INVOKABLE virtual void onButton1Clicked();
271
279 Q_INVOKABLE virtual void onButton2Clicked();
280
281signals:
284
287
290
293
296
299
300
301private:
302 Q_DISABLE_COPY_MOVE(Notification)
303
304 // Property data
305 QString m_button1Text {tr("Dismiss")};
306 QString m_button2Text;
308 Units::Timespan m_reactionTime;
309 QString m_spokenText;
310 QString m_title {u"Placeholder title"_s};
311 QString m_text;
313};
314
315} // namespace Notifications
void setButton1Text(const QString &newButton1Text)
Setter function for property of the same name.
QString button2Text() const
Getter function for property of the same name.
void button2TextChanged()
Notification signal.
Notification(QString _title, Notifications::Notification::Importance _importance=Notifications::Notification::Info, QObject *parent=nullptr)
Standard constructor.
void setButton2Text(const QString &newButton2Text)
Setter function for property of the same name.
TextBodyAction
Text body action.
@ OpenMapsAndDataPage
Open the page 'maps and data'.
@ OpenTrafficReceiverPage
Open the page 'traffic receiver'.
void setSpokenText(const QString &newSpokenText)
Setter function for property of the same name.
void setReactionTime(Units::Timespan newReactionTime)
Setter function for property of the same name.
Notifications::Notification::Importance importance
Importance of the notification.
void spokenTextChanged()
Notification signal.
Importance
Importance classification.
@ Warning_Navigation
Serious warning, "Prohibited Airspace 1 minutes ahead".
@ Info
Generic information, "Map updates available".
@ Info_Navigation
Information pertaining to navigation, "Top of descent reached".
@ Alert
Alert. Immediate action is required to avoid accident or serious rule infringion.
@ Warning
Generic warning, "Traffic data receiver inop".
QString text
Text body of the notification.
Units::Timespan reactionTime() const
Getter function for property of the same name.
QString title() const
Getter function for property of the same name.
QString spokenText() const
Getter function for property of the same name.
Notifications::Notification::Importance importance() const
Getter function for property of the same name.
QString text() const
Getter function for property of the same name.
virtual Q_INVOKABLE void onButton2Clicked()
Mouse click handler.
void reactionTimeChanged()
Notification signal.
void button1TextChanged()
Notification signal.
QString button2Text
Text for second button.
QString title
Title of the notification.
virtual Q_INVOKABLE void onButton1Clicked()
Mouse click handler.
Units::Timespan reactionTime
Time left to avert negative consequences.
void textBodyActionChanged()
Notification signal.
QString spokenText
Spoken text message for the notification.
Notifications::Notification::TextBodyAction textBodyAction
Text body action.
~Notification() override=default
Standard destructor.
QString button1Text
Text for first button.
Notifications::Notification::TextBodyAction textBodyAction() const
Getter function for property of the same name.
void setTextBodyAction(Notifications::Notification::TextBodyAction newTextBodyAction)
Setter function for property of the same name.
void textChanged()
Notification signal.
void setText(const QString &newText)
Setter function for property of the same name.
Convenience class for time computations.
Definition Timespan.h:35
Conversion between units used in aviation.
Definition Angle.h:34