2014-02-14 12:29:04 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file configdialog.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-02-14 12:29:04 +01:00
|
|
|
** @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.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-02-14 12:29:04 +01:00
|
|
|
** <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"
|
2014-06-17 11:50:11 +02:00
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
2014-07-13 14:49:00 +02:00
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QCloseEvent>
|
2015-06-19 13:21:46 +02:00
|
|
|
#include "../core/vapplication.h"
|
2014-02-14 12:29:04 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-14 12:29:04 +01:00
|
|
|
ConfigDialog::ConfigDialog(QWidget *parent) :
|
2014-06-17 11:50:11 +02:00
|
|
|
QDialog(parent), contentsWidget(nullptr), pagesWidget(nullptr), configurationPage(nullptr), patternPage(nullptr),
|
2016-01-06 06:34:30 +01:00
|
|
|
communityPage(nullptr), pathPage(nullptr), applyButton(nullptr), cancelButton(nullptr), okButton(nullptr),
|
|
|
|
isInitialized(false)
|
2014-02-14 12:29:04 +01:00
|
|
|
{
|
|
|
|
contentsWidget = new QListWidget;
|
|
|
|
contentsWidget->setViewMode(QListView::IconMode);
|
|
|
|
contentsWidget->setIconSize(QSize(96, 84));
|
|
|
|
contentsWidget->setMovement(QListView::Static);
|
|
|
|
contentsWidget->setMaximumWidth(128);
|
2016-01-06 07:49:44 +01:00
|
|
|
contentsWidget->setMinimumWidth(128);
|
2014-06-22 18:46:47 +02:00
|
|
|
contentsWidget->setMinimumHeight(500);
|
2014-02-14 12:29:04 +01:00
|
|
|
contentsWidget->setSpacing(12);
|
|
|
|
|
|
|
|
pagesWidget = new QStackedWidget;
|
2014-06-22 18:46:47 +02:00
|
|
|
|
2014-02-14 12:29:04 +01:00
|
|
|
configurationPage = new ConfigurationPage();
|
|
|
|
pagesWidget->addWidget(configurationPage);
|
2014-06-22 18:46:47 +02:00
|
|
|
|
2014-02-14 12:29:04 +01:00
|
|
|
patternPage = new PatternPage();
|
|
|
|
pagesWidget->addWidget(patternPage);
|
2014-06-22 18:46:47 +02:00
|
|
|
|
2014-06-15 21:30:26 +02:00
|
|
|
communityPage = new CommunityPage();
|
|
|
|
pagesWidget->addWidget(communityPage);
|
2014-02-14 12:29:04 +01:00
|
|
|
|
2014-06-22 18:46:47 +02:00
|
|
|
pathPage = new PathPage();
|
|
|
|
pagesWidget->addWidget(pathPage);
|
|
|
|
|
2016-01-06 06:34:30 +01:00
|
|
|
applyButton = new QPushButton(tr("Apply"));
|
|
|
|
cancelButton = new QPushButton(tr("&Cancel"));
|
|
|
|
okButton = new QPushButton(tr("&Ok"));
|
2014-02-14 12:29:04 +01:00
|
|
|
|
|
|
|
createIcons();
|
|
|
|
contentsWidget->setCurrentRow(0);
|
|
|
|
|
2015-12-01 21:53:29 +01:00
|
|
|
connect(cancelButton, &QPushButton::clicked, this, &ConfigDialog::close);
|
2014-02-14 12:29:04 +01:00
|
|
|
connect(applyButton, &QPushButton::clicked, this, &ConfigDialog::Apply);
|
|
|
|
connect(okButton, &QPushButton::clicked, this, &ConfigDialog::Ok);
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout = new QHBoxLayout;
|
|
|
|
horizontalLayout->addWidget(contentsWidget);
|
|
|
|
horizontalLayout->addWidget(pagesWidget, 1);
|
|
|
|
|
|
|
|
QHBoxLayout *buttonsLayout = new QHBoxLayout;
|
|
|
|
buttonsLayout->addStretch(1);
|
|
|
|
buttonsLayout->addWidget(applyButton);
|
2015-12-01 21:53:29 +01:00
|
|
|
buttonsLayout->addWidget(cancelButton);
|
2014-02-14 12:29:04 +01:00
|
|
|
buttonsLayout->addWidget(okButton);
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->addLayout(horizontalLayout);
|
2016-06-10 21:34:21 +02:00
|
|
|
mainLayout->addSpacing(12);
|
2014-02-14 12:29:04 +01:00
|
|
|
mainLayout->addLayout(buttonsLayout);
|
2016-06-09 13:16:04 +02:00
|
|
|
mainLayout->setStretch(0, 1);
|
2014-02-14 12:29:04 +01:00
|
|
|
setLayout(mainLayout);
|
|
|
|
|
|
|
|
setWindowTitle(tr("Config Dialog"));
|
2014-06-22 18:46:47 +02:00
|
|
|
|
2016-08-26 11:38:23 +02:00
|
|
|
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale::c());
|
2014-02-14 12:29:04 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-14 12:29:04 +01:00
|
|
|
void ConfigDialog::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
if (result() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
done(QDialog::Accepted);
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2016-01-06 06:34:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void ConfigDialog::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
{
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
RetranslateUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember to call base class implementation
|
|
|
|
QDialog::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-11-17 11:54:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void ConfigDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent( event );
|
|
|
|
if ( event->spontaneous() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInitialized)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// do your init stuff here
|
|
|
|
|
2016-06-10 21:34:21 +02:00
|
|
|
setMinimumSize(size());
|
|
|
|
|
|
|
|
QSize sz = qApp->Settings()->GetPreferenceDialogSize();
|
|
|
|
if (sz.isEmpty() == false)
|
2016-06-09 13:16:04 +02:00
|
|
|
{
|
2016-06-10 21:34:21 +02:00
|
|
|
resize(sz);
|
2016-06-09 13:16:04 +02:00
|
|
|
}
|
2015-11-17 11:54:18 +01:00
|
|
|
|
|
|
|
isInitialized = true;//first show windows are held
|
|
|
|
}
|
|
|
|
|
2016-06-09 13:16:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-06-10 21:34:21 +02:00
|
|
|
void ConfigDialog::resizeEvent(QResizeEvent *event)
|
2016-06-09 13:16:04 +02:00
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(event)
|
2016-06-10 21:34:21 +02:00
|
|
|
// 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());
|
|
|
|
}
|
2016-06-09 13:16:04 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-14 12:29:04 +01:00
|
|
|
void ConfigDialog::createIcons()
|
|
|
|
{
|
2014-06-22 18:46:47 +02:00
|
|
|
createIcon("://icon/config.png", tr("Configuration"));
|
|
|
|
createIcon("://icon/pattern_config.png", tr("Pattern"));
|
|
|
|
createIcon("://icon/community_config.png", tr("Community"));
|
|
|
|
createIcon("://icon/path_config.png", tr("Paths"));
|
2014-06-15 21:30:26 +02:00
|
|
|
|
2016-07-18 17:09:15 +02:00
|
|
|
connect(contentsWidget, &QListWidget::currentItemChanged,
|
|
|
|
[this](QListWidgetItem *current, QListWidgetItem *previous)
|
|
|
|
{
|
|
|
|
if (current == nullptr)
|
|
|
|
{
|
|
|
|
current = previous;
|
|
|
|
}
|
|
|
|
pagesWidget->setCurrentIndex(contentsWidget->row(current));
|
|
|
|
});
|
2014-02-14 12:29:04 +01:00
|
|
|
}
|
|
|
|
|
2014-06-22 18:46:47 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void ConfigDialog::createIcon(const QString &icon, const QString &text)
|
|
|
|
{
|
|
|
|
QListWidgetItem *button = new QListWidgetItem(contentsWidget);
|
|
|
|
button->setIcon(QIcon(icon));
|
|
|
|
button->setText(text);
|
|
|
|
button->setTextAlignment(Qt::AlignHCenter);
|
|
|
|
button->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-14 12:29:04 +01:00
|
|
|
void ConfigDialog::Apply()
|
|
|
|
{
|
2016-08-26 12:36:51 +02:00
|
|
|
configurationPage->Apply();
|
|
|
|
patternPage->Apply();
|
|
|
|
communityPage->Apply();
|
|
|
|
pathPage->Apply();
|
|
|
|
|
2016-08-26 11:38:23 +02:00
|
|
|
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale::c());
|
2015-02-10 18:50:47 +01:00
|
|
|
emit UpdateProperties();
|
2014-02-14 12:29:04 +01:00
|
|
|
setResult(QDialog::Accepted);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-14 12:29:04 +01:00
|
|
|
void ConfigDialog::Ok()
|
|
|
|
{
|
|
|
|
Apply();
|
|
|
|
done(QDialog::Accepted);
|
|
|
|
}
|
2016-01-06 06:34:30 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void ConfigDialog::RetranslateUi()
|
|
|
|
{
|
|
|
|
applyButton->setText(tr("Apply"));
|
|
|
|
cancelButton->setText(tr("&Cancel"));
|
|
|
|
okButton->setText(tr("&Ok"));
|
|
|
|
setWindowTitle(tr("Config Dialog"));
|
|
|
|
contentsWidget->item(0)->setText(tr("Configuration"));
|
|
|
|
contentsWidget->item(1)->setText(tr("Pattern"));
|
|
|
|
contentsWidget->item(2)->setText(tr("Community"));
|
|
|
|
contentsWidget->item(3)->setText(tr("Paths"));
|
|
|
|
}
|
|
|
|
|