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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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::WFlags 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. /**
  46. * Post message event to the main event loop. This function encapsulates
  47. * message into MessageEvent object and passes it to the main event loop.
  48. * @param type message type.
  49. * @param msg message string.
  50. */
  51. void postMsgEvent(QtMsgType type, const char *msg);
  52. };
  53. /**
  54. * Message Event. Custom event used by @ref MessageWindow to provide multi-threaded
  55. * access. Encapsulates message inside @a msg variable.
  56. */
  57. class MessageEvent: public QEvent
  58. {
  59. public:
  60. QString msg; ///< Message string.
  61. /**
  62. * Contructor.
  63. * @param msg message to post.
  64. */
  65. MessageEvent(QString & msg);
  66. };
  67. #endif /*MESSAGEWINDOW_H_*/