From cade111206188d5bdd0268b433be3acfda5c69fe Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 12 Apr 2017 15:50:48 +0300 Subject: [PATCH] Refactoring Tape's preferences dialog. Instead of manual declaring used Qt Designer. --HG-- branch : release --- .../configpages/tapeconfigurationpage.cpp | 341 ------------------ .../configpages/tapeconfigurationpage.h | 87 ----- .../tape/dialogs/configpages/tapepathpage.cpp | 255 ------------- .../tapepreferencesconfigurationpage.cpp | 169 +++++++++ .../tapepreferencesconfigurationpage.h | 60 +++ .../tapepreferencesconfigurationpage.ui | 202 +++++++++++ .../configpages/tapepreferencespathpage.cpp | 183 ++++++++++ ...pepathpage.h => tapepreferencespathpage.h} | 42 +-- .../configpages/tapepreferencespathpage.ui | 111 ++++++ .../tape/dialogs/dialogtapepreferences.cpp | 137 +++++++ ...configdialog.h => dialogtapepreferences.h} | 54 ++- src/app/tape/dialogs/dialogtapepreferences.ui | 143 ++++++++ src/app/tape/dialogs/tapeconfigdialog.cpp | 219 ----------- src/app/tape/tape.pri | 21 +- src/app/tape/tmainwindow.cpp | 23 +- src/app/tape/tmainwindow.h | 1 + .../preferencesconfigurationpage.cpp | 52 +-- .../preferencesconfigurationpage.h | 3 - src/app/valentina/mainwindow.cpp | 19 - src/app/valentina/mainwindow.h | 2 - src/libs/vmisc/def.cpp | 54 +++ src/libs/vmisc/def.h | 1 + src/libs/vwidgets/vabstractmainwindow.cpp | 21 ++ src/libs/vwidgets/vabstractmainwindow.h | 5 +- 24 files changed, 1161 insertions(+), 1044 deletions(-) delete mode 100644 src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp delete mode 100644 src/app/tape/dialogs/configpages/tapeconfigurationpage.h delete mode 100644 src/app/tape/dialogs/configpages/tapepathpage.cpp create mode 100644 src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp create mode 100644 src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h create mode 100644 src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui create mode 100644 src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp rename src/app/tape/dialogs/configpages/{tapepathpage.h => tapepreferencespathpage.h} (64%) create mode 100644 src/app/tape/dialogs/configpages/tapepreferencespathpage.ui create mode 100644 src/app/tape/dialogs/dialogtapepreferences.cpp rename src/app/tape/dialogs/{tapeconfigdialog.h => dialogtapepreferences.h} (58%) create mode 100644 src/app/tape/dialogs/dialogtapepreferences.ui delete mode 100644 src/app/tape/dialogs/tapeconfigdialog.cpp diff --git a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp deleted file mode 100644 index 0e873df21..000000000 --- a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/************************************************************************ - ** - ** @file tapeTapeConfigurationPage.cpp - ** @author Roman Telezhynskyi - ** @date 02 08, 2015 - ** - ** @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 "tapeconfigurationpage.h" -#include "../../mapplication.h" -#include "../vmisc/vtapesettings.h" -#include "../vpatterndb/variables/vmeasurement.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -TapeConfigurationPage::TapeConfigurationPage(QWidget *parent) - : QWidget(parent), - langCombo(nullptr), - systemCombo(nullptr), - labelCombo(nullptr), - osOptionCheck(nullptr), - langChanged(false), - systemChanged(false), - defGradationChanged(false), - sendReportCheck(nullptr), - askPointDeletionCheck(nullptr), - toolBarStyleCheck(nullptr), - systemAuthorValueLabel(nullptr), - systemBookValueLabel(nullptr), - langGroup(nullptr), - guiLabel(nullptr), - separatorLabel(nullptr), - pmSystemGroup(nullptr), - systemLabel(nullptr), - systemAuthorLabel(nullptr), - systemBookLabel(nullptr), - gradationGroup(nullptr), - defHeightLabel(nullptr), - defSizeLabel(nullptr), - defHeightCombo(nullptr), - defSizeCombo(nullptr) -{ - QGroupBox *langGroup = LangGroup(); - QGroupBox *pmSystemGroup = PMSystemGroup(); - QGroupBox *gradationBox = GradationGroup(); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(langGroup); - mainLayout->addWidget(pmSystemGroup); - mainLayout->addWidget(gradationBox); - mainLayout->addStretch(1); - setLayout(mainLayout); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigurationPage::Apply() -{ - VTapeSettings *settings = qApp->TapeSettings(); - settings->SetOsSeparator(osOptionCheck->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); - qApp->processEvents();// force to call changeEvent - - // Part about measurments will not be updated automatically - qApp->RetranslateTables(); - qApp->RetranslateGroups(); - } - - if (defGradationChanged) - { - settings->SetDefHeight(defHeightCombo->currentText().toInt()); - settings->SetDefSize(defSizeCombo->currentText().toInt()); - defGradationChanged = false; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigurationPage::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 *TapeConfigurationPage::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 = fileNames.at(i); // "valentina_de_De.qm" - locale.truncate(locale.lastIndexOf(QLatin1String("."))); // "valentina_de_De" - locale.remove(0, locale.indexOf(QLatin1String("_")) + 1); // "de_De" - - if (not englishUS) - { - englishUS = (en_US == locale); - } - - const QLocale loc(locale); - const 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))); - const QString lang = QLocale(en_US).nativeLanguageName(); - langCombo->addItem(ico, lang, en_US); - } - - // set default translators and language checked - const VTapeSettings *settings = qApp->TapeSettings(); - qint32 index = langCombo->findData(settings->GetLocale()); - if (index != -1) - { - langCombo->setCurrentIndex(index); - } - connect(langCombo, static_cast(&QComboBox::currentIndexChanged), RECEIVER(this)[this]() - { - langChanged = true; - }); - - 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); - //----------------------- - langGroup->setLayout(langLayout); - - return langGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *TapeConfigurationPage::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), RECEIVER(this)[this]() - { - 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); - }); - - // set default pattern making system - const VTapeSettings *settings = qApp->TapeSettings(); - const int index = systemCombo->findData(settings->GetPMSystemCode()); - if (index != -1) - { - systemCombo->setCurrentIndex(index); - } - - pmSystemGroup->setLayout(pmSystemLayout); - return pmSystemGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGroupBox *TapeConfigurationPage::GradationGroup() -{ - gradationGroup = new QGroupBox(tr("Default height and size")); - - QFormLayout *gradationLayout = new QFormLayout; - gradationLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - - const VTapeSettings *settings = qApp->TapeSettings(); - - defHeightLabel = new QLabel(tr("Default height:")); - defHeightCombo = new QComboBox; - defHeightCombo->addItems(VMeasurement::WholeListHeights(Unit::Cm)); - int index = defHeightCombo->findText(QString().setNum(settings->GetDefHeight())); - if (index != -1) - { - defHeightCombo->setCurrentIndex(index); - } - - auto DefGradationChanged = [this]() - { - defGradationChanged = true; - }; - - connect(defHeightCombo, static_cast(&QComboBox::currentIndexChanged), RECEIVER(this) - DefGradationChanged); - gradationLayout->addRow(defHeightLabel, defHeightCombo); - - - defSizeLabel = new QLabel(tr("Default size:")); - defSizeCombo = new QComboBox; - defSizeCombo->addItems(VMeasurement::WholeListSizes(Unit::Cm)); - index = defSizeCombo->findText(QString().setNum(settings->GetDefSize())); - if (index != -1) - { - defSizeCombo->setCurrentIndex(index); - } - connect(defHeightCombo, static_cast(&QComboBox::currentIndexChanged), RECEIVER(this) - DefGradationChanged); - gradationLayout->addRow(defSizeLabel, defSizeCombo); - - gradationGroup->setLayout(gradationLayout); - return gradationGroup; -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigurationPage::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 TapeConfigurationPage::RetranslateUi() -{ - 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())); - - 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); - - gradationGroup->setTitle(tr("Default height and size")); - defHeightLabel->setText(tr("Default height:")); - defSizeLabel->setText(tr("Default size:")); -} diff --git a/src/app/tape/dialogs/configpages/tapeconfigurationpage.h b/src/app/tape/dialogs/configpages/tapeconfigurationpage.h deleted file mode 100644 index f2aa0083c..000000000 --- a/src/app/tape/dialogs/configpages/tapeconfigurationpage.h +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************************************ - ** - ** @file tapeconfigurationpage.h - ** @author Roman Telezhynskyi - ** @date 02 08, 2015 - ** - ** @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 - -class QCheckBox; -class QSpinBox; -class QComboBox; -class QGroupBox; -class QLabel; - -class TapeConfigurationPage : public QWidget -{ - Q_OBJECT -public: - explicit TapeConfigurationPage(QWidget *parent = nullptr); - void Apply(); -protected: - virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; -private: - Q_DISABLE_COPY(TapeConfigurationPage) - QComboBox *langCombo; - QComboBox *systemCombo; - QComboBox *labelCombo; - QCheckBox *osOptionCheck; - bool langChanged; - bool systemChanged; - bool defGradationChanged; - QCheckBox *sendReportCheck; - QCheckBox *askPointDeletionCheck; - QCheckBox *toolBarStyleCheck; - QLabel *systemAuthorValueLabel; - QPlainTextEdit *systemBookValueLabel; - - QGroupBox *langGroup; - QLabel *guiLabel; - QLabel *separatorLabel; - - QGroupBox *pmSystemGroup; - QLabel *systemLabel; - QLabel *systemAuthorLabel; - QLabel *systemBookLabel; - - QGroupBox *gradationGroup; - QLabel *defHeightLabel; - QLabel *defSizeLabel; - QComboBox *defHeightCombo; - QComboBox *defSizeCombo; - - QGroupBox *LangGroup() Q_REQUIRED_RESULT; - QGroupBox *PMSystemGroup() Q_REQUIRED_RESULT; - QGroupBox *GradationGroup() Q_REQUIRED_RESULT; - void SetLabelComboBox(const QStringList &list); - void RetranslateUi(); -}; - -#endif // CONFIGURATIONPAGE_H diff --git a/src/app/tape/dialogs/configpages/tapepathpage.cpp b/src/app/tape/dialogs/configpages/tapepathpage.cpp deleted file mode 100644 index 958cbee98..000000000 --- a/src/app/tape/dialogs/configpages/tapepathpage.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/************************************************************************ - ** - ** @file tapepathpage.cpp - ** @author Roman Telezhynskyi - ** @date 02 08, 2015 - ** - ** @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 "tapepathpage.h" -#include "../../mapplication.h" -#include "../vmisc/vtapesettings.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -TapePathPage::TapePathPage(QWidget *parent) - : QWidget(parent), - defaultButton(nullptr), - editButton(nullptr), - pathTable(nullptr), - pathGroup(nullptr) -{ - QGroupBox *pathGroup = PathGroup(); - SCASSERT(pathGroup != nullptr) - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(pathGroup); - mainLayout->addStretch(1); - setLayout(mainLayout); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapePathPage::Apply() -{ - VTapeSettings *settings = qApp->TapeSettings(); - settings->SetPathIndividualMeasurements(pathTable->item(0, 1)->text()); - settings->SetPathStandardMeasurements(pathTable->item(1, 1)->text()); - settings->SetPathTemplate(pathTable->item(2, 1)->text()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapePathPage::DefaultPath() -{ - const int row = pathTable->currentRow(); - QTableWidgetItem *item = pathTable->item(row, 1); - SCASSERT(item != nullptr) - - QString path; - switch (row) - { - case 0: // individual measurements - path = VCommonSettings::GetDefPathIndividualMeasurements(); - break; - case 1: // standard measurements - path = VCommonSettings::GetDefPathStandardMeasurements(); - break; - case 2: // templates - path = VCommonSettings::GetDefPathTemplate(); - break; - default: - break; - } - - item->setText(path); - item->setToolTip(path); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapePathPage::EditPath() -{ - const int row = pathTable->currentRow(); - QTableWidgetItem *item = pathTable->item(row, 1); - SCASSERT(item != nullptr) - - QString path; - switch (row) - { - case 0: // individual measurements - path = qApp->TapeSettings()->GetPathIndividualMeasurements(); - break; - case 1: // standard measurements - path = qApp->TapeSettings()->GetPathStandardMeasurements(); - VCommonSettings::PrepareStandardTables(path); - break; - case 2: // templates - path = qApp->TapeSettings()->GetPathTemplate(); - break; - default: - break; - } - - bool usedNotExistedDir = false; - QDir directory(path); - if (not directory.exists()) - { - usedNotExistedDir = directory.mkpath("."); - } - - const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path, - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - if (dir.isEmpty()) - { - if (usedNotExistedDir) - { - QDir directory(path); - directory.rmpath("."); - } - - DefaultPath(); - return; - } - - item->setText(dir); - item->setToolTip(dir); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapePathPage::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 *TapePathPage::PathGroup() -{ - pathGroup = new QGroupBox(tr("Path that use Valentina")); - InitTable(); - - defaultButton = new QPushButton(tr("Default")); - defaultButton->setEnabled(false); - connect(defaultButton, &QPushButton::clicked, this, &TapePathPage::DefaultPath); - - editButton = new QPushButton(tr("Edit")); - editButton->setEnabled(false); - connect(editButton, &QPushButton::clicked, this, &TapePathPage::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 TapePathPage::InitTable() -{ - pathTable = new QTableWidget(); - pathTable->setRowCount(3); - pathTable->setColumnCount(2); - pathTable->verticalHeader()->setVisible(false); - pathTable->setEditTriggers(QAbstractItemView::NoEditTriggers); - pathTable->setSelectionBehavior(QAbstractItemView::SelectRows); - pathTable->setSelectionMode(QAbstractItemView::SingleSelection); - pathTable->setShowGrid(false); - - const QStringList tableHeader = QStringList() << tr("Type") << tr("Path"); - pathTable->setHorizontalHeaderLabels(tableHeader); - - const VTapeSettings *settings = qApp->TapeSettings(); - - { - 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); - } - - { - 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); - } - - { - pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Templates"))); - QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathTemplate()); - item->setToolTip(settings->GetPathTemplate()); - pathTable->setItem(2, 1, item); - } - - pathTable->verticalHeader()->setDefaultSectionSize(20); - pathTable->resizeColumnsToContents(); - pathTable->resizeRowsToContents(); - pathTable->horizontalHeader()->setStretchLastSection(true); - - connect(pathTable, &QTableWidget::itemSelectionChanged, [this] - { - defaultButton->setEnabled(true); - defaultButton->setDefault(false); - - editButton->setEnabled(true); - editButton->setDefault(true); - }); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapePathPage::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 Templates")); -} diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp new file mode 100644 index 000000000..36fdd6a38 --- /dev/null +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp @@ -0,0 +1,169 @@ +/************************************************************************ + ** + ** @file tapepreferencesconfigurationpage.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 "tapepreferencesconfigurationpage.h" +#include "ui_tapepreferencesconfigurationpage.h" +#include "../../mapplication.h" +#include "../vmisc/vtapesettings.h" +#include "../vpatterndb/variables/vmeasurement.h" + +//--------------------------------------------------------------------------------------------------------------------- +TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *parent) + : QWidget(parent), + ui(new Ui::TapePreferencesConfigurationPage), + m_langChanged(false), + m_systemChanged(false), + m_defGradationChanged(false) +{ + ui->setupUi(this); + + InitLanguages(ui->langCombo); + 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->TapeSettings()->GetOsSeparator()); + + //---------------------- 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 + int index = ui->systemCombo->findData(qApp->TapeSettings()->GetPMSystemCode()); + if (index != -1) + { + ui->systemCombo->setCurrentIndex(index); + } + + //----------------------------- Measurements Editing + connect(ui->resetWarningsButton, &QPushButton::released, []() + { + VTapeSettings *settings = qApp->TapeSettings(); + + settings->SetConfirmFormatRewriting(true); + }); + + //----------------------- Toolbar + ui->toolBarStyleCheck->setChecked(qApp->TapeSettings()->GetToolBarStyle()); + + //---------------------------Default height and size + ui->defHeightCombo->addItems(VMeasurement::WholeListHeights(Unit::Cm)); + index = ui->defHeightCombo->findText(QString().setNum(qApp->TapeSettings()->GetDefHeight())); + if (index != -1) + { + ui->defHeightCombo->setCurrentIndex(index); + } + + auto DefGradationChanged = [this]() + { + m_defGradationChanged = true; + }; + + connect(ui->defHeightCombo, static_cast(&QComboBox::currentIndexChanged), this, + DefGradationChanged); + + ui->defSizeCombo->addItems(VMeasurement::WholeListSizes(Unit::Cm)); + index = ui->defSizeCombo->findText(QString().setNum(qApp->TapeSettings()->GetDefSize())); + if (index != -1) + { + ui->defSizeCombo->setCurrentIndex(index); + } + connect(ui->defHeightCombo, static_cast(&QComboBox::currentIndexChanged), this, + DefGradationChanged); +} + +//--------------------------------------------------------------------------------------------------------------------- +TapePreferencesConfigurationPage::~TapePreferencesConfigurationPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TapePreferencesConfigurationPage::Apply() +{ + VTapeSettings *settings = qApp->TapeSettings(); + settings->SetOsSeparator(ui->osOptionCheck->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); + qApp->processEvents();// force to call changeEvent + + // Part about measurments will not be updated automatically + qApp->RetranslateTables(); + qApp->RetranslateGroups(); + } + + if (m_defGradationChanged) + { + settings->SetDefHeight(ui->defHeightCombo->currentText().toInt()); + settings->SetDefSize(ui->defSizeCombo->currentText().toInt()); + m_defGradationChanged = false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TapePreferencesConfigurationPage::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 TapePreferencesConfigurationPage::RetranslateUi() +{ + ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint())); +} diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h new file mode 100644 index 000000000..588827416 --- /dev/null +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @file tapepreferencesconfigurationpage.h + ** @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 . + ** + *************************************************************************/ + +#ifndef TAPEPREFERENCESCONFIGURATIONPAGE_H +#define TAPEPREFERENCESCONFIGURATIONPAGE_H + +#include + +namespace Ui +{ + class TapePreferencesConfigurationPage; +} + +class TapePreferencesConfigurationPage : public QWidget +{ + Q_OBJECT + +public: + explicit TapePreferencesConfigurationPage(QWidget *parent = nullptr); + virtual ~TapePreferencesConfigurationPage(); + + void Apply(); +protected: + virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(TapePreferencesConfigurationPage) + Ui::TapePreferencesConfigurationPage *ui; + bool m_langChanged; + bool m_systemChanged; + bool m_defGradationChanged; + + void RetranslateUi(); +}; + +#endif // TAPEPREFERENCESCONFIGURATIONPAGE_H diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui new file mode 100644 index 000000000..cd16d2a14 --- /dev/null +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui @@ -0,0 +1,202 @@ + + + TapePreferencesConfigurationPage + + + + 0 + 0 + 501 + 526 + + + + Configuration + + + + + + Language + + + + QFormLayout::ExpandingFieldsGrow + + + + + GUI language: + + + + + + + + + + Decimal separator parts: + + + + + + + < With OS options > + + + true + + + + + + + + + + Pattern making system + + + + QFormLayout::ExpandingFieldsGrow + + + + + Pattern making system: + + + + + + + + + + Author: + + + + + + + author + + + + + + + Book: + + + + + + + + 0 + 0 + + + + true + + + + + + + + + + Measurements editing + + + + + + + 0 + 0 + + + + Reset warnings + + + + + + + + + + Toolbar + + + + + + The text appears under the icon (recommended for beginners). + + + true + + + + + + + + + + Default height and size + + + + QFormLayout::ExpandingFieldsGrow + + + + + Default height: + + + + + + + + + + Default size: + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp new file mode 100644 index 000000000..5820cebf5 --- /dev/null +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp @@ -0,0 +1,183 @@ +/************************************************************************ + ** + ** @file tapepreferencespathpage.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 "tapepreferencespathpage.h" +#include "ui_tapepreferencespathpage.h" +#include "../../mapplication.h" +#include "../vmisc/vtapesettings.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +TapePreferencesPathPage::TapePreferencesPathPage(QWidget *parent) + : QWidget(parent), + ui(new Ui::TapePreferencesPathPage) +{ + ui->setupUi(this); + + InitTable(); + + connect(ui->defaultButton, &QPushButton::clicked, this, &TapePreferencesPathPage::DefaultPath); + connect(ui->editButton, &QPushButton::clicked, this, &TapePreferencesPathPage::EditPath); +} + +//--------------------------------------------------------------------------------------------------------------------- +TapePreferencesPathPage::~TapePreferencesPathPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TapePreferencesPathPage::Apply() +{ + VTapeSettings *settings = qApp->TapeSettings(); + settings->SetPathIndividualMeasurements(ui->pathTable->item(0, 1)->text()); + settings->SetPathStandardMeasurements(ui->pathTable->item(1, 1)->text()); + settings->SetPathTemplate(ui->pathTable->item(2, 1)->text()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TapePreferencesPathPage::DefaultPath() +{ + const int row = ui->pathTable->currentRow(); + QTableWidgetItem *item = ui->pathTable->item(row, 1); + SCASSERT(item != nullptr) + + QString path; + switch (row) + { + case 0: // individual measurements + path = VCommonSettings::GetDefPathIndividualMeasurements(); + break; + case 1: // standard measurements + path = VCommonSettings::GetDefPathStandardMeasurements(); + break; + case 2: // templates + path = VCommonSettings::GetDefPathTemplate(); + break; + default: + break; + } + + item->setText(path); + item->setToolTip(path); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TapePreferencesPathPage::EditPath() +{ + const int row = ui->pathTable->currentRow(); + QTableWidgetItem *item = ui->pathTable->item(row, 1); + SCASSERT(item != nullptr) + + QString path; + switch (row) + { + case 0: // individual measurements + path = qApp->TapeSettings()->GetPathIndividualMeasurements(); + break; + case 1: // standard measurements + path = qApp->TapeSettings()->GetPathStandardMeasurements(); + VCommonSettings::PrepareStandardTables(path); + break; + case 2: // templates + path = qApp->TapeSettings()->GetPathTemplate(); + break; + default: + break; + } + + bool usedNotExistedDir = false; + QDir directory(path); + if (not directory.exists()) + { + usedNotExistedDir = directory.mkpath("."); + } + + const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + if (dir.isEmpty()) + { + if (usedNotExistedDir) + { + QDir directory(path); + directory.rmpath("."); + } + + DefaultPath(); + return; + } + + item->setText(dir); + item->setToolTip(dir); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TapePreferencesPathPage::InitTable() +{ + ui->pathTable->setRowCount(3); + ui->pathTable->setColumnCount(2); + + const VTapeSettings *settings = qApp->TapeSettings(); + + { + ui->pathTable->setItem(0, 0, new QTableWidgetItem(tr("My Individual Measurements"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathIndividualMeasurements()); + item->setToolTip(settings->GetPathIndividualMeasurements()); + ui->pathTable->setItem(0, 1, item); + } + + { + ui->pathTable->setItem(1, 0, new QTableWidgetItem(tr("My Multisize Measurements"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathStandardMeasurements()); + item->setToolTip(settings->GetPathStandardMeasurements()); + ui->pathTable->setItem(1, 1, item); + } + + { + ui->pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Templates"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathTemplate()); + item->setToolTip(settings->GetPathTemplate()); + ui->pathTable->setItem(2, 1, item); + } + + ui->pathTable->verticalHeader()->setDefaultSectionSize(20); + ui->pathTable->resizeColumnsToContents(); + ui->pathTable->resizeRowsToContents(); + ui->pathTable->horizontalHeader()->setStretchLastSection(true); + + connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]() + { + ui->defaultButton->setEnabled(true); + ui->defaultButton->setDefault(false); + + ui->editButton->setEnabled(true); + ui->editButton->setDefault(true); + }); +} diff --git a/src/app/tape/dialogs/configpages/tapepathpage.h b/src/app/tape/dialogs/configpages/tapepreferencespathpage.h similarity index 64% rename from src/app/tape/dialogs/configpages/tapepathpage.h rename to src/app/tape/dialogs/configpages/tapepreferencespathpage.h index 89771d2a2..d8eda0749 100644 --- a/src/app/tape/dialogs/configpages/tapepathpage.h +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file tapepathpage.h + ** @file tapepreferencespathpage.h ** @author Roman Telezhynskyi - ** @date 02 08, 2015 + ** @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,33 @@ ** *************************************************************************/ -#ifndef PATHPAGE_H -#define PATHPAGE_H +#ifndef TAPEPREFERENCESPATHPAGE_H +#define TAPEPREFERENCESPATHPAGE_H -#include #include -class QGroupBox; -class QPushButton; -class QTableWidget; +namespace Ui +{ + class TapePreferencesPathPage; +} -class TapePathPage : public QWidget +class TapePreferencesPathPage : public QWidget { Q_OBJECT + public: - explicit TapePathPage(QWidget *parent = nullptr); - void Apply(); -protected: - virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; + explicit TapePreferencesPathPage(QWidget *parent = nullptr); + virtual ~TapePreferencesPathPage(); + + void Apply(); private slots: void DefaultPath(); void EditPath(); private: - Q_DISABLE_COPY(TapePathPage) - QPushButton *defaultButton; - QPushButton *editButton; - QTableWidget *pathTable; - QGroupBox *pathGroup; + Q_DISABLE_COPY(TapePreferencesPathPage) + Ui::TapePreferencesPathPage *ui; - QGroupBox *PathGroup() Q_REQUIRED_RESULT; - void InitTable(); - void RetranslateUi(); + void InitTable(); }; -#endif // PATHPAGE_H +#endif // TAPEPREFERENCESPATHPAGE_H diff --git a/src/app/tape/dialogs/configpages/tapepreferencespathpage.ui b/src/app/tape/dialogs/configpages/tapepreferencespathpage.ui new file mode 100644 index 000000000..7067c9143 --- /dev/null +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.ui @@ -0,0 +1,111 @@ + + + TapePreferencesPathPage + + + + 0 + 0 + 375 + 276 + + + + Paths + + + + + + 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/tape/dialogs/dialogtapepreferences.cpp b/src/app/tape/dialogs/dialogtapepreferences.cpp new file mode 100644 index 000000000..b2bf40561 --- /dev/null +++ b/src/app/tape/dialogs/dialogtapepreferences.cpp @@ -0,0 +1,137 @@ +/************************************************************************ + ** + ** @file dialogtapepreferences.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 "dialogtapepreferences.h" +#include "ui_dialogtapepreferences.h" +#include "../mapplication.h" +#include "configpages/tapepreferencesconfigurationpage.h" +#include "configpages/tapepreferencespathpage.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogTapePreferences::DialogTapePreferences(QWidget *parent) + :QDialog(parent), + ui(new Ui::DialogTapePreferences), + m_isInitialized(false), + m_configurationPage(new TapePreferencesConfigurationPage), + m_pathPage(new TapePreferencesPathPage) +{ + 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, &DialogTapePreferences::Ok); + + QPushButton *bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + SCASSERT(bApply != nullptr) + connect(bApply, &QPushButton::clicked, this, &DialogTapePreferences::Apply); + + ui->pagesWidget->insertWidget(0, m_configurationPage); + ui->pagesWidget->insertWidget(1, m_pathPage); + + connect(ui->contentsWidget, &QListWidget::currentItemChanged, this, &DialogTapePreferences::PageChanged); + ui->pagesWidget->setCurrentIndex(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogTapePreferences::~DialogTapePreferences() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTapePreferences::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 DialogTapePreferences::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 DialogTapePreferences::Apply() +{ + m_configurationPage->Apply(); + m_pathPage->Apply(); + + qApp->TapeSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + emit UpdateProperties(); + setResult(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTapePreferences::Ok() +{ + Apply(); + done(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTapePreferences::PageChanged(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (current == nullptr) + { + current = previous; + } + int rowIndex = ui->contentsWidget->row(current); + ui->pagesWidget->setCurrentIndex(rowIndex); +} diff --git a/src/app/tape/dialogs/tapeconfigdialog.h b/src/app/tape/dialogs/dialogtapepreferences.h similarity index 58% rename from src/app/tape/dialogs/tapeconfigdialog.h rename to src/app/tape/dialogs/dialogtapepreferences.h index b7367f216..4cfb3a82f 100644 --- a/src/app/tape/dialogs/tapeconfigdialog.h +++ b/src/app/tape/dialogs/dialogtapepreferences.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file tapeconfigdialog.h + ** @file dialogtapepreferences.h ** @author Roman Telezhynskyi - ** @date 02 08, 2015 + ** @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,46 +26,42 @@ ** *************************************************************************/ -#ifndef CONFIGDIALOG_H -#define CONFIGDIALOG_H +#ifndef DIALOGTAPEPREFERENCES_H +#define DIALOGTAPEPREFERENCES_H #include -#include "configpages/tapeconfigurationpage.h" -#include "configpages/tapepathpage.h" +namespace Ui +{ + class DialogTapePreferences; +} + +class TapePreferencesConfigurationPage; +class TapePreferencesPathPage; class QListWidgetItem; -class QStackedWidget; -class QListWidget; -class TapeConfigDialog : public QDialog +class DialogTapePreferences : public QDialog { Q_OBJECT + public: - explicit TapeConfigDialog(QWidget *parent = nullptr); + explicit DialogTapePreferences(QWidget *parent = nullptr); + virtual ~DialogTapePreferences(); 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: - Q_DISABLE_COPY(TapeConfigDialog) - QListWidget *contentsWidget; - QStackedWidget *pagesWidget; - TapeConfigurationPage *configurationPage; - TapePathPage *pathPage; - QPushButton *applyButton; - QPushButton *cancelButton; - QPushButton *okButton; - bool isInitialized; - - void createIcons(); - void createIcon(const QString &icon, const QString &text); +private slots: void Apply(); void Ok(); - - void RetranslateUi(); + void PageChanged(QListWidgetItem *current, QListWidgetItem *previous); +private: + Q_DISABLE_COPY(DialogTapePreferences) + Ui::DialogTapePreferences *ui; + bool m_isInitialized; + TapePreferencesConfigurationPage *m_configurationPage; + TapePreferencesPathPage *m_pathPage; }; -#endif // CONFIGDIALOG_H +#endif // DIALOGTAPEPREFERENCES_H diff --git a/src/app/tape/dialogs/dialogtapepreferences.ui b/src/app/tape/dialogs/dialogtapepreferences.ui new file mode 100644 index 000000000..694feed80 --- /dev/null +++ b/src/app/tape/dialogs/dialogtapepreferences.ui @@ -0,0 +1,143 @@ + + + DialogTapePreferences + + + + 0 + 0 + 831 + 669 + + + + Preferences + + + + :/tapeicon/64x64/logo.png:/tapeicon/64x64/logo.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 + + + + + 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() + DialogTapePreferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/tape/dialogs/tapeconfigdialog.cpp b/src/app/tape/dialogs/tapeconfigdialog.cpp deleted file mode 100644 index d7e5c9039..000000000 --- a/src/app/tape/dialogs/tapeconfigdialog.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/************************************************************************ - ** - ** @file tapeconfigdialog.cpp - ** @author Roman Telezhynskyi - ** @date 02 08, 2015 - ** - ** @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 "tapeconfigdialog.h" -#include -#include -#include -#include -#include -#include -#include "../mapplication.h" - -//--------------------------------------------------------------------------------------------------------------------- -TapeConfigDialog::TapeConfigDialog(QWidget *parent) - :QDialog(parent), - contentsWidget(nullptr), - pagesWidget(nullptr), - configurationPage(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(130); - contentsWidget->setMinimumWidth(130); - contentsWidget->setMinimumHeight(260); - contentsWidget->setSpacing(12); - - pagesWidget = new QStackedWidget; - pagesWidget->setMinimumWidth(550); - - configurationPage = new TapeConfigurationPage(); - pagesWidget->addWidget(configurationPage); - - pathPage = new TapePathPage(); - pagesWidget->addWidget(pathPage); - - applyButton = new QPushButton(tr("Apply")); - cancelButton = new QPushButton(tr("&Cancel")); - okButton = new QPushButton(tr("&Ok")); - - createIcons(); - connect(contentsWidget, &QListWidget::currentItemChanged, - RECEIVER(this)[this](QListWidgetItem *current, QListWidgetItem *previous) - { - if (current == nullptr) - { - current = previous; - } - pagesWidget->setCurrentIndex(contentsWidget->row(current)); - }); - contentsWidget->setCurrentRow(0); - - connect(cancelButton, &QPushButton::clicked, this, &TapeConfigDialog::close); - connect(applyButton, &QPushButton::clicked, this, &TapeConfigDialog::Apply); - connect(okButton, &QPushButton::clicked, this, &TapeConfigDialog::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); - setLayout(mainLayout); - - mainLayout->setStretch(0, 1); - - setWindowTitle(tr("Config Dialog")); - - qApp->TapeSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigDialog::closeEvent(QCloseEvent *event) -{ - if (result() == QDialog::Accepted) - { - done(QDialog::Accepted); - } - event->accept(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigDialog::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 TapeConfigDialog::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); - } - - isInitialized = true;//first show windows are held -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigDialog::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 TapeConfigDialog::createIcons() -{ - createIcon("://icon/config.png", tr("Configuration")); - createIcon("://icon/path_config.png", tr("Paths")); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigDialog::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 TapeConfigDialog::Apply() -{ - configurationPage->Apply(); - pathPage->Apply(); - - qApp->TapeSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); - emit UpdateProperties(); - setResult(QDialog::Accepted); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigDialog::Ok() -{ - Apply(); - done(QDialog::Accepted); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TapeConfigDialog::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("Paths")); -} diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index 45d4322f4..b0355ca60 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -8,11 +8,11 @@ SOURCES += \ $$PWD/dialogs/dialogabouttape.cpp \ $$PWD/dialogs/dialognewmeasurements.cpp \ $$PWD/dialogs/dialogmdatabase.cpp \ - $$PWD/dialogs/tapeconfigdialog.cpp \ - $$PWD/dialogs/configpages/tapeconfigurationpage.cpp \ - $$PWD/dialogs/configpages/tapepathpage.cpp \ $$PWD/dialogs/dialogexporttocsv.cpp \ - $$PWD/vlitepattern.cpp + $$PWD/vlitepattern.cpp \ + $$PWD/dialogs/dialogtapepreferences.cpp \ + $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.cpp \ + $$PWD/dialogs/configpages/tapepreferencespathpage.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -24,15 +24,18 @@ HEADERS += \ $$PWD/dialogs/dialognewmeasurements.h \ $$PWD/dialogs/dialogmdatabase.h \ $$PWD/version.h \ - $$PWD/dialogs/tapeconfigdialog.h \ - $$PWD/dialogs/configpages/tapeconfigurationpage.h \ - $$PWD/dialogs/configpages/tapepathpage.h \ $$PWD/dialogs/dialogexporttocsv.h \ - $$PWD/vlitepattern.h + $$PWD/vlitepattern.h \ + $$PWD/dialogs/dialogtapepreferences.h \ + $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.h \ + $$PWD/dialogs/configpages/tapepreferencespathpage.h FORMS += \ $$PWD/tmainwindow.ui \ $$PWD/dialogs/dialogabouttape.ui \ $$PWD/dialogs/dialognewmeasurements.ui \ $$PWD/dialogs/dialogmdatabase.ui \ - $$PWD/dialogs/dialogexporttocsv.ui + $$PWD/dialogs/dialogexporttocsv.ui \ + $$PWD/dialogs/dialogtapepreferences.ui \ + $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.ui \ + $$PWD/dialogs/configpages/tapepreferencespathpage.ui diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index ddb8c8fc7..ed2b7a184 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -31,7 +31,7 @@ #include "dialogs/dialogabouttape.h" #include "dialogs/dialognewmeasurements.h" #include "dialogs/dialogmdatabase.h" -#include "dialogs/tapeconfigdialog.h" +#include "dialogs/dialogtapepreferences.h" #include "dialogs/dialogexporttocsv.h" #include "../vpatterndb/calculator.h" #include "../ifc/ifcdef.h" @@ -485,17 +485,27 @@ void TMainWindow::CreateFromExisting() void TMainWindow::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()) { - TapeConfigDialog *config = new TapeConfigDialog(this); + DialogTapePreferences *preferences = new DialogTapePreferences(this); // QScopedPointer needs to be sure any exception will never block guard - QScopedPointer dlg(config); - guard = config; + QScopedPointer dlg(preferences); + guard = preferences; + // Must be first + connect(dlg.data(), &DialogTapePreferences::UpdateProperties, this, &TMainWindow::WindowsLocale); + connect(dlg.data(), &DialogTapePreferences::UpdateProperties, this, &TMainWindow::ToolBarStyles); dlg->exec(); } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::ToolBarStyles() +{ + ToolBarStyle(ui->toolBarGradation); + ToolBarStyle(ui->mainToolBar); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::closeEvent(QCloseEvent *event) { @@ -2740,6 +2750,9 @@ void TMainWindow::ReadSettings() restoreState(settings->GetWindowState()); restoreState(settings->GetToolbarsState(), APP_VERSION); + // Text under tool buton icon + ToolBarStyles(); + // Stack limit //qApp->getUndoStack()->setUndoLimit(settings->GetUndoCount()); } diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index c114dcba0..30af38ec1 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -78,6 +78,7 @@ private slots: void OpenTemplate(); void CreateFromExisting(); void Preferences(); + void ToolBarStyles(); bool FileSave(); bool FileSaveAs(); diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index 03eae27e6..e0215f921 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -47,7 +47,7 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) ui->setupUi(this); ui->autoSaveCheck->setChecked(qApp->ValentinaSettings()->GetAutosaveState()); - InitLanguages(); + InitLanguages(ui->langCombo); connect(ui->langCombo, static_cast(&QComboBox::currentIndexChanged), this, [this]() { m_langChanged = true; @@ -191,56 +191,6 @@ void PreferencesConfigurationPage::SetLabelComboBox(const QStringList &list) } } -//--------------------------------------------------------------------------------------------------------------------- -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() { diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h index d24abd22f..7098cdbb1 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.h @@ -56,10 +56,7 @@ private: bool m_labelLangChanged; void SetLabelComboBox(const QStringList &list); - - void InitLanguages(); void InitUnits(); - void RetranslateUi(); }; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index e3b5550b8..5f56b5968 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4230,12 +4230,6 @@ QStringList MainWindow::GetUnlokedRestoreFileList() const #endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindow::WindowsLocale() -{ - qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolBarStyles() { @@ -4335,19 +4329,6 @@ void MainWindow::ExportLayoutAs() ui->toolButtonLayoutExportAs->setChecked(false); } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindow::ToolBarStyle(QToolBar *bar) -{ - if (qApp->ValentinaSettings()->GetToolBarStyle()) - { - bar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - } - else - { - bar->setToolButtonStyle(Qt::ToolButtonIconOnly); - } -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ReopenFilesAfterCrash(QStringList &args) { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 24e39da84..a20fbc765 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -110,7 +110,6 @@ private slots: void FullParseFile(); void SetEnabledGUI(bool enabled); void GlobalChangePP(const QString &patternPiece); - void WindowsLocale(); void ToolBarStyles(); void ShowPaper(int index); void Preferences(); @@ -334,7 +333,6 @@ private: bool OpenNewValentina(const QString &fileName = QString())const; void FileClosedCorrect(); QStringList GetUnlokedRestoreFileList()const; - void ToolBarStyle(QToolBar *bar); void AddPP(const QString &PPName); QPointF StartPositionNewPP() const; diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 5b2341ce7..67b7ba3d7 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -2109,3 +2110,56 @@ PassmarkAngleType StringToPassmarkAngleType(const QString &value) } return PassmarkAngleType::Straightforward; } + +//--------------------------------------------------------------------------------------------------------------------- +void InitLanguages(QComboBox *combobox) +{ + SCASSERT(combobox != nullptr) + combobox->clear(); + + 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()))); + + combobox->addItem(ico, lang, locale); + } + + if (combobox->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(); + combobox->addItem(ico, lang, en_US); + } + + // set default translators and language checked + qint32 index = combobox->findData(qApp->Settings()->GetLocale()); + if (index != -1) + { + combobox->setCurrentIndex(index); + } +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 2161a88fc..e52b2ef22 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -719,6 +719,7 @@ qreal UnitConvertor(qreal value, const Unit &from, const Unit &to) Q_REQUIRED_RE void CheckFactor(qreal &oldFactor, const qreal &Newfactor); +void InitLanguages(QComboBox *combobox); QStringList SupportedLocales() Q_REQUIRED_RESULT; QStringList AllGroupNames() Q_REQUIRED_RESULT; diff --git a/src/libs/vwidgets/vabstractmainwindow.cpp b/src/libs/vwidgets/vabstractmainwindow.cpp index 59e11fa57..e800b6aa8 100644 --- a/src/libs/vwidgets/vabstractmainwindow.cpp +++ b/src/libs/vwidgets/vabstractmainwindow.cpp @@ -31,6 +31,7 @@ #include "../vmisc/vabstractapplication.h" #include +#include VAbstractMainWindow::VAbstractMainWindow(QWidget *parent) : QMainWindow(parent), @@ -68,3 +69,23 @@ bool VAbstractMainWindow::ContinueFormatRewrite(const QString ¤tFormatVers } return true; } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractMainWindow::ToolBarStyle(QToolBar *bar) +{ + SCASSERT(bar != nullptr) + if (qApp->Settings()->GetToolBarStyle()) + { + bar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + } + else + { + bar->setToolButtonStyle(Qt::ToolButtonIconOnly); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractMainWindow::WindowsLocale() +{ + qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); +} diff --git a/src/libs/vwidgets/vabstractmainwindow.h b/src/libs/vwidgets/vabstractmainwindow.h index 2522b2164..1fa7c0f14 100644 --- a/src/libs/vwidgets/vabstractmainwindow.h +++ b/src/libs/vwidgets/vabstractmainwindow.h @@ -45,12 +45,15 @@ public: public slots: virtual void ShowToolTip(const QString &toolTip)=0; +protected slots: + void WindowsLocale(); + protected: int m_curFileFormatVersion; QString m_curFileFormatVersionStr; bool ContinueFormatRewrite(const QString ¤tFormatVersion, const QString &maxFormatVersion); - + void ToolBarStyle(QToolBar *bar); private: Q_DISABLE_COPY(VAbstractMainWindow) };