valentina/src/app/puzzle/vpmainwindow.h

485 lines
14 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 <QMainWindow>
2020-04-10 21:08:29 +02:00
#include <QMessageBox>
2020-04-19 11:58:43 +02:00
#include <QDoubleSpinBox>
2020-11-14 10:55:57 +01:00
#include <QPointer>
#include "../vmisc/def.h"
2021-08-09 14:09:10 +02:00
#include "carousel/vpcarrousel.h"
#include "scene/vpmaingraphicsview.h"
#include "layout/vplayout.h"
#include "layout/vppiece.h"
2020-04-26 12:09:28 +02:00
#include "../vlayout/vlayoutpiece.h"
#include "vptilefactory.h"
2020-05-23 14:48:31 +02:00
#include "vpcommandline.h"
2020-11-14 12:37:43 +01:00
#include "../vlayout/vlayoutdef.h"
#include "../vwidgets/vabstractmainwindow.h"
2021-05-21 16:17:22 +02:00
#include "../vmisc/vlockguard.h"
2021-08-25 15:58:50 +02:00
#include "../vlayout/dialogs/vabstractlayoutdialog.h"
2020-02-16 17:17:50 +01:00
namespace Ui
{
2020-05-23 14:17:20 +02:00
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
{
Q_OBJECT
public:
2020-05-23 14:48:31 +02:00
explicit VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent = nullptr);
2020-05-23 14:17:20 +02:00
virtual ~VPMainWindow();
2020-02-16 17:17:50 +01:00
2021-05-21 17:08:37 +02:00
QString CurrentFile() const;
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
*/
bool LoadFile(QString path);
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
*/
2021-05-21 16:17:22 +02:00
bool SaveLayout(const QString &path, QString &error);
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();
2021-05-21 11:03:26 +02:00
virtual void ShowToolTip(const QString &toolTip) override;
2020-04-19 16:01:46 +02:00
protected:
virtual void closeEvent(QCloseEvent *event) override;
virtual void changeEvent(QEvent* event) override;
virtual QStringList RecentFileList() const 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.
*/
2021-05-21 16:17:22 +02:00
bool on_actionSave_triggered();
/**
* @brief on_actionSaveAs_triggered When the menu action File > Save As
* is triggered.
* The slot is automatically connected through name convention.
*/
2021-05-21 16:17:22 +02:00
bool on_actionSaveAs_triggered();
/**
* @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)
void SetDefaultGUILanguage();
private:
Q_DISABLE_COPY(VPMainWindow)
Ui::VPMainWindow *ui;
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};
2021-05-21 11:03:26 +02:00
QLabel* m_statusLabel{nullptr};
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};
/**
* @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();
/**
* @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;
QSizeF Template(VAbstractLayoutDialog::PaperSizeTemplate t) const;
QSizeF SheetTemplate() const;
QSizeF TileTemplate() const;
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);
void ExportApparelLayout(const VPExportData &data, const QVector<VLayoutPiece> &details, const QString &name,
const QSize &size) const;
void ExportFlatLayout(const VPExportData &data);
void ExportScene(const VPExportData &data);
void ExportUnifiedPdfFile(const VPExportData &data);
void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name);
void ExportPdfTiledFile(const VPExportData &data);
2021-09-13 16:27:46 +02:00
void GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter,
const QSharedPointer<QPrinter> &printer, bool &firstPage);
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
void DrawTilesScheme(QPrinter *printer, QPainter *painter, const VPSheetPtr &sheet, bool &firstPage);
auto AskLayoutIsInvalid(const QList<VPSheetPtr> &sheets) -> bool;
void PrintLayoutSheets(QPrinter *printer, const QList<VPSheetPtr> &sheets);
void PrintLayoutTiledSheets(QPrinter *printer, const QList<VPSheetPtr> &sheets);
2020-02-16 17:17:50 +01:00
};
2020-05-23 14:17:20 +02:00
#endif // VPMAINWINDOW_H