Merge with feature

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-05-14 15:50:49 +03:00
commit 0485489b22
59 changed files with 1084 additions and 1280 deletions

View File

@ -16,22 +16,19 @@ include(core/core.pri)
SOURCES += \
$$PWD/main.cpp \
$$PWD/mainwindow.cpp \
$$PWD/tablewindow.cpp \
$$PWD/stable.cpp \
$$PWD/version.cpp \
$$PWD/options.cpp
$$PWD/options.cpp \
$$PWD/mainwindowsnogui.cpp
# Some header files
HEADERS += \
$$PWD/mainwindow.h \
$$PWD/options.h \
$$PWD/tablewindow.h \
$$PWD/stable.h \
$$PWD/version.h
$$PWD/version.h \
$$PWD/mainwindowsnogui.h
# Main forms
FORMS += \
$$PWD/mainwindow.ui \
$$PWD/tablewindow.ui
$$PWD/mainwindow.ui

View File

@ -2068,14 +2068,14 @@ VSettings *VApplication::getSettings()
}
//---------------------------------------------------------------------------------------------------------------------
VMainGraphicsScene *VApplication::getCurrentScene() const
QGraphicsScene *VApplication::getCurrentScene() const
{
SCASSERT(currentScene != nullptr);
return currentScene;
}
//---------------------------------------------------------------------------------------------------------------------
void VApplication::setCurrentScene(VMainGraphicsScene *value)
void VApplication::setCurrentScene(QGraphicsScene *value)
{
currentScene = value;
}

View File

