QElectroTech  0.70
qetmainwindow.cpp
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 #include <QAction>
19 #include <QWhatsThis>
20 #include <QMenu>
21 #include <QMenuBar>
22 #include <QDragEnterEvent>
23 #include <QDesktopServices>
24 
25 #include "qetmainwindow.h"
26 #include "qeticons.h"
27 #include "qetapp.h"
28 #include "qetdiagrameditor.h"
29 #include "projectview.h"
30 
34 QETMainWindow::QETMainWindow(QWidget *widget, Qt::WindowFlags flags) :
35  QMainWindow(widget, flags),
36  display_toolbars_(nullptr),
37  first_activation_(true)
38 {
41 
42  setAcceptDrops(true);
43 }
44 
49 }
50 
55  QETApp *qet_app = QETApp::instance();
56 
57  configure_action_ = new QAction(QET::Icons::Configure, tr("&Configurer QElectroTech"), this);
58  configure_action_ -> setStatusTip(tr("Permet de régler différents paramètres de QElectroTech", "status bar tip"));
59  connect(configure_action_, &QAction::triggered, [qet_app]()
60  {
61  qet_app->configureQET();
62  //TODO we use reloadOldElementPanel only to keep up to date the string of the folio in the old element panel.
63  //then, if user change the option "Use labels of folio instead of their ID" the string of folio in the old element panel is up to date
64  for (QETDiagramEditor *qde : qet_app->diagramEditors())
65  {
66  qde->reloadOldElementPanel();
67  for (ProjectView *pv : qde->openedProjects())
68  {
69  pv->updateAllTabsTitle();
70  }
71  }
72  });
73 
74  fullscreen_action_ = new QAction(this);
76  connect(fullscreen_action_, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
77 
78  whatsthis_action_ = QWhatsThis::createAction(this);
79 
80  about_qet_ = new QAction(QET::Icons::QETLogo, tr("À &propos de QElectroTech"), this);
81  about_qet_ -> setStatusTip(tr("Affiche des informations sur QElectroTech", "status bar tip"));
82  connect(about_qet_, SIGNAL(triggered()), qet_app, SLOT(aboutQET()));
83 
84  manual_online_ = new QAction(QET::Icons::QETManual, tr("Manuel en ligne"), this);
85  manual_online_ -> setStatusTip(tr("Lance le navigateur par défaut vers le manuel en ligne de QElectroTech", "status bar tip"));
86 
87  connect(manual_online_, &QAction::triggered, [](bool) {
88  QString link = "https://download.tuxfamily.org/qet/manual_0.7/build/index.html";
89  QDesktopServices::openUrl(QUrl(link));
90  });
91 
92  manual_online_ -> setShortcut(Qt::Key_F1);
93 
94  youtube_ = new QAction(QET::Icons::QETVideo, tr("Chaine Youtube"), this);
95  youtube_ -> setStatusTip(tr("Lance le navigateur par défaut vers la chaine Youtube de QElectroTech", "status bar tip"));
96 
97  connect(youtube_, &QAction::triggered, [](bool) {
98  QString link = "https://www.youtube.com/user/scorpio8101/videos";
99  QDesktopServices::openUrl(QUrl(link));
100  });
101 
102  upgrade_ = new QAction(QET::Icons::QETDownload, tr("Télécharger une nouvelle version (dev)"), this);
103  upgrade_ -> setStatusTip(tr("Lance le navigateur par défaut vers le dépot Nightly en ligne de QElectroTech", "status bar tip"));
104 
105  upgrade_M = new QAction(QET::Icons::QETDownload, tr("Télécharger une nouvelle version (dev)"), this);
106  upgrade_M -> setStatusTip(tr("Lance le navigateur par défaut vers le dépot Nightly en ligne de QElectroTech", "status bar tip"));
107 
108  connect(upgrade_, &QAction::triggered, [](bool) {
109  QString link = "https://qelectrotech.org/download_windows_QET.html";
110  QDesktopServices::openUrl(QUrl(link));
111  });
112 
113  connect(upgrade_M, &QAction::triggered, [](bool) {
114  QString link = "https://qelectrotech.org/download_mac_QET.html";
115  QDesktopServices::openUrl(QUrl(link));
116  });
117 
118  donate_ = new QAction(QET::Icons::QETDonate, tr("Soutenir le projet par un don"), this);
119  donate_ -> setStatusTip(tr("Soutenir le projet QElectroTech par un don", "status bar tip"));
120 
121  connect(donate_, &QAction::triggered, [](bool) {
122  QString link = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZZHC9D7C3MDPC";
123  QDesktopServices::openUrl(QUrl(link));
124  });
125 
126  about_qt_ = new QAction(QET::Icons::QtLogo, tr("À propos de &Qt"), this);
127  about_qt_ -> setStatusTip(tr("Affiche des informations sur la bibliothèque Qt", "status bar tip"));
128  connect(about_qt_, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
129 }
130 
135  settings_menu_ = new QMenu(tr("&Configuration", "window menu"));
136  settings_menu_ -> addAction(fullscreen_action_);
137  settings_menu_ -> addAction(configure_action_);
138  connect(settings_menu_, SIGNAL(aboutToShow()), this, SLOT(checkToolbarsmenu()));
139 
140 
141  help_menu_ = new QMenu(tr("&Aide", "window menu"));
142  help_menu_ -> addAction(whatsthis_action_);
143  help_menu_ -> addSeparator();
144  help_menu_ -> addAction(about_qet_);
145  help_menu_ -> addAction(manual_online_);
146  help_menu_ -> addAction(youtube_);
147  help_menu_ -> addAction(upgrade_);
148  help_menu_ -> addAction(upgrade_M);
149  help_menu_ -> addAction(donate_);
150  help_menu_ -> addAction(about_qt_);
151 
152 #ifdef Q_OS_WIN32
153 upgrade_ -> setVisible(true);
154 #else
155 upgrade_ -> setVisible(false);
156 #endif
157 
158 #ifdef Q_OS_MAC
159 upgrade_M -> setVisible(true);
160 #else
161 upgrade_M -> setVisible(false);
162 #endif
163 
164  insertMenu(nullptr, settings_menu_);
165  insertMenu(nullptr, help_menu_);
166 }
167 
172 void QETMainWindow::insertMenu(QMenu *before, QMenu *menu, bool customize) {
173  if (!menu) return;
174 
175  QAction *before_action = actionForMenu(before);
176  QAction *menu_action = menuBar() -> insertMenu(before_action, menu);
177  menu_actions_.insert(menu, menu_action);
178 
179  if (customize) {
180  menu -> setTearOffEnabled(true);
181  }
182 }
183 
187 QAction *QETMainWindow::actionForMenu(QMenu *menu) {
188  return(menu_actions_.value(menu, nullptr));
189 }
190 
195  setWindowState(windowState() ^ Qt::WindowFullScreen);
196 }
197 
203  if (windowState() & Qt::WindowFullScreen) {
204  fullscreen_action_ -> setText(tr("Sortir du &mode plein écran"));
206  fullscreen_action_ -> setStatusTip(tr("Affiche QElectroTech en mode fenêtré", "status bar tip"));
207  } else {
208  fullscreen_action_ -> setText(tr("Passer en &mode plein écran"));
210  fullscreen_action_ -> setStatusTip(tr("Affiche QElectroTech en mode plein écran", "status bar tip"));
211  }
212  fullscreen_action_ -> setShortcut(QKeySequence(tr("Ctrl+Shift+F")));
213 }
214 
220  if (display_toolbars_) return;
221  display_toolbars_ = createPopupMenu();
222  if (display_toolbars_) {
223  display_toolbars_ -> setTearOffEnabled(true);
224  display_toolbars_ -> setTitle(tr("Afficher", "menu entry"));
227  }
228 }
229 
233 bool QETMainWindow::event(QEvent *e) {
234  if (e -> type() == QEvent::WindowStateChange) {
236  } else if (first_activation_ && e -> type() == QEvent::WindowActivate) {
237  firstActivation(e);
238  first_activation_ = false;
239  }
240  return(QMainWindow::event(e));
241 }
242 
247 }
248 
249 
255 void QETMainWindow::dragEnterEvent(QDragEnterEvent *e) {
256  if (e -> mimeData() -> hasUrls()) {
257  if (QETApp::handledFiles(e -> mimeData() -> urls()).count()) {
258  e -> acceptProposedAction();
259  }
260  }
261 }
262 
268 void QETMainWindow::dropEvent(QDropEvent *e) {
269  if (e -> mimeData() -> hasUrls()) {
270  QStringList filepaths = QETApp::handledFiles(e -> mimeData() -> urls());
271  if (filepaths.count()) {
272  QETApp::instance() -> openFiles(QETArguments(filepaths));
273  }
274  }
275 }
void configureQET()
Definition: qetapp.cpp:1472
void initCommonMenus()
QIcon QETDownload
Definition: qeticons.cpp:211
void checkToolbarsmenu()
static QStringList handledFiles(const QList< QUrl > &)
Definition: qetapp.cpp:757
void initCommonActions()
virtual void firstActivation(QEvent *)
QIcon QETManual
Definition: qeticons.cpp:209
void toggleFullScreen()
QIcon QETLogo
Definition: qeticons.cpp:151
void dragEnterEvent(QDragEnterEvent *e) override
QAction * about_qt_
launch the "About Qt" dialog
Definition: qetmainwindow.h:64
QMenu * settings_menu_
Settings menu.
Definition: qetmainwindow.h:65
QIcon Configure
Definition: qeticons.cpp:38
QMenu * display_toolbars_
Show/hide toolbars/docks.
Definition: qetmainwindow.h:67
bool event(QEvent *) override
QAction * configure_action_
Launch the QElectroTech configuration dialog.
Definition: qetmainwindow.h:55
QIcon FullScreenExit
Definition: qeticons.cpp:104
QIcon QETDonate
Definition: qeticons.cpp:210
QAction * about_qet_
Launch the "About QElectroTech" dialog.
Definition: qetmainwindow.h:58
QMenu * help_menu_
Help menu.
Definition: qetmainwindow.h:66
QAction * manual_online_
Launch browser on QElectroTech online manual.
Definition: qetmainwindow.h:59
void dropEvent(QDropEvent *e) override
QAction * upgrade_
Launch browser on QElectroTech Windows Nightly builds.
Definition: qetmainwindow.h:61
Definition: qetapp.h:53
QIcon tr
Definition: qeticons.cpp:204
~QETMainWindow() override
QAction * youtube_
Launch browser on QElectroTech Youtube channel.
Definition: qetmainwindow.h:60
bool first_activation_
Used to detect whether the window is activated for the first time.
Definition: qetmainwindow.h:69
QIcon ConfigureToolbars
Definition: qeticons.cpp:39
QAction * fullscreen_action_
Toggle full screen.
Definition: qetmainwindow.h:56
QIcon FullScreenEnter
Definition: qeticons.cpp:103
QAction * actionForMenu(QMenu *)
QAction * whatsthis_action_
Toggle "What&#39;s this" mode.
Definition: qetmainwindow.h:57
QIcon QtLogo
Definition: qeticons.cpp:153
static QList< QETDiagramEditor * > diagramEditors()
Definition: qetapp.cpp:1025
void insertMenu(QMenu *, QMenu *, bool=true)
QAction * donate_
Launch browser to donate link.
Definition: qetmainwindow.h:63
QAction * upgrade_M
Launch browser on QElectroTech MAC_OS_X builds.
Definition: qetmainwindow.h:62
QETMainWindow(QWidget *=nullptr, Qt::WindowFlags=nullptr)
QHash< QMenu *, QAction * > menu_actions_
Store actions retrieved when inserting menus.
Definition: qetmainwindow.h:68
void updateFullScreenAction()
static QETApp * instance()
Definition: qetapp.cpp:143
QIcon QETVideo
Definition: qeticons.cpp:212