diff --git a/qelectrotech.pro b/qelectrotech.pro index 2f2afe9fa..3df05b977 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -89,11 +89,17 @@ INCLUDEPATH += sources \ sources/ElementsCollection \ sources/ElementsCollection/ui \ sources/autoNum \ - sources/autoNum/ui + sources/autoNum/ui \ + sources/ui/configpage # Fichiers sources -HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) $$files(sources/editor/*.h) $$files(sources/titleblock/*.h) $$files(sources/richtext/*.h) $$files(sources/qetgraphicsitem/*.h) $$files(sources/factory/*.h) \ +HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \ + $$files(sources/editor/*.h) \ + $$files(sources/titleblock/*.h) \ + $$files(sources/richtext/*.h) \ + $$files(sources/qetgraphicsitem/*.h) \ + $$files(sources/factory/*.h) \ $$files(sources/properties/*.h) \ $$files(sources/editor/ui/*.h) \ $$files(sources/editor/esevent/*.h) \ @@ -104,9 +110,16 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) $$files(sources/editor/* $$files(sources/ElementsCollection/*.h) \ $$files(sources/ElementsCollection/ui/*.h) \ $$files(sources/autoNum/*.h) \ - $$files(sources/autoNum/ui/*.h) + $$files(sources/autoNum/ui/*.h) \ + $$files(sources/ui/configpage/*.h) -SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/titleblock/*.cpp) $$files(sources/richtext/*.cpp) $$files(sources/ui/*.cpp) $$files(sources/qetgraphicsitem/*.cpp) $$files(sources/factory/*.cpp) \ +SOURCES += $$files(sources/*.cpp) \ + $$files(sources/editor/*.cpp) \ + $$files(sources/titleblock/*.cpp) \ + $$files(sources/richtext/*.cpp) \ + $$files(sources/ui/*.cpp) \ + $$files(sources/qetgraphicsitem/*.cpp) \ + $$files(sources/factory/*.cpp) \ $$files(sources/properties/*.cpp) \ $$files(sources/editor/ui/*.cpp) \ $$files(sources/editor/esevent/*.cpp) \ @@ -117,7 +130,8 @@ SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/ $$files(sources/ElementsCollection/*.cpp) \ $$files(sources/ElementsCollection/ui/*.cpp) \ $$files(sources/autoNum/*.cpp) \ - $$files(sources/autoNum/ui/*.cpp) + $$files(sources/autoNum/ui/*.cpp) \ + $$files(sources/ui/configpage/*.cpp) # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc @@ -136,7 +150,8 @@ FORMS += $$files(sources/richtext/*.ui) \ $$files(sources/ui/*.ui) \ $$files(sources/editor/ui/*.ui) \ $$files(sources/ElementsCollection/ui/*.ui) \ - $$files(sources/autoNum/ui/*.ui) + $$files(sources/autoNum/ui/*.ui) \ + $$files(sources/ui/configpage/*.ui) UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/configpages.cpp b/sources/configpages.cpp index e5a31da58..2ec82e361 100644 --- a/sources/configpages.cpp +++ b/sources/configpages.cpp @@ -225,223 +225,6 @@ void NewDiagramPage::loadSavedTbp(){ applyConf(); } -/** - Constructeur - @param parent QWidget parent -*/ -GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : ConfigPage(parent) -{ - //Conf of QElectroTech - QSettings settings; - bool use_system_colors = settings.value("usesystemcolors", "true").toBool(); - bool tabbed = settings.value("diagrameditor/viewmode", "tabbed") == "tabbed"; - bool zoom_out_folio = settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool(); - bool use_trackpad = settings.value("diagramview/gestures", false).toBool(); - bool save_label_paste = settings.value("diagramcommands/erase-label-on-copy", true).toBool(); - bool panel_folio = settings.value("genericpanel/folio", true).toBool(); - bool highlight_integrated_elements = settings.value("diagrameditor/highlight-integrated-elements", true).toBool(); - bool terminal_exportlist = settings.value("nomenclature-exportlist", true).toBool(); - QString default_element_informations = settings.value("elementeditor/default-informations", "").toString(); - - appearance_ = new QGroupBox(tr("Apparence"), this); - use_system_colors_ = new QCheckBox(tr("Utiliser les couleurs du système"), appearance_); - projects_view_mode_ = new QGroupBox(tr("Projets"), this); - windowed_mode_ = new QRadioButton(tr("Utiliser des fenêtres (appliqué au prochain lancement de QElectroTech)"), projects_view_mode_); - tabbed_mode_ = new QRadioButton(tr("Utiliser des onglets (appliqué au prochain lancement de QElectroTech)"), projects_view_mode_); - use_trackpad_ = new QCheckBox(tr("Utiliser les gestes du pavé tactile"), projects_view_mode_); - save_label_paste_ = new QCheckBox(tr("Ne pas conserver les labels des éléments lors des copier coller"), projects_view_mode_); - folio_panel_ = new QCheckBox(tr("Utiliser les labels de folio à la place de leurs ID"), projects_view_mode_); - terminal_exportlist_ = new QCheckBox(tr("Exporter les bornes dans la nomenclature"), projects_view_mode_); - m_zoom_out_beyond_folio = new QCheckBox(tr("Autoriser le dézoom au delà du folio"), this); - - QString fontInfos = settings.value("diagramitemfont").toString() + " " + - settings.value("diagramitemsize").toString() + " (" + - settings.value("diagramitemstyle").toString() + ")"; - font_label = new QLabel(tr("Police des champs de texte")); - fontButton = new QPushButton(fontInfos); - fontButton->setMinimumHeight(28); - - QString foliolistfontInfos = settings.value("foliolistfont").toString() + " " + - settings.value("foliolistsize").toString() + " (" + - settings.value("folioliststyle").toString() + ")"; - foliolist_font_label = new QLabel(tr("Police des champs textes des pages sommaires")); - foliolist_fontButton = new QPushButton(foliolistfontInfos); - foliolist_fontButton->setMinimumHeight(28); - - elements_management_ = new QGroupBox(tr("Gestion des éléments"), this); - highlight_integrated_elements_ = new QCheckBox(tr("Mettre en valeur dans le panel les éléments fraîchement intégrés", "configuration option")); - default_element_infos_label_ = new QLabel( - tr( - "Chaque élément embarque des informations sur ses auteurs, sa licence, ou tout autre renseignement que vous jugerez utile dans un champ libre. " - "Vous pouvez spécifier ici la valeur par défaut de ce champ pour les éléments que vous créerez :" - ) - ); - default_element_infos_label_ -> setWordWrap(true); - default_element_infos_textfield_ = new QTextEdit(); - default_element_infos_textfield_ -> setAcceptRichText(false); - - use_system_colors_ -> setChecked(use_system_colors); - - use_trackpad_ -> setChecked(use_trackpad); - save_label_paste_ -> setChecked(save_label_paste); - folio_panel_ ->setChecked(panel_folio); - terminal_exportlist_ ->setChecked(terminal_exportlist); - - if (tabbed) { - tabbed_mode_ -> setChecked(true); - } else { - windowed_mode_ -> setChecked(true); - } - - m_zoom_out_beyond_folio -> setChecked(zoom_out_folio); - - highlight_integrated_elements_ -> setChecked(highlight_integrated_elements); - default_element_infos_textfield_ -> setPlainText(default_element_informations); - - QVBoxLayout *appearance_layout = new QVBoxLayout(); - appearance_layout -> addWidget(use_system_colors_); - appearance_ -> setLayout(appearance_layout); - - QVBoxLayout *projects_view_mode_layout = new QVBoxLayout; - QHBoxLayout *font_view_layout = new QHBoxLayout; - QHBoxLayout *foliolist_font_view_layout = new QHBoxLayout; - projects_view_mode_layout -> addWidget(windowed_mode_); - projects_view_mode_layout -> addWidget(tabbed_mode_); - projects_view_mode_layout -> addWidget(m_zoom_out_beyond_folio); - projects_view_mode_layout -> addWidget(use_trackpad_); - projects_view_mode_layout -> addWidget(save_label_paste_); - projects_view_mode_layout -> addWidget(folio_panel_); - projects_view_mode_layout -> addWidget(terminal_exportlist_); - font_view_layout->addWidget(font_label, 1); - font_view_layout->addWidget(fontButton, 0); - foliolist_font_view_layout->addWidget(foliolist_font_label, 1); - foliolist_font_view_layout->addWidget(foliolist_fontButton, 0); - projects_view_mode_layout-> addLayout(font_view_layout); - projects_view_mode_layout-> addLayout(foliolist_font_view_layout); - projects_view_mode_ -> setLayout(projects_view_mode_layout); - - - connect(fontButton, SIGNAL(clicked()), this, SLOT(setFont())); - connect(foliolist_fontButton, SIGNAL(clicked()), this, SLOT(setFoliolistFont())); - - - - QVBoxLayout *elements_management_layout = new QVBoxLayout(); - elements_management_layout -> addWidget(highlight_integrated_elements_); - elements_management_layout -> addWidget(default_element_infos_label_); - elements_management_layout -> addWidget(default_element_infos_textfield_); - elements_management_ -> setLayout(elements_management_layout); - - //setup lang combo box selection widget - lang_group_box = new QGroupBox(tr("Langue"), this); - QHBoxLayout *lang_layout = new QHBoxLayout(lang_group_box); - lang_combo_box = new QComboBox(); - lang_label = new QLabel(tr("La nouvelle langue sera prise en compte au prochain lancement de QElectroTech.")); - lang_layout->addWidget(lang_combo_box); - lang_layout->addWidget(lang_label); - fillLang(settings); - - QVBoxLayout *vlayout1 = new QVBoxLayout(); - - QLabel *title_label_ = new QLabel(title()); - vlayout1 -> addWidget(title_label_); - - QFrame *horiz_line_ = new QFrame(); - horiz_line_ -> setFrameShape(QFrame::HLine); - vlayout1 -> addWidget(horiz_line_); - - vlayout1 -> addWidget(appearance_); - vlayout1 -> addWidget(projects_view_mode_); - vlayout1 -> addWidget(elements_management_); - vlayout1 -> addWidget(lang_group_box); - vlayout1 -> addStretch(); - - setLayout(vlayout1); -} - -/// Destructeur -GeneralConfigurationPage::~GeneralConfigurationPage() { -} - -/** - * @brief GeneralConfigurationPage::applyConf - * Write all configuration in settings file - */ -void GeneralConfigurationPage::applyConf() -{ - QSettings settings; - - bool was_using_system_colors = settings.value("usesystemcolors", "true").toBool(); - bool must_use_system_colors = use_system_colors_ -> isChecked(); - settings.setValue("usesystemcolors", must_use_system_colors); - if (was_using_system_colors != must_use_system_colors) { - QETApp::instance() -> useSystemPalette(must_use_system_colors); - } - - settings.setValue("lang", lang_combo_box->itemData(lang_combo_box->currentIndex()).toString()); - - QString view_mode = tabbed_mode_ -> isChecked() ? "tabbed" : "windowed"; - settings.setValue("diagrameditor/viewmode", view_mode) ; - - settings.setValue("diagrameditor/highlight-integrated-elements", highlight_integrated_elements_ -> isChecked()); - settings.setValue("elementeditor/default-informations", default_element_infos_textfield_ -> toPlainText()); - settings.setValue("diagramview/gestures", use_trackpad_ -> isChecked()); - settings.setValue("diagramcommands/erase-label-on-copy", save_label_paste_ -> isChecked()); - settings.setValue("diagrameditor/zoom-out-beyond-of-folio", m_zoom_out_beyond_folio->isChecked()); - settings.setValue("genericpanel/folio",folio_panel_->isChecked()); - settings.setValue("nomenclature/terminal-exportlist",terminal_exportlist_->isChecked()); -} - -/// @return l'icone de cette page -QIcon GeneralConfigurationPage::icon() const { - return(QET::Icons::Settings); -} - -/// @return le titre de cette page -QString GeneralConfigurationPage::title() const { - return(tr("Général", "configuration page title")); -} - -/** - * @brief GeneralConfigurationPage::fillLang - * fill all available lang in @lang_combo_box - */ -void GeneralConfigurationPage::fillLang(QSettings &settings) { - lang_combo_box->addItem(QET::Icons::translation, tr("Système"), "system"); - lang_combo_box->insertSeparator(1); - - // all lang available on lang directory - lang_combo_box->addItem(QET::Icons::ar, tr("Arabe"), "ar"); - lang_combo_box->addItem(QET::Icons::br, tr("Brézilien"), "pt_br"); - lang_combo_box->addItem(QET::Icons::catalonia, tr("Catalan"), "ca"); - lang_combo_box->addItem(QET::Icons::cs, tr("Tchèque"), "cs"); - lang_combo_box->addItem(QET::Icons::de, tr("Allemand"), "de"); - lang_combo_box->addItem(QET::Icons::da, tr("Danois"), "da"); - lang_combo_box->addItem(QET::Icons::gr, tr("Grec"), "el"); - lang_combo_box->addItem(QET::Icons::en, tr("Anglais"), "en"); - lang_combo_box->addItem(QET::Icons::es, tr("Espagnol"), "es"); - lang_combo_box->addItem(QET::Icons::fr, tr("Français"), "fr"); - lang_combo_box->addItem(QET::Icons::hr, tr("Croate"), "hr"); - lang_combo_box->addItem(QET::Icons::it, tr("Italien"), "it"); - lang_combo_box->addItem(QET::Icons::pl, tr("Polonais"), "pl"); - lang_combo_box->addItem(QET::Icons::pt, tr("Portugais"), "pt"); - lang_combo_box->addItem(QET::Icons::ro, tr("Roumains"), "ro"); - lang_combo_box->addItem(QET::Icons::ru, tr("Russe"), "ru"); - lang_combo_box->addItem(QET::Icons::sl, tr("Slovène"), "sl"); - lang_combo_box->addItem(QET::Icons::nl, tr("Pays-Bas"), "nl"); - lang_combo_box->addItem(QET::Icons::be, tr("Belgique-Flemish"), "be"); - - //set current index to the lang found in setting file - //if lang doesn't exist set to system - for (int i=0; icount(); i++) { - if (lang_combo_box->itemData(i).toString() == settings.value("lang").toString()) { - lang_combo_box->setCurrentIndex(i); - return; - } - } - lang_combo_box->setCurrentIndex(0); -} - /** Constructeur @param parent QWidget parent @@ -544,43 +327,4 @@ QIcon PrintConfigPage::icon() const { QString PrintConfigPage::title() const { return(tr("Impression", "configuration page title")); } -/** - * @brief GeneralConfigurationPage::setFont - * Apply font to config - */ -void GeneralConfigurationPage::setFont() -{ - bool ok; - QSettings settings; - QFont font = QFontDialog::getFont(&ok, QFont("Sans Serif", 9), this); - if (ok) { - settings.setValue("diagramitemfont", font.family()); - settings.setValue("diagramitemsize", font.pointSize()); - settings.setValue("diagramitemweight", font.weight()); - settings.setValue("diagramitemstyle", font.styleName()); - QString fontInfos = settings.value("diagramitemfont").toString() + " " + - settings.value("diagramitemsize").toString() + " (" + - settings.value("diagramitemstyle").toString() + ")"; - fontButton->setText(fontInfos); - } -} -/** - * @brief GeneralConfigurationPage::setFoliolistFont - * * Apply font to summary pages - */ -void GeneralConfigurationPage::setFoliolistFont() -{ - bool ok; - QSettings settings; - QFont font = QFontDialog::getFont(&ok, QFont("Sans Serif", 9), this); - if (ok) { - settings.setValue("foliolistfont", font.family()); - settings.setValue("foliolistsize", font.pointSize()); - settings.setValue("foliolistweight", font.weight()); - settings.setValue("folioliststyle", font.styleName()); - QString fontInfos = settings.value("foliolistfont").toString() + " " + - settings.value("foliolistsize").toString() + " (" + - settings.value("folioliststyle").toString() + ")"; - foliolist_fontButton->setText(fontInfos); - } -} + diff --git a/sources/configpages.h b/sources/configpages.h index 0caf42a50..06fcc7c59 100644 --- a/sources/configpages.h +++ b/sources/configpages.h @@ -69,60 +69,6 @@ public slots: }; -/** - This configuration page enables users to specify various options,most of - them applying to the whole application. -*/ -class GeneralConfigurationPage : public ConfigPage { - Q_OBJECT - // constructors, destructor - public: - GeneralConfigurationPage(QWidget * = nullptr); - ~GeneralConfigurationPage() override; - private: - GeneralConfigurationPage(const GeneralConfigurationPage &); - - // methods - public: - void applyConf() override; - QString title() const override; - QIcon icon() const override; - - private: - void fillLang(QSettings &); - -public slots: - void setFont(); - void setFoliolistFont(); - - // attributes - private: - QLabel *title_label_; - QFrame *horiz_line_; - QGroupBox *appearance_; - QCheckBox *use_system_colors_; - QCheckBox *use_trackpad_; - QCheckBox *save_label_paste_; - QCheckBox *folio_panel_; - QCheckBox *terminal_exportlist_; - QGroupBox *projects_view_mode_; - QRadioButton *windowed_mode_; - QRadioButton *tabbed_mode_; - QCheckBox *m_zoom_out_beyond_folio; - QLabel *warning_view_mode_; - QGroupBox *elements_management_; - QCheckBox *highlight_integrated_elements_; - QLabel *default_element_infos_label_; - QTextEdit *default_element_infos_textfield_; - QGroupBox *lang_group_box; - QComboBox *lang_combo_box; - QLabel *lang_label; - QLabel *font_label; - QPushButton *fontButton; - QLabel *foliolist_font_label; - QPushButton *foliolist_fontButton; -}; - /** This configuration page enables users to set default export options. */ diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 651483629..07cd90469 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -29,6 +29,10 @@ #include "recentfiles.h" #include "qeticons.h" #include "templatescollection.h" +#include "generalconfigurationpage.h" +#include "qetmessagebox.h" +#include "projectview.h" + #include #include #define QUOTE(x) STRINGIFY(x) @@ -46,13 +50,13 @@ QString QETApp::common_tbt_dir_ = QString(); QString QETApp::config_dir = QString(); #endif QString QETApp::lang_dir = QString(); -TitleBlockTemplatesFilesCollection *QETApp::common_tbt_collection_; -TitleBlockTemplatesFilesCollection *QETApp::custom_tbt_collection_; +TitleBlockTemplatesFilesCollection *QETApp::m_common_tbt_collection; +TitleBlockTemplatesFilesCollection *QETApp::m_custom_tbt_collection; ElementsCollectionCache *QETApp::collections_cache_ = nullptr; QMap QETApp::registered_projects_ = QMap(); uint QETApp::next_project_id = 0; -RecentFiles *QETApp::projects_recent_files_ = nullptr; -RecentFiles *QETApp::elements_recent_files_ = nullptr; +RecentFiles *QETApp::m_projects_recent_files = nullptr; +RecentFiles *QETApp::m_elements_recent_files = nullptr; TitleBlockTemplate *QETApp::default_titleblock_template_ = nullptr; /** @@ -62,7 +66,7 @@ TitleBlockTemplate *QETApp::default_titleblock_template_ = nullptr; */ QETApp::QETApp(int &argc, char **argv) : QETSingleApplication(argc, argv, QString("qelectrotech-" + QETApp::userName())), - splash_screen_(nullptr), + m_splash_screen(nullptr), non_interactive_execution_(false) { parseArguments(); @@ -114,20 +118,43 @@ QETApp::QETApp(int &argc, char **argv) : openFiles(qet_arguments_); } buildSystemTrayMenu(); - splash_screen_ -> hide(); + m_splash_screen -> hide(); + + checkBackupFiles(); } -/// Destructeur -QETApp::~QETApp() { - elements_recent_files_ -> save(); - projects_recent_files_ -> save(); - delete splash_screen_; - delete elements_recent_files_; - delete projects_recent_files_; - delete qsti; - if (custom_tbt_collection_) delete custom_tbt_collection_; - if (common_tbt_collection_) delete common_tbt_collection_; +/** + * @brief QETApp::~QETApp + */ +QETApp::~QETApp() +{ + m_elements_recent_files->save(); + m_projects_recent_files->save(); + + delete m_splash_screen; + delete m_elements_recent_files; + delete m_projects_recent_files; + delete m_qsti; + + if (m_custom_tbt_collection) + delete m_custom_tbt_collection; + if (m_common_tbt_collection) + delete m_common_tbt_collection; + ElementFactory::dropInstance(); + + //Delete all backup files + QDir dir(configDir() + "backup"); + if(dir.exists()) + { + QStringList extension_filter("*.qet"); + QStringList list = dir.entryList(extension_filter); + for(QString str : list) + { + QFile file(dir.path() + "/" + str); + file.remove(); + } + } } /** @@ -197,7 +224,7 @@ void QETApp::systray(QSystemTrayIcon::ActivationReason reason) { case QSystemTrayIcon::Context: // affichage du menu buildSystemTrayMenu(); - qsti -> contextMenu() -> show(); + m_qsti -> contextMenu() -> show(); break; case QSystemTrayIcon::DoubleClick: case QSystemTrayIcon::Trigger: @@ -354,13 +381,13 @@ QString QETApp::elementInfoToVar(const QString &info) by QElecrotTech */ TitleBlockTemplatesFilesCollection *QETApp::commonTitleBlockTemplatesCollection() { - if (!common_tbt_collection_) { - common_tbt_collection_ = new TitleBlockTemplatesFilesCollection(QETApp::commonTitleBlockTemplatesDir()); - common_tbt_collection_ -> setTitle(tr("Cartouches QET", "title of the title block templates collection provided by QElectroTech")); - common_tbt_collection_ -> setProtocol(QETAPP_COMMON_TBT_PROTOCOL); - common_tbt_collection_ -> setCollection(QET::QetCollection::Common); + if (!m_common_tbt_collection) { + m_common_tbt_collection = new TitleBlockTemplatesFilesCollection(QETApp::commonTitleBlockTemplatesDir()); + m_common_tbt_collection -> setTitle(tr("Cartouches QET", "title of the title block templates collection provided by QElectroTech")); + m_common_tbt_collection -> setProtocol(QETAPP_COMMON_TBT_PROTOCOL); + m_common_tbt_collection -> setCollection(QET::QetCollection::Common); } - return(common_tbt_collection_); + return(m_common_tbt_collection); } /** @@ -368,13 +395,13 @@ TitleBlockTemplatesFilesCollection *QETApp::commonTitleBlockTemplatesCollection( by the end user */ TitleBlockTemplatesFilesCollection *QETApp::customTitleBlockTemplatesCollection() { - if (!custom_tbt_collection_) { - custom_tbt_collection_ = new TitleBlockTemplatesFilesCollection(QETApp::customTitleBlockTemplatesDir()); - custom_tbt_collection_ -> setTitle(tr("Cartouches utilisateur", "title of the user's title block templates collection")); - custom_tbt_collection_ -> setProtocol(QETAPP_CUSTOM_TBT_PROTOCOL); - custom_tbt_collection_ -> setCollection(QET::QetCollection::Custom); + if (!m_custom_tbt_collection) { + m_custom_tbt_collection = new TitleBlockTemplatesFilesCollection(QETApp::customTitleBlockTemplatesDir()); + m_custom_tbt_collection -> setTitle(tr("Cartouches utilisateur", "title of the user's title block templates collection")); + m_custom_tbt_collection -> setProtocol(QETAPP_CUSTOM_TBT_PROTOCOL); + m_custom_tbt_collection -> setCollection(QET::QetCollection::Custom); } - return(custom_tbt_collection_); + return(m_custom_tbt_collection); } /** @@ -384,8 +411,8 @@ TitleBlockTemplatesFilesCollection *QETApp::customTitleBlockTemplatesCollection( QList QETApp::availableTitleBlockTemplatesCollections() { QList collections_list; - collections_list << common_tbt_collection_; - collections_list << custom_tbt_collection_; + collections_list << m_common_tbt_collection; + collections_list << m_custom_tbt_collection; foreach(QETProject *opened_project, registered_projects_) { collections_list << opened_project -> embeddedTitleBlockTemplatesCollection(); @@ -400,9 +427,9 @@ QList QETApp::availableTitleBlockTemplatesColle */ TitleBlockTemplatesCollection *QETApp::titleBlockTemplatesCollection(const QString &protocol) { if (protocol == QETAPP_COMMON_TBT_PROTOCOL) { - return(common_tbt_collection_); + return(m_common_tbt_collection); } else if (protocol == QETAPP_CUSTOM_TBT_PROTOCOL) { - return(custom_tbt_collection_); + return(m_custom_tbt_collection); } else { QETProject *project = QETApp::projectFromString(protocol); if (project) { @@ -938,7 +965,7 @@ QList QETApp::elementEditors(QETProject *project) { Nettoie certaines choses avant que l'application ne quitte */ void QETApp::cleanup() { - qsti -> hide(); + m_qsti -> hide(); } /** @@ -970,14 +997,14 @@ template void QETApp::setMainWindowsVisible(bool visible) { @return La liste des fichiers recents pour les projets */ RecentFiles *QETApp::projectsRecentFiles() { - return(projects_recent_files_); + return(m_projects_recent_files); } /** @return La liste des fichiers recents pour les elements */ RecentFiles *QETApp::elementsRecentFiles() { - return(elements_recent_files_); + return(m_elements_recent_files); } /** @@ -1403,8 +1430,8 @@ void QETApp::parseArguments() { */ void QETApp::initSplashScreen() { if (non_interactive_execution_) return; - splash_screen_ = new QSplashScreen(QPixmap(":/ico/splash.png")); - splash_screen_ -> show(); + m_splash_screen = new QSplashScreen(QPixmap(":/ico/splash.png")); + m_splash_screen -> show(); setSplashScreenStep(tr("Chargement...", "splash screen caption")); } @@ -1414,9 +1441,9 @@ void QETApp::initSplashScreen() { rien. */ void QETApp::setSplashScreenStep(const QString &message) { - if (!splash_screen_) return; + if (!m_splash_screen) return; if (!message.isEmpty()) { - splash_screen_ -> showMessage(message, Qt::AlignBottom | Qt::AlignLeft); + m_splash_screen -> showMessage(message, Qt::AlignBottom | Qt::AlignLeft); } processEvents(); } @@ -1460,10 +1487,10 @@ void QETApp::initConfiguration() { // fichiers recents // note : les icones doivent etre initialisees avant ces instructions (qui creent des menus en interne) - projects_recent_files_ = new RecentFiles("projects"); - projects_recent_files_ -> setIconForFiles(QET::Icons::ProjectFile); - elements_recent_files_ = new RecentFiles("elements"); - elements_recent_files_ -> setIconForFiles(QET::Icons::Element); + m_projects_recent_files = new RecentFiles("projects"); + m_projects_recent_files -> setIconForFiles(QET::Icons::ProjectFile); + m_elements_recent_files = new RecentFiles("elements"); + m_elements_recent_files -> setIconForFiles(QET::Icons::Element); } /** @@ -1503,11 +1530,11 @@ void QETApp::initSystemTray() { connect(new_element, SIGNAL(triggered()), this, SLOT(newElementEditor())); // initialisation de l'icone du systray - qsti = new QSystemTrayIcon(QET::Icons::QETLogo, this); - qsti -> setToolTip(tr("QElectroTech", "systray icon tooltip")); - connect(qsti, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systray(QSystemTrayIcon::ActivationReason))); - qsti -> setContextMenu(menu_systray); - qsti -> show(); + m_qsti = new QSystemTrayIcon(QET::Icons::QETLogo, this); + m_qsti -> setToolTip(tr("QElectroTech", "systray icon tooltip")); + connect(m_qsti, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systray(QSystemTrayIcon::ActivationReason))); + m_qsti -> setContextMenu(menu_systray); + m_qsti -> show(); } /** @@ -1604,6 +1631,82 @@ void QETApp::buildSystemTrayMenu() { menu_systray -> addAction(quitter_qet); } +/** + * @brief QETApp::checkBackupFiles + * Check for backup files. + * If backup was found, open a dialog and ask user what to do. + */ +void QETApp::checkBackupFiles() +{ + //Delete all backup files + QDir dir(configDir() + "backup"); + if(dir.exists()) + { + QStringList extension_filter("*.qet"); + QStringList list = dir.entryList(extension_filter); + if(list.isEmpty()) + return; + + QString text; + if(list.size() == 1) + text.append(tr("Le fichier de restauration suivant a été trouvé,
" + "Voulez-vous l'ouvrir ?

