2020-04-13 12:43:27 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 14:29:18 +02:00
|
|
|
** @file vpcarrousel.cpp
|
2020-04-13 12:43:27 +02:00
|
|
|
** @author Ronan Le Tiec
|
|
|
|
** @date 13 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:29:18 +02:00
|
|
|
#include "vpcarrousel.h"
|
|
|
|
#include "ui_vpcarrousel.h"
|
2020-04-13 12:24:26 +02:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QMessageBox>
|
2020-05-05 17:40:36 +02:00
|
|
|
#include <QScrollBar>
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-13 14:27:52 +02:00
|
|
|
#include "../vmisc/backport/qoverload.h"
|
2020-05-11 16:48:08 +02:00
|
|
|
#include "vpuzzlelayer.h"
|
2020-04-13 14:27:52 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
#include <QLoggingCategory>
|
2020-05-11 16:48:08 +02:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QPainter>
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel")
|
|
|
|
|
2020-04-13 12:24:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
VPCarrousel::VPCarrousel(VPuzzleLayout *layout, QWidget *parent) :
|
2020-04-13 12:24:26 +02:00
|
|
|
QWidget(parent),
|
2020-05-23 14:29:18 +02:00
|
|
|
ui(new Ui::VPCarrousel),
|
2020-05-11 16:48:08 +02:00
|
|
|
m_layout(layout)
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->setupUi(this);
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
// init the combo box
|
2020-05-11 16:48:08 +02:00
|
|
|
connect(ui->comboBoxLayer, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2020-05-23 14:29:18 +02:00
|
|
|
&VPCarrousel::on_ActiveLayerChanged);
|
2020-04-26 12:09:28 +02:00
|
|
|
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
// ------ then we fill the carrousel with the layout content
|
2020-05-11 16:48:08 +02:00
|
|
|
Refresh();
|
|
|
|
}
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
void VPCarrousel::Refresh()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
|
|
|
// NOTE: alternative to clearing the carrousel and adding things again, we could make comparision
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
// --- clears the content of the carrousel
|
|
|
|
Clear();
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
// --- add the content saved in the layout to the carrousel.
|
2020-05-11 16:48:08 +02:00
|
|
|
// Do not rely on m_layout because we do not control it.
|
|
|
|
m_layers = m_layout->GetLayers();
|
|
|
|
m_layers.prepend(m_layout->GetUnplacedPiecesLayer());
|
2020-04-26 12:09:28 +02:00
|
|
|
|
2020-05-11 16:48:08 +02:00
|
|
|
for (auto layer : m_layers)
|
2020-04-13 12:24:26 +02:00
|
|
|
{
|
2020-04-26 12:09:28 +02:00
|
|
|
// add layer name to combo
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->comboBoxLayer->blockSignals(true);
|
|
|
|
ui->comboBoxLayer->addItem(layer->GetName());
|
|
|
|
ui->comboBoxLayer->blockSignals(false);
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-26 22:32:08 +02:00
|
|
|
on_ActiveLayerChanged(0);
|
2020-05-02 12:17:06 +02:00
|
|
|
|
|
|
|
RefreshOrientation();
|
2020-04-13 12:24:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
void VPCarrousel::Clear()
|
2020-04-13 12:24:26 +02:00
|
|
|
{
|
2020-04-26 12:09:28 +02:00
|
|
|
// remove the combobox entries
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->comboBoxLayer->clear();
|
2020-04-26 12:09:28 +02:00
|
|
|
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->clear();
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
2020-04-13 12:24:26 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
void VPCarrousel::on_ActiveLayerChanged(int index)
|
2020-04-13 12:24:26 +02:00
|
|
|
{
|
2020-04-26 12:09:28 +02:00
|
|
|
qCDebug(pCarrousel, "index changed %i", index);
|
|
|
|
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->clear();
|
|
|
|
|
|
|
|
if (index >= 0 && index < m_layers.size())
|
|
|
|
{
|
|
|
|
VPuzzleLayer *layer = m_layers.at(index);
|
|
|
|
|
|
|
|
if (layer)
|
|
|
|
{
|
|
|
|
QList<VPuzzlePiece*> pieces = layer->GetPieces();
|
|
|
|
|
|
|
|
for (auto piece : pieces)
|
|
|
|
{
|
|
|
|
new QListWidgetItem(piece->PieceIcon(QSize(120, 120)) , piece->GetName(), ui->listWidget);
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 12:24:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
void VPCarrousel::SetOrientation(Qt::Orientation orientation)
|
2020-04-13 12:24:26 +02:00
|
|
|
{
|
2020-05-02 12:17:06 +02:00
|
|
|
m_orientation = orientation;
|
|
|
|
RefreshOrientation();
|
|
|
|
}
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-05-02 12:17:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
void VPCarrousel::RefreshOrientation()
|
2020-05-02 12:17:06 +02:00
|
|
|
{
|
2020-04-26 14:03:43 +02:00
|
|
|
// then update the scrollarea min height / width and scrollbar behaviour
|
2020-05-02 12:17:06 +02:00
|
|
|
if(m_orientation == Qt::Horizontal)
|
2020-04-13 12:24:26 +02:00
|
|
|
{
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2020-04-26 14:03:43 +02:00
|
|
|
|
|
|
|
// scroll bar policy of scroll area
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
2020-04-26 14:03:43 +02:00
|
|
|
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->setFlow(QListView::TopToBottom);
|
2020-04-13 12:24:26 +02:00
|
|
|
}
|
|
|
|
else // Qt::Vertical
|
|
|
|
{
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-26 14:03:43 +02:00
|
|
|
// scroll bar policy of scroll area
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-05-11 16:48:08 +02:00
|
|
|
ui->listWidget->setFlow(QListView::LeftToRight);
|
2020-04-13 12:24:26 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-06 15:05:01 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:29:18 +02:00
|
|
|
void VPCarrousel::ClearSelection()
|
2020-05-06 15:05:01 +02:00
|
|
|
{
|
|
|
|
m_layout->ClearSelection();
|
|
|
|
}
|