Fixed issue #5.

--HG--
branch : develop
This commit is contained in:
dismine 2014-02-14 13:29:04 +02:00
parent abb541ba68
commit 4bf209a525
20 changed files with 667 additions and 32 deletions

View File

@ -41,5 +41,14 @@
<file>icon/32x32/splinePath_cut_point.png</file>
<file>icon/32x32/union.png</file>
<file>icon/32x32/arc_cut.png</file>
<file>icon/config.png</file>
<file>icon/pattern_config.png</file>
<file>icon/flags/cs.png</file>
<file>icon/flags/de.png</file>
<file>icon/flags/en.png</file>
<file>icon/flags/fr.png</file>
<file>icon/flags/he_IL.png</file>
<file>icon/flags/ru.png</file>
<file>icon/flags/uk.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -0,0 +1,146 @@
/************************************************************************
**
** @file configdialog.cpp
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 12 2, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "configdialog.h"
ConfigDialog::ConfigDialog(QWidget *parent) :
QDialog(parent), contentsWidget(0), pagesWidget(0), configurationPage(0), patternPage(0)
{
contentsWidget = new QListWidget;
Q_CHECK_PTR(contentsWidget);
contentsWidget->setViewMode(QListView::IconMode);
contentsWidget->setIconSize(QSize(96, 84));
contentsWidget->setMovement(QListView::Static);
contentsWidget->setMaximumWidth(128);
contentsWidget->setMinimumHeight(250);
contentsWidget->setSpacing(12);
pagesWidget = new QStackedWidget;
Q_CHECK_PTR(pagesWidget);
configurationPage = new ConfigurationPage();
Q_CHECK_PTR(configurationPage);
pagesWidget->addWidget(configurationPage);
patternPage = new PatternPage();
Q_CHECK_PTR(patternPage);
pagesWidget->addWidget(patternPage);
QPushButton *applyButton = new QPushButton(tr("Apply"));
Q_CHECK_PTR(applyButton);
QPushButton *canselButton = new QPushButton(tr("&Cancel"));
Q_CHECK_PTR(canselButton);
QPushButton *okButton = new QPushButton(tr("&Ok"));
Q_CHECK_PTR(okButton);
createIcons();
contentsWidget->setCurrentRow(0);
connect(canselButton, &QPushButton::clicked, this, &ConfigDialog::close);
connect(applyButton, &QPushButton::clicked, this, &ConfigDialog::Apply);
connect(okButton, &QPushButton::clicked, this, &ConfigDialog::Ok);
QHBoxLayout *horizontalLayout = new QHBoxLayout;
Q_CHECK_PTR(horizontalLayout);
horizontalLayout->addWidget(contentsWidget);
horizontalLayout->addWidget(pagesWidget, 1);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
Q_CHECK_PTR(buttonsLayout);
buttonsLayout->addStretch(1);
buttonsLayout->addWidget(applyButton);
buttonsLayout->addWidget(canselButton);
buttonsLayout->addWidget(okButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
Q_CHECK_PTR(mainLayout);
mainLayout->addLayout(horizontalLayout);
mainLayout->addStretch(1);
mainLayout->addSpacing(12);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
setWindowTitle(tr("Config Dialog"));
}
void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
{
if (current == false)
{
current = previous;
}
pagesWidget->setCurrentIndex(contentsWidget->row(current));
}
void ConfigDialog::closeEvent(QCloseEvent *event)
{
if (result() == QDialog::Accepted)
{
done(QDialog::Accepted);
}
event->accept();
}
void ConfigDialog::createIcons()
{
QListWidgetItem *configButton = new QListWidgetItem(contentsWidget);
Q_CHECK_PTR(configButton);
configButton->setIcon(QIcon("://icon/config.png"));
configButton->setText(tr("Configuration"));
configButton->setTextAlignment(Qt::AlignHCenter);
configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem *patternButton = new QListWidgetItem(contentsWidget);
Q_CHECK_PTR(patternButton);
patternButton->setIcon(QIcon("://icon/pattern_config.png"));
patternButton->setText(tr("Pattern"));
patternButton->setTextAlignment(Qt::AlignHCenter);
patternButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
connect(contentsWidget, &QListWidget::currentItemChanged, this, &ConfigDialog::changePage);
}
void ConfigDialog::Apply()
{
switch(contentsWidget->currentRow())
{
case(0):
configurationPage->Apply();
break;
case(1):
patternPage->Apply();
break;
default:
break;
}
setResult(QDialog::Accepted);
}
void ConfigDialog::Ok()
{
Apply();
done(QDialog::Accepted);
}

View File

@ -0,0 +1,59 @@
/************************************************************************
**
** @file configdialog.h
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 12 2, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
#include <QDialog>
#include <QListWidget>
#include "pages.h"
class QListWidgetItem;
class QStackedWidget;
class ConfigDialog : public QDialog
{
Q_OBJECT
public:
explicit ConfigDialog(QWidget *parent = 0);
public slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
protected:
virtual void closeEvent(QCloseEvent *event);
private:
Q_DISABLE_COPY(ConfigDialog)
QListWidget *contentsWidget;
QStackedWidget *pagesWidget;
ConfigurationPage *configurationPage;
PatternPage *patternPage;
void createIcons();
void Apply();
void Ok();
};
#endif // CONFIGDIALOG_H

View File

@ -51,5 +51,6 @@
#include "dialoguniondetails.h"
#include "dialogtriangle.h"
#include "dialogpointofintersection.h"
#include "configdialog.h"
#endif // DIALOGS_H

View File

@ -22,7 +22,9 @@ HEADERS += \
src/dialogs/dialogcutspline.h \
src/dialogs/dialogcutsplinepath.h \
src/dialogs/dialoguniondetails.h \
src/dialogs/dialogcutarc.h
src/dialogs/dialogcutarc.h \
src/dialogs/configdialog.h \
src/dialogs/pages.h
SOURCES += \
src/dialogs/dialogtriangle.cpp \
@ -47,7 +49,9 @@ SOURCES += \
src/dialogs/dialogcutspline.cpp \
src/dialogs/dialogcutsplinepath.cpp \
src/dialogs/dialoguniondetails.cpp \
src/dialogs/dialogcutarc.cpp
src/dialogs/dialogcutarc.cpp \
src/dialogs/configdialog.cpp \
src/dialogs/pages.cpp
FORMS += \
src/dialogs/dialogtriangle.ui \

295
src/dialogs/pages.cpp Normal file
View File

@ -0,0 +1,295 @@
/************************************************************************
**
** @file pages.cpp
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 12 2, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "pages.h"
#include <stdlib.h> //for user name
ConfigurationPage::ConfigurationPage(QWidget *parent):
QWidget(parent), autoSaveCheck(0), autoTime(0), langCombo(0), osOptionCheck(0), langChanged(false)
{
QGroupBox *saveGroup = SaveGroup();
QGroupBox *langGroup = LangGroup();
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(saveGroup);
mainLayout->addWidget(langGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
void ConfigurationPage::Apply()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked());
settings.setValue("configuration/autosave/time", autoTime->value());
//settings.setValue("configuration/osSeparator", osOptionCheck->isChecked());
if (langChanged)
{
QString locale = qvariant_cast<QString>(langCombo->itemData(langCombo->currentIndex()));
settings.setValue("configuration/locale", locale);
langChanged = false;
QString text = QString(tr("Setup user interface language updated and will be used the next time start") + " " +
QApplication::applicationName());
QMessageBox::information(this, QApplication::applicationName(), text);
}
}
void ConfigurationPage::LangChenged()
{
langChanged = true;
}
QGroupBox *ConfigurationPage::SaveGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *saveGroup = new QGroupBox(tr("Save"));
Q_CHECK_PTR(saveGroup);
autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern"));
Q_CHECK_PTR(autoSaveCheck);
bool autoSaveValue = settings.value("configuration/autosave/state", 1).toBool();
autoSaveCheck->setChecked(autoSaveValue);
QLabel *intervalLabel = new QLabel(tr("Interval:"));
Q_CHECK_PTR(intervalLabel);
autoTime = new QSpinBox();
Q_CHECK_PTR(autoTime);
bool ok = true;
qint32 autoTimeValue = settings.value("configuration/autosave/time", 5).toInt(&ok);
if (ok == false)
{
autoTimeValue = 5;
}
autoTime->setValue(autoTimeValue);
autoTime->setSuffix(tr("min"));
QHBoxLayout *autosaveLayout = new QHBoxLayout;
Q_CHECK_PTR(autosaveLayout);
autosaveLayout->addWidget(autoSaveCheck);
autosaveLayout->addWidget(intervalLabel);
autosaveLayout->addWidget(autoTime);
QVBoxLayout *saveLayout = new QVBoxLayout;
Q_CHECK_PTR(saveLayout);
saveLayout->addLayout(autosaveLayout);
saveGroup->setLayout(saveLayout);
return saveGroup;
}
QGroupBox *ConfigurationPage::LangGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *langGroup = new QGroupBox(tr("Language"));
Q_CHECK_PTR(langGroup);
QLabel *guiLabel = new QLabel(tr("GUI language"));
Q_CHECK_PTR(guiLabel);
langCombo = new QComboBox;
Q_CHECK_PTR(langCombo);
// format systems language
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString();
QString m_langPath = QApplication::applicationDirPath();
m_langPath.append("/translations");
QDir dir(m_langPath);
QStringList fileNames = dir.entryList(QStringList("valentina_*.qm"));
for (int i = 0; i < fileNames.size(); ++i)
{
// get locale extracted by filename
QString locale;
locale = fileNames[i]; // "valentina_de.qm"
locale.truncate(locale.lastIndexOf('.')); // "valentina_de"
locale.remove(0, locale.indexOf('_') + 1); // "de"
QString lang = QLocale(locale).nativeLanguageName();
QIcon ico(QString("%1/%2.png").arg("://icon/flags").arg(locale));
langCombo->addItem(ico, lang, locale);
}
// set default translators and language checked
qint32 index = langCombo->findData(checkedLocale);
if (index != -1)
{
langCombo->setCurrentIndex(index);
}
connect(langCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&ConfigurationPage::LangChenged);
QHBoxLayout *guiLangLayout = new QHBoxLayout;
Q_CHECK_PTR(guiLangLayout);
guiLangLayout->addWidget(guiLabel);
guiLangLayout->addWidget(langCombo);
QLabel *separatorLabel = new QLabel(tr("Decimal separator parts"));
Q_CHECK_PTR(separatorLabel);
osOptionCheck = new QCheckBox(tr("With OS options (.)"));
Q_CHECK_PTR(osOptionCheck);
//bool osOptionValue = settings.value("configuration/osSeparator", 1).toBool();
//osOptionCheck->setChecked(osOptionValue);
osOptionCheck->setEnabled(false);
QHBoxLayout *separatorLayout = new QHBoxLayout;
Q_CHECK_PTR(separatorLayout);
separatorLayout->addWidget(separatorLabel);
separatorLayout->addWidget(osOptionCheck);
QVBoxLayout *langLayout = new QVBoxLayout;
Q_CHECK_PTR(langLayout);
langLayout->addLayout(guiLangLayout);
langLayout->addLayout(separatorLayout);
langGroup->setLayout(langLayout);
return langGroup;
}
PatternPage::PatternPage(QWidget *parent):
QWidget(parent), userName(0), graphOutputCheck(0), undoneCount(0)
{
QGroupBox *userGroup = UserGroup();
QGroupBox *graphOutputGroup = GraphOutputGroup();
QGroupBox *undoneGroup = UndoneGroup();
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(userGroup);
mainLayout->addWidget(graphOutputGroup);
mainLayout->addWidget(undoneGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
void PatternPage::Apply()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
settings.setValue("pattern/user", userName->text());
//settings.setValue("pattern/graphicalOutput", graphOutputCheck->isChecked());
settings.setValue("pattern/undone", undoneCount->value());
}
QGroupBox *PatternPage::UserGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *userGroup = new QGroupBox(tr("User"));
Q_CHECK_PTR(userGroup);
QLabel *nameLabel = new QLabel(tr("User name"));
Q_CHECK_PTR(nameLabel);
userName = new QLineEdit;
Q_CHECK_PTR(userName);
#ifdef Q_OS_WIN32
QString user = settings.value("pattern/user", getenv("USERNAME")).toString(&ok);
#else
QString user = settings.value("pattern/user", getenv("USER")).toString();
#endif
userName->setText(user);
QHBoxLayout *nameLayout = new QHBoxLayout;
Q_CHECK_PTR(nameLayout);
nameLayout->addWidget(nameLabel);
nameLayout->addWidget(userName);
QVBoxLayout *userLayout = new QVBoxLayout;
Q_CHECK_PTR(userLayout);
userLayout->addLayout(nameLayout);
userGroup->setLayout(userLayout);
return userGroup;
}
QGroupBox *PatternPage::GraphOutputGroup()
{
// QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
// QApplication::applicationName());
QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output"));
Q_CHECK_PTR(graphOutputGroup);
graphOutputCheck = new QCheckBox(tr("Use antialiasing"));
Q_CHECK_PTR(graphOutputCheck);
//bool graphOutputValue = settings.value("pattern/graphicalOutput", 1).toBool();
//graphOutputCheck->setChecked(graphOutputValue);
graphOutputCheck->setEnabled(false);
QHBoxLayout *graphLayout = new QHBoxLayout;
Q_CHECK_PTR(graphLayout);
graphLayout->addWidget(graphOutputCheck);
QVBoxLayout *graphOutputLayout = new QVBoxLayout;
Q_CHECK_PTR(graphOutputLayout);
graphOutputLayout->addLayout(graphLayout);
graphOutputGroup->setLayout(graphOutputLayout);
return graphOutputGroup;
}
QGroupBox *PatternPage::UndoneGroup()
{
// QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
// QApplication::applicationName());
QGroupBox *undoneGroup = new QGroupBox(tr("Undone"));
Q_CHECK_PTR(undoneGroup);
QLabel *undoneLabel = new QLabel(tr("Count steps"));
Q_CHECK_PTR(undoneLabel);
undoneCount = new QSpinBox;
Q_CHECK_PTR(undoneCount);
// bool ok = true;
// qint32 count = settings.value("pattern/undone", 100).toInt(&ok);
// if (ok == false)
// {
// count = 100;
// }
// undoneCount->setValue(count);
undoneCount->setEnabled(false);
QHBoxLayout *countLayout = new QHBoxLayout;
Q_CHECK_PTR(countLayout);
countLayout->addWidget(undoneLabel);
countLayout->addWidget(undoneCount);
QVBoxLayout *undoneLayout = new QVBoxLayout;
Q_CHECK_PTR(undoneLayout);
undoneLayout->addLayout(countLayout);
undoneGroup->setLayout(undoneLayout);
return undoneGroup;
}

68
src/dialogs/pages.h Normal file
View File

@ -0,0 +1,68 @@
/************************************************************************
**
** @file pages.h
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 12 2, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef PAGES_H
#define PAGES_H
#include <QtWidgets>
class ConfigurationPage : public QWidget
{
Q_OBJECT
public:
ConfigurationPage(QWidget *parent = 0);
void Apply();
public slots:
void LangChenged();
private:
Q_DISABLE_COPY(ConfigurationPage)
QCheckBox *autoSaveCheck;
QSpinBox *autoTime;
QComboBox *langCombo;
QCheckBox *osOptionCheck;
bool langChanged;
QGroupBox *SaveGroup();
QGroupBox *LangGroup();
};
class PatternPage : public QWidget
{
public:
PatternPage(QWidget *parent = 0);
void Apply();
private:
Q_DISABLE_COPY(PatternPage)
QLineEdit *userName;
QCheckBox *graphOutputCheck;
QSpinBox *undoneCount;
QGroupBox *UserGroup();
QGroupBox *GraphOutputGroup();
QGroupBox *UndoneGroup();
};
#endif // PAGES_H

View File

@ -67,28 +67,33 @@ int main(int argc, char *argv[])
qInstallMessageHandler(myMessageOutput);
VApplication app(argc, argv);
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator appTranslator;
#ifdef Q_OS_WIN32
appTranslator.load("valentina_" + QLocale::system().name(), ".");
#else
#ifdef QT_DEBUG
appTranslator.load("valentina_" + QLocale::system().name(), ".");
#else
appTranslator.load("valentina_" + QLocale::system().name(), "/usr/share/valentina/translations");
#endif
#endif
app.installTranslator(&appTranslator);
app.setApplicationDisplayName("Valentina");
app.setApplicationName("Valentina");
app.setOrganizationName("ValentinaTeam");
app.setOrganizationDomain("valentinaproject.bitbucket.org");
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString();
QTranslator qtTranslator;
qtTranslator.load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator appTranslator;
#ifdef Q_OS_WIN32
appTranslator.load("valentina_" + checkedLocale, "./translations");
#else
#ifdef QT_DEBUG
appTranslator.load("valentina_" + checkedLocale, "./translations");
#else
appTranslator.load("valentina_" + checkedLocale, "/usr/share/valentina/translations");
#endif
#endif
app.installTranslator(&appTranslator);
MainWindow w;
w.setWindowState(w.windowState() ^ Qt::WindowMaximized);
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));

View File

@ -79,7 +79,8 @@ MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0),
sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0),
dialogTool(0), dialogHistory(0), comboBoxDraws(0), curFile(QString()), mode(Draw::Calculation),
currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{0,0,0,0,0}, separatorAct(0)
currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{0,0,0,0,0}, separatorAct(0),
autoSaveTimer(0)
{
CreateActions();
CreateMenus();
@ -131,11 +132,7 @@ MainWindow::MainWindow(QWidget *parent)
doc->CreateEmptyFile();
connect(doc, &VDomDocument::patternChanged, this, &MainWindow::PatternWasModified);
//Autosaving file each 5 minutes
QTimer *timer = new QTimer(this);
timer->setTimerType(Qt::VeryCoarseTimer);
connect(timer, &QTimer::timeout, this, &MainWindow::AutoSavePattern);
timer->start(300000);
InitAutoSave();
ui->toolBox->setCurrentIndex(0);
@ -513,11 +510,13 @@ void MainWindow::ClosedDialogCutArc(int result)
void MainWindow::About()
{
QDate date = QLocale(QLocale::C).toDate(QString(__DATE__).simplified(), QLatin1String("MMM d yyyy"));
QString fullName = QString("Valentina %1").arg(APP_VERSION);
QString qtBase(tr("Based on Qt %2 (32 bit)").arg(QT_VERSION_STR));
QString buildOn(tr("Built on %3 at %4").arg(__DATE__).arg(__TIME__));
QString about = QString(tr("<h1>%1</h1> %2 <br/><br/> %3 <br/><br/> %4")).arg(fullName).arg(qtBase).arg(
buildOn).arg(WARRANTY);
QString buildOn(tr("Built on %3 at %4").arg(date.toString()).arg(__TIME__));
QString about = QString(tr("<h1>%1</h1> %2 <br/><br/> %3 <br/><br/> %4")).arg(fullName).arg(qtBase).arg(buildOn)
.arg(WARRANTY);
QMessageBox::about(this, tr("About Valentina"), about);
}
@ -969,6 +968,15 @@ void MainWindow::Open()
}
}
void MainWindow::Options()
{
ConfigDialog dlg(this);
if (dlg.exec() == QDialog::Accepted)
{
InitAutoSave();
}
}
void MainWindow::Clear()
{
setCurrentFile("");
@ -1393,6 +1401,7 @@ void MainWindow::CreateActions()
connect(ui->actionAbout_Qt, &QAction::triggered, this, &MainWindow::AboutQt);
connect(ui->actionAbout_Valentina, &QAction::triggered, this, &MainWindow::About);
connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
connect(ui->actionOptions, &QAction::triggered, this, &MainWindow::Options);
//Actions for recent files loaded by a main window application.
for (int i = 0; i < MaxRecentFiles; ++i)
@ -1404,6 +1413,32 @@ void MainWindow::CreateActions()
}
}
void MainWindow::InitAutoSave()
{
//Autosaving file each 5 minutes
delete autoSaveTimer;
autoSaveTimer = 0;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool autoSave = settings.value("configuration/autosave/state", 1).toBool();
if (autoSave)
{
bool ok = true;
qint32 autoTime = settings.value("configuration/autosave/time", 5).toInt(&ok);
if (ok == false)
{
autoTime = 5;
}
autoSaveTimer = new QTimer(this);
Q_CHECK_PTR(autoSaveTimer);
autoSaveTimer->setTimerType(Qt::VeryCoarseTimer);
connect(autoSaveTimer, &QTimer::timeout, this, &MainWindow::AutoSavePattern);
autoSaveTimer->start(autoTime*60000);
}
}
MainWindow::~MainWindow()
{
CancelTool();

View File

@ -100,6 +100,10 @@ public slots:
* @brief Open ask user select pattern file.
*/
void Open();
/**
* @brief Options config dialog.
*/
void Options();
/**
* @brief NewPattern create new empty pattern.
*/
@ -460,6 +464,7 @@ private:
enum { MaxRecentFiles = 5 };
QAction *recentFileActs[MaxRecentFiles];
QAction *separatorAct;
QTimer *autoSaveTimer;
/**
* @brief ToolBarOption enable option toolbar.
*/
@ -564,6 +569,7 @@ private:
void UpdateRecentFileActions();
void CreateMenus();
void CreateActions();
void InitAutoSave();
};
#endif // MAINWINDOW_H

View File

@ -47,7 +47,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>144</width>
<height>150</height>
</rect>
</property>
@ -302,7 +302,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>100</width>
<height>58</height>
</rect>
</property>
@ -378,7 +378,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>100</width>
<height>104</height>
</rect>
</property>
@ -579,7 +579,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>100</width>
<height>58</height>
</rect>
</property>
@ -694,6 +694,8 @@
<addaction name="actionTable"/>
<addaction name="actionHistory"/>
<addaction name="actionLayout"/>
<addaction name="separator"/>
<addaction name="actionOptions"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuDrawing"/>
@ -986,6 +988,11 @@
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionOptions">
<property name="text">
<string>Options...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>