From 06d19ace25f7baf0bb0ad8092a532b650d2d9e27 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 21 May 2021 20:51:46 +0300 Subject: [PATCH] Dialog File > Preferences. --- .../puzzlepreferencesconfigurationpage.cpp | 104 +++++++++ .../puzzlepreferencesconfigurationpage.h | 57 +++++ .../puzzlepreferencesconfigurationpage.ui | 117 ++++++++++ .../configpages/puzzlepreferencespathpage.cpp | 220 ++++++++++++++++++ .../configpages/puzzlepreferencespathpage.h | 62 +++++ .../configpages/puzzlepreferencespathpage.ui | 111 +++++++++ .../dialogs/dialogpuzzlepreferences.cpp | 160 +++++++++++++ .../puzzle/dialogs/dialogpuzzlepreferences.h | 71 ++++++ .../puzzle/dialogs/dialogpuzzlepreferences.ui | 159 +++++++++++++ src/app/puzzle/main.cpp | 5 + src/app/puzzle/puzzle.pri | 9 + src/app/puzzle/vpapplication.cpp | 3 +- src/app/puzzle/vpmainwindow.cpp | 51 ++-- src/app/puzzle/vpmainwindow.h | 8 +- .../configpages/tapepreferencespathpage.cpp | 16 +- .../tape/dialogs/dialogtapepreferences.cpp | 2 +- src/app/tape/mapplication.cpp | 1 + src/app/tape/tmainwindow.cpp | 14 +- src/app/tape/tmainwindow.h | 3 +- src/libs/vmisc/vcommonsettings.cpp | 22 -- src/libs/vmisc/vcommonsettings.h | 4 - 21 files changed, 1143 insertions(+), 56 deletions(-) create mode 100644 src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp create mode 100644 src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h create mode 100644 src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui create mode 100644 src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp create mode 100644 src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h create mode 100644 src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.ui create mode 100644 src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp create mode 100644 src/app/puzzle/dialogs/dialogpuzzlepreferences.h create mode 100644 src/app/puzzle/dialogs/dialogpuzzlepreferences.ui diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp new file mode 100644 index 000000000..f5c06d700 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file puzzlepreferencesconfigurationpage.cpp + ** @author Roman Telezhynskyi + ** @date 21 5, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 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 "puzzlepreferencesconfigurationpage.h" +#include "ui_puzzlepreferencesconfigurationpage.h" +#include "../../vpapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +PuzzlePreferencesConfigurationPage::PuzzlePreferencesConfigurationPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::PuzzlePreferencesConfigurationPage) +{ + ui->setupUi(this); + + InitLanguages(ui->langCombo); + connect(ui->langCombo, QOverload::of(&QComboBox::currentIndexChanged), this, [this]() + { + m_langChanged = true; + }); + + // Theme + ui->darkModeCheck->setChecked(VPApplication::VApp()->PuzzleSettings()->GetDarkMode()); + + // Native dialogs + ui->checkBoxDontUseNativeDialog->setChecked(VPApplication::VApp()->PuzzleSettings()->IsDontUseNativeDialog()); + + //----------------------- Toolbar + ui->toolBarStyleCheck->setChecked(VPApplication::VApp()->PuzzleSettings()->GetToolBarStyle()); +} + +//--------------------------------------------------------------------------------------------------------------------- +PuzzlePreferencesConfigurationPage::~PuzzlePreferencesConfigurationPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList PuzzlePreferencesConfigurationPage::Apply() +{ + QStringList preferences; + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + + settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); + + if (settings->GetDarkMode() != ui->darkModeCheck->isChecked()) + { + settings->SetDarkMode(ui->darkModeCheck->isChecked()); + preferences.append(tr("dark mode")); + } + + if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked()) + { + settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked()); + } + + if (m_langChanged) + { + const QString locale = qvariant_cast(ui->langCombo->currentData()); + settings->SetLocale(locale); + m_langChanged = false; + + VAbstractApplication::VApp()->LoadTranslation(locale); + qApp->processEvents();// force to call changeEvent + } + + return preferences; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesConfigurationPage::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + } + // remember to call base class implementation + QWidget::changeEvent(event); +} diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h new file mode 100644 index 000000000..1656a2922 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file puzzlepreferencesconfigurationpage.h + ** @author Roman Telezhynskyi + ** @date 21 5, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 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 PUZZLEPREFERENCESCONFIGURATIONPAGE_H +#define PUZZLEPREFERENCESCONFIGURATIONPAGE_H + +#include + +namespace Ui +{ + class PuzzlePreferencesConfigurationPage; +} + +class PuzzlePreferencesConfigurationPage : public QWidget +{ + Q_OBJECT + +public: + explicit PuzzlePreferencesConfigurationPage(QWidget *parent = nullptr); + virtual ~PuzzlePreferencesConfigurationPage(); + + QStringList Apply(); + +protected: + virtual void changeEvent(QEvent* event) override; + +private: + Q_DISABLE_COPY(PuzzlePreferencesConfigurationPage) + Ui::PuzzlePreferencesConfigurationPage *ui; + bool m_langChanged{false}; +}; + +#endif // PUZZLEPREFERENCESCONFIGURATIONPAGE_H diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui new file mode 100644 index 000000000..7f10c762d --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui @@ -0,0 +1,117 @@ + + + PuzzlePreferencesConfigurationPage + + + + 0 + 0 + 505 + 548 + + + + Form + + + + + + true + + + + + 0 + 0 + 494 + 514 + + + + + + + Language + + + + QFormLayout::ExpandingFieldsGrow + + + + + GUI language: + + + + + + + + + + + + + Toolbar + + + + + + The text appears under the icon (recommended for beginners). + + + true + + + + + + + + + + User Interface + + + + + + Activate dark mode + + + + + + + Don't use the native file dialog + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp new file mode 100644 index 000000000..cc8a79429 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp @@ -0,0 +1,220 @@ +/************************************************************************ + ** + ** @file puzzlepreferencespathpage.cpp + ** @author Roman Telezhynskyi + ** @date 21 5, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 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 "puzzlepreferencespathpage.h" +#include "ui_puzzlepreferencespathpage.h" +#include "../../vpapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +PuzzlePreferencesPathPage::PuzzlePreferencesPathPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::PuzzlePreferencesPathPage) +{ + ui->setupUi(this); + + InitTable(); + + connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]() + { + ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); + ui->defaultButton->setDefault(false); + + ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); + ui->editButton->setDefault(true); + }); + + connect(ui->defaultButton, &QPushButton::clicked, this, &PuzzlePreferencesPathPage::DefaultPath); + connect(ui->editButton, &QPushButton::clicked, this, &PuzzlePreferencesPathPage::EditPath); +} + +//--------------------------------------------------------------------------------------------------------------------- +PuzzlePreferencesPathPage::~PuzzlePreferencesPathPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesPathPage::Apply() +{ + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + settings->SetPathIndividualMeasurements(ui->pathTable->item(0, 1)->text()); + settings->SetPathMultisizeMeasurements(ui->pathTable->item(1, 1)->text()); + settings->SetPathPattern(ui->pathTable->item(2, 1)->text()); + settings->SetPathTemplate(ui->pathTable->item(3, 1)->text()); + settings->SetPathManualLayouts(ui->pathTable->item(4, 1)->text()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesPathPage::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + InitTable(); + } + // remember to call base class implementation + QWidget::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesPathPage::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: // multisize measurements + path = VCommonSettings::GetDefPathMultisizeMeasurements(); + break; + case 2: // pattern path + path = VCommonSettings::GetDefPathPattern(); + break; + case 3: // templates + path = VCommonSettings::GetDefPathTemplate(); + break; + case 4: // layouts + path = VCommonSettings::GetDefPathManualLayouts(); + break; + default: + break; + } + + item->setText(path); + item->setToolTip(path); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesPathPage::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 = VPApplication::VApp()->PuzzleSettings()->GetPathIndividualMeasurements(); + break; + case 1: // multisize measurements + path = VPApplication::VApp()->PuzzleSettings()->GetPathMultisizeMeasurements(); + path = VCommonSettings::PrepareMultisizeTables(path); + break; + case 2: // pattern path + path = VPApplication::VApp()->PuzzleSettings()->GetPathPattern(); + break; + case 3: // templates + path = VPApplication::VApp()->PuzzleSettings()->GetPathTemplate(); + break; + case 4: // layouts + path = VPApplication::VApp()->PuzzleSettings()->GetPathManualLayouts(); + break; + default: + break; + } + + bool usedNotExistedDir = false; + QDir directory(path); + if (not directory.exists()) + { + usedNotExistedDir = directory.mkpath(QChar('.')); + } + + const QString dir = QFileDialog::getExistingDirectory( + this, tr("Open Directory"), path, + VAbstractApplication::VApp()->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks)); + if (dir.isEmpty()) + { + if (usedNotExistedDir) + { + QDir(path).rmpath(QChar('.')); + } + + DefaultPath(); + return; + } + + item->setText(dir); + item->setToolTip(dir); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesPathPage::InitTable() +{ + ui->pathTable->clearContents(); + ui->pathTable->setRowCount(5); + ui->pathTable->setColumnCount(2); + + const VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + + { + 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->GetPathMultisizeMeasurements()); + item->setToolTip(settings->GetPathMultisizeMeasurements()); + ui->pathTable->setItem(1, 1, item); + } + + { + ui->pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Patterns"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathPattern()); + item->setToolTip(settings->GetPathPattern()); + ui->pathTable->setItem(2, 1, item); + } + + { + ui->pathTable->setItem(3, 0, new QTableWidgetItem(tr("My Templates"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathTemplate()); + item->setToolTip(settings->GetPathTemplate()); + ui->pathTable->setItem(3, 1, item); + } + + { + ui->pathTable->setItem(4, 0, new QTableWidgetItem(tr("My Layouts"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathManualLayouts()); + item->setToolTip(settings->GetPathManualLayouts()); + ui->pathTable->setItem(4, 1, item); + } + + ui->pathTable->verticalHeader()->setDefaultSectionSize(20); + ui->pathTable->resizeColumnsToContents(); + ui->pathTable->resizeRowsToContents(); + ui->pathTable->horizontalHeader()->setStretchLastSection(true); +} diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h new file mode 100644 index 000000000..139208758 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file puzzlepreferencespathpage.h + ** @author Roman Telezhynskyi + ** @date 21 5, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 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 PUZZLEPREFERENCESPATHPAGE_H +#define PUZZLEPREFERENCESPATHPAGE_H + +#include + +namespace Ui +{ + class PuzzlePreferencesPathPage; +} + +class PuzzlePreferencesPathPage : public QWidget +{ + Q_OBJECT + +public: + explicit PuzzlePreferencesPathPage(QWidget *parent = nullptr); + virtual ~PuzzlePreferencesPathPage(); + + void Apply(); + +protected: + virtual void changeEvent(QEvent* event) override; + +private slots: + void DefaultPath(); + void EditPath(); + +private: + Q_DISABLE_COPY(PuzzlePreferencesPathPage) + Ui::PuzzlePreferencesPathPage *ui; + + void InitTable(); +}; + +#endif // PUZZLEPREFERENCESPATHPAGE_H diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.ui b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.ui new file mode 100644 index 000000000..9c8da0ff1 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.ui @@ -0,0 +1,111 @@ + + + PuzzlePreferencesPathPage + + + + 0 + 0 + 586 + 808 + + + + Form + + + + + + 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/puzzle/dialogs/dialogpuzzlepreferences.cpp b/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp new file mode 100644 index 000000000..1691fbab3 --- /dev/null +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp @@ -0,0 +1,160 @@ +/************************************************************************ + ** + ** @file dialogpuzzlepreferences.cpp + ** @author Roman Telezhynskyi + ** @date 21 5, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 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 "dialogpuzzlepreferences.h" +#include "ui_dialogpuzzlepreferences.h" +#include "../vpapplication.h" +#include "configpages/puzzlepreferencesconfigurationpage.h" +#include "configpages/puzzlepreferencespathpage.h" + +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogPuzzlePreferences::DialogPuzzlePreferences(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogPuzzlePreferences), + m_configurationPage(new PuzzlePreferencesConfigurationPage), + m_pathPage(new PuzzlePreferencesPathPage) +{ + ui->setupUi(this); + +#if defined(Q_OS_MAC) + setWindowFlags(Qt::Window); +#endif + + VAbstractApplication::VApp()->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + SCASSERT(bOk != nullptr) + connect(bOk, &QPushButton::clicked, this, &DialogPuzzlePreferences::Ok); + + QPushButton *bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + SCASSERT(bApply != nullptr) + connect(bApply, &QPushButton::clicked, this, &DialogPuzzlePreferences::Apply); + + ui->pagesWidget->insertWidget(0, m_configurationPage); + ui->pagesWidget->insertWidget(1, m_pathPage); + + connect(ui->contentsWidget, &QListWidget::currentItemChanged, this, &DialogPuzzlePreferences::PageChanged); + ui->pagesWidget->setCurrentIndex(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPuzzlePreferences::~DialogPuzzlePreferences() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPuzzlePreferences::showEvent(QShowEvent *event) +{ + QDialog::showEvent( event ); + if ( event->spontaneous() ) + { + return; + } + + if (m_isInitialized) + { + return; + } + // do your init stuff here + + QSize sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); + if (not sz.isEmpty()) + { + resize(sz); + } + + m_isInitialized = true;//first show windows are held +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPuzzlePreferences::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) + { + VAbstractApplication::VApp()->Settings()->SetPreferenceDialogSize(size()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPuzzlePreferences::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + } + // remember to call base class implementation + QDialog::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPuzzlePreferences::Apply() +{ + QStringList preferences; + + preferences += m_configurationPage->Apply(); + m_pathPage->Apply(); + + if (not preferences.isEmpty()) + { + const QString text = tr("Followed %n option(s) require restart to take effect: %1.", "", + preferences.size()).arg(preferences.join(QStringLiteral(", "))); + QMessageBox::information(this, QCoreApplication::applicationName(), text); + } + + VPApplication::VApp()->PuzzleSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + emit UpdateProperties(); + setResult(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPuzzlePreferences::Ok() +{ + Apply(); + done(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPuzzlePreferences::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/puzzle/dialogs/dialogpuzzlepreferences.h b/src/app/puzzle/dialogs/dialogpuzzlepreferences.h new file mode 100644 index 000000000..487a558cc --- /dev/null +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file dialogpuzzlepreferences.h + ** @author Roman Telezhynskyi + ** @date 21 5, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 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 DIALOGPUZZLEPREFERENCES_H +#define DIALOGPUZZLEPREFERENCES_H + +#include + +namespace Ui +{ + class DialogPuzzlePreferences; +} + +class PuzzlePreferencesConfigurationPage; +class PuzzlePreferencesPathPage; +class QListWidgetItem; + +class DialogPuzzlePreferences : public QDialog +{ + Q_OBJECT + +public: + explicit DialogPuzzlePreferences(QWidget *parent = nullptr); + virtual ~DialogPuzzlePreferences(); + +signals: + void UpdateProperties(); + +protected: + virtual void showEvent(QShowEvent *event) override; + virtual void resizeEvent(QResizeEvent *event) override; + virtual void changeEvent(QEvent* event) override; + +private slots: + void Apply(); + void Ok(); + void PageChanged(QListWidgetItem *current, QListWidgetItem *previous); + +private: + Q_DISABLE_COPY(DialogPuzzlePreferences) + Ui::DialogPuzzlePreferences *ui; + bool m_isInitialized{false}; + PuzzlePreferencesConfigurationPage *m_configurationPage; + PuzzlePreferencesPathPage *m_pathPage; +}; + +#endif // DIALOGPUZZLEPREFERENCES_H diff --git a/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui b/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui new file mode 100644 index 000000000..632f93440 --- /dev/null +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui @@ -0,0 +1,159 @@ + + + DialogPuzzlePreferences + + + + 0 + 0 + 851 + 551 + + + + Puzzle preferences + + + + :/puzzleicon/64x64/logo.png:/puzzleicon/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 + accepted() + DialogPuzzlePreferences + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogPuzzlePreferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/puzzle/main.cpp b/src/app/puzzle/main.cpp index f104053db..d282fe43a 100644 --- a/src/app/puzzle/main.cpp +++ b/src/app/puzzle/main.cpp @@ -53,6 +53,11 @@ int main(int argc, char *argv[]) #endif // defined(APPIMAGE) && defined(Q_OS_LINUX) Q_INIT_RESOURCE(puzzleicon); + Q_INIT_RESOURCE(theme); + Q_INIT_RESOURCE(icon); + Q_INIT_RESOURCE(schema); + Q_INIT_RESOURCE(flags); + Q_INIT_RESOURCE(style); QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index fe479e253..9df2bc733 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -2,6 +2,9 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp \ + $$PWD/dialogs/configpages/puzzlepreferencespathpage.cpp \ + $$PWD/dialogs/dialogpuzzlepreferences.cpp \ $$PWD/dialogs/vpdialogabout.cpp \ $$PWD/main.cpp \ $$PWD/vpapplication.cpp \ @@ -29,6 +32,9 @@ SOURCES += \ *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ + $$PWD/dialogs/configpages/puzzlepreferencesconfigurationpage.h \ + $$PWD/dialogs/configpages/puzzlepreferencespathpage.h \ + $$PWD/dialogs/dialogpuzzlepreferences.h \ $$PWD/dialogs/vpdialogabout.h \ $$PWD/stable.h \ $$PWD/vpapplication.h \ @@ -54,6 +60,9 @@ HEADERS += \ $$PWD/xml/vplayoutliterals.h FORMS += \ + $$PWD/dialogs/configpages/puzzlepreferencesconfigurationpage.ui \ + $$PWD/dialogs/configpages/puzzlepreferencespathpage.ui \ + $$PWD/dialogs/dialogpuzzlepreferences.ui \ $$PWD/dialogs/vpdialogabout.ui \ $$PWD/vpcarrousel.ui \ $$PWD/vpmainwindow.ui diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index d7ab56eec..d517136b3 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -340,7 +340,7 @@ auto VPApplication::MainWindow()-> VPMainWindow * } //--------------------------------------------------------------------------------------------------------------------- -auto VPApplication::MainWindows() -> QList +auto VPApplication::MainWindows() -> QList { Clean(); QList list; @@ -367,6 +367,7 @@ auto VPApplication::NewMainWindow(const VPCommandLinePtr &cmd) -> VPMainWindow * if (not cmd->IsTestModeEnabled()) { puzzle->show(); + puzzle->UpdateWindowTitle(); } puzzle->InitZoom(); return puzzle; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 9f89b2579..351c16465 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -44,6 +44,7 @@ #include "../ifc/exception/vexception.h" #include "../vwidgets/vmaingraphicsscene.h" #include "vpsheet.h" +#include "dialogs/dialogpuzzlepreferences.h" #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) #include "../vmisc/backport/qscopeguard.h" @@ -111,7 +112,6 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : SetPropertiesData(); - UpdateWindowTitle(); ReadSettings(); #if defined(Q_OS_MAC) @@ -825,7 +825,15 @@ void VPMainWindow::UpdateWindowTitle() } else { - showName = tr("untitled %1.vlt").arg(VPApplication::VApp()->MainWindows().size()+1); + int index = VPApplication::VApp()->MainWindows().indexOf(this); + if (index != -1) + { + showName = tr("untitled %1.vlt").arg(index+1); + } + else + { + showName = tr("untitled.vlt"); + } } showName += QLatin1String("[*]"); @@ -1111,10 +1119,11 @@ void VPMainWindow::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { - WindowsLocale(); - // retranslate designer form (single inheritance approach) ui->retranslateUi(this); + + WindowsLocale(); + UpdateWindowTitle(); } // remember to call base class implementation @@ -1134,7 +1143,7 @@ void VPMainWindow::on_actionOpen_triggered() const QString filter(tr("Layout files") + QLatin1String(" (*.vlt)")); //Use standard path to individual measurements - const QString pathTo = VPApplication::VApp()->PuzzleSettings()->GetPathLayouts(); + const QString pathTo = VPApplication::VApp()->PuzzleSettings()->GetPathManualLayouts(); bool usedNotExistedDir = false; QDir directory(pathTo); @@ -1205,7 +1214,7 @@ bool VPMainWindow::on_actionSaveAs_triggered() QString dir; if (curFile.isEmpty()) { - dir = VPApplication::VApp()->PuzzleSettings()->GetPathLayouts(); + dir = VPApplication::VApp()->PuzzleSettings()->GetPathManualLayouts(); } else { @@ -1874,23 +1883,23 @@ void VPMainWindow::ShowWindow() const } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::Preferences() +void VPMainWindow::on_actionPreferences_triggered() { // 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 -// if (guard.isNull()) -// { -// QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -// auto *preferences = new DialogPuzzlePreferences(this); -// // QScopedPointer needs to be sure any exception will never block guard -// QScopedPointer dlg(preferences); -// guard = preferences; -// // Must be first -// connect(dlg.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::WindowsLocale); -// connect(dlg.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::ToolBarStyles); -// QGuiApplication::restoreOverrideCursor(); -// dlg->exec(); - // } + static QPointer guard;// Prevent any second run + if (guard.isNull()) + { + QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + auto *preferences = new DialogPuzzlePreferences(this); + // QScopedPointer needs to be sure any exception will never block guard + QScopedPointer dlg(preferences); + guard = preferences; + // Must be first + connect(dlg.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::WindowsLocale); + connect(dlg.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::ToolBarStyles); + QGuiApplication::restoreOverrideCursor(); + dlg->exec(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index b93e8dcfa..4fce42e92 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -89,6 +89,8 @@ public: */ void InitZoom(); + void UpdateWindowTitle(); + public slots: /** * @brief on_actionNew_triggered When the menu action File > New @@ -391,8 +393,10 @@ private slots: */ void on_MouseMoved(const QPointF &scenePos); + void on_actionPreferences_triggered(); + void ShowWindow() const; - void Preferences(); + void ToolBarStyles(); #if defined(Q_OS_MAC) @@ -534,8 +538,6 @@ private: */ void SetCheckBoxValue(QCheckBox *checkbox, bool value); - void UpdateWindowTitle(); - void ReadSettings(); void WriteSettings(); diff --git a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp index 09edac40b..0b958396d 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp @@ -70,6 +70,7 @@ void TapePreferencesPathPage::Apply() settings->SetPathMultisizeMeasurements(ui->pathTable->item(1, 1)->text()); settings->SetPathPattern(ui->pathTable->item(2, 1)->text()); settings->SetPathTemplate(ui->pathTable->item(3, 1)->text()); + settings->SetPathManualLayouts(ui->pathTable->item(4, 1)->text()); } //--------------------------------------------------------------------------------------------------------------------- @@ -107,6 +108,9 @@ void TapePreferencesPathPage::DefaultPath() case 3: // templates path = VCommonSettings::GetDefPathTemplate(); break; + case 4: // layouts + path = VCommonSettings::GetDefPathManualLayouts(); + break; default: break; } @@ -138,6 +142,9 @@ void TapePreferencesPathPage::EditPath() case 3: // templates path = MApplication::VApp()->TapeSettings()->GetPathTemplate(); break; + case 4: // layouts + path = MApplication::VApp()->TapeSettings()->GetPathManualLayouts(); + break; default: break; } @@ -171,7 +178,7 @@ void TapePreferencesPathPage::EditPath() void TapePreferencesPathPage::InitTable() { ui->pathTable->clearContents(); - ui->pathTable->setRowCount(4); + ui->pathTable->setRowCount(5); ui->pathTable->setColumnCount(2); const VTapeSettings *settings = MApplication::VApp()->TapeSettings(); @@ -204,6 +211,13 @@ void TapePreferencesPathPage::InitTable() ui->pathTable->setItem(3, 1, item); } + { + ui->pathTable->setItem(4, 0, new QTableWidgetItem(tr("My Layouts"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathManualLayouts()); + item->setToolTip(settings->GetPathManualLayouts()); + ui->pathTable->setItem(4, 1, item); + } + ui->pathTable->verticalHeader()->setDefaultSectionSize(20); ui->pathTable->resizeColumnsToContents(); ui->pathTable->resizeRowsToContents(); diff --git a/src/app/tape/dialogs/dialogtapepreferences.cpp b/src/app/tape/dialogs/dialogtapepreferences.cpp index 11cf0e732..8be017276 100644 --- a/src/app/tape/dialogs/dialogtapepreferences.cpp +++ b/src/app/tape/dialogs/dialogtapepreferences.cpp @@ -89,7 +89,7 @@ void DialogTapePreferences::showEvent(QShowEvent *event) // do your init stuff here QSize sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); - if (sz.isEmpty() == false) + if (not sz.isEmpty()) { resize(sz); } diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index bf14c3907..584921b69 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -854,6 +854,7 @@ TMainWindow *MApplication::NewMainWindow() if (not MApplication::VApp()->IsTestMode()) { tape->show(); + tape->UpdateWindowTitle(); } return tape; } diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 94854b3ff..8a5b6cee8 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -133,7 +133,7 @@ TMainWindow::TMainWindow(QWidget *parent) connect(gradation, &QTimer::timeout, this, &TMainWindow::GradationChanged); SetupMenu(); - UpdateWindowTitle(); + ReadSettings(); #if defined(Q_OS_MAC) @@ -594,6 +594,8 @@ void TMainWindow::changeEvent(QEvent *event) // retranslate designer form (single inheritance approach) ui->retranslateUi(this); + UpdateWindowTitle(); + InitMeasurementUnits(); if (mType == MeasurementsType::Multisize) @@ -3241,7 +3243,15 @@ void TMainWindow::UpdateWindowTitle() } else { - showName = tr("untitled %1").arg(MApplication::VApp()->MainWindows().size()+1); + int index = MApplication::VApp()->MainWindows().indexOf(this); + if (index != -1) + { + showName = tr("untitled %1").arg(index+1); + } + else + { + showName = tr("untitled"); + } mType == MeasurementsType::Multisize ? showName += QLatin1String(".vst") : showName += QLatin1String(".vit"); } diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index cd8bdf11b..2bb9436e1 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -65,6 +65,8 @@ public: bool LoadFile(const QString &path); + void UpdateWindowTitle(); + protected: virtual void closeEvent(QCloseEvent *event) override; virtual void changeEvent(QEvent* event) override; @@ -215,7 +217,6 @@ private: void MeasurementGUI(); void Controls(); void MFields(bool enabled); - void UpdateWindowTitle(); void ReadSettings(); void WriteSettings(); diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index b7425823b..1aa73dc8d 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -73,7 +73,6 @@ namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsMultisizeMeasurements, (QLatin1String("paths/standard_measurements"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsLayouts, (QLatin1String("paths/layouts"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsPattern, (QLatin1String("paths/pattern"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsTemplates, (QLatin1String("paths/templates"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsLabelTemplate, (QLatin1String("paths/labels"))) @@ -407,27 +406,6 @@ void VCommonSettings::SetPathMultisizeMeasurements(const QString &value) settings.sync(); } -//--------------------------------------------------------------------------------------------------------------------- -QString VCommonSettings::GetDefPathLayouts() -{ - return QDir::homePath() + QLatin1String("/valentina/") + tr("layouts"); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VCommonSettings::GetPathLayouts() const -{ - QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); - return settings.value(*settingPathsLayouts, GetDefPathLayouts()).toString(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VCommonSettings::SetPathLayouts(const QString &value) -{ - QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); - settings.setValue(*settingPathsLayouts, value); - settings.sync(); -} - //--------------------------------------------------------------------------------------------------------------------- QString VCommonSettings::GetDefPathPattern() { diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index 7ff8d4666..8f4a049d3 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -68,10 +68,6 @@ public: QString GetPathMultisizeMeasurements() const; void SetPathMultisizeMeasurements(const QString &value); - static QString GetDefPathLayouts(); - QString GetPathLayouts() const; - void SetPathLayouts(const QString &value); - static QString GetDefPathPattern(); QString GetPathPattern() const; void SetPathPattern(const QString &value);