LibrePCB Developers Documentation
application.h
Go to the documentation of this file.
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 
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
70  const Version& getAppVersion() const noexcept { return mAppVersion; }
71  const QString& getAppVersionLabel() const noexcept {
72  return mAppVersionLabel;
73  }
74  const QString& getGitRevision() const noexcept { return mGitRevision; }
75  const QDateTime& getBuildDate() const noexcept { return mBuildDate; }
76  const Version& getFileFormatVersion() const noexcept {
77  return mFileFormatVersion;
78  }
79  bool isFileFormatStable() const noexcept { return mIsFileFormatStable; }
80  const FilePath& getResourcesDir() const noexcept { return mResourcesDir; }
81  FilePath getResourcesFilePath(const QString& filepath) const noexcept;
82  QStringList getAvailableTranslationLocales() const noexcept;
83  const QFont& getDefaultSansSerifFont() const noexcept {
84  return mSansSerifFont;
85  }
86  const QFont& getDefaultMonospaceFont() const noexcept {
87  return mMonospaceFont;
88  }
89  const StrokeFontPool& getStrokeFonts() const noexcept {
90  return *mStrokeFontPool;
91  }
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
116  QString mGitRevision;
117  QDateTime mBuildDate;
121 
123  QScopedPointer<StrokeFontPool> mStrokeFontPool;
124 
127 
130 
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
FilePath mResourcesDir
Definition: application.h:120
static Application * instance() noexcept
Definition: application.cpp:259
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
const QString & getAppVersionLabel() const noexcept
Definition: application.h:71
QList< std::shared_ptr< QTranslator > > mTranslators
All currently installed translators.
Definition: application.h:132
const StrokeFontPool & getStrokeFonts() const noexcept
Definition: application.h:89
QFont mMonospaceFont
Default monospace font.
Definition: application.h:129
const QFont & getDefaultSansSerifFont() const noexcept
Definition: application.h:83
QDateTime mBuildDate
Definition: application.h:117
const Version & getFileFormatVersion() const noexcept
Definition: application.h:76
Definition: alignment.cpp:30
QString getDefaultStrokeFontName() const noexcept
Definition: application.h:92
FilePath getResourcesFilePath(const QString &filepath) const noexcept
Definition: application.cpp:179
const QFont & getDefaultMonospaceFont() const noexcept
Definition: application.h:86
QString mGitRevision
Definition: application.h:116
Version mFileFormatVersion
Definition: application.h:118
QFont mSansSerifFont
Default sans serif font.
Definition: application.h:126
bool isFileFormatStable() const noexcept
Definition: application.h:79
bool notify(QObject *receiver, QEvent *e)
Definition: application.cpp:246
Application & operator=(const Application &rhs)=delete
QStringList getAvailableTranslationLocales() const noexcept
Definition: application.cpp:184
const QDateTime & getBuildDate() const noexcept
Definition: application.h:75
static void about() noexcept
Definition: application.cpp:269
void setTranslationLocale(const QLocale &locale) noexcept
Definition: application.cpp:208
QString mAppVersionLabel
Definition: application.h:115
const StrokeFont & getDefaultStrokeFont() const noexcept
Definition: application.cpp:195
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const QString & getGitRevision() const noexcept
Definition: application.h:74
void removeAllTranslators() noexcept
Definition: application.cpp:279
~Application() noexcept
Definition: application.cpp:169
Version mAppVersion
Definition: application.h:114
const FilePath & getResourcesDir() const noexcept
Definition: application.h:80
QScopedPointer< StrokeFontPool > mStrokeFontPool
Pool containing all application stroke fonts.
Definition: application.h:123
The StrokeFontPool class.
Definition: strokefontpool.h:46
The StrokeFont class.
Definition: strokefont.h:52
bool mIsFileFormatStable
Definition: application.h:119
const Version & getAppVersion() const noexcept
Definition: application.h:70
The Application class extends the QApplication with the exception-safe method notify() ...
Definition: application.h:59