work on units, layout and reader

This commit is contained in:
Ronan Le Tiec 2020-04-19 11:58:43 +02:00
parent c83ac5e493
commit 8be95376f1
5 changed files with 276 additions and 4 deletions

View File

@ -38,7 +38,7 @@ PuzzleMainWindow::PuzzleMainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::PuzzleMainWindow), ui(new Ui::PuzzleMainWindow),
pieceCarrousel(new VPieceCarrousel), pieceCarrousel(new VPieceCarrousel),
m_layout (new VPuzzleLayout) m_layout (nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -47,9 +47,13 @@ PuzzleMainWindow::PuzzleMainWindow(QWidget *parent) :
InitPieceCarrousel(); InitPieceCarrousel();
// for test purposes, to be removed when we can edit the size / margins through the UI: // ----- for test purposes, to be removed------------------
m_layout->SetLayoutMargins(1.5, 2.00, 4.21, 0.25); m_layout = new VPuzzleLayout();
m_layout->SetLayoutSize(21.0, 29.7); m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25);
m_layout->SetLayoutSizeConverted(21.0, 29.7);
m_layout->SetPiecesGapConverted(1);
m_layout->SetUnit(Unit::Cm);
SetPropertiesData();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -233,6 +237,90 @@ void PuzzleMainWindow::InitPieceCarrousel()
} }
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetPropertiesData()
{
if(m_layout == nullptr)
{
// TODO : hide the tabs when there is no layout
}
else
{
SetPropertyTabCurrentPieceData();
SetPropertyTabLayoutData();
SetPropertyTabTilesData();
SetPropertyTabLayersData();
}
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
{
if(m_selectedPiece == nullptr)
{
if(false) // check for multiple piece selection
{
// TODO in the future
}
else
{
// TODO : update current piece data to show a "no current piece selected"
}
}
else
{
// TODO set the values of the piece currently selected
}
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetPropertyTabLayoutData()
{
// set Unit
int index = ui->comboBoxLayoutUnit->findData(QVariant(UnitsToStr(m_layout->getUnit())));
if(index != -1)
{
ui->comboBoxLayoutUnit->blockSignals(true); // FIXME: is there a better way to block the signals?
ui->comboBoxLayoutUnit->setCurrentIndex(index);
ui->comboBoxLayoutUnit->blockSignals(false);
}
// set Width / Length
QSizeF size = m_layout->GetLayoutSizeConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, size.width());
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, size.height());
// set margins
QMarginsF margins = m_layout->GetLayoutMarginsConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginLeft, margins.left());
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginTop, margins.top());
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginRight, margins.right());
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginBottom, margins.bottom());
// set pieces gap
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutPiecesGap, m_layout->GetPiecesGapConverted());
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetPropertyTabTilesData()
{
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetPropertyTabLayersData()
{
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value)
{
spinBox->blockSignals(true);
spinBox->setValue(value);
spinBox->blockSignals(false);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -30,10 +30,12 @@
#include <QMainWindow> #include <QMainWindow>
#include <QMessageBox> #include <QMessageBox>
#include <QDoubleSpinBox>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "vpiececarrousel.h" #include "vpiececarrousel.h"
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlepiece.h"
namespace Ui namespace Ui
{ {
@ -62,6 +64,8 @@ private:
VPuzzleLayout *m_layout; VPuzzleLayout *m_layout;
VPuzzlePiece *m_selectedPiece;
void InitMenuBar(); void InitMenuBar();
void InitProperties(); void InitProperties();
@ -71,6 +75,21 @@ private:
void InitPropertyTabLayers(); void InitPropertyTabLayers();
void InitPieceCarrousel(); void InitPieceCarrousel();
void SetPropertiesData();
void SetPropertyTabCurrentPieceData();
void SetPropertyTabLayoutData();
void SetPropertyTabTilesData();
void SetPropertyTabLayersData();
/**
* @brief SetDoubleSpinBoxValue sets the given spinbox to the given value
* the signals are blocked before changing the value and unblocked after
* @param spinbox
* @param value
*/
void SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value);
private slots: private slots:
void Open(); void Open();
void Save(); void Save();

View File

@ -95,18 +95,45 @@ void VPuzzleLayout::SetLayoutSize(qreal width, qreal height)
m_size.setHeight(height); m_size.setHeight(height);
} }
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutSizeConverted(qreal width, qreal height)
{
m_size.setWidth(UnitConvertor(width, m_unit,Unit::Px));
m_size.setHeight(UnitConvertor(height, m_unit,Unit::Px));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutSize(QSizeF size) void VPuzzleLayout::SetLayoutSize(QSizeF size)
{ {
m_size = size; m_size = size;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutSizeConverted(QSizeF size)
{
m_size = QSizeF(
UnitConvertor(size.width(), m_unit,Unit::Px),
UnitConvertor(size.height(), m_unit,Unit::Px)
);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QSizeF VPuzzleLayout::GetLayoutSize() QSizeF VPuzzleLayout::GetLayoutSize()
{ {
return m_size; return m_size;
} }
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPuzzleLayout::GetLayoutSizeConverted()
{
QSizeF convertedSize = QSizeF(
UnitConvertor(m_size.width(), Unit::Px, m_unit),
UnitConvertor(m_size.height(), Unit::Px, m_unit)
);
return convertedSize;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom) void VPuzzleLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom)
{ {
@ -115,6 +142,14 @@ void VPuzzleLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal b
m_margins.setRight(right); m_margins.setRight(right);
m_margins.setBottom(bottom); m_margins.setBottom(bottom);
} }
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom)
{
m_margins.setLeft(UnitConvertor(left, m_unit, Unit::Px));
m_margins.setTop(UnitConvertor(top, m_unit, Unit::Px));
m_margins.setRight(UnitConvertor(right, m_unit, Unit::Px));
m_margins.setBottom(UnitConvertor(bottom, m_unit, Unit::Px));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutMargins(QMarginsF margins) void VPuzzleLayout::SetLayoutMargins(QMarginsF margins)
@ -122,12 +157,24 @@ void VPuzzleLayout::SetLayoutMargins(QMarginsF margins)
m_margins = margins; m_margins = margins;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetLayoutMarginsConverted(QMarginsF margins)
{
m_margins = UnitConvertor(margins, m_unit, Unit::Px);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QMarginsF VPuzzleLayout::GetLayoutMargins() QMarginsF VPuzzleLayout::GetLayoutMargins()
{ {
return m_margins; return m_margins;
} }
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPuzzleLayout::GetLayoutMarginsConverted()
{
return UnitConvertor(m_margins, Unit::Px, m_unit);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetFollowGrainline(FollowGrainline state) void VPuzzleLayout::SetFollowGrainline(FollowGrainline state)
{ {
@ -146,12 +193,25 @@ void VPuzzleLayout::SetPiecesGap(qreal value)
m_piecesGap = value; m_piecesGap = value;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetPiecesGapConverted(qreal value)
{
m_piecesGap = UnitConvertor(value, m_unit, Unit::Px);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPuzzleLayout::GetPiecesGap() qreal VPuzzleLayout::GetPiecesGap()
{ {
return m_piecesGap; return m_piecesGap;
} }
//---------------------------------------------------------------------------------------------------------------------
qreal VPuzzleLayout::GetPiecesGapConverted()
{
return UnitConvertor(m_piecesGap, Unit::Px, m_unit);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetWarningSuperpositionOfPieces(bool state) void VPuzzleLayout::SetWarningSuperpositionOfPieces(bool state)
{ {

View File

@ -53,20 +53,112 @@ public:
void SetUnit(Unit unit); void SetUnit(Unit unit);
Unit getUnit(); Unit getUnit();
/**
* @brief SetLayoutSize sets the size of the layout, the values have to be in Unit::Px
* @param width
* @param height
*/
void SetLayoutSize(qreal width, qreal height); void SetLayoutSize(qreal width, qreal height);
/**
* @brief SetLayoutSize sets the size of the layout, the values have to be in the layout's unit
* @param width
* @param height
*/
void SetLayoutSizeConverted(qreal width, qreal height);
/**
* @brief SetLayoutSize sets the size of the layout, the values have to be in Unit::Px
* @param size
*/
void SetLayoutSize(QSizeF size); void SetLayoutSize(QSizeF size);
/**
* @brief SetLayoutSizeConverted sets the size of the layout, the values have to be in the layout's unit
* @param size
*/
void SetLayoutSizeConverted(QSizeF size);
/**
* @brief GetLayoutSize Returns the size in Unit::Px
* @return
*/
QSizeF GetLayoutSize(); QSizeF GetLayoutSize();
/**
* @brief GetLayoutSizeConverted Returns the size in the layout's unit
* @return
*/
QSizeF GetLayoutSizeConverted();
/**
* @brief SetLayoutMargins, set the margins of the layout, the values have to be in Unit::Px
* @param left in Unit::Px
* @param top in Unit::Px
* @param right in Unit::Px
* @param bottom in Unit::Px
*/
void SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom); void SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom);
/**
* @brief SetLayoutMargins, set the margins of the layout, the values have to be in the unit of the layout
* @param left in Unit::Px
* @param top in Unit::Px
* @param right in Unit::Px
* @param bottom in Unit::Px
*/
void SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom);
/**
* @brief SetLayoutMargins set the margins of the layout, the values have to be in Unit::Px
* @param margins
*/
void SetLayoutMargins(QMarginsF margins); void SetLayoutMargins(QMarginsF margins);
/**
* @brief SetLayoutMargins set the margins of the layout, the values have to be in the unit of the layout
* @param margins
*/
void SetLayoutMarginsConverted(QMarginsF margins);
/**
* @brief GetLayoutMargins Returns the size in Unit::Px
* @return
*/
QMarginsF GetLayoutMargins(); QMarginsF GetLayoutMargins();
/**
* @brief GetLayoutMarginsConverted Returns the margins in the layout's unit
* @return
*/
QMarginsF GetLayoutMarginsConverted();
void SetFollowGrainline(FollowGrainline state); void SetFollowGrainline(FollowGrainline state);
FollowGrainline SetFollowGrainline(); FollowGrainline SetFollowGrainline();
/**
* @brief SetPiecesGap sets the pieces gap to the given value, the unit has to be in Unit::Px
* @param value
*/
void SetPiecesGap(qreal value); void SetPiecesGap(qreal value);
/**
* @brief SetPiecesGapConverted sets the pieces gap to the given value, the unit has to be in the layout's unit
* @param value
*/
void SetPiecesGapConverted(qreal value);
/**
* @brief GetPiecesGap returns the pieces gap in Unit::Px
* @return
*/
qreal GetPiecesGap(); qreal GetPiecesGap();
/**
* @brief GetPiecesGapConverted returns the pieces gap in the layout's unit
* @return
*/
qreal GetPiecesGapConverted();
void SetWarningSuperpositionOfPieces(bool state); void SetWarningSuperpositionOfPieces(bool state);
bool GetWarningSuperpositionOfPieces(); bool GetWarningSuperpositionOfPieces();
@ -83,13 +175,23 @@ private:
// format // format
Unit m_unit; Unit m_unit;
/**
* @brief m_size the Size in Unit::Px
*/
QSizeF m_size; QSizeF m_size;
// margins // margins
/**
* @brief m_margins the margins in Unit::Px
*/
QMarginsF m_margins; QMarginsF m_margins;
// control // control
FollowGrainline m_followGrainLine; FollowGrainline m_followGrainLine;
/**
* @brief m_piecesGap the pieces gap in Unit::Px
*/
qreal m_piecesGap; qreal m_piecesGap;
bool m_warningSuperpositionOfPieces; bool m_warningSuperpositionOfPieces;
bool m_warningPiecesOutOfBound; bool m_warningPiecesOutOfBound;

View File

@ -44,6 +44,9 @@ public:
bool ReadFile(VPuzzleLayout *layout, QFile *file); bool ReadFile(VPuzzleLayout *layout, QFile *file);
private: private:
/**
* @brief m_layoutFormatVersion holds the version of the layout currently being read
*/
int m_layoutFormatVersion; int m_layoutFormatVersion;
void ReadLayout(VPuzzleLayout *layout); void ReadLayout(VPuzzleLayout *layout);