Optimizing the piece carrousel

This commit is contained in:
Ronan Le Tiec 2020-05-02 12:17:06 +02:00
parent e27e543fbc
commit 497cb65cb2
6 changed files with 73 additions and 9 deletions

View File

@ -144,6 +144,14 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
// TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece()
// TODO / FIXME: make a few tests, on the data to check for validity. If not
//
// If seam allowance enabled, but the path is empty — invalid.
// If seam line path not hidden, but the path is empty — invalid.
// If seam allowance is built-in, but the seam line path is empty — invalid.
VPuzzlePiece *piece = CreatePiece(rawPiece); VPuzzlePiece *piece = CreatePiece(rawPiece);
m_layout->GetUnplacedPiecesLayer()->AddPiece(piece); m_layout->GetUnplacedPiecesLayer()->AddPiece(piece);
} }
@ -165,10 +173,12 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece) VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece)
{ {
VPuzzlePiece *piece = new VPuzzlePiece(); VPuzzlePiece *piece = new VPuzzlePiece();
piece->SetName(rawPiece.GetName()); piece->SetName(rawPiece.GetName());
piece->SetUuid(rawPiece.GetUUID()); piece->SetUuid(rawPiece.GetUUID());
piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints()); piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints());
piece->SetSeamLine(rawPiece.GetMappedContourPoints());
// TODO : set all the information we need for the piece! // TODO : set all the information we need for the piece!

View File

@ -75,8 +75,10 @@ void VPieceCarrousel::Init()
QVBoxLayout *layersContainerLayout = new QVBoxLayout(); QVBoxLayout *layersContainerLayout = new QVBoxLayout();
layersContainerLayout->setMargin(0); layersContainerLayout->setMargin(0);
m_layersContainer->setLayout(layersContainerLayout); m_layersContainer->setLayout(layersContainerLayout);
m_layersContainer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding); QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);
layersContainerWrapperLayout->addWidget(m_layersContainer); layersContainerWrapperLayout->addWidget(m_layersContainer);
layersContainerWrapperLayout->addSpacerItem(spacer); layersContainerWrapperLayout->addSpacerItem(spacer);
@ -92,9 +94,6 @@ void VPieceCarrousel::Init()
// ------ then we fill the carrousel with the layout content // ------ then we fill the carrousel with the layout content
Refresh(); Refresh();
// ------ and make sure the calculation for the qlayout is right
SetOrientation(Qt::Vertical);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -126,6 +125,8 @@ void VPieceCarrousel::Refresh()
} }
on_ActiveLayerChanged(0); on_ActiveLayerChanged(0);
RefreshOrientation();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -188,8 +189,14 @@ void VPieceCarrousel::on_ActiveLayerChanged(int index)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
{ {
m_orientation = orientation;
RefreshOrientation();
}
QBoxLayout::Direction direction = (orientation == Qt::Horizontal)? //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrousel::RefreshOrientation()
{
QBoxLayout::Direction direction = (m_orientation == Qt::Horizontal)?
QBoxLayout::LeftToRight QBoxLayout::LeftToRight
: :
QBoxLayout::TopToBottom; QBoxLayout::TopToBottom;
@ -207,7 +214,7 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
} }
// then update the scrollarea min height / width and scrollbar behaviour // then update the scrollarea min height / width and scrollbar behaviour
if(orientation == Qt::Horizontal) if(m_orientation == Qt::Horizontal)
{ {
m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@ -232,7 +239,6 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
m_scrollArea->setMinimumWidth(124 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2); m_scrollArea->setMinimumWidth(124 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2);
// FIXME: find a nicer way than putting directly the 120 width of the piece // FIXME: find a nicer way than putting directly the 120 width of the piece
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -43,8 +43,19 @@ public:
explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr); explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr);
virtual ~VPieceCarrousel(); virtual ~VPieceCarrousel();
/**
* @brief SetOrientation Sets the orientation to the given value and refreshes
* the orientation of the carrousel.
* @param orientation the orientation to set the carrousel to.
*/
void SetOrientation(Qt::Orientation orientation); void SetOrientation(Qt::Orientation orientation);
/**
* @brief RefreshOrientation Refreshes the orientation of the carrousel with the
* m_orientation value;
*/
void RefreshOrientation();
/** /**
* @brief Inits the carroussel * @brief Inits the carroussel
*/ */
@ -85,6 +96,8 @@ private:
QList<VPieceCarrouselLayer*> m_carrouselLayers; QList<VPieceCarrouselLayer*> m_carrouselLayers;
Qt::Orientation m_orientation{Qt::Vertical};
private slots: private slots:
void on_ActiveLayerChanged(int index); void on_ActiveLayerChanged(int index);

