/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox 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.
**
** Tox 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 "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "geometry/vspline.h"
#include
#include "exception/vexceptionobjecterror.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongparameterid.h"
#include "exception/vexceptionuniqueid.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0),
sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0),
dialogEndLine(QSharedPointer()), dialogLine(QSharedPointer()),
dialogAlongLine(QSharedPointer()),
dialogShoulderPoint(QSharedPointer()), dialogNormal(QSharedPointer()),
dialogBisector(QSharedPointer()),
dialogLineIntersect(QSharedPointer()), dialogSpline(QSharedPointer()),
dialogArc(QSharedPointer()), dialogSplinePath(QSharedPointer()),
dialogPointOfContact(QSharedPointer()),
dialogDetail(QSharedPointer()), dialogHeight(QSharedPointer()),
dialogTriangle(QSharedPointer()),
dialogPointOfIntersection(QSharedPointer()),
dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation){
ui->setupUi(this);
ToolBarOption();
ToolBarDraws();
QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize);
sceneDraw = new VMainGraphicsScene(sceneRect);
currentScene = sceneDraw;
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
sceneDetails = new VMainGraphicsScene(sceneRect);
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
view = new VMainGraphicsView();
ui->LayoutView->addWidget(view);
view->setScene(currentScene);
connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
view->setSizePolicy(policy);
helpLabel = new QLabel(tr("Create new drawing for start working."));
ui->statusBar->addWidget(helpLabel);
connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::ActionAroowTool);
connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::ActionDraw);
connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails);
connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::ActionNewDraw);
connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::OptionDraw);
connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::ActionSaveAs);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::ActionSave);
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::ActionOpen);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::ActionNew);
connect(ui->actionTable, &QAction::triggered, this, &MainWindow::ActionTable);
connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine);
connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine);
connect(ui->toolButtonAlongLine, &QToolButton::clicked, this, &MainWindow::ToolAlongLine);
connect(ui->toolButtonShoulderPoint, &QToolButton::clicked, this, &MainWindow::ToolShoulderPoint);
connect(ui->toolButtonNormal, &QToolButton::clicked, this, &MainWindow::ToolNormal);
connect(ui->toolButtonBisector, &QToolButton::clicked, this, &MainWindow::ToolBisector);
connect(ui->toolButtonLineIntersect, &QToolButton::clicked, this, &MainWindow::ToolLineIntersect);
connect(ui->toolButtonSpline, &QToolButton::clicked, this, &MainWindow::ToolSpline);
connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc);
connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath);
connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact);
connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail);
connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight);
connect(ui->toolButtonTriangle, &QToolButton::clicked, this, &MainWindow::ToolTriangle);
connect(ui->toolButtonPointOfIntersection, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersection);
data = new VContainer;
doc = new VDomDocument(data, comboBoxDraws, &mode);
doc->CreateEmptyFile();
connect(doc, &VDomDocument::haveChange, this, &MainWindow::haveChange);
fileName.clear();
changeInFile = false;
//Autosaving file each 5 minutes
QTimer *timer = new QTimer(this);
timer->setTimerType(Qt::VeryCoarseTimer);
connect(timer, &QTimer::timeout, this, &MainWindow::AutoSavePattern);
timer->start(300000);
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);
ui->toolBox->setCurrentIndex(0);
}
void MainWindow::ActionNewDraw(){
QString nameDraw;
bool bOk;
qint32 index;
QString nDraw = QString(tr("Drawing %1")).arg(comboBoxDraws->count()+1);
QInputDialog *dlg = new QInputDialog(this);
dlg->setInputMode( QInputDialog::TextInput );
dlg->setLabelText(tr("Drawing:"));
dlg->setTextEchoMode(QLineEdit::Normal);
dlg->setWindowTitle(tr("Enter a name for the drawing."));
dlg->resize(300,100);
dlg->setTextValue(nDraw);
while(1){
bOk = dlg->exec();
nameDraw = dlg->textValue();
if(!bOk || nameDraw.isEmpty()){
delete dlg;
return;
}
index = comboBoxDraws->findText(nameDraw);
if(index != -1){//we already have this name
qCritical()<appendDraw(nameDraw);
if(bOk == false){
qCritical()<
(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
comboBoxDraws->addItem(nameDraw);
index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index);
currentDrawChanged( index );
}
connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
data->ClearObject();
//Create single point
qint64 id = data->AddPoint(VPointF((10+comboBoxDraws->count()*5)*PrintDPI/25.4, 10*PrintDPI/25.4, "А", 5,
10));
VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui);
sceneDraw->addItem(spoint);
connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem);
connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
QHash* tools = doc->getTools();
tools->insert(id, spoint);
VDrawTool::AddRecord(id, Tool::SinglePointTool, doc);
SetEnableTool(true);
SetEnableWidgets(true);
changeInFile = true;
}
void MainWindow::OptionDraw(){
QString nameDraw;
bool bOk;
qint32 index;
QString nDraw = doc->GetNameActivDraw();
QInputDialog *dlg = new QInputDialog(this);
dlg->setInputMode( QInputDialog::TextInput );
dlg->setLabelText(tr("Drawing:"));
dlg->setTextEchoMode(QLineEdit::Normal);
dlg->setWindowTitle(tr("Enter a new name for the drawing."));
dlg->resize(300,100);
dlg->setTextValue(nDraw);
while(1){
bOk = dlg->exec();
nameDraw = dlg->textValue();
if(!bOk || nameDraw.isEmpty()){
delete dlg;
return;
}
index = comboBoxDraws->findText(nameDraw);
if(index != -1){//we already have this name
qCritical()<findText(doc->GetNameActivDraw());
if(doc->SetNameDraw(nameDraw)){
comboBoxDraws->setItemText(index, nameDraw);
} else {
QMessageBox::warning(this, tr("Error saving change!!!"), tr("Can't save new name of drawing"));
}
}
template
void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor,
const QString &toolTip, QSharedPointer