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 
14 namespace cutehmi {
15 
19 class CUTEHMI_API Message:
20  public QObject
21 {
22  Q_OBJECT
23 
24  public:
25  Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
26  Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
27  Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText NOTIFY informativeTextChanged)
28  Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText NOTIFY detailedTextChanged)
29  Q_PROPERTY(Buttons buttons READ buttons WRITE setButtons NOTIFY buttonsChanged)
30  Q_PROPERTY(Button response READ response NOTIFY responseChanged)
31 
32  enum Type {
33  INFO = 1,
34  WARNING = 2,
35  CRITICAL = 3,
36  QUESTION = 4
37  };
38  Q_ENUM(Type)
39 
40 
45  enum Button : qint32 {
46  BUTTON_OK = 0x00000400,
47  BUTTON_OPEN = 0x00002000,
48  BUTTON_SAVE = 0x00000800,
49  BUTTON_CANCEL = 0x00400000,
50  BUTTON_CLOSE = 0x00200000,
51  BUTTON_DISCARD = 0x00800000,
52  BUTTON_APPLY = 0x02000000,
53  BUTTON_RESET = 0x04000000,
54  BUTTON_RESTORE_DEFAULTS = 0x08000000,
55  BUTTON_HELP = 0x01000000,
56  BUTTON_SAVE_ALL = 0x00001000,
57  BUTTON_YES = 0x00004000,
58  BUTTON_YES_TO_ALL = 0x00008000,
59  BUTTON_NO = 0x00010000,
60  BUTTON_NO_TO_ALL = 0x00020000,
61  BUTTON_ABORT = 0x00040000,
62  BUTTON_RETRY = 0x00080000,
63  BUTTON_IGNORE = 0x00100000,
64  NO_BUTTON = 0x00000000
65  };
66  Q_DECLARE_FLAGS(Buttons, Button)
67  Q_FLAG(Buttons)
68  Q_ENUM(Button)
69 
70 
76  static std::unique_ptr<Message> Info(const QString & text, Message::Buttons buttons = Message::BUTTON_OK);
77 
84  static std::unique_ptr<Message> Warning(const QString & text, Message::Buttons buttons = Message::BUTTON_OK);
85 
92  static std::unique_ptr<Message> Question(const QString & text, Message::Buttons buttons = Message::Buttons{Message::BUTTON_YES, Message::BUTTON_NO});
93 
100  static std::unique_ptr<Message> Critical(const QString & text, Message::Buttons buttons = Message::BUTTON_OK);
101 
109  static std::unique_ptr<Message> Critical(const ErrorInfo & errorInfo, Message::Buttons buttons = Message::BUTTON_OK);
110 
118  explicit Message(Type type = INFO, const QString & text = QString(), Buttons buttons = Message::NO_BUTTON, QObject * parent = nullptr);
119 
128  Message(Type type, const QString & text, const QString & informativeText, Buttons buttons = Message::NO_BUTTON, QObject * parent = nullptr);
129 
139  Message(Type type, const QString & text, const QString & informativeText, const QString & detailedText, Buttons buttons = Message::NO_BUTTON, QObject * parent = nullptr);
140 
144  ~Message() override = default;
145 
150  Type type() const;
151 
156  void setType(Type type);
157 
162  QString text() const;
163 
168  void setText(const QString & text);
169 
174  QString informativeText() const;
175 
180  void setInformativeText(const QString & informativeText);
181 
186  QString detailedText() const;
187 
192  void setDetailedText(const QString & detailedText);
193 
198  Buttons buttons() const;
199 
204  void setButtons(Buttons buttons);
205 
210  Button response() const;
211 
216  std::unique_ptr<Message> clone() const;
217 
227  Button exec();
228 
229  public slots:
235  void acceptResponse(Button response);
236 
237  signals:
238  void typeChanged();
239 
240  void textChanged();
241 
242  void informativeTextChanged();
243 
244  void detailedTextChanged();
245 
246  void buttonsChanged();
247 
248  void responseChanged();
249 
250  void responseArrived(cutehmi::Message::Button response);
251 
252  private:
253  struct Members
254  {
255  Type type;
256  QString text;
257  QString informativeText;
258  QString detailedText;
259  Buttons buttons;
260  Button response;
261  };
262 
263  MPtr<Members> m;
264 };
265 
266 }
267 
268 Q_DECLARE_OPERATORS_FOR_FLAGS(cutehmi::Message::Buttons)
269 Q_DECLARE_METATYPE(cutehmi::Message::Button) // Must use this macro despite using Q_ENUM to register metatype inside Init.
270 
271 #endif
272 
273 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
274 //(c)C: This file is a part of CuteHMI.
275 //(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.
276 //(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.
277 //(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/>.
cutehmi::errorInfo
ErrorInfo errorInfo(ERR err)
Get error info.
Definition: ErrorInfo.hpp:38
cutehmi::Message
Message.
Definition: Message.hpp:19
QObject
cutehmi::Message::Type
Type
Definition: Message.hpp:32
cutehmi
Definition: constants.hpp:6
QString
cutehmi::Message::Button
Button
Dialog button.
Definition: Message.hpp:45
cutehmi::Message::BUTTON_NO
@ BUTTON_NO
Definition: Message.hpp:59
cutehmi::Message::BUTTON_YES
@ BUTTON_YES
Definition: Message.hpp:57
cutehmi::Message::BUTTON_OK
@ BUTTON_OK
Definition: Message.hpp:46
std::unique_ptr
cutehmi::Message::NO_BUTTON
@ NO_BUTTON
Definition: Message.hpp:64