View File

@ -72,6 +72,7 @@ void VPieceCarrouselPiece::Init()
m_graphicsView->setScene(graphicsScene); m_graphicsView->setScene(graphicsScene);
m_graphicsView->setFixedSize(120,100); m_graphicsView->setFixedSize(120,100);
m_graphicsView->setStyleSheet("border: 4px solid transparent;"); m_graphicsView->setStyleSheet("border: 4px solid transparent;");
m_graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
// define the label // define the label
m_label = new QLabel(); m_label = new QLabel();
@ -98,9 +99,11 @@ void VPieceCarrouselPiece::Refresh()
{ {
// update the graphic view / the scene // update the graphic view / the scene
// TODO / FIXME : not perfect and maybe not the right way, still need to work on this QVector<QPointF> points = m_piece->GetSeamLine();
// for instance: use a painter to habve a better quality, less pixeled. if(points.isEmpty())
QVector<QPointF> points = m_piece->GetCuttingLine(); {
points = m_piece->GetCuttingLine();
}
QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
pen.setCosmetic(true); pen.setCosmetic(true);

View File

@ -79,6 +79,17 @@ void VPuzzlePiece::SetCuttingLine(const QVector<QPointF> &cuttingLine)
m_cuttingLine = cuttingLine; m_cuttingLine = cuttingLine;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VPuzzlePiece::GetSeamLine() const
{
return m_seamLine;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetSeamLine(const QVector<QPointF> &seamLine)
{
m_seamLine = seamLine;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPuzzlePiece::GetShowSeamLine() bool VPuzzlePiece::GetShowSeamLine()

View File

@ -61,10 +61,30 @@ public:
*/ */
void SetUuid(const QUuid &uuid); void SetUuid(const QUuid &uuid);
/**
* @brief GetCuttingLine Returns the vector points of the cutting line
* @return the vector points of the cutting line
*/
QVector<QPointF> GetCuttingLine() const; QVector<QPointF> GetCuttingLine() const;
/**
* @brief SetCuttingLine Sets the vector points of the cutting line to the given value
* @param cuttingLine the new vector points for the cutting line
*/
void SetCuttingLine(const QVector<QPointF> &cuttingLine); void SetCuttingLine(const QVector<QPointF> &cuttingLine);
/**
* @brief GetSeamLine Returns the vector points of the seam line
* @return the vector points of the seam line
*/
QVector<QPointF> GetSeamLine() const;
/**
* @brief SetSeamLine Sets the vector points of the seam line to the given value
* @param seamLine the new vector points for the seam line
*/
void SetSeamLine(const QVector<QPointF> &seamLine);
/** /**
* @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not * @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 * @return true if the seamline has to be shown
@ -94,6 +114,7 @@ private:
QUuid m_uuid{QUuid()}; QUuid m_uuid{QUuid()};
QString m_name{QString()}; QString m_name{QString()};
QVector<QPointF> m_cuttingLine{QVector<QPointF>()}; QVector<QPointF> m_cuttingLine{QVector<QPointF>()};
QVector<QPointF> m_seamLine{QVector<QPointF>()};
bool m_showSeamline{true}; bool m_showSeamline{true};
bool m_mirrorPiece{false}; bool m_mirrorPiece{false};
}; };