2015-07-10 11:49:37 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file tmainwindow.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 10 7, 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) 2015 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 "tmainwindow.h"
|
|
|
|
#include "ui_tmainwindow.h"
|
2015-07-12 17:56:34 +02:00
|
|
|
#include "mapplication.h"
|
2015-07-12 19:38:30 +02:00
|
|
|
#include "dialogs/dialogabouttape.h"
|
2015-07-13 12:48:29 +02:00
|
|
|
#include "dialogs/dialognewmeasurements.h"
|
2015-07-10 11:49:37 +02:00
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMessageBox>
|
2015-07-21 15:18:10 +02:00
|
|
|
#include <QComboBox>
|
2015-07-18 14:39:33 +02:00
|
|
|
|
2015-07-10 11:49:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
TMainWindow::TMainWindow(QWidget *parent)
|
|
|
|
:QMainWindow(parent),
|
2015-07-15 09:16:59 +02:00
|
|
|
ui(new Ui::TMainWindow),
|
|
|
|
m(nullptr),
|
2015-07-16 11:38:54 +02:00
|
|
|
data(nullptr),
|
|
|
|
mUnit(Unit::Cm),
|
2015-07-18 14:39:33 +02:00
|
|
|
mType(MeasurementsType::Individual),
|
2015-07-21 15:18:10 +02:00
|
|
|
curFile(),
|
|
|
|
gradationHeights(nullptr),
|
|
|
|
gradationSizes(nullptr)
|
2015-07-10 11:49:37 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-07-10 13:22:46 +02:00
|
|
|
ui->tabWidget->setVisible(false);
|
2015-07-12 16:19:53 +02:00
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
ui->toolBarGradation->setVisible(false);
|
|
|
|
|
2015-07-12 16:19:53 +02:00
|
|
|
SetupMenu();
|
2015-07-18 14:50:34 +02:00
|
|
|
|
|
|
|
setWindowTitle(tr("untitled"));
|
2015-07-10 11:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
TMainWindow::~TMainWindow()
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
delete data;
|
|
|
|
delete m;
|
2015-07-10 11:49:37 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
2015-07-10 13:14:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::LoadFile(const QString &path)
|
2015-07-12 16:19:53 +02:00
|
|
|
{
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
ui->tabWidget->setVisible(true);
|
|
|
|
}
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::FileNew()
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
if (m == nullptr)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
DialogNewMeasurements measurements(this);
|
|
|
|
if (measurements.exec() == QDialog::Rejected)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
mUnit = measurements.MUnit();
|
|
|
|
mType = measurements.Type();
|
|
|
|
|
|
|
|
data = new VContainer(qApp->TrVars(), &mUnit);
|
2015-07-21 15:18:10 +02:00
|
|
|
data->SetHeight(measurements.BaseHeight());
|
|
|
|
data->SetSize(measurements.BaseSize());
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
m = new VMeasurements(mUnit, measurements.BaseSize(), measurements.BaseHeight(), data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m = new VMeasurements(mUnit, data);
|
|
|
|
}
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
SetCurrentFile("");
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
InitWindow();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
qApp->MainWindow()->FileNew();
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::FileOpen()
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
if (m == nullptr)
|
|
|
|
{
|
2015-07-12 17:56:34 +02:00
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
qApp->MainWindow()->FileOpen();
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
}
|
|
|
|
|
2015-07-18 15:01:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
if (MaybeSave())
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::FileSave()
|
|
|
|
{
|
2015-07-18 14:39:33 +02:00
|
|
|
if (curFile.isEmpty())
|
|
|
|
{
|
|
|
|
return FileSaveAs();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString error;
|
|
|
|
bool result = SaveMeasurements(curFile, error);
|
|
|
|
if (not result)
|
|
|
|
{
|
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
messageBox.setInformativeText(tr("Could not save file"));
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
messageBox.exec();
|
|
|
|
}
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::FileSaveAs()
|
|
|
|
{
|
2015-07-18 14:39:33 +02:00
|
|
|
QString filters;
|
|
|
|
QString fName = tr("measurements");
|
|
|
|
QString suffix;
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
filters = tr("Standard measurements (*.vst)");
|
|
|
|
suffix = "vst";
|
|
|
|
fName += "." + suffix;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filters = tr("Individual measurements (*.vit)");
|
|
|
|
suffix = "vit";
|
|
|
|
fName += "." + suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString dir;
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
{
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
dir = qApp->Settings()->GetPathStandardMeasurements() + "/" + fName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dir = qApp->Settings()->GetPathIndividualMeasurements() + "/" + fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dir = QFileInfo(curFile).absolutePath() + "/" + fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir, filters);
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
QFileInfo f( fileName );
|
|
|
|
if (f.suffix().isEmpty() && f.suffix() != suffix)
|
|
|
|
{
|
|
|
|
fileName += "." + suffix;
|
|
|
|
}
|
|
|
|
QString error;
|
|
|
|
bool result = SaveMeasurements(fileName, error);
|
|
|
|
if (result == false)
|
|
|
|
{
|
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
messageBox.setInformativeText(tr("Could not save file"));
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
messageBox.exec();
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::AboutToShowWindowMenu()
|
|
|
|
{
|
|
|
|
ui->menuWindow->clear();
|
2015-07-15 09:16:59 +02:00
|
|
|
QList<TMainWindow*> windows = qApp->MainWindows();
|
2015-07-12 17:56:34 +02:00
|
|
|
for (int i = 0; i < windows.count(); ++i)
|
|
|
|
{
|
|
|
|
TMainWindow *window = windows.at(i);
|
2015-07-18 14:50:34 +02:00
|
|
|
|
|
|
|
QString title = window->windowTitle();
|
|
|
|
const int index = title.lastIndexOf("[*]");
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
title.replace(index, 3, "*");
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *action = ui->menuWindow->addAction(title, this, SLOT(ShowWindow()));
|
2015-07-12 17:56:34 +02:00
|
|
|
action->setData(i);
|
|
|
|
action->setCheckable(true);
|
|
|
|
if (window == this)
|
|
|
|
{
|
|
|
|
action->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::ShowWindow()
|
|
|
|
{
|
|
|
|
if (QAction *action = qobject_cast<QAction*>(sender()))
|
|
|
|
{
|
|
|
|
const QVariant v = action->data();
|
|
|
|
if (v.canConvert<int>())
|
|
|
|
{
|
|
|
|
const int offset = qvariant_cast<int>(v);
|
2015-07-15 09:16:59 +02:00
|
|
|
QList<TMainWindow*> windows = qApp->MainWindows();
|
2015-07-12 17:56:34 +02:00
|
|
|
windows.at(offset)->activateWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::AboutApplication()
|
|
|
|
{
|
2015-07-12 19:38:30 +02:00
|
|
|
DialogAboutTape * aboutDialog = new DialogAboutTape(this);
|
|
|
|
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
aboutDialog->show();
|
2015-07-12 17:56:34 +02:00
|
|
|
}
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SaveGivenName()
|
|
|
|
{
|
|
|
|
m->SetGivenName(ui->lineEditGivenName->text());
|
2015-07-18 14:53:37 +02:00
|
|
|
MeasurementsWasSaved(false);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SaveFamilyName()
|
|
|
|
{
|
|
|
|
m->SetFamilyName(ui->lineEditFamilyName->text());
|
2015-07-18 14:53:37 +02:00
|
|
|
MeasurementsWasSaved(false);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SaveEmail()
|
|
|
|
{
|
|
|
|
m->SetEmail(ui->lineEditEmail->text());
|
2015-07-18 14:53:37 +02:00
|
|
|
MeasurementsWasSaved(false);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SaveSex(int index)
|
|
|
|
{
|
|
|
|
m->SetSex(static_cast<SexType>(ui->comboBoxSex->itemData(index).toInt()));
|
2015-07-18 14:53:37 +02:00
|
|
|
MeasurementsWasSaved(false);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SaveBirthDate(const QDate &date)
|
|
|
|
{
|
|
|
|
m->SetBirthDate(date);
|
2015-07-18 14:53:37 +02:00
|
|
|
MeasurementsWasSaved(false);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SaveNotes()
|
|
|
|
{
|
|
|
|
m->SetNotes(ui->plainTextEditNotes->toPlainText());
|
2015-07-18 14:53:37 +02:00
|
|
|
MeasurementsWasSaved(false);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::ReadOnly(bool ro)
|
|
|
|
{
|
|
|
|
ui->actionReadOnly->setChecked(ro);
|
|
|
|
if (ro)
|
|
|
|
{
|
|
|
|
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_locked.png"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_opened.png"));
|
|
|
|
}
|
|
|
|
m->SetReadOnly(ro);
|
2015-07-18 15:23:18 +02:00
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
|
|
ui->plainTextEditNotes->setDisabled(ro);
|
|
|
|
ui->actionAddCustom->setDisabled(ro);
|
|
|
|
ui->actionAddKnown->setDisabled(ro);
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
ui->lineEditGivenName->setDisabled(ro);
|
|
|
|
ui->lineEditFamilyName->setDisabled(ro);
|
|
|
|
ui->dateEditBirthDate->setDisabled(ro);
|
|
|
|
ui->comboBoxSex->setDisabled(ro);
|
|
|
|
ui->lineEditEmail->setDisabled(ro);
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::AddCustom()
|
|
|
|
{
|
|
|
|
ui->tableWidget->setFocus(Qt::OtherFocusReason);
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
const qint32 currentRow = ui->tableWidget->rowCount();
|
|
|
|
ui->tableWidget->insertRow( currentRow );
|
|
|
|
|
|
|
|
qint32 num = 1;
|
|
|
|
QString name;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
name = QString("@" + tr("M_%1")).arg(num);
|
|
|
|
num++;
|
|
|
|
} while (data->IsUnique(name) == false);
|
|
|
|
|
|
|
|
const int id = m->AddEmptyMeasurement(name);
|
|
|
|
|
|
|
|
VMeasurement *meash;
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
meash = new VMeasurement(name, 0, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meash = new VMeasurement(data, id, name, 0, "0");
|
|
|
|
}
|
|
|
|
data->AddVariable(name, meash);
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
AddCell(name, currentRow, 0, id); // name
|
|
|
|
AddCell("0", currentRow, 2); // value
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AddCell(name, currentRow, 0); // name
|
|
|
|
AddCell("0", currentRow, 1); // calculated value
|
|
|
|
AddCell("0", currentRow, 3); // base value
|
|
|
|
AddCell("0", currentRow, 4); // in sizes
|
|
|
|
AddCell("0", currentRow, 5); // in heights
|
|
|
|
}
|
|
|
|
|
|
|
|
//ui->toolButtonRemove->setEnabled(true);
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::AddKnown()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::ChangedSize(const QString &text)
|
|
|
|
{
|
|
|
|
data->SetSize(text.toInt());
|
|
|
|
RefreshData();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::ChangedHeight(const QString &text)
|
|
|
|
{
|
|
|
|
data->SetHeight(text.toInt());
|
|
|
|
RefreshData();
|
|
|
|
}
|
|
|
|
|
2015-07-12 16:19:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SetupMenu()
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2015-07-12 17:56:34 +02:00
|
|
|
// File
|
2015-07-13 12:48:29 +02:00
|
|
|
connect(ui->actionNew, &QAction::triggered, this, &TMainWindow::FileNew);
|
|
|
|
ui->actionNew->setShortcuts(QKeySequence::New);
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
connect(ui->actionOpen, &QAction::triggered, this, &TMainWindow::FileOpen);
|
|
|
|
ui->actionOpen->setShortcuts(QKeySequence::Open);
|
|
|
|
|
|
|
|
connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave);
|
2015-07-13 12:48:29 +02:00
|
|
|
ui->actionSave->setShortcuts(QKeySequence::Save);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
connect(ui->actionSaveAs, &QAction::triggered, this, &TMainWindow::FileSaveAs);
|
2015-07-13 12:48:29 +02:00
|
|
|
ui->actionSaveAs->setShortcuts(QKeySequence::SaveAs);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
connect(ui->actionReadOnly, &QAction::triggered, this, &TMainWindow::ReadOnly);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close);
|
|
|
|
ui->actionQuit->setShortcuts(QKeySequence::Quit);
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
// Measurements
|
|
|
|
connect(ui->actionAddCustom, &QAction::triggered, this, &TMainWindow::AddCustom);
|
|
|
|
connect(ui->actionAddKnown, &QAction::triggered, this, &TMainWindow::AddKnown);
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
// Window
|
|
|
|
connect(ui->menuWindow, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowWindowMenu);
|
|
|
|
AboutToShowWindowMenu();
|
2015-07-10 13:14:55 +02:00
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
// Help
|
|
|
|
connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
|
|
|
|
connect(ui->actionAboutTape, &QAction::triggered, this, &TMainWindow::AboutApplication);
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
void TMainWindow::InitWindow()
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2015-07-16 11:38:54 +02:00
|
|
|
SCASSERT(m != nullptr);
|
2015-07-13 12:48:29 +02:00
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
ui->tabWidget->setVisible(true);
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
ui->plainTextEditNotes->setEnabled(true);
|
2015-07-15 09:16:59 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
if (mType == MeasurementsType::Standard)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2015-07-14 18:28:50 +02:00
|
|
|
ui->labelMType->setText(tr("Standard measurements"));
|
2015-07-18 13:08:44 +02:00
|
|
|
ui->labelBaseSizeValue->setText(QString().setNum(m->BaseSize()) + " " +
|
|
|
|
VDomDocument::UnitsToStr(m->MUnit(), true));
|
|
|
|
ui->labelBaseHeightValue->setText(QString().setNum(m->BaseHeight()) + " " +
|
|
|
|
VDomDocument::UnitsToStr(m->MUnit(), true));
|
2015-07-14 18:28:50 +02:00
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
// Tab Measurements
|
|
|
|
delete ui->labelValue;
|
|
|
|
delete ui->horizontalLayoutValue;
|
2015-07-18 13:08:44 +02:00
|
|
|
delete ui->plainTextEditFormula;
|
|
|
|
delete ui->pushButtonGrowLength;
|
|
|
|
delete ui->toolButtonExprLength;
|
|
|
|
delete ui->labelEqual;
|
|
|
|
delete ui->labelResultCalculation;
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
|
|
// Tab Information
|
|
|
|
delete ui->labelGivenName;
|
|
|
|
delete ui->lineEditGivenName;
|
|
|
|
delete ui->labelFamilyName;
|
|
|
|
delete ui->lineEditFamilyName;
|
|
|
|
delete ui->labelBirthDate;
|
|
|
|
delete ui->dateEditBirthDate;
|
|
|
|
delete ui->labelSex;
|
|
|
|
delete ui->comboBoxSex;
|
|
|
|
delete ui->labelEmail;
|
|
|
|
delete ui->lineEditEmail;
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
|
|
ui->toolBarGradation->setVisible(true);
|
|
|
|
const QStringList listHeights = VMeasurement::WholeListHeights(mUnit);
|
|
|
|
const QStringList listSizes = VMeasurement::WholeListSizes(mUnit);
|
|
|
|
|
|
|
|
gradationHeights = SetGradationList(tr("Height: "), listHeights);
|
|
|
|
SetDefaultHeight(static_cast<int>(data->height()));
|
|
|
|
connect(gradationHeights, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &TMainWindow::ChangedHeight);
|
|
|
|
|
|
|
|
gradationSizes = SetGradationList(tr("Size: "), listSizes);
|
|
|
|
SetDefaultSize(static_cast<int>(data->size()));
|
|
|
|
connect(gradationSizes, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &TMainWindow::ChangedSize);
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-14 18:28:50 +02:00
|
|
|
ui->labelMType->setText(tr("Individual measurements"));
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
ui->lineEditGivenName->setEnabled(true);
|
|
|
|
ui->lineEditFamilyName->setEnabled(true);
|
|
|
|
ui->dateEditBirthDate->setEnabled(true);
|
|
|
|
ui->comboBoxSex->setEnabled(true);
|
|
|
|
ui->lineEditEmail->setEnabled(true);
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
// Tab Measurements
|
|
|
|
delete ui->labelBaseValue;
|
|
|
|
delete ui->doubleSpinBoxBaseValue;
|
|
|
|
delete ui->labelInSizes;
|
|
|
|
delete ui->doubleSpinBoxInSizes;
|
|
|
|
delete ui->labelInHeights;
|
|
|
|
delete ui->doubleSpinBoxInHeights;
|
|
|
|
|
|
|
|
// Tab Information
|
|
|
|
delete ui->labelBaseSize;
|
|
|
|
delete ui->labelBaseSizeValue;
|
|
|
|
delete ui->labelBaseHeight;
|
|
|
|
delete ui->labelBaseHeightValue;
|
2015-07-18 13:08:44 +02:00
|
|
|
|
|
|
|
ui->lineEditGivenName->setText(m->GivenName());
|
|
|
|
ui->lineEditFamilyName->setText(m->FamilyName());
|
|
|
|
|
|
|
|
ui->comboBoxSex->addItem(tr("male"), QVariant(static_cast<int>(SexType::Male)));
|
|
|
|
ui->comboBoxSex->addItem(tr("female"), QVariant(static_cast<int>(SexType::Female)));
|
|
|
|
const qint32 index = ui->comboBoxSex->findData(static_cast<int>(m->Sex()));
|
|
|
|
ui->comboBoxSex->setCurrentIndex(index);
|
|
|
|
|
|
|
|
ui->dateEditBirthDate->setDate(m->BirthDate());
|
|
|
|
ui->lineEditEmail->setText(m->Email());
|
|
|
|
ui->plainTextEditNotes->setPlainText(m->Notes());
|
|
|
|
|
|
|
|
connect(ui->lineEditGivenName, &QLineEdit::editingFinished, this, &TMainWindow::SaveGivenName);
|
|
|
|
connect(ui->lineEditFamilyName, &QLineEdit::editingFinished, this, &TMainWindow::SaveFamilyName);
|
|
|
|
connect(ui->lineEditEmail, &QLineEdit::editingFinished, this, &TMainWindow::SaveEmail);
|
|
|
|
connect(ui->comboBoxSex, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&TMainWindow::SaveSex);
|
|
|
|
connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate);
|
|
|
|
connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes);
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
ui->actionAddCustom->setEnabled(true);
|
|
|
|
ui->actionAddKnown->setEnabled(true);
|
|
|
|
ui->actionReadOnly->setEnabled(true);
|
2015-07-18 14:39:33 +02:00
|
|
|
ui->actionSaveAs->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
InitTable();
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
void TMainWindow::InitTable()
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2015-07-16 11:38:54 +02:00
|
|
|
if (mType == MeasurementsType::Standard)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2015-07-19 14:28:01 +02:00
|
|
|
ui->tableWidget->setColumnHidden( 2, true );// value
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-19 14:28:01 +02:00
|
|
|
ui->tableWidget->setColumnHidden( 1, true );// calculated value
|
|
|
|
ui->tableWidget->setColumnHidden( 3, true );// base value
|
|
|
|
ui->tableWidget->setColumnHidden( 4, true );// in sizes
|
|
|
|
ui->tableWidget->setColumnHidden( 5, true );// in heights
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::MeasurementsWasSaved(bool saved)
|
|
|
|
{
|
|
|
|
setWindowModified(!saved);
|
|
|
|
ui->actionSave->setEnabled(!saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SetCurrentFile(const QString &fileName)
|
|
|
|
{
|
|
|
|
curFile = fileName;
|
|
|
|
QString shownName = QFileInfo(curFile).fileName();
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
{
|
|
|
|
shownName = tr("untitled");
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
shownName += ".vst";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shownName += ".vit";
|
|
|
|
}
|
|
|
|
ui->labelPathToFile->setText(tr("<Empty>"));
|
|
|
|
ui->pushButtonShowInFolder->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->labelPathToFile->setText(curFile);
|
|
|
|
ui->pushButtonShowInFolder->setEnabled(true);
|
|
|
|
}
|
|
|
|
shownName += "[*]";
|
|
|
|
setWindowTitle(shownName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool TMainWindow::SaveMeasurements(const QString &fileName, QString &error)
|
|
|
|
{
|
|
|
|
const bool result = m->SaveDocument(fileName, error);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
SetCurrentFile(fileName);
|
|
|
|
MeasurementsWasSaved(result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-07-18 15:01:57 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool TMainWindow::MaybeSave()
|
|
|
|
{
|
|
|
|
if (this->isWindowModified())
|
|
|
|
{
|
|
|
|
QMessageBox::StandardButton ret;
|
|
|
|
ret = QMessageBox::warning(this, tr("Unsaved changes"), tr("Measurements have been modified.\n"
|
|
|
|
"Do you want to save your changes?"),
|
|
|
|
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
|
|
if (ret == QMessageBox::Save)
|
|
|
|
{
|
|
|
|
FileSave();
|
|
|
|
}
|
|
|
|
else if (ret == QMessageBox::Cancel)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::AddCell(const QString &text, int row, int column, int id)
|
|
|
|
{
|
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(text);
|
|
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
// set the item non-editable (view only), and non-selectable
|
|
|
|
Qt::ItemFlags flags = item->flags();
|
|
|
|
flags &= ~(Qt::ItemIsEditable); // reset/clear the flag
|
|
|
|
item->setFlags(flags);
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual && id >= 0)
|
|
|
|
{
|
|
|
|
item->setData(Qt::UserRole, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->tableWidget->setItem(row, column, item);
|
|
|
|
}
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QComboBox *TMainWindow::SetGradationList(const QString &label, const QStringList &list)
|
|
|
|
{
|
|
|
|
ui->toolBarGradation->addWidget(new QLabel(label));
|
|
|
|
|
|
|
|
QComboBox *comboBox = new QComboBox;
|
|
|
|
comboBox->addItems(list);
|
|
|
|
ui->toolBarGradation->addWidget(comboBox);
|
|
|
|
|
|
|
|
return comboBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SetDefaultHeight(int value)
|
|
|
|
{
|
|
|
|
const qint32 index = gradationHeights->findText(QString("%1").arg(value));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
gradationHeights->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data->SetHeight(gradationHeights->currentText().toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::SetDefaultSize(int value)
|
|
|
|
{
|
|
|
|
const qint32 index = gradationSizes->findText(QString("%1").arg(value));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
gradationSizes->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data->SetSize(gradationSizes->currentText().toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TMainWindow::RefreshData()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|