valentina/mainwindow.cpp

922 lines
36 KiB
C++
Raw Normal View History

2013-06-20 16:09:50 +02:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2013-07-03 14:29:26 +02:00
#include <QLabel>
#include <QSpinBox>
#include <QScrollBar>
#include <QShowEvent>
2013-07-13 12:51:31 +02:00
#include <QDebug>
#include <QInputDialog>
#include <QFileDialog>
2013-07-25 14:00:51 +02:00
#include <QDebug>
2013-07-03 14:29:26 +02:00
#include "options.h"
2013-07-25 14:00:51 +02:00
#include "tools/vtoolendline.h"
2013-07-25 20:39:51 +02:00
#include "tools/vtoolline.h"
2013-07-28 00:18:06 +02:00
#include "tools/vtoolalongline.h"
2013-07-29 14:55:40 +02:00
#include "tools/vtoolshoulderpoint.h"
2013-07-30 15:09:34 +02:00
#include "tools/vtoolnormal.h"
2013-07-30 20:46:40 +02:00
#include "tools/vtoolbisector.h"
2013-07-31 13:34:39 +02:00
#include "tools/vtoollineintersect.h"
2013-06-20 16:09:50 +02:00
MainWindow::MainWindow(QWidget *parent) :
2013-07-03 14:29:26 +02:00
QMainWindow(parent), ui(new Ui::MainWindow)
2013-06-20 16:09:50 +02:00
{
ui->setupUi(this);
2013-07-13 12:51:31 +02:00
tool = Tools::ArrowTool;
2013-07-03 14:29:26 +02:00
isInitialized = false;
ToolBarOption();
ToolBarDraws();
2013-07-13 12:51:31 +02:00
QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize);
2013-07-03 14:29:26 +02:00
scene = new VMainGraphicsScene(sceneRect);
ui->graphicsView->setScene(scene);
connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
connect(ui->toolButtonSinglePoint, &QToolButton::clicked, this,
2013-07-25 14:00:51 +02:00
&MainWindow::ToolSinglePoint);
2013-07-03 14:29:26 +02:00
helpLabel = new QLabel("Створіть новий файл для початку роботи.");
ui->statusBar->addWidget(helpLabel);
2013-07-25 14:00:51 +02:00
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);
2013-07-25 20:39:51 +02:00
connect(ui->toolButtonLine, &QToolButton::clicked, this,
&MainWindow::ToolLine);
2013-07-28 00:18:06 +02:00
connect(ui->toolButtonAlongLine, &QToolButton::clicked, this,
&MainWindow::ToolAlongLine);
2013-07-29 14:55:40 +02:00
connect(ui->toolButtonShoulderPoint, &QToolButton::clicked, this,
&MainWindow::ToolShoulderPoint);
2013-07-30 15:09:34 +02:00
connect(ui->toolButtonNormal, &QToolButton::clicked, this,
&MainWindow::ToolNormal);
2013-07-30 20:46:40 +02:00
connect(ui->toolButtonBisector, &QToolButton::clicked, this,
&MainWindow::ToolBisector);
2013-07-31 13:34:39 +02:00
connect(ui->toolButtonLineIntersect, &QToolButton::clicked, this,
&MainWindow::ToolLineIntersect);
2013-07-13 12:51:31 +02:00
data = new VContainer;
2013-07-17 13:38:11 +02:00
CreateManTableIGroup ();
2013-07-13 12:51:31 +02:00
doc = new VDomDocument(data);
doc->CreateEmptyFile();
connect(doc, &VDomDocument::haveChange, this, &MainWindow::haveChange);
fileName.clear();
changeInFile = false;
2013-07-25 14:00:51 +02:00
2013-07-13 12:51:31 +02:00
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionNewDraw(){
2013-07-13 12:51:31 +02:00
QString nameDraw;
bool bOk;
qint32 index;
QString nDraw = QString("Креслення %1").arg(comboBoxDraws->count()+1);
QInputDialog *dlg = new QInputDialog(this);
dlg->setInputMode( QInputDialog::TextInput );
dlg->setLabelText("Креслення:");
dlg->setTextEchoMode(QLineEdit::Normal);
dlg->setWindowTitle("Введіть назву креслення.");
dlg->resize(300,100);
dlg->setTextValue(nDraw);
while(1){
bOk = false;
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()<<"Помилка. Креслення з таким ім'ям вже існує.";
} else {
break;
}
}
delete dlg;
bOk = doc->appendDraw(nameDraw);
if(bOk == false){
qCritical()<<"Помилка створення креслення з ім'ям"<<nameDraw<<".";
return;//не змогли додати креслення.
}
comboBoxDraws->addItem(nameDraw, true);
index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index);
}
2013-07-17 13:38:11 +02:00
SetEnableWidgets(true);
2013-07-25 14:00:51 +02:00
SetEnableTool(false);
2013-07-13 12:51:31 +02:00
}
2013-07-25 14:00:51 +02:00
void MainWindow::OptionDraw(){
2013-07-13 12:51:31 +02:00
QString nameDraw;
bool bOk;
qint32 index;
QString nDraw = doc->GetNameActivDraw();
QInputDialog *dlg = new QInputDialog(this);
dlg->setInputMode( QInputDialog::TextInput );
dlg->setLabelText("Креслення:");
dlg->setTextEchoMode(QLineEdit::Normal);
dlg->setWindowTitle("Введіть нову назву креслення.");
dlg->resize(300,100);
dlg->setTextValue(nDraw);
while(1){
bOk = false;
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()<<"Помилка. Креслення з таким ім'ям вже існує.";
} else {
break;
}
}
delete dlg;
index = comboBoxDraws->findText(doc->GetNameActivDraw());
doc->SetNameDraw(nameDraw);
comboBoxDraws->setItemText(index, nameDraw);
2013-07-03 14:29:26 +02:00
}
/*
* Інструмет базова точка креслення.
*/
2013-07-25 14:00:51 +02:00
void MainWindow::ToolSinglePoint(bool checked){
2013-07-13 12:51:31 +02:00
if(checked){
CanselTool();
tool = Tools::SinglePointTool;
QPixmap pixmap(":/cursor/spoint_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть розташування для точки.");
2013-07-28 00:18:06 +02:00
dialogSinglePoint = new DialogSinglePoint(data);
2013-07-13 12:51:31 +02:00
//покажемо вікно як тільки буде вибрано місце розташування для точки
connect(scene, &VMainGraphicsScene::mousePress, dialogSinglePoint,
&DialogSinglePoint::mousePress);
2013-07-28 00:18:06 +02:00
connect(dialogSinglePoint, &DialogSinglePoint::DialogClosed, this,
&MainWindow::ClosedDialogSinglePoint);
2013-07-13 12:51:31 +02:00
} else { //не даємо користувачу зняти виділення кнопки
ui->toolButtonSinglePoint->setChecked(true);
}
2013-07-03 14:29:26 +02:00
}
2013-07-25 14:00:51 +02:00
void MainWindow::ToolEndLine(bool checked){
if(checked){
CanselTool();
tool = Tools::EndLineTool;
QPixmap pixmap(":/cursor/endline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Заповніть усі поля.");
dialogEndLine = new DialogEndLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogEndLine,
&DialogEndLine::ChoosedPoint);
connect(dialogEndLine, &DialogEndLine::DialogClosed, this,
&MainWindow::ClosedDialogEndLine);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine, &DialogEndLine::UpdateList);
} else {
ui->toolButtonEndLine->setChecked(true);
}
}
void MainWindow::ClosedDialogEndLine(int result){
if(result == QDialog::Accepted){
QString pointName = dialogEndLine->getPointName();
QString typeLine = dialogEndLine->getTypeLine();
QString formula = dialogEndLine->getFormula();
qint32 angle = dialogEndLine->getAngle();
qint64 basePointId = dialogEndLine->getBasePointId();
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
line.setAngle(angle);
qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10));
2013-07-30 15:09:34 +02:00
data->AddLine(basePointId, id);
2013-07-25 14:00:51 +02:00
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, basePointId,
Tool::FromGui);
scene->addItem(point);
connect(point, &VToolPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
2013-07-25 20:39:51 +02:00
void MainWindow::ToolLine(bool checked){
if(checked){
CanselTool();
tool = Tools::LineTool;
QPixmap pixmap(":/cursor/line_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogLine = new DialogLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogLine, &DialogLine::ChoosedPoint);
connect(dialogLine, &DialogLine::DialogClosed, this, &MainWindow::ClosedDialogLine);
} else {
ui->toolButtonLine->setChecked(true);
}
}
void MainWindow::ClosedDialogLine(int result){
if(result == QDialog::Accepted){
qint64 firstPoint = dialogLine->getFirstPoint();
qint64 secondPoint = dialogLine->getSecondPoint();
2013-07-30 15:09:34 +02:00
data->AddLine(firstPoint, secondPoint);
2013-07-25 20:39:51 +02:00
qint64 id = data->getNextId();
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, Tool::FromGui);
scene->addItem(line);
connect(line, &VToolLine::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
ArrowTool();
}
2013-07-28 00:18:06 +02:00
void MainWindow::ToolAlongLine(bool checked){
if(checked){
CanselTool();
tool = Tools::AlongLineTool;
QPixmap pixmap(":/cursor/alongline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogAlongLine = new DialogAlongLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogAlongLine, &DialogAlongLine::ChoosedPoint);
connect(dialogAlongLine, &DialogLine::DialogClosed, this, &MainWindow::ClosedDialogAlongLine);
} else {
ui->toolButtonAlongLine->setChecked(true);
}
}
void MainWindow::ClosedDialogAlongLine(int result){
if(result == QDialog::Accepted){
QString formula = dialogAlongLine->getFormula();
qint64 firstPointId = dialogAlongLine->getFirstPointId();
qint64 secondPointId = dialogAlongLine->getSecondPointId();
QString typeLine = dialogAlongLine->getTypeLine();
QString pointName = dialogAlongLine->getPointName();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10));
2013-07-30 15:09:34 +02:00
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
2013-07-28 00:18:06 +02:00
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId,
typeLine, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolAlongLine::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
2013-07-29 14:55:40 +02:00
void MainWindow::ToolShoulderPoint(bool checked){
if(checked){
CanselTool();
tool = Tools::ShoulderPointTool;
QPixmap pixmap(":/cursor/shoulder_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogShoulderPoint = new DialogShoulderPoint(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogShoulderPoint,
&DialogShoulderPoint::ChoosedPoint);
connect(dialogShoulderPoint, &DialogShoulderPoint::DialogClosed, this,
&MainWindow::ClosedDialogShoulderPoint);
} else {
ui->toolButtonShoulderPoint->setChecked(true);
}
}
void MainWindow::ClosedDialogShoulderPoint(int result){
if(result == QDialog::Accepted){
QString formula = dialogShoulderPoint->getFormula();
qint64 p1Line = dialogShoulderPoint->getP1Line();
qint64 p2Line = dialogShoulderPoint->getP2Line();
qint64 pShoulder = dialogShoulderPoint->getPShoulder();
QString typeLine = dialogShoulderPoint->getTypeLine();
QString pointName = dialogShoulderPoint->getPointName();
VPointF firstPoint = data->GetPoint(p1Line);
VPointF secondPoint = data->GetPoint(p2Line);
VPointF shoulderPoint = data->GetPoint(pShoulder);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint, secondPoint, shoulderPoint,
result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
2013-07-30 15:09:34 +02:00
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
2013-07-29 14:55:40 +02:00
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, p1Line,
p2Line, pShoulder, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolShoulderPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
2013-07-30 15:09:34 +02:00
void MainWindow::ToolNormal(bool checked){
if(checked){
CanselTool();
tool = Tools::NormalTool;
QPixmap pixmap(":/cursor/normal_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogNormal = new DialogNormal(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogNormal,
&DialogNormal::ChoosedPoint);
connect(dialogNormal, &DialogNormal::DialogClosed, this,
&MainWindow::ClosedDialogNormal);
} else {
ui->toolButtonNormal->setChecked(true);
}
}
void MainWindow::ClosedDialogNormal(int result){
if(result == QDialog::Accepted){
QString formula = dialogNormal->getFormula();
qint64 firstPointId = dialogNormal->getFirstPointId();
qint64 secondPointId = dialogNormal->getSecondPointId();
QString typeLine = dialogNormal->getTypeLine();
QString pointName = dialogNormal->getPointName();
qint32 angle = dialogNormal->getAngle();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolNormal::FindPoint(firstPoint, secondPoint, result*PrintDPI/25.4,
angle);
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(firstPointId, id);
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, firstPointId,
secondPointId, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolNormal::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
2013-07-30 20:46:40 +02:00
void MainWindow::ToolBisector(bool checked){
if(checked){
CanselTool();
tool = Tools::BisectorTool;
QPixmap pixmap(":/cursor/bisector_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogBisector = new DialogBisector(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogBisector,
&DialogBisector::ChoosedPoint);
connect(dialogBisector, &DialogBisector::DialogClosed, this,
&MainWindow::ClosedDialogBisector);
} else {
ui->toolButtonBisector->setChecked(true);
}
}
void MainWindow::ClosedDialogBisector(int result){
if(result == QDialog::Accepted){
QString formula = dialogBisector->getFormula();
qint64 firstPointId = dialogBisector->getFirstPointId();
qint64 secondPointId = dialogBisector->getSecondPointId();
qint64 thirdPointId = dialogBisector->getThirdPointId();
QString typeLine = dialogBisector->getTypeLine();
QString pointName = dialogBisector->getPointName();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
VPointF thirdPoint = data->GetPoint(thirdPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolBisector::FindPoint(firstPoint, secondPoint, thirdPoint,
result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(secondPointId, id);
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId,
secondPointId, thirdPointId, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolBisector::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
2013-07-31 13:34:39 +02:00
void MainWindow::ToolLineIntersect(bool checked){
if(checked){
CanselTool();
tool = Tools::LineIntersectTool;
QPixmap pixmap(":/cursor/intersect_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogLineIntersect = new DialogLineIntersect(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogLineIntersect,
&DialogLineIntersect::ChoosedPoint);
connect(dialogLineIntersect, &DialogLineIntersect::DialogClosed, this,
&MainWindow::ClosedDialogLineIntersect);
} else {
ui->toolButtonLineIntersect->setChecked(true);
}
}
void MainWindow::ClosedDialogLineIntersect(int result){
if(result == QDialog::Accepted){
qint64 p1Line1Id = dialogLineIntersect->getP1Line1();
qint64 p2Line1Id = dialogLineIntersect->getP2Line1();
qint64 p1Line2Id = dialogLineIntersect->getP1Line2();
qint64 p2Line2Id = dialogLineIntersect->getP2Line2();
QString pointName = dialogLineIntersect->getPointName();
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
QLineF line1(p1Line1, p2Line1);
QLineF line2(p1Line2, p2Line2);
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id,
p2Line1Id, p1Line2Id,
p2Line2Id, Tool::FromFile);
scene->addItem(point);
connect(point, &VToolLineIntersect::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
2013-07-03 14:29:26 +02:00
void MainWindow::showEvent( QShowEvent *event ){
QMainWindow::showEvent( event );
if( event->spontaneous() ){
return;
}
if(isInitialized){
return;
}
// do your init stuff here
QScrollBar *horScrollBar = ui->graphicsView->horizontalScrollBar();
horScrollBar->setValue(horScrollBar->minimum());
QScrollBar *verScrollBar = ui->graphicsView->verticalScrollBar();
verScrollBar->setValue(verScrollBar->minimum());
isInitialized = true;//перший показ вікна вже відбувся
}
void MainWindow::ToolBarOption(){
QLabel * labelGrowth = new QLabel;
labelGrowth->setText("Зріст: ");
ui->toolBarOption->addWidget(labelGrowth);
2013-06-20 16:09:50 +02:00
QStringList list;
2013-07-03 14:29:26 +02:00
list << "104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176"
<< "182" << "188";
2013-07-17 13:38:11 +02:00
QComboBox *comboBoxGrow = new QComboBox;
2013-07-03 14:29:26 +02:00
comboBoxGrow->clear();
comboBoxGrow->addItems(list);
comboBoxGrow->setCurrentIndex(12);
ui->toolBarOption->addWidget(comboBoxGrow);
2013-07-17 13:38:11 +02:00
connect(comboBoxGrow,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedGrowth);
2013-07-03 14:29:26 +02:00
QLabel * labelSize = new QLabel;
labelSize->setText(" Розмір: ");
ui->toolBarOption->addWidget(labelSize);
list.clear();
2013-06-20 16:09:50 +02:00
list << "28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50" << "52" << "54" << "56";
2013-07-17 13:38:11 +02:00
QComboBox *comboBoxSize = new QComboBox;
2013-07-03 14:29:26 +02:00
comboBoxSize->clear();
2013-06-20 16:09:50 +02:00
comboBoxSize->addItems(list);
2013-07-03 14:29:26 +02:00
comboBoxSize->setCurrentIndex(11);
2013-06-20 16:09:50 +02:00
ui->toolBarOption->addWidget(comboBoxSize);
2013-07-17 13:38:11 +02:00
connect(comboBoxSize,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize);
2013-07-03 14:29:26 +02:00
ui->toolBarOption->addSeparator();
mouseCoordinate = new QLabel;
mouseCoordinate ->setText("0, 0");
ui->toolBarOption->addWidget(mouseCoordinate);
}
void MainWindow::ToolBarDraws(){
QLabel * labelNameDraw = new QLabel;
labelNameDraw ->setText("Креслення: ");
ui->toolBarDraws->addWidget(labelNameDraw);
2013-07-13 12:51:31 +02:00
comboBoxDraws = new QComboBox;
2013-07-03 14:29:26 +02:00
ui->toolBarDraws->addWidget(comboBoxDraws);
2013-07-13 12:51:31 +02:00
comboBoxDraws->setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
2013-07-03 14:29:26 +02:00
2013-07-13 12:51:31 +02:00
ui->toolBarDraws->addAction(ui->actionOptionDraw);
ui->actionOptionDraw->setEnabled(false);
2013-07-17 13:38:11 +02:00
ui->toolBarDraws->addAction(ui->actionTable);
ui->actionTable->setEnabled(false);
2013-07-13 12:51:31 +02:00
}
2013-07-03 14:29:26 +02:00
2013-07-13 12:51:31 +02:00
void MainWindow::currentDrawChanged( int index ){
if(index != -1) {
bool status = qvariant_cast<bool>(comboBoxDraws->itemData(index));
ui->toolButtonSinglePoint->setEnabled(status);
2013-07-25 14:00:51 +02:00
if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
2013-07-13 12:51:31 +02:00
doc->ChangeActivDraw(comboBoxDraws->itemText(index));
}
2013-07-03 14:29:26 +02:00
}
void MainWindow::mouseMove(QPointF scenePos){
QString string = QString("%1, %2")
2013-07-13 12:51:31 +02:00
.arg((qint32)(scenePos.x()/PrintDPI*25.4))
.arg((qint32)(scenePos.y()/PrintDPI*25.4));
2013-07-03 14:29:26 +02:00
mouseCoordinate->setText(string);
}
void MainWindow::CanselTool(){
switch( tool )
{
case Tools::ArrowTool:
2013-07-13 12:51:31 +02:00
ui->actionArrowTool->setChecked(false);
2013-07-03 14:29:26 +02:00
break;
case Tools::SinglePointTool:
//Знищимо діалогове вікно.
delete dialogSinglePoint;
2013-07-13 12:51:31 +02:00
ui->toolButtonSinglePoint->setChecked(false);
2013-07-03 14:29:26 +02:00
break;
2013-07-25 14:00:51 +02:00
case Tools::EndLineTool:
delete dialogEndLine;
ui->toolButtonEndLine->setChecked(false);
2013-07-29 14:55:40 +02:00
scene->setFocus(Qt::OtherFocusReason);
2013-07-25 14:00:51 +02:00
scene->clearSelection();
break;
2013-07-25 20:39:51 +02:00
case Tools::LineTool:
delete dialogLine;
ui->toolButtonLine->setChecked(false);
2013-07-29 14:55:40 +02:00
scene->setFocus(Qt::OtherFocusReason);
2013-07-25 20:39:51 +02:00
scene->clearFocus();
break;
2013-07-28 00:18:06 +02:00
case Tools::AlongLineTool:
delete dialogAlongLine;
ui->toolButtonAlongLine->setChecked(false);
2013-07-29 14:55:40 +02:00
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::ShoulderPointTool:
delete dialogShoulderPoint;
ui->toolButtonShoulderPoint->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
2013-07-28 00:18:06 +02:00
break;
2013-07-30 15:09:34 +02:00
case Tools::NormalTool:
delete dialogNormal;
ui->toolButtonNormal->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-07-30 20:46:40 +02:00
case Tools::BisectorTool:
delete dialogBisector;
ui->toolButtonBisector->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-07-31 13:34:39 +02:00
case Tools::LineIntersectTool:
delete dialogLineIntersect;
ui->toolButtonLineIntersect->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-07-03 14:29:26 +02:00
}
}
void MainWindow::ArrowTool(){
CanselTool();
2013-07-13 12:51:31 +02:00
ui->actionArrowTool->setChecked(true);
2013-07-03 14:29:26 +02:00
tool = Tools::ArrowTool;
QCursor cur(Qt::ArrowCursor);
ui->graphicsView->setCursor(cur);
helpLabel->setText("");
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionAroowTool(){
2013-07-03 14:29:26 +02:00
ArrowTool();
2013-06-20 16:09:50 +02:00
}
2013-07-13 12:51:31 +02:00
void MainWindow::keyPressEvent ( QKeyEvent * event ){
switch(event->key()){
case Qt::Key_Escape:
ArrowTool();
break;
}
QMainWindow::keyPressEvent ( event );
}
2013-07-28 00:18:06 +02:00
void MainWindow::ClosedDialogSinglePoint(int result){
if(result == QDialog::Accepted){
QPointF point = dialogSinglePoint->getPoint();
QString name = dialogSinglePoint->getName();
qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10));
VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui);
scene->addItem(spoint);
connect(spoint, &VToolPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
ArrowTool();
ui->toolButtonSinglePoint->setEnabled(false);
qint32 index = comboBoxDraws->currentIndex();
comboBoxDraws->setItemData(index, false);
ui->actionSave->setEnabled(true);
SetEnableTool(true);
}
2013-07-13 12:51:31 +02:00
ArrowTool();
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionDraw(bool checked){
2013-07-13 12:51:31 +02:00
if(checked){
ui->actionDetails->setChecked(false);
} else {
ui->actionDraw->setChecked(true);
}
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionDetails(bool checked){
2013-07-13 12:51:31 +02:00
if(checked){
ui->actionDraw->setChecked(false);
} else {
ui->actionDetails->setChecked(true);
}
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionSaveAs(){
2013-07-13 12:51:31 +02:00
QString filters("Lekalo files (*.xml);;All files (*.*)");
QString defaultFilter("Lekalo files (*.xml)");
QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(),
filters, &defaultFilter);
if(fName.indexOf(".xml",fName.size()-4)<0){
fName.append(".xml");
}
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
QFile file(fileName);
if(file.open(QIODevice::WriteOnly| QIODevice::Truncate)){
const int Indent = 4;
QTextStream out(&file);
doc->save(out, Indent);
file.close();
}
ui->actionSave->setEnabled(false);
changeInFile = false;
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionSave(){
2013-07-13 12:51:31 +02:00
if(!fileName.isEmpty()){
QFile file(fileName);
if(file.open(QIODevice::WriteOnly| QIODevice::Truncate)){
const int Indent = 4;
QTextStream out(&file);
doc->save(out, Indent);
file.close();
}
ui->actionSave->setEnabled(false);
changeInFile = false;
}
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionOpen(){
2013-07-13 12:51:31 +02:00
QString filter("Lekalo files (*.xml)");
QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter);
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
QFile file(fileName);
if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file)){
comboBoxDraws->clear();
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
doc->Parse(Document::FullParse, scene, comboBoxDraws);
2013-07-17 13:38:11 +02:00
CreateManTableIGroup ();
2013-07-13 12:51:31 +02:00
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
ui->actionSave->setEnabled(true);
ui->actionSaveAs->setEnabled(true);
2013-07-17 13:38:11 +02:00
ui->actionTable->setEnabled(true);
2013-07-13 12:51:31 +02:00
QString nameDraw = doc->GetNameActivDraw();
qint32 index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index);
}
}
file.close();
}
2013-07-25 14:00:51 +02:00
if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
2013-07-13 12:51:31 +02:00
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionNew(){
2013-07-13 12:51:31 +02:00
setWindowTitle("Valentina");
data->Clear();
doc->clear();
2013-07-17 13:38:11 +02:00
CreateManTableIGroup ();
2013-07-13 12:51:31 +02:00
CanselTool();
comboBoxDraws->clear();
fileName.clear();
ui->toolButtonSinglePoint->setEnabled(true);
ui->actionOptionDraw->setEnabled(false);
ui->actionSave->setEnabled(false);
2013-07-25 14:00:51 +02:00
SetEnableTool(false);
2013-07-13 12:51:31 +02:00
}
void MainWindow::haveChange(){
if(!fileName.isEmpty()){
ui->actionSave->setEnabled(true);
}
}
2013-07-17 13:38:11 +02:00
void MainWindow::CreateManTableIGroup () const{
data->AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3));
data->AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3));
data->AddStandartTableCell("Vtos", VStandartTableCell(1450, 2, 51));
data->AddStandartTableCell("Vtosh", VStandartTableCell(1506, 2, 54));
data->AddStandartTableCell("Vpt", VStandartTableCell(1438, 3, 52));
data->AddStandartTableCell("Vst", VStandartTableCell(1257, -1, 49));
data->AddStandartTableCell("Vlt", VStandartTableCell(1102, 0, 43));
data->AddStandartTableCell("Vk", VStandartTableCell(503, 0, 22));
data->AddStandartTableCell("Vsht", VStandartTableCell(1522, 2, 54));
data->AddStandartTableCell("Vzy", VStandartTableCell(1328, 0, 49));
data->AddStandartTableCell("Vlop", VStandartTableCell(1320, 0, 49));
data->AddStandartTableCell("Vps", VStandartTableCell(811, -1, 36));
data->AddStandartTableCell("Osh", VStandartTableCell(404,8, 2));
data->AddStandartTableCell("OgI", VStandartTableCell(1034, 36, 4));
data->AddStandartTableCell("OgII", VStandartTableCell(1044, 38, 2));
data->AddStandartTableCell("OgIII", VStandartTableCell(1000, 40, 0));
data->AddStandartTableCell("Ot", VStandartTableCell(780, 40, 0));
data->AddStandartTableCell("Ob", VStandartTableCell(984, 30, 10));
data->AddStandartTableCell("ObI", VStandartTableCell(964, 24, 12));
data->AddStandartTableCell("Obed", VStandartTableCell(566, 18, 6));
data->AddStandartTableCell("Ok", VStandartTableCell(386, 8, 8));
data->AddStandartTableCell("Oi", VStandartTableCell(380, 8, 6));
data->AddStandartTableCell("Osch", VStandartTableCell(234, 4, 4));
data->AddStandartTableCell("Os", VStandartTableCell(350, 2, 8));
data->AddStandartTableCell("Dsb", VStandartTableCell(1120, 0, 44));
data->AddStandartTableCell("Dsp", VStandartTableCell(1110, 0, 43));
data->AddStandartTableCell("Dn", VStandartTableCell(826, -3, 37));
data->AddStandartTableCell("Dps", VStandartTableCell(316, 4, 7));
data->AddStandartTableCell("Dpob", VStandartTableCell(783, 14, 15));
data->AddStandartTableCell("Ds", VStandartTableCell(260, 1, 6));
data->AddStandartTableCell("Op", VStandartTableCell(316, 12, 0));
data->AddStandartTableCell("Ozap", VStandartTableCell(180, 4, 0));
data->AddStandartTableCell("Pkis", VStandartTableCell(250, 4, 0));
data->AddStandartTableCell("SHp", VStandartTableCell(160, 1, 4));
data->AddStandartTableCell("Dlych", VStandartTableCell(500, 2, 15));
data->AddStandartTableCell("Dzap", VStandartTableCell(768, 2, 24));
data->AddStandartTableCell("DIIIp", VStandartTableCell(970, 2, 29));
data->AddStandartTableCell("Vprp", VStandartTableCell(214, 3, 3));
data->AddStandartTableCell("Vg", VStandartTableCell(262, 8, 3));
data->AddStandartTableCell("Dtp", VStandartTableCell(460, 7, 9));
data->AddStandartTableCell("Dp", VStandartTableCell(355, 5, 5));
data->AddStandartTableCell("Vprz", VStandartTableCell(208, 3, 5));
data->AddStandartTableCell("Dts", VStandartTableCell(438, 2, 10));
data->AddStandartTableCell("DtsI", VStandartTableCell(469, 2, 10));
data->AddStandartTableCell("Dvcht", VStandartTableCell(929, 9, 19));
data->AddStandartTableCell("SHg", VStandartTableCell(370, 14, 4));
data->AddStandartTableCell("Cg", VStandartTableCell(224, 6, 0));
data->AddStandartTableCell("SHs", VStandartTableCell(416, 10, 2));
data->AddStandartTableCell("dpzr", VStandartTableCell(121, 6, 0));
data->AddStandartTableCell("Ogol", VStandartTableCell(576, 4, 4));
data->AddStandartTableCell("Ssh1", VStandartTableCell(205, 5, 0));
data->AddStandartTableCell("St", VStandartTableCell(410, 20, 0));
data->AddStandartTableCell("Drzap", VStandartTableCell(594, 3, 19));
data->AddStandartTableCell("DbII", VStandartTableCell(1020, 0, 44));
data->AddStandartTableCell("Sb", VStandartTableCell(504, 15, 4));
}
void MainWindow::ChangedSize(const QString & text){
qint32 size = text.toInt();
data->SetSize(size*10);
doc->FullUpdateTree();
}
void MainWindow::ChangedGrowth(const QString &text){
qint32 growth = text.toInt();
data->SetGrowth(growth*10);
doc->FullUpdateTree();
}
void MainWindow::SetEnableWidgets(bool enable){
ui->actionSaveAs->setEnabled(enable);
ui->actionDraw->setEnabled(enable);
ui->actionDetails->setEnabled(enable);
ui->toolButtonSinglePoint->setEnabled(enable);
ui->actionOptionDraw->setEnabled(enable);
2013-07-25 14:00:51 +02:00
if(enable == true && !fileName.isEmpty()){
ui->actionSave->setEnabled(enable);
}
2013-07-17 13:38:11 +02:00
ui->actionTable->setEnabled(enable);
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionTable(bool checked){
2013-07-17 13:38:11 +02:00
if(checked){
2013-07-28 00:18:06 +02:00
dialogTable = new DialogIncrements(data, doc, this);
connect(dialogTable, &DialogIncrements::DialogClosed, this,
2013-07-25 14:00:51 +02:00
&MainWindow::ClosedActionTable);
2013-07-17 13:38:11 +02:00
dialogTable->show();
} else {
ui->actionTable->setChecked(true);
dialogTable->activateWindow();
}
}
2013-07-25 14:00:51 +02:00
void MainWindow::ClosedActionTable(){
2013-07-17 13:38:11 +02:00
ui->actionTable->setChecked(false);
delete dialogTable;
}
2013-07-25 14:00:51 +02:00
void MainWindow::SetEnableTool(bool enable){
ui->toolButtonEndLine->setEnabled(enable);
2013-07-25 20:39:51 +02:00
ui->toolButtonLine->setEnabled(enable);
2013-07-28 00:18:06 +02:00
ui->toolButtonAlongLine->setEnabled(enable);
2013-07-29 14:55:40 +02:00
ui->toolButtonShoulderPoint->setEnabled(enable);
2013-07-30 15:09:34 +02:00
ui->toolButtonNormal->setEnabled(enable);
2013-07-30 20:46:40 +02:00
ui->toolButtonBisector->setEnabled(enable);
2013-07-31 13:34:39 +02:00
ui->toolButtonLineIntersect->setEnabled(enable);
2013-07-25 14:00:51 +02:00
}
2013-07-13 12:51:31 +02:00
MainWindow::~MainWindow(){
2013-07-03 14:29:26 +02:00
CanselTool();
2013-06-20 16:09:50 +02:00
delete ui;
2013-07-13 12:51:31 +02:00
QFile file("lekalo.xml");
if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)){
const int Indent = 4;
QTextStream out(&file);
doc->save(out, Indent);
file.close();
}
delete data;
if(!doc->isNull()){
delete doc;
}
2013-06-20 16:09:50 +02:00
}