2012-02-13 22:10:36 +00:00
/*
2020-06-15 17:42:37 +02:00
Copyright 2006 - 2020 The QElectroTech Team
2012-02-13 22:10:36 +00:00
This file is part of QElectroTech .
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
QElectroTech is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 2 of the License , or
( at your option ) any later version .
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
QElectroTech is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
You should have received a copy of the GNU General Public License
along with QElectroTech . If not , see < http : //www.gnu.org/licenses/>.
*/
2016-05-27 12:59:24 +00:00
# include <QAction>
# include <QWhatsThis>
# include <QMenu>
# include <QMenuBar>
# include <QDragEnterEvent>
2016-09-15 03:02:56 +00:00
# include <QDesktopServices>
2016-05-27 12:59:24 +00:00
2012-02-13 22:10:36 +00:00
# include "qetmainwindow.h"
# include "qeticons.h"
# include "qetapp.h"
2016-09-14 13:58:44 +00:00
# include "qetdiagrameditor.h"
2017-02-18 13:30:38 +00:00
# include "projectview.h"
2012-02-13 22:10:36 +00:00
/**
Constructor
*/
QETMainWindow : : QETMainWindow ( QWidget * widget , Qt : : WindowFlags flags ) :
QMainWindow ( widget , flags ) ,
2017-08-05 02:06:59 +00:00
display_toolbars_ ( nullptr ) ,
2012-03-16 18:01:32 +00:00
first_activation_ ( true )
2012-02-13 22:10:36 +00:00
{
initCommonActions ( ) ;
initCommonMenus ( ) ;
2020-09-24 17:01:33 +02:00
2012-05-24 17:27:15 +00:00
setAcceptDrops ( true ) ;
2012-02-13 22:10:36 +00:00
}
/**
Destructor
*/
2020-09-07 22:03:40 +02:00
QETMainWindow : : ~ QETMainWindow ( )
{
2012-02-13 22:10:36 +00:00
}
/**
Initialize common actions .
*/
2020-09-07 22:03:40 +02:00
void QETMainWindow : : initCommonActions ( )
{
2012-02-13 22:10:36 +00:00
QETApp * qet_app = QETApp : : instance ( ) ;
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
configure_action_ = new QAction ( QET : : Icons : : Configure , tr ( " &Configurer QElectroTech " ) , this ) ;
2015-03-02 20:14:56 +00:00
configure_action_ - > setStatusTip ( tr ( " Permet de régler différents paramètres de QElectroTech " , " status bar tip " ) ) ;
2017-02-18 13:30:38 +00:00
connect ( configure_action_ , & QAction : : triggered , [ qet_app ] ( )
{
2016-09-14 13:58:44 +00:00
qet_app - > configureQET ( ) ;
2020-09-24 17:01:33 +02:00
# if TODO_LIST
# pragma message("@TODO we use reloadOldElementPanel only to keep up to date the string of the folio in the old element panel. 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")
# endif
2017-02-18 13:30:38 +00:00
//TODO we use reloadOldElementPanel only to keep up to date the string of the folio in the old element panel.
//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
for ( QETDiagramEditor * qde : qet_app - > diagramEditors ( ) )
{
2016-09-14 13:58:44 +00:00
qde - > reloadOldElementPanel ( ) ;
2017-02-18 13:30:38 +00:00
for ( ProjectView * pv : qde - > openedProjects ( ) )
{
pv - > updateAllTabsTitle ( ) ;
}
}
2016-09-14 13:58:44 +00:00
} ) ;
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
fullscreen_action_ = new QAction ( this ) ;
updateFullScreenAction ( ) ;
connect ( fullscreen_action_ , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleFullScreen ( ) ) ) ;
2020-09-24 17:01:33 +02:00
2012-04-28 16:45:10 +00:00
whatsthis_action_ = QWhatsThis : : createAction ( this ) ;
2020-09-24 17:01:33 +02:00
2015-03-02 20:14:56 +00:00
about_qet_ = new QAction ( QET : : Icons : : QETLogo , tr ( " À &propos de QElectroTech " ) , this ) ;
2012-02-13 22:10:36 +00:00
about_qet_ - > setStatusTip ( tr ( " Affiche des informations sur QElectroTech " , " status bar tip " ) ) ;
connect ( about_qet_ , SIGNAL ( triggered ( ) ) , qet_app , SLOT ( aboutQET ( ) ) ) ;
2020-09-24 17:01:33 +02:00
2016-09-15 03:42:01 +00:00
manual_online_ = new QAction ( QET : : Icons : : QETManual , tr ( " Manuel en ligne " ) , this ) ;
2016-09-15 15:19:36 +00:00
manual_online_ - > setStatusTip ( tr ( " Lance le navigateur par défaut vers le manuel en ligne de QElectroTech " , " status bar tip " ) ) ;
2020-09-24 17:01:33 +02:00
2018-08-29 16:14:30 +00:00
connect ( manual_online_ , & QAction : : triggered , [ ] ( bool ) {
2019-01-21 13:17:50 +00:00
QString link = " https://download.tuxfamily.org/qet/manual_0.7/build/index.html " ;
2016-09-15 03:02:56 +00:00
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
} ) ;
2020-09-24 17:01:33 +02:00
2020-09-07 22:03:40 +02:00
manual_online_ - > setShortcut ( Qt : : Key_F1 ) ;
2020-09-24 17:01:33 +02:00
2016-09-15 15:09:26 +00:00
youtube_ = new QAction ( QET : : Icons : : QETVideo , tr ( " Chaine Youtube " ) , this ) ;
2016-09-15 15:19:36 +00:00
youtube_ - > setStatusTip ( tr ( " Lance le navigateur par défaut vers la chaine Youtube de QElectroTech " , " status bar tip " ) ) ;
2020-09-24 17:01:33 +02:00
2018-08-29 16:14:30 +00:00
connect ( youtube_ , & QAction : : triggered , [ ] ( bool ) {
2016-09-15 11:48:34 +00:00
QString link = " https://www.youtube.com/user/scorpio8101/videos " ;
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
} ) ;
2020-09-24 17:01:33 +02:00
2016-09-15 11:48:34 +00:00
upgrade_ = new QAction ( QET : : Icons : : QETDownload , tr ( " Télécharger une nouvelle version (dev) " ) , this ) ;
2016-09-15 15:29:21 +00:00
upgrade_ - > setStatusTip ( tr ( " Lance le navigateur par défaut vers le dépot Nightly en ligne de QElectroTech " , " status bar tip " ) ) ;
2020-09-24 17:01:33 +02:00
2016-09-26 00:46:02 +00:00
upgrade_M = new QAction ( QET : : Icons : : QETDownload , tr ( " Télécharger une nouvelle version (dev) " ) , this ) ;
upgrade_M - > setStatusTip ( tr ( " Lance le navigateur par défaut vers le dépot Nightly en ligne de QElectroTech " , " status bar tip " ) ) ;
2020-09-24 17:01:33 +02:00
2018-08-29 16:14:30 +00:00
connect ( upgrade_ , & QAction : : triggered , [ ] ( bool ) {
2016-10-30 13:29:16 +00:00
QString link = " https://qelectrotech.org/download_windows_QET.html " ;
2016-09-15 11:48:34 +00:00
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
} ) ;
2020-09-24 17:01:33 +02:00
2018-08-29 16:14:30 +00:00
connect ( upgrade_M , & QAction : : triggered , [ ] ( bool ) {
2016-10-30 13:29:16 +00:00
QString link = " https://qelectrotech.org/download_mac_QET.html " ;
2016-09-26 00:46:02 +00:00
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
} ) ;
2020-09-24 17:01:33 +02:00
2016-09-15 15:09:26 +00:00
donate_ = new QAction ( QET : : Icons : : QETDonate , tr ( " Soutenir le projet par un don " ) , this ) ;
2016-09-15 04:35:07 +00:00
donate_ - > setStatusTip ( tr ( " Soutenir le projet QElectroTech par un don " , " status bar tip " ) ) ;
2020-09-24 17:01:33 +02:00
2018-08-29 16:14:30 +00:00
connect ( donate_ , & QAction : : triggered , [ ] ( bool ) {
2016-09-15 04:35:07 +00:00
QString link = " https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZZHC9D7C3MDPC " ;
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
} ) ;
2020-09-24 17:01:33 +02:00
2015-03-02 20:14:56 +00:00
about_qt_ = new QAction ( QET : : Icons : : QtLogo , tr ( " À propos de &Qt " ) , this ) ;
about_qt_ - > setStatusTip ( tr ( " Affiche des informations sur la bibliothèque Qt " , " status bar tip " ) ) ;
2018-11-06 13:45:47 +00:00
connect ( about_qt_ , SIGNAL ( triggered ( ) ) , qApp , SLOT ( aboutQt ( ) ) ) ;
2012-02-13 22:10:36 +00:00
}
/**
Initialize common menus .
*/
2020-09-07 22:03:40 +02:00
void QETMainWindow : : initCommonMenus ( )
{
2012-02-13 22:10:36 +00:00
settings_menu_ = new QMenu ( tr ( " &Configuration " , " window menu " ) ) ;
settings_menu_ - > addAction ( fullscreen_action_ ) ;
settings_menu_ - > addAction ( configure_action_ ) ;
connect ( settings_menu_ , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( checkToolbarsmenu ( ) ) ) ;
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
help_menu_ = new QMenu ( tr ( " &Aide " , " window menu " ) ) ;
2012-04-28 16:45:10 +00:00
help_menu_ - > addAction ( whatsthis_action_ ) ;
help_menu_ - > addSeparator ( ) ;
2012-02-13 22:10:36 +00:00
help_menu_ - > addAction ( about_qet_ ) ;
2016-09-15 03:02:56 +00:00
help_menu_ - > addAction ( manual_online_ ) ;
2016-09-15 11:48:34 +00:00
help_menu_ - > addAction ( youtube_ ) ;
help_menu_ - > addAction ( upgrade_ ) ;
2016-09-26 00:46:02 +00:00
help_menu_ - > addAction ( upgrade_M ) ;
2016-09-15 04:35:07 +00:00
help_menu_ - > addAction ( donate_ ) ;
2012-02-13 22:10:36 +00:00
help_menu_ - > addAction ( about_qt_ ) ;
2020-09-24 17:01:33 +02:00
2016-09-15 11:48:34 +00:00
# ifdef Q_OS_WIN32
upgrade_ - > setVisible ( true ) ;
# else
upgrade_ - > setVisible ( false ) ;
# endif
2016-09-26 00:46:02 +00:00
2019-09-08 18:29:29 +02:00
# ifdef Q_OS_MACOS
2016-09-26 00:46:02 +00:00
upgrade_M - > setVisible ( true ) ;
# else
upgrade_M - > setVisible ( false ) ;
# endif
2017-08-05 02:06:59 +00:00
insertMenu ( nullptr , settings_menu_ ) ;
insertMenu ( nullptr , help_menu_ ) ;
2012-02-13 22:10:36 +00:00
}
/**
Add \ a menu before \ a before . Unless \ a customize is false , this method also
enables some common settings on the inserted menu .
*/
void QETMainWindow : : insertMenu ( QMenu * before , QMenu * menu , bool customize ) {
if ( ! menu ) return ;
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
QAction * before_action = actionForMenu ( before ) ;
QAction * menu_action = menuBar ( ) - > insertMenu ( before_action , menu ) ;
menu_actions_ . insert ( menu , menu_action ) ;
2020-09-24 17:01:33 +02:00
2012-02-13 22:10:36 +00:00
if ( customize ) {
menu - > setTearOffEnabled ( true ) ;
}
}
/**
@ return the action returned when inserting \ a menu
*/
QAction * QETMainWindow : : actionForMenu ( QMenu * menu ) {
2017-08-05 02:06:59 +00:00
return ( menu_actions_ . value ( menu , nullptr ) ) ;
2012-02-13 22:10:36 +00:00
}
/**
Toggle the window from / to full screen .
*/
2020-09-07 22:03:40 +02:00
void QETMainWindow : : toggleFullScreen ( )
{
2012-02-13 22:10:36 +00:00
setWindowState ( windowState ( ) ^ Qt : : WindowFullScreen ) ;
}
/**
Update the look of the full screen action according to the current state of
the window .
*/
2020-09-07 22:03:40 +02:00
void QETMainWindow : : updateFullScreenAction ( )
{
2012-02-13 22:10:36 +00:00
if ( windowState ( ) & Qt : : WindowFullScreen ) {
2015-03-02 20:14:56 +00:00
fullscreen_action_ - > setText ( tr ( " Sortir du &mode plein écran " ) ) ;
2012-02-13 22:10:36 +00:00
fullscreen_action_ - > setIcon ( QET : : Icons : : FullScreenExit ) ;
2015-03-02 20:14:56 +00:00
fullscreen_action_ - > setStatusTip ( tr ( " Affiche QElectroTech en mode fenêtré " , " status bar tip " ) ) ;
2012-02-13 22:10:36 +00:00
} else {
2015-03-02 20:14:56 +00:00
fullscreen_action_ - > setText ( tr ( " Passer en &mode plein écran " ) ) ;
2012-02-13 22:10:36 +00:00
fullscreen_action_ - > setIcon ( QET : : Icons : : FullScreenEnter ) ;
2015-03-02 20:14:56 +00:00
fullscreen_action_ - > setStatusTip ( tr ( " Affiche QElectroTech en mode plein écran " , " status bar tip " ) ) ;
2012-02-13 22:10:36 +00:00
}
fullscreen_action_ - > setShortcut ( QKeySequence ( tr ( " Ctrl+Shift+F " ) ) ) ;
}
/**
Check whether a sub menu dedicated to docks and toolbars can be inserted on
top of the settings menu .
*/
2020-09-07 22:03:40 +02:00
void QETMainWindow : : checkToolbarsmenu ( )
{
2012-02-13 22:10:36 +00:00
if ( display_toolbars_ ) return ;
display_toolbars_ = createPopupMenu ( ) ;
if ( display_toolbars_ ) {
display_toolbars_ - > setTearOffEnabled ( true ) ;
display_toolbars_ - > setTitle ( tr ( " Afficher " , " menu entry " ) ) ;
display_toolbars_ - > setIcon ( QET : : Icons : : ConfigureToolbars ) ;
settings_menu_ - > insertMenu ( fullscreen_action_ , display_toolbars_ ) ;
}
}
/**
Handle the \ a e event .
*/
bool QETMainWindow : : event ( QEvent * e ) {
if ( e - > type ( ) = = QEvent : : WindowStateChange ) {
updateFullScreenAction ( ) ;
2012-03-16 18:01:32 +00:00
} else if ( first_activation_ & & e - > type ( ) = = QEvent : : WindowActivate ) {
firstActivation ( e ) ;
first_activation_ = false ;
2012-02-13 22:10:36 +00:00
}
return ( QMainWindow : : event ( e ) ) ;
}
2012-03-16 18:01:32 +00:00
/**
Base implementation of firstActivation ( does nothing ) .
*/
void QETMainWindow : : firstActivation ( QEvent * ) {
}
2012-05-24 17:27:15 +00:00
/**
Accept or refuse drag ' n drop events depending on the dropped mime type ;
especially , accepts only URLs to local files that we could open .
@ param e le QDragEnterEvent correspondant au drag ' n drop tente
*/
void QETMainWindow : : dragEnterEvent ( QDragEnterEvent * e ) {
if ( e - > mimeData ( ) - > hasUrls ( ) ) {
if ( QETApp : : handledFiles ( e - > mimeData ( ) - > urls ( ) ) . count ( ) ) {
e - > acceptProposedAction ( ) ;
}
}
}
/**
Handle drops accepted on main windows ; more specifically , open dropped files
as long as they are handled by QElectrotech .
@ param e the QDropEvent describing the current drag ' n drop
*/
void QETMainWindow : : dropEvent ( QDropEvent * e ) {
if ( e - > mimeData ( ) - > hasUrls ( ) ) {
QStringList filepaths = QETApp : : handledFiles ( e - > mimeData ( ) - > urls ( ) ) ;
if ( filepaths . count ( ) ) {
QETApp : : instance ( ) - > openFiles ( QETArguments ( filepaths ) ) ;
}
}
}