diff --git a/share/resources/icon.qrc b/share/resources/icon.qrc index 5188b15ad..504b28697 100644 --- a/share/resources/icon.qrc +++ b/share/resources/icon.qrc @@ -41,5 +41,14 @@ icon/32x32/splinePath_cut_point.png icon/32x32/union.png icon/32x32/arc_cut.png + icon/config.png + icon/pattern_config.png + icon/flags/cs.png + icon/flags/de.png + icon/flags/en.png + icon/flags/fr.png + icon/flags/he_IL.png + icon/flags/ru.png + icon/flags/uk.png diff --git a/share/resources/icon/config.png b/share/resources/icon/config.png new file mode 100644 index 000000000..fffe949eb Binary files /dev/null and b/share/resources/icon/config.png differ diff --git a/share/resources/icon/flags/cs.png b/share/resources/icon/flags/cs.png new file mode 100644 index 000000000..73ac44241 Binary files /dev/null and b/share/resources/icon/flags/cs.png differ diff --git a/share/resources/icon/flags/de.png b/share/resources/icon/flags/de.png new file mode 100644 index 000000000..0c229c322 Binary files /dev/null and b/share/resources/icon/flags/de.png differ diff --git a/share/resources/icon/flags/en.png b/share/resources/icon/flags/en.png new file mode 100644 index 000000000..ce1d2269b Binary files /dev/null and b/share/resources/icon/flags/en.png differ diff --git a/share/resources/icon/flags/fr.png b/share/resources/icon/flags/fr.png new file mode 100644 index 000000000..f27f41143 Binary files /dev/null and b/share/resources/icon/flags/fr.png differ diff --git a/share/resources/icon/flags/he_IL.png b/share/resources/icon/flags/he_IL.png new file mode 100644 index 000000000..8a8d4a8f8 Binary files /dev/null and b/share/resources/icon/flags/he_IL.png differ diff --git a/share/resources/icon/flags/ru.png b/share/resources/icon/flags/ru.png new file mode 100644 index 000000000..d9624ca1c Binary files /dev/null and b/share/resources/icon/flags/ru.png differ diff --git a/share/resources/icon/flags/uk.png b/share/resources/icon/flags/uk.png new file mode 100644 index 000000000..e46611fac Binary files /dev/null and b/share/resources/icon/flags/uk.png differ diff --git a/share/resources/icon/pattern_config.png b/share/resources/icon/pattern_config.png new file mode 100644 index 000000000..4f5fb8004 Binary files /dev/null and b/share/resources/icon/pattern_config.png differ diff --git a/src/dialogs/configdialog.cpp b/src/dialogs/configdialog.cpp new file mode 100644 index 000000000..1cfdb228b --- /dev/null +++ b/src/dialogs/configdialog.cpp @@ -0,0 +1,146 @@ +/************************************************************************ + ** + ** @file configdialog.cpp + ** @author Roman Telezhinsky + ** @date 12 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#include "configdialog.h" + +ConfigDialog::ConfigDialog(QWidget *parent) : + QDialog(parent), contentsWidget(0), pagesWidget(0), configurationPage(0), patternPage(0) +{ + contentsWidget = new QListWidget; + Q_CHECK_PTR(contentsWidget); + contentsWidget->setViewMode(QListView::IconMode); + contentsWidget->setIconSize(QSize(96, 84)); + contentsWidget->setMovement(QListView::Static); + contentsWidget->setMaximumWidth(128); + contentsWidget->setMinimumHeight(250); + contentsWidget->setSpacing(12); + + pagesWidget = new QStackedWidget; + Q_CHECK_PTR(pagesWidget); + configurationPage = new ConfigurationPage(); + Q_CHECK_PTR(configurationPage); + pagesWidget->addWidget(configurationPage); + patternPage = new PatternPage(); + Q_CHECK_PTR(patternPage); + pagesWidget->addWidget(patternPage); + + QPushButton *applyButton = new QPushButton(tr("Apply")); + Q_CHECK_PTR(applyButton); + QPushButton *canselButton = new QPushButton(tr("&Cancel")); + Q_CHECK_PTR(canselButton); + QPushButton *okButton = new QPushButton(tr("&Ok")); + Q_CHECK_PTR(okButton); + + createIcons(); + contentsWidget->setCurrentRow(0); + + connect(canselButton, &QPushButton::clicked, this, &ConfigDialog::close); + connect(applyButton, &QPushButton::clicked, this, &ConfigDialog::Apply); + connect(okButton, &QPushButton::clicked, this, &ConfigDialog::Ok); + + QHBoxLayout *horizontalLayout = new QHBoxLayout; + Q_CHECK_PTR(horizontalLayout); + horizontalLayout->addWidget(contentsWidget); + horizontalLayout->addWidget(pagesWidget, 1); + + QHBoxLayout *buttonsLayout = new QHBoxLayout; + Q_CHECK_PTR(buttonsLayout); + buttonsLayout->addStretch(1); + buttonsLayout->addWidget(applyButton); + buttonsLayout->addWidget(canselButton); + buttonsLayout->addWidget(okButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + Q_CHECK_PTR(mainLayout); + mainLayout->addLayout(horizontalLayout); + mainLayout->addStretch(1); + mainLayout->addSpacing(12); + mainLayout->addLayout(buttonsLayout); + setLayout(mainLayout); + + setWindowTitle(tr("Config Dialog")); +} + +void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (current == false) + { + current = previous; + } + pagesWidget->setCurrentIndex(contentsWidget->row(current)); +} + +void ConfigDialog::closeEvent(QCloseEvent *event) +{ + if (result() == QDialog::Accepted) + { + done(QDialog::Accepted); + } + event->accept(); +} + +void ConfigDialog::createIcons() +{ + QListWidgetItem *configButton = new QListWidgetItem(contentsWidget); + Q_CHECK_PTR(configButton); + configButton->setIcon(QIcon("://icon/config.png")); + configButton->setText(tr("Configuration")); + configButton->setTextAlignment(Qt::AlignHCenter); + configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + QListWidgetItem *patternButton = new QListWidgetItem(contentsWidget); + Q_CHECK_PTR(patternButton); + patternButton->setIcon(QIcon("://icon/pattern_config.png")); + patternButton->setText(tr("Pattern")); + patternButton->setTextAlignment(Qt::AlignHCenter); + patternButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + connect(contentsWidget, &QListWidget::currentItemChanged, this, &ConfigDialog::changePage); +} + +void ConfigDialog::Apply() +{ + switch(contentsWidget->currentRow()) + { + case(0): + configurationPage->Apply(); + break; + case(1): + patternPage->Apply(); + break; + default: + break; + } + setResult(QDialog::Accepted); +} + +void ConfigDialog::Ok() +{ + Apply(); + done(QDialog::Accepted); +} diff --git a/src/dialogs/configdialog.h b/src/dialogs/configdialog.h new file mode 100644 index 000000000..9acc653aa --- /dev/null +++ b/src/dialogs/configdialog.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file configdialog.h + ** @author Roman Telezhinsky + ** @date 12 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef CONFIGDIALOG_H +#define CONFIGDIALOG_H + +#include +#include +#include "pages.h" + +class QListWidgetItem; +class QStackedWidget; + +class ConfigDialog : public QDialog +{ + Q_OBJECT +public: + explicit ConfigDialog(QWidget *parent = 0); +public slots: + void changePage(QListWidgetItem *current, QListWidgetItem *previous); +protected: + virtual void closeEvent(QCloseEvent *event); +private: + Q_DISABLE_COPY(ConfigDialog) + QListWidget *contentsWidget; + QStackedWidget *pagesWidget; + ConfigurationPage *configurationPage; + PatternPage *patternPage; + void createIcons(); + void Apply(); + void Ok(); +}; + +#endif // CONFIGDIALOG_H diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h index 9cdc7c318..ace57ca71 100644 --- a/src/dialogs/dialogs.h +++ b/src/dialogs/dialogs.h @@ -51,5 +51,6 @@ #include "dialoguniondetails.h" #include "dialogtriangle.h" #include "dialogpointofintersection.h" +#include "configdialog.h" #endif // DIALOGS_H diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index 291077001..747b7005a 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -22,7 +22,9 @@ HEADERS += \ src/dialogs/dialogcutspline.h \ src/dialogs/dialogcutsplinepath.h \ src/dialogs/dialoguniondetails.h \ - src/dialogs/dialogcutarc.h + src/dialogs/dialogcutarc.h \ + src/dialogs/configdialog.h \ + src/dialogs/pages.h SOURCES += \ src/dialogs/dialogtriangle.cpp \ @@ -47,7 +49,9 @@ SOURCES += \ src/dialogs/dialogcutspline.cpp \ src/dialogs/dialogcutsplinepath.cpp \ src/dialogs/dialoguniondetails.cpp \ - src/dialogs/dialogcutarc.cpp + src/dialogs/dialogcutarc.cpp \ + src/dialogs/configdialog.cpp \ + src/dialogs/pages.cpp FORMS += \ src/dialogs/dialogtriangle.ui \ diff --git a/src/dialogs/pages.cpp b/src/dialogs/pages.cpp new file mode 100644 index 000000000..92fb7f6d4 --- /dev/null +++ b/src/dialogs/pages.cpp @@ -0,0 +1,295 @@ +/************************************************************************ + ** + ** @file pages.cpp + ** @author Roman Telezhinsky + ** @date 12 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#include "pages.h" +#include //for user name + +ConfigurationPage::ConfigurationPage(QWidget *parent): + QWidget(parent), autoSaveCheck(0), autoTime(0), langCombo(0), osOptionCheck(0), langChanged(false) +{ + QGroupBox *saveGroup = SaveGroup(); + QGroupBox *langGroup = LangGroup(); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(saveGroup); + mainLayout->addWidget(langGroup); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + +void ConfigurationPage::Apply() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked()); + settings.setValue("configuration/autosave/time", autoTime->value()); + //settings.setValue("configuration/osSeparator", osOptionCheck->isChecked()); + if (langChanged) + { + QString locale = qvariant_cast(langCombo->itemData(langCombo->currentIndex())); + settings.setValue("configuration/locale", locale); + langChanged = false; + QString text = QString(tr("Setup user interface language updated and will be used the next time start") + " " + + QApplication::applicationName()); + QMessageBox::information(this, QApplication::applicationName(), text); + } +} + +void ConfigurationPage::LangChenged() +{ + langChanged = true; +} + +QGroupBox *ConfigurationPage::SaveGroup() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + + QGroupBox *saveGroup = new QGroupBox(tr("Save")); + Q_CHECK_PTR(saveGroup); + + autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern")); + Q_CHECK_PTR(autoSaveCheck); + bool autoSaveValue = settings.value("configuration/autosave/state", 1).toBool(); + autoSaveCheck->setChecked(autoSaveValue); + + QLabel *intervalLabel = new QLabel(tr("Interval:")); + Q_CHECK_PTR(intervalLabel); + + autoTime = new QSpinBox(); + Q_CHECK_PTR(autoTime); + bool ok = true; + qint32 autoTimeValue = settings.value("configuration/autosave/time", 5).toInt(&ok); + if (ok == false) + { + autoTimeValue = 5; + } + autoTime->setValue(autoTimeValue); + autoTime->setSuffix(tr("min")); + + QHBoxLayout *autosaveLayout = new QHBoxLayout; + Q_CHECK_PTR(autosaveLayout); + autosaveLayout->addWidget(autoSaveCheck); + autosaveLayout->addWidget(intervalLabel); + autosaveLayout->addWidget(autoTime); + + QVBoxLayout *saveLayout = new QVBoxLayout; + Q_CHECK_PTR(saveLayout); + saveLayout->addLayout(autosaveLayout); + saveGroup->setLayout(saveLayout); + return saveGroup; +} + +QGroupBox *ConfigurationPage::LangGroup() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + + QGroupBox *langGroup = new QGroupBox(tr("Language")); + Q_CHECK_PTR(langGroup); + + QLabel *guiLabel = new QLabel(tr("GUI language")); + Q_CHECK_PTR(guiLabel); + + langCombo = new QComboBox; + Q_CHECK_PTR(langCombo); + + // format systems language + QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" + defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" + QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString(); + + QString m_langPath = QApplication::applicationDirPath(); + m_langPath.append("/translations"); + QDir dir(m_langPath); + QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); + + for (int i = 0; i < fileNames.size(); ++i) + { + // get locale extracted by filename + QString locale; + locale = fileNames[i]; // "valentina_de.qm" + locale.truncate(locale.lastIndexOf('.')); // "valentina_de" + locale.remove(0, locale.indexOf('_') + 1); // "de" + + QString lang = QLocale(locale).nativeLanguageName(); + QIcon ico(QString("%1/%2.png").arg("://icon/flags").arg(locale)); + + langCombo->addItem(ico, lang, locale); + } + // set default translators and language checked + qint32 index = langCombo->findData(checkedLocale); + if (index != -1) + { + langCombo->setCurrentIndex(index); + } + connect(langCombo, static_cast(&QComboBox::currentIndexChanged), this, + &ConfigurationPage::LangChenged); + + QHBoxLayout *guiLangLayout = new QHBoxLayout; + Q_CHECK_PTR(guiLangLayout); + guiLangLayout->addWidget(guiLabel); + guiLangLayout->addWidget(langCombo); + + QLabel *separatorLabel = new QLabel(tr("Decimal separator parts")); + Q_CHECK_PTR(separatorLabel); + + osOptionCheck = new QCheckBox(tr("With OS options (.)")); + Q_CHECK_PTR(osOptionCheck); + //bool osOptionValue = settings.value("configuration/osSeparator", 1).toBool(); + //osOptionCheck->setChecked(osOptionValue); + osOptionCheck->setEnabled(false); + + QHBoxLayout *separatorLayout = new QHBoxLayout; + Q_CHECK_PTR(separatorLayout); + separatorLayout->addWidget(separatorLabel); + separatorLayout->addWidget(osOptionCheck); + + QVBoxLayout *langLayout = new QVBoxLayout; + Q_CHECK_PTR(langLayout); + langLayout->addLayout(guiLangLayout); + langLayout->addLayout(separatorLayout); + langGroup->setLayout(langLayout); + return langGroup; +} + + +PatternPage::PatternPage(QWidget *parent): + QWidget(parent), userName(0), graphOutputCheck(0), undoneCount(0) +{ + QGroupBox *userGroup = UserGroup(); + QGroupBox *graphOutputGroup = GraphOutputGroup(); + QGroupBox *undoneGroup = UndoneGroup(); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(userGroup); + mainLayout->addWidget(graphOutputGroup); + mainLayout->addWidget(undoneGroup); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + +void PatternPage::Apply() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + settings.setValue("pattern/user", userName->text()); + //settings.setValue("pattern/graphicalOutput", graphOutputCheck->isChecked()); + settings.setValue("pattern/undone", undoneCount->value()); +} + +QGroupBox *PatternPage::UserGroup() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + + QGroupBox *userGroup = new QGroupBox(tr("User")); + Q_CHECK_PTR(userGroup); + + QLabel *nameLabel = new QLabel(tr("User name")); + Q_CHECK_PTR(nameLabel); + + userName = new QLineEdit; + Q_CHECK_PTR(userName); +#ifdef Q_OS_WIN32 + QString user = settings.value("pattern/user", getenv("USERNAME")).toString(&ok); +#else + QString user = settings.value("pattern/user", getenv("USER")).toString(); +#endif + userName->setText(user); + + QHBoxLayout *nameLayout = new QHBoxLayout; + Q_CHECK_PTR(nameLayout); + nameLayout->addWidget(nameLabel); + nameLayout->addWidget(userName); + + QVBoxLayout *userLayout = new QVBoxLayout; + Q_CHECK_PTR(userLayout); + userLayout->addLayout(nameLayout); + userGroup->setLayout(userLayout); + return userGroup; +} + +QGroupBox *PatternPage::GraphOutputGroup() +{ +// QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), +// QApplication::applicationName()); + + QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output")); + Q_CHECK_PTR(graphOutputGroup); + + graphOutputCheck = new QCheckBox(tr("Use antialiasing")); + Q_CHECK_PTR(graphOutputCheck); + //bool graphOutputValue = settings.value("pattern/graphicalOutput", 1).toBool(); + //graphOutputCheck->setChecked(graphOutputValue); + graphOutputCheck->setEnabled(false); + + QHBoxLayout *graphLayout = new QHBoxLayout; + Q_CHECK_PTR(graphLayout); + graphLayout->addWidget(graphOutputCheck); + + QVBoxLayout *graphOutputLayout = new QVBoxLayout; + Q_CHECK_PTR(graphOutputLayout); + graphOutputLayout->addLayout(graphLayout); + graphOutputGroup->setLayout(graphOutputLayout); + return graphOutputGroup; +} + +QGroupBox *PatternPage::UndoneGroup() +{ + // QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + // QApplication::applicationName()); + + QGroupBox *undoneGroup = new QGroupBox(tr("Undone")); + Q_CHECK_PTR(undoneGroup); + + QLabel *undoneLabel = new QLabel(tr("Count steps")); + Q_CHECK_PTR(undoneLabel); + + undoneCount = new QSpinBox; + Q_CHECK_PTR(undoneCount); +// bool ok = true; +// qint32 count = settings.value("pattern/undone", 100).toInt(&ok); +// if (ok == false) +// { +// count = 100; +// } +// undoneCount->setValue(count); + undoneCount->setEnabled(false); + + QHBoxLayout *countLayout = new QHBoxLayout; + Q_CHECK_PTR(countLayout); + countLayout->addWidget(undoneLabel); + countLayout->addWidget(undoneCount); + + QVBoxLayout *undoneLayout = new QVBoxLayout; + Q_CHECK_PTR(undoneLayout); + undoneLayout->addLayout(countLayout); + undoneGroup->setLayout(undoneLayout); + return undoneGroup; +} diff --git a/src/dialogs/pages.h b/src/dialogs/pages.h new file mode 100644 index 000000000..3c28df093 --- /dev/null +++ b/src/dialogs/pages.h @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file pages.h + ** @author Roman Telezhinsky + ** @date 12 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef PAGES_H +#define PAGES_H + +#include + +class ConfigurationPage : public QWidget +{ + Q_OBJECT +public: + ConfigurationPage(QWidget *parent = 0); + void Apply(); +public slots: + void LangChenged(); +private: + Q_DISABLE_COPY(ConfigurationPage) + QCheckBox *autoSaveCheck; + QSpinBox *autoTime; + QComboBox *langCombo; + QCheckBox *osOptionCheck; + bool langChanged; + QGroupBox *SaveGroup(); + QGroupBox *LangGroup(); +}; + +class PatternPage : public QWidget +{ +public: + PatternPage(QWidget *parent = 0); + void Apply(); +private: + Q_DISABLE_COPY(PatternPage) + QLineEdit *userName; + QCheckBox *graphOutputCheck; + QSpinBox *undoneCount; + QGroupBox *UserGroup(); + QGroupBox *GraphOutputGroup(); + QGroupBox *UndoneGroup(); +}; + +#endif // PAGES_H diff --git a/src/main.cpp b/src/main.cpp index 84cf80822..6cb211d25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,28 +67,33 @@ int main(int argc, char *argv[]) qInstallMessageHandler(myMessageOutput); VApplication app(argc, argv); - - QTranslator qtTranslator; - qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - app.installTranslator(&qtTranslator); - - QTranslator appTranslator; -#ifdef Q_OS_WIN32 - appTranslator.load("valentina_" + QLocale::system().name(), "."); -#else - #ifdef QT_DEBUG - appTranslator.load("valentina_" + QLocale::system().name(), "."); - #else - appTranslator.load("valentina_" + QLocale::system().name(), "/usr/share/valentina/translations"); - #endif -#endif - app.installTranslator(&appTranslator); - app.setApplicationDisplayName("Valentina"); app.setApplicationName("Valentina"); app.setOrganizationName("ValentinaTeam"); app.setOrganizationDomain("valentinaproject.bitbucket.org"); + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" + defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" + QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString(); + + QTranslator qtTranslator; + qtTranslator.load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + app.installTranslator(&qtTranslator); + + QTranslator appTranslator; +#ifdef Q_OS_WIN32 + appTranslator.load("valentina_" + checkedLocale, "./translations"); +#else + #ifdef QT_DEBUG + appTranslator.load("valentina_" + checkedLocale, "./translations"); + #else + appTranslator.load("valentina_" + checkedLocale, "/usr/share/valentina/translations"); + #endif +#endif + app.installTranslator(&appTranslator); + MainWindow w; w.setWindowState(w.windowState() ^ Qt::WindowMaximized); app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png")); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e2fcd4b09..764c93072 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -79,7 +79,8 @@ MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0), dialogTool(0), dialogHistory(0), comboBoxDraws(0), curFile(QString()), mode(Draw::Calculation), - currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{0,0,0,0,0}, separatorAct(0) + currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{0,0,0,0,0}, separatorAct(0), + autoSaveTimer(0) { CreateActions(); CreateMenus(); @@ -131,11 +132,7 @@ MainWindow::MainWindow(QWidget *parent) doc->CreateEmptyFile(); connect(doc, &VDomDocument::patternChanged, this, &MainWindow::PatternWasModified); - //Autosaving file each 5 minutes - QTimer *timer = new QTimer(this); - timer->setTimerType(Qt::VeryCoarseTimer); - connect(timer, &QTimer::timeout, this, &MainWindow::AutoSavePattern); - timer->start(300000); + InitAutoSave(); ui->toolBox->setCurrentIndex(0); @@ -513,11 +510,13 @@ void MainWindow::ClosedDialogCutArc(int result) void MainWindow::About() { + QDate date = QLocale(QLocale::C).toDate(QString(__DATE__).simplified(), QLatin1String("MMM d yyyy")); + QString fullName = QString("Valentina %1").arg(APP_VERSION); QString qtBase(tr("Based on Qt %2 (32 bit)").arg(QT_VERSION_STR)); - QString buildOn(tr("Built on %3 at %4").arg(__DATE__).arg(__TIME__)); - QString about = QString(tr("

%1

%2

%3

%4")).arg(fullName).arg(qtBase).arg( - buildOn).arg(WARRANTY); + QString buildOn(tr("Built on %3 at %4").arg(date.toString()).arg(__TIME__)); + QString about = QString(tr("

%1

%2

%3

%4")).arg(fullName).arg(qtBase).arg(buildOn) + .arg(WARRANTY); QMessageBox::about(this, tr("About Valentina"), about); } @@ -969,6 +968,15 @@ void MainWindow::Open() } } +void MainWindow::Options() +{ + ConfigDialog dlg(this); + if (dlg.exec() == QDialog::Accepted) + { + InitAutoSave(); + } +} + void MainWindow::Clear() { setCurrentFile(""); @@ -1393,6 +1401,7 @@ void MainWindow::CreateActions() connect(ui->actionAbout_Qt, &QAction::triggered, this, &MainWindow::AboutQt); connect(ui->actionAbout_Valentina, &QAction::triggered, this, &MainWindow::About); connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close); + connect(ui->actionOptions, &QAction::triggered, this, &MainWindow::Options); //Actions for recent files loaded by a main window application. for (int i = 0; i < MaxRecentFiles; ++i) @@ -1404,6 +1413,32 @@ void MainWindow::CreateActions() } } +void MainWindow::InitAutoSave() +{ + //Autosaving file each 5 minutes + delete autoSaveTimer; + autoSaveTimer = 0; + + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + bool autoSave = settings.value("configuration/autosave/state", 1).toBool(); + if (autoSave) + { + bool ok = true; + qint32 autoTime = settings.value("configuration/autosave/time", 5).toInt(&ok); + if (ok == false) + { + autoTime = 5; + } + + autoSaveTimer = new QTimer(this); + Q_CHECK_PTR(autoSaveTimer); + autoSaveTimer->setTimerType(Qt::VeryCoarseTimer); + connect(autoSaveTimer, &QTimer::timeout, this, &MainWindow::AutoSavePattern); + autoSaveTimer->start(autoTime*60000); + } +} + MainWindow::~MainWindow() { CancelTool(); diff --git a/src/mainwindow.h b/src/mainwindow.h index a98ad4366..c37f23667 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -100,6 +100,10 @@ public slots: * @brief Open ask user select pattern file. */ void Open(); + /** + * @brief Options config dialog. + */ + void Options(); /** * @brief NewPattern create new empty pattern. */ @@ -460,6 +464,7 @@ private: enum { MaxRecentFiles = 5 }; QAction *recentFileActs[MaxRecentFiles]; QAction *separatorAct; + QTimer *autoSaveTimer; /** * @brief ToolBarOption enable option toolbar. */ @@ -564,6 +569,7 @@ private: void UpdateRecentFileActions(); void CreateMenus(); void CreateActions(); + void InitAutoSave(); }; #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 214dbddf7..5d5d63a7d 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -47,7 +47,7 @@ 0 0 - 150 + 144 150 @@ -302,7 +302,7 @@ 0 0 - 150 + 100 58 @@ -378,7 +378,7 @@ 0 0 - 150 + 100 104 @@ -579,7 +579,7 @@ 0 0 - 150 + 100 58 @@ -694,6 +694,8 @@ + + @@ -986,6 +988,11 @@ Ctrl+Q + + + Options... + +