SafeQApplication.hpp
1 #pragma once
2 #include <QApplication>
3 #include <QMessageBox>
4 
5 #include <cstdio>
6 #include <verdigris>
7 
8 #ifdef __APPLE__
9 #endif
10 
11 #include <score/widgets/MessageBox.hpp>
12 
13 #include <score_lib_base_export.h>
14 
21 class SCORE_LIB_BASE_EXPORT LogFile
22 {
23 public:
24  LogFile()
25  : fd{fopen("score.log", "a")}
26  {
27  }
28 
29  FILE* desc() const { return fd; }
30  ~LogFile() { fclose(fd); }
31 
32 private:
33  FILE* fd{};
34 };
35 
43 class SCORE_LIB_BASE_EXPORT SafeQApplication final : public QApplication
44 {
45  W_OBJECT(SafeQApplication)
46 public:
47  SafeQApplication(int& argc, char** argv)
48  : QApplication{argc, argv}
49  {
50 #if defined(SCORE_DEBUG)
51  qInstallMessageHandler(DebugOutput);
52 #endif
53  }
54 
56  static void
57  DebugOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg);
58 
59 #if !defined(SCORE_DEBUG)
60  void inform(const QString& str)
61  {
62  score::information(QApplication::activeWindow(), "", str);
63  }
64 
65  bool notify(QObject* receiver, QEvent* event) override;
66 #endif
67 
68  bool event(QEvent* ev) override;
69 
70  void fileOpened(const QString& opened)
71  E_SIGNAL(SCORE_LIB_BASE_EXPORT, fileOpened, opened)
72 
73 #if defined(__APPLE__)
74  QString fileToOpen;
75 #endif
76 };
C++ abstraction over fopen/fclose.
Definition: SafeQApplication.hpp:22
Wrapper over QApplication.
Definition: SafeQApplication.hpp:44