2020-04-26 12:09:28 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 14:33:02 +02:00
|
|
|
** @file vpcarrouselpiecelist.cpp
|
2020-04-26 12:09:28 +02:00
|
|
|
** @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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2020-05-23 14:33:02 +02:00
|
|
|
#include "vpcarrouselpiecelist.h"
|
2020-05-23 14:29:18 +02:00
|
|
|
#include "vpcarrousel.h"
|
2020-05-09 12:57:42 +02:00
|
|
|
#include "../vmisc/backport/qoverload.h"
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer")
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
VPCarrouselPieceList::VPCarrouselPieceList(VPuzzleLayer *layer, VPCarrousel *carrousel) :
|
2020-05-02 09:44:45 +02:00
|
|
|
m_layer(layer),
|
2020-05-06 15:05:01 +02:00
|
|
|
m_carrousel(carrousel),
|
2020-05-02 09:44:45 +02:00
|
|
|
m_carrouselPieces(QList<VPieceCarrouselPiece*>())
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
VPCarrouselPieceList::~VPCarrouselPieceList()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
2020-05-08 23:49:41 +02:00
|
|
|
Clear();
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::Init()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
|
|
|
// initiales the structure
|
|
|
|
QVBoxLayout *layoutPiecesLayout = new QVBoxLayout();
|
|
|
|
layoutPiecesLayout->setMargin(0);
|
|
|
|
setLayout(layoutPiecesLayout);
|
|
|
|
|
|
|
|
// then refresh the content
|
|
|
|
Refresh();
|
2020-05-08 23:49:41 +02:00
|
|
|
|
|
|
|
// add the connections
|
2020-05-23 14:33:02 +02:00
|
|
|
connect(m_layer, &VPuzzleLayer::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
|
|
|
|
connect(m_layer, &VPuzzleLayer::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::Refresh()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
2020-05-08 23:49:41 +02:00
|
|
|
Clear();
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
// Updates the carrousel pieces from the pieces list
|
|
|
|
QList<VPuzzlePiece*> pieces = m_layer->GetPieces();
|
|
|
|
|
2020-04-26 14:03:43 +02:00
|
|
|
// 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
|
2020-04-26 22:32:08 +02:00
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
bool _isVisible = isVisible();
|
|
|
|
setVisible(true);
|
2020-04-26 12:09:28 +02:00
|
|
|
for (auto piece : pieces)
|
|
|
|
{
|
2020-05-06 15:05:01 +02:00
|
|
|
VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece, this);
|
2020-04-26 12:09:28 +02:00
|
|
|
m_carrouselPieces.append(carrouselPiece);
|
|
|
|
layout()->addWidget(carrouselPiece);
|
2020-05-08 23:49:41 +02:00
|
|
|
carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed.
|
|
|
|
}
|
|
|
|
setVisible(_isVisible);
|
|
|
|
}
|
2020-04-26 22:32:08 +02:00
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::Clear()
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
|
|
|
// Removes and deletes the carrousel pieces from the layer
|
|
|
|
while (!m_carrouselPieces.isEmpty())
|
|
|
|
{
|
|
|
|
VPieceCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast();
|
|
|
|
|
|
|
|
if(carrouselPiece != nullptr)
|
|
|
|
{
|
|
|
|
layout()->removeWidget(carrouselPiece);
|
|
|
|
delete carrouselPiece;
|
|
|
|
}
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
2020-05-08 23:49:41 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
2020-05-01 18:26:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
QList<VPieceCarrouselPiece*> VPCarrouselPieceList::GetCarrouselPieces()
|
2020-05-01 18:26:02 +02:00
|
|
|
{
|
|
|
|
return m_carrouselPieces;
|
|
|
|
}
|
|
|
|
|
2020-05-06 15:05:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
VPCarrousel* VPCarrouselPieceList::GetCarrousel()
|
2020-05-06 15:05:01 +02:00
|
|
|
{
|
|
|
|
return m_carrousel;
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
VPuzzleLayer* VPCarrouselPieceList::GetLayer()
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
|
|
|
return m_layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::on_PieceAdded(VPuzzlePiece* piece)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(piece)
|
|
|
|
|
|
|
|
// TODO/ FIXME: see if we find a solution more efficient refreshing the complete layout everytime.
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::on_PieceRemoved(VPuzzlePiece* piece)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
|
|
|
for (auto carrouselPiece : m_carrouselPieces)
|
|
|
|
{
|
|
|
|
if(carrouselPiece->GetPiece() == piece)
|
|
|
|
{
|
|
|
|
m_carrouselPieces.removeAll(carrouselPiece);
|
|
|
|
layout()->removeWidget(carrouselPiece);
|
|
|
|
delete carrouselPiece;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|