Optimize the carrousel piece fitInView

This commit is contained in:
Ronan Le Tiec 2020-04-26 22:32:08 +02:00
parent 4edcbfd0c5
commit 7bca5f41ec
4 changed files with 19 additions and 1 deletions

View file

@ -121,7 +121,7 @@ void VPieceCarrousel::Refresh()
m_layersContainer->layout()->addWidget(carrouselLayer); m_layersContainer->layout()->addWidget(carrouselLayer);
} }
m_comboBoxLayer->setCurrentIndex(0); on_ActiveLayerChanged(0);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -72,6 +72,7 @@ void VPieceCarrouselLayer::Refresh()
[](const VPuzzlePiece* a, const VPuzzlePiece* b) -> bool { return a->GetName() < b->GetName();}); [](const VPuzzlePiece* a, const VPuzzlePiece* b) -> bool { return a->GetName() < b->GetName();});
// create the corresponding carrousel pieces // create the corresponding carrousel pieces
for (auto piece : pieces) for (auto piece : pieces)
{ {
// qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str()); // qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str());
@ -79,5 +80,11 @@ void VPieceCarrouselLayer::Refresh()
VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece); VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece);
m_carrouselPieces.append(carrouselPiece); m_carrouselPieces.append(carrouselPiece);
layout()->addWidget(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);
} }
} }

View file

@ -79,6 +79,12 @@ void VPieceCarrouselPiece::Init()
Refresh(); Refresh();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::CleanPreview()
{
m_graphicsView->fitInView(m_graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::Refresh() void VPieceCarrouselPiece::Refresh()
{ {

View file

@ -44,6 +44,11 @@ public:
void Init(); void Init();
void Refresh(); 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();
signals: signals: