From 3cb7e5a39325c255cae02e90a0894be29292cf5e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 12 May 2015 15:42:19 +0300 Subject: [PATCH 1/9] First step to unite Layout and main windows. --HG-- branch : feature --- src/app/app.pri | 6 +- src/app/main.cpp | 3 - src/app/mainwindow.cpp | 212 ++++++++++-------- src/app/mainwindow.h | 23 +- src/app/mainwindow.ui | 65 +++++- src/app/mainwindowsnogui.cpp | 81 +++++++ src/app/mainwindowsnogui.h | 65 ++++++ .../32x32/emblems/emblem-system.png | Bin 0 -> 2481 bytes .../icons/win.icon.theme/index.theme | 6 +- src/app/share/resources/theme.qrc | 1 + src/libs/vgeometry/vgeometrydef.h | 2 +- 11 files changed, 350 insertions(+), 114 deletions(-) create mode 100644 src/app/mainwindowsnogui.cpp create mode 100644 src/app/mainwindowsnogui.h create mode 100644 src/app/share/resources/icons/win.icon.theme/32x32/emblems/emblem-system.png diff --git a/src/app/app.pri b/src/app/app.pri index bfc1e20c3..ceb1aeec4 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -19,7 +19,8 @@ SOURCES += \ $$PWD/tablewindow.cpp \ $$PWD/stable.cpp \ $$PWD/version.cpp \ - $$PWD/options.cpp + $$PWD/options.cpp \ + $$PWD/mainwindowsnogui.cpp # Some header files HEADERS += \ @@ -27,7 +28,8 @@ HEADERS += \ $$PWD/options.h \ $$PWD/tablewindow.h \ $$PWD/stable.h \ - $$PWD/version.h + $$PWD/version.h \ + $$PWD/mainwindowsnogui.h # Main forms FORMS += \ diff --git a/src/app/main.cpp b/src/app/main.cpp index a2c470d01..b3556fd2c 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -118,9 +118,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..025fceb32 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -73,8 +73,8 @@ 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), doc(nullptr), 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), currentToolBoxIndex(0), drawMode(true), recentFileActs(), @@ -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); @@ -221,6 +201,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. @@ -704,16 +707,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() { @@ -1125,13 +1118,16 @@ 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) + { + /*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()); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -1160,11 +1156,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; @@ -1180,6 +1178,8 @@ void MainWindow::ActionDraw(bool checked) ui->actionOptionDraw->setEnabled(true); ui->actionNewDraw->setEnabled(true); + ui->dockWidgetLayoutPages->setVisible(false); + ui->dockWidgetToolOptions->setVisible(true); } else { @@ -1198,11 +1198,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 +1212,20 @@ 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->dockWidgetLayoutPages->setVisible(false); + ui->dockWidgetToolOptions->setVisible(true); } else { @@ -1228,6 +1233,60 @@ 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->dockWidgetLayoutPages->setVisible(true); + ui->dockWidgetToolOptions->setVisible(false); + } + else + { + ui->actionLayout->setChecked(true); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveAs save as pattern file. @@ -1644,16 +1703,17 @@ 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); } else { + listDetails.clear(); ui->actionDetails->setEnabled(false); ui->actionLayout->setEnabled(false); + ui->actionDraw->setChecked(true); } } @@ -1898,41 +1958,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 +1977,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 +2021,9 @@ void MainWindow::SetEnableTool(bool enable) //Modeling Tools ui->toolButtonUnionDetails->setEnabled(modelingTools); + + //Layout tools + ui->toolButtonLayoutSettings->setEnabled(layoutTools); } //--------------------------------------------------------------------------------------------------------------------- @@ -2456,7 +2493,6 @@ MainWindow::~MainWindow() #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) delete lock; // Unlock pattern file #endif - delete pattern; delete doc; delete sceneDetails; delete sceneDraw; diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 62330c558..1e7a1202e 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -29,15 +29,14 @@ #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 +48,7 @@ class VToolOptionsPropertyBrowser; /** * @brief The MainWindow class main windows. */ -class MainWindow : public QMainWindow +class MainWindow : public MainWindowsNoGUI { Q_OBJECT public: @@ -70,7 +69,6 @@ public slots: void ActionCurveDetailsMode(bool checked); void DrawOption(); - void tableClosed(); void ClosedActionTable(); void ClosedActionHistory(); @@ -141,13 +139,6 @@ public slots: void WindowsLocale(); void ToolBarStyles(); 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: @@ -160,9 +151,6 @@ private: /** @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; @@ -172,9 +160,6 @@ private: /** @brief tool last used tool */ Tool lastUsedTool; - /** @brief currentScene pointer to current scene. */ - VMainGraphicsScene *currentScene; - /** @brief sceneDraw draw scene. */ VMainGraphicsScene *sceneDraw; @@ -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..77573adb3 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -40,7 +40,7 @@ - 4 + 5 @@ -734,6 +734,32 @@ + + + Layout + + + + + + Settings + + + + + + + 32 + 32 + + + + true + + + + + @@ -990,6 +1016,40 @@ + + + QDockWidget::NoDockWidgetFeatures + + + Qt::RightDockWidgetArea + + + Layout pages + + + 2 + + + + + + + + 0 + 0 + + + + + 150 + 200 + + + + + + + @@ -1202,6 +1262,9 @@ + + true + false diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp new file mode 100644 index 000000000..5e2d37c22 --- /dev/null +++ b/src/app/mainwindowsnogui.cpp @@ -0,0 +1,81 @@ +/************************************************************************ + ** + ** @file mainwindowsnogui.cpp + ** @author Roman Telezhynskyi + ** @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) 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 "mainwindowsnogui.h" +#include "../core/vapplication.h" +#include "../container/vcontainer.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) + : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), + pattern(new VContainer()) +{ + InitTempLayoutScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +MainWindowsNoGUI::~MainWindowsNoGUI() +{ + delete tempSceneLayout; + delete pattern; +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *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 MainWindowsNoGUI::InitTempLayoutScene() +{ + tempSceneLayout = new VMainGraphicsScene(); + tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) ); +} diff --git a/src/app/mainwindowsnogui.h b/src/app/mainwindowsnogui.h new file mode 100644 index 000000000..4edbb8f93 --- /dev/null +++ b/src/app/mainwindowsnogui.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file mainwindowsnogui.h + ** @author Roman Telezhynskyi + ** @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) 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 MAINWINDOWSNOGUI_H +#define MAINWINDOWSNOGUI_H + +#include + +#include "../geometry/vdetail.h" +#include "../libs/vlayout/vlayoutdetail.h" +#include "../widgets/vmaingraphicsscene.h" + +class MainWindowsNoGUI : public QMainWindow +{ + Q_OBJECT +public: + MainWindowsNoGUI(QWidget *parent = nullptr); + virtual ~MainWindowsNoGUI(); + +protected: + QVector listDetails; + + /** @brief currentScene pointer to current scene. */ + VMainGraphicsScene *currentScene; + + VMainGraphicsScene *tempSceneLayout; + + /** @brief pattern container with data (points, arcs, splines, spline paths, variables) */ + VContainer *pattern; + + void PrepareDetailsForLayout(const QHash *details); + + void InitTempLayoutScene(); + +private: + Q_DISABLE_COPY(MainWindowsNoGUI) + +}; + +#endif // MAINWINDOWSNOGUI_H 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 0000000000000000000000000000000000000000..41408e9465c181466f5feeb5e332946fe4ff4444 GIT binary patch literal 2481 zcmV;i2~PHjP)&3?F5f!W23MI=I5tZd;%t+H75s6_(Iwb^FKQw%P_)H!(I* ze{A;0wq~=5iN-%AyK%cΝT6t-3}as3b0>bgfn>m43)q`5NYBc$t~^o%id$cYnZ; zDQ$J@kDcV?P0l@Y&vVbc=Q-yP{D|M1Z@yXR@pwukNpcH<0Mj&+gM)+PZ@lrw%$@E< zeuRHlPfyROl9G~#2_X{4ac~^RymIAAPh(@_UI50OY{vbN!E3L*wpNv87)EhXQIS+w zScpI%fTE%ziBeh&AS>O_ahy8`z;Vl}`uh5UmX?;sUV7;zjxm;QlHu`q+#JUtC4>;T z-R=xg6f;srj4{;J)p19T9C>X2{{02F1Hi9UFvif((6II3!GqoV_wWC0US8hD-Me>p z1p)#8E3drr_>)gQ`NyiNsvRDWhd7Rdl(^mQ+^VXo9o5y6-w&^UgbX_St7YtgNj3TW)UdGntv0006Jo3qcS-2!WyNxH2|{@5X1K85H1z zWe28-3=s%zDnMy40A3K`ILn8yEDN@6BOZ^Vudna;i4!M2JbCgY_U+qu^A#}0;PrZ4 zufP8KXN`@G_j4Qvx7&^E>})7YF?`-X2tE=nG(W6J}78VxtR3vXoLqZ6G!C&>H-f>MfPGKrblIh^hq z0D}mR$Bm?JAR0?RR$`DBR}y!XjDEXCrmZ40Jp!Zb~IJf2*i&zGI< z{FZ5W;J|@>wY9ZRd%fP(JN&eN7~qy4rKahKB~&Pi0_yP4O&dwWgr*r#lSx<>MNBm? zH5Elh_M6!^Swy996?hwSWZ$g;eC zZf>sI*xU$Jv~jnMnvC5Cj3AogKmTa2%2(03g^_ zQH(tgS3^~kux%65(=)huc^qF}nuY-nG&KQD(~wXN?A%g_NA9nHAPSHq3CU#A0Wik% zysjw9M04}Btj`&;cA$7 zw_z9(r4+VpuTm>@959Dr=*o4-(KzCog`~+~I|NvH8;;|^wryCJjm*q!wCwv8wpA2k zR*qw6WCA^XgK)Vr0FYHeN{MNjQX-LX3zSllQl=;t0Js%a`)X(unr@)5un@sbo3MRL z83-Xau_TxcHECdAcm`J|=CPzG$o9Cf+%H&g9C`zQ6xngQt|x8Vw$c}D+g|=s8=E)f zgHi{YVL?fl&@E?`GnVsQ2V)M#!Uq2Ij{%I&#vqC!9EYKFQvn=GZ|R&;YU#S36r$1S zcq|s{b-7%{f*@qL-R@vkRu&e5 zD5Y3hTEg(~@T(tx{BaLsEDpfBB@-qRiMg#?x9;)#{dt5C*p`j$KMf+HX!!c#HJFAD zhuSc0ilvx}`G}0!nQ2T`Wq*6=} z1PFo%K@hO3>L+-pb_;?V{7A&&P!^+Lwt-O4hnB~7;pNt5?0KkiCG8vtf&kmLVcRwe z3JNxsmzQs-tE>Ch@#DwY`|rPhb2)zQx#u2lX=!=SaU5_Q2cGAV-h6T#2aXUBjzE$m zh=K?Z0=7a*SX1dzsj8|fbX^A_1Z{0?PqeqU|MQktFfuYSaOu*eiS%NWlGPTBF%SpP zbp!g!2#{`<-oB-T=Xr>th{3_ZiK(fnf!mhjv9Ylj$8r4|Hf(6l&(F_HG2_tC&{wLe z#w1Ddd%fNp`iE2xm}==47Z))$Hg?+z`BSG(J>J#T_3iie10y3N z)0EPG=jG)+;`jS=y1Tniyzs&czwYhr?eKU!mt|S@tzW->lgs70p;t^K68PeaFZ#}% zJNN35BS-$w(b4hN#*G_8p-^bc(9qD-yYIfc_oI(K8u*__rka|XlBTAnr+J>2()E77 zfAa?)d@wOQJj~MN^y$;%e!stT&5$ECG&CICxpQaf?feM0TNoG^7zc2CtzMR8jWMRJ z?Uo54nk>uOn$gVc?CgB&`wlAnh~YFAjYel8k;vUV&y$sR!lKdWEP&YmV>(7{ZSCgj v>gtf&?e+qIrfKT=^XI?o@9!VI)4l!++nzLI33j?g00000NkvXXu0mjfKSZ@V literal 0 HcmV?d00001 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/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 }; From f4e511e825ff62538143896ff83278f1a8960e69 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 12 May 2015 16:22:39 +0300 Subject: [PATCH 2/9] Hide toolbar if user doesn't need it. --HG-- branch : feature --- src/app/mainwindow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 025fceb32..462bc3f8d 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1178,6 +1178,8 @@ void MainWindow::ActionDraw(bool checked) ui->actionOptionDraw->setEnabled(true); ui->actionNewDraw->setEnabled(true); + ui->toolBarOption->setVisible(true); + ui->dockWidgetLayoutPages->setVisible(false); ui->dockWidgetToolOptions->setVisible(true); } @@ -1224,6 +1226,8 @@ void MainWindow::ActionDetails(bool checked) ui->actionOptionDraw->setEnabled(false); ui->actionNewDraw->setEnabled(false); + ui->toolBarOption->setVisible(false); + ui->dockWidgetLayoutPages->setVisible(false); ui->dockWidgetToolOptions->setVisible(true); } @@ -1278,6 +1282,8 @@ void MainWindow::ActionLayout(bool checked) ui->actionOptionDraw->setEnabled(false); ui->actionNewDraw->setEnabled(false); + ui->toolBarOption->setVisible(false); + ui->dockWidgetLayoutPages->setVisible(true); ui->dockWidgetToolOptions->setVisible(false); } From c76718e9d0edee860fb636add523f8e9cf8daf5f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 12 May 2015 18:15:10 +0300 Subject: [PATCH 3/9] Tool layout settings. --HG-- branch : feature --- src/app/core/vapplication.cpp | 4 +- src/app/core/vapplication.h | 7 +- src/app/dialogs/tools/dialogalongline.cpp | 3 +- src/app/dialogs/tools/dialogarc.cpp | 3 +- src/app/dialogs/tools/dialogbisector.cpp | 3 +- .../tools/dialogcurveintersectaxis.cpp | 5 +- src/app/dialogs/tools/dialogcutarc.cpp | 3 +- src/app/dialogs/tools/dialogcutspline.cpp | 3 +- src/app/dialogs/tools/dialogcutsplinepath.cpp | 3 +- src/app/dialogs/tools/dialogendline.cpp | 5 +- src/app/dialogs/tools/dialogheight.cpp | 3 +- src/app/dialogs/tools/dialogline.cpp | 3 +- src/app/dialogs/tools/dialoglineintersect.cpp | 3 +- .../dialogs/tools/dialoglineintersectaxis.cpp | 5 +- src/app/dialogs/tools/dialognormal.cpp | 3 +- .../dialogs/tools/dialogpointofcontact.cpp | 3 +- .../tools/dialogpointofintersection.cpp | 3 +- src/app/dialogs/tools/dialogshoulderpoint.cpp | 3 +- src/app/dialogs/tools/dialogspline.cpp | 3 +- src/app/dialogs/tools/dialogsplinepath.cpp | 3 +- src/app/dialogs/tools/dialogtriangle.cpp | 3 +- src/app/mainwindow.cpp | 75 +++++++-- src/app/mainwindow.h | 3 + src/app/mainwindow.ui | 11 +- src/app/mainwindowsnogui.cpp | 142 +++++++++++++++++- src/app/mainwindowsnogui.h | 21 ++- src/app/tools/drawTools/vtoolalongline.cpp | 3 +- src/app/tools/drawTools/vtoolarc.cpp | 3 +- src/app/tools/drawTools/vtoolbisector.cpp | 3 +- .../drawTools/vtoolcurveintersectaxis.cpp | 3 +- src/app/tools/drawTools/vtoolcutarc.cpp | 3 +- src/app/tools/drawTools/vtoolcutspline.cpp | 3 +- .../tools/drawTools/vtoolcutsplinepath.cpp | 3 +- src/app/tools/drawTools/vtoolendline.cpp | 3 +- src/app/tools/drawTools/vtoolheight.cpp | 3 +- src/app/tools/drawTools/vtoolline.cpp | 3 +- .../tools/drawTools/vtoollineintersect.cpp | 3 +- .../drawTools/vtoollineintersectaxis.cpp | 3 +- src/app/tools/drawTools/vtoolnormal.cpp | 3 +- .../tools/drawTools/vtoolpointofcontact.cpp | 3 +- .../drawTools/vtoolpointofintersection.cpp | 3 +- .../tools/drawTools/vtoolshoulderpoint.cpp | 3 +- src/app/tools/drawTools/vtoolspline.cpp | 3 +- src/app/tools/drawTools/vtoolsplinepath.cpp | 3 +- src/app/tools/drawTools/vtooltriangle.cpp | 3 +- src/app/visualization/visualization.cpp | 2 +- src/app/visualization/visualization.h | 2 +- 47 files changed, 319 insertions(+), 68 deletions(-) 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/mainwindow.cpp b/src/app/mainwindow.cpp index 462bc3f8d..df748737e 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -264,7 +264,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); @@ -273,7 +277,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); } } @@ -304,7 +307,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); @@ -315,7 +322,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); } } @@ -331,7 +337,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(); @@ -351,8 +360,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 @@ -382,8 +394,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 @@ -792,6 +807,33 @@ void MainWindow::customEvent(QEvent *event) } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ClearLayout() +{ + qDeleteAll (scenes); + scenes.clear(); + shadows.clear(); + papers.clear(); + ui->listWidget->clear(); + //EnableActions(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); + //EnableActions(true); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolBarOption enable option toolbar. @@ -944,6 +986,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -1120,13 +1163,16 @@ void MainWindow::SaveCurrentScene() { if (mode == Draw::Calculation || mode == Draw::Modeling) { + VMainGraphicsScene *scene = qobject_cast(currentScene); + SCASSERT(scene != nullptr); + /*Save transform*/ - currentScene->setTransform(ui->view->transform()); + scene->setTransform(ui->view->transform()); /*Save scroll bars value for previous scene.*/ QScrollBar *horScrollBar = ui->view->horizontalScrollBar(); - currentScene->setHorScrollBar(horScrollBar->value()); + scene->setHorScrollBar(horScrollBar->value()); QScrollBar *verScrollBar = ui->view->verticalScrollBar(); - currentScene->setVerScrollBar(verScrollBar->value()); + scene->setVerScrollBar(verScrollBar->value()); } } @@ -1136,13 +1182,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()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 1e7a1202e..94a1a7a79 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -146,6 +146,9 @@ 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 */ diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index 77573adb3..e2b8f5ade 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -24,6 +24,9 @@ + + true + 2 @@ -40,7 +43,7 @@ - 5 + 4 @@ -685,6 +688,9 @@ + + false + Seam allowance tool @@ -741,6 +747,9 @@ + + false + Settings diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index 5e2d37c22..fb00a38b4 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -29,13 +29,20 @@ #include "mainwindowsnogui.h" #include "../core/vapplication.h" #include "../container/vcontainer.h" +#include "../dialogs/app/dialoglayoutsettings.h" +#include "../../libs/vlayout/vlayoutgenerator.h" +#include "../dialogs/app/dialoglayoutprogress.h" +#include "../dialogs/app/dialogsavelayout.h" +#include "../../libs/vlayout/vposter.h" #include +#include //--------------------------------------------------------------------------------------------------------------------- MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer()) + pattern(new VContainer()), papers(QList()), shadows(QList()), + scenes(QList()), details(QList >()) { InitTempLayoutScene(); } @@ -47,6 +54,60 @@ MainWindowsNoGUI::~MainWindowsNoGUI() delete pattern; } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ToolLayoutSettings(bool checked) +{ + if (checked) + { + VLayoutGenerator lGenerator(this); + lGenerator.SetDetails(listDetails); + + DialogLayoutSettings layout(&lGenerator, this); + if (layout.exec() == QDialog::Rejected) + { + 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(); + break; + case LayoutErrors::ProcessStoped: + break; + case LayoutErrors::PrepareLayoutError: + case LayoutErrors::PaperSizeError: + case LayoutErrors::EmptyPaperError: + ClearLayout(); + break; + default: + break; + } + } + else + { + if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) + { + tButton->setChecked(true); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *details) { @@ -76,6 +137,83 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::InitTempLayoutScene() { - tempSceneLayout = new VMainGraphicsScene(); + tempSceneLayout = new QGraphicsScene(); tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) ); } + +//--------------------------------------------------------------------------------------------------------------------- +QIcon MainWindowsNoGUI::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()) + { + 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 MainWindowsNoGUI::CreateScenes() +{ + 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); + } +} diff --git a/src/app/mainwindowsnogui.h b/src/app/mainwindowsnogui.h index 4edbb8f93..4a426f86e 100644 --- a/src/app/mainwindowsnogui.h +++ b/src/app/mainwindowsnogui.h @@ -33,7 +33,8 @@ #include "../geometry/vdetail.h" #include "../libs/vlayout/vlayoutdetail.h" -#include "../widgets/vmaingraphicsscene.h" + +class QGraphicsScene; class MainWindowsNoGUI : public QMainWindow { @@ -42,24 +43,38 @@ public: MainWindowsNoGUI(QWidget *parent = nullptr); virtual ~MainWindowsNoGUI(); +public slots: + void ToolLayoutSettings(bool checked); + protected: QVector listDetails; /** @brief currentScene pointer to current scene. */ - VMainGraphicsScene *currentScene; + QGraphicsScene *currentScene; - VMainGraphicsScene *tempSceneLayout; + QGraphicsScene *tempSceneLayout; /** @brief pattern container with data (points, arcs, splines, spline paths, variables) */ VContainer *pattern; + QList papers; + QList shadows; + QList scenes; + QList > details; + 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) + void CreateShadows(); + void CreateScenes(); + }; #endif // MAINWINDOWSNOGUI_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); From e0b78f0f27a2b22d1dc7722879bc5441e00bbc47 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 12 May 2015 19:52:07 +0300 Subject: [PATCH 4/9] Show the result generation a layout. --HG-- branch : feature --- src/app/mainwindow.cpp | 21 +++++++++++++++++++++ src/app/mainwindow.h | 2 ++ src/app/mainwindow.ui | 27 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index df748737e..e5ed8b021 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -131,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -2218,6 +2221,8 @@ void MainWindow::ReadSettings() */ void MainWindow::WriteSettings() { + ActionDraw(true); + qApp->getSettings()->SetGeometry(saveGeometry()); qApp->getSettings()->SetWindowState(saveState()); qApp->getSettings()->SetToolbarsState(saveState(APP_VERSION)); @@ -2735,6 +2740,22 @@ void MainWindow::ToolBarStyles() ToolBarStyle(ui->mainToolBar); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ShowPaper(int index) +{ + if (index < 0 || index > scenes.size()) + { + ui->view->setScene(tempSceneLayout); + //EnableActions(false); + } + else + { + ui->view->setScene(scenes.at(index)); + } + + 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 94a1a7a79..c140b2451 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -138,6 +138,8 @@ public slots: void GlobalChangePP(const QString &patternPiece); void WindowsLocale(); void ToolBarStyles(); + + void ShowPaper(int index); signals: void RefreshHistory(); void EnableItemMove(bool move); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index e2b8f5ade..f5b72fcfb 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -1048,12 +1048,39 @@ 0 + + QFrame::StyledPanel + + + QFrame::Sunken + + + true + + + false + 150 200 + + QListView::Static + + + QListView::TopToBottom + + + QListView::Adjust + + + 10 + + + QListView::IconMode + From 46948a9fc49a028e8e0b863bc11776968c6950ec Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 12 May 2015 20:13:45 +0300 Subject: [PATCH 5/9] Restore layout scene. --HG-- branch : feature --- src/app/mainwindow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e5ed8b021..3106403fb 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1338,6 +1338,8 @@ void MainWindow::ActionLayout(bool checked) ui->dockWidgetLayoutPages->setVisible(true); ui->dockWidgetToolOptions->setVisible(false); + + ShowPaper(ui->listWidget->currentRow()); } else { @@ -2549,6 +2551,7 @@ QString MainWindow::PatternPieceName(const QString &text) MainWindow::~MainWindow() { CancelTool(); + ClearLayout(); #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) delete lock; // Unlock pattern file @@ -2743,7 +2746,7 @@ void MainWindow::ToolBarStyles() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ShowPaper(int index) { - if (index < 0 || index > scenes.size()) + if (index < 0 || index >= scenes.size()) { ui->view->setScene(tempSceneLayout); //EnableActions(false); @@ -2751,6 +2754,7 @@ void MainWindow::ShowPaper(int index) else { ui->view->setScene(scenes.at(index)); + //EnableActions(true); } ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); From 80d7c39a922b5aff267693e7c0305f6ca6b477f1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 12 May 2015 20:59:36 +0300 Subject: [PATCH 6/9] Show layout settings dialog if a layout was not created. --HG-- branch : feature --- src/app/mainwindow.cpp | 5 +++++ src/app/mainwindowsnogui.cpp | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 3106403fb..efe78ec7c 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1340,6 +1340,11 @@ void MainWindow::ActionLayout(bool checked) ui->dockWidgetToolOptions->setVisible(false); ShowPaper(ui->listWidget->currentRow()); + + if (scenes.isEmpty()) + { + ui->toolButtonLayoutSettings->click(); + } } else { diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index fb00a38b4..08b06c8de 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -57,6 +57,9 @@ MainWindowsNoGUI::~MainWindowsNoGUI() //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::ToolLayoutSettings(bool checked) { + QToolButton *tButton = qobject_cast< QToolButton * >(this->sender()); + SCASSERT(tButton != nullptr) + if (checked) { VLayoutGenerator lGenerator(this); @@ -65,6 +68,7 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) DialogLayoutSettings layout(&lGenerator, this); if (layout.exec() == QDialog::Rejected) { + tButton->setChecked(false); return; } @@ -98,13 +102,11 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) default: break; } + tButton->setChecked(false); } else { - if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) - { - tButton->setChecked(true); - } + tButton->setChecked(true); } } From 7a7753e3f116c14dabb37b2a814ea2a7b0b1a33d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 13 May 2015 13:23:57 +0300 Subject: [PATCH 7/9] Disable or hide all unnecessary functions in Layout mode. --HG-- branch : feature --- src/app/mainwindow.cpp | 45 +++++++++++++++++++++++++++++++----- src/app/mainwindow.ui | 23 ++++++++++++++---- src/app/mainwindowsnogui.cpp | 3 ++- src/app/mainwindowsnogui.h | 4 ++++ 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index efe78ec7c..0aff6c557 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1229,8 +1229,17 @@ 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); - ui->toolBarOption->setVisible(true); + if (qApp->patternType() == MeasurementsType::Standard) + { + ui->toolBarOption->setVisible(true); + } ui->dockWidgetLayoutPages->setVisible(false); ui->dockWidgetToolOptions->setVisible(true); @@ -1277,11 +1286,22 @@ void MainWindow::ActionDetails(bool checked) 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); - ui->toolBarOption->setVisible(false); + if (qApp->patternType() == MeasurementsType::Standard) + { + ui->toolBarOption->setVisible(true); + } ui->dockWidgetLayoutPages->setVisible(false); ui->dockWidgetToolOptions->setVisible(true); + + helpLabel->setText(""); } else { @@ -1333,8 +1353,18 @@ void MainWindow::ActionLayout(bool checked) 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(""); - ui->toolBarOption->setVisible(false); + if (qApp->patternType() == MeasurementsType::Standard) + { + ui->toolBarOption->setVisible(false); + } ui->dockWidgetLayoutPages->setVisible(true); ui->dockWidgetToolOptions->setVisible(false); @@ -1345,6 +1375,8 @@ void MainWindow::ActionLayout(bool checked) { ui->toolButtonLayoutSettings->click(); } + + helpLabel->setText(""); } else { @@ -2295,13 +2327,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); @@ -2312,7 +2344,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); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index f5b72fcfb..b502d1349 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -50,7 +50,7 @@ 0 0 - 105 + 100 272 @@ -337,7 +337,7 @@ 0 0 - 105 + 100 58 @@ -413,7 +413,7 @@ 0 0 - 105 + 100 156 @@ -567,7 +567,7 @@ 0 0 - 105 + 100 104 @@ -741,6 +741,14 @@ + + + 0 + 0 + 87 + 58 + + Layout @@ -754,7 +762,9 @@ Settings - + + + @@ -1474,6 +1484,9 @@ + + false + Last Tool diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index 08b06c8de..fdbf6360f 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -42,7 +42,8 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), pattern(new VContainer()), papers(QList()), shadows(QList()), - scenes(QList()), details(QList >()) + scenes(QList()), details(QList >()), undoAction(nullptr), + redoAction(nullptr), actionDockWidgetToolOptions(nullptr) { InitTempLayoutScene(); } diff --git a/src/app/mainwindowsnogui.h b/src/app/mainwindowsnogui.h index 4a426f86e..0716d0382 100644 --- a/src/app/mainwindowsnogui.h +++ b/src/app/mainwindowsnogui.h @@ -62,6 +62,10 @@ protected: QList scenes; QList > details; + QAction *undoAction; + QAction *redoAction; + QAction *actionDockWidgetToolOptions; + void PrepareDetailsForLayout(const QHash *details); void InitTempLayoutScene(); From c954c2654cc1735d62ab6885829c7e22258a81cd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 14 May 2015 15:27:04 +0300 Subject: [PATCH 8/9] Print/Save functions. --HG-- branch : feature --- src/app/mainwindow.cpp | 40 +- src/app/mainwindow.h | 9 +- src/app/mainwindow.ui | 137 +++- src/app/mainwindowsnogui.cpp | 655 +++++++++++++++++- src/app/mainwindowsnogui.h | 42 ++ src/app/share/resources/icon.qrc | 1 + .../icon/32x32/export_to_picture_document.png | Bin 0 -> 4181 bytes 7 files changed, 863 insertions(+), 21 deletions(-) create mode 100644 src/app/share/resources/icon/32x32/export_to_picture_document.png diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 0aff6c557..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) - :MainWindowsNoGUI(parent), ui(new Ui::MainWindow), doc(nullptr), currentTool(Tool::Arrow), + :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), @@ -818,7 +818,7 @@ void MainWindow::ClearLayout() shadows.clear(); papers.clear(); ui->listWidget->clear(); - //EnableActions(false); + SetLayoutModeActions(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -833,7 +833,7 @@ void MainWindow::PrepareSceneList() if (not scenes.isEmpty()) { ui->listWidget->setCurrentRow(0); - //EnableActions(true); + SetLayoutModeActions(true); } } @@ -1804,6 +1804,7 @@ void MainWindow::Layout() { ui->actionDetails->setEnabled(true); ui->actionLayout->setEnabled(true); + SetLayoutModeActions(true); } else { @@ -1811,6 +1812,7 @@ void MainWindow::Layout() ui->actionDetails->setEnabled(false); ui->actionLayout->setEnabled(false); ui->actionDraw->setChecked(true); + SetLayoutModeActions(false); } } @@ -1970,6 +1972,7 @@ void MainWindow::PatternWasModified(bool saved) { setWindowModified(!saved); ui->actionSave->setEnabled(!saved); + isLayoutStale = true; } } @@ -2123,6 +2126,23 @@ void MainWindow::SetEnableTool(bool enable) 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); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief MinimumScrollBar set scroll bar to minimum. @@ -2524,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. @@ -2787,12 +2815,12 @@ void MainWindow::ShowPaper(int index) if (index < 0 || index >= scenes.size()) { ui->view->setScene(tempSceneLayout); - //EnableActions(false); + SetLayoutModeActions(false); } else { ui->view->setScene(scenes.at(index)); - //EnableActions(true); + SetLayoutModeActions(true); } ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index c140b2451..07288e4bf 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -35,8 +35,6 @@ #include "tools/vtooldetail.h" #include "tools/vtooluniondetails.h" #include "tools/drawTools/drawtools.h" -#include "xml/vdomdocument.h" - namespace Ui { @@ -156,8 +154,7 @@ private: /** @brief ui keeps information about user interface */ Ui::MainWindow *ui; - /** @brief doc dom document container */ - VPattern *doc; + /** @brief tool current tool */ Tool currentTool; @@ -187,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; @@ -222,6 +216,7 @@ private: void SetEnableWidgets(bool enable); void SetEnableTool(bool enable); + void SetLayoutModeActions(bool enable); void SaveCurrentScene(); void RestoreCurrentScene(); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index b502d1349..d3f5123c9 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -50,7 +50,7 @@ 0 0 - 100 + 105 272 @@ -337,7 +337,7 @@ 0 0 - 100 + 105 58 @@ -413,7 +413,7 @@ 0 0 - 100 + 105 156 @@ -567,7 +567,7 @@ 0 0 - 100 + 105 104 @@ -745,8 +745,8 @@ 0 0 - 87 - 58 + 105 + 380 @@ -815,11 +815,27 @@ &File + + + Layout + + + + + + + + + + + + + @@ -1514,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/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index fdbf6360f..f59c1fb1b 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -29,21 +29,36 @@ #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" #include "../dialogs/app/dialoglayoutprogress.h" #include "../dialogs/app/dialogsavelayout.h" #include "../../libs/vlayout/vposter.h" +#include +#include #include +#include +#include #include +#include +#include +#include +#include + +#ifdef Q_OS_WIN +# define PDFTOPS "pdftops.exe" +#else +# define PDFTOPS "pdftops" +#endif //--------------------------------------------------------------------------------------------------------------------- MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer()), papers(QList()), shadows(QList()), + pattern(new VContainer()), doc(nullptr), papers(QList()), shadows(QList()), scenes(QList()), details(QList >()), undoAction(nullptr), - redoAction(nullptr), actionDockWidgetToolOptions(nullptr) + redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), isLayoutStale(true), isTiled(false) { InitTempLayoutScene(); } @@ -92,6 +107,7 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) CreateShadows(); CreateScenes(); PrepareSceneList(); + isLayoutStale = false; break; case LayoutErrors::ProcessStoped: break; @@ -111,6 +127,224 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ExportLayoutAs() +{ + if (isLayoutStale) + { + if (ContinueIfLayoutStale() == QMessageBox::No) + { + return; + } + } + QMap extByMessage = InitFormates(); + DialogSaveLayout dialog(extByMessage, scenes.size(), FileName(), this); + + if (dialog.exec() == QDialog::Rejected) + { + return; + } + + QString suf = dialog.Formate(); + suf.replace(".", ""); + + const QString path = dialog.Path(); + qApp->getSettings()->SetPathLayout(path); + const QString mask = dialog.FileName(); + + for (int i=0; i < scenes.size(); ++i) + { + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) + { + const QString name = path + "/" + mask+QString::number(i+1) + dialog.Formate(); + QBrush *brush = new QBrush(); + brush->setColor( QColor( Qt::white ) ); + scenes[i]->setBackgroundBrush( *brush ); + shadows[i]->setVisible(false); + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); + const QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj"; + switch (suffix.indexOf(suf)) + { + case 0: //svg + paper->setVisible(false); + SvgFile(name, i); + paper->setVisible(true); + break; + case 1: //png + PngFile(name, i); + break; + case 2: //pdf + PdfFile(name, i); + break; + case 3: //eps + EpsFile(name, i); + break; + case 4: //ps + PsFile(name, i); + break; + case 5: //obj + paper->setVisible(false); + ObjFile(name, i); + paper->setVisible(true); + break; + default: + qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO; + break; + } + paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); + brush->setColor( QColor( Qt::gray ) ); + brush->setStyle( Qt::SolidPattern ); + scenes[i]->setBackgroundBrush( *brush ); + shadows[i]->setVisible(true); + delete brush; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::SaveAsPDF() +{ + if (not isPagesUniform()) + { + qCritical()< images = AllSheets(); + + QVector poster; + if (isTiled) + { + 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; + if (not painter.begin(printer)) + { // failed to open file + qWarning("failed to open file, is it writable?"); + return; + } + + // Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. + int firstPage = printer->fromPage() - 1; + if (firstPage >= poster.size()) + { + return; + } + if (firstPage == -1) + { + firstPage = 0; + } + + int lastPage = printer->toPage() - 1; + if (lastPage == -1 || lastPage >= poster.size()) + { + lastPage = poster.size() - 1; + } + + const int numPages = lastPage - firstPage + 1; + int copyCount = 1; + if (not printer->supportsMultipleCopies()) + { + copyCount = printer->copyCount(); + } + + for (int i = 0; i < copyCount; ++i) + { + for (int j = 0; j < numPages; ++j) + { + if (i != 0 || j != 0) + { + if (not printer->newPage()) + { + qWarning("failed in flushing page to disk, disk full?"); + return; + } + } + int index; + if (printer->pageOrder() == QPrinter::FirstPageFirst) + { + index = firstPage + j; + } + else + { + index = lastPage - j; + } + painter.drawImage(QPointF(), poster.at(index)); + } + } + + painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::PrintPreviewOrigin() +{ + if (not isPagesUniform()) + { + qCritical()< *details) { @@ -220,3 +454,420 @@ void MainWindowsNoGUI::CreateScenes() scenes.append(scene); } } + +//--------------------------------------------------------------------------------------------------------------------- +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"; + + 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)) + { + extByMessage[ tr("PS files (*.ps)") ] = ".ps"; + extByMessage[ tr("EPS files (*.eps)") ] = ".eps"; + } + else + { + qDebug()<(papers.at(i)); + if (paper) + { + QSvgGenerator generator; + generator.setFileName(name); + generator.setSize(paper->rect().size().toSize()); + generator.setViewBox(paper->rect()); + generator.setTitle("Valentina. Pattern layout"); + generator.setDescription(doc->GetDescription()); + generator.setResolution(static_cast(qApp->PrintDPI)); + QPainter painter; + painter.begin(&generator); + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + scenes.at(i)->render(&painter); + painter.end(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PngFile save layout to png file. + * @param name name layout file. + */ +void MainWindowsNoGUI::PngFile(const QString &name, int i) const +{ + 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 + QImage image(QSize(static_cast(r.width()), static_cast(r.height())), QImage::Format_ARGB32); + image.fill(Qt::transparent); // Start all pixels transparent + 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, r, r); + image.save(name); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PdfFile save layout to pdf file. + * @param name name layout file. + */ +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; + if (painter.begin( &printer ) == false) + { // failed to open file + qCritical("Can't open printer %s", qPrintable(name)); + return; + } + 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(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief EpsFile save layout to eps file. + * @param name name layout file. + */ +void MainWindowsNoGUI::EpsFile(const QString &name, int i) const +{ + QTemporaryFile tmp; + if (tmp.open()) + { + PdfFile(tmp.fileName(), i); + QStringList params = QStringList() << "-eps" << tmp.fileName() << name; + PdfToPs(params); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PsFile save layout to ps file. + * @param name name layout file. + */ +void MainWindowsNoGUI::PsFile(const QString &name, int i) const +{ + QTemporaryFile tmp; + if (tmp.open()) + { + PdfFile(tmp.fileName(), i); + QStringList params = QStringList() << tmp.fileName() << name; + PdfToPs(params); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format. + * @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when + * need create eps file. + */ +void MainWindowsNoGUI::PdfToPs(const QStringList ¶ms) const +{ +#ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); +#endif + QProcess proc; + proc.start(PDFTOPS, params); + proc.waitForFinished(15000); +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + + QFile f(params.last()); + if (f.exists() == false) + { + QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString()); + QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default); + msgBox.exec(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ObjFile(const QString &name, int i) const +{ + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) + { + VObjPaintDevice generator; + generator.setFileName(name); + generator.setSize(paper->rect().size().toSize()); + generator.setResolution(static_cast(qApp->PrintDPI)); + QPainter painter; + painter.begin(&generator); + scenes.at(i)->render(&painter); + painter.end(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector MainWindowsNoGUI::AllSheets() +{ + QVector images; + for (int i=0; i < scenes.size(); ++i) + { + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) + { + // Hide shadow and paper border + QBrush *brush = new QBrush(); + brush->setColor( QColor( Qt::white ) ); + scenes[i]->setBackgroundBrush( *brush ); + shadows[i]->setVisible(false); + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));// border + + // Render png + const QRectF r = paper->rect(); + // Create the image with the exact size of the shrunk scene + QImage image(QSize(static_cast(r.width()), static_cast(r.height())), QImage::Format_RGB32); + 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(); + images.append(image); + + // Resore + paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); + brush->setColor( QColor( Qt::gray ) ); + brush->setStyle( Qt::SolidPattern ); + scenes[i]->setBackgroundBrush( *brush ); + shadows[i]->setVisible(true); + delete brush; + } + } + return images; +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::SaveLayoutAs() +{ + 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 MainWindowsNoGUI::PrintPreview() +{ + if (isLayoutStale) + { + if (ContinueIfLayoutStale() == QMessageBox::No) + { + 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 + { + 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 MainWindowsNoGUI::LayoutPrint() +{ + if (isLayoutStale) + { + if (ContinueIfLayoutStale() == QMessageBox::No) + { + return; + } + } + // 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 MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) +{ + SCASSERT(printer != nullptr) + printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion()); + + // Set orientation + if (papers.size() > 0) + { + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(0)); + SCASSERT(paper != nullptr) + if (paper->rect().height()>= paper->rect().width()) + { + printer->setOrientation(QPrinter::Portrait); + } + else + { + printer->setOrientation(QPrinter::Landscape); + } + } + + if (not isTiled && papers.size() > 0) + { + 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 ); + } + + printer->setDocName(FileName()); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool MainWindowsNoGUI::isPagesUniform() const +{ + if (papers.size() < 2) + { + return true; + } + else + { + QGraphicsRectItem *paper = qgraphicsitem_cast(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 true; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString MainWindowsNoGUI::FileName() const +{ + QString fileName; + curFile.isEmpty() ? fileName = tr("unnamed") : fileName = curFile; + return QFileInfo(fileName).baseName(); +} + +//--------------------------------------------------------------------------------------------------------------------- +int MainWindowsNoGUI::ContinueIfLayoutStale() +{ + 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/mainwindowsnogui.h b/src/app/mainwindowsnogui.h index 0716d0382..07ac4f0cc 100644 --- a/src/app/mainwindowsnogui.h +++ b/src/app/mainwindowsnogui.h @@ -33,8 +33,10 @@ #include "../geometry/vdetail.h" #include "../libs/vlayout/vlayoutdetail.h" +#include "xml/vpattern.h" class QGraphicsScene; +class QPrinter; class MainWindowsNoGUI : public QMainWindow { @@ -45,6 +47,14 @@ public: public slots: void ToolLayoutSettings(bool checked); + void ExportLayoutAs(); + void SaveAsPDF(); + void SaveAsTiledPDF(); + void PrintPages (QPrinter *printer); + void PrintPreviewOrigin(); + void PrintPreviewTiled(); + void PrintOrigin(); + void PrintTiled(); protected: QVector listDetails; @@ -57,6 +67,9 @@ protected: /** @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; @@ -66,6 +79,11 @@ protected: QAction *redoAction; QAction *actionDockWidgetToolOptions; + /** @brief fileName name current pattern file. */ + QString curFile; + + bool isLayoutStale; + void PrepareDetailsForLayout(const QHash *details); void InitTempLayoutScene(); @@ -76,9 +94,33 @@ protected: 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; + void PdfFile(const QString &name, int i)const; + void EpsFile(const QString &name, int i)const; + void PsFile(const QString &name, int i)const; + void PdfToPs(const QStringList ¶ms)const; + void ObjFile(const QString &name, int i)const; + + QVector AllSheets(); + + void SaveLayoutAs(); + void PrintPreview(); + void LayoutPrint(); + + void SetPrinterSettings(QPrinter *printer); + + bool isPagesUniform() const; + QString FileName() const; + + int ContinueIfLayoutStale(); }; #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 0000000000000000000000000000000000000000..b2f15bacfde5a1e80e604327c9c75d64cee6d4ed GIT binary patch literal 4181 zcmV-b5UTHqP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z000GmNklA6O6~}+~zK@w_PdwQ1xONPINU;mC-3lV8fTqfV&~Es)qHI`2 z6jgu_Labmh6bT7f(?t^&X;oC=1R=U$0Tq>~Dp4myYC8#aZD@lT&>x{{h^00DiZ@%a<=d13dM=7<*WnztjW(b8~N#&*u@p^Es6{#b0J#<;L|Jh$q~>sR%GSI?DL?IL4SQdurbhT>Zw4 z28PdUhhTAWk?HAaZsy*`tQsDDdnRq3}y(XAjnx|YY(^E=eV#CKi{ZVFTu5xFo$jEnwx`G%P8NnEXQVOj# z#+VKPY5`b0_n(Y&d>ChspZwA%9!84E^*2_D|7viXl8+}&;ukzJ3{kCAK?*khUFK6~ zKgrc!{h9LSyG(t5y&1k3S1Yj4^YxY@YNcDG?y3XMIvm@%ym7n4TCh$~3ZZQA5&=Pv zkDv7M5)zs8a29GSbsqWl=Xmv}f5KMFJoLSJoUY(1OVG2eimv(Craa$UF>;;6ZV_Bc z!q7+h0_Pm{J9QrW$>S`(G)!fsM7+8|ZLL$5w@$uA>U}xjtTR?wrL@A7EoN0CJc$=d zq%V@Q!26Mv)n-W;{tx2gW?R%^X#dSFXgyLw<-^DPKSKaeICb;48v+iww`Kn4=4 z4Qs`9bX}25C+HhF#P#R?Ks9rn!(+dv{`Y`lB8h)!fKsW%(9jTCZM$PH4)_g95A3jB4{x*a2L)0pDGRFpa{l&{HN7txCzv0e; zOnKg{UaFEeoXJV6k27!AX)mH&4Q!H=JQ+BFqQ163^i{1-nXolaw|C5j>j1_oFU zHb{^3@z$+3(GSIZ@Z2z&OlH^S?HOQk6m~ID>@1T)2$9WZ zMLwVRmX?-+zP>)+Ip-;*gzx)OYwa6j{4flKF{b5C&+{B$j4?`UZKEi%N+}DNa=ENh zsg$0XnXwHlZeIZHH%+qHY-=Ew%ZWmvAjZeX1;Fa+YHO~)zuz4>a>V6wIX5ve;o3Om f+G^~sEcovLdXl8^{1b4J00000NkvXXu0mjfyO``W literal 0 HcmV?d00001 From b1b932c1c26679ea24fa57f9c58578f034a9e77e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 14 May 2015 15:49:44 +0300 Subject: [PATCH 9/9] We don't need these classes anymore. --HG-- branch : feature --- src/app/app.pri | 7 +- src/app/main.cpp | 1 - src/app/tablewindow.cpp | 836 ------------------------- src/app/tablewindow.h | 121 ---- src/app/tablewindow.ui | 328 ---------- src/app/widgets/vtablegraphicsview.cpp | 255 -------- src/app/widgets/vtablegraphicsview.h | 95 --- src/app/widgets/widgets.pri | 2 - 8 files changed, 1 insertion(+), 1644 deletions(-) delete mode 100644 src/app/tablewindow.cpp delete mode 100644 src/app/tablewindow.h delete mode 100644 src/app/tablewindow.ui delete mode 100644 src/app/widgets/vtablegraphicsview.cpp delete mode 100644 src/app/widgets/vtablegraphicsview.h diff --git a/src/app/app.pri b/src/app/app.pri index ceb1aeec4..4d185e939 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -16,7 +16,6 @@ include(core/core.pri) SOURCES += \ $$PWD/main.cpp \ $$PWD/mainwindow.cpp \ - $$PWD/tablewindow.cpp \ $$PWD/stable.cpp \ $$PWD/version.cpp \ $$PWD/options.cpp \ @@ -26,14 +25,10 @@ SOURCES += \ HEADERS += \ $$PWD/mainwindow.h \ $$PWD/options.h \ - $$PWD/tablewindow.h \ $$PWD/stable.h \ $$PWD/version.h \ $$PWD/mainwindowsnogui.h # Main forms FORMS += \ - $$PWD/mainwindow.ui \ - $$PWD/tablewindow.ui - - + $$PWD/mainwindow.ui diff --git a/src/app/main.cpp b/src/app/main.cpp index b3556fd2c..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 diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp deleted file mode 100644 index 1dc29d50e..000000000 --- a/src/app/tablewindow.cpp +++ /dev/null @@ -1,836 +0,0 @@ -/************************************************************************ - ** - ** @file tablewindow.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 "tablewindow.h" -#include "ui_tablewindow.h" -#include "widgets/vtablegraphicsview.h" -#include "core/vapplication.h" -#include "core/vsettings.h" -#include "../../libs/vobj/vobjpaintdevice.h" -#include "../dialogs/app/dialoglayoutsettings.h" -#include "../../libs/vlayout/vlayoutgenerator.h" -#include "../dialogs/app/dialoglayoutprogress.h" -#include "../dialogs/app/dialogsavelayout.h" -#include "../../libs/vlayout/vposter.h" - -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_OS_WIN -# define PDFTOPS "pdftops.exe" -#else -# define PDFTOPS "pdftops" -#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) -{ - 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 -} - -//--------------------------------------------------------------------------------------------------------------------- -TableWindow::~TableWindow() -{ - ClearLayout(); - delete ui; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @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) -{ - this->description = description; - - QString file; - if (fileName.isEmpty()) - { - file = tr("untitled"); - } - else - { - file = fileName; - } - 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() -{ - QMap extByMessage = InitFormates(); - DialogSaveLayout dialog(extByMessage, scenes.size(), fileName, this); - - if (dialog.exec() == QDialog::Rejected) - { - return; - } - - QString suf = dialog.Formate(); - suf.replace(".", ""); - - const QString path = dialog.Path(); - qApp->getSettings()->SetPathLayout(path); - const QString mask = dialog.FileName(); - - for (int i=0; i < scenes.size(); ++i) - { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - const QString name = path + "/" + mask+QString::number(i+1) + dialog.Formate(); - QBrush *brush = new QBrush(); - brush->setColor( QColor( Qt::white ) ); - 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"; - switch (suffix.indexOf(suf)) - { - case 0: //svg - paper->setVisible(false); - SvgFile(name, i); - paper->setVisible(true); - break; - case 1: //png - PngFile(name, i); - break; - case 2: //pdf - PdfFile(name, i); - break; - case 3: //eps - EpsFile(name, i); - break; - case 4: //ps - PsFile(name, i); - break; - case 5: //obj - paper->setVisible(false); - ObjFile(name, i); - paper->setVisible(true); - break; - default: - qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO; - break; - } - paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); - brush->setColor( QColor( Qt::gray ) ); - brush->setStyle( Qt::SolidPattern ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(true); - delete brush; - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::ShowPaper(int index) -{ - if (index < 0 || index > scenes.size()) - { - ui->view->setScene(tempScene); - EnableActions(false); - } - else - { - ui->view->setScene(scenes.at(index)); - } - - ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::PrintPreview() -{ - 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(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::Print(QPrinter *printer) -{ - if (printer == nullptr) - { - return; - } - - const QVector images = AllSheets(); - - VPoster posterazor(printer); - QVector poster; - for (int i=0; i < images.size(); i++) - { - poster += posterazor.Generate(images.at(i), i+1, images.size()); - } - - QPainter painter; - if (not painter.begin(printer)) - { // failed to open file - qWarning("failed to open file, is it writable?"); - return; - } - - // Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. - int firstPage = printer->fromPage() - 1; - if (firstPage >= poster.size()) - { - return; - } - if (firstPage == -1) - { - firstPage = 0; - } - - int lastPage = printer->toPage() - 1; - if (lastPage == -1 || lastPage >= poster.size()) - { - lastPage = poster.size() - 1; - } - - const int numPages = lastPage - firstPage + 1; - int copyCount = 1; - if (not printer->supportsMultipleCopies()) - { - copyCount = printer->copyCount(); - } - - for (int i = 0; i < copyCount; ++i) - { - for (int j = 0; j < numPages; ++j) - { - if (i != 0 || j != 0) - { - if (not printer->newPage()) - { - qWarning("failed in flushing page to disk, disk full?"); - return; - } - } - int index; - if (printer->pageOrder() == QPrinter::FirstPageFirst) - { - index = firstPage + j; - } - else - { - index = lastPage - j; - } - painter.drawImage(QPointF(), poster.at(index)); - } - } - - painter.end(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::LayoutPrint() -{ - // 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 ) - { - printer.setResolution(static_cast(VApplication::PrintDPI)); - Print( &printer ); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::PrintToPdf() -{ - QPrinter printer; - printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion()); - printer.setDocName(fileName); - - QPageSetupDialog dialog(&printer, this); - if ( dialog.exec() == QDialog::Accepted ) - { - 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"); - } - - printer.setOutputFileName(fileName); - printer.setResolution(static_cast(VApplication::PrintDPI)); - Print( &printer ); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::Layout() -{ - VLayoutGenerator lGenerator(this); - lGenerator.SetDetails(listDetails); - - DialogLayoutSettings layout(&lGenerator, this); - if (layout.exec() == QDialog::Rejected) - { - 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(); - break; - case LayoutErrors::ProcessStoped: - break; - case LayoutErrors::PrepareLayoutError: - case LayoutErrors::PaperSizeError: - case LayoutErrors::EmptyPaperError: - ClearLayout(); - break; - default: - break; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SvgFile save layout to svg file. - * @param name name layout file. - */ -void TableWindow::SvgFile(const QString &name, int i) const -{ - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - QSvgGenerator generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setViewBox(paper->rect()); - generator.setTitle("Valentina. Pattern layout"); - generator.setDescription(description); - generator.setResolution(static_cast(qApp->PrintDPI)); - QPainter painter; - painter.begin(&generator); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter); - painter.end(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PngFile save layout to png file. - * @param name name layout file. - */ -void TableWindow::PngFile(const QString &name, int i) const -{ - 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 - QImage image(QSize(static_cast(r.width()), static_cast(r.height())), QImage::Format_ARGB32); - image.fill(Qt::transparent); // Start all pixels transparent - 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, r, r); - image.save(name); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PdfFile save layout to pdf file. - * @param name name layout file. - */ -void TableWindow::PdfFile(const QString &name, int i) const -{ - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - QPrinter printer; - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(name); - const QRectF r = paper->rect(); - printer.setResolution(static_cast(qApp->PrintDPI)); - printer.setPaperSize ( QSizeF(qApp->fromPixel(r.width(), Unit::Mm), qApp->fromPixel(r.height(), Unit::Mm)), - QPrinter::Millimeter ); - QPainter painter; - if (painter.begin( &printer ) == false) - { // failed to open file - qCritical("Can't open printer %s", qPrintable(name)); - return; - } - 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(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief EpsFile save layout to eps file. - * @param name name layout file. - */ -void TableWindow::EpsFile(const QString &name, int i) const -{ - QTemporaryFile tmp; - if (tmp.open()) - { - PdfFile(tmp.fileName(), i); - QStringList params = QStringList() << "-eps" << tmp.fileName() << name; - PdfToPs(params); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PsFile save layout to ps file. - * @param name name layout file. - */ -void TableWindow::PsFile(const QString &name, int i) const -{ - QTemporaryFile tmp; - if (tmp.open()) - { - PdfFile(tmp.fileName(), i); - QStringList params = QStringList() << tmp.fileName() << name; - PdfToPs(params); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format. - * @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 -{ -#ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); -#endif - QProcess proc; - proc.start(PDFTOPS, params); - proc.waitForFinished(15000); -#ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); -#endif - - QFile f(params.last()); - if (f.exists() == false) - { - QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString()); - QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default); - msgBox.exec(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::ObjFile(const QString &name, int i) const -{ - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - VObjPaintDevice generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setResolution(static_cast(qApp->PrintDPI)); - QPainter painter; - painter.begin(&generator); - scenes.at(i)->render(&painter); - painter.end(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QVector TableWindow::AllSheets() -{ - QVector images; - for (int i=0; i < scenes.size(); ++i) - { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - // Hide shadow and paper border - QBrush *brush = new QBrush(); - brush->setColor( QColor( Qt::white ) ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(false); - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));// border - - // Render png - const QRectF r = paper->rect(); - // Create the image with the exact size of the shrunk scene - QImage image(QSize(static_cast(r.width()), static_cast(r.height())), QImage::Format_RGB32); - 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(); - images.append(image); - - // Resore - paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); - brush->setColor( QColor( Qt::gray ) ); - brush->setStyle( Qt::SolidPattern ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(true); - delete brush; - } - } - return images; -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::ClearLayout() -{ - qDeleteAll (scenes); - scenes.clear(); - shadows.clear(); - papers.clear(); - ui->listWidget->clear(); - EnableActions(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::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::CreateScenes() -{ - 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) - { - scene->addItem(paperDetails.at(i)); - } - - scenes.append(scene); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::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); - 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()) - { - 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)); -} - -//--------------------------------------------------------------------------------------------------------------------- -QMap TableWindow::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"; - - 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)) - { - extByMessage[ tr("PS files (*.ps)") ] = ".ps"; - extByMessage[ tr("EPS files (*.eps)") ] = ".eps"; - } - else - { - qDebug()<actionSave->setEnabled(enable); - ui->actionSave_to_p_df->setEnabled(enable); - ui->actionPrint_pre_view->setEnabled(enable); - ui->action_Print->setEnabled(enable); -} - -//--------------------------------------------------------------------------------------------------------------------- -void TableWindow::ToolBarStyle(QToolBar *bar) -{ - 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); -} diff --git a/src/app/tablewindow.h b/src/app/tablewindow.h deleted file mode 100644 index ad2452732..000000000 --- a/src/app/tablewindow.h +++ /dev/null @@ -1,121 +0,0 @@ -/************************************************************************ - ** - ** @file tablewindow.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 TABLEWINDOW_H -#define TABLEWINDOW_H - -#include -#include - -#include "../../libs/vlayout/vlayoutdetail.h" -#include "../../libs/vlayout/vbank.h" - -namespace Ui -{ - class TableWindow; -} - -class QGraphicsScene; -class QGraphicsRectItem; -class QPrinter; - -/** - * @brief TableWindow class layout window. - */ -class TableWindow : public QMainWindow -{ - Q_OBJECT -public: - explicit TableWindow(QWidget *parent = nullptr); - ~TableWindow(); - -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(); - -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; - - QList papers; - QList shadows; - QList scenes; - QList > details; - - /** @brief fileName keep name of pattern file. */ - QString fileName; - - /** @brief description pattern description */ - QString description; - - QGraphicsScene* tempScene; - - void SvgFile(const QString &name, int i)const; - void PngFile(const QString &name, int i)const; - void PdfFile(const QString &name, int i)const; - void EpsFile(const QString &name, int i)const; - void PsFile(const QString &name, int i)const; - void PdfToPs(const QStringList ¶ms)const; - void ObjFile(const QString &name, int i)const; - - QVector AllSheets(); - - void ClearLayout(); - void CreateShadows(); - void CreateScenes(); - void PrepareSceneList(); - QIcon ScenePreview(int i) const; - QMap InitFormates() const; - - void EnableActions(bool enable); - void ToolBarStyle(QToolBar *bar); - void ReadSettings(); - void ToolBarStyles(); -}; - -#endif // TABLEWINDOW_H 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/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 \