valentina/mainwindow.cpp

729 lines
25 KiB
C++
Raw Normal View History

2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
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>
#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-08-05 10:37:56 +02:00
#include "tools/vtoolspline.h"
2013-08-06 09:56:09 +02:00
#include "tools/vtoolarc.h"
2013-08-09 08:49:34 +02:00
#include "tools/vtoolsplinepath.h"
2013-08-21 10:03:53 +02:00
#include "tools/vtoolpointofcontact.h"
2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic pop
2013-08-05 10:37:56 +02:00
#include "geometry/vspline.h"
2013-06-20 16:09:50 +02:00
MainWindow::MainWindow(QWidget *parent) :
2013-08-20 12:26:02 +02:00
QMainWindow(parent), ui(new Ui::MainWindow), tool(Tools::ArrowTool), scene(0), mouseCoordinate(0),
helpLabel(0), view(0), isInitialized(false), dialogTable(0),
dialogEndLine(QSharedPointer<DialogEndLine>()), dialogLine(QSharedPointer<DialogLine>()),
dialogAlongLine(QSharedPointer<DialogAlongLine>()),
dialogShoulderPoint(QSharedPointer<DialogShoulderPoint>()), dialogNormal(QSharedPointer<DialogNormal>()),
dialogBisector(QSharedPointer<DialogBisector>()),
dialogLineIntersect(QSharedPointer<DialogLineIntersect>()),
dialogSpline(QSharedPointer<DialogSpline>()),
dialogArc(QSharedPointer<DialogArc>()), dialogSplinePath(QSharedPointer<DialogSplinePath>()),
2013-08-21 10:03:53 +02:00
dialogPointOfContact(QSharedPointer<DialogPointOfContact>()), dialogHistory(0),
doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false){
2013-06-20 16:09:50 +02:00
ui->setupUi(this);
2013-07-03 14:29:26 +02:00
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);
view = new VMainGraphicsView();
ui->LayoutView->addWidget(view);
view->setScene(scene);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
view->setSizePolicy(policy);
2013-07-03 14:29:26 +02:00
connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
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);
2013-08-15 22:39:00 +02:00
connect(ui->actionHistory, &QAction::triggered, this, &MainWindow::ActionHistory);
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);
2013-08-21 10:03:53 +02:00
connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact);
2013-07-13 12:51:31 +02:00
data = new VContainer;
2013-08-15 22:39:00 +02:00
doc = new VDomDocument(data, comboBoxDraws);
2013-07-13 12:51:31 +02:00
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;//не змогли додати креслення.
}
2013-08-15 22:39:00 +02:00
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
comboBoxDraws->addItem(nameDraw);
2013-07-13 12:51:31 +02:00
index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index);
2013-08-15 22:39:00 +02:00
currentDrawChanged( index );
2013-07-13 12:51:31 +02:00
}
2013-08-15 22:39:00 +02:00
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&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);
scene->addItem(spoint);
connect(spoint, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id, spoint);
VAbstractTool::AddRecord(id, Tools::SinglePointTool, doc);
SetEnableTool(true);
2013-07-17 13:38:11 +02:00
SetEnableWidgets(true);
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
}
template <typename Dialog, typename Func>
void MainWindow::SetToolButton(bool checked, Tools::Enum t, const QString &cursor,
QSharedPointer<Dialog> &dialog, Func closeDialogSlot){
if(checked){
CanselTool();
tool = t;
QPixmap pixmap(cursor);
QCursor cur(pixmap, 2, 3);
view->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialog = QSharedPointer<Dialog>(new Dialog(data));
connect(scene, &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject);
connect(dialog.data(), &Dialog::DialogClosed, this, closeDialogSlot);
connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList);
} else {
if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){
tButton->setChecked(true);
}
}
}
void MainWindow::ToolEndLine(bool checked){
SetToolButton(checked, Tools::EndLineTool, ":/cursor/endline_cursor.png", dialogEndLine,
&MainWindow::ClosedDialogEndLine);
2013-07-25 14:00:51 +02:00
}
void MainWindow::ClosedDialogEndLine(int result){
if(result == QDialog::Accepted){
VToolEndLine::Create(dialogEndLine, scene, doc, data);
2013-07-25 14:00:51 +02:00
}
ArrowTool();
}
2013-07-25 20:39:51 +02:00
void MainWindow::ToolLine(bool checked){
SetToolButton(checked, Tools::LineTool, ":/cursor/line_cursor.png", dialogLine,
&MainWindow::ClosedDialogLine);
2013-07-25 20:39:51 +02:00
}
void MainWindow::ClosedDialogLine(int result){
if(result == QDialog::Accepted){
VToolLine::Create(dialogLine, scene, doc, data);
2013-07-25 20:39:51 +02:00
}
ArrowTool();
}
2013-07-28 00:18:06 +02:00
void MainWindow::ToolAlongLine(bool checked){
SetToolButton(checked, Tools::AlongLineTool, ":/cursor/alongline_cursor.png", dialogAlongLine,
&MainWindow::ClosedDialogAlongLine);
2013-07-28 00:18:06 +02:00
}
void MainWindow::ClosedDialogAlongLine(int result){
if(result == QDialog::Accepted){
VToolAlongLine::Create(dialogAlongLine, scene, doc, data);
2013-07-28 00:18:06 +02:00
}
ArrowTool();
}
2013-07-29 14:55:40 +02:00
void MainWindow::ToolShoulderPoint(bool checked){
SetToolButton(checked, Tools::ShoulderPointTool, ":/cursor/shoulder_cursor.png", dialogShoulderPoint,
&MainWindow::ClosedDialogShoulderPoint);
2013-07-29 14:55:40 +02:00
}
void MainWindow::ClosedDialogShoulderPoint(int result){
if(result == QDialog::Accepted){
VToolShoulderPoint::Create(dialogShoulderPoint, scene, doc, data);
2013-07-29 14:55:40 +02:00
}
ArrowTool();
}
2013-07-30 15:09:34 +02:00
void MainWindow::ToolNormal(bool checked){
SetToolButton(checked, Tools::NormalTool, ":/cursor/normal_cursor.png", dialogNormal,
&MainWindow::ClosedDialogNormal);
2013-07-30 15:09:34 +02:00
}
void MainWindow::ClosedDialogNormal(int result){
if(result == QDialog::Accepted){
VToolNormal::Create(dialogNormal, scene, doc, data);
2013-07-30 15:09:34 +02:00
}
ArrowTool();
}
2013-07-30 20:46:40 +02:00
void MainWindow::ToolBisector(bool checked){
SetToolButton(checked, Tools::BisectorTool, ":/cursor/bisector_cursor.png", dialogBisector,
&MainWindow::ClosedDialogBisector);
2013-07-30 20:46:40 +02:00
}
void MainWindow::ClosedDialogBisector(int result){
if(result == QDialog::Accepted){
VToolBisector::Create(dialogBisector, scene, doc, data);
2013-07-30 20:46:40 +02:00
}
ArrowTool();
}
2013-07-31 13:34:39 +02:00
void MainWindow::ToolLineIntersect(bool checked){
SetToolButton(checked, Tools::LineIntersectTool, ":/cursor/intersect_cursor.png", dialogLineIntersect,
&MainWindow::ClosedDialogLineIntersect);
2013-07-31 13:34:39 +02:00
}
void MainWindow::ClosedDialogLineIntersect(int result){
if(result == QDialog::Accepted){
VToolLineIntersect::Create(dialogLineIntersect, scene, doc, data);
2013-07-31 13:34:39 +02:00
}
ArrowTool();
}
2013-08-05 10:37:56 +02:00
void MainWindow::ToolSpline(bool checked){
SetToolButton(checked, Tools::SplineTool, ":/cursor/spline_cursor.png", dialogSpline,
&MainWindow::ClosedDialogSpline);
2013-08-05 10:37:56 +02:00
}
void MainWindow::ClosedDialogSpline(int result){
if(result == QDialog::Accepted){
VToolSpline::Create(dialogSpline, scene, doc, data);
2013-08-05 10:37:56 +02:00
}
ArrowTool();
}
2013-08-06 09:56:09 +02:00
void MainWindow::ToolArc(bool checked){
SetToolButton(checked, Tools::ArcTool, ":/cursor/arc_cursor.png", dialogArc,
&MainWindow::ClosedDialogArc);
2013-08-06 09:56:09 +02:00
}
void MainWindow::ClosedDialogArc(int result){
if(result == QDialog::Accepted){
VToolArc::Create(dialogArc, scene, doc, data);
2013-08-06 09:56:09 +02:00
}
ArrowTool();
}
2013-08-09 08:49:34 +02:00
void MainWindow::ToolSplinePath(bool checked){
SetToolButton(checked, Tools::SplinePathTool, ":/cursor/splinepath_cursor.png", dialogSplinePath,
&MainWindow::ClosedDialogSplinePath);
2013-08-09 08:49:34 +02:00
}
void MainWindow::ClosedDialogSplinePath(int result){
if(result == QDialog::Accepted){
VToolSplinePath::Create(dialogSplinePath, scene, doc, data);
2013-08-09 08:49:34 +02:00
}
ArrowTool();
}
2013-08-21 10:03:53 +02:00
void MainWindow::ToolPointOfContact(bool checked){
SetToolButton(checked, Tools::PointOfContact, ":/cursor/pointcontact_cursor.png", dialogPointOfContact,
&MainWindow::ClosedDialogPointOfContact);
}
void MainWindow::ClosedDialogPointOfContact(int result){
if(result == QDialog::Accepted){
VToolPointOfContact::Create(dialogPointOfContact, scene, doc, data);
}
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 = view->horizontalScrollBar();
2013-07-03 14:29:26 +02:00
horScrollBar->setValue(horScrollBar->minimum());
QScrollBar *verScrollBar = view->verticalScrollBar();
2013-07-03 14:29:26 +02:00
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-08-15 22:39:00 +02:00
ui->toolBarDraws->addAction(ui->actionHistory);
ui->actionHistory->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) {
2013-08-15 22:39:00 +02:00
doc->setCurrentData();
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-08-15 22:39:00 +02:00
.arg(static_cast<qint32>(scenePos.x()/PrintDPI*25.4))
.arg(static_cast<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:
2013-08-15 22:39:00 +02:00
//Nothing to do here because we can't create this tool from main window.
2013-07-03 14:29:26 +02:00
break;
2013-07-25 14:00:51 +02:00
case Tools::EndLineTool:
dialogEndLine.clear();
2013-07-25 14:00:51 +02:00
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:
dialogLine.clear();
2013-07-25 20:39:51 +02:00
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:
dialogAlongLine.clear();
2013-07-28 00:18:06 +02:00
ui->toolButtonAlongLine->setChecked(false);
2013-07-29 14:55:40 +02:00
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::ShoulderPointTool:
dialogShoulderPoint.clear();
2013-07-29 14:55:40 +02:00
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:
dialogNormal.clear();
2013-07-30 15:09:34 +02:00
ui->toolButtonNormal->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-07-30 20:46:40 +02:00
case Tools::BisectorTool:
dialogBisector.clear();
2013-07-30 20:46:40 +02:00
ui->toolButtonBisector->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-07-31 13:34:39 +02:00
case Tools::LineIntersectTool:
dialogLineIntersect.clear();
2013-07-31 13:34:39 +02:00
ui->toolButtonLineIntersect->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-08-05 10:37:56 +02:00
case Tools::SplineTool:
dialogSpline.clear();
2013-08-05 10:37:56 +02:00
ui->toolButtonSpline->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-08-06 09:56:09 +02:00
case Tools::ArcTool:
dialogArc.clear();
2013-08-06 09:56:09 +02:00
ui->toolButtonArc->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-08-09 08:49:34 +02:00
case Tools::SplinePathTool:
dialogSplinePath.clear();
2013-08-09 08:49:34 +02:00
ui->toolButtonSplinePath->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
2013-08-21 10:03:53 +02:00
case Tools::PointOfContact:
dialogPointOfContact.clear();
ui->toolButtonPointOfContact->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);
view->setCursor(cur);
2013-07-03 14:29:26 +02:00
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-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.isEmpty())
return;
2013-07-13 12:51:31 +02:00
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);
if(fName.isEmpty())
return;
2013-07-13 12:51:31 +02:00
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)){
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
2013-08-15 22:39:00 +02:00
doc->Parse(Document::FullParse, scene);
2013-07-13 12:51:31 +02:00
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
QString nameDraw = doc->GetNameActivDraw();
qint32 index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index);
}
2013-08-15 22:39:00 +02:00
if(comboBoxDraws->count() > 0){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
2013-08-15 22:39:00 +02:00
SetEnableWidgets(true);
2013-07-13 12:51:31 +02:00
}
file.close();
}
}
2013-07-25 14:00:51 +02:00
void MainWindow::ActionNew(){
2013-07-13 12:51:31 +02:00
setWindowTitle("Valentina");
fileName.clear();
2013-07-13 12:51:31 +02:00
data->Clear();
doc->clear();
scene->clear();
2013-07-13 12:51:31 +02:00
CanselTool();
comboBoxDraws->clear();
fileName.clear();
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::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->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-08-15 22:39:00 +02:00
ui->actionHistory->setEnabled(enable);
2013-07-17 13:38:11 +02:00
}
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-08-15 22:39:00 +02:00
void MainWindow::ActionHistory(bool checked){
if(checked){
dialogHistory = new DialogHistory(data, doc, this);
dialogHistory->setWindowFlags(Qt::Window);
connect(dialogHistory, &DialogHistory::DialogClosed, this,
&MainWindow::ClosedActionHistory);
dialogHistory->show();
} else {
ui->actionHistory->setChecked(true);
dialogHistory->activateWindow();
}
}
void MainWindow::ClosedActionHistory(){
ui->actionHistory->setChecked(false);
delete dialogHistory;
}
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-08-05 10:37:56 +02:00
ui->toolButtonSpline->setEnabled(enable);
2013-08-06 09:56:09 +02:00
ui->toolButtonArc->setEnabled(enable);
2013-08-09 08:49:34 +02:00
ui->toolButtonSplinePath->setEnabled(enable);
2013-08-21 10:03:53 +02:00
ui->toolButtonPointOfContact->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
}