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 QString& getLinkingType() const noexcept { return mLinkingType; }
77  const QString& getUnbundledLibs() const noexcept { return mUnbundledLibs; }
78  const Version& getFileFormatVersion() const noexcept {
79  return mFileFormatVersion;
80  }
81  bool isFileFormatStable() const noexcept { return mIsFileFormatStable; }
82  const FilePath& getResourcesDir() const noexcept { return mResourcesDir; }
83  FilePath getResourcesFilePath(const QString& filepath) const noexcept;
84  QStringList getAvailableTranslationLocales() const noexcept;
85  const QFont& getDefaultSansSerifFont() const noexcept {
86  return mSansSerifFont;
87  }
88  const QFont& getDefaultMonospaceFont() const noexcept {
89  return mMonospaceFont;
90  }
91  const StrokeFontPool& getStrokeFonts() const noexcept {
92  return *mStrokeFontPool;
93  }
94  QString getDefaultStrokeFontName() const noexcept { return "newstroke.bene"; }
95  const StrokeFont& getDefaultStrokeFont() const noexcept;
96 
97  // Setters
98  void setTranslationLocale(const QLocale& locale) noexcept;
99 
100  // Reimplemented from QApplication
101  bool notify(QObject* receiver, QEvent* e);
102 
103  // Operator Overloadings
104  Application& operator=(const Application& rhs) = delete;
105 
106  // Static Methods
107  static Application* instance() noexcept;
108 
109 public slots:
110  static void about() noexcept;
111 
112 private: // Methods
113  void removeAllTranslators() noexcept;
114 
115 private: // Data
118  QString mGitRevision;
119  QDateTime mBuildDate;
120  QString mLinkingType;
121  QString mUnbundledLibs;
125 
127  QScopedPointer<StrokeFontPool> mStrokeFontPool;
128 
131 
134 
136  QList<std::shared_ptr<QTranslator>> mTranslators;
137 };
138 
139 /*******************************************************************************
140  * End of File
141  ******************************************************************************/
142 
143 } // namespace librepcb
144 
145 #endif // LIBREPCB_APPLICATION_H
FilePath mResourcesDir
Definition: application.h:124
static Application * instance() noexcept
Definition: application.cpp:261
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:136
const StrokeFontPool & getStrokeFonts() const noexcept
Definition: application.h:91
QFont mMonospaceFont
Default monospace font.
Definition: application.h:133
const QFont & getDefaultSansSerifFont() const noexcept
Definition: application.h:85
const QString & getUnbundledLibs() const noexcept
Definition: application.h:77
QDateTime mBuildDate
Definition: application.h:119
const Version & getFileFormatVersion() const noexcept
Definition: application.h:78
Definition: airwiresbuilder.cpp:32
QString getDefaultStrokeFontName() const noexcept
Definition: application.h:94
FilePath getResourcesFilePath(const QString &filepath) const noexcept
Definition: application.cpp:181
const QFont & getDefaultMonospaceFont() const noexcept
Definition: application.h:88
QString mGitRevision
Definition: application.h:118
QString mUnbundledLibs
Definition: application.h:121
Version mFileFormatVersion
Definition: application.h:122
QFont mSansSerifFont
Default sans serif font.
Definition: application.h:130
bool isFileFormatStable() const noexcept
Definition: application.h:81
bool notify(QObject *receiver, QEvent *e)
Definition: application.cpp:248
Application & operator=(const Application &rhs)=delete
QStringList getAvailableTranslationLocales() const noexcept
Definition: application.cpp:186
const QDateTime & getBuildDate() const noexcept
Definition: application.h:75
static void about() noexcept
Definition: application.cpp:271
void setTranslationLocale(const QLocale &locale) noexcept
Definition: application.cpp:210
QString mAppVersionLabel
Definition: application.h:117
const StrokeFont & getDefaultStrokeFont() const noexcept
Definition: application.cpp:197
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const QString & getGitRevision() const noexcept
Definition: application.h:74
const QString & getLinkingType() const noexcept
Definition: application.h:76
QString mLinkingType
Definition: application.h:120
void removeAllTranslators() noexcept
Definition: application.cpp:281
~Application() noexcept
Definition: application.cpp:171
Version mAppVersion
Definition: application.h:116
const FilePath & getResourcesDir() const noexcept
Definition: application.h:82
QScopedPointer< StrokeFontPool > mStrokeFontPool
Pool containing all application stroke fonts.
Definition: application.h:127
The StrokeFontPool class.
Definition: strokefontpool.h:46
The StrokeFont class.
Definition: strokefont.h:52
bool mIsFileFormatStable
Definition: application.h:123
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