From 1ee0988f8a88093dd3eca1d6632b34bfb0ed78c2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 12 Apr 2017 13:31:11 +0300 Subject: [PATCH] Refactoring Valentina's preferences dialog. Instead of manual declaring used Qt Designer. --HG-- branch : release --- src/app/valentina/dialogs/configdialog.cpp | 221 -------- .../dialogs/configpages/configurationpage.cpp | 496 ------------------ .../dialogs/configpages/configurationpage.h | 107 ---- .../dialogs/configpages/patternpage.cpp | 242 --------- .../preferencesconfigurationpage.cpp | 268 ++++++++++ ...npage.h => preferencesconfigurationpage.h} | 65 +-- .../preferencesconfigurationpage.ui | 267 ++++++++++ .../{pathpage.cpp => preferencespathpage.cpp} | 175 ++---- .../{pathpage.h => preferencespathpage.h} | 46 +- .../configpages/preferencespathpage.ui | 111 ++++ .../configpages/preferencespatternpage.cpp | 88 ++++ .../{pages.h => preferencespatternpage.h} | 36 +- .../configpages/preferencespatternpage.ui | 146 ++++++ .../valentina/dialogs/dialogpreferences.cpp | 139 +++++ .../{configdialog.h => dialogpreferences.h} | 56 +- .../valentina/dialogs/dialogpreferences.ui | 157 ++++++ src/app/valentina/dialogs/dialogs.h | 2 +- src/app/valentina/dialogs/dialogs.pri | 27 +- src/app/valentina/mainwindow.cpp | 15 +- 19 files changed, 1354 insertions(+), 1310 deletions(-) delete mode 100644 src/app/valentina/dialogs/configdialog.cpp delete mode 100644 src/app/valentina/dialogs/configpages/configurationpage.cpp delete mode 100644 src/app/valentina/dialogs/configpages/configurationpage.h delete mode 100644 src/app/valentina/dialogs/configpages/patternpage.cpp create mode 100644 src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp rename src/app/valentina/dialogs/configpages/{patternpage.h => preferencesconfigurationpage.h} (51%) create mode 100644 src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui rename src/app/valentina/dialogs/configpages/{pathpage.cpp => preferencespathpage.cpp} (51%) rename src/app/valentina/dialogs/configpages/{pathpage.h => preferencespathpage.h} (64%) create mode 100644 src/app/valentina/dialogs/configpages/preferencespathpage.ui create mode 100644 src/app/valentina/dialogs/configpages/preferencespatternpage.cpp rename src/app/valentina/dialogs/configpages/{pages.h => preferencespatternpage.h} (66%) create mode 100644 src/app/valentina/dialogs/configpages/preferencespatternpage.ui create mode 100644 src/app/valentina/dialogs/dialogpreferences.cpp rename src/app/valentina/dialogs/{configdialog.h => dialogpreferences.h} (57%) create mode 100644 src/app/valentina/dialogs/dialogpreferences.ui diff --git a/src/app/valentina/dialogs/configdialog.cpp b/src/app/valentina/dialogs/configdialog.cpp deleted file mode 100644 index e7e8300db..000000000 --- a/src/app/valentina/dialogs/configdialog.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/************************************************************************ - ** - ** @file configdialog.cpp - ** @author Roman Telezhynskyi - ** @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-2015 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" -#include -#include -#include -#include -#include -#include -#include "../core/vapplication.h" - -//--------------------------------------------------------------------------------------------------------------------- -ConfigDialog::ConfigDialog(QWidget *parent) : - QDialog(parent), contentsWidget(nullptr), pagesWidget(nullptr), configurationPage(nullptr), patternPage(nullptr), - pathPage(nullptr), applyButton(nullptr), cancelButton(nullptr), okButton(nullptr), - isInitialized(false) -{ - contentsWidget = new QListWidget; - contentsWidget->setViewMode(QListView::IconMode); - contentsWidget->setIconSize(QSize(96, 84)); - contentsWidget->setMovement(QListView::Static); - contentsWidget->setMaximumWidth(128); - contentsWidget->setMinimumWidth(128); - contentsWidget->setMinimumHeight(500); - contentsWidget->setSpacing(12); - - pagesWidget = new QStackedWidget; - - configurationPage = new ConfigurationPage(); - pagesWidget->addWidget(configurationPage); - - patternPage = new PatternPage(); - pagesWidget->addWidget(patternPage); - - pathPage = new PathPage(); - pagesWidget->addWidget(pathPage); - - applyButton = new QPushButton(tr("Apply")); - cancelButton = new QPushButton(tr("&Cancel")); - okButton = new QPushButton(tr("&Ok")); - - createIcons(); - contentsWidget->setCurrentRow(0); - - connect(cancelButton, &QPushButton::clicked, this, &ConfigDialog::close); - connect(applyButton, &QPushButton::clicked, this, &ConfigDialog::Apply); - connect(okButton, &QPushButton::clicked, this, &ConfigDialog::Ok); - - QHBoxLayout *horizontalLayout = new QHBoxLayout; - horizontalLayout->addWidget(contentsWidget); - horizontalLayout->addWidget(pagesWidget, 1); - - QHBoxLayout *buttonsLayout = new QHBoxLayout; - buttonsLayout->addStretch(1); - buttonsLayout->addWidget(applyButton); - buttonsLayout->addWidget(cancelButton); - buttonsLayout->addWidget(okButton); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout(horizontalLayout); - mainLayout->addSpacing(12); - mainLayout->addLayout(buttonsLayout); - mainLayout->setStretch(0, 1); - setLayout(mainLayout); - - setWindowTitle(tr("Config Dialog")); - - qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::closeEvent(QCloseEvent *event) -{ - if (result() == QDialog::Accepted) - { - done(QDialog::Accepted); - } - event->accept(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::changeEvent(QEvent *event) -{ - if (event->type() == QEvent::LanguageChange) - { - // retranslate designer form (single inheritance approach) - RetranslateUi(); - } - - // remember to call base class implementation - QDialog::changeEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::showEvent(QShowEvent *event) -{ - QDialog::showEvent( event ); - if ( event->spontaneous() ) - { - return; - } - - if (isInitialized) - { - return; - } - // do your init stuff here - - setMinimumSize(size()); - - QSize sz = qApp->Settings()->GetPreferenceDialogSize(); - if (sz.isEmpty() == false) - { - resize(sz); - } - - okButton->setFocus(); - - isInitialized = true;//first show windows are held -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event) - // remember the size for the next time this dialog is opened, but only - // if widget was already initialized, which rules out the resize at - // dialog creating, which would - if (isInitialized == true) - { - qApp->Settings()->SetPreferenceDialogSize(size()); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::createIcons() -{ - createIcon("://icon/config.png", tr("Configuration")); - createIcon("://icon/pattern_config.png", tr("Pattern")); - createIcon("://icon/path_config.png", tr("Paths")); - - connect(contentsWidget, &QListWidget::currentItemChanged, - RECEIVER(this)[this](QListWidgetItem *current, QListWidgetItem *previous) - { - if (current == nullptr) - { - current = previous; - } - pagesWidget->setCurrentIndex(contentsWidget->row(current)); - }); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::createIcon(const QString &icon, const QString &text) -{ - SCASSERT(contentsWidget != nullptr) - - QListWidgetItem *button = new QListWidgetItem(contentsWidget); - button->setIcon(QIcon(icon)); - button->setText(text); - button->setTextAlignment(Qt::AlignHCenter); - button->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::Apply() -{ - configurationPage->Apply(); - patternPage->Apply(); - pathPage->Apply(); - - qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); - emit UpdateProperties(); - setResult(QDialog::Accepted); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::Ok() -{ - Apply(); - done(QDialog::Accepted); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigDialog::RetranslateUi() -{ - applyButton->setText(tr("Apply")); - cancelButton->setText(tr("&Cancel")); - okButton->setText(tr("&Ok")); - setWindowTitle(tr("Config Dialog")); - contentsWidget->item(0)->setText(tr("Configuration")); - contentsWidget->item(1)->setText(tr("Pattern")); - contentsWidget->item(2)->setText(tr("Paths")); -} - diff --git a/src/app/valentina/dialogs/configpages/configurationpage.cpp b/src/app/valentina/dialogs/configpages/configurationpage.cpp deleted file mode 100644 index 0e19e9a41..000000000 --- a/src/app/valentina/dialogs/configpages/configurationpage.cpp +++ /dev/null @@ -1,496 +0,0 @@ -/************************************************************************ - ** - ** @file configurationpage.cpp - ** @author Roman Telezhynskyi - ** @date 21 6, 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-2015 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 "configurationpage.h" -#include "../../options.h" -#include "../../core/vapplication.h" -#include "../vmisc/vsettings.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -ConfigurationPage::ConfigurationPage(QWidget *parent) - : QWidget(parent), - autoSaveCheck(nullptr), - autoTime(nullptr), - langCombo(nullptr), - labelCombo(nullptr), - unitCombo(nullptr), - osOptionCheck(nullptr), - langChanged(false), - systemChanged(), - unitChanged(false), - labelLangChanged(false), - sendReportCheck(nullptr), - resetWarningsButton(nullptr), - toolBarStyleCheck(nullptr), - saveGroup(nullptr), - intervalLabel(nullptr), - langGroup(nullptr), - guiLabel(nullptr), - separatorLabel(nullptr), - unitLabel(nullptr), - languageLabel(nullptr), - pmSystemGroup(nullptr), - systemLabel(nullptr), - systemCombo(nullptr), - systemAuthorLabel(nullptr), - systemBookLabel(nullptr), - systemAuthorValueLabel(nullptr), - systemBookValueLabel(nullptr), - sendGroup(nullptr), - description(nullptr), - drawGroup(nullptr), - toolBarGroup(nullptr) -{ - QGroupBox *saveGroup = SaveGroup(); - QGroupBox *langGroup = LangGroup(); - QGroupBox *pmSystemGroup = PMSystemGroup(); - QGroupBox *sendGroup = SendGroup(); - QGroupBox *drawGroup = DrawGroup(); - QGroupBox *toolBarGroup = ToolBarGroup(); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(saveGroup); - mainLayout->addWidget(langGroup); - mainLayout->addWidget(pmSystemGroup); - mainLayout->addWidget(sendGroup); - mainLayout->addWidget(drawGroup); - mainLayout->addWidget(toolBarGroup); - mainLayout->addStretch(1); - setLayout(mainLayout); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::Apply() -{ - VSettings *settings = qApp->ValentinaSettings(); - settings->SetAutosaveState(autoSaveCheck->isChecked()); - settings->SetAutosaveTime(autoTime->value()); - - QTimer *autoSaveTimer = qApp->getAutoSaveTimer(); - SCASSERT(autoSaveTimer) - - autoSaveCheck->isChecked() ? autoSaveTimer->start(autoTime->value()*60000) : autoSaveTimer->stop(); - - settings->SetOsSeparator(osOptionCheck->isChecked()); - settings->SetSendReportState(sendReportCheck->isChecked()); - settings->SetToolBarStyle(toolBarStyleCheck->isChecked()); - - if (langChanged || systemChanged) - { - const QString locale = qvariant_cast(langCombo->itemData(langCombo->currentIndex())); - settings->SetLocale(locale); - langChanged = false; - - const QString code = qvariant_cast(systemCombo->itemData(systemCombo->currentIndex())); - settings->SetPMSystemCode(code); - systemChanged = false; - - qApp->LoadTranslation(locale); - } - if (this->unitChanged) - { - const QString unit = qvariant_cast(this->unitCombo->itemData(this->unitCombo->currentIndex())); - settings->SetUnit(unit); - this->unitChanged = false; - const QString text = tr("The Default unit has been updated and will be used as the default for the next " - "pattern you create."); - QMessageBox::information(this, QApplication::applicationName(), text); - } - if (labelLangChanged) - { - const QString locale = qvariant_cast(labelCombo->itemData(labelCombo->currentIndex())); - settings->SetLabelLanguage(locale); - labelLangChanged = false; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::LangChanged() -{ - langChanged = true; -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::UnitChanged() -{ - this->unitChanged = true; -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::LabelLangChanged() -{ - labelLangChanged = true; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *ConfigurationPage::SaveGroup() -{ - saveGroup = new QGroupBox(tr("Save")); - - autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern")); - autoSaveCheck->setChecked(qApp->ValentinaSettings()->GetAutosaveState()); - - autoTime = new QSpinBox(); - autoTime->setRange(1, 60); - autoTime->setValue(qApp->ValentinaSettings()->GetAutosaveTime()); - autoTime->setSuffix(tr("min")); - - QHBoxLayout *autosaveLayout = new QHBoxLayout; - autosaveLayout->addWidget(autoSaveCheck); - intervalLabel = new QLabel(tr("Interval:")); - autosaveLayout->addWidget(intervalLabel); - autosaveLayout->addWidget(autoTime); - - QVBoxLayout *saveLayout = new QVBoxLayout; - saveLayout->addLayout(autosaveLayout); - saveGroup->setLayout(saveLayout); - return saveGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *ConfigurationPage::LangGroup() -{ - langGroup = new QGroupBox(tr("Language")); - guiLabel = new QLabel(tr("GUI language:")); - langCombo = new QComboBox; - - QStringList fileNames; - QDirIterator it(qApp->translationsPath(), QStringList() << QStringList("valentina_*.qm"), QDir::Files, - QDirIterator::Subdirectories); - while (it.hasNext()) - { - it.next(); - fileNames.append(it.fileName()); - } - - bool englishUS = false; - const QString en_US = QStringLiteral("en_US"); - - for (int i = 0; i < fileNames.size(); ++i) - { - // get locale extracted by filename - QString locale; - locale = fileNames.at(i); // "valentina_de_De.qm" - locale.truncate(locale.lastIndexOf('.')); // "valentina_de_De" - locale.remove(0, locale.indexOf('_') + 1); // "de_De" - - if (not englishUS) - { - englishUS = (en_US == locale); - } - - QLocale loc = QLocale(locale); - QString lang = loc.nativeLanguageName(); - QIcon ico(QString("%1/%2.png").arg("://flags").arg(QLocale::countryToString(loc.country()))); - - langCombo->addItem(ico, lang, locale); - } - - if (langCombo->count() == 0 || not englishUS) - { - // English language is internal and doens't have own *.qm file. - QIcon ico(QString("%1/%2.png").arg("://flags").arg(QLocale::countryToString(QLocale::UnitedStates))); - QString lang = QLocale(en_US).nativeLanguageName(); - langCombo->addItem(ico, lang, en_US); - } - - // set default translators and language checked - const VSettings *settings = qApp->ValentinaSettings(); - qint32 index = langCombo->findData(settings->GetLocale()); - if (index != -1) - { - langCombo->setCurrentIndex(index); - } - connect(langCombo, static_cast(&QComboBox::currentIndexChanged), this, - &ConfigurationPage::LangChanged); - - QFormLayout *langLayout = new QFormLayout; - langLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - langLayout->addRow(guiLabel, langCombo); - - //-------------------- Decimal separator setup - separatorLabel = new QLabel(tr("Decimal separator parts:")); - osOptionCheck = new QCheckBox(tr("With OS options (%1)").arg(QLocale().decimalPoint())); - osOptionCheck->setChecked(settings->GetOsSeparator()); - langLayout->addRow(separatorLabel, osOptionCheck); - - //----------------------- Unit setup - this->unitCombo = new QComboBox; - this->unitCombo->addItem(tr("Centimeters"), "cm"); - this->unitCombo->addItem(tr("Millimiters"), "mm"); - this->unitCombo->addItem(tr("Inches"), "in"); - - // set default unit - const qint32 indexUnit = this->unitCombo->findData(settings->GetUnit()); - if (indexUnit != -1) - { - this->unitCombo->setCurrentIndex(indexUnit); - } - connect(this->unitCombo, static_cast(&QComboBox::currentIndexChanged), this, - &ConfigurationPage::UnitChanged); - - unitLabel = new QLabel(tr("Default unit:")); - langLayout->addRow(unitLabel, this->unitCombo); - - //----------------------- Label language - labelCombo = new QComboBox; - - SetLabelComboBox(VApplication::LabelLanguages()); - - index = labelCombo->findData(settings->GetLabelLanguage()); - if (index != -1) - { - labelCombo->setCurrentIndex(index); - } - connect(labelCombo, static_cast(&QComboBox::currentIndexChanged), this, - &ConfigurationPage::LabelLangChanged); - - languageLabel = new QLabel(tr("Label language:")); - langLayout->addRow(languageLabel, labelCombo); - - langGroup->setLayout(langLayout); - return langGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *ConfigurationPage::PMSystemGroup() -{ - pmSystemGroup = new QGroupBox(tr("Pattern making system")); - - systemLabel = new QLabel(tr("Pattern making system:")); - systemCombo = new QComboBox; - - InitPMSystems(systemCombo); - - QFormLayout *pmSystemLayout = new QFormLayout; - pmSystemLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - pmSystemLayout->addRow(systemLabel, systemCombo); - - //---- - systemAuthorLabel = new QLabel(tr("Author:")); - systemAuthorValueLabel = new QLabel(""); - - pmSystemLayout->addRow(systemAuthorLabel, systemAuthorValueLabel); - - //---- - systemBookLabel = new QLabel(tr("Book:")); - systemBookValueLabel = new QPlainTextEdit(""); - systemBookValueLabel->setReadOnly(true); - systemBookValueLabel->setFixedHeight(4 * QFontMetrics(systemBookValueLabel->font()).lineSpacing()); - - pmSystemLayout->addRow(systemBookLabel, systemBookValueLabel); - - connect(systemCombo, static_cast(&QComboBox::currentIndexChanged), this, - &ConfigurationPage::SystemChanged); - - // set default pattern making system - const VSettings *settings = qApp->ValentinaSettings(); - const int index = systemCombo->findData(settings->GetPMSystemCode()); - if (index != -1) - { - systemCombo->setCurrentIndex(index); - } - - pmSystemGroup->setLayout(pmSystemLayout); - return pmSystemGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *ConfigurationPage::SendGroup() -{ - sendGroup = new QGroupBox(tr("Send crash reports")); - - sendReportCheck = new QCheckBox(tr("Send crash reports (recommended)")); - sendReportCheck->setChecked(qApp->ValentinaSettings()->GetSendReportState()); - - description = new QLabel(tr("After each crash Valentina collects information that may help us fix the " - "problem. We do not collect any personal information. Find more about what %1" - "kind of information%2 we collect.") - .arg("") - .arg("")); - description->setTextFormat(Qt::RichText); - description->setTextInteractionFlags(Qt::TextBrowserInteraction); - description->setOpenExternalLinks(true); - description->setWordWrap(true); - - QVBoxLayout *sendLayout = new QVBoxLayout; - sendLayout->addWidget(sendReportCheck); - sendLayout->addWidget(description); - - sendGroup->setLayout(sendLayout); - return sendGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *ConfigurationPage::DrawGroup() -{ - drawGroup = new QGroupBox(tr("Pattern Editing")); - - resetWarningsButton = new QPushButton(tr("Reset warnings")); - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(resetWarningsButton->sizePolicy().hasHeightForWidth()); - resetWarningsButton->setSizePolicy(sizePolicy); - connect(resetWarningsButton, &QPushButton::released, this, &ConfigurationPage::ResetWarnings); - - QVBoxLayout *editLayout = new QVBoxLayout; - editLayout->addWidget(resetWarningsButton); - - drawGroup->setLayout(editLayout); - return drawGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *ConfigurationPage::ToolBarGroup() -{ - toolBarGroup = new QGroupBox(tr("Toolbar")); - - toolBarStyleCheck = new QCheckBox(tr("The text appears under the icon (recommended for beginners).")); - toolBarStyleCheck->setChecked(qApp->ValentinaSettings()->GetToolBarStyle()); - - QVBoxLayout *editLayout = new QVBoxLayout; - editLayout->addWidget(toolBarStyleCheck); - - toolBarGroup->setLayout(editLayout); - return toolBarGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::SystemChanged() -{ - systemChanged = true; - QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); - systemAuthorValueLabel->setText(text); - systemAuthorValueLabel->setToolTip(text); - - text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); - systemBookValueLabel->setPlainText(text); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::SetLabelComboBox(const QStringList &list) -{ - for (int i = 0; i < list.size(); ++i) - { - QLocale loc = QLocale(list.at(i)); - labelCombo->addItem(loc.nativeLanguageName(), list.at(i)); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::changeEvent(QEvent *event) -{ - if (event->type() == QEvent::LanguageChange) - { - // retranslate designer form (single inheritance approach) - RetranslateUi(); - } - // remember to call base class implementation - QWidget::changeEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::ResetWarnings() -{ - VSettings *settings = qApp->ValentinaSettings(); - - settings->SetConfirmItemDelete(true); - settings->SetConfirmFormatRewriting(true); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ConfigurationPage::RetranslateUi() -{ - toolBarStyleCheck->setText(tr("The text appears under the icon (recommended for beginners).")); - resetWarningsButton->setText(tr("Reset warnings")); - - saveGroup->setTitle(tr("Save")); - autoSaveCheck->setText(tr("Auto-save modified pattern")); - autoTime->setSuffix(tr("min")); - intervalLabel->setText(tr("Interval:")); - - langGroup->setTitle(tr("Language")); - guiLabel->setText(tr("GUI language:")); - - separatorLabel->setText(tr("Decimal separator parts:")); - osOptionCheck->setText(tr("With OS options (%1)").arg(QLocale().decimalPoint())); - - unitLabel->setText(tr("Default unit:")); - this->unitCombo->setItemText(0, tr("Centimeters")); - this->unitCombo->setItemText(1, tr("Millimiters")); - this->unitCombo->setItemText(2, tr("Inches")); - - languageLabel->setText(tr("Label language:")); - - pmSystemGroup->setTitle(tr("Pattern making system")); - systemLabel->setText(tr("Pattern making system:")); - - const int index = systemCombo->currentIndex(); - systemCombo->blockSignals(true); - systemCombo->clear(); - InitPMSystems(systemCombo); - systemCombo->setCurrentIndex(index); - systemCombo->blockSignals(false); - - systemAuthorLabel->setText(tr("Author:")); - systemBookLabel->setText(tr("Book:")); - - QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); - systemAuthorValueLabel->setText(text); - systemAuthorValueLabel->setToolTip(text); - - text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); - systemBookValueLabel->setPlainText(text); - - sendGroup->setTitle(tr("Send crash reports")); - sendReportCheck->setText(tr("Send crash reports (recommended)")); - description->setText(tr("After each crash Valentina collects information that may help us fix the " - "problem. We do not collect any personal information. Find more about what " - "kind of information we collect.")); - - drawGroup->setTitle(tr("Pattern Editing")); - resetWarningsButton->setText(tr("Confirm item deletion")); - toolBarGroup->setTitle(tr("Toolbar")); - toolBarStyleCheck->setText(tr("The text appears under the icon (recommended for beginners).")); -} diff --git a/src/app/valentina/dialogs/configpages/configurationpage.h b/src/app/valentina/dialogs/configpages/configurationpage.h deleted file mode 100644 index eda3aefe2..000000000 --- a/src/app/valentina/dialogs/configpages/configurationpage.h +++ /dev/null @@ -1,107 +0,0 @@ -/************************************************************************ - ** - ** @file configurationpage.h - ** @author Roman Telezhynskyi - ** @date 21 6, 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-2015 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 CONFIGURATIONPAGE_H -#define CONFIGURATIONPAGE_H - -#include -#include -#include -#include - -class QCheckBox; -class QSpinBox; -class QComboBox; -class QGroupBox; -class QLabel; - -class ConfigurationPage : public QWidget -{ - Q_OBJECT -public: - explicit ConfigurationPage(QWidget *parent = nullptr); - void Apply(); -public slots: - void LangChanged(); - void SystemChanged(); - void UnitChanged(); - void LabelLangChanged(); -protected: - virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; -private slots: - void ResetWarnings(); -private: - Q_DISABLE_COPY(ConfigurationPage) - QCheckBox *autoSaveCheck; - QSpinBox *autoTime; - QComboBox *langCombo; - QComboBox *labelCombo; - QComboBox *unitCombo; - QCheckBox *osOptionCheck; - bool langChanged; - bool systemChanged; - bool unitChanged; - bool labelLangChanged; - QCheckBox *sendReportCheck; - QPushButton *resetWarningsButton; - QCheckBox *toolBarStyleCheck; - - QGroupBox *saveGroup; - QLabel *intervalLabel; - QGroupBox *langGroup; - QLabel *guiLabel; - QLabel *separatorLabel; - QLabel *unitLabel; - QLabel *languageLabel; - - QGroupBox *pmSystemGroup; - QLabel *systemLabel; - QComboBox *systemCombo; - QLabel *systemAuthorLabel; - QLabel *systemBookLabel; - QLabel *systemAuthorValueLabel; - QPlainTextEdit *systemBookValueLabel; - - QGroupBox *sendGroup; - QLabel *description; - - QGroupBox *drawGroup; - QGroupBox *toolBarGroup; - - QGroupBox *SaveGroup() Q_REQUIRED_RESULT; - QGroupBox *LangGroup() Q_REQUIRED_RESULT; - QGroupBox *PMSystemGroup() Q_REQUIRED_RESULT; - QGroupBox *SendGroup() Q_REQUIRED_RESULT; - QGroupBox *DrawGroup() Q_REQUIRED_RESULT; - QGroupBox *ToolBarGroup() Q_REQUIRED_RESULT; - void SetLabelComboBox(const QStringList &list); - - void RetranslateUi(); -}; - -#endif // CONFIGURATIONPAGE_H diff --git a/src/app/valentina/dialogs/configpages/patternpage.cpp b/src/app/valentina/dialogs/configpages/patternpage.cpp deleted file mode 100644 index c9bae976a..000000000 --- a/src/app/valentina/dialogs/configpages/patternpage.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/************************************************************************ - ** - ** @file patternpage.cpp - ** @author Roman Telezhynskyi - ** @date 21 6, 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-2015 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 "patternpage.h" -#include "../../options.h" -#include "../../core/vapplication.h" -#include "../vmisc/vsettings.h" -#include "../vwidgets/vmaingraphicsview.h" -#include "../ifc/xml/vabstractpattern.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -PatternPage::PatternPage(QWidget *parent): - QWidget(parent), - userGroup(nullptr), - userName(nullptr), - userNameLabel(nullptr), - graphOutputGroup(nullptr), - graphOutputCheck(nullptr), - undoGroup(nullptr), - undoCount(nullptr), - countStepsLabel(nullptr), - userMaterialsGroup(nullptr), - userMaterialClearButton(nullptr), - workpieceGroup(nullptr), - forbidFlippingCheck(nullptr), - doublePassmarkCheck(nullptr) -{ - QGroupBox *userGroup = UserGroup(); - QGroupBox *graphOutputGroup = GraphOutputGroup(); - QGroupBox *undoGroup = UndoGroup(); - QGroupBox *userMatGroup = UserMaterialGroup(); - QGroupBox *workpieceGroup = UserWorkpieceGroup(); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(userGroup); - mainLayout->addWidget(graphOutputGroup); - mainLayout->addWidget(undoGroup); - mainLayout->addWidget(userMatGroup); - mainLayout->addWidget(workpieceGroup); - mainLayout->addStretch(1); - setLayout(mainLayout); -} - -//--------------------------------------------------------------------------------------------------------------------- -void PatternPage::Apply() -{ - VSettings *settings = qApp->ValentinaSettings(); - settings->SetUser(userName->text()); - - // Scene antialiasing - settings->SetGraphicalOutput(graphOutputCheck->isChecked()); - qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, graphOutputCheck->isChecked()); - qApp->getSceneView()->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputCheck->isChecked()); - - /* Maximum number of commands in undo stack may only be set when the undo stack is empty, since setting it on a - * non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack - * prints a warning and does nothing.*/ - settings->SetUndoCount(undoCount->value()); - - settings->SetForbidWorkpieceFlipping(forbidFlippingCheck->isChecked()); - - if (settings->IsDoublePassmark() != doublePassmarkCheck->isChecked()) - { - settings->SetDoublePassmark(doublePassmarkCheck->isChecked()); - qApp->getCurrentDocument()->LiteParseTree(Document::LiteParse); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void PatternPage::ClearUserDefinedMaterials() -{ - VSettings* pSet = qApp->ValentinaSettings(); - pSet->ClearUserDefinedMaterial(); - pSet->sync(); - QString qsMsg = tr("All user defined materials have been deleted!"); - QMessageBox::information(this, QApplication::applicationName(), qsMsg); -} - -//--------------------------------------------------------------------------------------------------------------------- -void PatternPage::changeEvent(QEvent *event) -{ - if (event->type() == QEvent::LanguageChange) - { - // retranslate designer form (single inheritance approach) - RetranslateUi(); - } - - // remember to call base class implementation - QWidget::changeEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *PatternPage::UserGroup() -{ - userGroup = new QGroupBox(tr("User")); - - userName = new QLineEdit; -#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) - userName->setClearButtonEnabled(true); -#endif - userName->setText(qApp->ValentinaSettings()->GetUser()); - - QFormLayout *nameLayout = new QFormLayout; - userNameLabel = new QLabel(tr("User name:")); - nameLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - nameLayout->addRow(userNameLabel, userName); - - QVBoxLayout *userLayout = new QVBoxLayout; - userLayout->addLayout(nameLayout); - userGroup->setLayout(userLayout); - return userGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *PatternPage::GraphOutputGroup() -{ - graphOutputGroup = new QGroupBox(tr("Graphical output")); - - graphOutputCheck = new QCheckBox(tr("Use antialiasing")); - graphOutputCheck->setChecked(qApp->ValentinaSettings()->GetGraphicalOutput()); - - QHBoxLayout *graphLayout = new QHBoxLayout; - graphLayout->addWidget(graphOutputCheck); - - QVBoxLayout *graphOutputLayout = new QVBoxLayout; - graphOutputLayout->addLayout(graphLayout); - graphOutputGroup->setLayout(graphOutputLayout); - return graphOutputGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *PatternPage::UndoGroup() -{ - undoGroup = new QGroupBox(tr("Undo")); - undoCount = new QSpinBox; - undoCount->setMinimum(0); - undoCount->setValue(qApp->ValentinaSettings()->GetUndoCount()); - - QFormLayout *countLayout = new QFormLayout; - countStepsLabel = new QLabel(tr("Count steps (0 - no limit):")); - countLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - countLayout->addRow(countStepsLabel, undoCount); - - QVBoxLayout *undoLayout = new QVBoxLayout; - undoLayout->addLayout(countLayout); - undoGroup->setLayout(undoLayout); - return undoGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *PatternPage::UserMaterialGroup() -{ - userMaterialsGroup = new QGroupBox(tr("User defined materials")); - userMaterialClearButton = new QPushButton(tr("Delete all")); - connect(userMaterialClearButton, &QPushButton::clicked, this, &PatternPage::ClearUserDefinedMaterials); - - QHBoxLayout* pLayout = new QHBoxLayout; - pLayout->addWidget(userMaterialClearButton); - pLayout->addStretch(1); - - userMaterialsGroup->setLayout(pLayout); - return userMaterialsGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *PatternPage::UserWorkpieceGroup() -{ - workpieceGroup = new QGroupBox(tr("Workpiece")); - - forbidFlippingCheck = new QCheckBox(tr("Forbid flipping")); - forbidFlippingCheck->setToolTip(tr("By default forbid flipping for all new created workpieces")); - forbidFlippingCheck->setChecked(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping()); - - doublePassmarkCheck = new QCheckBox(tr("Show second passmark on seam line")); - doublePassmarkCheck->setToolTip(tr("Show a passmark both in the seam allowance and on the seam line.")); - doublePassmarkCheck->setChecked(qApp->ValentinaSettings()->IsDoublePassmark()); - - QVBoxLayout *editLayout = new QVBoxLayout; - editLayout->addWidget(forbidFlippingCheck); - editLayout->addWidget(doublePassmarkCheck); - - workpieceGroup->setLayout(editLayout); - return workpieceGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -void PatternPage::RetranslateUi() -{ - userGroup->setTitle(tr("User")); - userNameLabel->setText(tr("User name:")); - - graphOutputGroup->setTitle(tr("Graphical output")); - graphOutputCheck->setText(tr("Use antialiasing")); - - undoGroup->setTitle(tr("Undo")); - countStepsLabel->setText(tr("Count steps (0 - no limit):")); - - userMaterialsGroup->setTitle(tr("User defined materials")); - userMaterialClearButton->setText(tr("Delete all")); - - workpieceGroup->setTitle(tr("Workpiece")); - forbidFlippingCheck->setText(tr("Forbid flipping")); - forbidFlippingCheck->setToolTip(tr("By default forbid flipping for all new created workpieces")); - doublePassmarkCheck->setText(tr("Show second passmark on seam line")); - doublePassmarkCheck->setToolTip(tr("Show a passmark both in the seam allowance and on the seam line.")); -} diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp new file mode 100644 index 000000000..03eae27e6 --- /dev/null +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -0,0 +1,268 @@ +/************************************************************************ + ** + ** @file preferencesconfigurationpage.cpp + ** @author Roman Telezhynskyi + ** @date 12 4, 2017 + ** + ** @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) 2017 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 "preferencesconfigurationpage.h" +#include "ui_preferencesconfigurationpage.h" +#include "../../core/vapplication.h" + +#include +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) + : QWidget(parent), + ui(new Ui::PreferencesConfigurationPage), + m_langChanged(false), + m_systemChanged(), + m_unitChanged(false), + m_labelLangChanged(false) +{ + ui->setupUi(this); + ui->autoSaveCheck->setChecked(qApp->ValentinaSettings()->GetAutosaveState()); + + InitLanguages(); + connect(ui->langCombo, static_cast(&QComboBox::currentIndexChanged), this, [this]() + { + m_langChanged = true; + }); + + //-------------------- Decimal separator setup + ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint())); + ui->osOptionCheck->setChecked(qApp->ValentinaSettings()->GetOsSeparator()); + + //----------------------- Unit setup + InitUnits(); + connect(ui->unitCombo, static_cast(&QComboBox::currentIndexChanged), this, [this]() + { + m_unitChanged = true; + }); + + //----------------------- Label language + SetLabelComboBox(VApplication::LabelLanguages()); + + int index = ui->labelCombo->findData(qApp->ValentinaSettings()->GetLabelLanguage()); + if (index != -1) + { + ui->labelCombo->setCurrentIndex(index); + } + connect(ui->labelCombo, static_cast(&QComboBox::currentIndexChanged), this, [this]() + { + m_labelLangChanged = true; + }); + + //---------------------- Pattern making system + InitPMSystems(ui->systemCombo); + ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing()); + connect(ui->systemCombo, static_cast(&QComboBox::currentIndexChanged), this, [this]() + { + m_systemChanged = true; + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(ui->systemCombo).toString()); + ui->systemAuthorValueLabel->setText(text); + ui->systemAuthorValueLabel->setToolTip(text); + + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(ui->systemCombo).toString()); + ui->systemBookValueLabel->setPlainText(text); + }); + + // set default pattern making system + index = ui->systemCombo->findData(qApp->ValentinaSettings()->GetPMSystemCode()); + if (index != -1) + { + ui->systemCombo->setCurrentIndex(index); + } + //---------------------- Send crash reports + ui->sendReportCheck->setChecked(qApp->ValentinaSettings()->GetSendReportState()); + ui->description = new QLabel(tr("After each crash Valentina collects information that may help us fix the " + "problem. We do not collect any personal information. Find more about what %1" + "kind of information%2 we collect.") + .arg("") + .arg("")); + + //----------------------------- Pattern Editing + connect(ui->resetWarningsButton, &QPushButton::released, []() + { + VSettings *settings = qApp->ValentinaSettings(); + + settings->SetConfirmItemDelete(true); + settings->SetConfirmFormatRewriting(true); + }); + + //----------------------- Toolbar + ui->toolBarStyleCheck->setChecked(qApp->ValentinaSettings()->GetToolBarStyle()); +} + +//--------------------------------------------------------------------------------------------------------------------- +PreferencesConfigurationPage::~PreferencesConfigurationPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesConfigurationPage::Apply() +{ + VSettings *settings = qApp->ValentinaSettings(); + settings->SetAutosaveState(ui->autoSaveCheck->isChecked()); + settings->SetAutosaveTime(ui->autoTime->value()); + + QTimer *autoSaveTimer = qApp->getAutoSaveTimer(); + SCASSERT(autoSaveTimer) + + ui->autoSaveCheck->isChecked() ? autoSaveTimer->start(ui->autoTime->value()*60000) : autoSaveTimer->stop(); + + settings->SetOsSeparator(ui->osOptionCheck->isChecked()); + settings->SetSendReportState(ui->sendReportCheck->isChecked()); + settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); + + if (m_langChanged || m_systemChanged) + { + const QString locale = qvariant_cast(ui->langCombo->currentData()); + settings->SetLocale(locale); + m_langChanged = false; + + const QString code = qvariant_cast(ui->systemCombo->currentData()); + settings->SetPMSystemCode(code); + m_systemChanged = false; + + qApp->LoadTranslation(locale); + } + if (m_unitChanged) + { + const QString unit = qvariant_cast(ui->unitCombo->currentData()); + settings->SetUnit(unit); + m_unitChanged = false; + const QString text = tr("The Default unit has been updated and will be used as the default for the next " + "pattern you create."); + QMessageBox::information(this, QApplication::applicationName(), text); + } + if (m_labelLangChanged) + { + const QString locale = qvariant_cast(ui->labelCombo->currentData()); + settings->SetLabelLanguage(locale); + m_labelLangChanged = false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesConfigurationPage::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + RetranslateUi(); + } + // remember to call base class implementation + QWidget::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesConfigurationPage::SetLabelComboBox(const QStringList &list) +{ + for (int i = 0; i < list.size(); ++i) + { + QLocale loc = QLocale(list.at(i)); + ui->labelCombo->addItem(loc.nativeLanguageName(), list.at(i)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesConfigurationPage::InitLanguages() +{ + QStringList fileNames; + QDirIterator it(qApp->translationsPath(), QStringList("valentina_*.qm"), QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) + { + it.next(); + fileNames.append(it.fileName()); + } + + bool englishUS = false; + const QString en_US = QStringLiteral("en_US"); + + for (int i = 0; i < fileNames.size(); ++i) + { + // get locale extracted by filename + QString locale; + locale = fileNames.at(i); // "valentina_de_De.qm" + locale.truncate(locale.lastIndexOf('.')); // "valentina_de_De" + locale.remove(0, locale.indexOf('_') + 1); // "de_De" + + if (not englishUS) + { + englishUS = (en_US == locale); + } + + QLocale loc = QLocale(locale); + QString lang = loc.nativeLanguageName(); + QIcon ico(QString("%1/%2.png").arg("://flags").arg(QLocale::countryToString(loc.country()))); + + ui->langCombo->addItem(ico, lang, locale); + } + + if (ui->langCombo->count() == 0 || not englishUS) + { + // English language is internal and doens't have own *.qm file. + QIcon ico(QString("%1/%2.png").arg("://flags").arg(QLocale::countryToString(QLocale::UnitedStates))); + QString lang = QLocale(en_US).nativeLanguageName(); + ui->langCombo->addItem(ico, lang, en_US); + } + + // set default translators and language checked + qint32 index = ui->langCombo->findData(qApp->ValentinaSettings()->GetLocale()); + if (index != -1) + { + ui->langCombo->setCurrentIndex(index); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesConfigurationPage::InitUnits() +{ + ui->unitCombo->addItem(tr("Centimeters"), "cm"); + ui->unitCombo->addItem(tr("Millimiters"), "mm"); + ui->unitCombo->addItem(tr("Inches"), "in"); + + // set default unit + const qint32 indexUnit = ui->unitCombo->findData(qApp->ValentinaSettings()->GetUnit()); + if (indexUnit != -1) + { + ui->unitCombo->setCurrentIndex(indexUnit); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesConfigurationPage::RetranslateUi() +{ + ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint())); + ui->description->setText(tr("After each crash Valentina collects information that may help us fix the " + "problem. We do not collect any personal information. Find more about what %1" + "kind of information%2 we collect.") + .arg("") + .arg("")); +} diff --git a/src/app/valentina/dialogs/configpages/patternpage.h b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h similarity index 51% rename from src/app/valentina/dialogs/configpages/patternpage.h rename to src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h index 43e2fd793..d24abd22f 100644 --- a/src/app/valentina/dialogs/configpages/patternpage.h +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file patternpage.h + ** @file preferencesconfigurationpage.h ** @author Roman Telezhynskyi - ** @date 21 6, 2014 + ** @date 12 4, 2017 ** ** @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-2015 Valentina project + ** Copyright (C) 2017 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,52 +26,41 @@ ** *************************************************************************/ -#ifndef PATTERNPAGE_H -#define PATTERNPAGE_H +#ifndef PREFERENCESCONFIGURATIONPAGE_H +#define PREFERENCESCONFIGURATIONPAGE_H -#include #include -class QCheckBox; -class QSpinBox; -class QGroupBox; -class QLineEdit; -class QLabel; -class QPushButton; +namespace Ui +{ + class PreferencesConfigurationPage; +} -class PatternPage : public QWidget +class PreferencesConfigurationPage : public QWidget { Q_OBJECT + public: - explicit PatternPage(QWidget *parent = nullptr); - void Apply(); -public slots: - void ClearUserDefinedMaterials(); + explicit PreferencesConfigurationPage(QWidget *parent = nullptr); + virtual ~PreferencesConfigurationPage(); + + void Apply(); protected: virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; private: - Q_DISABLE_COPY(PatternPage) - QGroupBox *userGroup; - QLineEdit *userName; - QLabel *userNameLabel; - QGroupBox *graphOutputGroup; - QCheckBox *graphOutputCheck; - QGroupBox *undoGroup; - QSpinBox *undoCount; - QLabel *countStepsLabel; - QGroupBox *userMaterialsGroup; - QPushButton* userMaterialClearButton; - QGroupBox *workpieceGroup; - QCheckBox *forbidFlippingCheck; - QCheckBox *doublePassmarkCheck; + Q_DISABLE_COPY(PreferencesConfigurationPage) + Ui::PreferencesConfigurationPage *ui; + bool m_langChanged; + bool m_systemChanged; + bool m_unitChanged; + bool m_labelLangChanged; - QGroupBox *UserGroup() Q_REQUIRED_RESULT; - QGroupBox *GraphOutputGroup() Q_REQUIRED_RESULT; - QGroupBox *UndoGroup() Q_REQUIRED_RESULT; - QGroupBox *UserMaterialGroup() Q_REQUIRED_RESULT; - QGroupBox *UserWorkpieceGroup() Q_REQUIRED_RESULT; + void SetLabelComboBox(const QStringList &list); - void RetranslateUi(); + void InitLanguages(); + void InitUnits(); + + void RetranslateUi(); }; -#endif // PATTERNPAGE_H +#endif // PREFERENCESCONFIGURATIONPAGE_H diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui new file mode 100644 index 000000000..902a70929 --- /dev/null +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui @@ -0,0 +1,267 @@ + + + PreferencesConfigurationPage + + + + 0 + 0 + 501 + 640 + + + + Configuration + + + + + + Save + + + + + + Auto-save modified pattern + + + true + + + + + + + Interval: + + + + + + + + 0 + 0 + + + + min + + + 1 + + + 60 + + + + + + + + + + Language + + + + QFormLayout::ExpandingFieldsGrow + + + + + GUI language: + + + + + + + + + + Decimal separator parts: + + + + + + + < With OS options > + + + true + + + + + + + Default unit: + + + + + + + Label language: + + + + + + + + + + + + + + + + Pattern making system + + + + QFormLayout::ExpandingFieldsGrow + + + + + Pattern making system: + + + + + + + + + + Author: + + + + + + + author + + + + + + + Book: + + + + + + + true + + + + + + + + + + Send crash reports + + + + + + Send crash reports (recommended) + + + true + + + + + + + TextLabel + + + Qt::RichText + + + true + + + true + + + Qt::TextBrowserInteraction + + + + + + + + + + Pattern editing + + + + + + + 0 + 0 + + + + Reset warnings + + + + + + + + + + Toolbar + + + + + + The text appears under the icon (recommended for beginners). + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/app/valentina/dialogs/configpages/pathpage.cpp b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp similarity index 51% rename from src/app/valentina/dialogs/configpages/pathpage.cpp rename to src/app/valentina/dialogs/configpages/preferencespathpage.cpp index 95f4db0c8..14bd768a4 100644 --- a/src/app/valentina/dialogs/configpages/pathpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file pathpage.cpp + ** @file preferencespathpage.cpp ** @author Roman Telezhynskyi - ** @date 21 6, 2014 + ** @date 12 4, 2017 ** ** @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-2015 Valentina project + ** Copyright (C) 2017 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,55 +26,45 @@ ** *************************************************************************/ -#include "pathpage.h" +#include "preferencespathpage.h" +#include "ui_preferencespathpage.h" +#include "../vmisc/vsettings.h" #include "../../options.h" #include "../../core/vapplication.h" -#include "../vmisc/vsettings.h" + #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include //--------------------------------------------------------------------------------------------------------------------- -PathPage::PathPage(QWidget *parent) - : QWidget(parent), defaultButton(nullptr), editButton(nullptr), pathTable(nullptr), pathGroup(nullptr) +PreferencesPathPage::PreferencesPathPage(QWidget *parent) + : QWidget(parent), + ui(new Ui::PreferencesPathPage) { - QGroupBox *pathGroup = PathGroup(); - SCASSERT(pathGroup != nullptr) + ui->setupUi(this); - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(pathGroup); - mainLayout->addStretch(1); - setLayout(mainLayout); + InitTable(); + + connect(ui->defaultButton, &QPushButton::clicked, this, &PreferencesPathPage::DefaultPath); + connect(ui->editButton, &QPushButton::clicked, this, &PreferencesPathPage::EditPath); } //--------------------------------------------------------------------------------------------------------------------- -void PathPage::Apply() +PreferencesPathPage::~PreferencesPathPage() { - VSettings *settings = qApp->ValentinaSettings(); - settings->SetPathIndividualMeasurements(pathTable->item(0, 1)->text()); - settings->SetPathStandardMeasurements(pathTable->item(1, 1)->text()); - settings->SetPathPattern(pathTable->item(2, 1)->text()); - settings->SetPathLayout(pathTable->item(3, 1)->text()); - settings->SetPathTemplate(pathTable->item(4, 1)->text()); + delete ui; } //--------------------------------------------------------------------------------------------------------------------- -void PathPage::DefaultPath() +void PreferencesPathPage::Apply() { - const int row = pathTable->currentRow(); - QTableWidgetItem *item = pathTable->item(row, 1); + +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesPathPage::DefaultPath() +{ + const int row = ui->pathTable->currentRow(); + QTableWidgetItem *item = ui->pathTable->item(row, 1); SCASSERT(item != nullptr) QString path; @@ -105,10 +95,10 @@ void PathPage::DefaultPath() } //--------------------------------------------------------------------------------------------------------------------- -void PathPage::EditPath() +void PreferencesPathPage::EditPath() { - const int row = pathTable->currentRow(); - QTableWidgetItem *item = pathTable->item(row, 1); + const int row = ui->pathTable->currentRow(); + QTableWidgetItem *item = ui->pathTable->item(row, 1); SCASSERT(item != nullptr) QString path; @@ -165,123 +155,58 @@ void PathPage::EditPath() } //--------------------------------------------------------------------------------------------------------------------- -void PathPage::changeEvent(QEvent *event) +void PreferencesPathPage::InitTable() { - if (event->type() == QEvent::LanguageChange) - { - // retranslate designer form (single inheritance approach) - RetranslateUi(); - } + ui->pathTable->setRowCount(5); + ui->pathTable->setColumnCount(2); - // remember to call base class implementation - QWidget::changeEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *PathPage::PathGroup() -{ - pathGroup = new QGroupBox(tr("Path that use Valentina")); - InitTable(); - - defaultButton = new QPushButton(tr("Default")); - defaultButton->setEnabled(false); - connect(defaultButton, &QPushButton::clicked, this, &PathPage::DefaultPath); - - editButton = new QPushButton(tr("Edit")); - editButton->setEnabled(false); - connect(editButton, &QPushButton::clicked, this, &PathPage::EditPath); - - QHBoxLayout *buttonsLayout = new QHBoxLayout; - buttonsLayout->addWidget(defaultButton); - buttonsLayout->addWidget(editButton); - - QVBoxLayout *pathLayout = new QVBoxLayout; - pathLayout->addWidget(pathTable); - pathLayout->addLayout(buttonsLayout); - - pathGroup->setLayout(pathLayout); - return pathGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -void PathPage::InitTable() -{ - pathTable = new QTableWidget(); - pathTable->setRowCount(5); - pathTable->setColumnCount(2); - pathTable->verticalHeader()->setVisible(false); - pathTable->setEditTriggers(QAbstractItemView::NoEditTriggers); - pathTable->setSelectionBehavior(QAbstractItemView::SelectRows); - pathTable->setSelectionMode(QAbstractItemView::SingleSelection); - pathTable->setShowGrid(false); - - QStringList tableHeader = QStringList() << tr("Type") << tr("Path"); - pathTable->setHorizontalHeaderLabels(tableHeader); const VSettings *settings = qApp->ValentinaSettings(); { - pathTable->setItem(0, 0, new QTableWidgetItem(tr("My Individual Measurements"))); + ui->pathTable->setItem(0, 0, new QTableWidgetItem(tr("My Individual Measurements"))); QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathIndividualMeasurements()); item->setToolTip(settings->GetPathIndividualMeasurements()); - pathTable->setItem(0, 1, item); + ui->pathTable->setItem(0, 1, item); } { - pathTable->setItem(1, 0, new QTableWidgetItem(tr("My Multisize Measurements"))); + ui->pathTable->setItem(1, 0, new QTableWidgetItem(tr("My Multisize Measurements"))); QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathStandardMeasurements()); item->setToolTip(settings->GetPathStandardMeasurements()); - pathTable->setItem(1, 1, item); + ui->pathTable->setItem(1, 1, item); } { - pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Patterns"))); + ui->pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Patterns"))); QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathPattern()); item->setToolTip(settings->GetPathPattern()); - pathTable->setItem(2, 1, item); + ui->pathTable->setItem(2, 1, item); } { - pathTable->setItem(3, 0, new QTableWidgetItem(tr("My Layouts"))); + ui->pathTable->setItem(3, 0, new QTableWidgetItem(tr("My Layouts"))); QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathLayout()); item->setToolTip(settings->GetPathLayout()); - pathTable->setItem(3, 1, item); + ui->pathTable->setItem(3, 1, item); } { - pathTable->setItem(4, 0, new QTableWidgetItem(tr("My Templates"))); + ui->pathTable->setItem(4, 0, new QTableWidgetItem(tr("My Templates"))); QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathTemplate()); item->setToolTip(settings->GetPathTemplate()); - pathTable->setItem(4, 1, item); + ui->pathTable->setItem(4, 1, item); } - pathTable->verticalHeader()->setDefaultSectionSize(20); - pathTable->resizeColumnsToContents(); - pathTable->resizeRowsToContents(); - pathTable->horizontalHeader()->setStretchLastSection(true); + ui->pathTable->verticalHeader()->setDefaultSectionSize(20); + ui->pathTable->resizeColumnsToContents(); + ui->pathTable->resizeRowsToContents(); - connect(pathTable, &QTableWidget::itemSelectionChanged, RECEIVER(this)[this]() + connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]() { - defaultButton->setEnabled(true); - defaultButton->setDefault(false); + ui->defaultButton->setEnabled(true); + ui->defaultButton->setDefault(false); - editButton->setEnabled(true); - editButton->setDefault(true); + ui->editButton->setEnabled(true); + ui->editButton->setDefault(true); }); } - -//--------------------------------------------------------------------------------------------------------------------- -void PathPage::RetranslateUi() -{ - pathGroup->setTitle(tr("Path that use Valentina")); - defaultButton->setText(tr("Default")); - editButton->setText(tr("Edit")); - - const QStringList tableHeader = QStringList() << tr("Type") << tr("Path"); - pathTable->setHorizontalHeaderLabels(tableHeader); - - pathTable->item(0, 0)->setText(tr("My Individual Measurements")); - pathTable->item(1, 0)->setText(tr("My Multisize Measurements")); - pathTable->item(2, 0)->setText(tr("My Patterns")); - pathTable->item(3, 0)->setText(tr("My Layouts")); - pathTable->item(4, 0)->setText(tr("My Templates")); -} diff --git a/src/app/valentina/dialogs/configpages/pathpage.h b/src/app/valentina/dialogs/configpages/preferencespathpage.h similarity index 64% rename from src/app/valentina/dialogs/configpages/pathpage.h rename to src/app/valentina/dialogs/configpages/preferencespathpage.h index 9bcedd9e5..3235d10ec 100644 --- a/src/app/valentina/dialogs/configpages/pathpage.h +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file pathpage.h + ** @file preferencespathpage.h ** @author Roman Telezhynskyi - ** @date 21 6, 2014 + ** @date 12 4, 2017 ** ** @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-2015 Valentina project + ** Copyright (C) 2017 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,37 +26,35 @@ ** *************************************************************************/ -#ifndef PATHPAGE_H -#define PATHPAGE_H +#ifndef PREFERENCESPATHPAGE_H +#define PREFERENCESPATHPAGE_H -#include #include -class QGroupBox; -class QPushButton; -class QTableWidget; +namespace Ui +{ + class PreferencesPathPage; +} -class PathPage : public QWidget +class PreferencesPathPage : public QWidget { Q_OBJECT + public: - explicit PathPage(QWidget *parent = nullptr); - void Apply(); -protected: - virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; + explicit PreferencesPathPage(QWidget *parent = nullptr); + virtual ~PreferencesPathPage(); + + void Apply(); + private slots: void DefaultPath(); void EditPath(); -private: - Q_DISABLE_COPY(PathPage) - QPushButton *defaultButton; - QPushButton *editButton; - QTableWidget *pathTable; - QGroupBox *pathGroup; - QGroupBox *PathGroup() Q_REQUIRED_RESULT; - void InitTable(); - void RetranslateUi(); +private: + Q_DISABLE_COPY(PreferencesPathPage) + Ui::PreferencesPathPage *ui; + + void InitTable(); }; -#endif // PATHPAGE_H +#endif // PREFERENCESPATHPAGE_H diff --git a/src/app/valentina/dialogs/configpages/preferencespathpage.ui b/src/app/valentina/dialogs/configpages/preferencespathpage.ui new file mode 100644 index 000000000..afdae08a3 --- /dev/null +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.ui @@ -0,0 +1,111 @@ + + + PreferencesPathPage + + + + 0 + 0 + 422 + 295 + + + + Path + + + + + + Paths that Valentina uses + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + true + + + false + + + + Type + + + + + Path + + + + + + + + + + + + + false + + + + 0 + 0 + + + + Default + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + + 0 + 0 + + + + Edit + + + + + + + + + + diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp new file mode 100644 index 000000000..7973ec4b1 --- /dev/null +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file preferencespatternpage.cpp + ** @author Roman Telezhynskyi + ** @date 12 4, 2017 + ** + ** @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) 2017 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 "preferencespatternpage.h" +#include "ui_preferencespatternpage.h" +#include "../../core/vapplication.h" +#include "../ifc/xml/vabstractpattern.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) + : QWidget(parent), + ui(new Ui::PreferencesPatternPage) +{ + ui->setupUi(this); + ui->userName->setText(qApp->ValentinaSettings()->GetUser()); + ui->graphOutputCheck->setChecked(qApp->ValentinaSettings()->GetGraphicalOutput()); + ui->undoCount->setValue(qApp->ValentinaSettings()->GetUndoCount()); + + connect(ui->userMaterialClearButton, &QPushButton::clicked, this, [this]() + { + VSettings* pSet = qApp->ValentinaSettings(); + pSet->ClearUserDefinedMaterial(); + pSet->sync(); + QString qsMsg = tr("All user defined materials have been deleted!"); + QMessageBox::information(this, QApplication::applicationName(), qsMsg); + }); + + ui->forbidFlippingCheck->setChecked(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping()); + ui->doublePassmarkCheck->setChecked(qApp->ValentinaSettings()->IsDoublePassmark()); +} + +//--------------------------------------------------------------------------------------------------------------------- +PreferencesPatternPage::~PreferencesPatternPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesPatternPage::Apply() +{ + VSettings *settings = qApp->ValentinaSettings(); + settings->SetUser(ui->userName->text()); + + // Scene antialiasing + settings->SetGraphicalOutput(ui->graphOutputCheck->isChecked()); + qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, ui->graphOutputCheck->isChecked()); + qApp->getSceneView()->setRenderHint(QPainter::SmoothPixmapTransform, ui->graphOutputCheck->isChecked()); + + /* Maximum number of commands in undo stack may only be set when the undo stack is empty, since setting it on a + * non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack + * prints a warning and does nothing.*/ + settings->SetUndoCount(ui->undoCount->value()); + + settings->SetForbidWorkpieceFlipping(ui->forbidFlippingCheck->isChecked()); + + if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked()) + { + settings->SetDoublePassmark(ui->doublePassmarkCheck->isChecked()); + qApp->getCurrentDocument()->LiteParseTree(Document::LiteParse); + } +} diff --git a/src/app/valentina/dialogs/configpages/pages.h b/src/app/valentina/dialogs/configpages/preferencespatternpage.h similarity index 66% rename from src/app/valentina/dialogs/configpages/pages.h rename to src/app/valentina/dialogs/configpages/preferencespatternpage.h index 5ec82a7c3..a09cd6186 100644 --- a/src/app/valentina/dialogs/configpages/pages.h +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file pages.h + ** @file preferencespatternpage.h ** @author Roman Telezhynskyi - ** @date 12 2, 2014 + ** @date 12 4, 2017 ** ** @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-2015 Valentina project + ** Copyright (C) 2017 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,11 +26,29 @@ ** *************************************************************************/ -#ifndef PAGES_H -#define PAGES_H +#ifndef PREFERENCESPATTERNPAGE_H +#define PREFERENCESPATTERNPAGE_H -#include "configurationpage.h" -#include "patternpage.h" -#include "pathpage.h" +#include -#endif // PAGES_H +namespace Ui +{ + class PreferencesPatternPage; +} + +class PreferencesPatternPage : public QWidget +{ + Q_OBJECT + +public: + explicit PreferencesPatternPage(QWidget *parent = nullptr); + virtual ~PreferencesPatternPage(); + + void Apply(); + +private: + Q_DISABLE_COPY(PreferencesPatternPage) + Ui::PreferencesPatternPage *ui; +}; + +#endif // PREFERENCESPATTERNPAGE_H diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.ui b/src/app/valentina/dialogs/configpages/preferencespatternpage.ui new file mode 100644 index 000000000..5a8c4a167 --- /dev/null +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.ui @@ -0,0 +1,146 @@ + + + PreferencesPatternPage + + + + 0 + 0 + 327 + 414 + + + + Pattern + + + + + + User + + + + + + User name: + + + + + + + true + + + + + + + + + + Graphical output + + + + + + Use antialiasing + + + + + + + + + + Undo + + + + QFormLayout::ExpandingFieldsGrow + + + + + Count steps (0 - no limit): + + + + + + + + + + + + + User defined materials + + + + + + + 0 + 0 + + + + Delete all + + + + + + + + + + Workpiece + + + + + + By default forbid flipping for all new created workpieces" + + + Forbid flipping + + + + + + + Show a passmark both in the seam allowance and on the seam line. + + + Show second passmark on seam line + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/app/valentina/dialogs/dialogpreferences.cpp b/src/app/valentina/dialogs/dialogpreferences.cpp new file mode 100644 index 000000000..170b4b736 --- /dev/null +++ b/src/app/valentina/dialogs/dialogpreferences.cpp @@ -0,0 +1,139 @@ +/************************************************************************ + ** + ** @file dialogpreferences.cpp + ** @author Roman Telezhynskyi + ** @date 12 4, 2017 + ** + ** @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) 2017 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 "dialogpreferences.h" +#include "ui_dialogpreferences.h" +#include "../core/vapplication.h" +#include "configpages/preferencesconfigurationpage.h" +#include "configpages/preferencespatternpage.h" +#include "configpages/preferencespathpage.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogPreferences::DialogPreferences(QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogPreferences), + m_isInitialized(false), + m_configurePage(new PreferencesConfigurationPage), + m_patternPage(new PreferencesPatternPage), + m_pathPage(new PreferencesPathPage) +{ + ui->setupUi(this); + qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + SCASSERT(bOk != nullptr) + connect(bOk, &QPushButton::clicked, this, &DialogPreferences::Ok); + + QPushButton *bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + SCASSERT(bApply != nullptr) + connect(bApply, &QPushButton::clicked, this, &DialogPreferences::Apply); + + ui->pagesWidget->insertWidget(0, m_configurePage); + ui->pagesWidget->insertWidget(1, m_patternPage); + ui->pagesWidget->insertWidget(2, m_pathPage); + + connect(ui->contentsWidget, &QListWidget::currentItemChanged, this, &DialogPreferences::PageChanged); + ui->pagesWidget->setCurrentIndex(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPreferences::~DialogPreferences() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPreferences::showEvent(QShowEvent *event) +{ + QDialog::showEvent( event ); + if ( event->spontaneous() ) + { + return; + } + + if (m_isInitialized) + { + return; + } + // do your init stuff here + + setMinimumSize(size()); + + QSize sz = qApp->Settings()->GetPreferenceDialogSize(); + if (sz.isEmpty() == false) + { + resize(sz); + } + + m_isInitialized = true;//first show windows are held +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPreferences::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) + // remember the size for the next time this dialog is opened, but only + // if widget was already initialized, which rules out the resize at + // dialog creating, which would + if (m_isInitialized) + { + qApp->Settings()->SetPreferenceDialogSize(size()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPreferences::PageChanged(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (current == nullptr) + { + current = previous; + } + int rowIndex = ui->contentsWidget->row(current); + ui->pagesWidget->setCurrentIndex(rowIndex); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPreferences::Apply() +{ + m_configurePage->Apply(); + m_patternPage->Apply(); + m_pathPage->Apply(); + + qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + emit UpdateProperties(); + setResult(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPreferences::Ok() +{ + Apply(); + done(QDialog::Accepted); +} diff --git a/src/app/valentina/dialogs/configdialog.h b/src/app/valentina/dialogs/dialogpreferences.h similarity index 57% rename from src/app/valentina/dialogs/configdialog.h rename to src/app/valentina/dialogs/dialogpreferences.h index 836ccb7bc..099fde45f 100644 --- a/src/app/valentina/dialogs/configdialog.h +++ b/src/app/valentina/dialogs/dialogpreferences.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file configdialog.h + ** @file dialogpreferences.h ** @author Roman Telezhynskyi - ** @date 12 2, 2014 + ** @date 12 4, 2017 ** ** @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-2015 Valentina project + ** Copyright (C) 2017 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,45 +26,45 @@ ** *************************************************************************/ -#ifndef CONFIGDIALOG_H -#define CONFIGDIALOG_H +#ifndef DIALOGPREFERENCES_H +#define DIALOGPREFERENCES_H #include -#include "configpages/pages.h" +namespace Ui +{ + class DialogPreferences; +} + +class PreferencesConfigurationPage; +class PreferencesPatternPage; +class PreferencesPathPage; class QListWidgetItem; -class QStackedWidget; -class QListWidget; -class ConfigDialog : public QDialog +class DialogPreferences : public QDialog { Q_OBJECT + public: - explicit ConfigDialog(QWidget *parent = nullptr); + explicit DialogPreferences(QWidget *parent = nullptr); + virtual ~DialogPreferences(); signals: void UpdateProperties(); protected: - virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; - virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; +private slots: + void PageChanged(QListWidgetItem *current, QListWidgetItem *previous); private: - Q_DISABLE_COPY(ConfigDialog) - QListWidget *contentsWidget; - QStackedWidget *pagesWidget; - ConfigurationPage *configurationPage; - PatternPage *patternPage; - PathPage *pathPage; - QPushButton *applyButton; - QPushButton *cancelButton; - QPushButton *okButton; - bool isInitialized; - void createIcons(); - void createIcon(const QString &icon, const QString &text); - void Apply(); - void Ok(); + Q_DISABLE_COPY(DialogPreferences) + Ui::DialogPreferences *ui; + bool m_isInitialized; + PreferencesConfigurationPage *m_configurePage; + PreferencesPatternPage *m_patternPage; + PreferencesPathPage *m_pathPage; - void RetranslateUi(); + void Apply(); + void Ok(); }; -#endif // CONFIGDIALOG_H +#endif // DIALOGPREFERENCES_H diff --git a/src/app/valentina/dialogs/dialogpreferences.ui b/src/app/valentina/dialogs/dialogpreferences.ui new file mode 100644 index 000000000..55a7fb711 --- /dev/null +++ b/src/app/valentina/dialogs/dialogpreferences.ui @@ -0,0 +1,157 @@ + + + DialogPreferences + + + + 0 + 0 + 712 + 522 + + + + Preferences + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + 128 + 0 + + + + + 128 + 16777215 + + + + + 96 + 84 + + + + Qt::ElideMiddle + + + QListView::Static + + + 12 + + + QListView::IconMode + + + 0 + + + + Configuration + + + AlignCenter + + + + :/icon/config.png:/icon/config.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Pattern + + + AlignCenter + + + + :/icon/pattern_config.png:/icon/pattern_config.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Paths + + + AlignCenter + + + + :/icon/path_config.png:/icon/path_config.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + rejected() + DialogPreferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/valentina/dialogs/dialogs.h b/src/app/valentina/dialogs/dialogs.h index 921c82404..5ab889460 100644 --- a/src/app/valentina/dialogs/dialogs.h +++ b/src/app/valentina/dialogs/dialogs.h @@ -31,9 +31,9 @@ #include "dialoghistory.h" #include "dialogincrements.h" -#include "configdialog.h" #include "dialogpatternproperties.h" #include "dialognewpattern.h" #include "dialogaboutapp.h" +#include "dialogpreferences.h" #endif // DIALOGS_H diff --git a/src/app/valentina/dialogs/dialogs.pri b/src/app/valentina/dialogs/dialogs.pri index 9fef62f74..8599a928e 100644 --- a/src/app/valentina/dialogs/dialogs.pri +++ b/src/app/valentina/dialogs/dialogs.pri @@ -5,35 +5,34 @@ HEADERS += \ $$PWD/dialogs.h \ $$PWD/dialogincrements.h \ $$PWD/dialoghistory.h \ - $$PWD/configdialog.h \ - $$PWD/configpages/pages.h \ $$PWD/dialogpatternproperties.h \ $$PWD/dialognewpattern.h \ $$PWD/dialogaboutapp.h \ - $$PWD/configpages/configurationpage.h \ - $$PWD/configpages/patternpage.h \ - $$PWD/configpages/pathpage.h \ $$PWD/dialoglayoutsettings.h \ $$PWD/dialoglayoutprogress.h \ $$PWD/dialogsavelayout.h \ $$PWD/vwidgetgroups.h \ - $$PWD/vwidgetdetails.h + $$PWD/vwidgetdetails.h \ + $$PWD/dialogpreferences.h \ + $$PWD/configpages/preferencesconfigurationpage.h \ + $$PWD/configpages/preferencespatternpage.h \ + $$PWD/configpages/preferencespathpage.h SOURCES += \ $$PWD/dialogincrements.cpp \ $$PWD/dialoghistory.cpp \ - $$PWD/configdialog.cpp \ $$PWD/dialogpatternproperties.cpp \ $$PWD/dialognewpattern.cpp \ $$PWD/dialogaboutapp.cpp \ - $$PWD/configpages/configurationpage.cpp \ - $$PWD/configpages/patternpage.cpp \ - $$PWD/configpages/pathpage.cpp \ $$PWD/dialoglayoutsettings.cpp \ $$PWD/dialoglayoutprogress.cpp \ $$PWD/dialogsavelayout.cpp \ $$PWD/vwidgetgroups.cpp \ - $$PWD/vwidgetdetails.cpp + $$PWD/vwidgetdetails.cpp \ + $$PWD/dialogpreferences.cpp \ + $$PWD/configpages/preferencesconfigurationpage.cpp \ + $$PWD/configpages/preferencespatternpage.cpp \ + $$PWD/configpages/preferencespathpage.cpp FORMS += \ $$PWD/dialogincrements.ui \ @@ -45,4 +44,8 @@ FORMS += \ $$PWD/dialoglayoutprogress.ui \ $$PWD/dialogsavelayout.ui \ $$PWD/vwidgetgroups.ui \ - $$PWD/vwidgetdetails.ui + $$PWD/vwidgetdetails.ui \ + $$PWD/dialogpreferences.ui \ + $$PWD/configpages/preferencesconfigurationpage.ui \ + $$PWD/configpages/preferencespatternpage.ui \ + $$PWD/configpages/preferencespathpage.ui diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index dbc7c8e52..e3b5550b8 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4265,16 +4265,17 @@ void MainWindow::ShowPaper(int index) void MainWindow::Preferences() { // Calling constructor of the dialog take some time. Because of this user have time to call the dialog twice. - static QPointer guard;// Prevent any second run + static QPointer guard;// Prevent any second run if (guard.isNull()) { - ConfigDialog *config = new ConfigDialog(this); + DialogPreferences *preferences = new DialogPreferences(this); // QScopedPointer needs to be sure any exception will never block guard - QScopedPointer dlg(config); - guard = config; - connect(dlg.data(), &ConfigDialog::UpdateProperties, this, &MainWindow::WindowsLocale); // Must be first - connect(dlg.data(), &ConfigDialog::UpdateProperties, toolOptions, &VToolOptionsPropertyBrowser::RefreshOptions); - connect(dlg.data(), &ConfigDialog::UpdateProperties, this, &MainWindow::ToolBarStyles); + QScopedPointer dlg(preferences); + guard = preferences; + connect(dlg.data(), &DialogPreferences::UpdateProperties, this, &MainWindow::WindowsLocale); // Must be first + connect(dlg.data(), &DialogPreferences::UpdateProperties, toolOptions, + &VToolOptionsPropertyBrowser::RefreshOptions); + connect(dlg.data(), &DialogPreferences::UpdateProperties, this, &MainWindow::ToolBarStyles); if (guard->exec() == QDialog::Accepted) {