QElectroTech  0.70
qetapp.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef QET_APP_H
19 #define QET_APP_H
20 
21 #include <QTranslator>
22 #include <QSystemTrayIcon>
23 #include <QPalette>
24 #include <QByteArray>
25 
26 #include "elementslocation.h"
27 #include "templatelocation.h"
28 #include "qetarguments.h"
29 
30 class QSplashScreen;
31 class QMenu;
32 class QAction;
33 class QMainWindow;
34 
35 #define QETAPP_COMMON_TBT_PROTOCOL "commontbt"
36 #define QETAPP_CUSTOM_TBT_PROTOCOL "customtbt"
37 
38 class AboutQET;
39 class QETDiagramEditor;
40 class QETElementEditor;
42 class TitleBlockTemplate;
45 class QETProject;
48 class RecentFiles;
49 
53 class QETApp : public QObject
54 {
55  Q_OBJECT
56  // constructors, destructor
57  public:
58  QETApp();
59  ~QETApp() override;
60 
61  private:
62  QETApp(const QETApp &);
63 
64  // methods
65  public:
66  static QETApp *instance();
67  void setLanguage(const QString &);
68  static QString langFromSetting ();
69  void switchLayout(Qt::LayoutDirection);
70  static void printHelp();
71  static void printVersion();
72  static void printLicense();
73 
75  static QStringList elementInfoKeys();
76  static QString elementTranslatedInfoKey(const QString &);
77  static QString elementInfoToVar(const QString &info);
78 
79  static QStringList conductorInfoKeys();
80  static QString conductorTranslatedInfoKey(const QString &key);
81 
82  static QStringList diagramInfoKeys();
83  static QString diagramTranslatedInfoKey(const QString &key);
84 
87  static QList<TitleBlockTemplatesCollection *> availableTitleBlockTemplatesCollections();
89 
90  static QString commonElementsDir();
91  static QString customElementsDir();
92  static QString commonElementsDirN();
93  static QString customElementsDirN();
94  static void resetUserElementsDir();
95  static QString commonTitleBlockTemplatesDir();
96  static QString customTitleBlockTemplatesDir();
97  static bool registerProject(QETProject *);
98  static bool unregisterProject(QETProject *);
99  static QMap<uint, QETProject *> registeredProjects();
100  static QETProject *project(const uint &);
101  static int projectId(const QETProject *);
102  static QString configDir();
103  static QString languagesPath();
104  static QString realPath(const QString &);
105  static QString symbolicPath(const QString &);
106  static QStringList handledFileExtensions();
107  static QStringList handledFiles(const QList<QUrl> &);
110 
111 #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
112  public:
113  static void overrideCommonElementsDir(const QString &);
114  private:
115  static QString common_elements_dir;
116 #endif
117 
118 #ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
119  public:
120  static void overrideCommonTitleBlockTemplatesDir(const QString &);
121  private:
122  static QString common_tbt_dir_;
123 #endif
124 
125 #ifdef QET_ALLOW_OVERRIDE_CD_OPTION
126  public:
127  static void overrideConfigDir(const QString &);
128  private:
129  static QString config_dir;
130 #endif
131 
132  public:
133  static void overrideLangDir(const QString &);
134  static QString lang_dir;
135  static QFont diagramTextsFont(qreal = -1.0);
136  static QFont diagramTextsItemFont(qreal = -1.0);
137  static QFont dynamicTextsItemFont(qreal = -1.0);
138  static QFont foliolistTextsFont(qreal = -1.0);
139  static QFont indiTextsItemFont (qreal = -1.0);
140  static QETDiagramEditor *diagramEditorForFile(const QString &);
141  static QETDiagramEditor *diagramEditorAncestorOf (const QWidget *child);
142  static QList<QETDiagramEditor *> diagramEditors();
143  static QList<QETElementEditor *> elementEditors();
144  static QList<QETElementEditor *> elementEditors(QETProject *);
145  static QList<QETTitleBlockTemplateEditor *> titleBlockTemplateEditors();
146  static QList<QETTitleBlockTemplateEditor *> titleBlockTemplateEditors(QETProject *);
149 
150  protected:
151 
152 #ifdef Q_OS_DARWIN
153  bool eventFiltrer(QObject *object, QEvent *);
154 #endif
155 
156  // attributes
157  private:
158  static QETApp *m_qetapp;
159  QTranslator qtTranslator;
160  QTranslator qetTranslator;
161  QSystemTrayIcon *m_qsti;
162  QSplashScreen *m_splash_screen;
163  QMenu *menu_systray;
164  QAction *quitter_qet;
165  QAction *reduce_appli;
166  QAction *restore_appli;
167  QAction *reduce_diagrams;
169  QAction *reduce_elements;
173  QAction *new_diagram;
174  QAction *new_element;
175  QHash<QMainWindow *, QByteArray> window_geometries;
176  QHash<QMainWindow *, QByteArray> window_states;
184  QSignalMapper signal_map;
187  QPalette initial_palette_;
188 
192  static QMap<uint, QETProject *> registered_projects_;
193  static uint next_project_id;
199  static QString m_user_custom_tbt_dir;
200 
201  public slots:
202  void systray(QSystemTrayIcon::ActivationReason);
203  void reduceEveryEditor();
204  void restoreEveryEditor();
205  void reduceDiagramEditors();
206  void restoreDiagramEditors();
207  void reduceElementEditors();
208  void restoreElementEditors();
211  void newDiagramEditor();
212  void newElementEditor();
213  bool closeEveryEditor();
214  void setMainWindowVisible(QMainWindow *, bool);
215  void invertMainWindowVisibility(QWidget *);
216  void useSystemPalette(bool);
217  void quitQET();
218  void checkRemainingWindows();
219  void openFiles(const QETArguments &);
220  void openProjectFiles(const QStringList &);
221  void openElementFiles(const QStringList &);
222  void openElementLocations(const QList<ElementsLocation> &);
223  void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false);
224  void openTitleBlockTemplate(const QString &);
225  void openTitleBlockTemplateFiles(const QStringList &);
226  void configureQET();
227  void aboutQET();
228  void receiveMessage(int instanceId, QByteArray message);
229 
230  private:
231  template <class T> QList<T *> detectWindows() const;
232  template <class T> void setMainWindowsVisible(bool);
233  QList<QWidget *> floatingToolbarsAndDocksForMainWindow(QMainWindow *) const;
234  void parseArguments();
235  void initSplashScreen();
236  void setSplashScreenStep(const QString & = QString());
237  void initLanguage();
238  void initStyle();
239  void initConfiguration();
240  void initSystemTray();
241  void buildSystemTrayMenu();
242  void checkBackupFiles();
243  void fetchWindowStats(
244  const QList<QETDiagramEditor *> &,
245  const QList<QETElementEditor *> &,
246  const QList<QETTitleBlockTemplateEditor *> &
247  );
248  template <class T> void addWindowsListToMenu(QMenu *, const QList<T *> &);
249  static int projectIdFromString(const QString &);
250  static QETProject *projectFromString(const QString &);
251 };
252 
253 #endif
void configureQET()
Definition: qetapp.cpp:1472
static TitleBlockTemplatesFilesCollection * commonTitleBlockTemplatesCollection()
Definition: qetapp.cpp:448
static QTextOrientationSpinBoxWidget * createTextOrientationSpinBoxWidget()
Definition: qetapp.cpp:1072
static QString symbolicPath(const QString &)
Definition: qetapp.cpp:725
void fetchWindowStats(const QList< QETDiagramEditor *> &, const QList< QETElementEditor *> &, const QList< QETTitleBlockTemplateEditor *> &)
Met a jour les booleens concernant l&#39;etat des fenetres.
Definition: qetapp.cpp:1860
void reduceEveryEditor()
Reduit toutes les fenetres de l&#39;application dans le systray.
Definition: qetapp.cpp:223
static QString customTitleBlockTemplatesDir()
Definition: qetapp.cpp:643
static QString commonTitleBlockTemplatesDir()
Definition: qetapp.cpp:621
static bool unregisterProject(QETProject *)
Definition: qetapp.cpp:1976
static QStringList handledFiles(const QList< QUrl > &)
Definition: qetapp.cpp:757
QPalette initial_palette_
System color palette.
Definition: qetapp.h:187
void invertMainWindowVisibility(QWidget *)
Definition: qetapp.cpp:1206
static TitleBlockTemplate * defaultTitleBlockTemplate()
Definition: qetapp.cpp:1088
void initSplashScreen()
Definition: qetapp.cpp:1585
void openElementFiles(const QStringList &)
Definition: qetapp.cpp:1336
static void printHelp()
Definition: qetapp.cpp:1910
QETArguments qet_arguments_
Comand-line arguments parser.
Definition: qetapp.h:185
void reduceDiagramEditors()
Reduit tous les editeurs de schemas dans le systray.
Definition: qetapp.cpp:239
static RecentFiles * m_elements_recent_files
Definition: qetapp.h:195
void restoreElementEditors()
Restaure tous les editeurs d&#39;element dans le systray.
Definition: qetapp.cpp:254
void newElementEditor()
lance un nouvel editeur d&#39;element
Definition: qetapp.cpp:274
static QMap< uint, QETProject * > registeredProjects()
Definition: qetapp.cpp:1949
static QString customElementsDir()
QETApp::customElementsDir.
Definition: qetapp.cpp:555
static QStringList handledFileExtensions()
Definition: qetapp.cpp:743
QAction * restore_appli
Definition: qetapp.h:166
void addWindowsListToMenu(QMenu *, const QList< T *> &)
Definition: qetapp.cpp:1702
void initLanguage()
Definition: qetapp.cpp:1608
bool every_diagram_visible
Definition: qetapp.h:179
void aboutQET()
QETApp::aboutQET Open the dialog about qet.
Definition: qetapp.cpp:1500
QAction * new_element
Definition: qetapp.h:174
QSignalMapper signal_map
Definition: qetapp.h:184
void systray(QSystemTrayIcon::ActivationReason)
Definition: qetapp.cpp:202
static int projectIdFromString(const QString &)
Definition: qetapp.cpp:1719
void setMainWindowVisible(QMainWindow *, bool)
Definition: qetapp.cpp:1182
static QFont foliolistTextsFont(qreal=-1.0)
QETApp::foliolistTextsFont the font for to use in summary pages.
Definition: qetapp.cpp:982
bool non_interactive_execution_
Whether the application will end without any user interaction.
Definition: qetapp.h:186
QHash< QMainWindow *, QByteArray > window_geometries
Definition: qetapp.h:175
void openFiles(const QETArguments &)
Definition: qetapp.cpp:1285
void initStyle()
QETApp::initStyle Setup the gui style.
Definition: qetapp.cpp:1616
QAction * reduce_templates
Definition: qetapp.h:171
void reduceElementEditors()
Reduit tous les editeurs d&#39;element dans le systray.
Definition: qetapp.cpp:249
void buildSystemTrayMenu()
construit le menu de l&#39;icone dans le systray
Definition: qetapp.cpp:1744
QAction * new_diagram
Definition: qetapp.h:173
QAction * restore_elements
Definition: qetapp.h:170
static ElementsCollectionCache * collectionCache()
Definition: qetapp.cpp:281
void parseArguments()
Definition: qetapp.cpp:1537
~QETApp() override
QETApp::~QETApp.
Definition: qetapp.cpp:121
void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool=false)
Definition: qetapp.cpp:1412
QAction * reduce_elements
Definition: qetapp.h:169
static bool registerProject(QETProject *)
Definition: qetapp.cpp:1958
void setSplashScreenStep(const QString &=QString())
Definition: qetapp.cpp:1597
static int projectId(const QETProject *)
Definition: qetapp.cpp:2002
static QETProject * project(const uint &)
Definition: qetapp.cpp:1990
static QString langFromSetting()
QETApp::langFromSetting.
Definition: qetapp.cpp:184
void receiveMessage(int instanceId, QByteArray message)
Definition: qetapp.cpp:1124
static QString languagesPath()
Definition: qetapp.cpp:864
void initSystemTray()
Definition: qetapp.cpp:1653
void quitQET()
Definition: qetapp.cpp:1254
QAction * reduce_diagrams
Definition: qetapp.h:167
static QStringList conductorInfoKeys()
QETApp::conductorInfoKeys.
Definition: qetapp.cpp:382
static QString m_user_common_elements_dir
Definition: qetapp.h:197
static QString diagramTranslatedInfoKey(const QString &key)
QETApp::diagramTranslatedInfoKey.
Definition: qetapp.cpp:432
QAction * restore_diagrams
Definition: qetapp.h:168
static QETProject * projectFromString(const QString &)
Definition: qetapp.cpp:1737
static TitleBlockTemplatesFilesCollection * customTitleBlockTemplatesCollection()
Definition: qetapp.cpp:462
bool every_editor_reduced
Definition: qetapp.h:177
static QETApp * m_qetapp
Definition: qetapp.h:158
QList< QWidget * > floatingToolbarsAndDocksForMainWindow(QMainWindow *) const
Definition: qetapp.cpp:1514
bool every_element_reduced
Definition: qetapp.h:180
bool every_template_visible
Definition: qetapp.h:183
bool every_diagram_reduced
Definition: qetapp.h:178
QAction * reduce_appli
Definition: qetapp.h:165
static QFont indiTextsItemFont(qreal=-1.0)
QETApp::indiTextsItemFont The default font to use for independent text item.
Definition: qetapp.cpp:1007
bool closeEveryEditor()
Definition: qetapp.cpp:887
static void overrideLangDir(const QString &)
Definition: qetapp.cpp:853
void checkBackupFiles()
QETApp::checkBackupFiles Check for backup files. If backup was found, open a dialog and ask user what...
Definition: qetapp.cpp:1793
QMenu * menu_systray
Definition: qetapp.h:163
static RecentFiles * projectsRecentFiles()
Definition: qetapp.cpp:1166
static QList< QETTitleBlockTemplateEditor * > titleBlockTemplateEditors()
Definition: qetapp.cpp:1039
static RecentFiles * m_projects_recent_files
Definition: qetapp.h:194
static QList< QETElementEditor * > elementEditors()
Definition: qetapp.cpp:1032
static QString m_user_custom_elements_dir
Definition: qetapp.h:198
static QMap< uint, QETProject * > registered_projects_
Definition: qetapp.h:192
static QString elementInfoToVar(const QString &info)
QETApp::elementInfoToVar.
Definition: qetapp.cpp:355
QSplashScreen * m_splash_screen
Definition: qetapp.h:162
Definition: qetapp.h:53
static QStringList elementInfoKeys()
QETApp::elementInfoKeys.
Definition: qetapp.cpp:289
static QFont dynamicTextsItemFont(qreal=-1.0)
QETApp::dynamicTextsFont the defaukt font of dynamic element text item.
Definition: qetapp.cpp:962
static void printVersion()
Definition: qetapp.cpp:1935
bool every_template_reduced
Definition: qetapp.h:182
static ElementsCollectionCache * collections_cache_
Definition: qetapp.h:191
QAction * restore_templates
Definition: qetapp.h:172
void switchLayout(Qt::LayoutDirection)
Definition: qetapp.cpp:194
void restoreEveryEditor()
Restaure toutes les fenetres de l&#39;application dans le systray.
Definition: qetapp.cpp:231
QHash< QMainWindow *, QByteArray > window_states
Definition: qetapp.h:176
QAction * quitter_qet
Definition: qetapp.h:164
static TitleBlockTemplatesFilesCollection * m_custom_tbt_collection
Definition: qetapp.h:190
void setLanguage(const QString &)
Definition: qetapp.cpp:152
QTranslator qetTranslator
Definition: qetapp.h:160
static QString conductorTranslatedInfoKey(const QString &key)
QETApp::conductorTranslatedInfoKey.
Definition: qetapp.cpp:399
static QFont diagramTextsItemFont(qreal=-1.0)
QETApp::diagramTextsItemFont the font for to use in independent text item.
Definition: qetapp.cpp:934
void openProjectFiles(const QStringList &)
Definition: qetapp.cpp:1299
void useSystemPalette(bool)
Definition: qetapp.cpp:1232
void setMainWindowsVisible(bool)
Definition: qetapp.cpp:1157
static TitleBlockTemplate * default_titleblock_template_
Definition: qetapp.h:196
void openTitleBlockTemplateFiles(const QStringList &)
Definition: qetapp.cpp:1434
static TitleBlockTemplatesCollection * titleBlockTemplatesCollection(const QString &)
Definition: qetapp.cpp:493
void newDiagramEditor()
lance un nouvel editeur de schemas
Definition: qetapp.cpp:269
bool every_element_visible
Definition: qetapp.h:181
static QFont diagramTextsFont(qreal=-1.0)
QETApp::diagramTextsFont The font to use By default the font is "sans Serif" and size 9...
Definition: qetapp.cpp:910
void reduceTitleBlockTemplateEditors()
Reduce all known template editors.
Definition: qetapp.cpp:259
static QETDiagramEditor * diagramEditorAncestorOf(const QWidget *child)
QETApp::diagramEditorAncestorOf.
Definition: qetapp.cpp:796
static QString customElementsDirN()
QETApp::customElementsDirN like QString QETApp::customElementsDir but without "/" at the end...
Definition: qetapp.cpp:598
void initConfiguration()
Definition: qetapp.cpp:1631
static QList< TitleBlockTemplatesCollection * > availableTitleBlockTemplatesCollections()
Definition: qetapp.cpp:476
static QString elementTranslatedInfoKey(const QString &)
ElementsProperties::translatedInfo Return the translated information key given by If don&#39;t match...
Definition: qetapp.cpp:321
void restoreTitleBlockTemplateEditors()
Restore all known template editors.
Definition: qetapp.cpp:264
static QList< QETDiagramEditor * > diagramEditors()
Definition: qetapp.cpp:1025
static QString commonElementsDir()
QETApp::commonElementsDir.
Definition: qetapp.cpp:511
QSystemTrayIcon * m_qsti
Definition: qetapp.h:161
void openElementLocations(const QList< ElementsLocation > &)
Definition: qetapp.cpp:1377
static TitleBlockTemplatesFilesCollection * m_common_tbt_collection
Definition: qetapp.h:189
QETApp()
QETApp::QETApp.
Definition: qetapp.cpp:73
static QString lang_dir
Directory containing localization files.
Definition: qetapp.h:134
void checkRemainingWindows()
Definition: qetapp.cpp:1264
static QString commonElementsDirN()
QETApp::commonElementsDirN like QString QETApp::commonElementsDir but without "/" at the end...
Definition: qetapp.cpp:586
static RecentFiles * elementsRecentFiles()
Definition: qetapp.cpp:1173
static QString m_user_custom_tbt_dir
Definition: qetapp.h:199
static void resetUserElementsDir()
QETApp::resetUserElementsDir Reset the path of the user common and custom elements dir...
Definition: qetapp.cpp:610
static uint next_project_id
Definition: qetapp.h:193
static QETApp * instance()
Definition: qetapp.cpp:143
static void printLicense()
Definition: qetapp.cpp:1942
QList< T * > detectWindows() const
Definition: qetapp.cpp:1142
QTranslator qtTranslator
Definition: qetapp.h:159
static QETDiagramEditor * diagramEditorForFile(const QString &)
Definition: qetapp.cpp:777
void restoreDiagramEditors()
Restaure tous les editeurs de schemas dans le systray.
Definition: qetapp.cpp:244
static QString realPath(const QString &)
Definition: qetapp.cpp:704
static QString configDir()
Definition: qetapp.cpp:676
static QStringList diagramInfoKeys()
QETApp::diagramInfoKeys.
Definition: qetapp.cpp:412