Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageWindow.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file MessageWindow.h
  3. * @brief Message Window.
  4. * @see MessageWindow
  5. * @author Micha? Policht
  6. */
  7. #ifndef MESSAGEWINDOW_H_
  8. #define MESSAGEWINDOW_H_
  9. #include <QDockWidget>
  10. #include <QTextEdit>
  11. #include <QEvent>
  12. /**
  13. * Message Window. Handling errors and other messages.
  14. */
  15. class MessageWindow: public QDockWidget
  16. {
  17. Q_OBJECT
  18. QTextEdit msgTextEdit; ///< Main widget.
  19. static MessageWindow *MsgHandler; ///< Set in constructor.
  20. static const char *WINDOW_TITLE; ///< Window title.
  21. private:
  22. static QString QtMsgToQString(QtMsgType type, const char *msg);
  23. protected:
  24. /**
  25. * Handle custom events. MessageWindow hadles custom events listed in
  26. * EventType enum.
  27. */
  28. virtual void customEvent(QEvent* event);
  29. public:
  30. enum EventType {MessageEventType = QEvent::User}; ///< Custom event types.
  31. /**
  32. * Default constructor.
  33. * @param parent parent widget.
  34. * @param flags widget flags.
  35. */
  36. MessageWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
  37. /**
  38. * Append message wrapper. Since ISO forbids casting member functions
  39. * to C functions, wrapper is needed to use this class as QtMsgHandler.
  40. * This method is thread-safe but not reentrant.
  41. * @param type message type.
  42. * @param msg message string.
  43. */
  44. static void AppendMsgWrapper(QtMsgType type, const char *msg);
  45. #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
  46. static void AppendMsgWrapper(QtMsgType type, const QMessageLogContext &context, const QString &msg);
  47. #endif
  48. /**
  49. * Post message event to the main event loop. This function encapsulates
  50. * message into MessageEvent object and passes it to the main event loop.
  51. * @param type message type.
  52. * @param msg message string.
  53. */
  54. void postMsgEvent(QtMsgType type, const char *msg);
  55. };
  56. /**
  57. * Message Event. Custom event used by @ref MessageWindow to provide multi-threaded
  58. * access. Encapsulates message inside @a msg variable.
  59. */
  60. class MessageEvent: public QEvent
  61. {
  62. public:
  63. QString msg; ///< Message string.
  64. /**
  65. * Contructor.
  66. * @param msg message to post.
  67. */
  68. MessageEvent(QString &msg);
  69. };
  70. #endif /*MESSAGEWINDOW_H_*/