valentina/src/app/puzzle/vpmainwindow.h

533 lines
16 KiB
C
Raw Normal View History

2020-02-16 17:17:50 +01:00
/************************************************************************
**
2020-05-23 14:17:20 +02:00
** @file vpmainwindow.h
2020-02-16 17:17:50 +01:00
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 16 2, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
2020-05-23 14:17:20 +02:00
#ifndef VPMAINWINDOW_H
#define VPMAINWINDOW_H
2020-02-16 17:17:50 +01:00
#include <QDoubleSpinBox>
2020-02-16 17:17:50 +01:00
#include <QMainWindow>
2020-04-10 21:08:29 +02:00
#include <QMessageBox>
2020-11-14 10:55:57 +01:00
#include <QPointer>
#include <memory>
#include "../vlayout/dialogs/vabstractlayoutdialog.h"
#include "../vlayout/vlayoutpiece.h"
#include "../vmisc/def.h"
2023-10-23 15:57:22 +02:00
#include "../vmisc/vabstractshortcutmanager.h"
#include "../vmisc/vlockguard.h"
#include "../vwidgets/vabstractmainwindow.h"
2021-08-09 14:09:10 +02:00
#include "carousel/vpcarrousel.h"
#include "layout/vplayout.h"
#include "scene/vpmaingraphicsview.h"
2020-05-23 14:48:31 +02:00
#include "vpcommandline.h"
2020-02-16 17:17:50 +01:00
namespace Ui
{
class VPMainWindow;
2020-02-16 17:17:50 +01:00
}
2021-08-14 16:16:52 +02:00
class QFileSystemWatcher;
2021-08-21 15:13:56 +02:00
template <typename T> class QSharedPointer;
class DialogPuzzlePreferences;
2021-09-06 14:31:19 +02:00
struct VPExportData;
2021-09-11 18:39:38 +02:00
class WatermarkWindow;
2021-08-14 16:16:52 +02:00
class VPMainWindow : public VAbstractMainWindow
2020-02-16 17:17:50 +01:00
{
2022-08-12 17:50:13 +02:00
Q_OBJECT // NOLINT
2020-02-16 17:17:50 +01:00
public:
2024-04-06 11:09:38 +02:00
explicit VPMainWindow(VPCommandLinePtr cmd, QWidget *parent = nullptr);
2022-08-12 17:50:13 +02:00
~VPMainWindow() override;
2020-02-16 17:17:50 +01:00
2022-08-12 17:50:13 +02:00
auto CurrentFile() const -> QString;
2021-05-21 17:08:37 +02:00
2020-04-19 16:01:46 +02:00
/**
* @brief LoadFile Loads the layout file of given path in m_layout.
* This function doesn't update the gui.
2020-04-23 17:41:34 +02:00
* @param path path to layout
* @return true if success
2020-04-19 16:01:46 +02:00
*/
auto LoadFile(const QString &path) -> bool;
2020-02-16 18:18:39 +01:00
2021-05-21 16:17:22 +02:00
void LayoutWasSaved(bool saved);
void SetCurrentFile(const QString &fileName);
2020-04-19 16:01:46 +02:00
/**
2021-05-21 16:17:22 +02:00
* @brief SaveLayout Saves the current layout to the layout file of given path
2020-04-23 17:41:34 +02:00
* @param path path to layout file
* @return true if success
2020-04-19 16:01:46 +02:00
*/
2022-08-12 17:50:13 +02:00
auto SaveLayout(const QString &path, QString &error) -> bool;
2020-04-19 16:01:46 +02:00
/**
* @brief ImportRawLayouts The function imports the raw layouts of given paths
2020-04-26 12:09:28 +02:00
* @param rawLayouts paths of the layouts to import
*/
2020-04-26 12:09:28 +02:00
void ImportRawLayouts(const QStringList &rawLayouts);
2020-11-13 23:31:22 +01:00
/**
* @brief InitZoom Initialises the zoom to fit best
*/
void InitZoom();
2021-05-21 19:51:46 +02:00
void UpdateWindowTitle();
public slots:
/**
* @brief on_actionNew_triggered When the menu action File > New
* is triggered
*/
void on_actionNew_triggered();
2022-08-12 17:50:13 +02:00
void ShowToolTip(const QString &toolTip) override;
2020-04-19 16:01:46 +02:00
protected:
2022-08-12 17:50:13 +02:00
void closeEvent(QCloseEvent *event) override;
void changeEvent(QEvent *event) override;
2022-08-12 17:50:13 +02:00
auto RecentFileList() const -> QStringList override;
2021-05-27 20:11:32 +02:00
private slots:
/**
* @brief on_actionOpen_triggered When the menu action File > Open is
* triggered.
* The slot is automatically connected through name convention.
*/
void on_actionOpen_triggered();
/**
* @brief on_actionSave_triggered When the menu action File > Save is
* triggered.
* The slot is automatically connected through name convention.
*/
bool on_actionSave_triggered(); // NOLINT(modernize-use-trailing-return-type)
/**
* @brief on_actionSaveAs_triggered When the menu action File > Save As
* is triggered.
* The slot is automatically connected through name convention.
*/
bool on_actionSaveAs_triggered(); // NOLINT(modernize-use-trailing-return-type)
/**
* @brief on_actionImportRawLayout_triggered When the menu action
* File > Import Raw Layout is triggered.
* The slot is automatically connected through name convention.
*/
void on_actionImportRawLayout_triggered();
/**
* @brief on_actionAboutQt_triggered When the menu action Help > About Qt
* is triggered.
* The slot is automatically connected through name convention.
*/
void on_actionAboutQt_triggered();
/**
* @brief on_actionAboutPuzzle_triggered When the menu action Help > About Puzzle
* is triggered.
* The slot is automatically connected through name convention.
*/
void on_actionAboutPuzzle_triggered();
/**
2021-08-25 15:58:50 +02:00
* @brief on_LayoutUnitChanged When the unit is changed in
* the layout property tab.
* The slot is automatically connected through name convention.
* @param index the index of the selected unit
*/
2021-08-25 15:58:50 +02:00
void on_LayoutUnitChanged(int index);
/**
2020-11-14 15:58:42 +01:00
* @brief on_SheetSizeChanged When the width or the length has been changed in
* the sheet property tab
*/
2021-08-25 15:58:50 +02:00
void on_SheetSizeChanged();
/**
2020-11-14 15:58:42 +01:00
* @brief on_SheetOrientationChanged When one of the radio boxes for the sheet
* orientation has been clicked
*/
2021-08-25 15:58:50 +02:00
void on_SheetOrientationChanged(bool checked);
/**
2020-11-14 15:58:42 +01:00
* @brief on_SheetMarginChanged When one of the margin values has been changed
* in the sheet property tab.
*/
void on_SheetMarginChanged();
/**
* @brief on_checkBoxSheetShowGrid_toggled When the checkbox "show grid" is
* clicked
* @param checked show grid
*/
void on_checkBoxSheetShowGrid_toggled(bool checked);
/**
* @brief on_doubleSpinBoxSheetGridColWidth_valueChanged When the "grid placement
* column width" value is changed in the layout property tab.
* The slot is automatically connected through name convention.
* @param value the new value of the grid placement column width
*/
void on_doubleSpinBoxSheetGridColWidth_valueChanged(double value);
/**
* @brief on_doubleSpinBoxSheetGridRowHeight_valueChanged When the "grid placement
* row height" value is changed in the layout property tab.
* The slot is automatically connected through name convention.
* @param value the new value of the grid placement row height
*/
void on_doubleSpinBoxSheetGridRowHeight_valueChanged(double value);
2020-11-14 15:58:42 +01:00
/**
* @brief on_TilesSizeChanged When the width or the length has been changed in
* the tiles property tab
*/
2021-08-25 15:58:50 +02:00
void on_TilesSizeChanged();
2020-11-14 15:58:42 +01:00
/**
* @brief on_TilesOrientationChanged When one of the radio boxes for the tiles
* orientation has been clicked
*/
2021-08-25 15:58:50 +02:00
void on_TilesOrientationChanged(bool checked);
2020-11-14 15:58:42 +01:00
/**
* @brief on_TilesMarginChanged When one of the margin values has been changed
* in the tiles property tab.
*/
void on_TilesMarginChanged();
/**
2020-05-23 14:29:18 +02:00
* @brief CarrouselLocationChanged When the piece carrousel's location
* has been changed
2020-05-02 09:44:45 +02:00
* @param area The new area where the piece carrousel has been placed
*/
2020-05-23 14:29:18 +02:00
void on_CarrouselLocationChanged(Qt::DockWidgetArea area);
2020-04-13 12:24:26 +02:00
/**
2020-05-05 17:40:36 +02:00
* @brief on_PieceSelectionChanged When the piece selection has changed
*/
2020-05-05 17:40:36 +02:00
void on_PieceSelectionChanged();
2020-11-14 10:20:02 +01:00
/**
2020-11-14 10:55:57 +01:00
* @brief on_ScaleChanged When the scale of the graphic view is changed
2020-11-14 10:20:02 +01:00
*/
void on_ScaleChanged(qreal scale);
2020-11-14 10:55:57 +01:00
/**
* @brief mouseMove save mouse position and show user.
* @param scenePos position mouse.
*/
void on_MouseMoved(const QPointF &scenePos);
2021-05-21 19:51:46 +02:00
void on_actionPreferences_triggered();
void ShowWindow() const;
2021-05-21 19:51:46 +02:00
void ToolBarStyles();
2021-05-27 20:11:32 +02:00
void on_actionAddSheet_triggered();
2021-08-25 15:58:50 +02:00
void on_ApplyPieceTransformation();
void on_ResetPieceTransformationSettings();
void on_RelativeTranslationChanged(bool checked);
void on_ConvertPaperSize();
2021-09-06 14:31:19 +02:00
void on_ExportLayout();
void on_ExportSheet();
void on_actionPrintLayout_triggered();
void on_actionPrintPreviewLayout_triggered();
void on_actionPrintTiledLayout_triggered();
void on_actionPrintPreviewTiledLayout_triggered();
2021-09-13 16:27:46 +02:00
void on_printLayoutSheets(QPrinter *printer);
void on_printLayoutTiledPages(QPrinter *printer);
2021-09-06 14:31:19 +02:00
void on_actionPrintSheet_triggered();
void on_actionPrintPreviewSheet_triggered();
void on_actionPrintTiledSheet_triggered();
void on_actionPrintPreviewTiledSheet_triggered();
2021-09-13 16:27:46 +02:00
void on_printLayoutSheet(QPrinter *printer);
void on_printLayoutSheetTiledPages(QPrinter *printer);
2021-09-11 18:39:38 +02:00
void CreateWatermark();
void EditCurrentWatermark();
void LoadWatermark();
void RemoveWatermark();
#if defined(Q_OS_MAC)
void AboutToShowDockMenu();
#endif // defined(Q_OS_MAC)
2023-06-27 13:15:21 +02:00
void AskDefaultSettings();
2022-08-12 17:50:13 +02:00
void HorizontalScaleChanged(double value);
void VerticalScaleChanged(double value);
2024-04-08 15:26:09 +02:00
void LayoutWarningPieceGapePosition_toggled(bool checked);
2022-08-12 17:50:13 +02:00
void LayoutWarningPiecesSuperposition_toggled(bool checked);
void LayoutWarningPiecesOutOfBound_toggled(bool checked);
2024-01-06 13:20:56 +01:00
void LayoutCutOnFold_toggled(bool checked);
2022-08-12 17:50:13 +02:00
2023-10-23 15:57:22 +02:00
void UpdateShortcuts();
void TogetherWithNotchesChanged(bool checked);
2024-04-06 11:09:38 +02:00
void CurrentPieceShowSeamLineToggled(bool checked);
void ShowFullPieceToggled(bool checked);
void ShowMirrorLineToggled(bool checked);
void CurrentPieceVerticallyFlippedToggled(bool checked);
void CurrentPieceHorizontallyFlippedToggled(bool checked);
private:
2022-08-12 17:50:13 +02:00
Q_DISABLE_COPY_MOVE(VPMainWindow) // NOLINT
std::unique_ptr<Ui::VPMainWindow> ui;
std::unique_ptr<VPCarrousel> m_carrousel{nullptr};
VPMainGraphicsView *m_graphicsView{nullptr};
VPCommandLinePtr m_cmd;
2021-08-17 17:49:28 +02:00
QUndoStack *m_undoStack;
VPLayoutPtr m_layout;
/**
* @brief spin box with the scale factor of the graphic view
*/
QPointer<QDoubleSpinBox> m_doubleSpinBoxScale{nullptr};
/**
* @brief mouseCoordinate pointer to label who show mouse coordinate.
*/
QLabel *m_mouseCoordinate{nullptr};
QLabel *m_statusLabel{nullptr};
2021-05-21 11:03:26 +02:00
QString curFile{};
bool isInitialized{false};
2021-05-21 16:17:22 +02:00
QSharedPointer<VLockGuard<char>> lock{nullptr};
2021-08-14 16:16:52 +02:00
QFileSystemWatcher *m_layoutWatcher;
2021-08-17 17:49:28 +02:00
QAction *undoAction{nullptr};
QAction *redoAction{nullptr};
2021-08-25 15:58:50 +02:00
Unit m_oldPieceTranslationUnit{Unit::Mm};
Unit m_oldLayoutUnit{Unit::Mm};
2021-09-06 15:56:56 +02:00
bool m_scaleConnected{true};
2021-09-11 18:39:38 +02:00
QList<QPointer<WatermarkWindow>> m_watermarkEditors{};
QFileSystemWatcher *m_watermarkWatcher{nullptr};
2023-10-23 15:57:22 +02:00
QMultiHash<VShortcutAction, QAction *> m_actionShortcuts{};
2022-08-12 17:50:13 +02:00
struct VPLayoutPrinterPage
{
VPSheetPtr sheet{};
bool tilesScheme{false};
int tileRow{-1};
int tileCol{-1};
2022-08-12 17:50:13 +02:00
};
/**
* @brief InitMenuBar Inits the menu bar (File, Edit, Help ...)
*/
void SetupMenu();
/**
* @brief InitProperties Init the properties
*/
void InitProperties();
/**
* @brief InitPropertyTabCurrentPiece Inits the current piece tab in the properties
*/
void InitPropertyTabCurrentPiece();
/**
* @brief InitPropertyTabCurrentSheet Inits the current sheet tab in the properties;
*/
void InitPropertyTabCurrentSheet();
2022-08-12 17:50:13 +02:00
void InitPaperSizeData(const QString &suffix);
void InitMarginsData(const QString &suffix);
/**
* @brief InitPropertyTabLayout Inits the layout tab in the properties
*/
void InitPropertyTabLayout();
/**
* @brief InitPropertyTabTiles Inits the tiles tab in the properties
*/
void InitPropertyTabTiles();
/**
* @brief InitCarrousel Inits the carrousel
*/
void InitCarrousel();
/**
* @brief InitMainGraphics Initialises the puzzle main graphics
*/
void InitMainGraphics();
/**
* @brief InitToolBar Initialises the tool bar
*/
void InitZoomToolBar();
/**
* @brief InitScaleToolBar Initialises the scale tool bar
*/
void InitScaleToolBar();
/**
* @brief SetPropertiesData Sets the values of UI elements
* in all the property tabs to the values saved in m_layout
*/
void SetPropertiesData();
/**
* @brief SetPropertyTabCurrentPieceData Sets the values of UI elements
* in the Current Piece Tab to the values saved in m_layout
*/
void SetPropertyTabCurrentPieceData();
/**
* @brief SetPropertyTabSheetData Sets the values of UI elements
* in the Sheet Tab to the values saved in focused sheet
*/
void SetPropertyTabSheetData();
/**
* @brief SetPropertyTabTilesData Sets the values of UI elements
* in the Tiles Tab to the values saved in m_layout
*/
void SetPropertyTabTilesData();
/**
* @brief SetPropertyTabLayoutData Sets the values of UI elements
* in the Layout Tab to the values saved in m_layout
*/
void SetPropertyTabLayoutData();
void ReadSettings();
void WriteSettings();
2021-08-14 15:00:42 +02:00
auto MaybeSave() -> bool;
void CreateWindowMenu(QMenu *menu);
2021-05-27 20:11:32 +02:00
2021-08-14 16:16:52 +02:00
auto IsLayoutReadOnly() const -> bool;
2021-08-21 15:13:56 +02:00
void ConnectToPreferences(const QSharedPointer<DialogPuzzlePreferences> &preferences);
2021-08-25 15:58:50 +02:00
auto SelectedPieces() const -> QList<VPPiecePtr>;
auto TranslateUnit() const -> Unit;
auto LayoutUnit() const -> Unit;
2022-08-12 17:50:13 +02:00
auto Template(VAbstractLayoutDialog::PaperSizeTemplate t) const -> QSizeF;
auto SheetTemplate() const -> QSizeF;
auto TileTemplate() const -> QSizeF;
2021-08-25 15:58:50 +02:00
void SheetSize(const QSizeF &size);
void TileSize(const QSizeF &size);
void CorrectPaperDecimals();
void SheetPaperSizeChanged();
void TilePaperSizeChanged();
void MinimumSheetPaperSize();
void MinimumTilePaperSize();
void FindTemplate(QComboBox *box, qreal width, qreal height);
void FindSheetTemplate();
void FindTileTemplate();
void CorrectTileMaxMargins();
void CorrectSheetMaxMargins();
void CorrectMaxMargins();
2021-08-26 18:04:24 +02:00
void RotatePiecesToGrainline();
2021-09-06 14:31:19 +02:00
void ExportData(const VPExportData &data);
2022-08-12 17:50:13 +02:00
static void ExportApparelLayout(const VPExportData &data, const QVector<VLayoutPiece> &details, const QString &name,
const QSize &size);
2021-09-06 14:31:19 +02:00
void ExportFlatLayout(const VPExportData &data);
void ExportScene(const VPExportData &data);
2022-08-12 17:50:13 +02:00
static void ExportUnifiedPdfFile(const VPExportData &data);
static void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name);
2021-09-06 14:31:19 +02:00
void ExportPdfTiledFile(const VPExportData &data);
2023-06-22 17:30:43 +02:00
auto GeneratePdfTiledFile(const VPSheetPtr &sheet, const VPExportData &data, QPainter *painter,
const QSharedPointer<QPrinter> &printer, bool &firstPage) -> bool;
2021-09-06 15:56:56 +02:00
void UpdateScaleConnection() const;
2021-09-11 18:39:38 +02:00
void OpenWatermark(const QString &path = QString());
void CleanWaterkmarkEditors();
2021-09-13 16:27:46 +02:00
2022-08-12 17:50:13 +02:00
auto DrawTilesScheme(QPrinter *printer, QPainter *painter, const VPSheetPtr &sheet, bool firstPage) -> bool;
2021-09-13 16:27:46 +02:00
auto AskLayoutIsInvalid(const QList<VPSheetPtr> &sheets) -> bool;
2022-08-12 17:50:13 +02:00
auto CheckPiecesOutOfBound(const VPPiecePtr &piece, bool &outOfBoundChecked) -> bool;
auto CheckSuperpositionOfPieces(const VPPiecePtr &piece, bool &pieceSuperpositionChecked) -> bool;
2024-04-08 15:26:09 +02:00
auto CheckPieceGapePosition(const VPPiecePtr &piece, bool &pieceGapePositionChecked) -> bool;
2021-09-13 16:27:46 +02:00
void PrintLayoutSheets(QPrinter *printer, const QList<VPSheetPtr> &sheets);
static auto PrintLayoutSheetPage(QPrinter *printer, QPainter &painter, const VPSheetPtr &sheet) -> bool;
2021-09-13 16:27:46 +02:00
void PrintLayoutTiledSheets(QPrinter *printer, const QList<VPSheetPtr> &sheets);
2022-08-12 17:50:13 +02:00
auto PrepareLayoutTilePages(const QList<VPSheetPtr> &sheets) -> QVector<VPLayoutPrinterPage>;
auto PrintLayoutTiledSheetPage(QPrinter *printer, QPainter &painter, const VPLayoutPrinterPage &page,
bool firstPage) -> bool;
2022-02-18 16:57:41 +01:00
void ZValueMove(int move);
2022-08-12 17:50:13 +02:00
auto ImportRawLayout(const QString &rawLayout) -> bool;
auto AddLayoutPieces(const QVector<VLayoutPiece> &pieces) -> bool;
void TranslatePieces();
void TranslatePieceRelatively(const VPPiecePtr &piece, const QRectF &rect, vsizetype selectedPiecesCount, qreal dx,
2022-08-12 17:50:13 +02:00
qreal dy);
void RotatePieces();
void InitIcons();
2020-02-16 17:17:50 +01:00
};
2020-05-23 14:17:20 +02:00
#endif // VPMAINWINDOW_H