1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_APPLICATION_H
21 #define LIBREPCB_APPLICATION_H
22 
23 /*******************************************************************************
24  *  Includes
25  ******************************************************************************/
26 #include "fileio/filepath.h"
27 #include "version.h"
28 
29 #include <QApplication>
30 #include <QFont>
31 #include <QtCore>
32 
33 #include <memory>
34 
35 /*******************************************************************************
36  *  Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 class StrokeFont;
41 class StrokeFontPool;
42 
43 /*******************************************************************************
44  *  Macros
45  ******************************************************************************/
46 #if defined(qApp)
47 #undef qApp
48 #endif
49 #define qApp (Application::instance())
50 
51 /*******************************************************************************
52  *  Class Application
53  ******************************************************************************/
54 
55 /**
56  * @brief The Application class extends the QApplication with the exception-safe
57  * method #notify()
58  */
59 class Application final : public QApplication {
60   Q_OBJECT
61 
62 public:
63   // Constructors / Destructor
64   Application() = delete;
65   Application(const Application& other) = delete;
66   Application(int& argc, char** argv) noexcept;
67   ~Application() noexcept;
68 
69   // Getters
getAppVersion()70   const Version& getAppVersion() const noexcept { return mAppVersion; }
getAppVersionLabel()71   const QString& getAppVersionLabel() const noexcept {
72     return mAppVersionLabel;
73   }
getGitRevision()74   const QString& getGitRevision() const noexcept { return mGitRevision; }
getBuildDate()75   const QDateTime& getBuildDate() const noexcept { return mBuildDate; }
getFileFormatVersion()76   const Version& getFileFormatVersion() const noexcept {
77     return mFileFormatVersion;
78   }
isFileFormatStable()79   bool isFileFormatStable() const noexcept { return mIsFileFormatStable; }
getResourcesDir()80   const FilePath& getResourcesDir() const noexcept { return mResourcesDir; }
81   FilePath getResourcesFilePath(const QString& filepath) const noexcept;
82   QStringList getAvailableTranslationLocales() const noexcept;
getDefaultSansSerifFont()83   const QFont& getDefaultSansSerifFont() const noexcept {
84     return mSansSerifFont;
85   }
getDefaultMonospaceFont()86   const QFont& getDefaultMonospaceFont() const noexcept {
87     return mMonospaceFont;
88   }
getStrokeFonts()89   const StrokeFontPool& getStrokeFonts() const noexcept {
90     return *mStrokeFontPool;
91   }
getDefaultStrokeFontName()92   QString getDefaultStrokeFontName() const noexcept { return "newstroke.bene"; }
93   const StrokeFont& getDefaultStrokeFont() const noexcept;
94 
95   // Setters
96   void setTranslationLocale(const QLocale& locale) noexcept;
97 
98   // Reimplemented from QApplication
99   bool notify(QObject* receiver, QEvent* e);
100 
101   // Operator Overloadings
102   Application& operator=(const Application& rhs) = delete;
103 
104   // Static Methods
105   static Application* instance() noexcept;
106 
107 public slots:
108   static void about() noexcept;
109 
110 private:  // Methods
111   void removeAllTranslators() noexcept;
112 
113 private:  // Data
114   Version mAppVersion;
115   QString mAppVersionLabel;
116   QString mGitRevision;
117   QDateTime mBuildDate;
118   Version mFileFormatVersion;
119   bool mIsFileFormatStable;
120   FilePath mResourcesDir;
121 
122   /// Pool containing all application stroke fonts
123   QScopedPointer<StrokeFontPool> mStrokeFontPool;
124 
125   /// Default sans serif font
126   QFont mSansSerifFont;
127 
128   /// Default monospace font
129   QFont mMonospaceFont;
130 
131   /// All currently installed translators
132   QList<std::shared_ptr<QTranslator>> mTranslators;
133 };
134 
135 /*******************************************************************************
136  *  End of File
137  ******************************************************************************/
138 
139 }  // namespace librepcb
140 
141 #endif  // LIBREPCB_APPLICATION_H
142