@ -38,7 +38,6 @@
class VApplication;// used in define
class QUndoStack;
class VMainGraphicsView;
class VMainGraphicsScene;
class VPattern;
class QFile;
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
@ -110,8 +109,8 @@ public:
void OpenSettings();
VSettings *getSettings();
VMainGraphicsScene *getCurrentScene() const;
void setCurrentScene(VMainGraphicsScene *value);
QGraphicsScene *getCurrentScene() const;
void setCurrentScene(QGraphicsScene *value);
void setCurrentDocument(VPattern *doc);
VPattern *getCurrentDocument()const;
@ -151,7 +150,7 @@ private:
QMap<QString, qmu::QmuTranslation> stDescriptions;
QUndoStack *undoStack;
VMainGraphicsView *sceneView;
VMainGraphicsScene *currentScene;
QGraphicsScene *currentScene;
QTimer *autoSaveTimer;
/**
* @brief mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main window

View File

@ -117,7 +117,8 @@ void DialogAlongLine::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -225,7 +225,8 @@ void DialogArc::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View File

@ -126,7 +126,8 @@ void DialogBisector::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -166,7 +166,7 @@ void DialogCurveIntersectAxis::ShowDialog(bool click)
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
@ -258,7 +258,8 @@ void DialogCurveIntersectAxis::ShowVisualization()
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolCurveIntersectAxis::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -92,7 +92,8 @@ void DialogCutArc::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View File

@ -196,7 +196,8 @@ void DialogCutSpline::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View File

@ -196,7 +196,8 @@ void DialogCutSplinePath::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View File

@ -261,7 +261,7 @@ void DialogEndLine::ShowDialog(bool click)
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
@ -287,7 +287,8 @@ void DialogEndLine::ShowVisualization()
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -254,7 +254,8 @@ void DialogHeight::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -145,7 +145,8 @@ void DialogLine::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -229,7 +229,8 @@ void DialogLineIntersect::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -187,7 +187,7 @@ void DialogLineIntersectAxis::ShowDialog(bool click)
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
@ -322,7 +322,8 @@ void DialogLineIntersectAxis::ShowVisualization()
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLineIntersectAxis::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -116,7 +116,8 @@ void DialogNormal::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -133,7 +133,8 @@ void DialogPointOfContact::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -161,7 +161,8 @@ void DialogPointOfIntersection::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
line->RefreshGeometry();
}

View File

@ -126,7 +126,8 @@ void DialogShoulderPoint::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -185,7 +185,8 @@ void DialogSpline::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View File

@ -267,7 +267,8 @@ void DialogSplinePath::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor);
scene->addItem(visPath);
visPath->setMode(Mode::Show);

View File

@ -200,7 +200,8 @@ void DialogTriangle::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View File

@ -29,7 +29,6 @@
#include "mainwindow.h"
#include "core/vapplication.h"
#include "core/vsettings.h"
#include "tablewindow.h"
#include "version.h"
#include <QTextCodec>
@ -118,9 +117,6 @@ int main(int argc, char *argv[])
MainWindow w;
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));
app.setMainWindow(&w);
TableWindow table;
QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen);
QObject::connect(&table, &TableWindow::closed, &w, &MainWindow::tableClosed);
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("main", "Pattern making program."));

View File

@ -73,10 +73,10 @@ Q_LOGGING_CATEGORY(vMainWindow, "v.mainwindow")
* @param parent parent widget.
*/
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), currentTool(Tool::Arrow),
lastUsedTool(Tool::Arrow), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr),
:MainWindowsNoGUI(parent), ui(new Ui::MainWindow), currentTool(Tool::Arrow),
lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr),
mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), dialogTable(nullptr), dialogTool(nullptr),
dialogHistory(nullptr), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0),
dialogHistory(nullptr), comboBoxDraws(nullptr), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs(),
separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr),
gradationSizes(nullptr),
@ -95,33 +95,13 @@ MainWindow::MainWindow(QWidget *parent)
CreateMenus();
ToolBarDraws();
InitToolButtons();
sceneDraw = new VMainGraphicsScene();
currentScene = sceneDraw;
qApp->setCurrentScene(currentScene);
connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove);
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
sceneDetails = new VMainGraphicsScene();
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
ui->view->setScene(currentScene);
sceneDraw->setTransform(ui->view->transform());
sceneDetails->setTransform(ui->view->transform());
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
ui->view->setSizePolicy(policy);
qApp->setSceneView(ui->view);
InitScenes();
helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working."));
ui->statusBar->addWidget(helpLabel);
ToolBarTools();
pattern = new VContainer();
doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails);
connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear);
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified);
@ -151,6 +131,9 @@ MainWindow::MainWindow(QWidget *parent)
ui->toolBarStages->setIconSize(QSize(24, 24));
ui->toolBarTools->setIconSize(QSize(24, 24));
#endif
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &MainWindow::ShowPaper);
ui->dockWidgetLayoutPages->setVisible(false);
}
//---------------------------------------------------------------------------------------------------------------------
@ -221,6 +204,29 @@ void MainWindow::AddPP(const QString &PPName, const QString &path)
ui->actionNewDraw->setEnabled(true);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::InitScenes()
{
sceneDraw = new VMainGraphicsScene();
currentScene = sceneDraw;
qApp->setCurrentScene(currentScene);
connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove);
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
sceneDetails = new VMainGraphicsScene();
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
ui->view->setScene(currentScene);
sceneDraw->setTransform(ui->view->transform());
sceneDetails->setTransform(ui->view->transform());
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
ui->view->setSizePolicy(policy);
qApp->setSceneView(ui->view);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief OptionDraw help change name of pattern piece.
@ -261,7 +267,11 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
helpLabel->setText(toolTip);
ui->view->setShowToolOptions(false);
dialogTool = new Dialog(pattern, 0, this);
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot);
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
ui->view->itemClicked(nullptr);
@ -270,7 +280,6 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
{
if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender()))
{
SCASSERT(tButton != nullptr);
tButton->setChecked(true);
}
}
@ -301,7 +310,11 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
ui->view->setShowToolOptions(false);
helpLabel->setText(toolTip);
dialogTool = new Dialog(pattern, 0, this);
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot);
connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot);
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
@ -312,7 +325,6 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
{
if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender()))
{
SCASSERT(tButton != nullptr);
tButton->setChecked(true);
}
}
@ -328,7 +340,10 @@ void MainWindow::ClosedDialog(int result)
SCASSERT(dialogTool != nullptr);
if (result == QDialog::Accepted)
{
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(DrawTool::Create(dialogTool, currentScene, doc, pattern));
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(DrawTool::Create(dialogTool, scene, doc, pattern));
ui->view->itemClicked(tool);
}
ArrowTool();
@ -348,8 +363,11 @@ void MainWindow::ClosedDialogWithApply(int result)
// Only create tool if not already created with apply
if (dialogTool->GetAssociatedTool() == nullptr)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
dialogTool->SetAssociatedTool(
dynamic_cast<VAbstractTool * > (DrawTool::Create(dialogTool, currentScene, doc, pattern)));
dynamic_cast<VAbstractTool * > (DrawTool::Create(dialogTool, scene, doc, pattern)));
}
else
{ // Or update associated tool with data
@ -379,8 +397,11 @@ void MainWindow::ApplyDialog()
// Only create tool if not already created with apply
if (dialogTool->GetAssociatedTool() == nullptr)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
dialogTool->SetAssociatedTool(
static_cast<VAbstractTool * > (DrawTool::Create(dialogTool, currentScene, doc, pattern)));
static_cast<VAbstractTool * > (DrawTool::Create(dialogTool, scene, doc, pattern)));
}
else
{ // Or update associated tool with data
@ -704,16 +725,6 @@ void MainWindow::ShowToolTip(const QString &toolTip)
helpLabel->setText(toolTip);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief tableClosed handle after close layout window.
*/
void MainWindow::tableClosed()
{
ui->actionDetails->setChecked(true);
show();
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::OpenRecentFile()
{
@ -799,6 +810,33 @@ void MainWindow::customEvent(QEvent *event)
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ClearLayout()
{
qDeleteAll (scenes);
scenes.clear();
shadows.clear();
papers.clear();
ui->listWidget->clear();
SetLayoutModeActions(false);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::PrepareSceneList()
{
for (int i=1; i<=scenes.size(); ++i)
{
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1), QString::number(i));
ui->listWidget->addItem(item);
}
if (not scenes.isEmpty())
{
ui->listWidget->setCurrentRow(0);
SetLayoutModeActions(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolBarOption enable option toolbar.
@ -951,6 +989,7 @@ void MainWindow::InitToolButtons()
connect(ui->toolButtonLineIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolLineIntersectAxis);
connect(ui->toolButtonCurveIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolCurveIntersectAxis);
connect(ui->toolButtonArcIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolCurveIntersectAxis);
connect(ui->toolButtonLayoutSettings, &QToolButton::clicked, this, &MainWindow::ToolLayoutSettings);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1125,13 +1164,19 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
*/
void MainWindow::SaveCurrentScene()
{
/*Save transform*/
currentScene->setTransform(ui->view->transform());
/*Save scroll bars value for previous scene.*/
QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
currentScene->setHorScrollBar(horScrollBar->value());
QScrollBar *verScrollBar = ui->view->verticalScrollBar();
currentScene->setVerScrollBar(verScrollBar->value());
if (mode == Draw::Calculation || mode == Draw::Modeling)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
/*Save transform*/
scene->setTransform(ui->view->transform());
/*Save scroll bars value for previous scene.*/
QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
scene->setHorScrollBar(horScrollBar->value());
QScrollBar *verScrollBar = ui->view->verticalScrollBar();
scene->setVerScrollBar(verScrollBar->value());
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -1140,13 +1185,16 @@ void MainWindow::SaveCurrentScene()
*/
void MainWindow::RestoreCurrentScene()
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
/*Set transform for current scene*/
ui->view->setTransform(currentScene->transform());
ui->view->setTransform(scene->transform());
/*Set value for current scene scroll bar.*/
QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
horScrollBar->setValue(currentScene->getHorScrollBar());
horScrollBar->setValue(scene->getHorScrollBar());
QScrollBar *verScrollBar = ui->view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar());
verScrollBar->setValue(scene->getVerScrollBar());
}
//---------------------------------------------------------------------------------------------------------------------
@ -1160,11 +1208,13 @@ void MainWindow::ActionDraw(bool checked)
{
qCDebug(vMainWindow, "Show draw scene");
ui->actionDetails->setChecked(false);
ui->actionLayout->setChecked(false);
SaveCurrentScene();
currentScene = sceneDraw;
ui->view->setScene(currentScene);
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor,
Qt::UniqueConnection);
RestoreCurrentScene();
mode = Draw::Calculation;
@ -1179,7 +1229,20 @@ void MainWindow::ActionDraw(bool checked)
ui->actionHistory->setEnabled(true);
ui->actionOptionDraw->setEnabled(true);
ui->actionNewDraw->setEnabled(true);
ui->actionTable->setEnabled(true);
ui->actionArrowTool->setEnabled(true);
ui->actionShowCurveDetails->setEnabled(true);
actionDockWidgetToolOptions->setEnabled(true);
undoAction->setEnabled(true);
redoAction->setEnabled(true);
if (qApp->patternType() == MeasurementsType::Standard)
{
ui->toolBarOption->setVisible(true);
}
ui->dockWidgetLayoutPages->setVisible(false);
ui->dockWidgetToolOptions->setVisible(true);
}
else
{
@ -1198,11 +1261,12 @@ void MainWindow::ActionDetails(bool checked)
{
qCDebug(vMainWindow, "Show details scene");
ui->actionDraw->setChecked(false);
ui->actionLayout->setChecked(false);
SaveCurrentScene();
currentScene = sceneDetails;
ui->view->itemClicked(nullptr);
ui->view->setScene(sceneDetails);
ui->view->setScene(currentScene);
disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
RestoreCurrentScene();
@ -1211,16 +1275,33 @@ void MainWindow::ActionDetails(bool checked)
comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1);
comboBoxDraws->setEnabled(false);
if (mode == Draw::Calculation)
{
currentToolBoxIndex = ui->toolBox->currentIndex();
}
mode = Draw::Modeling;
SetEnableTool(true);
currentToolBoxIndex = ui->toolBox->currentIndex();
ui->toolBox->setCurrentIndex(4);
ui->actionHistory->setEnabled(false);
ui->actionOptionDraw->setEnabled(false);
ui->actionNewDraw->setEnabled(false);
ui->actionTable->setEnabled(false);
ui->actionArrowTool->setEnabled(true);
ui->actionShowCurveDetails->setEnabled(false);
actionDockWidgetToolOptions->setEnabled(true);
undoAction->setEnabled(true);
redoAction->setEnabled(true);
if (qApp->patternType() == MeasurementsType::Standard)
{
ui->toolBarOption->setVisible(true);
}
ui->dockWidgetLayoutPages->setVisible(false);
ui->dockWidgetToolOptions->setVisible(true);
helpLabel->setText("");
}
else
{
@ -1228,6 +1309,81 @@ void MainWindow::ActionDetails(bool checked)
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionLayout begin creation layout.
* @param checked true - button checked.
*/
void MainWindow::ActionLayout(bool checked)
{
if (checked)
{
qCDebug(vMainWindow, "Show layout scene");
ui->actionDraw->setChecked(false);
ui->actionDetails->setChecked(false);
SaveCurrentScene();
const QHash<quint32, VDetail> *details = pattern->DataDetails();
if (details->count() == 0)
{
Layout();
return;
}
PrepareDetailsForLayout(details);
currentScene = tempSceneLayout;
ui->view->itemClicked(nullptr);
ui->view->setScene(currentScene);
disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
drawMode = false;
currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace
comboBoxDraws->setCurrentIndex(-1);
comboBoxDraws->setEnabled(false);
if (mode == Draw::Calculation)
{
currentToolBoxIndex = ui->toolBox->currentIndex();
}
mode = Draw::Layout;
SetEnableTool(true);
ui->toolBox->setCurrentIndex(5);
ui->actionHistory->setEnabled(false);
ui->actionOptionDraw->setEnabled(false);
ui->actionNewDraw->setEnabled(false);
ui->actionArrowTool->setEnabled(false);
ui->actionTable->setEnabled(false);
ui->actionShowCurveDetails->setEnabled(false);
actionDockWidgetToolOptions->setEnabled(false);
undoAction->setEnabled(false);
redoAction->setEnabled(false);
mouseCoordinate->setText("");
if (qApp->patternType() == MeasurementsType::Standard)
{
ui->toolBarOption->setVisible(false);
}
ui->dockWidgetLayoutPages->setVisible(true);
ui->dockWidgetToolOptions->setVisible(false);
ShowPaper(ui->listWidget->currentRow());
if (scenes.isEmpty())
{
ui->toolButtonLayoutSettings->click();
}
helpLabel->setText("");
}
else
{
ui->actionLayout->setChecked(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveAs save as pattern file.
@ -1644,16 +1800,19 @@ void MainWindow::ClickEndVisualization()
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::Layout()
{
const QHash<quint32, VDetail> *details = pattern->DataDetails();
if (details->size() > 0)
if (pattern->DataDetails()->size() > 0)
{
ui->actionDetails->setEnabled(true);
ui->actionLayout->setEnabled(true);
SetLayoutModeActions(true);
}
else
{
listDetails.clear();
ui->actionDetails->setEnabled(false);
ui->actionLayout->setEnabled(false);
ui->actionDraw->setChecked(true);
SetLayoutModeActions(false);
}
}
@ -1813,6 +1972,7 @@ void MainWindow::PatternWasModified(bool saved)
{
setWindowModified(!saved);
ui->actionSave->setEnabled(!saved);
isLayoutStale = true;
}
}
@ -1898,41 +2058,6 @@ void MainWindow::ActionCurveDetailsMode(bool checked)
sceneDraw->EnableDetailsMode(checked);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionLayout begin creation layout.
* @param checked true - button checked.
*/
void MainWindow::ActionLayout(bool checked)
{
Q_UNUSED(checked);
ActionDetails(true);//Get all list of details.
QVector<VLayoutDetail> listDetails;
const QHash<quint32, VDetail> *details = pattern->DataDetails();
if (details->count() == 0)
{
return;
}
hide();//Now we can hide window
QHashIterator<quint32, VDetail> idetail(*details);
while (idetail.hasNext())
{
idetail.next();
VLayoutDetail det = VLayoutDetail();
det.SetCountourPoints(idetail.value().ContourPoints(pattern));
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern), idetail.value().getSeamAllowance());
det.setName(idetail.value().getName());
det.setWidth(qApp->toPixel(idetail.value().getWidth()));
listDetails.append(det);
}
QString description = doc->GetDescription();
QString fileName;
curFile.isEmpty() ? fileName = "unnamed" : fileName = curFile;
emit ModelChosen(listDetails, fileName, description);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedActionHistory actions after closing history window with variables.
@ -1952,14 +2077,23 @@ void MainWindow::SetEnableTool(bool enable)
{
bool drawTools = false;
bool modelingTools = false;
if (mode == Draw::Calculation)
bool layoutTools = false;
switch (mode)
{
drawTools = enable;
}
else
{
modelingTools = enable;
case Draw::Calculation:
drawTools = enable;
break;
case Draw::Modeling:
modelingTools = enable;
break;
case Draw::Layout:
layoutTools = enable;
break;
default:
break;
}
//Drawing Tools
ui->toolButtonEndLine->setEnabled(drawTools);
ui->toolButtonLine->setEnabled(drawTools);
@ -1987,6 +2121,26 @@ void MainWindow::SetEnableTool(bool enable)
//Modeling Tools
ui->toolButtonUnionDetails->setEnabled(modelingTools);
//Layout tools
ui->toolButtonLayoutSettings->setEnabled(layoutTools);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetLayoutModeActions(bool enable)
{
bool value = enable;
if (scenes.isEmpty())
{
value = false;
}
ui->actionExportAs->setEnabled(value);
ui->actionPrintPreview->setEnabled(value);
ui->actionPrintPreviewTailed->setEnabled(value);
ui->actionSaveAsPDF->setEnabled(value);
ui->actionSaveAsTiledPDF->setEnabled(value);
ui->actionPrint->setEnabled(value);
ui->actionPrintTiled->setEnabled(value);
}
//---------------------------------------------------------------------------------------------------------------------
@ -2126,6 +2280,8 @@ void MainWindow::ReadSettings()
*/
void MainWindow::WriteSettings()
{
ActionDraw(true);
qApp->getSettings()->SetGeometry(saveGeometry());
qApp->getSettings()->SetWindowState(saveState());
qApp->getSettings()->SetToolbarsState(saveState(APP_VERSION));
@ -2191,13 +2347,13 @@ void MainWindow::CreateMenus()
UpdateRecentFileActions();
//Add Undo/Redo actions.
QAction *undoAction = qApp->getUndoStack()->createUndoAction(this, tr("&Undo"));
undoAction = qApp->getUndoStack()->createUndoAction(this, tr("&Undo"));
undoAction->setShortcuts(QKeySequence::Undo);
undoAction->setIcon(QIcon::fromTheme("edit-undo"));
ui->menuPatternPiece->insertAction(ui->actionLast_tool, undoAction);
ui->toolBarTools->addAction(undoAction);
QAction *redoAction = qApp->getUndoStack()->createRedoAction(this, tr("&Redo"));
redoAction = qApp->getUndoStack()->createRedoAction(this, tr("&Redo"));
redoAction->setShortcuts(QKeySequence::Redo);
redoAction->setIcon(QIcon::fromTheme("edit-redo"));
ui->menuPatternPiece->insertAction(ui->actionLast_tool, redoAction);
@ -2208,7 +2364,8 @@ void MainWindow::CreateMenus()
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct);
//Add dock
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, ui->dockWidgetToolOptions->toggleViewAction());
actionDockWidgetToolOptions = ui->dockWidgetToolOptions->toggleViewAction();
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, actionDockWidgetToolOptions);
separatorAct = new QAction(this);
separatorAct->setSeparator(true);
@ -2387,6 +2544,14 @@ void MainWindow::CreateActions()
connect(ui->actionEdit_pattern_code, &QAction::triggered, this, &MainWindow::EditPatternCode);
connect(ui->actionCloseWindow, &QAction::triggered, this, &MainWindow::ResetWindow);
connect(ui->actionShowCurveDetails, &QAction::triggered, this, &MainWindow::ActionCurveDetailsMode);
connect(ui->actionExportAs, &QAction::triggered, this, &MainWindow::ExportLayoutAs);
connect(ui->actionPrintPreview, &QAction::triggered, this, &MainWindow::PrintPreviewOrigin);
connect(ui->actionPrintPreviewTailed, &QAction::triggered, this, &MainWindow::PrintPreviewTiled);
connect(ui->actionSaveAsPDF, &QAction::triggered, this, &MainWindow::SaveAsPDF);
connect(ui->actionSaveAsTiledPDF, &QAction::triggered, this, &MainWindow::SaveAsTiledPDF);
connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::PrintOrigin);
connect(ui->actionPrintTiled, &QAction::triggered, this, &MainWindow::PrintTiled);
ui->actionEdit_pattern_code->setEnabled(false);
//Actions for recent files loaded by a main window application.
@ -2452,11 +2617,11 @@ QString MainWindow::PatternPieceName(const QString &text)
MainWindow::~MainWindow()
{
CancelTool();
ClearLayout();
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
delete lock; // Unlock pattern file
#endif
delete pattern;
delete doc;
delete sceneDetails;
delete sceneDraw;
@ -2644,6 +2809,23 @@ void MainWindow::ToolBarStyles()
ToolBarStyle(ui->mainToolBar);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ShowPaper(int index)
{
if (index < 0 || index >= scenes.size())
{
ui->view->setScene(tempSceneLayout);
SetLayoutModeActions(false);
}
else
{
ui->view->setScene(scenes.at(index));
SetLayoutModeActions(true);
}
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToolBarStyle(QToolBar *bar)
{

View File

@ -29,15 +29,12 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "widgets/vmaingraphicsscene.h"
#include "mainwindowsnogui.h"
#include "widgets/vmaingraphicsview.h"
#include "dialogs/dialogs.h"
#include "tools/vtooldetail.h"
#include "tools/vtooluniondetails.h"
#include "tools/drawTools/drawtools.h"
#include "xml/vdomdocument.h"
#include "../libs/vlayout/vlayoutdetail.h"
namespace Ui
{
@ -49,7 +46,7 @@ class VToolOptionsPropertyBrowser;
/**
* @brief The MainWindow class main windows.
*/
class MainWindow : public QMainWindow
class MainWindow : public MainWindowsNoGUI
{
Q_OBJECT
public:
@ -70,7 +67,6 @@ public slots:
void ActionCurveDetailsMode(bool checked);
void DrawOption();
void tableClosed();
void ClosedActionTable();
void ClosedActionHistory();
@ -140,14 +136,9 @@ public slots:
void GlobalChangePP(const QString &patternPiece);
void WindowsLocale();
void ToolBarStyles();
void ShowPaper(int index);
signals:
/**
* @brief ModelChosen emit after calculation all details.
* @param listDetails list of details.
* @param description pattern description.
*/
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &curFile,
const QString &description);
void RefreshHistory();
void EnableItemMove(bool move);
protected:
@ -155,16 +146,15 @@ protected:
virtual void showEvent(QShowEvent *event);
virtual void closeEvent(QCloseEvent *event);
virtual void customEvent(QEvent * event);
virtual void ClearLayout();
virtual void PrepareSceneList();
private:
Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */
Ui::MainWindow *ui;
/** @brief pattern container with data (points, arcs, splines, spline paths, variables) */
VContainer *pattern;
/** @brief doc dom document container */
VPattern *doc;
/** @brief tool current tool */
Tool currentTool;
@ -172,9 +162,6 @@ private:
/** @brief tool last used tool */
Tool lastUsedTool;
/** @brief currentScene pointer to current scene. */
VMainGraphicsScene *currentScene;
/** @brief sceneDraw draw scene. */
VMainGraphicsScene *sceneDraw;
@ -197,9 +184,6 @@ private:
/** @brief comboBoxDraws comboc who show name of pattern peaces. */
QComboBox *comboBoxDraws;
/** @brief fileName name current pattern file. */
QString curFile;
/** @brief mode keep current draw mode. */
Draw mode;
@ -232,6 +216,7 @@ private:
void SetEnableWidgets(bool enable);
void SetEnableTool(bool enable);
void SetLayoutModeActions(bool enable);
void SaveCurrentScene();
void RestoreCurrentScene();
@ -284,6 +269,8 @@ private:
void ToolBarStyle(QToolBar *bar);
void AddPP(const QString &PPName, const QString &path);
void InitScenes();
};
#endif // MAINWINDOW_H

View File

@ -24,6 +24,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolBox" name="toolBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>2</horstretch>
@ -685,6 +688,9 @@
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonNewDetail">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Seam allowance tool</string>
</property>
@ -734,6 +740,45 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_6">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>105</width>
<height>380</height>
</rect>
</property>
<attribute name="label">
<string>Layout</string>
</attribute>
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonLayoutSettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Settings</string>
</property>
<property name="icon">
<iconset theme="emblem-system">
<normaloff/>
</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@ -770,11 +815,27 @@
<property name="title">
<string>&amp;File</string>
</property>
<widget class="QMenu" name="menuLayout">
<property name="title">
<string>Layout</string>
</property>
<addaction name="actionSaveAsPDF"/>
<addaction name="actionPrintPreview"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionSaveAsTiledPDF"/>
<addaction name="actionPrintPreviewTailed"/>
<addaction name="actionPrintTiled"/>
<addaction name="separator"/>
<addaction name="actionExportAs"/>
</widget>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
<addaction name="separator"/>
<addaction name="menuLayout"/>
<addaction name="separator"/>
<addaction name="actionPreferences"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
@ -990,6 +1051,67 @@
</attribute>
<addaction name="actionArrowTool"/>
</widget>
<widget class="QDockWidget" name="dockWidgetLayoutPages">
<property name="features">
<set>QDockWidget::NoDockWidgetFeatures</set>
</property>
<property name="allowedAreas">
<set>Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle">
<string>Layout pages</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="tabKeyNavigation">
<bool>true</bool>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>150</width>
<height>200</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>10</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<action name="actionNew">
<property name="icon">
<iconset theme="document-new">
@ -1202,6 +1324,9 @@
</property>
</action>
<action name="actionLayout">
<property name="checkable">
<bool>true</bool>
</property>
<property name="enabled">
<bool>false</bool>
</property>
@ -1375,6 +1500,9 @@
</property>
</action>
<action name="actionLast_tool">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Last Tool</string>
</property>
@ -1402,6 +1530,115 @@
<string>F2</string>
</property>
</action>
<action name="actionSaveAsPDF">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/pdf.png</normaloff>:/icon/32x32/pdf.png</iconset>
</property>
<property name="text">
<string>Save as PDF</string>
</property>
<property name="toolTip">
<string>Save original layout</string>
</property>
</action>
<action name="actionSaveAsTiledPDF">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/pdf.png</normaloff>:/icon/32x32/pdf.png</iconset>
</property>
<property name="text">
<string>Save as tiled PDF</string>
</property>
<property name="toolTip">
<string>Split and save a layout into smaller pages</string>
</property>
</action>
<action name="actionPrint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-print">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Print</string>
</property>
<property name="toolTip">
<string>Print original a layout</string>
</property>
</action>
<action name="actionPrintTiled">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-print">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Print tiled</string>
</property>
<property name="toolTip">
<string>Split and print a layout into smaller pages (for regular printers)</string>
</property>
</action>
<action name="actionPrintPreview">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-print-preview">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Print preview</string>
</property>
<property name="toolTip">
<string>Print preview original layout</string>
</property>
</action>
<action name="actionPrintPreviewTailed">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-print-preview">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Print preview tailed</string>
</property>
<property name="toolTip">
<string>Print preview tailed layout</string>
</property>
</action>
<action name="actionExportAs">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/export_to_picture_document.png</normaloff>:/icon/32x32/export_to_picture_document.png</iconset>
</property>
<property name="text">
<string>Export As...</string>
</property>
<property name="toolTip">
<string>Export original layout</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View File

@ -1,14 +1,14 @@
/************************************************************************
**
** @file tablewindow.cpp
** @file mainwindowsnogui.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date November 15, 2013
** @date 12 5, 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) 2013-2015 Valentina project
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
@ -26,11 +26,9 @@
**
*************************************************************************/
#include "tablewindow.h"
#include "ui_tablewindow.h"
#include "widgets/vtablegraphicsview.h"
#include "core/vapplication.h"
#include "core/vsettings.h"
#include "mainwindowsnogui.h"
#include "../core/vapplication.h"
#include "../container/vcontainer.h"
#include "../../libs/vobj/vobjpaintdevice.h"
#include "../dialogs/app/dialoglayoutsettings.h"
#include "../../libs/vlayout/vlayoutgenerator.h"
@ -38,13 +36,16 @@
#include "../dialogs/app/dialogsavelayout.h"
#include "../../libs/vlayout/vposter.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
#include <QMessageBox>
#include <QProcess>
#include <QToolButton>
#include <QtSvg>
#include <QPrinter>
#include <QGraphicsScene>
#include <QPrintPreviewDialog>
#include <QPrintDialog>
#include <QtPrintSupport>
#include <QtCore/qmath.h>
#ifdef Q_OS_WIN
# define PDFTOPS "pdftops.exe"
@ -53,135 +54,91 @@
#endif
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief TableWindow constructor.
* @param parent parent widget.
*/
TableWindow::TableWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::TableWindow),
listDetails(QVector<VLayoutDetail>()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()), fileName(QString()),
description(QString()), tempScene(nullptr)
MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
: QMainWindow(parent), listDetails(QVector<VLayoutDetail>()), currentScene(nullptr), tempSceneLayout(nullptr),
pattern(new VContainer()), doc(nullptr), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()), undoAction(nullptr),
redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), isLayoutStale(true), isTiled(false)
{
ui->setupUi(this);
qApp->getSettings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)));
QBrush brush;
brush.setStyle( Qt::SolidPattern );
brush.setColor( QColor( Qt::gray ) );
tempScene->setBackgroundBrush( brush );
ui->view->setScene(tempScene);
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
ui->horizontalLayout->addWidget(ui->view);
connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn);
connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut);
connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable);
connect(ui->actionSave, &QAction::triggered, this, &TableWindow::SaveLayout);
connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper);
connect(ui->actionPrint_pre_view, &QAction::triggered, this, &TableWindow::PrintPreview);
connect(ui->action_Print, &QAction::triggered, this, &TableWindow::LayoutPrint);
connect(ui->actionSave_to_p_df, &QAction::triggered, this, &TableWindow::PrintToPdf);
ReadSettings();
#if defined(Q_OS_MAC)
// On Mac deafault icon size is 32x32.
ui->toolBar->setIconSize(QSize(24, 24));
#endif
InitTempLayoutScene();
}
//---------------------------------------------------------------------------------------------------------------------
TableWindow::~TableWindow()
MainWindowsNoGUI::~MainWindowsNoGUI()
{
ClearLayout();
delete ui;
delete tempSceneLayout;
delete pattern;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ModelChosen show window when user want create new layout.
* @param listDetails list of details.
* @param description pattern description.
*/
/*
* Get details for creation layout.
*/
void TableWindow::ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName, const QString &description)
void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
{
this->description = description;
QToolButton *tButton = qobject_cast< QToolButton * >(this->sender());
SCASSERT(tButton != nullptr)
QString file;
if (fileName.isEmpty())
if (checked)
{
file = tr("untitled");
VLayoutGenerator lGenerator(this);
lGenerator.SetDetails(listDetails);
DialogLayoutSettings layout(&lGenerator, this);
if (layout.exec() == QDialog::Rejected)
{
tButton->setChecked(false);
return;
}
DialogLayoutProgress progress(listDetails.count(), this);
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
lGenerator.Generate();
switch (lGenerator.State())
{
case LayoutErrors::NoError:
ClearLayout();
papers = lGenerator.GetPapersItems();// Blank sheets
details = lGenerator.GetAllDetails();// All details
CreateShadows();
CreateScenes();
PrepareSceneList();
isLayoutStale = false;
break;
case LayoutErrors::ProcessStoped:
break;
case LayoutErrors::PrepareLayoutError:
case LayoutErrors::PaperSizeError:
case LayoutErrors::EmptyPaperError:
ClearLayout();
break;
default:
break;
}
tButton->setChecked(false);
}
else
{
file = fileName;
tButton->setChecked(true);
}
QFileInfo fi( file );
this->fileName = fi.baseName();
this->listDetails = listDetails;
show();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief closeEvent handle after close window.
* @param event close event.
*/
void TableWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
StopTable();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief moveToCenter move screen to the center of window.
*/
void TableWindow::moveToCenter()
{
QRect rect = frameGeometry();
rect.moveCenter(QDesktopWidget().availableGeometry().center());
move(rect.topLeft());
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief showEvent handle after show window.
* @param event show event.
*/
void TableWindow::showEvent ( QShowEvent * event )
{
QMainWindow::showEvent(event);
moveToCenter();
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief StopTable stop creation layout.
*/
void TableWindow::StopTable()
{
hide();
ClearLayout();
emit closed();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief saveScene save created layout.
*/
void TableWindow::SaveLayout()
void MainWindowsNoGUI::ExportLayoutAs()
{
if (isLayoutStale)
{
if (ContinueIfLayoutStale() == QMessageBox::No)
{
return;
}
}
QMap<QString, QString> extByMessage = InitFormates();
DialogSaveLayout dialog(extByMessage, scenes.size(), fileName, this);
DialogSaveLayout dialog(extByMessage, scenes.size(), FileName(), this);
if (dialog.exec() == QDialog::Rejected)
{
@ -206,7 +163,7 @@ void TableWindow::SaveLayout()
scenes[i]->setBackgroundBrush( *brush );
shadows[i]->setVisible(false);
paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj";
const QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj";
switch (suffix.indexOf(suf))
{
case 0: //svg
@ -246,55 +203,27 @@ void TableWindow::SaveLayout()
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ShowPaper(int index)
void MainWindowsNoGUI::SaveAsPDF()
{
if (index < 0 || index > scenes.size())
if (not isPagesUniform())
{
ui->view->setScene(tempScene);
EnableActions(false);
qCritical()<<tr("For saving multypage document all sheet should have the same size. Use export "
"function instead.");
return;
}
else
{
ui->view->setScene(scenes.at(index));
}
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
isTiled = false;
SaveLayoutAs();
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::PrintPreview()
void MainWindowsNoGUI::SaveAsTiledPDF()
{
QPrinterInfo def = QPrinterInfo::defaultPrinter();
//if there is no default printer set the print preview won't show
if(def.isNull() || def.printerName().isEmpty())
{
if(QPrinterInfo::availablePrinters().isEmpty())
{
QMessageBox::critical(this, tr("Print error"),
tr("Cannot proceed because there are no available printers in your system."),
QMessageBox::Ok);
return;
}
else
{
def = QPrinterInfo::availablePrinters().first();
}
}
QPrinter printer(def, QPrinter::ScreenResolution);
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
printer.setDocName(fileName);
// display print preview dialog
QPrintPreviewDialog preview(&printer);
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &TableWindow::Print);
preview.exec();
isTiled = true;
SaveLayoutAs();
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::Print(QPrinter *printer)
void MainWindowsNoGUI::PrintPages(QPrinter *printer)
{
if (printer == nullptr)
{
@ -303,11 +232,18 @@ void TableWindow::Print(QPrinter *printer)
const QVector<QImage> images = AllSheets();
VPoster posterazor(printer);
QVector<QImage> poster;
for (int i=0; i < images.size(); i++)
if (isTiled)
{
poster += posterazor.Generate(images.at(i), i+1, images.size());
VPoster posterazor(printer);
for (int i=0; i < images.size(); i++)
{
poster += posterazor.Generate(images.at(i), i+1, images.size());
}
}
else
{
poster = images;
}
QPainter painter;
@ -370,92 +306,180 @@ void TableWindow::Print(QPrinter *printer)
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::LayoutPrint()
void MainWindowsNoGUI::PrintPreviewOrigin()
{
// display print dialog and if accepted print
QPrinter printer(QPrinter::HighResolution);
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
printer.setDocName(fileName);
QPrintDialog dialog( &printer, this );
// If only user couldn't change page margins we could use method setMinMax();
dialog.setOption(QPrintDialog::PrintCurrentPage, false);
if ( dialog.exec() == QDialog::Accepted )
if (not isPagesUniform())
{
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
Print( &printer );
qCritical()<<tr("For previewing multypage document all sheet should have the same size.");
return;
}
isTiled = false;
PrintPreview();
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::PrintPreviewTiled()
{
isTiled = true;
PrintPreview();
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::PrintOrigin()
{
if (not isPagesUniform())
{
qCritical()<<tr("For printing multypages document all sheet should have the same size.");
return;
}
isTiled = false;
LayoutPrint();
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::PrintTiled()
{
isTiled = false;
LayoutPrint();
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VDetail> *details)
{
SCASSERT(details != nullptr)
if (details->count() == 0)
{
listDetails.clear();
return;
}
listDetails.clear();
QHashIterator<quint32, VDetail> idetail(*details);
while (idetail.hasNext())
{
idetail.next();
VLayoutDetail det = VLayoutDetail();
det.SetCountourPoints(idetail.value().ContourPoints(pattern));
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern),
idetail.value().getSeamAllowance());
det.setName(idetail.value().getName());
det.setWidth(qApp->toPixel(idetail.value().getWidth()));
listDetails.append(det);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::PrintToPdf()
void MainWindowsNoGUI::InitTempLayoutScene()
{
QPrinter printer;
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
printer.setDocName(fileName);
tempSceneLayout = new QGraphicsScene();
tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) );
}
QPageSetupDialog dialog(&printer, this);
if ( dialog.exec() == QDialog::Accepted )
//---------------------------------------------------------------------------------------------------------------------
QIcon MainWindowsNoGUI::ScenePreview(int i) const
{
QImage image;
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
{
printer.setOutputFormat(QPrinter::PdfFormat);
QString fileName = QFileDialog::getSaveFileName(this, tr("Print to pdf"),
QDir::homePath()+"/"+this->fileName+".pdf",
tr("PDF file (*.pdf)"));
if (not fileName.isEmpty())
{
if(QFileInfo(fileName).suffix().isEmpty())
{
fileName.append(".pdf");
}
const QRectF r = paper->rect();
// Create the image with the exact size of the shrunk scene
image = QImage(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
printer.setOutputFileName(fileName);
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
Print( &printer );
if (not image.isNull())
{
image.fill(Qt::white);
QPainter painter(&image);
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
scenes.at(i)->render(&painter);
painter.end();
}
else
{
qWarning()<<"Cannot create image. Size too big";
}
}
else
{
image = QImage(QSize(101, 146), QImage::Format_RGB32);
image.fill(Qt::white);
}
return QIcon(QBitmap::fromImage(image));
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::CreateShadows()
{
for (int i=0; i< papers.size(); ++i)
{
qreal x1=0, y1=0, x2=0, y2=0;
QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (item)
{
item->rect().getCoords(&x1, &y1, &x2, &y2);
QGraphicsRectItem *shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4));
shadowPaper->setBrush(QBrush(Qt::black));
shadows.append(shadowPaper);
}
else
{
shadows.append(nullptr);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::Layout()
void MainWindowsNoGUI::CreateScenes()
{
VLayoutGenerator lGenerator(this);
lGenerator.SetDetails(listDetails);
DialogLayoutSettings layout(&lGenerator, this);
if (layout.exec() == QDialog::Rejected)
for (int i=0; i<papers.size(); ++i)
{
return;
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern));
scene->addItem(shadows.at(i));
scene->addItem(papers.at(i));
QList<QGraphicsItem *> paperDetails = details.at(i);
for (int i=0; i < paperDetails.size(); ++i)
{
scene->addItem(paperDetails.at(i));
}
scenes.append(scene);
}
}
DialogLayoutProgress progress(listDetails.count(), this);
//---------------------------------------------------------------------------------------------------------------------
QMap<QString, QString> MainWindowsNoGUI::InitFormates() const
{
QMap<QString, QString> extByMessage;
extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
extByMessage[ tr("Images (*.png)") ] = ".png";
extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj";
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
lGenerator.Generate();
switch (lGenerator.State())
QProcess proc;
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
proc.start(qApp->applicationDirPath()+"/"+PDFTOPS); // Seek pdftops in app bundle or near valentin.exe
#else
proc.start(PDFTOPS); // Seek pdftops in standard path
#endif
if (proc.waitForFinished(15000))
{
case LayoutErrors::NoError:
ClearLayout();
papers = lGenerator.GetPapersItems();// Blank sheets
details = lGenerator.GetAllDetails();// All details
CreateShadows();
CreateScenes();
PrepareSceneList();
break;
case LayoutErrors::ProcessStoped:
break;
case LayoutErrors::PrepareLayoutError:
case LayoutErrors::PaperSizeError:
case LayoutErrors::EmptyPaperError:
ClearLayout();
break;
default:
break;
extByMessage[ tr("PS files (*.ps)") ] = ".ps";
extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
}
else
{
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
}
return extByMessage;
}
//---------------------------------------------------------------------------------------------------------------------
@ -463,7 +487,7 @@ void TableWindow::Layout()
* @brief SvgFile save layout to svg file.
* @param name name layout file.
*/
void TableWindow::SvgFile(const QString &name, int i) const
void MainWindowsNoGUI::SvgFile(const QString &name, int i) const
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
@ -473,7 +497,7 @@ void TableWindow::SvgFile(const QString &name, int i) const
generator.setSize(paper->rect().size().toSize());
generator.setViewBox(paper->rect());
generator.setTitle("Valentina. Pattern layout");
generator.setDescription(description);
generator.setDescription(doc->GetDescription());
generator.setResolution(static_cast<int>(qApp->PrintDPI));
QPainter painter;
painter.begin(&generator);
@ -492,7 +516,7 @@ void TableWindow::SvgFile(const QString &name, int i) const
* @brief PngFile save layout to png file.
* @param name name layout file.
*/
void TableWindow::PngFile(const QString &name, int i) const
void MainWindowsNoGUI::PngFile(const QString &name, int i) const
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
@ -517,16 +541,27 @@ void TableWindow::PngFile(const QString &name, int i) const
* @brief PdfFile save layout to pdf file.
* @param name name layout file.
*/
void TableWindow::PdfFile(const QString &name, int i) const
void MainWindowsNoGUI::PdfFile(const QString &name, int i) const
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
{
QPrinter printer;
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(name);
printer.setDocName(FileName());
const QRectF r = paper->rect();
printer.setResolution(static_cast<int>(qApp->PrintDPI));
// Set orientation
if (paper->rect().height()>= paper->rect().width())
{
printer.setOrientation(QPrinter::Portrait);
}
else
{
printer.setOrientation(QPrinter::Landscape);
}
printer.setPaperSize ( QSizeF(qApp->fromPixel(r.width(), Unit::Mm), qApp->fromPixel(r.height(), Unit::Mm)),
QPrinter::Millimeter );
QPainter painter;
@ -550,7 +585,7 @@ void TableWindow::PdfFile(const QString &name, int i) const
* @brief EpsFile save layout to eps file.
* @param name name layout file.
*/
void TableWindow::EpsFile(const QString &name, int i) const
void MainWindowsNoGUI::EpsFile(const QString &name, int i) const
{
QTemporaryFile tmp;
if (tmp.open())
@ -566,7 +601,7 @@ void TableWindow::EpsFile(const QString &name, int i) const
* @brief PsFile save layout to ps file.
* @param name name layout file.
*/
void TableWindow::PsFile(const QString &name, int i) const
void MainWindowsNoGUI::PsFile(const QString &name, int i) const
{
QTemporaryFile tmp;
if (tmp.open())
@ -583,7 +618,7 @@ void TableWindow::PsFile(const QString &name, int i) const
* @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when
* need create eps file.
*/
void TableWindow::PdfToPs(const QStringList &params) const
void MainWindowsNoGUI::PdfToPs(const QStringList &params) const
{
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
@ -605,7 +640,7 @@ void TableWindow::PdfToPs(const QStringList &params) const
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ObjFile(const QString &name, int i) const
void MainWindowsNoGUI::ObjFile(const QString &name, int i) const
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
@ -622,7 +657,7 @@ void TableWindow::ObjFile(const QString &name, int i) const
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QImage> TableWindow::AllSheets()
QVector<QImage> MainWindowsNoGUI::AllSheets()
{
QVector<QImage> images;
for (int i=0; i < scenes.size(); ++i)
@ -665,172 +700,174 @@ QVector<QImage> TableWindow::AllSheets()
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ClearLayout()
void MainWindowsNoGUI::SaveLayoutAs()
{
qDeleteAll (scenes);
scenes.clear();
shadows.clear();
papers.clear();
ui->listWidget->clear();
EnableActions(false);
if (isLayoutStale)
{
if (ContinueIfLayoutStale() == QMessageBox::No)
{
return;
}
}
QPrinter printer;
SetPrinterSettings(&printer);
printer.setOutputFormat(QPrinter::PdfFormat);
QString fileName = QFileDialog::getSaveFileName(this, tr("Print to pdf"),
qApp->getSettings()->GetPathLayout()+"/"+FileName()+".pdf",
tr("PDF file (*.pdf)"));
if (not fileName.isEmpty())
{
QFileInfo f( fileName );
if(f.suffix().isEmpty())
{
fileName.append(".pdf");
}
qApp->getSettings()->SetPathLayout(f.absolutePath());
printer.setOutputFileName(fileName);
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
PrintPages( &printer );
}
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::CreateShadows()
void MainWindowsNoGUI::PrintPreview()
{
for (int i=0; i< papers.size(); ++i)
if (isLayoutStale)
{
qreal x1=0, y1=0, x2=0, y2=0;
QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (item)
if (ContinueIfLayoutStale() == QMessageBox::No)
{
item->rect().getCoords(&x1, &y1, &x2, &y2);
QGraphicsRectItem *shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4));
shadowPaper->setBrush(QBrush(Qt::black));
shadows.append(shadowPaper);
return;
}
}
QPrinterInfo def = QPrinterInfo::defaultPrinter();
//if there is no default printer set the print preview won't show
if(def.isNull() || def.printerName().isEmpty())
{
if(QPrinterInfo::availablePrinters().isEmpty())
{
QMessageBox::critical(this, tr("Print error"),
tr("Cannot proceed because there are no available printers in your system."),
QMessageBox::Ok);
return;
}
else
{
shadows.append(nullptr);
def = QPrinterInfo::availablePrinters().first();
}
}
QPrinter printer(def, QPrinter::ScreenResolution);
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
SetPrinterSettings(&printer);
// display print preview dialog
QPrintPreviewDialog preview(&printer);
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages);
preview.exec();
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::CreateScenes()
void MainWindowsNoGUI::LayoutPrint()
{
QBrush brush;
brush.setStyle( Qt::SolidPattern );
brush.setColor( QColor( Qt::gray ) );
for (int i=0; i<papers.size(); ++i)
if (isLayoutStale)
{
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(brush);
scene->addItem(shadows.at(i));
scene->addItem(papers.at(i));
QList<QGraphicsItem *> paperDetails = details.at(i);
for (int i=0; i < paperDetails.size(); ++i)
if (ContinueIfLayoutStale() == QMessageBox::No)
{
scene->addItem(paperDetails.at(i));
return;
}
scenes.append(scene);
}
// display print dialog and if accepted print
QPrinter printer(QPrinter::HighResolution);
SetPrinterSettings(&printer);
QPrintDialog dialog( &printer, this );
// If only user couldn't change page margins we could use method setMinMax();
dialog.setOption(QPrintDialog::PrintCurrentPage, false);
if ( dialog.exec() == QDialog::Accepted )
{
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
PrintPages( &printer );
}
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::PrepareSceneList()
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
{
for (int i=1; i<=scenes.size(); ++i)
{
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1), QString::number(i));
ui->listWidget->addItem(item);
}
SCASSERT(printer != nullptr)
printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
if (not scenes.isEmpty())
// Set orientation
if (papers.size() > 0)
{
ui->listWidget->setCurrentRow(0);
EnableActions(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
QIcon TableWindow::ScenePreview(int i) const
{
QImage image;
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
{
const QRectF r = paper->rect();
// Create the image with the exact size of the shrunk scene
image = QImage(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
if (not image.isNull())
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
SCASSERT(paper != nullptr)
if (paper->rect().height()>= paper->rect().width())
{
image.fill(Qt::white);
QPainter painter(&image);
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
scenes.at(i)->render(&painter);
painter.end();
printer->setOrientation(QPrinter::Portrait);
}
else
{
qWarning()<<"Cannot create image. Size too big";
printer->setOrientation(QPrinter::Landscape);
}
}
else
if (not isTiled && papers.size() > 0)
{
image = QImage(QSize(101, 146), QImage::Format_RGB32);
image.fill(Qt::white);
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
SCASSERT(paper != nullptr)
printer->setPaperSize ( QSizeF(qApp->fromPixel(paper->rect().width(), Unit::Mm),
qApp->fromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter );
}
return QIcon(QBitmap::fromImage(image));
printer->setDocName(FileName());
}
//---------------------------------------------------------------------------------------------------------------------
QMap<QString, QString> TableWindow::InitFormates() const
bool MainWindowsNoGUI::isPagesUniform() const
{
QMap<QString, QString> extByMessage;
extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
extByMessage[ tr("Images (*.png)") ] = ".png";
extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj";
QProcess proc;
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
proc.start(qApp->applicationDirPath()+"/"+PDFTOPS); // Seek pdftops in app bundle or near valentin.exe
#else
proc.start(PDFTOPS); // Seek pdftops in standard path
#endif
if (proc.waitForFinished(15000))
if (papers.size() < 2)
{
extByMessage[ tr("PS files (*.ps)") ] = ".ps";
extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
return true;
}
else
{
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
SCASSERT(paper != nullptr)
for (int i=1; i < papers.size(); ++i)
{
QGraphicsRectItem *p = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
SCASSERT(p != nullptr)
if (paper->rect() != p->rect())
{
return false;
}
}
}
return extByMessage;
return true;
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::EnableActions(bool enable)
QString MainWindowsNoGUI::FileName() const
{
ui->actionSave->setEnabled(enable);
ui->actionSave_to_p_df->setEnabled(enable);
ui->actionPrint_pre_view->setEnabled(enable);
ui->action_Print->setEnabled(enable);
QString fileName;
curFile.isEmpty() ? fileName = tr("unnamed") : fileName = curFile;
return QFileInfo(fileName).baseName();
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ToolBarStyle(QToolBar *bar)
int MainWindowsNoGUI::ContinueIfLayoutStale()
{
if (qApp->getSettings()->GetToolBarStyle())
{
bar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
}
else
{
bar->setToolButtonStyle(Qt::ToolButtonIconOnly);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ReadSettings()
{
// Text under tool buton icon
ToolBarStyles();
}
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ToolBarStyles()
{
ToolBarStyle(ui->toolBar);
ToolBarStyle(ui->toolBar_2);
QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(tr("The layout is stale."));
msgBox.setText(tr("The layout was not updated since last pattern modification. Do you want to continue?"));
msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout* layout = static_cast<QGridLayout*>(msgBox.layout());
SCASSERT(layout != nullptr);
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox.exec();
return msgBox.result();
}

View File

@ -1,14 +1,14 @@
/************************************************************************
**
** @file tablewindow.h
** @file mainwindowsnogui.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date November 15, 2013
** @date 12 5, 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) 2013-2015 Valentina project
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
@ -26,74 +26,80 @@
**
*************************************************************************/
#ifndef TABLEWINDOW_H
#define TABLEWINDOW_H
#ifndef MAINWINDOWSNOGUI_H
#define MAINWINDOWSNOGUI_H
#include <QLabel>
#include <QMainWindow>
#include "../../libs/vlayout/vlayoutdetail.h"
#include "../../libs/vlayout/vbank.h"
namespace Ui
{
class TableWindow;
}
#include "../geometry/vdetail.h"
#include "../libs/vlayout/vlayoutdetail.h"
#include "xml/vpattern.h"
class QGraphicsScene;
class QGraphicsRectItem;
class QPrinter;
/**
* @brief TableWindow class layout window.
*/
class TableWindow : public QMainWindow
class MainWindowsNoGUI : public QMainWindow
{
Q_OBJECT
public:
explicit TableWindow(QWidget *parent = nullptr);
~TableWindow();
MainWindowsNoGUI(QWidget *parent = nullptr);
virtual ~MainWindowsNoGUI();
public slots:
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName, const QString &description);
void Layout();
void StopTable();
void SaveLayout();
void ShowPaper(int index);
void PrintPreview();
void Print (QPrinter *printer);
void LayoutPrint();
void PrintToPdf();
signals:
/** @brief closed emit if window is closing. */
void closed();
void ToolLayoutSettings(bool checked);
void ExportLayoutAs();
void SaveAsPDF();
void SaveAsTiledPDF();
void PrintPages (QPrinter *printer);
void PrintPreviewOrigin();
void PrintPreviewTiled();
void PrintOrigin();
void PrintTiled();
protected:
void closeEvent(QCloseEvent *event);
void moveToCenter();
void showEvent ( QShowEvent * event );
private:
Q_DISABLE_COPY(TableWindow)
/** @brief ui keeps information about user interface */
Ui::TableWindow* ui;
/** @brief listDetails list of details. */
QVector<VLayoutDetail> listDetails;
/** @brief currentScene pointer to current scene. */
QGraphicsScene *currentScene;
QGraphicsScene *tempSceneLayout;
/** @brief pattern container with data (points, arcs, splines, spline paths, variables) */
VContainer *pattern;
/** @brief doc dom document container */
VPattern *doc;
QList<QGraphicsItem *> papers;
QList<QGraphicsItem *> shadows;
QList<QGraphicsScene *> scenes;
QList<QList<QGraphicsItem *> > details;
/** @brief fileName keep name of pattern file. */
QString fileName;
QAction *undoAction;
QAction *redoAction;
QAction *actionDockWidgetToolOptions;
/** @brief description pattern description */
QString description;
/** @brief fileName name current pattern file. */
QString curFile;
QGraphicsScene* tempScene;
bool isLayoutStale;
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
void InitTempLayoutScene();
virtual void ClearLayout()=0;
virtual void PrepareSceneList()=0;
QIcon ScenePreview(int i) const;
private:
Q_DISABLE_COPY(MainWindowsNoGUI)
bool isTiled;
void CreateShadows();
void CreateScenes();
QMap<QString, QString> InitFormates() const;
void SvgFile(const QString &name, int i)const;
void PngFile(const QString &name, int i)const;
@ -105,17 +111,16 @@ private:
QVector<QImage> AllSheets();
void ClearLayout();
void CreateShadows();
void CreateScenes();
void PrepareSceneList();
QIcon ScenePreview(int i) const;
QMap<QString, QString> InitFormates() const;
void SaveLayoutAs();
void PrintPreview();
void LayoutPrint();
void EnableActions(bool enable);
void ToolBarStyle(QToolBar *bar);
void ReadSettings();
void ToolBarStyles();
void SetPrinterSettings(QPrinter *printer);
bool isPagesUniform() const;
QString FileName() const;
int ContinueIfLayoutStale();
};
#endif // TABLEWINDOW_H
#endif // MAINWINDOWSNOGUI_H

View File

@ -60,5 +60,6 @@
<file>icon/16x16/fx.png</file>
<file>icon/16x16/roll.png</file>
<file>icon/16x16/progress.gif</file>
<file>icon/32x32/export_to_picture_document.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -5,7 +5,7 @@ Inherits=gnome,hicolor
Example=x-directory-normal
#Directories
Directories=16x16/actions,24x24/actions,32x32/actions
Directories=16x16/actions,24x24/actions,32x32/actions,32x32/emblems
[16x16/actions]
Size=16
@ -22,4 +22,8 @@ Size=32
Context=Actions
Type=Fixed
[32x32/emblemss]
Size=32
Context=Emblems
Type=Fixed

View File

@ -67,5 +67,6 @@
<file alias="16x16/actions/document-print-preview.png">icons/win.icon.theme/16x16/actions/document-print-preview.png</file>
<file alias="24x24/actions/document-print-preview.png">icons/win.icon.theme/24x24/actions/document-print-preview.png</file>
<file alias="32x32/actions/document-print-preview.png">icons/win.icon.theme/32x32/actions/document-print-preview.png</file>
<file alias="32x32/emblems/emblem-system.png">icons/win.icon.theme/32x32/emblems/emblem-system.png</file>
</qresource>
</RCC>

View File

@ -1,328 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TableWindow</class>
<widget class="QMainWindow" name="TableWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>730</height>
</rect>
</property>
<property name="windowTitle">
<string>Create a layout</string>
</property>
<property name="windowIcon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="VTableGraphicsView" name="view">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>20</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="resizeAnchor">
<enum>QGraphicsView::AnchorUnderMouse</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="windowTitle">
<string>Main toolbar</string>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionSave"/>
<addaction name="actionZoomIn"/>
<addaction name="actionZoomOut"/>
<addaction name="actionStop"/>
<addaction name="actionLayout"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QDockWidget" name="dockWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>187</width>
<height>121</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>187</width>
<height>524287</height>
</size>
</property>
<property name="features">
<set>QDockWidget::DockWidgetMovable</set>
</property>
<property name="allowedAreas">
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle">
<string>Layout pages</string>
</property>
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="iconSize">
<size>
<width>150</width>
<height>200</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>3</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionPrint_pre_view"/>
<addaction name="action_Print"/>
<addaction name="actionSave_to_p_df"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionZoomIn"/>
<addaction name="actionZoomOut"/>
</widget>
<widget class="QMenu" name="menuLayout">
<property name="title">
<string>Layout</string>
</property>
<addaction name="actionLayout"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuLayout"/>
</widget>
<widget class="QToolBar" name="toolBar_2">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="windowTitle">
<string>Toolbar print</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionSave_to_p_df"/>
<addaction name="actionPrint_pre_view"/>
<addaction name="action_Print"/>
</widget>
<action name="actionSave">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-save-as">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>&amp;Save As...</string>
</property>
<property name="toolTip">
<string>Save layout</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionStop">
<property name="icon">
<iconset theme="process-stop">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Back</string>
</property>
<property name="toolTip">
<string>Back to main window</string>
</property>
</action>
<action name="actionZoomIn">
<property name="icon">
<iconset theme="zoom-in">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Zoom In</string>
</property>
<property name="toolTip">
<string>Zoom In</string>
</property>
</action>
<action name="actionZoomOut">
<property name="icon">
<iconset theme="zoom-out">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Zoom Out</string>
</property>
<property name="toolTip">
<string>Zoom Out</string>
</property>
</action>
<action name="actionLayout">
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/layout.png</normaloff>:/icon/32x32/layout.png</iconset>
</property>
<property name="text">
<string>Create Layout</string>
</property>
<property name="toolTip">
<string>Create Layout</string>
</property>
</action>
<action name="actionPrint_pre_view">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-print-preview">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Print pre&amp;view...</string>
</property>
</action>
<action name="action_Print">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-print">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>&amp;Print...</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="actionSave_to_p_df">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/pdf.png</normaloff>:/icon/32x32/pdf.png</iconset>
</property>
<property name="text">
<string>Print to p&amp;df</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>VTableGraphicsView</class>
<extends>QGraphicsView</extends>
<header>vtablegraphicsview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="share/resources/icon.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -189,7 +189,8 @@ void VToolAlongLine::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolAlongLine *visual = new VisToolAlongLine(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -293,7 +293,8 @@ void VToolArc::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolArc * visual = new VisToolArc(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -347,7 +347,8 @@ void VToolBisector::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolBisector * visual = new VisToolBisector(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -227,7 +227,8 @@ void VToolCurveIntersectAxis::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCurveIntersectAxis * visual = new VisToolCurveIntersectAxis(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -192,7 +192,8 @@ void VToolCutArc::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCutArc * visual = new VisToolCutArc(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -202,7 +202,8 @@ void VToolCutSpline::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCutSpline * visual = new VisToolCutSpline(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -246,7 +246,8 @@ void VToolCutSplinePath::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -287,7 +287,8 @@ void VToolEndLine::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolEndLine * visual = new VisToolEndLine(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -291,7 +291,8 @@ void VToolHeight::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolHeight * visual = new VisToolHeight(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -428,7 +428,8 @@ void VToolLine::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolLine * visual = new VisToolLine(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -309,7 +309,8 @@ void VToolLineIntersect::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolLineIntersect * visual = new VisToolLineIntersect(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -239,7 +239,8 @@ void VToolLineIntersectAxis::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolLineIntersectAxis * visual = new VisToolLineIntersectAxis(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -324,7 +324,8 @@ void VToolNormal::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolNormal * visual = new VisToolNormal(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -355,7 +355,8 @@ void VToolPointOfContact::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolPointOfContact * visual = new VisToolPointOfContact(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -260,7 +260,8 @@ void VToolPointOfIntersection::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolPointOfIntersection * visual = new VisToolPointOfIntersection(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -353,7 +353,8 @@ void VToolShoulderPoint::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolShoulderPoint * visual = new VisToolShoulderPoint(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -237,7 +237,8 @@ void VToolSpline::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolSpline *visual = new VisToolSpline(getData(), this);
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);

View File

@ -318,7 +318,8 @@ void VToolSplinePath::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolSplinePath *visual = new VisToolSplinePath(getData(), this);
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);

View File

@ -325,7 +325,8 @@ void VToolTriangle::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolTriangle * visual = new VisToolTriangle(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View File

@ -67,7 +67,7 @@ void Visualization::setScenePos(const QPointF &value)
//---------------------------------------------------------------------------------------------------------------------
void Visualization::VisualMode(const quint32 &pointId)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
this->point1Id = pointId;

View File

@ -87,7 +87,7 @@ protected:
void AddItem(Item *item)
{
SCASSERT(item != nullptr);
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
scene->addItem(item);

View File

@ -1,255 +0,0 @@
/************************************************************************
**
** @file vtablegraphicsview.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date November 15, 2013
**
** @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) 2013-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 "vtablegraphicsview.h"
#include <QDebug>
#include <QGraphicsItem>
#include <QGuiApplication>
#include <QWheelEvent>
#include <QScrollBar>
#include "../options.h"
//---------------------------------------------------------------------------------------------------------------------
VTableGraphicsView::VTableGraphicsView(QWidget *parent)
:QGraphicsView(parent)
{
QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief selectionChanged handle selection change.
*/
// cppcheck-suppress unusedFunction
void VTableGraphicsView::selectionChanged()
{
QList<QGraphicsItem *> listSelectedItems = scene()->selectedItems();
if ( listSelectedItems.isEmpty() == true )
{
qDebug() << tr("can't find detail");
emit itemChect(true);
}
else
{
qDebug() << tr("detail found");
emit itemChect(false);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief MirrorItem mirror detail.
*/
// cppcheck-suppress unusedFunction
void VTableGraphicsView::MirrorItem()
{
QList<QGraphicsItem *> list = scene()->selectedItems();
if (list.size()>0)
{
for ( qint32 i = 0; i < list.count(); ++i )
{
QGraphicsItem *item = list.at(i);
SCASSERT(item != nullptr);
QRectF itemRectOld = item->sceneBoundingRect();
//Get the current transform
QTransform transform(item->transform());
qreal m11 = transform.m11(); // Horizontal scaling
qreal m12 = transform.m12(); // Vertical shearing
qreal m13 = transform.m13(); // Horizontal Projection
qreal m21 = transform.m21(); // Horizontal shearing
qreal m22 = transform.m22(); // vertical scaling
qreal m23 = transform.m23(); // Vertical Projection
qreal m31 = transform.m31(); // Horizontal Position (DX)
qreal m32 = transform.m32(); // Vertical Position (DY)
qreal m33 = transform.m33(); // Addtional Projection Factor
// Horizontal flip
m11 = -m11;
// Write back to the matrix
transform.setMatrix(m11, m12, m13, m21, m22, m23, m31, m32, m33);
// Set the items transformation
item->setTransform(transform);
QRectF itemRectNew = item->sceneBoundingRect();
qreal dx, dy;
dx = itemRectOld.center().x()-itemRectNew.center().x();
dy = itemRectOld.center().y()-itemRectNew.center().y();
item->moveBy(dx, dy);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief wheelEvent handle wheel events.
* @param event wheel event.
*/
// cppcheck-suppress unusedFunction
void VTableGraphicsView::wheelEvent(QWheelEvent *event)
{
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier)
{
// If was pressed button CTRL this code will execute
if ((event->delta())>0)
{
ZoomIn();
}
else if ((event->delta())<0)
{
ZoomOut();
}
}
else
{
verticalScrollBar()->setValue(verticalScrollBar()->value()-event->delta());
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mousePressEvent handle mouse press events.
* @param mousePress mouse press event.
*/
void VTableGraphicsView::mousePressEvent(QMouseEvent *mousePress)
{
if (mousePress->button() & Qt::LeftButton)
{
switch (QGuiApplication::keyboardModifiers())
{
case Qt::ControlModifier:
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
QGraphicsView::mousePressEvent(mousePress);
break;
default:
QGraphicsView::mousePressEvent(mousePress);
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @param event mouse release event.
*/
void VTableGraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
QGraphicsView::mouseReleaseEvent ( event );
QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag );
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief keyPressEvent handle key press events.
* @param event key press event.
*/
void VTableGraphicsView::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Space:
rotateIt();
break;
case Qt::Key_Left:
MoveItem(VTableGraphicsView::Left);
break;
case Qt::Key_Right:
MoveItem(VTableGraphicsView::Right);
break;
case Qt::Key_Up:
MoveItem(VTableGraphicsView::Up);
break;
case Qt::Key_Down:
MoveItem(VTableGraphicsView::Down);
break;
default:
break;
}
QGraphicsView::keyPressEvent ( event );
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief rotateIt rotate selected details on 180 degree.
*/
void VTableGraphicsView::rotateIt()
{
QList<QGraphicsItem *> list = scene()->selectedItems();
if (list.size()>0)
{
for ( qint32 i = 0; i < list.count(); ++i )
{
QGraphicsItem *item = list.at(i);
SCASSERT(item != nullptr);
item->setTransformOriginPoint(item->boundingRect().center());
item->setRotation(item->rotation() + 90);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief MoveItem move selected detail.
* @param move type of move.
*/
void VTableGraphicsView::MoveItem(VTableGraphicsView::typeMove_e move)
{
qreal dx = 0, dy = 0;
switch (move)
{
case VTableGraphicsView::Left:
dx = -3;
dy = 0;
break;
case VTableGraphicsView::Right:
dx = 3;
dy = 0;
break;
case VTableGraphicsView::Up:
dx = 0;
dy = -3;
break;
case VTableGraphicsView::Down:
dx = 0;
dy = 3;
break;
default:
break;
}
QList<QGraphicsItem *> listSelectedItems = scene()->selectedItems();
if (listSelectedItems.size()>0)
{
for ( qint32 i = 0; i < listSelectedItems.count(); ++i )
{
listSelectedItems.at(i)->moveBy(dx, dy);
}
}
}

View File

@ -1,95 +0,0 @@
/************************************************************************
**
** @file vtablegraphicsview.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date November 15, 2013
**
** @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) 2013-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/>.
**
*************************************************************************/
#ifndef VTABLEGRAPHICSVIEW_H
#define VTABLEGRAPHICSVIEW_H
#include <QGraphicsView>
/**
* @brief The VTableGraphicsView class table layout view.
*/
class VTableGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
/**
* @brief The typeMove_e enum type items moves.
*/
enum typeMove_e { Left, Right, Up, Down };
VTableGraphicsView(QWidget *parent = nullptr);
signals:
/**
* @brief itemChect emit after change selection state detail.
* @param flag false - selected, true - don't selected.
*/
void itemChect( bool flag );
public slots:
void selectionChanged();
void rotateItems();
void MirrorItem();
void ZoomIn();
void ZoomOut();
protected:
void wheelEvent ( QWheelEvent * event );
void mousePressEvent(QMouseEvent *mousePress);
void mouseReleaseEvent ( QMouseEvent * event );
void keyPressEvent ( QKeyEvent * event );
void rotateIt();
void MoveItem( VTableGraphicsView::typeMove_e move );
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief rotateItems handle rotatation detail.
*/
inline void VTableGraphicsView::rotateItems()
{
rotateIt();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ZoomIn zoom in paper scale.
*/
inline void VTableGraphicsView::ZoomIn()
{
scale(1.1, 1.1);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ZoomOut zoom out paper scale.
*/
inline void VTableGraphicsView::ZoomOut()
{
scale(1/1.1, 1/1.1);
}
#endif // VTABLEGRAPHICSVIEW_H

View File

@ -2,7 +2,6 @@
# This need for corect working file translations.pro
HEADERS += \
$$PWD/vtablegraphicsview.h \
$$PWD/vmaingraphicsview.h \
$$PWD/vmaingraphicsscene.h \
$$PWD/doubledelegate.h \
@ -13,7 +12,6 @@ HEADERS += \
$$PWD/vwidgetpopup.h
SOURCES += \
$$PWD/vtablegraphicsview.cpp \
$$PWD/vmaingraphicsview.cpp \
$$PWD/vmaingraphicsscene.cpp \
$$PWD/doubledelegate.cpp \

View File

@ -31,7 +31,7 @@
#include <QString>
enum class Draw : char { Calculation, Modeling };
enum class Draw : char { Calculation, Modeling, Layout };
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
enum class SplinePointPosition : char { FirstPoint, LastPoint };