CuteHMI - CuteHMI (CuteHMI.2)
Message.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_2_INCLUDE_CUTEHMI_MESSAGE_HPP
2#define H_EXTENSIONS_CUTEHMI_2_INCLUDE_CUTEHMI_MESSAGE_HPP
3
4#include "internal/platform.hpp"
5#include "MPtr.hpp"
6#include "ErrorInfo.hpp"
7
8#include <memory>
9
10#include <QObject>
11#include <QAtomicInteger>
12#include <QMutex>
13#include <QQmlEngine>
14
15namespace cutehmi {
16
20class CUTEHMI_API Message:
21 public QObject
22{
23 Q_OBJECT
24 QML_NAMED_ELEMENT(Message)
25
26 public:
27 Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
28 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
29 Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText NOTIFY informativeTextChanged)
30 Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText NOTIFY detailedTextChanged)
31 Q_PROPERTY(Buttons buttons READ buttons WRITE setButtons NOTIFY buttonsChanged)
32 Q_PROPERTY(Button response READ response NOTIFY responseChanged)
33
34 enum Type {
35 INFO = 1,
36 WARNING = 2,
37 CRITICAL = 3,
38 QUESTION = 4
39 };
40 Q_ENUM(Type)
41
42
47 enum Button : qint32 {
48 BUTTON_OK = 0x00000400,
49 BUTTON_OPEN = 0x00002000,
50 BUTTON_SAVE = 0x00000800,
51 BUTTON_CANCEL = 0x00400000,
52 BUTTON_CLOSE = 0x00200000,
53 BUTTON_DISCARD = 0x00800000,
54 BUTTON_APPLY = 0x02000000,
55 BUTTON_RESET = 0x04000000,
56 BUTTON_RESTORE_DEFAULTS = 0x08000000,
57 BUTTON_HELP = 0x01000000,
58 BUTTON_SAVE_ALL = 0x00001000,
59 BUTTON_YES = 0x00004000,
60 BUTTON_YES_TO_ALL = 0x00008000,
61 BUTTON_NO = 0x00010000,
62 BUTTON_NO_TO_ALL = 0x00020000,
63 BUTTON_ABORT = 0x00040000,
64 BUTTON_RETRY = 0x00080000,
65 BUTTON_IGNORE = 0x00100000,
66 NO_BUTTON = 0x00000000
67 };
68 Q_DECLARE_FLAGS(Buttons, Button)
69 Q_FLAG(Buttons)
70 Q_ENUM(Button)
71
72
78 static std::unique_ptr<Message> Info(const QString & text, Message::Buttons buttons = Message::BUTTON_OK);
79
86 static std::unique_ptr<Message> Warning(const QString & text, Message::Buttons buttons = Message::BUTTON_OK);
87
94 static std::unique_ptr<Message> Question(const QString & text, Message::Buttons buttons = Message::Buttons{Message::BUTTON_YES, Message::BUTTON_NO});
95
102 static std::unique_ptr<Message> Critical(const QString & text, Message::Buttons buttons = Message::BUTTON_OK);
103
111 static std::unique_ptr<Message> Critical(const ErrorInfo & errorInfo, Message::Buttons buttons = Message::BUTTON_OK);
112
120 explicit Message(Type type = INFO, const QString & text = QString(), Buttons buttons = Message::NO_BUTTON, QObject * parent = nullptr);
121
130 Message(Type type, const QString & text, const QString & informativeText, Buttons buttons = Message::NO_BUTTON, QObject * parent = nullptr);
131
141 Message(Type type, const QString & text, const QString & informativeText, const QString & detailedText, Buttons buttons = Message::NO_BUTTON, QObject * parent = nullptr);
142
146 ~Message() override = default;
147
152 Type type() const;
153
158 void setType(Type type);
159
164 QString text() const;
165
170 void setText(const QString & text);
171
176 QString informativeText() const;
177
182 void setInformativeText(const QString & informativeText);
183
188 QString detailedText() const;
189
194 void setDetailedText(const QString & detailedText);
195
200 Buttons buttons() const;
201
206 void setButtons(Buttons buttons);
207
212 Button response() const;
213
218 std::unique_ptr<Message> clone() const;
219
229 Button exec();
230
231 public slots:
237 void acceptResponse(cutehmi::Message::Button response);
238
239 signals:
241
243
245
247
249
251
253
254 private:
255 struct Members
256 {
257 Type type;
258 QString text;
259 QString informativeText;
260 QString detailedText;
261 Buttons buttons;
262 Button response;
263 };
264
266};
267
268}
269
270Q_DECLARE_OPERATORS_FOR_FLAGS(cutehmi::Message::Buttons)
271Q_DECLARE_METATYPE(cutehmi::Message::Button) // Must use this macro despite using Q_ENUM to register metatype inside Init.
272
273#endif
274
275//(c)C: Copyright © 2019-2022, Michał Policht <michal@policht.pl>. All rights reserved.
276//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
277//(c)C: This file is a part of CuteHMI.
278//(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
279//(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
280//(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
281//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
282//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
283//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
284//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Message.
Definition: Message.hpp:22
void responseChanged()
void detailedTextChanged()
void responseArrived(cutehmi::Message::Button response)
void informativeTextChanged()
Type
Definition: Message.hpp:34
Button
Dialog button.
Definition: Message.hpp:47
@ BUTTON_NO
Definition: Message.hpp:61
@ BUTTON_YES
Definition: Message.hpp:59
@ BUTTON_OK
Definition: Message.hpp:48
@ NO_BUTTON
Definition: Message.hpp:66
~Message() override=default
Destructor.
Definition: constants.hpp:6
ErrorInfo errorInfo(ERR err)
Get error info.
Definition: ErrorInfo.hpp:38