diff --git a/src/app/app.pri b/src/app/app.pri index bfc1e20c3..4d185e939 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -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 diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index daaf8c478..61076608c 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -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; } diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index da5df856d..38c714903 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -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 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 diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 9d3cd576d..f33b72ab8 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -117,7 +117,8 @@ void DialogAlongLine::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 4edc42a66..3105693df 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -225,7 +225,8 @@ void DialogArc::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); scene->addItem(path); path->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 4d3136c2c..c43a27d1a 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -126,7 +126,8 @@ void DialogBisector::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogcurveintersectaxis.cpp b/src/app/dialogs/tools/dialogcurveintersectaxis.cpp index d240d3d23..3476be2d2 100644 --- a/src/app/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/app/dialogs/tools/dialogcurveintersectaxis.cpp @@ -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(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolCurveIntersectAxis::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 437831a70..7268423e9 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -92,7 +92,8 @@ void DialogCutArc::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); scene->addItem(path); path->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 62e72c46d..8eefa1e0d 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -196,7 +196,8 @@ void DialogCutSpline::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); scene->addItem(path); path->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index 46affdf82..f2f06812d 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -196,7 +196,8 @@ void DialogCutSplinePath::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); scene->addItem(path); path->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 43553a0b0..27b9891e0 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -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(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index 971e86f5f..9440e517a 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -254,7 +254,8 @@ void DialogHeight::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogline.cpp b/src/app/dialogs/tools/dialogline.cpp index 3f358cb83..218deabb2 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -145,7 +145,8 @@ void DialogLine::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 48ab1b952..084373e2c 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -229,7 +229,8 @@ void DialogLineIntersect::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialoglineintersectaxis.cpp b/src/app/dialogs/tools/dialoglineintersectaxis.cpp index f54198ae5..d9aac1dd7 100644 --- a/src/app/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/app/dialogs/tools/dialoglineintersectaxis.cpp @@ -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(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLineIntersectAxis::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index 960bac439..fe54d4703 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -116,7 +116,8 @@ void DialogNormal::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 5f5e3f336..694ab9cdc 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -133,7 +133,8 @@ void DialogPointOfContact::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 3c03d60e5..b122108a7 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -161,7 +161,8 @@ void DialogPointOfIntersection::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); line->RefreshGeometry(); } diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 16619b558..33194dbce 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -126,7 +126,8 @@ void DialogShoulderPoint::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogspline.cpp b/src/app/dialogs/tools/dialogspline.cpp index e6cdcc807..297cd135d 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -185,7 +185,8 @@ void DialogSpline::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); scene->addItem(path); path->RefreshGeometry(); diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index d9b3dc968..d36870d10 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -267,7 +267,8 @@ void DialogSplinePath::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor); scene->addItem(visPath); visPath->setMode(Mode::Show); diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index d35d9e68e..e765be0c7 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -200,7 +200,8 @@ void DialogTriangle::ShowVisualization() { if (prepare == false) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); scene->addItem(line); line->RefreshGeometry(); diff --git a/src/app/main.cpp b/src/app/main.cpp index a2c470d01..b17b8b4a4 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -29,7 +29,6 @@ #include "mainwindow.h" #include "core/vapplication.h" #include "core/vsettings.h" -#include "tablewindow.h" #include "version.h" #include @@ -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.")); diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 95687119f..b8a16bd18 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -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(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(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(DrawTool::Create(dialogTool, currentScene, doc, pattern)); + VMainGraphicsScene *scene = qobject_cast(currentScene); + SCASSERT(scene != nullptr); + + QGraphicsItem *tool = dynamic_cast(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(currentScene); + SCASSERT(scene != nullptr); + dialogTool->SetAssociatedTool( - dynamic_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + dynamic_cast (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(currentScene); + SCASSERT(scene != nullptr); + dialogTool->SetAssociatedTool( - static_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + static_cast (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(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(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 *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 *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 listDetails; - const QHash *details = pattern->DataDetails(); - if (details->count() == 0) - { - return; - } - hide();//Now we can hide window - QHashIterator 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) { diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 62330c558..07288e4bf 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -29,15 +29,12 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include -#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 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 diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index 067fc3773..d3f5123c9 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -24,6 +24,9 @@ + + true + 2 @@ -685,6 +688,9 @@ + + false + Seam allowance tool @@ -734,6 +740,45 @@ + + + + 0 + 0 + 105 + 380 + + + + Layout + + + + + + false + + + Settings + + + + + + + + + 32 + 32 + + + + true + + + + + @@ -770,11 +815,27 @@ &File + + + Layout + + + + + + + + + + + + + @@ -990,6 +1051,67 @@ + + + QDockWidget::NoDockWidgetFeatures + + + Qt::RightDockWidgetArea + + + Layout pages + + + 2 + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + true + + + false + + + + 150 + 200 + + + + QListView::Static + + + QListView::TopToBottom + + + QListView::Adjust + + + 10 + + + QListView::IconMode + + + + + + @@ -1202,6 +1324,9 @@ + + true + false @@ -1375,6 +1500,9 @@ + + false + Last Tool @@ -1402,6 +1530,115 @@ F2 + + + false + + + + :/icon/32x32/pdf.png:/icon/32x32/pdf.png + + + Save as PDF + + + Save original layout + + + + + false + + + + :/icon/32x32/pdf.png:/icon/32x32/pdf.png + + + Save as tiled PDF + + + Split and save a layout into smaller pages + + + + + false + + + + + + + + Print + + + Print original a layout + + + + + false + + + + + + + + Print tiled + + + Split and print a layout into smaller pages (for regular printers) + + + + + false + + + + + + + + Print preview + + + Print preview original layout + + + + + false + + + + + + + + Print preview tailed + + + Print preview tailed layout + + + + + false + + + + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png + + + Export As... + + + Export original layout + + diff --git a/src/app/tablewindow.cpp b/src/app/mainwindowsnogui.cpp similarity index 66% rename from src/app/tablewindow.cpp rename to src/app/mainwindowsnogui.cpp index 1dc29d50e..f59c1fb1b 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file tablewindow.cpp + ** @file mainwindowsnogui.cpp ** @author Roman Telezhynskyi - ** @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 ** 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 +#include +#include +#include +#include +#include #include #include -#include #include #include -#include -#include #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()), papers(QList()), shadows(QList()), - scenes(QList()), details(QList >()), fileName(QString()), - description(QString()), tempScene(nullptr) +MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) + : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), + pattern(new VContainer()), doc(nullptr), papers(QList()), shadows(QList()), + scenes(QList()), details(QList >()), 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 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 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()<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(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 images = AllSheets(); - VPoster posterazor(printer); QVector 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(VApplication::PrintDPI)); - Print( &printer ); + qCritical()< *details) +{ + SCASSERT(details != nullptr) + if (details->count() == 0) + { + listDetails.clear(); + return; + } + + listDetails.clear(); + QHashIterator 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(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(r.width()), static_cast(r.height())), QImage::Format_RGB32); - printer.setOutputFileName(fileName); - printer.setResolution(static_cast(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(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; isetBackgroundBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern)); + scene->addItem(shadows.at(i)); + scene->addItem(papers.at(i)); + + QList 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 MainWindowsNoGUI::InitFormates() const +{ + QMap 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()<(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(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(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(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(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 ¶ms) const +void MainWindowsNoGUI::PdfToPs(const QStringList ¶ms) const { #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); @@ -605,7 +640,7 @@ void TableWindow::PdfToPs(const QStringList ¶ms) const } //--------------------------------------------------------------------------------------------------------------------- -void TableWindow::ObjFile(const QString &name, int i) const +void MainWindowsNoGUI::ObjFile(const QString &name, int i) const { QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); if (paper) @@ -622,7 +657,7 @@ void TableWindow::ObjFile(const QString &name, int i) const } //--------------------------------------------------------------------------------------------------------------------- -QVector TableWindow::AllSheets() +QVector MainWindowsNoGUI::AllSheets() { QVector images; for (int i=0; i < scenes.size(); ++i) @@ -665,172 +700,174 @@ QVector 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(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(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(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; isetBackgroundBrush(brush); - scene->addItem(shadows.at(i)); - scene->addItem(papers.at(i)); - - QList 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(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(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(r.width()), static_cast(r.height())), QImage::Format_RGB32); - - if (not image.isNull()) + QGraphicsRectItem *paper = qgraphicsitem_cast(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(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 TableWindow::InitFormates() const +bool MainWindowsNoGUI::isPagesUniform() const { - QMap 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()<(papers.at(0)); + SCASSERT(paper != nullptr) + for (int i=1; i < papers.size(); ++i) + { + QGraphicsRectItem *p = qgraphicsitem_cast(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(msgBox.layout()); + SCASSERT(layout != nullptr); + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + msgBox.exec(); + return msgBox.result(); } diff --git a/src/app/tablewindow.h b/src/app/mainwindowsnogui.h similarity index 55% rename from src/app/tablewindow.h rename to src/app/mainwindowsnogui.h index ad2452732..07ac4f0cc 100644 --- a/src/app/tablewindow.h +++ b/src/app/mainwindowsnogui.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file tablewindow.h + ** @file mainwindowsnogui.h ** @author Roman Telezhynskyi - ** @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 ** 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 #include -#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 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 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 papers; QList shadows; QList scenes; QList > 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 *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 InitFormates() const; void SvgFile(const QString &name, int i)const; void PngFile(const QString &name, int i)const; @@ -105,17 +111,16 @@ private: QVector AllSheets(); - void ClearLayout(); - void CreateShadows(); - void CreateScenes(); - void PrepareSceneList(); - QIcon ScenePreview(int i) const; - QMap 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 diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index e14838f16..4b33c74c8 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -60,5 +60,6 @@ icon/16x16/fx.png icon/16x16/roll.png icon/16x16/progress.gif + icon/32x32/export_to_picture_document.png diff --git a/src/app/share/resources/icon/32x32/export_to_picture_document.png b/src/app/share/resources/icon/32x32/export_to_picture_document.png new file mode 100644 index 000000000..b2f15bacf Binary files /dev/null and b/src/app/share/resources/icon/32x32/export_to_picture_document.png differ diff --git a/src/app/share/resources/icons/win.icon.theme/32x32/emblems/emblem-system.png b/src/app/share/resources/icons/win.icon.theme/32x32/emblems/emblem-system.png new file mode 100644 index 000000000..41408e946 Binary files /dev/null and b/src/app/share/resources/icons/win.icon.theme/32x32/emblems/emblem-system.png differ diff --git a/src/app/share/resources/icons/win.icon.theme/index.theme b/src/app/share/resources/icons/win.icon.theme/index.theme index 2f0b86327..078e57995 100755 --- a/src/app/share/resources/icons/win.icon.theme/index.theme +++ b/src/app/share/resources/icons/win.icon.theme/index.theme @@ -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 diff --git a/src/app/share/resources/theme.qrc b/src/app/share/resources/theme.qrc index 05b2ad324..f89a5ca50 100644 --- a/src/app/share/resources/theme.qrc +++ b/src/app/share/resources/theme.qrc @@ -67,5 +67,6 @@ icons/win.icon.theme/16x16/actions/document-print-preview.png icons/win.icon.theme/24x24/actions/document-print-preview.png icons/win.icon.theme/32x32/actions/document-print-preview.png + icons/win.icon.theme/32x32/emblems/emblem-system.png diff --git a/src/app/tablewindow.ui b/src/app/tablewindow.ui deleted file mode 100644 index ea8afd5c9..000000000 --- a/src/app/tablewindow.ui +++ /dev/null @@ -1,328 +0,0 @@ - - - TableWindow - - - - 0 - 0 - 1000 - 730 - - - - Create a layout - - - - :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - - - - - - - - - - - 20 - 0 - - - - QGraphicsView::AnchorUnderMouse - - - - - - - - - 10 - - - - Main toolbar - - - - 24 - 24 - - - - Qt::ToolButtonTextUnderIcon - - - TopToolBarArea - - - false - - - - - - - - - - - - 0 - 0 - - - - - 187 - 121 - - - - - 187 - 524287 - - - - QDockWidget::DockWidgetMovable - - - Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea - - - Layout pages - - - 1 - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 150 - 200 - - - - QListView::Static - - - QListView::TopToBottom - - - true - - - QListView::Adjust - - - 3 - - - QListView::IconMode - - - - - - - - - - 0 - 0 - 1000 - 25 - - - - - File - - - - - - - - - - Edit - - - - - - - Layout - - - - - - - - - - - 10 - - - - Toolbar print - - - Qt::ToolButtonTextUnderIcon - - - TopToolBarArea - - - false - - - - - - - - false - - - - - - - - &Save As... - - - Save layout - - - Ctrl+S - - - - - - - - - - Back - - - Back to main window - - - - - - - - - - Zoom In - - - Zoom In - - - - - - - - - - Zoom Out - - - Zoom Out - - - - - - :/icon/32x32/layout.png:/icon/32x32/layout.png - - - Create Layout - - - Create Layout - - - - - false - - - - - - - - Print pre&view... - - - - - false - - - - - - - - &Print... - - - Ctrl+P - - - - - false - - - - :/icon/32x32/pdf.png:/icon/32x32/pdf.png - - - Print to p&df - - - - - - VTableGraphicsView - QGraphicsView -
vtablegraphicsview.h
-
-
- - - - -
diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 616567143..2fb5c2587 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 9fe94e448..57ab391d3 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 025adcf0a..4361b76a7 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp b/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp index eb81c8a01..7bcd8ea8d 100644 --- a/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp +++ b/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index c2eacbccb..6f2876c63 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 6690f2737..e4f2690c5 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index f160d41ef..211022387 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index bc23fc022..d69a26404 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index fc021dc66..84acc0609 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index d440acef4..20fa07a60 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 050a7d044..10ce3e675 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoollineintersectaxis.cpp b/src/app/tools/drawTools/vtoollineintersectaxis.cpp index eadae8e6d..a6ead89bc 100644 --- a/src/app/tools/drawTools/vtoollineintersectaxis.cpp +++ b/src/app/tools/drawTools/vtoollineintersectaxis.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index d5aef5670..9b6f4e4e8 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 360d8a4b0..14bf954fc 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 7908fa150..7ea98a311 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index fbfa389bf..4537df002 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 897ecfc6a..cd04d94e5 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 414becdaa..9fd9947dd 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index b3071bbba..965d629c7 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -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(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); diff --git a/src/app/visualization/visualization.cpp b/src/app/visualization/visualization.cpp index 66dc9a856..f14f3a9c7 100644 --- a/src/app/visualization/visualization.cpp +++ b/src/app/visualization/visualization.cpp @@ -67,7 +67,7 @@ void Visualization::setScenePos(const QPointF &value) //--------------------------------------------------------------------------------------------------------------------- void Visualization::VisualMode(const quint32 &pointId) { - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); this->point1Id = pointId; diff --git a/src/app/visualization/visualization.h b/src/app/visualization/visualization.h index 860db38d9..c72d21ad2 100644 --- a/src/app/visualization/visualization.h +++ b/src/app/visualization/visualization.h @@ -87,7 +87,7 @@ protected: void AddItem(Item *item) { SCASSERT(item != nullptr); - VMainGraphicsScene *scene = qApp->getCurrentScene(); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); scene->addItem(item); diff --git a/src/app/widgets/vtablegraphicsview.cpp b/src/app/widgets/vtablegraphicsview.cpp deleted file mode 100644 index 46425b455..000000000 --- a/src/app/widgets/vtablegraphicsview.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/************************************************************************ - ** - ** @file vtablegraphicsview.cpp - ** @author Roman Telezhynskyi - ** @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 - ** 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 . - ** - *************************************************************************/ - -#include "vtablegraphicsview.h" - -#include -#include -#include -#include -#include -#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 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 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 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 listSelectedItems = scene()->selectedItems(); - if (listSelectedItems.size()>0) - { - for ( qint32 i = 0; i < listSelectedItems.count(); ++i ) - { - listSelectedItems.at(i)->moveBy(dx, dy); - } - } -} diff --git a/src/app/widgets/vtablegraphicsview.h b/src/app/widgets/vtablegraphicsview.h deleted file mode 100644 index 9bb837f42..000000000 --- a/src/app/widgets/vtablegraphicsview.h +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************************************ - ** - ** @file vtablegraphicsview.h - ** @author Roman Telezhynskyi - ** @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 - ** 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 . - ** - *************************************************************************/ - -#ifndef VTABLEGRAPHICSVIEW_H -#define VTABLEGRAPHICSVIEW_H - -#include - -/** - * @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 diff --git a/src/app/widgets/widgets.pri b/src/app/widgets/widgets.pri index 1e0e507e6..e82137562 100644 --- a/src/app/widgets/widgets.pri +++ b/src/app/widgets/widgets.pri @@ -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 \ diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index 85edf189d..3ff9b30d0 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -31,7 +31,7 @@ #include -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 };