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-05-24 14:55:03 +02:00
|
|
|
#include <QFontMetrics>
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2020-04-13 14:27:52 +02:00
|
|
|
#include "../vmisc/backport/qoverload.h"
|
2020-05-23 15:29:57 +02:00
|
|
|
#include "vppiecelist.h"
|
2020-05-23 17:47:04 +02:00
|
|
|
#include "vpsheet.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 15:34:11 +02:00
|
|
|
VPCarrousel::VPCarrousel(VPLayout *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-05-24 19:53:51 +02:00
|
|
|
ui->listWidget->SetCarrousel(this);
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
// init the combo box
|
2020-05-23 15:29:57 +02:00
|
|
|
connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&VPCarrousel::on_ActivePieceListChanged);
|
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
|
|
|
{
|
2021-05-27 14:55:25 +02:00
|
|
|
const int index = ui->comboBoxPieceList->currentIndex();
|
|
|
|
|
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.
|
2021-05-27 14:55:25 +02:00
|
|
|
m_pieceLists = QList<VPCarrouselSheet>();
|
2020-05-24 19:53:51 +02:00
|
|
|
|
2021-05-27 14:55:25 +02:00
|
|
|
if (m_layout != nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
VPCarrouselSheet carrouselSheet;
|
|
|
|
carrouselSheet.unplaced = true;
|
|
|
|
carrouselSheet.name = tr("Unplaced pieces");
|
|
|
|
carrouselSheet.pieces = m_layout->GetUnplacedPieceList();
|
|
|
|
|
|
|
|
m_pieceLists.append(carrouselSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<VPSheet *> sheets = m_layout->GetSheets();
|
|
|
|
for (auto *sheet : sheets)
|
|
|
|
{
|
|
|
|
VPCarrouselSheet carrouselSheet;
|
|
|
|
carrouselSheet.unplaced = false;
|
|
|
|
carrouselSheet.name = sheet->GetName();
|
|
|
|
carrouselSheet.pieces = sheet->GetPieceList();
|
|
|
|
|
|
|
|
m_pieceLists.append(carrouselSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->comboBoxPieceList->blockSignals(true);
|
|
|
|
|
|
|
|
for (const auto& sheet: m_pieceLists)
|
|
|
|
{
|
|
|
|
ui->comboBoxPieceList->addItem(GetSheetName(sheet));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->comboBoxPieceList->blockSignals(false);
|
|
|
|
}
|
2020-04-13 12:24:26 +02:00
|
|
|
|
2021-05-27 20:11:32 +02:00
|
|
|
ui->comboBoxPieceList->setCurrentIndex(-1);
|
|
|
|
ui->comboBoxPieceList->setCurrentIndex(index != -1 ? index : 0);
|
2020-05-02 12:17:06 +02:00
|
|
|
|
|
|
|
RefreshOrientation();
|
2020-04-13 12:24:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:45:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 14:55:25 +02:00
|
|
|
void VPCarrousel::RefreshSheetNames()
|
2020-11-21 13:45:26 +01:00
|
|
|
{
|
2021-05-27 14:55:25 +02:00
|
|
|
// Here we assume that order and number of sheets are the same in layout and here
|
|
|
|
QList<VPSheet *> sheets = m_layout->GetSheets();
|
|
|
|
if (m_pieceLists.size() != sheets.size()+1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-11-21 13:45:26 +01:00
|
|
|
|
2021-05-27 14:55:25 +02:00
|
|
|
for (int i=0; i < sheets.size(); ++i)
|
|
|
|
{
|
|
|
|
m_pieceLists[i+1].name = sheets.at(i)->GetName();
|
|
|
|
ui->comboBoxPieceList->setItemText(i+1, GetSheetName(m_pieceLists.at(i+1)));
|
|
|
|
}
|
2020-11-21 13:45:26 +01:00
|
|
|
}
|
|
|
|
|
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-23 15:29:57 +02:00
|
|
|
ui->comboBoxPieceList->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 15:29:57 +02:00
|
|
|
void VPCarrousel::on_ActivePieceListChanged(int index)
|
2020-04-13 12:24:26 +02:00
|
|
|
{
|
2020-04-26 12:09:28 +02:00
|
|
|
qCDebug(pCarrousel, "index changed %i", index);
|
|
|
|
|
2021-05-27 14:55:25 +02:00
|
|
|
if (not m_pieceLists.isEmpty() && index >= 0 && index < m_pieceLists.size())
|
2020-05-11 16:48:08 +02:00
|
|
|
{
|
2021-05-27 14:55:25 +02:00
|
|
|
ui->listWidget->SetCurrentPieceList(m_pieceLists.at(index).pieces);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->listWidget->SetCurrentPieceList(nullptr);
|
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-23 15:29:57 +02:00
|
|
|
ui->comboBoxPieceList->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-23 15:29:57 +02:00
|
|
|
ui->comboBoxPieceList->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
|
|
|
{
|
2021-05-27 14:55:25 +02:00
|
|
|
if (m_layout != nullptr)
|
|
|
|
{
|
|
|
|
m_layout->ClearSelection();
|
|
|
|
}
|
2020-05-06 15:05:01 +02:00
|
|
|
}
|
2020-05-24 19:53:51 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPCarrousel::ClearSelectionExceptForCurrentPieceList()
|
|
|
|
{
|
|
|
|
if (m_layout != nullptr)
|
|
|
|
{
|
|
|
|
m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList());
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 14:55:25 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPCarrousel::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
{
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
|
|
|
|
RefreshSheetNames();
|
|
|
|
on_ActivePieceListChanged(ui->comboBoxPieceList->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember to call base class implementation
|
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPCarrousel::GetSheetName(const VPCarrouselSheet &sheet) -> QString
|
|
|
|
{
|
|
|
|
return sheet.unplaced ? sheet.name : tr("Pieces of ") + sheet.name;
|
|
|
|
}
|