")); + else + text.append(tr("Les fichiers de restauration suivant on été trouvé,
" + "Voulez-vous les ouvrir ?

")); + for(QString name : list) + text.append("
" + name); + + if (QET::QetMessageBox::question(nullptr, tr("Fichier de restauration"), text, QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok) + { + QStringList files_list; + for(QString str : list) + files_list << dir.path() + "/" + str; + + QList diagrams_editors = diagramEditors(); + + //If there is opened editors, we find those who are visible + if (diagrams_editors.count()) + { + QList visible_diagrams_editors; + for(QETDiagramEditor *de : diagrams_editors) { + if (de->isVisible()) + visible_diagrams_editors << de; + } + + //We take the first visible, or the first one + QETDiagramEditor *de_open; + if (visible_diagrams_editors.count()) { + de_open = visible_diagrams_editors.first(); + } + else + { + de_open = diagrams_editors.first(); + de_open -> setVisible(true); + } + + for(QString file : files_list) { + de_open -> openAndAddProject(file); + } + } + else { + new QETDiagramEditor(files_list); + } + + //Because the file was open from backup, we remove the file path of each project opened, + //for avoid user to save in the backup directory + for(QETDiagramEditor *editor : diagramEditors()) + { + for(ProjectView *pv : editor->openedProjects()) + { + if(files_list.contains(pv->project()->filePath())) + pv->project()->setFilePath(QString()); + } + } + } + } +} + /// Met a jour les booleens concernant l'etat des fenetres void QETApp::fetchWindowStats( const QList &diagrams, diff --git a/sources/qetapp.h b/sources/qetapp.h index f4e944957..f439e8146 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -50,188 +50,195 @@ class RecentFiles; /** This class represents the QElectroTech application. */ -class QETApp : public QETSingleApplication { +class QETApp : public QETSingleApplication +{ Q_OBJECT - // constructors, destructor + // constructors, destructor public: - QETApp(int &, char **); - ~QETApp() override; + QETApp(int &, char **); + ~QETApp() override; private: - QETApp(const QETApp &); + QETApp(const QETApp &); - // methods + // methods public: - static QETApp *instance(); - void setLanguage(const QString &); - static QString langFromSetting (); - void switchLayout(Qt::LayoutDirection); - static void printHelp(); - static void printVersion(); - static void printLicense(); - - static ElementsCollectionCache *collectionCache(); - static QStringList elementInfoKeys(); - static QString elementTranslatedInfoKey(const QString &); - static QString elementInfoToVar(const QString &info); - - static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); - static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); - static QList availableTitleBlockTemplatesCollections(); - static TitleBlockTemplatesCollection *titleBlockTemplatesCollection(const QString &); - - static QString userName(); - static QString commonElementsDir(); - static QString customElementsDir(); - static QString commonElementsDirN(); - static QString customElementsDirN(); - static QString commonTitleBlockTemplatesDir(); - static QString customTitleBlockTemplatesDir(); - static bool registerProject(QETProject *); - static bool unregisterProject(QETProject *); - static QMap registeredProjects(); - static QETProject *project(const uint &); - static int projectId(const QETProject *); - static QString configDir(); - static QString languagesPath(); - static QString realPath(const QString &); - static QString symbolicPath(const QString &); - static QStringList handledFileExtensions(); - static QStringList handledFiles(const QList &); - static RecentFiles *projectsRecentFiles(); - static RecentFiles *elementsRecentFiles(); + static QETApp *instance(); + void setLanguage(const QString &); + static QString langFromSetting (); + void switchLayout(Qt::LayoutDirection); + static void printHelp(); + static void printVersion(); + static void printLicense(); + + static ElementsCollectionCache *collectionCache(); + static QStringList elementInfoKeys(); + static QString elementTranslatedInfoKey(const QString &); + static QString elementInfoToVar(const QString &info); + + static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); + static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); + static QList availableTitleBlockTemplatesCollections(); + static TitleBlockTemplatesCollection *titleBlockTemplatesCollection(const QString &); + + static QString userName(); + static QString commonElementsDir(); + static QString customElementsDir(); + static QString commonElementsDirN(); + static QString customElementsDirN(); + static QString commonTitleBlockTemplatesDir(); + static QString customTitleBlockTemplatesDir(); + static bool registerProject(QETProject *); + static bool unregisterProject(QETProject *); + static QMap registeredProjects(); + static QETProject *project(const uint &); + static int projectId(const QETProject *); + static QString configDir(); + static QString languagesPath(); + static QString realPath(const QString &); + static QString symbolicPath(const QString &); + static QStringList handledFileExtensions(); + static QStringList handledFiles(const QList &); + static RecentFiles *projectsRecentFiles(); + static RecentFiles *elementsRecentFiles(); + #ifdef QET_ALLOW_OVERRIDE_CED_OPTION public: - static void overrideCommonElementsDir(const QString &); + static void overrideCommonElementsDir(const QString &); private: - static QString common_elements_dir; ///< Directory containing the common elements collection + static QString common_elements_dir; ///< Directory containing the common elements collection #endif + #ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION public: - static void overrideCommonTitleBlockTemplatesDir(const QString &); + static void overrideCommonTitleBlockTemplatesDir(const QString &); private: - static QString common_tbt_dir_; ///< Directory containing the common title block templates collection + static QString common_tbt_dir_; ///< Directory containing the common title block templates collection #endif + #ifdef QET_ALLOW_OVERRIDE_CD_OPTION public: - static void overrideConfigDir(const QString &); + static void overrideConfigDir(const QString &); private: - static QString config_dir; ///< Directory containing the user configuration and the custom elements collection + static QString config_dir; ///< Directory containing the user configuration and the custom elements collection #endif + public: - static void overrideLangDir(const QString &); - static QString lang_dir; ///< Directory containing localization files. - static QFont diagramTextsFont(qreal = -1.0); - static QFont diagramTextsItemFont(qreal = -1.0); - static QFont foliolistTextsFont(qreal = -1.0); - static QETDiagramEditor *diagramEditorForFile(const QString &); - static QETDiagramEditor *diagramEditorAncestorOf (const QWidget *child); - static QList diagramEditors(); - static QList elementEditors(); - static QList elementEditors(QETProject *); - static QList titleBlockTemplateEditors(); - static QList titleBlockTemplateEditors(QETProject *); - static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget(); - static TitleBlockTemplate *defaultTitleBlockTemplate(); + static void overrideLangDir(const QString &); + static QString lang_dir; ///< Directory containing localization files. + static QFont diagramTextsFont(qreal = -1.0); + static QFont diagramTextsItemFont(qreal = -1.0); + static QFont foliolistTextsFont(qreal = -1.0); + static QETDiagramEditor *diagramEditorForFile(const QString &); + static QETDiagramEditor *diagramEditorAncestorOf (const QWidget *child); + static QList diagramEditors(); + static QList elementEditors(); + static QList elementEditors(QETProject *); + static QList titleBlockTemplateEditors(); + static QList titleBlockTemplateEditors(QETProject *); + static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget(); + static TitleBlockTemplate *defaultTitleBlockTemplate(); protected: + #ifdef Q_OS_DARWIN bool event(QEvent *); #endif - // attributes + // attributes private: - QTranslator qtTranslator; - QTranslator qetTranslator; - QSystemTrayIcon *qsti; - QSplashScreen *splash_screen_; - QMenu *menu_systray; - QAction *quitter_qet; - QAction *reduce_appli; - QAction *restore_appli; - QAction *reduce_diagrams; - QAction *restore_diagrams; - QAction *reduce_elements; - QAction *restore_elements; - QAction *reduce_templates; - QAction *restore_templates; - QAction *new_diagram; - QAction *new_element; - QHash window_geometries; - QHash window_states; - bool every_editor_reduced; - bool every_diagram_reduced; - bool every_diagram_visible; - bool every_element_reduced; - bool every_element_visible; - bool every_template_reduced; - bool every_template_visible; - QSignalMapper signal_map; - QETArguments qet_arguments_; ///< Comand-line arguments parser - bool non_interactive_execution_; ///< Whether the application will end without any user interaction - QPalette initial_palette_; ///< System color palette - - static TitleBlockTemplatesFilesCollection *common_tbt_collection_; - static TitleBlockTemplatesFilesCollection *custom_tbt_collection_; - static ElementsCollectionCache *collections_cache_; - static QMap registered_projects_; - static uint next_project_id; - static RecentFiles *projects_recent_files_; - static RecentFiles *elements_recent_files_; - static TitleBlockTemplate *default_titleblock_template_; + QTranslator qtTranslator; + QTranslator qetTranslator; + QSystemTrayIcon *m_qsti; + QSplashScreen *m_splash_screen; + QMenu *menu_systray; + QAction *quitter_qet; + QAction *reduce_appli; + QAction *restore_appli; + QAction *reduce_diagrams; + QAction *restore_diagrams; + QAction *reduce_elements; + QAction *restore_elements; + QAction *reduce_templates; + QAction *restore_templates; + QAction *new_diagram; + QAction *new_element; + QHash window_geometries; + QHash window_states; + bool every_editor_reduced; + bool every_diagram_reduced; + bool every_diagram_visible; + bool every_element_reduced; + bool every_element_visible; + bool every_template_reduced; + bool every_template_visible; + QSignalMapper signal_map; + QETArguments qet_arguments_; ///< Comand-line arguments parser + bool non_interactive_execution_; ///< Whether the application will end without any user interaction + QPalette initial_palette_; ///< System color palette + + static TitleBlockTemplatesFilesCollection *m_common_tbt_collection; + static TitleBlockTemplatesFilesCollection *m_custom_tbt_collection; + static ElementsCollectionCache *collections_cache_; + static QMap registered_projects_; + static uint next_project_id; + static RecentFiles *m_projects_recent_files; + static RecentFiles *m_elements_recent_files; + static TitleBlockTemplate *default_titleblock_template_; public slots: - void systray(QSystemTrayIcon::ActivationReason); - void reduceEveryEditor(); - void restoreEveryEditor(); - void reduceDiagramEditors(); - void restoreDiagramEditors(); - void reduceElementEditors(); - void restoreElementEditors(); - void reduceTitleBlockTemplateEditors(); - void restoreTitleBlockTemplateEditors(); - void newDiagramEditor(); - void newElementEditor(); - bool closeEveryEditor(); - void setMainWindowVisible(QMainWindow *, bool); - void invertMainWindowVisibility(QWidget *); - void useSystemPalette(bool); - void quitQET(); - void checkRemainingWindows(); - void messageReceived(const QString &); - void openFiles(const QETArguments &); - void openProjectFiles(const QStringList &); - void openElementFiles(const QStringList &); - void openElementLocations(const QList &); - void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false); - void openTitleBlockTemplate(const QString &); - void openTitleBlockTemplateFiles(const QStringList &); - void configureQET(); - void aboutQET(); + void systray(QSystemTrayIcon::ActivationReason); + void reduceEveryEditor(); + void restoreEveryEditor(); + void reduceDiagramEditors(); + void restoreDiagramEditors(); + void reduceElementEditors(); + void restoreElementEditors(); + void reduceTitleBlockTemplateEditors(); + void restoreTitleBlockTemplateEditors(); + void newDiagramEditor(); + void newElementEditor(); + bool closeEveryEditor(); + void setMainWindowVisible(QMainWindow *, bool); + void invertMainWindowVisibility(QWidget *); + void useSystemPalette(bool); + void quitQET(); + void checkRemainingWindows(); + void messageReceived(const QString &); + void openFiles(const QETArguments &); + void openProjectFiles(const QStringList &); + void openElementFiles(const QStringList &); + void openElementLocations(const QList &); + void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false); + void openTitleBlockTemplate(const QString &); + void openTitleBlockTemplateFiles(const QStringList &); + void configureQET(); + void aboutQET(); private slots: - void cleanup(); + void cleanup(); private: - template QList detectWindows() const; - template void setMainWindowsVisible(bool); - QList floatingToolbarsAndDocksForMainWindow(QMainWindow *) const; - void parseArguments(); - void initSplashScreen(); - void setSplashScreenStep(const QString & = QString()); - void initLanguage(); - void initStyle(); - void initConfiguration(); - void initSystemTray(); - void buildSystemTrayMenu(); - void fetchWindowStats( - const QList &, - const QList &, - const QList & - ); - template void addWindowsListToMenu(QMenu *, const QList &); - static int projectIdFromString(const QString &); - static QETProject *projectFromString(const QString &); + template QList detectWindows() const; + template void setMainWindowsVisible(bool); + QList floatingToolbarsAndDocksForMainWindow(QMainWindow *) const; + void parseArguments(); + void initSplashScreen(); + void setSplashScreenStep(const QString & = QString()); + void initLanguage(); + void initStyle(); + void initConfiguration(); + void initSystemTray(); + void buildSystemTrayMenu(); + void checkBackupFiles(); + void fetchWindowStats( + const QList &, + const QList &, + const QList & + ); + template void addWindowsListToMenu(QMenu *, const QList &); + static int projectIdFromString(const QString &); + static QETProject *projectFromString(const QString &); }; #endif diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 2ee5de6c9..17c21cebb 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -32,9 +32,11 @@ #include "numerotationcontextcommands.h" #include "assignvariables.h" - +#include #include +static int BACKUP_INTERVAL = 300000; //interval in ms of backup + /** Constructeur par defaut - cree un schema contenant une collection d'elements vide et un schema vide. @@ -63,8 +65,26 @@ QETProject::QETProject(int diagrams, QObject *parent) : setupTitleBlockTemplatesCollection(); - undo_stack_ = new QUndoStack(); - connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool))); + m_undo_stack = new QUndoStack(); + connect(m_undo_stack, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool))); + + m_save_backup_timer.setInterval(BACKUP_INTERVAL); + connect(&m_save_backup_timer, &QTimer::timeout, this, &QETProject::writeBackup); + m_save_backup_timer.start(); + + QSettings settings; + int autosave_interval = settings.value("diagrameditor/autosave-interval", 0).toInt(); + if(autosave_interval > 0) + { + int ms = autosave_interval*60*1000; + m_autosave_timer.setInterval(ms); + connect(&m_autosave_timer, &QTimer::timeout, [this]() + { + if(!this->m_file_path.isEmpty()) + this->write(); + }); + m_autosave_timer.start(); + } } /** @@ -111,8 +131,27 @@ QETProject::QETProject(const QString &path, QObject *parent) : setReadOnly(true); } - undo_stack_ = new QUndoStack(); - connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool))); + m_undo_stack = new QUndoStack(); + connect(m_undo_stack, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool))); + + m_save_backup_timer.setInterval(BACKUP_INTERVAL); + connect(&m_save_backup_timer, &QTimer::timeout, this, &QETProject::writeBackup); + m_save_backup_timer.start(); + writeBackup(); + + QSettings settings; + int autosave_interval = settings.value("diagrameditor/autosave-interval", 0).toInt(); + if(autosave_interval > 0) + { + int ms = autosave_interval*60*1000; + m_autosave_timer.setInterval(ms); + connect(&m_autosave_timer, &QTimer::timeout, [this]() + { + if(!this->m_file_path.isEmpty()) + this->write(); + }); + m_autosave_timer.start(); + } } /** @@ -122,7 +161,18 @@ QETProject::QETProject(const QString &path, QObject *parent) : QETProject::~QETProject() { qDeleteAll(m_diagrams_list); - delete undo_stack_; + delete m_undo_stack; + + //Project is closed without crash, we can safely remove the backup file. + if (!m_file_path.isEmpty()) + { + QDir dir(QETApp::configDir() + "/backup"); + if(!dir.exists()) + return; + + QString project_name = m_file_path.split("/").last(); + dir.remove(project_name); + } } /** @@ -187,7 +237,7 @@ TitleBlockTemplatesProjectCollection *QETProject::embeddedTitleBlockTemplatesCol @return le chemin du fichier dans lequel ce projet est enregistre */ QString QETProject::filePath() { - return(file_path_); + return(m_file_path); } /** @@ -195,15 +245,15 @@ QString QETProject::filePath() { @param filepath Nouveau chemin de fichier */ void QETProject::setFilePath(const QString &filepath) { - file_path_ = filepath; + m_file_path = filepath; // le chemin a change : on reevalue la necessite du mode lecture seule - QFileInfo file_path_info(file_path_); + QFileInfo file_path_info(m_file_path); if (file_path_info.isWritable()) { setReadOnly(false); } - emit(projectFilePathChanged(this, file_path_)); + emit(projectFilePathChanged(this, m_file_path)); emit(projectInformationsChanged(this)); } @@ -214,10 +264,10 @@ void QETProject::setFilePath(const QString &filepath) { */ QString QETProject::currentDir() const { QString current_directory; - if (file_path_.isEmpty()) { + if (m_file_path.isEmpty()) { current_directory = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); } else { - current_directory = QFileInfo(file_path_).absoluteDir().absolutePath(); + current_directory = QFileInfo(m_file_path).absoluteDir().absolutePath(); } return(current_directory); } @@ -240,14 +290,14 @@ QString QETProject::pathNameTitle() const { "Projet « %1 : %2»", "displayed title for a ProjectView - %1 is the project title, -%2 is the project path" ) - ).arg(project_title_).arg (file_path_); - } else if (!file_path_.isEmpty()) { + ).arg(project_title_).arg (m_file_path); + } else if (!m_file_path.isEmpty()) { final_title = QString( tr( "Projet %1", "displayed title for a title-less project - %1 is the file name" ) - ).arg(QFileInfo(file_path_).completeBaseName()); + ).arg(QFileInfo(m_file_path).completeBaseName()); } else { final_title = QString( tr( @@ -800,12 +850,12 @@ bool QETProject::close() { QETResult QETProject::write() { // this operation requires a filepath - if (file_path_.isEmpty()) + if (m_file_path.isEmpty()) return(QString("unable to save project to file: no filepath was specified")); // if the project was opened read-only and the file is still non-writable, do not save the project - if (isReadOnly() && !QFileInfo(file_path_).isWritable()) - return(QString("the file %1 was opened read-only and thus will not be written").arg(file_path_)); + if (isReadOnly() && !QFileInfo(m_file_path).isWritable()) + return(QString("the file %1 was opened read-only and thus will not be written").arg(m_file_path)); //Get the project in xml @@ -813,7 +863,7 @@ QETResult QETProject::write() xml_project.appendChild(xml_project.importNode(toXml().documentElement(), true)); QString error_message; - if (!QET::writeXmlFile(xml_project, file_path_, &error_message)) return(error_message); + if (!QET::writeXmlFile(xml_project, m_file_path, &error_message)) return(error_message); setModified(false); return(QETResult()); @@ -823,7 +873,7 @@ QETResult QETProject::write() @return true si le projet est en mode readonly, false sinon */ bool QETProject::isReadOnly() const { - return(read_only_ && read_only_file_path_ == file_path_); + return(read_only_ && read_only_file_path_ == m_file_path); } /** @@ -836,7 +886,7 @@ void QETProject::setReadOnly(bool read_only) if (read_only_ != read_only) { //keep the file to which this project is read-only - read_only_file_path_ = file_path_; + read_only_file_path_ = m_file_path; read_only_ = read_only; emit(readOnlyChanged(this, read_only)); } @@ -1597,6 +1647,30 @@ NamesList QETProject::namesListForIntegrationCategory() { return(names); } +/** + * @brief QETProject::writeBackup + * Write a backup file of this project, in the case that QET crash + */ +void QETProject::writeBackup() +{ + if(m_file_path.isEmpty()) + return; + + QDir dir(QETApp::configDir() + "/backup"); + if(!dir.exists()) + { + dir.cdUp(); + dir.mkdir("backup"); + dir.cd("backup"); + } + + QDomDocument xml_project; + xml_project.appendChild(xml_project.importNode(toXml().documentElement(), true)); + + QString project_name = m_file_path.split("/").last(); + QET::writeXmlFile(xml_project, dir.absoluteFilePath(project_name)); +} + /** @return true if project options (title, project-wide properties, settings for new diagrams, diagrams order...) were modified, false otherwise. @@ -1634,7 +1708,7 @@ void QETProject::setProjectProperties(const DiagramContext &context) { bool QETProject::projectWasModified() { if ( projectOptionsWereModified() || - !undo_stack_ -> isClean() || + !m_undo_stack -> isClean() || titleblocks_.templates().count() ) return(true); diff --git a/sources/qetproject.h b/sources/qetproject.h index 8c42b23d5..59f5713ed 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -34,6 +34,7 @@ class MoveTitleBlockTemplatesHandler; class NumerotationContext; class QUndoStack; class XmlElementCollection; +class QTimer; /** This class represents a QET project. Typically saved as a .qet file, it @@ -55,7 +56,6 @@ class QETProject : public QObject private: QETProject(const QETProject &); - void init (); // enums public: @@ -163,7 +163,7 @@ class QETProject : public QObject bool projectOptionsWereModified(); DiagramContext projectProperties(); void setProjectProperties(const DiagramContext &); - QUndoStack* undoStack() {return undo_stack_;} + QUndoStack* undoStack() {return m_undo_stack;} public slots: Diagram *addNewDiagram(); @@ -204,7 +204,6 @@ class QETProject : public QObject private: void setupTitleBlockTemplatesCollection(); - void readProjectXml(QDomDocument &xml_project); void readDiagramsXml(QDomDocument &xml_project); void readElementsCollectionXml(QDomDocument &xml_project); @@ -215,11 +214,12 @@ class QETProject : public QObject void writeDefaultPropertiesXml(QDomElement &); void addDiagram(Diagram *); NamesList namesListForIntegrationCategory(); + void writeBackup(); // attributes private: /// File path this project is saved to - QString file_path_; + QString m_file_path; /// Current state of the project ProjectState state_; /// Diagrams carried by the project @@ -249,7 +249,7 @@ class QETProject : public QObject /// project-wide variables that will be made available to child diagrams DiagramContext project_properties_; /// undo stack for this project - QUndoStack *undo_stack_; + QUndoStack *m_undo_stack; /// Conductor auto numerotation QHash m_conductor_autonum;//Title and NumContext hash QString m_current_conductor_autonum; @@ -264,6 +264,8 @@ class QETProject : public QObject XmlElementCollection *m_elements_collection; bool m_freeze_new_elements; bool m_freeze_new_conductors; + QTimer m_save_backup_timer, + m_autosave_timer; }; Q_DECLARE_METATYPE(QETProject *) diff --git a/sources/ui/configpage/generalconfigurationpage.cpp b/sources/ui/configpage/generalconfigurationpage.cpp new file mode 100644 index 000000000..605276c80 --- /dev/null +++ b/sources/ui/configpage/generalconfigurationpage.cpp @@ -0,0 +1,204 @@ +/* + Copyright 2006-2018 The QElectroTech Team + This file is part of QElectroTech. + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "generalconfigurationpage.h" +#include "ui_generalconfigurationpage.h" +#include "qeticons.h" +#include "qetapp.h" + +#include +#include + +/** + * @brief GeneralConfigurationPage::GeneralConfigurationPage + * @param parent + */ +GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : + ConfigPage(parent), + ui(new Ui::GeneralConfigurationPage) +{ + ui->setupUi(this); + + QSettings settings; + + ui->m_use_system_color_cb->setChecked(settings.value("usesystemcolors", "true").toBool()); + bool tabbed = settings.value("diagrameditor/viewmode", "tabbed") == "tabbed"; + if(tabbed) + ui->m_use_tab_mode_rb->setChecked(true); + else + ui->m_use_windows_mode_rb->setChecked(true); + ui->m_zoom_out_beyond_folio->setChecked(settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool()); + ui->m_use_gesture_trackpad->setChecked(settings.value("diagramview/gestures", false).toBool()); + ui->m_save_label_paste->setChecked(settings.value("diagramcommands/erase-label-on-copy", true).toBool()); + ui->m_use_folio_label->setChecked(settings.value("genericpanel/folio", true).toBool()); + ui->m_export_terminal->setChecked(settings.value("nomenclature-exportlist", true).toBool()); + ui->m_autosave_sb->setValue(settings.value("diagrameditor/autosave-interval", 0).toInt()); + + QString fontInfos = settings.value("diagramitemfont").toString() + " " + + settings.value("diagramitemsize").toString() + " (" + + settings.value("diagramitemstyle").toString() + ")"; + ui->m_font_pb->setText(fontInfos); + + QString foliolistfontInfos = settings.value("foliolistfont").toString() + " " + + settings.value("foliolistsize").toString() + " (" + + settings.value("folioliststyle").toString() + ")"; + ui->m_folio_list_pb->setText(foliolistfontInfos); + + ui->m_highlight_integrated_elements->setChecked(settings.value("diagrameditor/highlight-integrated-elements", true).toBool()); + ui->m_default_elements_info->setPlainText(settings.value("elementeditor/default-informations", "").toString()); + + fillLang(); +} + +GeneralConfigurationPage::~GeneralConfigurationPage() +{ + delete ui; +} + +/** + * @brief GeneralConfigurationPage::applyConf + * Write all configuration in settings file + */ +void GeneralConfigurationPage::applyConf() +{ + QSettings settings; + + bool was_using_system_colors = settings.value("usesystemcolors", "true").toBool(); + bool must_use_system_colors = ui->m_use_system_color_cb->isChecked(); + settings.setValue("usesystemcolors", must_use_system_colors); + if (was_using_system_colors != must_use_system_colors) { + QETApp::instance()->useSystemPalette(must_use_system_colors); + } + + settings.setValue("lang", ui->m_lang_cb->itemData(ui->m_lang_cb->currentIndex()).toString()); + + QString view_mode = ui->m_use_tab_mode_rb->isChecked() ? "tabbed" : "windowed"; + settings.setValue("diagrameditor/viewmode", view_mode) ; + + settings.setValue("diagrameditor/highlight-integrated-elements", ui->m_highlight_integrated_elements->isChecked()); + settings.setValue("elementeditor/default-informations", ui->m_default_elements_info->toPlainText()); + settings.setValue("diagramview/gestures", ui->m_use_gesture_trackpad->isChecked()); + settings.setValue("diagramcommands/erase-label-on-copy", ui->m_save_label_paste->isChecked()); + settings.setValue("diagrameditor/zoom-out-beyond-of-folio", ui->m_zoom_out_beyond_folio->isChecked()); + settings.setValue("genericpanel/folio",ui->m_use_folio_label->isChecked()); + settings.setValue("nomenclature/terminal-exportlist",ui->m_export_terminal->isChecked()); + settings.setValue("diagrameditor/autosave-interval", ui->m_autosave_sb->value()); +} + +/** + * @brief GeneralConfigurationPage::title + * @return The title of this page + */ +QString GeneralConfigurationPage::title() const { + return(tr("Général", "configuration page title")); +} + +/** + * @brief GeneralConfigurationPage::icon + * @return The icon of this page + */ +QIcon GeneralConfigurationPage::icon() const { + return(QET::Icons::Settings); +} + +/** + * @brief GeneralConfigurationPage::fillLang + * fill all available lang + */ +void GeneralConfigurationPage::fillLang() +{ + ui->m_lang_cb->addItem(QET::Icons::translation, tr("Système"), "system"); + ui->m_lang_cb->insertSeparator(1); + + // all lang available on lang directory + ui->m_lang_cb->addItem(QET::Icons::ar, tr("Arabe"), "ar"); + ui->m_lang_cb->addItem(QET::Icons::br, tr("Brézilien"), "pt_br"); + ui->m_lang_cb->addItem(QET::Icons::catalonia, tr("Catalan"), "ca"); + ui->m_lang_cb->addItem(QET::Icons::cs, tr("Tchèque"), "cs"); + ui->m_lang_cb->addItem(QET::Icons::de, tr("Allemand"), "de"); + ui->m_lang_cb->addItem(QET::Icons::da, tr("Danois"), "da"); + ui->m_lang_cb->addItem(QET::Icons::gr, tr("Grec"), "el"); + ui->m_lang_cb->addItem(QET::Icons::en, tr("Anglais"), "en"); + ui->m_lang_cb->addItem(QET::Icons::es, tr("Espagnol"), "es"); + ui->m_lang_cb->addItem(QET::Icons::fr, tr("Français"), "fr"); + ui->m_lang_cb->addItem(QET::Icons::hr, tr("Croate"), "hr"); + ui->m_lang_cb->addItem(QET::Icons::it, tr("Italien"), "it"); + ui->m_lang_cb->addItem(QET::Icons::pl, tr("Polonais"), "pl"); + ui->m_lang_cb->addItem(QET::Icons::pt, tr("Portugais"), "pt"); + ui->m_lang_cb->addItem(QET::Icons::ro, tr("Roumains"), "ro"); + ui->m_lang_cb->addItem(QET::Icons::ru, tr("Russe"), "ru"); + ui->m_lang_cb->addItem(QET::Icons::sl, tr("Slovène"), "sl"); + ui->m_lang_cb->addItem(QET::Icons::nl, tr("Pays-Bas"), "nl"); + ui->m_lang_cb->addItem(QET::Icons::be, tr("Belgique-Flemish"), "be"); + + //set current index to the lang found in setting file + //if lang doesn't exist set to system + QSettings settings; + for (int i=0; im_lang_cb->count(); i++) + { + if (ui->m_lang_cb->itemData(i).toString() == settings.value("lang").toString()) + { + ui->m_lang_cb->setCurrentIndex(i); + return; + } + } + ui->m_lang_cb->setCurrentIndex(0); +} + +/** + * @brief GeneralConfigurationPage::on_m_font_pb_clicked + * Apply font to config + */ +void GeneralConfigurationPage::on_m_font_pb_clicked() +{ + bool ok; + QSettings settings; + QFont font = QFontDialog::getFont(&ok, QFont("Sans Serif", 9), this); + if (ok) + { + settings.setValue("diagramitemfont", font.family()); + settings.setValue("diagramitemsize", font.pointSize()); + settings.setValue("diagramitemweight", font.weight()); + settings.setValue("diagramitemstyle", font.styleName()); + QString fontInfos = settings.value("diagramitemfont").toString() + " " + + settings.value("diagramitemsize").toString() + " (" + + settings.value("diagramitemstyle").toString() + ")"; + ui->m_font_pb->setText(fontInfos); + } +} + +/** + * @brief GeneralConfigurationPage::on_m_folio_list_pb_clicked + * Apply font to summary pages + */ +void GeneralConfigurationPage::on_m_folio_list_pb_clicked() +{ + bool ok; + QSettings settings; + QFont font = QFontDialog::getFont(&ok, QFont("Sans Serif", 9), this); + if (ok) + { + settings.setValue("foliolistfont", font.family()); + settings.setValue("foliolistsize", font.pointSize()); + settings.setValue("foliolistweight", font.weight()); + settings.setValue("folioliststyle", font.styleName()); + QString fontInfos = settings.value("foliolistfont").toString() + " " + + settings.value("foliolistsize").toString() + " (" + + settings.value("folioliststyle").toString() + ")"; + ui->m_folio_list_pb->setText(fontInfos); + } +} diff --git a/sources/ui/configpage/generalconfigurationpage.h b/sources/ui/configpage/generalconfigurationpage.h new file mode 100644 index 000000000..3771cfc38 --- /dev/null +++ b/sources/ui/configpage/generalconfigurationpage.h @@ -0,0 +1,51 @@ +/* + Copyright 2006-2018 The QElectroTech Team + This file is part of QElectroTech. + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef GENERALCONFIGURATIONPAGE_H +#define GENERALCONFIGURATIONPAGE_H + +#include +#include "configpage.h" + +namespace Ui { + class GeneralConfigurationPage; +} + +class GeneralConfigurationPage : public ConfigPage +{ + Q_OBJECT + + public: + explicit GeneralConfigurationPage(QWidget *parent = 0); + ~GeneralConfigurationPage(); + + virtual void applyConf() override; + virtual QString title() const override; + virtual QIcon icon() const override; + + private slots: + void on_m_font_pb_clicked(); + void on_m_folio_list_pb_clicked(); + + private: + void fillLang(); + + private: + Ui::GeneralConfigurationPage *ui; +}; + +#endif // GENERALCONFIGURATIONPAGE_H diff --git a/sources/ui/configpage/generalconfigurationpage.ui b/sources/ui/configpage/generalconfigurationpage.ui new file mode 100644 index 000000000..91bd754b0 --- /dev/null +++ b/sources/ui/configpage/generalconfigurationpage.ui @@ -0,0 +1,229 @@ + + + GeneralConfigurationPage + + + + 0 + 0 + 827 + 662 + + + + Form + + + + + + Général + + + + + + + Qt::Horizontal + + + + + + + Apparence + + + + + + Utiliser les couleurs du système + + + + + + + + + + Projets + + + + + + + + + + + + + Interval de la sauvegarde automatique (appliqué au prochain lancement de QElectroTech) + + + + + + + + + + + + + + Ne pas conserver les labels des éléments lors des copier coller + + + + + + + Utilisé des onglets (appliqué au proc&hain lancement de QElectroTech) + + + + + + + Utiliser les gestes du pavé tactile + + + + + + + Police des champs textes des pages sommaires + + + + + + + Police des champs de texte + + + + + + + Exporter les bornes dans la nomenclature + + + + + + + true + + + Désactivé + + + min + + + + + + + Utiliser des fenêtres (appliqué au prochain lancement de &QElectroTech) + + + + + + + Autoriser le dézoom au delà du folio + + + + + + + Utiliser les labels de folio à la place de leurs ID + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Gestion des éléments + + + + + + Mettre en valeur dans le panel les éléments fraîchement intégrés + + + + + + + Chaque élément embarque des informations sur ses auteurs, sa licence, ou tout autre renseignement que vous jugerez utile dans un champ libre. +Vous pouvez spécifier ici la valeur par défaut de ce champ pour les éléments que vous créerez : + + + + + + + + + + + + + Langue + + + + + + + + + Appliqué au prochain lancement de QElectroTech + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + +