Merge branch 'feature/manual-layout' into 'feature/manual-layout'

Work on the piece carrousel,  Feature/manual layout

See merge request smart-pattern/valentina!6
This commit is contained in:
Roman Telezhynskyi 2020-05-02 07:51:52 +00:00
commit ab569feff8
19 changed files with 1330 additions and 381 deletions

View File

@ -14,7 +14,9 @@ SOURCES += \
$$PWD/vpuzzlepiece.cpp \ $$PWD/vpuzzlepiece.cpp \
$$PWD/xml/layoutliterals.cpp \ $$PWD/xml/layoutliterals.cpp \
$$PWD/xml/vpuzzlelayoutfilewriter.cpp \ $$PWD/xml/vpuzzlelayoutfilewriter.cpp \
$$PWD/xml/vpuzzlelayoutfilereader.cpp $$PWD/xml/vpuzzlelayoutfilereader.cpp \
$$PWD/vpiececarrousellayer.cpp \
$$PWD/vpiececarrouselpiece.cpp
*msvc*:SOURCES += $$PWD/stable.cpp *msvc*:SOURCES += $$PWD/stable.cpp
@ -31,7 +33,9 @@ HEADERS += \
$$PWD/vpuzzlepiece.h \ $$PWD/vpuzzlepiece.h \
$$PWD/xml/layoutliterals.h \ $$PWD/xml/layoutliterals.h \
$$PWD/xml/vpuzzlelayoutfilewriter.h \ $$PWD/xml/vpuzzlelayoutfilewriter.h \
$$PWD/xml/vpuzzlelayoutfilereader.h $$PWD/xml/vpuzzlelayoutfilereader.h \
$$PWD/vpiececarrousellayer.h \
$$PWD/vpiececarrouselpiece.h
FORMS += \ FORMS += \
$$PWD/puzzlemainwindow.ui \ $$PWD/puzzlemainwindow.ui \

View File

@ -53,22 +53,24 @@ QT_WARNING_POP
PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent) : PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::PuzzleMainWindow), ui(new Ui::PuzzleMainWindow),
pieceCarrousel(new VPieceCarrousel),
m_cmd(cmd) m_cmd(cmd)
{ {
ui->setupUi(this);
InitMenuBar(); m_layout = new VPuzzleLayout();
InitProperties();
InitPieceCarrousel();
// ----- for test purposes, to be removed------------------ // ----- for test purposes, to be removed------------------
m_layout = new VPuzzleLayout();
m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25); m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25);
m_layout->SetLayoutSizeConverted(30.0, 29.7); m_layout->SetLayoutSizeConverted(30.0, 29.7);
m_layout->SetPiecesGapConverted(1.27); m_layout->SetPiecesGapConverted(1.27);
m_layout->SetUnit(Unit::Cm); m_layout->SetUnit(Unit::Cm);
m_layout->SetWarningSuperpositionOfPieces(true); m_layout->SetWarningSuperpositionOfPieces(true);
// --------------------------------------------------------
ui->setupUi(this);
InitMenuBar();
InitProperties();
InitPieceCarrousel();
SetPropertiesData(); SetPropertiesData();
} }
@ -77,7 +79,7 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa
PuzzleMainWindow::~PuzzleMainWindow() PuzzleMainWindow::~PuzzleMainWindow()
{ {
delete ui; 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; 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 else
{ {
qCCritical(pWindow, "%s\n", qPrintable(tr("Could not extract data from file '%1'. %2") 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()) if (m_cmd != nullptr && not m_cmd->IsGuiEnabled())
{ {
m_cmd->ShowHelp(V_EX_DATAERR); 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() void PuzzleMainWindow::InitMenuBar()
{ {
// most of the actions are connected through name convention (auto-connection)
// -------------------- connects the actions for the file menu // -------------------- 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); connect(ui->actionExit, &QAction::triggered, this, &PuzzleMainWindow::close);
// -------------------- connects the actions for the edit menu // -------------------- connects the actions for the edit menu
@ -166,16 +189,11 @@ void PuzzleMainWindow::InitMenuBar()
// -------------------- connects the actions for the windows menu // -------------------- connects the actions for the windows menu
// TODO : initialise the entries for the different windows // TODO : initialise the entries for the different windows
connect(ui->actionCloseLayout, &QAction::triggered, this, &PuzzleMainWindow::CloseLayout);
// Add dock properties action // Add dock properties action
QAction* actionDockWidgetToolOptions = ui->dockWidgetProperties->toggleViewAction(); QAction* actionDockWidgetToolOptions = ui->dockWidgetProperties->toggleViewAction();
ui->menuWindows->addAction(actionDockWidgetToolOptions); 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() void PuzzleMainWindow::InitPropertyTabCurrentPiece()
{ {
// ------------------------------ seamline ------------------------------------
connect(ui->checkBoxCurrentPieceShowSeamline, QOverload<bool>::of(&QCheckBox::toggled), this,
&PuzzleMainWindow::CurrentPieceShowSeamlineChanged);
// ------------------------------ geometry ------------------------------------
connect(ui->checkBoxCurrentPieceMirrorPiece, QOverload<bool>::of(&QCheckBox::toggled), this,
&PuzzleMainWindow::CurrentPieceMirrorPieceChanged);
// ------------------------------ rotation ------------------------------------
connect(ui->doubleSpinBoxCurrentPieceAngle, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::CurrentPieceAngleChanged);
// ------------------------------ placement ----------------------------------- // ------------------------------ placement -----------------------------------
connect(ui->doubleSpinBoxCurrentPieceBoxPositionX, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxCurrentPieceBoxPositionX, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::CurrentPiecePositionChanged); &PuzzleMainWindow::on_CurrentPiecePositionChanged);
connect(ui->doubleSpinBoxCurrentPieceBoxPositionY, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxCurrentPieceBoxPositionY, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::CurrentPiecePositionChanged); &PuzzleMainWindow::on_CurrentPiecePositionChanged);
} }
@ -226,63 +232,41 @@ void PuzzleMainWindow::InitPropertyTabLayout()
// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); // ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
// } // }
connect(ui->comboBoxLayoutUnit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, // some of the UI Elements are connected to the slots via auto-connect
&PuzzleMainWindow::LayoutUnitChanged); // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect
// -------------------- init the template combobox ---------------------
// TODO
connect(ui->comboBoxLayoutTemplate, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&PuzzleMainWindow::LayoutTemplateChanged);
// -------------------- layout width, length, orientation ------------------------ // -------------------- layout width, length, orientation ------------------------
connect(ui->doubleSpinBoxLayoutWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxLayoutWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutSizeChanged); &PuzzleMainWindow::on_LayoutSizeChanged);
connect(ui->doubleSpinBoxLayoutLength, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxLayoutLength, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutSizeChanged); &PuzzleMainWindow::on_LayoutSizeChanged);
connect(ui->radioButtonLayoutPortrait, QOverload<bool>::of(&QRadioButton::clicked), this, connect(ui->radioButtonLayoutPortrait, QOverload<bool>::of(&QRadioButton::clicked), this,
&PuzzleMainWindow::LayoutOrientationChanged); &PuzzleMainWindow::on_LayoutOrientationChanged);
connect(ui->radioButtonLayoutLandscape, QOverload<bool>::of(&QRadioButton::clicked), this, connect(ui->radioButtonLayoutLandscape, QOverload<bool>::of(&QRadioButton::clicked), this,
&PuzzleMainWindow::LayoutOrientationChanged); &PuzzleMainWindow::on_LayoutOrientationChanged);
connect(ui->pushButtonLayoutRemoveUnusedLength, QOverload<bool>::of(&QPushButton::clicked), this,
&PuzzleMainWindow::LayoutRemoveUnusedLength);
// -------------------- margins ------------------------ // -------------------- margins ------------------------
connect(ui->doubleSpinBoxLayoutMarginTop, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxLayoutMarginTop, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutMarginChanged); &PuzzleMainWindow::on_LayoutMarginChanged);
connect(ui->doubleSpinBoxLayoutMarginRight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxLayoutMarginRight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutMarginChanged); &PuzzleMainWindow::on_LayoutMarginChanged);
connect(ui->doubleSpinBoxLayoutMarginBottom, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxLayoutMarginBottom, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutMarginChanged); &PuzzleMainWindow::on_LayoutMarginChanged);
connect(ui->doubleSpinBoxLayoutMarginLeft, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(ui->doubleSpinBoxLayoutMarginLeft, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutMarginChanged); &PuzzleMainWindow::on_LayoutMarginChanged);
// ------------------- follow grainline ----------------------- // ------------------- follow grainline -----------------------
connect(ui->radioButtonLayoutFollowGrainlineNo, QOverload<bool>::of(&QRadioButton::clicked), this, connect(ui->radioButtonLayoutFollowGrainlineNo, QOverload<bool>::of(&QRadioButton::clicked), this,
&PuzzleMainWindow::LayoutFollowGrainlineChanged); &PuzzleMainWindow::on_LayoutFollowGrainlineChanged);
connect(ui->radioButtonLayoutFollowGrainlineVertical, QOverload<bool>::of(&QRadioButton::clicked), this, connect(ui->radioButtonLayoutFollowGrainlineVertical, QOverload<bool>::of(&QRadioButton::clicked), this,
&PuzzleMainWindow::LayoutFollowGrainlineChanged); &PuzzleMainWindow::on_LayoutFollowGrainlineChanged);
connect(ui->radioButtonLayoutFollowGrainlineHorizontal, QOverload<bool>::of(&QRadioButton::clicked), this, connect(ui->radioButtonLayoutFollowGrainlineHorizontal, QOverload<bool>::of(&QRadioButton::clicked), this,
&PuzzleMainWindow::LayoutFollowGrainlineChanged); &PuzzleMainWindow::on_LayoutFollowGrainlineChanged);
// -------------------- pieces gap and checkboxes ---------------
connect(ui->doubleSpinBoxLayoutPiecesGap, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&PuzzleMainWindow::LayoutPiecesGapChanged);
connect(ui->checkBoxLayoutWarningPiecesSuperposition, QOverload<bool>::of(&QCheckBox::toggled), this,
&PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged);
connect(ui->checkBoxLayoutWarningPiecesOutOfBound, QOverload<bool>::of(&QCheckBox::toggled), this,
&PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged);
connect(ui->checkBoxLayoutStickyEdges, QOverload<bool>::of(&QCheckBox::toggled), this,
&PuzzleMainWindow::LayoutStickyEdgesChanged);
// -------------------- export --------------------------- // -------------------- export ---------------------------
// TODO init the file format export combobox // TODO init the file format export combobox
connect(ui->pushButtonLayoutExport, QOverload<bool>::of(&QPushButton::clicked), this,
&PuzzleMainWindow::LayoutExport);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -304,10 +288,14 @@ void PuzzleMainWindow::InitPropertyTabLayers()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::InitPieceCarrousel() void PuzzleMainWindow::InitPieceCarrousel()
{ {
ui->dockWidgetPieceCarrousel->setWidget(pieceCarrousel); m_pieceCarrousel = new VPieceCarrousel(m_layout, ui->dockWidgetPieceCarrousel);
ui->dockWidgetPieceCarrousel->setWidget(m_pieceCarrousel);
connect(ui->dockWidgetPieceCarrousel, QOverload<Qt::DockWidgetArea>::of(&QDockWidget::dockLocationChanged), this, connect(ui->dockWidgetPieceCarrousel, QOverload<Qt::DockWidgetArea>::of(&QDockWidget::dockLocationChanged), this,
&PuzzleMainWindow::PieceCarrouselLocationChanged); &PuzzleMainWindow::on_PieceCarrouselLocationChanged);
connect(m_pieceCarrousel, QOverload<VPuzzlePiece*>::of(&VPieceCarrousel::pieceClicked), this,
&PuzzleMainWindow::on_PieceSelected);
} }
@ -339,11 +327,22 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
else else
{ {
// TODO : update current piece data to show a "no current piece selected" // TODO : update current piece data to show a "no current piece selected"
ui->containerCurrentPieceNoData->setVisible(true);
ui->containerCurrentPieceData->setVisible(false);
} }
} }
else 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: // just for test purpuses, to be removed:
QMessageBox msgBox; QMessageBox msgBox;
@ -437,7 +436,7 @@ void PuzzleMainWindow::New()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::Open() void PuzzleMainWindow::on_actionOpen_triggered()
{ {
qCDebug(pWindow, "Openning puzzle layout file."); 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: // just for test purpuses, to be removed:
QMessageBox msgBox; 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. // 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: // TODO: here the code is probably just bad, to be edited
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::ImportRawLayout");
int ret = msgBox.exec();
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: // just for test purpuses, to be removed:
QMessageBox msgBox; QMessageBox msgBox;
@ -560,13 +575,13 @@ void PuzzleMainWindow::CloseLayout()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::AboutQt() void PuzzleMainWindow::on_actionAboutQt_triggered()
{ {
QMessageBox::aboutQt(this, tr("About Qt")); QMessageBox::aboutQt(this, tr("About Qt"));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::AboutPuzzle() void PuzzleMainWindow::on_actionAboutPuzzle_triggered()
{ {
auto *aboutDialog = new DialogAboutPuzzle(this); auto *aboutDialog = new DialogAboutPuzzle(this);
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true); 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); Q_UNUSED(index);
QVariant comboBoxValue = ui->comboBoxLayoutUnit->currentData(); 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: // just for test purpuses, to be removed:
QMessageBox msgBox; 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()); 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 // swap the width and length
qreal width_before = ui->doubleSpinBoxLayoutWidth->value(); 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: // just for test purpuses, to be removed:
QMessageBox msgBox; QMessageBox msgBox;
@ -661,7 +676,7 @@ void PuzzleMainWindow::LayoutRemoveUnusedLength()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutMarginChanged() void PuzzleMainWindow::on_LayoutMarginChanged()
{ {
m_layout->SetLayoutMarginsConverted( m_layout->SetLayoutMarginsConverted(
ui->doubleSpinBoxLayoutMarginLeft->value(), ui->doubleSpinBoxLayoutMarginLeft->value(),
@ -676,7 +691,7 @@ void PuzzleMainWindow::LayoutMarginChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutFollowGrainlineChanged() void PuzzleMainWindow::on_LayoutFollowGrainlineChanged()
{ {
// just for test purpuses, to be removed: // just for test purpuses, to be removed:
QMessageBox msgBox; 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); 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); 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); 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); 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: // just for test purpuses, to be removed:
QMessageBox msgBox; 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: if(m_selectedPiece != nullptr)
QMessageBox msgBox; {
msgBox.setText("TODO PuzzleMainWindow::CurrentPieceShowSeamlineChanged"); m_selectedPiece->SetShowSeamLine(checked);
int ret = msgBox.exec(); }
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::CurrentPieceMirrorPieceChanged(bool checked) void PuzzleMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked)
{ {
// just for test purpuses, to be removed: if(m_selectedPiece != nullptr)
QMessageBox msgBox; {
msgBox.setText("TODO PuzzleMainWindow::CurrentPieceMirrorPieceChanged"); m_selectedPiece->SetPieceMirrored(checked);
int ret = msgBox.exec(); }
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::CurrentPieceAngleChanged(double value) void PuzzleMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value)
{ {
// just for test purpuses, to be removed: // just for test purpuses, to be removed:
QMessageBox msgBox; 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: // just for test purpuses, to be removed:
QMessageBox msgBox; 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) if(area == Qt::BottomDockWidgetArea || area == Qt::TopDockWidgetArea)
{ {
pieceCarrousel->setOrientation(Qt::Horizontal); m_pieceCarrousel->SetOrientation(Qt::Horizontal);
ui->dockWidgetPieceCarrousel->setMaximumHeight(208); ui->dockWidgetPieceCarrousel->setMaximumHeight(208);
ui->dockWidgetPieceCarrousel->setMaximumWidth(10000); ui->dockWidgetPieceCarrousel->setMaximumWidth(10000);
} }
else if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea) else if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea)
{ {
pieceCarrousel->setOrientation(Qt::Vertical); m_pieceCarrousel->SetOrientation(Qt::Vertical);
ui->dockWidgetPieceCarrousel->setMaximumHeight(10000); ui->dockWidgetPieceCarrousel->setMaximumHeight(10000);
ui->dockWidgetPieceCarrousel->setMaximumWidth(160); 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();
}

View File

@ -36,6 +36,7 @@
#include "vpiececarrousel.h" #include "vpiececarrousel.h"
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
#include "../vlayout/vlayoutpiece.h"
#include "vpuzzlecommandline.h" #include "vpuzzlecommandline.h"
namespace Ui namespace Ui
@ -66,10 +67,18 @@ public:
*/ */
bool SaveFile(const QString &path); 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: public slots:
void New(); /**
* @brief on_actionNew_triggered When the menu action File > New
* is triggered
*/
void on_actionNew_triggered();
protected: protected:
enum { MaxRecentFiles = 5 }; enum { MaxRecentFiles = 5 };
@ -77,20 +86,52 @@ protected:
private: private:
Q_DISABLE_COPY(PuzzleMainWindow) Q_DISABLE_COPY(PuzzleMainWindow)
Ui::PuzzleMainWindow *ui; Ui::PuzzleMainWindow *ui;
VPieceCarrousel *pieceCarrousel; VPieceCarrousel *m_pieceCarrousel{nullptr};
VPuzzleCommandLinePtr m_cmd; VPuzzleCommandLinePtr m_cmd;
VPuzzleLayout *m_layout{nullptr}; VPuzzleLayout *m_layout{nullptr};
VPuzzlePiece *m_selectedPiece{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(); void InitMenuBar();
/**
* @brief InitProperties Init the properties
*/
void InitProperties(); void InitProperties();
/**
* @brief InitPropertyTabCurrentPiece Inits the current piece tab in the properties
*/
void InitPropertyTabCurrentPiece(); void InitPropertyTabCurrentPiece();
/**
* @brief InitPropertyTabLayout Inits the layout tab in the properties
*/
void InitPropertyTabLayout(); void InitPropertyTabLayout();
/**
* @brief InitPropertyTabTiles Inits the tiles tab in the properties
*/
void InitPropertyTabTiles(); void InitPropertyTabTiles();
/**
* @brief InitPropertyTabLayers Inits the layers tab in the properties
*/
void InitPropertyTabLayers(); void InitPropertyTabLayers();
/**
* @brief InitPieceCarrousel Inits the piece carrousel
*/
void InitPieceCarrousel(); void InitPieceCarrousel();
@ -141,34 +182,185 @@ private:
void SetCheckBoxValue(QCheckBox *checkbox, bool value); void SetCheckBoxValue(QCheckBox *checkbox, bool value);
private slots: private slots:
void Open(); /**
void Save(); * @brief on_actionOpen_triggered When the menu action File > Open is
void SaveAs(); * triggered.
void ImportRawLayout(); * The slot is automatically connected through name convention.
void CloseLayout(); */
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); * @brief on_actionSaveAs_triggered When the menu action File > Save As
void LayoutSizeChanged(); * is triggered.
void LayoutOrientationChanged(); * The slot is automatically connected through name convention.
void LayoutRemoveUnusedLength(); */
void LayoutMarginChanged(); void on_actionSaveAs_triggered();
void LayoutFollowGrainlineChanged();
void LayoutPiecesGapChanged(double value);
void LayoutWarningPiecesSuperpositionChanged(bool checked);
void LayoutWarningPiecesOutOfBoundChanged(bool checked);
void LayoutStickyEdgesChanged(bool checked);
void LayoutExport();
void CurrentPieceShowSeamlineChanged(bool checked); /**
void CurrentPieceMirrorPieceChanged(bool checked); * @brief on_actionImportRawLayout_triggered When the menu action
void CurrentPieceAngleChanged(double value); * File > Import Raw Layout is triggered.
void CurrentPiecePositionChanged(); * 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);
}; };

View File

@ -94,8 +94,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>160</width> <width>24</width>
<height>208</height> <height>37</height>
</size> </size>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@ -126,7 +126,11 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_10"/> <layout class="QVBoxLayout" name="verticalLayout_10">
<property name="spacing">
<number>0</number>
</property>
</layout>
</widget> </widget>
</widget> </widget>
<widget class="QDockWidget" name="dockWidgetProperties"> <widget class="QDockWidget" name="dockWidgetProperties">
@ -171,7 +175,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -228,8 +232,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>170</width> <width>342</width>
<height>452</height> <height>894</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -250,44 +254,24 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBoxCurrentPieceInfo"> <widget class="QWidget" name="containerCurrentPieceNoData" native="true">
<property name="title"> <layout class="QVBoxLayout" name="containerCurrentPieceNoDataLayout">
<string>Infos</string> <property name="spacing">
</property> <number>0</number>
<layout class="QFormLayout" name="formLayout_4"> </property>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditCurrentPieceName">
<property name="text">
<string>DummyName</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelCurrentPieceName">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxCurrentPieceSeamline">
<property name="title">
<string>Seamline</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item> <item>
<widget class="QCheckBox" name="checkBoxCurrentPieceShowSeamline"> <widget class="QLabel" name="labelCurrentPieceNoPieceSelected">
<property name="text"> <property name="minimumSize">
<string>Show Seamline</string> <size>
<width>0</width>
<height>400</height>
</size>
</property> </property>
<property name="checked"> <property name="text">
<bool>true</bool> <string>No piece selected</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
@ -295,85 +279,136 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBoxCurrentPieceGeometry"> <widget class="QWidget" name="containerCurrentPieceData" native="true">
<property name="title"> <layout class="QVBoxLayout" name="containerCurrentPieceDataLayout">
<string>Geometry</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item> <item>
<widget class="QCheckBox" name="checkBoxCurrentPieceMirrorPiece"> <widget class="QGroupBox" name="groupBoxCurrentPieceInfo">
<property name="text"> <property name="title">
<string>Mirror piece</string> <string>Infos</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_4">
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditCurrentPieceName">
<property name="text">
<string>DummyName</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelCurrentPieceName">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> <item>
</widget> <widget class="QGroupBox" name="groupBoxCurrentPieceSeamline">
</item> <property name="title">
<item> <string>Seamline</string>
<widget class="QGroupBox" name="groupBoxCurrentPieceRotation">
<property name="title">
<string>Rotation</string>
</property>
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QLabel" name="labelCurrentPieceAngle">
<property name="text">
<string>Angle:</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QCheckBox" name="checkBoxCurrentPieceShowSeamline">
<property name="text">
<string>Show Seamline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceAngle"> <widget class="QGroupBox" name="groupBoxCurrentPieceGeometry">
<property name="maximum"> <property name="title">
<double>360.000000000000000</double> <string>Geometry</string>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QCheckBox" name="checkBoxCurrentPieceMirrorPiece">
<property name="text">
<string>Mirror piece</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> <item>
</widget> <widget class="QGroupBox" name="groupBoxCurrentPieceRotation">
</item> <property name="title">
<item> <string>Rotation</string>
<widget class="QGroupBox" name="groupBoxCurrentPiecePlacement">
<property name="title">
<string>Placement</string>
</property>
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<widget class="QLabel" name="labelCurrentPiecePositionX">
<property name="text">
<string>X:</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QLabel" name="labelCurrentPieceAngle">
<property name="text">
<string>Angle:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceAngle">
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceBoxPositionX"> <widget class="QGroupBox" name="groupBoxCurrentPiecePlacement">
<property name="maximum"> <property name="title">
<double>10000.000000000000000</double> <string>Placement</string>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelCurrentPiecePositionY">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceBoxPositionY">
<property name="maximum">
<double>10000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property> </property>
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<widget class="QLabel" name="labelCurrentPiecePositionX">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceBoxPositionX">
<property name="maximum">
<double>10000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelCurrentPiecePositionY">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceBoxPositionY">
<property name="maximum">
<double>10000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -858,8 +893,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>98</width> <width>356</width>
<height>41</height> <height>760</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -938,8 +973,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>98</width> <width>356</width>
<height>41</height> <height>760</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">

View File

@ -27,131 +27,218 @@
*************************************************************************/ *************************************************************************/
#include "vpiececarrousel.h" #include "vpiececarrousel.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel>
#include <QMessageBox> #include <QMessageBox>
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#include <QLoggingCategory>
#include <QScrollBar>
Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPieceCarrousel::VPieceCarrousel(QWidget *parent) : VPieceCarrousel::VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent) :
QWidget(parent), QWidget(parent),
comboBoxLayer(new QComboBox), m_layout(layout),
mainScrollArea(new QScrollArea(this)), m_comboBoxLayer(new QComboBox(this)),
layers(QList<QWidget *>()) m_scrollArea(new QScrollArea(this)),
m_layersContainer(new QWidget(this)),
m_carrouselLayers(QList<VPieceCarrouselLayer *>())
{ {
Init();
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<int>::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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPieceCarrousel::~VPieceCarrousel() VPieceCarrousel::~VPieceCarrousel()
{ {
delete comboBoxLayer; delete m_comboBoxLayer;
delete mainScrollArea; 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<int>::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<VPuzzleLayer*> 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<VPieceCarrouselPiece*>::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;i<layerCount;i++)
{
m_comboBoxLayer->removeItem(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<VPieceCarrouselPiece*> 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; int j=0;
for (QWidget *widget: layers) { for (VPieceCarrouselLayer *carrouselLayer: m_carrouselLayers) {
widget->setVisible(j == index); carrouselLayer->setVisible(j == index);
j++; j++;
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrousel::setOrientation(Qt::Orientation orientation) void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
{ {
QBoxLayout::Direction direction = QBoxLayout::LeftToRight;
if(orientation == Qt::Horizontal) QBoxLayout::Direction direction = (orientation == Qt::Horizontal)?
{ QBoxLayout::LeftToRight
comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); :
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); QBoxLayout::TopToBottom;
}
else // Qt::Vertical
{
direction = QBoxLayout::TopToBottom;
comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
}
QBoxLayout* mainScrollAreaLayout = qobject_cast<QBoxLayout*>(mainScrollArea->widget()->layout()); // Update the various qlayouts
QBoxLayout* mainScrollAreaLayout = qobject_cast<QBoxLayout*>(m_layersContainer->layout());
mainScrollAreaLayout->setDirection(direction); mainScrollAreaLayout->setDirection(direction);
for (QWidget *widget: layers) { QBoxLayout* layerContainerWrapper = qobject_cast<QBoxLayout*>(m_scrollArea->widget()->layout());
layerContainerWrapper->setDirection(direction);
for (VPieceCarrouselLayer *widget: m_carrouselLayers) {
QBoxLayout* layerLayout = qobject_cast<QBoxLayout*>(widget->layout()); QBoxLayout* layerLayout = qobject_cast<QBoxLayout*>(widget->layout());
layerLayout->setDirection(direction); 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());
}

View File

@ -32,27 +32,62 @@
#include <QWidget> #include <QWidget>
#include <QComboBox> #include <QComboBox>
#include <QScrollArea> #include <QScrollArea>
#include "vpuzzlelayout.h"
#include "vpuzzlepiece.h"
#include "vpiececarrousellayer.h"
class VPieceCarrousel : public QWidget class VPieceCarrousel : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit VPieceCarrousel(QWidget *parent = nullptr); explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr);
virtual ~VPieceCarrousel(); 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: signals:
void pieceClicked(VPuzzlePiece* piece);
public slots: public slots:
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
private: private:
Q_DISABLE_COPY(VPieceCarrousel) Q_DISABLE_COPY(VPieceCarrousel)
QComboBox *comboBoxLayer;
QScrollArea *mainScrollArea; VPuzzleLayout *m_layout;
QList<QWidget *> layers;
QComboBox *m_comboBoxLayer;
QScrollArea *m_scrollArea;
QWidget *m_layersContainer;
QList<VPieceCarrouselLayer*> m_carrouselLayers;
private slots: private slots:
void ActiveLayerChanged(int index); void on_ActiveLayerChanged(int index);
}; };
#endif // VPIECECARROUSEL_H #endif // VPIECECARROUSEL_H

View File

@ -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
** <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/>.
**
*************************************************************************/
#include "vpiececarrousellayer.h"
#include <QVBoxLayout>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer")
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselLayer::VPieceCarrouselLayer(VPuzzleLayer *layer, QWidget *parent) :
QWidget(parent),
m_layer(layer),
m_carrouselPieces(QList<VPieceCarrouselPiece*>())
{
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<VPuzzlePiece*> 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<VPieceCarrouselPiece*>::of(&VPieceCarrouselPiece::clicked), this,
&VPieceCarrouselLayer::on_PieceClicked);
}
}
//---------------------------------------------------------------------------------------------------------------------
QList<VPieceCarrouselPiece*> VPieceCarrouselLayer::GetCarrouselPieces()
{
return m_carrouselPieces;
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselLayer::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece)
{
emit pieceClicked(carrouselPiece);
}

View File

@ -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
** <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/>.
**
*************************************************************************/
#ifndef VPIECECARROUSELLAYER_H
#define VPIECECARROUSELLAYER_H
#include <QWidget>
#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<VPieceCarrouselPiece*> GetCarrouselPieces();
signals:
void pieceClicked(VPieceCarrouselPiece* carrouselPiece);
public slots:
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
private:
Q_DISABLE_COPY(VPieceCarrouselLayer)
VPuzzleLayer *m_layer;
QList<VPieceCarrouselPiece*> m_carrouselPieces;
private slots:
};
#endif // VPIECECARROUSELLAYER_H

View File

@ -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
** <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/>.
**
*************************************************************************/
#include "vpiececarrouselpiece.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QGraphicsScene>
#include <QPainter>
#include <QLoggingCategory>
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<QPointF> 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);
}
}
}

View File

@ -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
** <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/>.
**
*************************************************************************/
#ifndef VPIECECARROUSELPIECE_H
#define VPIECECARROUSELPIECE_H
#include <QFrame>
#include <QLabel>
#include <QGraphicsView>
#include <QMouseEvent>
#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

View File

@ -27,12 +27,18 @@
*************************************************************************/ *************************************************************************/
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlelayer.h" #include "vpuzzlelayer.h"
#include "vpuzzlepiece.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayout::VPuzzleLayout() : VPuzzleLayout::VPuzzleLayout() :
m_unplacedPiecesLayer(new VPuzzleLayer()) 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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -41,7 +41,6 @@ enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2};
class VPuzzleLayout class VPuzzleLayout
{ {
public: public:
VPuzzleLayout(); VPuzzleLayout();
virtual ~VPuzzleLayout(); virtual ~VPuzzleLayout();

View File

@ -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<QPointF> VPuzzlePiece::GetCuttingLine() const
{
return m_cuttingLine;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetCuttingLine(const QVector<QPointF> &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;
}

View File

@ -28,14 +28,74 @@
#ifndef VPUZZLEPIECE_H #ifndef VPUZZLEPIECE_H
#define VPUZZLEPIECE_H #define VPUZZLEPIECE_H
#include <QUuid>
#include <QVector>
#include <QPoint>
class VPuzzlePiece class VPuzzlePiece
{ {
public: public:
VPuzzlePiece(); VPuzzlePiece();
~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<QPointF> GetCuttingLine() const;
void SetCuttingLine(const QVector<QPointF> &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<QPointF> m_cuttingLine{QVector<QPointF>()};
bool m_showSeamline{true};
bool m_mirrorPiece{false};
}; };
#endif // VPUZZLEPIECE_H #endif // VPUZZLEPIECE_H

View File

@ -60,4 +60,5 @@ const QString AttrFollowGrainLine = QStringLiteral("followGrainLine");
const QString AttrID = QStringLiteral("id"); const QString AttrID = QStringLiteral("id");
const QString AttrMirrored = QStringLiteral("mirrored"); const QString AttrMirrored = QStringLiteral("mirrored");
const QString AttrTransform = QStringLiteral("transform"); const QString AttrTransform = QStringLiteral("transform");
const QString AttrShowSeamline = QStringLiteral("showSeamline");
} }

View File

@ -65,6 +65,7 @@ extern const QString AttrFollowGrainLine;
extern const QString AttrID; extern const QString AttrID;
extern const QString AttrMirrored; extern const QString AttrMirrored;
extern const QString AttrTransform; extern const QString AttrTransform;
extern const QString AttrShowSeamline;
} }

View File

@ -62,7 +62,7 @@ bool VPuzzleLayoutFileReader::ReadFile(VPuzzleLayout *layout, QFile *file)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagLayout); SCASSERT(isStartElement() && name() == ML::TagLayout);
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -84,7 +84,7 @@ void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagProperties); SCASSERT(isStartElement() && name() == ML::TagProperties);
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -162,7 +162,7 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout)
{ {
Q_UNUSED(layout); // to be removed when used Q_UNUSED(layout); // to be removed when used
Q_ASSERT(isStartElement() && name() == ML::TagTiles); SCASSERT(isStartElement() && name() == ML::TagTiles);
// QXmlStreamAttributes attribs = attributes(); // QXmlStreamAttributes attribs = attributes();
// attribs.value(ML::AttrVisible); // TODO // attribs.value(ML::AttrVisible); // TODO
@ -195,7 +195,7 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout) void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagLayers); SCASSERT(isStartElement() && name() == ML::TagLayers);
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -219,7 +219,7 @@ void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer) void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagLayer); SCASSERT(isStartElement() && (name() == ML::TagLayer || name() == ML::TagUnplacedPiecesLayer));
QXmlStreamAttributes attribs = attributes(); QXmlStreamAttributes attribs = attributes();
layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer"))); layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer")));
@ -245,9 +245,21 @@ void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer)
void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece) void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece)
{ {
Q_UNUSED(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()) while (readNextStartElement())
{ {

View File

@ -163,9 +163,10 @@ void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece)
Q_UNUSED(piece); Q_UNUSED(piece);
writeStartElement(ML::TagPiece); writeStartElement(ML::TagPiece);
SetAttribute(ML::AttrID, "uuid1"); // TODO / Fixme get the right value SetAttribute(ML::AttrID, piece->GetUuid().toString());
SetAttribute(ML::AttrName, "Piece name"); // TODO / Fixme get the right value SetAttribute(ML::AttrName, piece->GetName());
SetAttribute(ML::AttrMirrored, "false"); // TODO / Fixme get the right value 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 SetAttribute(ML::AttrTransform, "string representation of the transformation"); // TODO / Fixme get the right value
// TODO cuttingLine // TODO cuttingLine

View File

@ -34,8 +34,8 @@ struct VRawLayoutData
{ {
QVector<VLayoutPiece> pieces{}; QVector<VLayoutPiece> pieces{};
friend QDataStream& operator<< (QDataStream& dataStream, const VRawLayoutData& date); friend QDataStream& operator<< (QDataStream& dataStream, const VRawLayoutData& data);
friend QDataStream& operator>> (QDataStream& dataStream, VRawLayoutData& date); friend QDataStream& operator>> (QDataStream& dataStream, VRawLayoutData& data);
private: private:
static const quint32 streamHeader; static const quint32 streamHeader;