diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index c6a0ccadb..4cd78670e 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -14,7 +14,9 @@ SOURCES += \ $$PWD/vpuzzlepiece.cpp \ $$PWD/xml/layoutliterals.cpp \ $$PWD/xml/vpuzzlelayoutfilewriter.cpp \ - $$PWD/xml/vpuzzlelayoutfilereader.cpp + $$PWD/xml/vpuzzlelayoutfilereader.cpp \ + $$PWD/vpiececarrousellayer.cpp \ + $$PWD/vpiececarrouselpiece.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -31,7 +33,9 @@ HEADERS += \ $$PWD/vpuzzlepiece.h \ $$PWD/xml/layoutliterals.h \ $$PWD/xml/vpuzzlelayoutfilewriter.h \ - $$PWD/xml/vpuzzlelayoutfilereader.h + $$PWD/xml/vpuzzlelayoutfilereader.h \ + $$PWD/vpiececarrousellayer.h \ + $$PWD/vpiececarrouselpiece.h FORMS += \ $$PWD/puzzlemainwindow.ui \ diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index 3452a8b70..8f8252a76 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -53,22 +53,24 @@ QT_WARNING_POP PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent) : QMainWindow(parent), ui(new Ui::PuzzleMainWindow), - pieceCarrousel(new VPieceCarrousel), m_cmd(cmd) { - ui->setupUi(this); - InitMenuBar(); - InitProperties(); - InitPieceCarrousel(); + m_layout = new VPuzzleLayout(); // ----- for test purposes, to be removed------------------ - m_layout = new VPuzzleLayout(); m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25); m_layout->SetLayoutSizeConverted(30.0, 29.7); m_layout->SetPiecesGapConverted(1.27); m_layout->SetUnit(Unit::Cm); m_layout->SetWarningSuperpositionOfPieces(true); + // -------------------------------------------------------- + + ui->setupUi(this); + + InitMenuBar(); + InitProperties(); + InitPieceCarrousel(); SetPropertiesData(); } @@ -77,7 +79,7 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa PuzzleMainWindow::~PuzzleMainWindow() { delete ui; - delete pieceCarrousel; + delete m_pieceCarrousel; } //--------------------------------------------------------------------------------------------------------------------- @@ -127,21 +129,31 @@ bool PuzzleMainWindow::SaveFile(const QString &path) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::ImportRawLayouts(const QStringList &layouts) +void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) { - VRawLayout layoutReader; + VRawLayout rawLayoutReader; - for(auto &path : layouts) + for(auto &path : rawLayouts) { VRawLayoutData data; - if (layoutReader.ReadFile(path, data)) + if (rawLayoutReader.ReadFile(path, data)) { - // Do somethinmg with raw layout data + for (int i = 0; i < data.pieces.size(); ++i) + { + VLayoutPiece rawPiece = data.pieces.at(i); + + // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() + + VPuzzlePiece *piece = CreatePiece(rawPiece); + m_layout->GetUnplacedPiecesLayer()->AddPiece(piece); + } + + m_pieceCarrousel->Refresh(); } else { qCCritical(pWindow, "%s\n", qPrintable(tr("Could not extract data from file '%1'. %2") - .arg(path, layoutReader.ErrorString()))); + .arg(path, rawLayoutReader.ErrorString()))); if (m_cmd != nullptr && not m_cmd->IsGuiEnabled()) { m_cmd->ShowHelp(V_EX_DATAERR); @@ -150,15 +162,26 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &layouts) } } +//--------------------------------------------------------------------------------------------------------------------- +VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece) +{ + VPuzzlePiece *piece = new VPuzzlePiece(); + piece->SetName(rawPiece.GetName()); + piece->SetUuid(rawPiece.GetUUID()); + piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints()); + + // TODO : set all the information we need for the piece! + + return piece; +} + //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::InitMenuBar() { + // most of the actions are connected through name convention (auto-connection) + + // -------------------- connects the actions for the file menu - connect(ui->actionNew, &QAction::triggered, this, &PuzzleMainWindow::New); - connect(ui->actionOpen, &QAction::triggered, this, &PuzzleMainWindow::Open); - connect(ui->actionSave, &QAction::triggered, this, &PuzzleMainWindow::Save); - connect(ui->actionSaveAs, &QAction::triggered, this, &PuzzleMainWindow::SaveAs); - connect(ui->actionImportRawLayout, &QAction::triggered, this, &PuzzleMainWindow::ImportRawLayout); connect(ui->actionExit, &QAction::triggered, this, &PuzzleMainWindow::close); // -------------------- connects the actions for the edit menu @@ -166,16 +189,11 @@ void PuzzleMainWindow::InitMenuBar() // -------------------- connects the actions for the windows menu // TODO : initialise the entries for the different windows - connect(ui->actionCloseLayout, &QAction::triggered, this, &PuzzleMainWindow::CloseLayout); // Add dock properties action QAction* actionDockWidgetToolOptions = ui->dockWidgetProperties->toggleViewAction(); ui->menuWindows->addAction(actionDockWidgetToolOptions); - // connects the action for the Help Menu - connect(ui->actionAboutQt, &QAction::triggered, this, &PuzzleMainWindow::AboutQt); - connect(ui->actionAboutPuzzle, &QAction::triggered, this, &PuzzleMainWindow::AboutPuzzle); - } //--------------------------------------------------------------------------------------------------------------------- @@ -190,24 +208,12 @@ void PuzzleMainWindow::InitProperties() //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::InitPropertyTabCurrentPiece() { - // ------------------------------ seamline ------------------------------------ - connect(ui->checkBoxCurrentPieceShowSeamline, QOverload::of(&QCheckBox::toggled), this, - &PuzzleMainWindow::CurrentPieceShowSeamlineChanged); - - // ------------------------------ geometry ------------------------------------ - connect(ui->checkBoxCurrentPieceMirrorPiece, QOverload::of(&QCheckBox::toggled), this, - &PuzzleMainWindow::CurrentPieceMirrorPieceChanged); - - // ------------------------------ rotation ------------------------------------ - connect(ui->doubleSpinBoxCurrentPieceAngle, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::CurrentPieceAngleChanged); // ------------------------------ placement ----------------------------------- connect(ui->doubleSpinBoxCurrentPieceBoxPositionX, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::CurrentPiecePositionChanged); + &PuzzleMainWindow::on_CurrentPiecePositionChanged); connect(ui->doubleSpinBoxCurrentPieceBoxPositionY, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::CurrentPiecePositionChanged); - + &PuzzleMainWindow::on_CurrentPiecePositionChanged); } @@ -226,63 +232,41 @@ void PuzzleMainWindow::InitPropertyTabLayout() // ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); // } - connect(ui->comboBoxLayoutUnit, QOverload::of(&QComboBox::currentIndexChanged), this, - &PuzzleMainWindow::LayoutUnitChanged); - - - // -------------------- init the template combobox --------------------- - - // TODO - - connect(ui->comboBoxLayoutTemplate, QOverload::of(&QComboBox::currentIndexChanged), this, - &PuzzleMainWindow::LayoutTemplateChanged); + // some of the UI Elements are connected to the slots via auto-connect + // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect // -------------------- layout width, length, orientation ------------------------ connect(ui->doubleSpinBoxLayoutWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutSizeChanged); + &PuzzleMainWindow::on_LayoutSizeChanged); connect(ui->doubleSpinBoxLayoutLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutSizeChanged); + &PuzzleMainWindow::on_LayoutSizeChanged); connect(ui->radioButtonLayoutPortrait, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::LayoutOrientationChanged); + &PuzzleMainWindow::on_LayoutOrientationChanged); connect(ui->radioButtonLayoutLandscape, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::LayoutOrientationChanged); - connect(ui->pushButtonLayoutRemoveUnusedLength, QOverload::of(&QPushButton::clicked), this, - &PuzzleMainWindow::LayoutRemoveUnusedLength); + &PuzzleMainWindow::on_LayoutOrientationChanged); // -------------------- margins ------------------------ connect(ui->doubleSpinBoxLayoutMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutMarginChanged); + &PuzzleMainWindow::on_LayoutMarginChanged); connect(ui->doubleSpinBoxLayoutMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutMarginChanged); + &PuzzleMainWindow::on_LayoutMarginChanged); connect(ui->doubleSpinBoxLayoutMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutMarginChanged); + &PuzzleMainWindow::on_LayoutMarginChanged); connect(ui->doubleSpinBoxLayoutMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutMarginChanged); + &PuzzleMainWindow::on_LayoutMarginChanged); // ------------------- follow grainline ----------------------- connect(ui->radioButtonLayoutFollowGrainlineNo, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::LayoutFollowGrainlineChanged); + &PuzzleMainWindow::on_LayoutFollowGrainlineChanged); connect(ui->radioButtonLayoutFollowGrainlineVertical, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::LayoutFollowGrainlineChanged); + &PuzzleMainWindow::on_LayoutFollowGrainlineChanged); connect(ui->radioButtonLayoutFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::LayoutFollowGrainlineChanged); - - // -------------------- pieces gap and checkboxes --------------- - connect(ui->doubleSpinBoxLayoutPiecesGap, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::LayoutPiecesGapChanged); - connect(ui->checkBoxLayoutWarningPiecesSuperposition, QOverload::of(&QCheckBox::toggled), this, - &PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged); - connect(ui->checkBoxLayoutWarningPiecesOutOfBound, QOverload::of(&QCheckBox::toggled), this, - &PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged); - connect(ui->checkBoxLayoutStickyEdges, QOverload::of(&QCheckBox::toggled), this, - &PuzzleMainWindow::LayoutStickyEdgesChanged); + &PuzzleMainWindow::on_LayoutFollowGrainlineChanged); // -------------------- export --------------------------- // TODO init the file format export combobox - connect(ui->pushButtonLayoutExport, QOverload::of(&QPushButton::clicked), this, - &PuzzleMainWindow::LayoutExport); } //--------------------------------------------------------------------------------------------------------------------- @@ -304,10 +288,14 @@ void PuzzleMainWindow::InitPropertyTabLayers() //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::InitPieceCarrousel() { - ui->dockWidgetPieceCarrousel->setWidget(pieceCarrousel); + m_pieceCarrousel = new VPieceCarrousel(m_layout, ui->dockWidgetPieceCarrousel); + ui->dockWidgetPieceCarrousel->setWidget(m_pieceCarrousel); connect(ui->dockWidgetPieceCarrousel, QOverload::of(&QDockWidget::dockLocationChanged), this, - &PuzzleMainWindow::PieceCarrouselLocationChanged); + &PuzzleMainWindow::on_PieceCarrouselLocationChanged); + + connect(m_pieceCarrousel, QOverload::of(&VPieceCarrousel::pieceClicked), this, + &PuzzleMainWindow::on_PieceSelected); } @@ -339,11 +327,22 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData() else { // TODO : update current piece data to show a "no current piece selected" + ui->containerCurrentPieceNoData->setVisible(true); + ui->containerCurrentPieceData->setVisible(false); } } else { - // TODO set the values of the piece currently selected + ui->containerCurrentPieceNoData->setVisible(false); + ui->containerCurrentPieceData->setVisible(true); + + // set the value to the current piece + ui->lineEditCurrentPieceName->setText(m_selectedPiece->GetName()); + + ui->checkBoxCurrentPieceShowSeamline->setChecked(m_selectedPiece->GetShowSeamLine()); + ui->checkBoxCurrentPieceMirrorPiece->setChecked(m_selectedPiece->GetPieceMirrored()); + + // TODO:rotation and placement; } } @@ -422,7 +421,7 @@ void PuzzleMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value) //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::New() +void PuzzleMainWindow::on_actionNew_triggered() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -437,7 +436,7 @@ void PuzzleMainWindow::New() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::Open() +void PuzzleMainWindow::on_actionOpen_triggered() { qCDebug(pWindow, "Openning puzzle layout file."); @@ -491,7 +490,7 @@ void PuzzleMainWindow::Open() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::Save() +void PuzzleMainWindow::on_actionSave_triggered() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -504,7 +503,7 @@ void PuzzleMainWindow::Save() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SaveAs() +void PuzzleMainWindow::on_actionSaveAs_triggered() { // TODO / FIXME : See valentina how the save is done over there. we need to add the extension .vlt, check for empty file names etc. @@ -534,20 +533,36 @@ void PuzzleMainWindow::SaveAs() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::ImportRawLayout() +void PuzzleMainWindow::on_actionImportRawLayout_triggered() { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::ImportRawLayout"); - int ret = msgBox.exec(); + // TODO: here the code is probably just bad, to be edited - Q_UNUSED(ret); + QString dir; + if (true) + { + dir = QDir::homePath(); + } + else + { + // TODO / FIXME get the default path for raw layouts + } + + const QString filter(tr("Raw Layout files") + QLatin1String(" (*.rld)")); + + qCDebug(pWindow, "Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir)); + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr); + + QStringList rawLayouts = QStringList(); + rawLayouts.append(filePath); + + ImportRawLayouts(rawLayouts); + + // TODO / FIXME : better error handling - // TODO } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::CloseLayout() +void PuzzleMainWindow::on_actionCloseLayout_triggered() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -560,13 +575,13 @@ void PuzzleMainWindow::CloseLayout() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::AboutQt() +void PuzzleMainWindow::on_actionAboutQt_triggered() { QMessageBox::aboutQt(this, tr("About Qt")); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::AboutPuzzle() +void PuzzleMainWindow::on_actionAboutPuzzle_triggered() { auto *aboutDialog = new DialogAboutPuzzle(this); aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true); @@ -574,7 +589,7 @@ void PuzzleMainWindow::AboutPuzzle() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutUnitChanged(int index) +void PuzzleMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) { Q_UNUSED(index); QVariant comboBoxValue = ui->comboBoxLayoutUnit->currentData(); @@ -597,7 +612,7 @@ void PuzzleMainWindow::LayoutUnitChanged(int index) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutTemplateChanged(int index) +void PuzzleMainWindow::on_comboBoxLayoutTemplate_currentIndexChanged(int index) { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -612,7 +627,7 @@ void PuzzleMainWindow::LayoutTemplateChanged(int index) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutSizeChanged() +void PuzzleMainWindow::on_LayoutSizeChanged() { m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value()); @@ -633,7 +648,7 @@ void PuzzleMainWindow::LayoutSizeChanged() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutOrientationChanged() +void PuzzleMainWindow::on_LayoutOrientationChanged() { // swap the width and length qreal width_before = ui->doubleSpinBoxLayoutWidth->value(); @@ -647,7 +662,7 @@ void PuzzleMainWindow::LayoutOrientationChanged() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutRemoveUnusedLength() +void PuzzleMainWindow::on_pushButtonLayoutRemoveUnusedLength_clicked() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -661,7 +676,7 @@ void PuzzleMainWindow::LayoutRemoveUnusedLength() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutMarginChanged() +void PuzzleMainWindow::on_LayoutMarginChanged() { m_layout->SetLayoutMarginsConverted( ui->doubleSpinBoxLayoutMarginLeft->value(), @@ -676,7 +691,7 @@ void PuzzleMainWindow::LayoutMarginChanged() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutFollowGrainlineChanged() +void PuzzleMainWindow::on_LayoutFollowGrainlineChanged() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -690,7 +705,7 @@ void PuzzleMainWindow::LayoutFollowGrainlineChanged() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutPiecesGapChanged(double value) +void PuzzleMainWindow::on_doubleSpinBoxLayoutPiecesGap_valueChanged(double value) { m_layout->SetPiecesGapConverted(value); @@ -699,7 +714,7 @@ void PuzzleMainWindow::LayoutPiecesGapChanged(double value) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged(bool checked) +void PuzzleMainWindow::on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool checked) { m_layout->SetWarningSuperpositionOfPieces(checked); @@ -708,7 +723,7 @@ void PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged(bool checked) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged(bool checked) +void PuzzleMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked) { m_layout->SetWarningPiecesOutOfBound(checked); @@ -717,7 +732,7 @@ void PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged(bool checked) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutStickyEdgesChanged(bool checked) +void PuzzleMainWindow::on_checkBoxLayoutStickyEdges_toggled(bool checked) { m_layout->SetStickyEdges(checked); @@ -728,7 +743,7 @@ void PuzzleMainWindow::LayoutStickyEdgesChanged(bool checked) //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::LayoutExport() +void PuzzleMainWindow::on_pushButtonLayoutExport_clicked() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -742,35 +757,25 @@ void PuzzleMainWindow::LayoutExport() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::CurrentPieceShowSeamlineChanged(bool checked) +void PuzzleMainWindow::on_checkBoxCurrentPieceShowSeamline_toggled(bool checked) { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::CurrentPieceShowSeamlineChanged"); - int ret = msgBox.exec(); - - Q_UNUSED(checked); - Q_UNUSED(ret); - - // TODO + if(m_selectedPiece != nullptr) + { + m_selectedPiece->SetShowSeamLine(checked); + } } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::CurrentPieceMirrorPieceChanged(bool checked) +void PuzzleMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked) { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::CurrentPieceMirrorPieceChanged"); - int ret = msgBox.exec(); - - Q_UNUSED(checked); - Q_UNUSED(ret); - - // TODO + if(m_selectedPiece != nullptr) + { + m_selectedPiece->SetPieceMirrored(checked); + } } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::CurrentPieceAngleChanged(double value) +void PuzzleMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value) { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -785,7 +790,7 @@ void PuzzleMainWindow::CurrentPieceAngleChanged(double value) //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::CurrentPiecePositionChanged() +void PuzzleMainWindow::on_CurrentPiecePositionChanged() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -798,19 +803,34 @@ void PuzzleMainWindow::CurrentPiecePositionChanged() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::PieceCarrouselLocationChanged(Qt::DockWidgetArea area) +void PuzzleMainWindow::on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area) { if(area == Qt::BottomDockWidgetArea || area == Qt::TopDockWidgetArea) { - pieceCarrousel->setOrientation(Qt::Horizontal); + m_pieceCarrousel->SetOrientation(Qt::Horizontal); ui->dockWidgetPieceCarrousel->setMaximumHeight(208); ui->dockWidgetPieceCarrousel->setMaximumWidth(10000); } else if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea) { - pieceCarrousel->setOrientation(Qt::Vertical); + m_pieceCarrousel->SetOrientation(Qt::Vertical); ui->dockWidgetPieceCarrousel->setMaximumHeight(10000); ui->dockWidgetPieceCarrousel->setMaximumWidth(160); } } +//--------------------------------------------------------------------------------------------------------------------- +void PuzzleMainWindow::on_PieceSelected(VPuzzlePiece* piece) +{ + m_selectedPiece = piece; + + // update the state of the piece carrousel + m_pieceCarrousel->SelectPiece(piece); + + // update the Layout + + // TODO + + // update the property of the piece currently selected + SetPropertyTabCurrentPieceData(); +} diff --git a/src/app/puzzle/puzzlemainwindow.h b/src/app/puzzle/puzzlemainwindow.h index 7b2456a10..eb8dde989 100644 --- a/src/app/puzzle/puzzlemainwindow.h +++ b/src/app/puzzle/puzzlemainwindow.h @@ -36,6 +36,7 @@ #include "vpiececarrousel.h" #include "vpuzzlelayout.h" #include "vpuzzlepiece.h" +#include "../vlayout/vlayoutpiece.h" #include "vpuzzlecommandline.h" namespace Ui @@ -66,10 +67,18 @@ public: */ bool SaveFile(const QString &path); - void ImportRawLayouts(const QStringList &layouts); + /** + * @brief ImportRawLayouts The function imports the raw layouts of given paths + * @param rawLayouts paths of the layouts to import + */ + void ImportRawLayouts(const QStringList &rawLayouts); public slots: - void New(); + /** + * @brief on_actionNew_triggered When the menu action File > New + * is triggered + */ + void on_actionNew_triggered(); protected: enum { MaxRecentFiles = 5 }; @@ -77,20 +86,52 @@ protected: private: Q_DISABLE_COPY(PuzzleMainWindow) Ui::PuzzleMainWindow *ui; - VPieceCarrousel *pieceCarrousel; + VPieceCarrousel *m_pieceCarrousel{nullptr}; VPuzzleCommandLinePtr m_cmd; VPuzzleLayout *m_layout{nullptr}; VPuzzlePiece *m_selectedPiece{nullptr}; + /** + * @brief CreatePiece creates a piece from the given VLayoutPiece data + * @param rawPiece the raw piece data + */ + VPuzzlePiece* CreatePiece(const VLayoutPiece &rawPiece); + /** + * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...) + */ void InitMenuBar(); + + /** + * @brief InitProperties Init the properties + */ void InitProperties(); + + /** + * @brief InitPropertyTabCurrentPiece Inits the current piece tab in the properties + */ void InitPropertyTabCurrentPiece(); + + /** + * @brief InitPropertyTabLayout Inits the layout tab in the properties + */ void InitPropertyTabLayout(); + + /** + * @brief InitPropertyTabTiles Inits the tiles tab in the properties + */ void InitPropertyTabTiles(); + + /** + * @brief InitPropertyTabLayers Inits the layers tab in the properties + */ void InitPropertyTabLayers(); + + /** + * @brief InitPieceCarrousel Inits the piece carrousel + */ void InitPieceCarrousel(); @@ -141,34 +182,185 @@ private: void SetCheckBoxValue(QCheckBox *checkbox, bool value); private slots: - void Open(); - void Save(); - void SaveAs(); - void ImportRawLayout(); - void CloseLayout(); + /** + * @brief on_actionOpen_triggered When the menu action File > Open is + * triggered. + * The slot is automatically connected through name convention. + */ + void on_actionOpen_triggered(); - void AboutQt(); - void AboutPuzzle(); + /** + * @brief on_actionSave_triggered When the menu action File > Save is + * triggered. + * The slot is automatically connected through name convention. + */ + void on_actionSave_triggered(); - void LayoutUnitChanged(int index); - void LayoutTemplateChanged(int index); - void LayoutSizeChanged(); - void LayoutOrientationChanged(); - void LayoutRemoveUnusedLength(); - void LayoutMarginChanged(); - void LayoutFollowGrainlineChanged(); - void LayoutPiecesGapChanged(double value); - void LayoutWarningPiecesSuperpositionChanged(bool checked); - void LayoutWarningPiecesOutOfBoundChanged(bool checked); - void LayoutStickyEdgesChanged(bool checked); - void LayoutExport(); + /** + * @brief on_actionSaveAs_triggered When the menu action File > Save As + * is triggered. + * The slot is automatically connected through name convention. + */ + void on_actionSaveAs_triggered(); - void CurrentPieceShowSeamlineChanged(bool checked); - void CurrentPieceMirrorPieceChanged(bool checked); - void CurrentPieceAngleChanged(double value); - void CurrentPiecePositionChanged(); + /** + * @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(); - void PieceCarrouselLocationChanged(Qt::DockWidgetArea area); + /** + * @brief on_actionCloseLayout_triggered When the menu action + * File > Close Layout is triggered. + * The slot is automatically connected through name convention. + */ + void on_actionCloseLayout_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(); + + /** + * @brief on_comboBoxLayoutUnit_currentIndexChanged 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 + */ + void on_comboBoxLayoutUnit_currentIndexChanged(int index); + + /** + * @brief on_comboBoxLayoutTemplate_currentIndexChanged When the template is + * changed in the layout property tab. + * The slot is automatically connected through name convention. + * @param index the index of the selected templated + */ + void on_comboBoxLayoutTemplate_currentIndexChanged(int index); + + /** + * @brief LayoutSizeChanged When the width or the length has been changed in + * the layout property tab + */ + void on_LayoutSizeChanged(); + + /** + * @brief LayoutOrientationChanged When one of the radio boxes for the layout + * orientation has been clicked + */ + void on_LayoutOrientationChanged(); + + /** + * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button + * "Remove unused length" in the layout property tab is clicked. + * The slot is automatically connected through name convention. + */ + void on_pushButtonLayoutRemoveUnusedLength_clicked(); + + /** + * @brief on_LayoutMarginChanged When one of the margin values has been changed + * in the layout property tab. + */ + void on_LayoutMarginChanged(); + + /** + * @brief LayoutFollowGrainlineChanged When one of the radio boxes for the + * "Follow grainline" has been clicked in the layout property tab. + */ + void on_LayoutFollowGrainlineChanged(); + + /** + * @brief on_doubleSpinBoxLayoutPiecesGap_valueChanged When the "pieces gap" + * value is changed in the layout property tab. + * The slot is automatically connected through name convention. + * @param value the new value of the pieces gap + */ + void on_doubleSpinBoxLayoutPiecesGap_valueChanged(double value); + + /** + * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the + * "Warning when pieces superposition" checkbox value in the layout + * property tab is toggled. + * The slot is automatically connected through name convention. + * @param checked the new checked value + */ + void on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool checked); + + /** + * @brief on_checkBoxLayoutWarningPiecesOutOfBound_toggled When the + * "Warning when pieces out of bound" checkbox value in the layout property + * tab is toggled. + * The slot is automatically connected through name convention. + * @param checked the new checked value + */ + void on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked); + + /** + * @brief on_checkBoxLayoutStickyEdges_toggled When the "Sticky edges" + * checkbox value in the layout property tab is toggled. + * The slot is automatically connected through name convention. + * @param checked the new checked value + */ + void on_checkBoxLayoutStickyEdges_toggled(bool checked); + + /** + * @brief on_pushButtonLayoutExport_clicked When the button + * "Export layout" in the layout property is clicked. + * The slot is automatically connected through name convention. + */ + void on_pushButtonLayoutExport_clicked(); + + /** + * @brief on_checkBoxCurrentPieceShowSeamline_toggled When the + * "Show seamline" checkbox value in the current piece tab is toggled. + * The slot is automatically connected through name convention. + * @param checked the new checked value + */ + void on_checkBoxCurrentPieceShowSeamline_toggled(bool checked); + + /** + * @brief on_checkBoxCurrentPieceMirrorPiece_toggled When the + * "Mirror piece" checkbox in the current piece tab is toggled. + * The slot is automatically connected through name convention. + * @param checked the new checked value + */ + void on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked); + + /** + * @brief on_doubleSpinBoxCurrentPieceAngle_valueChanged When the + * "Current Piece Angle" value in the current piece property is changed + * The slot is automatically connected through name convention. + * @param value the new angle value + */ + void on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value); + + /** + * @brief on_CurrentPiecePositionChanged When the positionX or the positionY + * is changed in the current piece tab + */ + void on_CurrentPiecePositionChanged(); + + /** + * @brief PieceCarrouselLocationChanged When the piece carrousel's location + * has been changed + * @param area The new area where the piece carrousel has been placed + */ + void on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area); + + /** + * @brief on_PieceSelected When a piece has been selected + * @param piece the piece that was selected + */ + void on_PieceSelected(VPuzzlePiece* piece); }; diff --git a/src/app/puzzle/puzzlemainwindow.ui b/src/app/puzzle/puzzlemainwindow.ui index d8516accc..5f63f8644 100644 --- a/src/app/puzzle/puzzlemainwindow.ui +++ b/src/app/puzzle/puzzlemainwindow.ui @@ -94,8 +94,8 @@ - 160 - 208 + 24 + 37 @@ -126,7 +126,11 @@ 0 - + + + 0 + + @@ -171,7 +175,7 @@ QTabWidget::Rounded - 1 + 0 @@ -228,8 +232,8 @@ 0 0 - 170 - 452 + 342 + 894 @@ -250,44 +254,24 @@ - - - Infos - - - - - - DummyName - - - true - - - - - - - Name: - - - - - - - - - - Seamline - - + + + + 0 + - - - Show Seamline + + + + 0 + 400 + - - true + + No piece selected + + + Qt::AlignCenter @@ -295,85 +279,136 @@ - - - Geometry - - + + - - - Mirror piece + + + Infos + + + + + DummyName + + + true + + + + + + + Name: + + + + - - - - - - - Rotation - - - - - - Angle: + + + + Seamline + + + + + Show Seamline + + + true + + + + - - - - 360.000000000000000 - - - 0.100000000000000 + + + + Geometry + + + + + Mirror piece + + + + - - - - - - - Placement - - - - - - X: + + + + Rotation + + + + + Angle: + + + + + + + 360.000000000000000 + + + 0.100000000000000 + + + + - - - - 10000.000000000000000 - - - 0.100000000000000 - - - - - - - Y: - - - - - - - 10000.000000000000000 - - - 0.100000000000000 + + + + Placement + + + + + X: + + + + + + + 10000.000000000000000 + + + 0.100000000000000 + + + + + + + Y: + + + + + + + 10000.000000000000000 + + + 0.100000000000000 + + + + @@ -858,8 +893,8 @@ 0 0 - 98 - 41 + 356 + 760 @@ -938,8 +973,8 @@ 0 0 - 98 - 41 + 356 + 760 diff --git a/src/app/puzzle/vpiececarrousel.cpp b/src/app/puzzle/vpiececarrousel.cpp index 02b85c0a1..06741ffb7 100644 --- a/src/app/puzzle/vpiececarrousel.cpp +++ b/src/app/puzzle/vpiececarrousel.cpp @@ -27,131 +27,218 @@ *************************************************************************/ #include "vpiececarrousel.h" #include -#include #include #include "../vmisc/backport/qoverload.h" +#include +#include + +Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel") + //--------------------------------------------------------------------------------------------------------------------- -VPieceCarrousel::VPieceCarrousel(QWidget *parent) : +VPieceCarrousel::VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent) : QWidget(parent), - comboBoxLayer(new QComboBox), - mainScrollArea(new QScrollArea(this)), - layers(QList()) + m_layout(layout), + m_comboBoxLayer(new QComboBox(this)), + m_scrollArea(new QScrollArea(this)), + m_layersContainer(new QWidget(this)), + m_carrouselLayers(QList()) { - - QVBoxLayout *mainLayout = new QVBoxLayout(); - setLayout(mainLayout); - - setMinimumSize(140,140); - - mainLayout->addWidget(comboBoxLayer); - comboBoxLayer->addItem(tr("Unplaced pieces")); - comboBoxLayer->addItem(tr("Layout")); - comboBoxLayer->setCurrentIndex(0); - connect(comboBoxLayer, QOverload::of(&QComboBox::currentIndexChanged), this, - &VPieceCarrousel::ActiveLayerChanged); - - QWidget *widget = new QWidget(); - QVBoxLayout *mainScrollAreaLayout = new QVBoxLayout(); - mainScrollAreaLayout->setMargin(0); - widget->setLayout(mainScrollAreaLayout); - mainScrollArea->setWidget(widget); - - mainLayout->addWidget(mainScrollArea); -// mainScrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - mainScrollArea->setWidgetResizable( true ); - - - // this code is for test purpuses, it needs to be updated when we have proper data! - - QWidget *unplacedPieces = new QWidget(); - QVBoxLayout *unplacedPiecesLayout = new QVBoxLayout(); - unplacedPiecesLayout->setMargin(0); - unplacedPieces->setLayout(unplacedPiecesLayout); - for(int i=0; i<=10; ++i) - { - QLabel *myLabel = new QLabel(); - myLabel->setText(QString ("Element A.%1").arg(i)); - myLabel->setFixedSize(120,120); - myLabel->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); - if(i%2 ==0) - { - myLabel->setStyleSheet("background-color:white"); - } - else { - myLabel->setStyleSheet("background-color:red"); - } - unplacedPiecesLayout->addWidget(myLabel); - } - mainScrollAreaLayout->addWidget(unplacedPieces); - layers.append(unplacedPieces); - - QWidget *layoutPieces = new QWidget(); - QVBoxLayout *layoutPiecesLayout = new QVBoxLayout(); - layoutPiecesLayout->setMargin(0); - layoutPieces->setLayout(layoutPiecesLayout); - for(int i=0; i<=5; ++i) - { - QLabel *myLabel = new QLabel(); - myLabel->setText(QString ("Element B.%1").arg(i)); - myLabel->setFixedSize(120,120); - myLabel->sizePolicy(); - myLabel->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); - myLabel->setStyleSheet("background-color:cornflowerblue"); - layoutPiecesLayout->addWidget(myLabel); - } - mainScrollAreaLayout->addWidget(layoutPieces); - layers.append(layoutPieces); - - QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding); - mainScrollAreaLayout->addSpacerItem(spacer); - - // -------------------- init the layers combobox --------------------- - ActiveLayerChanged(0); + Init(); } //--------------------------------------------------------------------------------------------------------------------- VPieceCarrousel::~VPieceCarrousel() { - delete comboBoxLayer; - delete mainScrollArea; + delete m_comboBoxLayer; + delete m_layersContainer; } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::ActiveLayerChanged(int index) +void VPieceCarrousel::Init() { + // ------ first we initialize the structure of the carrousel + + // init the combo box + connect(m_comboBoxLayer, QOverload::of(&QComboBox::currentIndexChanged), this, + &VPieceCarrousel::on_ActiveLayerChanged); + + // init the layers container and corresponding scroll area + QWidget *layersContainerWrapper = new QWidget(); + + QVBoxLayout *layersContainerWrapperLayout = new QVBoxLayout(); + layersContainerWrapperLayout->setMargin(0); + layersContainerWrapper->setLayout(layersContainerWrapperLayout); + + QVBoxLayout *layersContainerLayout = new QVBoxLayout(); + layersContainerLayout->setMargin(0); + m_layersContainer->setLayout(layersContainerLayout); + QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding); + + layersContainerWrapperLayout->addWidget(m_layersContainer); + layersContainerWrapperLayout->addSpacerItem(spacer); + + m_scrollArea->setWidgetResizable( true ); + m_scrollArea->setWidget(layersContainerWrapper); + + // init the layout of the piece carrousel + QVBoxLayout *mainLayout = new QVBoxLayout(); + setLayout(mainLayout); + + mainLayout->addWidget(m_comboBoxLayer); + mainLayout->addWidget(m_scrollArea); + + // ------ then we fill the carrousel with the layout content + Refresh(); + + // ------ and make sure the calculation for the qlayout is right + SetOrientation(Qt::Vertical); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrousel::Refresh() +{ + + // NOTE: alternative to clearing the carrousel and adding things again, we could make comparision + + // --- clears the content of the carrousel + Clear(); + + // --- add the content saved in the layout to the carrousel. + QList layers = m_layout->GetLayers(); + layers.prepend(m_layout->GetUnplacedPiecesLayer()); + + for (auto layer : layers) + { + // add layer name to combo + m_comboBoxLayer->addItem(layer->GetName()); + + // add new carrousel layer + VPieceCarrouselLayer *carrouselLayer = new VPieceCarrouselLayer(layer, this); + m_carrouselLayers.append(carrouselLayer); + m_layersContainer->layout()->addWidget(carrouselLayer); + + connect(carrouselLayer, QOverload::of(&VPieceCarrouselLayer::pieceClicked), this, + &VPieceCarrousel::on_PieceClicked); + + } + + on_ActiveLayerChanged(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrousel::Clear() +{ + // remove the combobox entries + int layerCount = m_comboBoxLayer->count(); + for(int i=0;iremoveItem(0); + } + + // remove the carrousel layers from the qlayout + while(!m_layersContainer->layout()->isEmpty()) + { + QLayoutItem* item = m_layersContainer->layout()->takeAt(0); + if(item != nullptr) + { + delete item; + } + } + + // Removes and deletes the carrousel layers from the list + while (!m_carrouselLayers.isEmpty()) + { + VPieceCarrouselLayer *carrouselLayer = m_carrouselLayers.takeLast(); + if(carrouselLayer != nullptr) + { + delete carrouselLayer; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrousel::SelectPiece(VPuzzlePiece* piece) +{ + for (auto layer : m_carrouselLayers) + { + QList carrouselPieces = layer->GetCarrouselPieces(); + for (auto carrouselPiece : carrouselPieces) + { + carrouselPiece->SetIsSelected(carrouselPiece->GetPiece() == piece); + } + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrousel::on_ActiveLayerChanged(int index) +{ + qCDebug(pCarrousel, "index changed %i", index); + int j=0; - for (QWidget *widget: layers) { - widget->setVisible(j == index); + for (VPieceCarrouselLayer *carrouselLayer: m_carrouselLayers) { + carrouselLayer->setVisible(j == index); j++; } } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::setOrientation(Qt::Orientation orientation) +void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) { - QBoxLayout::Direction direction = QBoxLayout::LeftToRight; - if(orientation == Qt::Horizontal) - { - comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - } - else // Qt::Vertical - { - direction = QBoxLayout::TopToBottom; - comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - } + QBoxLayout::Direction direction = (orientation == Qt::Horizontal)? + QBoxLayout::LeftToRight + : + QBoxLayout::TopToBottom; - QBoxLayout* mainScrollAreaLayout = qobject_cast(mainScrollArea->widget()->layout()); + // Update the various qlayouts + QBoxLayout* mainScrollAreaLayout = qobject_cast(m_layersContainer->layout()); mainScrollAreaLayout->setDirection(direction); - for (QWidget *widget: layers) { + QBoxLayout* layerContainerWrapper = qobject_cast(m_scrollArea->widget()->layout()); + layerContainerWrapper->setDirection(direction); + + for (VPieceCarrouselLayer *widget: m_carrouselLayers) { QBoxLayout* layerLayout = qobject_cast(widget->layout()); layerLayout->setDirection(direction); } + + // then update the scrollarea min height / width and scrollbar behaviour + if(orientation == Qt::Horizontal) + { + m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + // scroll bar policy of scroll area + m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + + // FIXME: find a nicer way than putting directly the 120 height of the piece + m_scrollArea->setMinimumHeight(128 + m_scrollArea->horizontalScrollBar()->sizeHint().height()+2); + m_scrollArea->setMinimumWidth(0); + } + else // Qt::Vertical + { + m_comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + + + // scroll bar policy of scroll area + m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + + m_scrollArea->setMinimumHeight(0); + m_scrollArea->setMinimumWidth(124 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2); + // FIXME: find a nicer way than putting directly the 120 width of the piece + } + } +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrousel::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece) +{ + emit pieceClicked(carrouselPiece->GetPiece()); +} + + diff --git a/src/app/puzzle/vpiececarrousel.h b/src/app/puzzle/vpiececarrousel.h index 009d5348e..9e90c56d7 100644 --- a/src/app/puzzle/vpiececarrousel.h +++ b/src/app/puzzle/vpiececarrousel.h @@ -32,27 +32,62 @@ #include #include #include +#include "vpuzzlelayout.h" +#include "vpuzzlepiece.h" +#include "vpiececarrousellayer.h" class VPieceCarrousel : public QWidget { Q_OBJECT public: - explicit VPieceCarrousel(QWidget *parent = nullptr); + explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr); virtual ~VPieceCarrousel(); - void setOrientation(Qt::Orientation orientation); + void SetOrientation(Qt::Orientation orientation); + + /** + * @brief Inits the carroussel + */ + void Init(); + + /** + * @brief Refresh Refreshes the content of the carrousel + */ + void Refresh(); + + /** + * @brief Clear Clears the carrousel (removes everything) + */ + void Clear(); + + /** + * @brief SelectPiece Updates the carrousel so that the given piece is selected + * @param piece the piece to select + */ + void SelectPiece(VPuzzlePiece* piece); + + signals: + void pieceClicked(VPuzzlePiece* piece); public slots: + void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece); + private: Q_DISABLE_COPY(VPieceCarrousel) - QComboBox *comboBoxLayer; - QScrollArea *mainScrollArea; - QList layers; + + VPuzzleLayout *m_layout; + + QComboBox *m_comboBoxLayer; + QScrollArea *m_scrollArea; + QWidget *m_layersContainer; + + QList m_carrouselLayers; + private slots: - void ActiveLayerChanged(int index); + void on_ActiveLayerChanged(int index); }; #endif // VPIECECARROUSEL_H diff --git a/src/app/puzzle/vpiececarrousellayer.cpp b/src/app/puzzle/vpiececarrousellayer.cpp new file mode 100644 index 000000000..d00ed6ecb --- /dev/null +++ b/src/app/puzzle/vpiececarrousellayer.cpp @@ -0,0 +1,109 @@ +/************************************************************************ + ** + ** @file vpiececarrousellayer.cpp + ** @author Ronan Le Tiec + ** @date 25 4, 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 + ** 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 "vpiececarrousellayer.h" + +#include + +#include + +Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer") + +//--------------------------------------------------------------------------------------------------------------------- +VPieceCarrouselLayer::VPieceCarrouselLayer(VPuzzleLayer *layer, QWidget *parent) : + QWidget(parent), + m_layer(layer), + m_carrouselPieces(QList()) +{ + Init(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPieceCarrouselLayer::~VPieceCarrouselLayer() +{ + // TODO +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselLayer::Init() +{ + // initiales the structure + QVBoxLayout *layoutPiecesLayout = new QVBoxLayout(); + layoutPiecesLayout->setMargin(0); + setLayout(layoutPiecesLayout); + + // then refresh the content + Refresh(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselLayer::Refresh() +{ + // remove the existing carrousel pieces + // TODO + + // Updates the carrousel pieces from the pieces list + QList pieces = m_layer->GetPieces(); + + // sort the pieces in alphabetical order + std::sort(pieces.begin(), pieces.end(), + [](const VPuzzlePiece* a, const VPuzzlePiece* b) -> bool { return a->GetName() < b->GetName();}); + + // create the corresponding carrousel pieces + + for (auto piece : pieces) + { +// qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str()); + + VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece); + m_carrouselPieces.append(carrouselPiece); + layout()->addWidget(carrouselPiece); + + // FIXME? the fitInView inside the refresh of the piece doesn't workd properly. + // only by doing the following I did get it to work: + setVisible(true); + carrouselPiece->CleanPreview(); + setVisible(false); + + connect(carrouselPiece, QOverload::of(&VPieceCarrouselPiece::clicked), this, + &VPieceCarrouselLayer::on_PieceClicked); + + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QList VPieceCarrouselLayer::GetCarrouselPieces() +{ + return m_carrouselPieces; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselLayer::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece) +{ + emit pieceClicked(carrouselPiece); +} diff --git a/src/app/puzzle/vpiececarrousellayer.h b/src/app/puzzle/vpiececarrousellayer.h new file mode 100644 index 000000000..aa3bae3a2 --- /dev/null +++ b/src/app/puzzle/vpiececarrousellayer.h @@ -0,0 +1,64 @@ +/************************************************************************ + ** + ** @file vpiececarrousellayer.h + ** @author Ronan Le Tiec + ** @date 25 4, 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 + ** 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 VPIECECARROUSELLAYER_H +#define VPIECECARROUSELLAYER_H + +#include +#include "vpuzzlelayer.h" +#include "vpiececarrouselpiece.h" + +class VPieceCarrouselLayer : public QWidget +{ + Q_OBJECT +public: + explicit VPieceCarrouselLayer(VPuzzleLayer *layer, QWidget *parent = nullptr); + ~VPieceCarrouselLayer(); + + void Init(); + void Refresh(); + + QList GetCarrouselPieces(); + +signals: + void pieceClicked(VPieceCarrouselPiece* carrouselPiece); + +public slots: + void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece); + +private: + Q_DISABLE_COPY(VPieceCarrouselLayer) + + VPuzzleLayer *m_layer; + QList m_carrouselPieces; + +private slots: + +}; + +#endif // VPIECECARROUSELLAYER_H diff --git a/src/app/puzzle/vpiececarrouselpiece.cpp b/src/app/puzzle/vpiececarrouselpiece.cpp new file mode 100644 index 000000000..3ce4771a1 --- /dev/null +++ b/src/app/puzzle/vpiececarrouselpiece.cpp @@ -0,0 +1,165 @@ +/************************************************************************ + ** + ** @file vpiececarrouselpiece.cpp + ** @author Ronan Le Tiec + ** @date 25 4, 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 + ** 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 "vpiececarrouselpiece.h" +#include +#include +#include +#include + +#include + +Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece") + +//--------------------------------------------------------------------------------------------------------------------- +VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent) : + QFrame(parent), + m_piece(piece) +{ + Init(); +} + + +//--------------------------------------------------------------------------------------------------------------------- +VPieceCarrouselPiece::~VPieceCarrouselPiece() +{ + delete m_graphicsView; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselPiece::Init() +{ + // Define the structure + setFixedSize(124,128); + QVBoxLayout *pieceLayout = new QVBoxLayout(); + pieceLayout->setMargin(0); + pieceLayout->setSpacing(0); + setLayout(pieceLayout); + + setStyleSheet("background-color:white; border: 2px solid transparent;"); + + // define the preview of the piece + m_graphicsView = new QGraphicsView(this); + + // m_graphicsView = new VMainGraphicsView(this); + // --> undefined reference to 'VMainGraphicsView::VMainGraphicView(QWidget*)' + QGraphicsScene *graphicsScene = new QGraphicsScene(this); + m_graphicsView->setScene(graphicsScene); + m_graphicsView->setFixedSize(120,100); + m_graphicsView->setStyleSheet("border: 4px solid transparent;"); + + // define the label + m_label = new QLabel(); + m_label->sizePolicy(); + m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + m_label->setFixedSize(120,24); + m_label->setStyleSheet("border: 0px;"); + + pieceLayout->addWidget(m_graphicsView); + pieceLayout->addWidget(m_label); + + // then refresh the data + Refresh(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselPiece::CleanPreview() +{ + m_graphicsView->fitInView(m_graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselPiece::Refresh() +{ + // update the graphic view / the scene + + // TODO / FIXME : not perfect and maybe not the right way, still need to work on this + // for instance: use a painter to habve a better quality, less pixeled. + QVector points = m_piece->GetCuttingLine(); + + QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + pen.setCosmetic(true); + QBrush noBrush(Qt::NoBrush); + + QPainterPath path; + path.moveTo(points.first()); + for (int i = 1; i < points.size(); ++i) + path.lineTo(points.at(i)); + m_graphicsView->scene()->addPath(path, pen, noBrush); + + m_graphicsView->fitInView(m_graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); + + // update the label of the piece + QFontMetrics metrix(m_label->font()); + int width = m_label->width() - 8; + QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width); + m_label->setText(clippedText); + + // set the tooltip + setToolTip(m_piece->GetName()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPuzzlePiece * VPieceCarrouselPiece::GetPiece() +{ + return m_piece; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselPiece::SetIsSelected(bool value) +{ + m_isSelected = value; + + if(value) + { + setStyleSheet("background-color:white; border: 2px solid red;"); + } + else + { + setStyleSheet("background-color:white; border: 2px solid transparent;"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPieceCarrouselPiece::GetIsSelected() +{ + return m_isSelected; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + if(!m_isSelected) + { + emit clicked(this); + } + } +} + diff --git a/src/app/puzzle/vpiececarrouselpiece.h b/src/app/puzzle/vpiececarrouselpiece.h new file mode 100644 index 000000000..6eb7df138 --- /dev/null +++ b/src/app/puzzle/vpiececarrouselpiece.h @@ -0,0 +1,93 @@ +/************************************************************************ + ** + ** @file vpiececarrouselpiece.h + ** @author Ronan Le Tiec + ** @date 25 4, 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 + ** 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 VPIECECARROUSELPIECE_H +#define VPIECECARROUSELPIECE_H + +#include +#include +#include +#include + +#include "vpuzzlepiece.h" + + +class VPieceCarrouselPiece : public QFrame +{ + Q_OBJECT +public: + explicit VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent = nullptr); + ~VPieceCarrouselPiece(); + + void Init(); + void Refresh(); + /** + * @brief CleanPiecesPreview fitInView of the qGraphicsView of the pieces works properly + * only when the piece is in place in the layer and we call it from the layer. + */ + void CleanPreview(); + + /** + * @brief GetLayoutPiece Returns the corresponding layout piece + * @return the corresponding layout piece + */ + VPuzzlePiece * GetPiece(); + + /** + * @brief SetSelected sets the selected state to the given value + * @param value the new selected state + */ + void SetIsSelected(bool value); + + /** + * @brief GetSelected Returns wether the piece is selected or not + * @return true if the piece is selected + */ + bool GetIsSelected(); + +signals: + void clicked(VPieceCarrouselPiece* m_piece); + +public slots: + +protected: + void mousePressEvent(QMouseEvent *event) override; + +private: + Q_DISABLE_COPY(VPieceCarrouselPiece) + + VPuzzlePiece *m_piece; + QLabel *m_label{nullptr}; + QGraphicsView *m_graphicsView{nullptr}; + + bool m_isSelected = false; + +private slots: + +}; + +#endif // VPIECECARROUSELPIECE_H diff --git a/src/app/puzzle/vpuzzlelayout.cpp b/src/app/puzzle/vpuzzlelayout.cpp index e1f7603cc..61290add7 100644 --- a/src/app/puzzle/vpuzzlelayout.cpp +++ b/src/app/puzzle/vpuzzlelayout.cpp @@ -27,12 +27,18 @@ *************************************************************************/ #include "vpuzzlelayout.h" #include "vpuzzlelayer.h" +#include "vpuzzlepiece.h" //--------------------------------------------------------------------------------------------------------------------- VPuzzleLayout::VPuzzleLayout() : m_unplacedPiecesLayer(new VPuzzleLayer()) { + m_unplacedPiecesLayer->SetName(QObject::tr("Unplaced pieces")); + // create a standard default layer: + VPuzzleLayer *layer = new VPuzzleLayer(); + layer->SetName(QObject::tr("Layout")); + AddLayer(layer); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpuzzlelayout.h b/src/app/puzzle/vpuzzlelayout.h index f26e753dd..436957475 100644 --- a/src/app/puzzle/vpuzzlelayout.h +++ b/src/app/puzzle/vpuzzlelayout.h @@ -41,7 +41,6 @@ enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; class VPuzzleLayout { - public: VPuzzleLayout(); virtual ~VPuzzleLayout(); diff --git a/src/app/puzzle/vpuzzlepiece.cpp b/src/app/puzzle/vpuzzlepiece.cpp index 8c9a708f5..21daa67a2 100644 --- a/src/app/puzzle/vpuzzlepiece.cpp +++ b/src/app/puzzle/vpuzzlepiece.cpp @@ -39,3 +39,68 @@ VPuzzlePiece::~VPuzzlePiece() } + +//--------------------------------------------------------------------------------------------------------------------- +QString VPuzzlePiece::GetName() const +{ + return m_name; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetName(const QString &name) +{ + m_name = name; +} + + +//--------------------------------------------------------------------------------------------------------------------- +QUuid VPuzzlePiece::GetUuid() const +{ + return m_uuid; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetUuid(const QUuid &uuid) +{ + m_uuid = uuid; +} + + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPuzzlePiece::GetCuttingLine() const +{ + return m_cuttingLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetCuttingLine(const QVector &cuttingLine) +{ + m_cuttingLine = cuttingLine; +} + + +//--------------------------------------------------------------------------------------------------------------------- +bool VPuzzlePiece::GetShowSeamLine() +{ + return m_showSeamline; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetShowSeamLine(bool value) +{ + m_showSeamline = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPuzzlePiece::GetPieceMirrored() +{ + return m_mirrorPiece; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetPieceMirrored(bool value) +{ + m_mirrorPiece = value; +} + diff --git a/src/app/puzzle/vpuzzlepiece.h b/src/app/puzzle/vpuzzlepiece.h index f20473764..55d0f3fd8 100644 --- a/src/app/puzzle/vpuzzlepiece.h +++ b/src/app/puzzle/vpuzzlepiece.h @@ -28,14 +28,74 @@ #ifndef VPUZZLEPIECE_H #define VPUZZLEPIECE_H +#include +#include +#include + class VPuzzlePiece { public: VPuzzlePiece(); ~VPuzzlePiece(); -private: + /** + * @brief GetName Returns the name of the piece + * @return the piece's name + */ + QString GetName() const; + /** + * @brief SetName Sets the piece's name to the given name + * @param name new name of the piece + */ + void SetName(const QString &name); + + /** + * @brief GetUuid Returns the uuid of the piece + * @return the uuid of the piece + */ + QUuid GetUuid() const; + + /** + * @brief SetUuid Sets the uuid of the piece to the given value + */ + void SetUuid(const QUuid &uuid); + + QVector GetCuttingLine() const; + + void SetCuttingLine(const QVector &cuttingLine); + + /** + * @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not + * @return true if the seamline has to be shown + */ + bool GetShowSeamLine(); + + /** + * @brief SetShowSeamLine sets wether the seam line of the piece has to be shown or not + * @param value true if the seamline has to be shown + */ + void SetShowSeamLine(bool value); + + /** + * @brief GetMirrorPiece returns wether the piece is mirrored or not + * @return true if the piece is mirrored + */ + bool GetPieceMirrored(); + + /** + * @brief SetMirrorPiece sets wether the piece is mirrored or not + * @param value true if the piece will be mirrored + */ + void SetPieceMirrored(bool value); + + +private: + QUuid m_uuid{QUuid()}; + QString m_name{QString()}; + QVector m_cuttingLine{QVector()}; + bool m_showSeamline{true}; + bool m_mirrorPiece{false}; }; #endif // VPUZZLEPIECE_H diff --git a/src/app/puzzle/xml/layoutliterals.cpp b/src/app/puzzle/xml/layoutliterals.cpp index c3bdb6d6d..d73088fc8 100644 --- a/src/app/puzzle/xml/layoutliterals.cpp +++ b/src/app/puzzle/xml/layoutliterals.cpp @@ -60,4 +60,5 @@ const QString AttrFollowGrainLine = QStringLiteral("followGrainLine"); const QString AttrID = QStringLiteral("id"); const QString AttrMirrored = QStringLiteral("mirrored"); const QString AttrTransform = QStringLiteral("transform"); +const QString AttrShowSeamline = QStringLiteral("showSeamline"); } diff --git a/src/app/puzzle/xml/layoutliterals.h b/src/app/puzzle/xml/layoutliterals.h index 3f2577203..82157f9bf 100644 --- a/src/app/puzzle/xml/layoutliterals.h +++ b/src/app/puzzle/xml/layoutliterals.h @@ -65,6 +65,7 @@ extern const QString AttrFollowGrainLine; extern const QString AttrID; extern const QString AttrMirrored; extern const QString AttrTransform; +extern const QString AttrShowSeamline; } diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp b/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp index 106338f60..31ab72691 100644 --- a/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp +++ b/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp @@ -62,7 +62,7 @@ bool VPuzzleLayoutFileReader::ReadFile(VPuzzleLayout *layout, QFile *file) //--------------------------------------------------------------------------------------------------------------------- void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) { - Q_ASSERT(isStartElement() && name() == ML::TagLayout); + SCASSERT(isStartElement() && name() == ML::TagLayout); while (readNextStartElement()) { @@ -84,7 +84,7 @@ void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) //--------------------------------------------------------------------------------------------------------------------- void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) { - Q_ASSERT(isStartElement() && name() == ML::TagProperties); + SCASSERT(isStartElement() && name() == ML::TagProperties); while (readNextStartElement()) { @@ -162,7 +162,7 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout) { Q_UNUSED(layout); // to be removed when used - Q_ASSERT(isStartElement() && name() == ML::TagTiles); + SCASSERT(isStartElement() && name() == ML::TagTiles); // QXmlStreamAttributes attribs = attributes(); // attribs.value(ML::AttrVisible); // TODO @@ -195,7 +195,7 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout) //--------------------------------------------------------------------------------------------------------------------- void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout) { - Q_ASSERT(isStartElement() && name() == ML::TagLayers); + SCASSERT(isStartElement() && name() == ML::TagLayers); while (readNextStartElement()) { @@ -219,7 +219,7 @@ void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout) //--------------------------------------------------------------------------------------------------------------------- void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer) { - Q_ASSERT(isStartElement() && name() == ML::TagLayer); + SCASSERT(isStartElement() && (name() == ML::TagLayer || name() == ML::TagUnplacedPiecesLayer)); QXmlStreamAttributes attribs = attributes(); layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer"))); @@ -245,9 +245,21 @@ void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer) void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece) { Q_UNUSED(piece); - Q_ASSERT(isStartElement() && name() == ML::TagPiece); + SCASSERT(isStartElement() && name() == ML::TagPiece); + + QXmlStreamAttributes attribs = attributes(); + piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece"))); + + QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid().toString());// FIXME: is that correct to have a default value here? + piece->SetUuid(QUuid(uuidStr)); + + bool showSeamline = ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr); + piece->SetShowSeamLine(showSeamline); + + bool pieceMirrored = ReadAttributeBool(attribs, ML::AttrMirrored, falseStr); + piece->SetPieceMirrored(pieceMirrored); + // TODO read the further attributes - // TODO read the attributes while (readNextStartElement()) { diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp b/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp index c85f725b9..6b8dced26 100644 --- a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp @@ -163,9 +163,10 @@ void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece) Q_UNUSED(piece); writeStartElement(ML::TagPiece); - SetAttribute(ML::AttrID, "uuid1"); // TODO / Fixme get the right value - SetAttribute(ML::AttrName, "Piece name"); // TODO / Fixme get the right value - SetAttribute(ML::AttrMirrored, "false"); // TODO / Fixme get the right value + SetAttribute(ML::AttrID, piece->GetUuid().toString()); + SetAttribute(ML::AttrName, piece->GetName()); + SetAttribute(ML::AttrMirrored, piece->GetPieceMirrored()); // TODO / Fixme get the right value + SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine()); // TODO / Fixme get the right value SetAttribute(ML::AttrTransform, "string representation of the transformation"); // TODO / Fixme get the right value // TODO cuttingLine diff --git a/src/libs/vlayout/vrawlayout.h b/src/libs/vlayout/vrawlayout.h index 6521f62e7..23078048a 100644 --- a/src/libs/vlayout/vrawlayout.h +++ b/src/libs/vlayout/vrawlayout.h @@ -34,8 +34,8 @@ struct VRawLayoutData { QVector pieces{}; - friend QDataStream& operator<< (QDataStream& dataStream, const VRawLayoutData& date); - friend QDataStream& operator>> (QDataStream& dataStream, VRawLayoutData& date); + friend QDataStream& operator<< (QDataStream& dataStream, const VRawLayoutData& data); + friend QDataStream& operator>> (QDataStream& dataStream, VRawLayoutData& data); private: static const quint32 streamHeader;