Refactoring Piece carrousel
This commit is contained in:
parent
b4b77c4cdf
commit
f00168e59b
|
@ -8,7 +8,6 @@ SOURCES += \
|
|||
$$PWD/vpcarrousel.cpp \
|
||||
$$PWD/vpcarrouselpiece.cpp \
|
||||
$$PWD/vpcarrouselpiecelist.cpp \
|
||||
$$PWD/vpcarrouselpiecepreview.cpp \
|
||||
$$PWD/vpcommandline.cpp \
|
||||
$$PWD/vpcommands.cpp \
|
||||
$$PWD/vpgraphicspiece.cpp \
|
||||
|
@ -33,7 +32,6 @@ HEADERS += \
|
|||
$$PWD/vpcarrousel.h \
|
||||
$$PWD/vpcarrouselpiece.h \
|
||||
$$PWD/vpcarrouselpiecelist.h \
|
||||
$$PWD/vpcarrouselpiecepreview.h \
|
||||
$$PWD/vpcommandline.h \
|
||||
$$PWD/vpcommands.h \
|
||||
$$PWD/vpgraphicspiece.h \
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
#include <QFontMetrics>
|
||||
|
||||
#include "../vmisc/backport/qoverload.h"
|
||||
#include "vppiecelist.h"
|
||||
|
@ -53,8 +54,6 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
|
|||
connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&VPCarrousel::on_ActivePieceListChanged);
|
||||
|
||||
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// ------ then we fill the carrousel with the layout content
|
||||
Refresh();
|
||||
}
|
||||
|
@ -103,21 +102,11 @@ void VPCarrousel::on_ActivePieceListChanged(int index)
|
|||
{
|
||||
qCDebug(pCarrousel, "index changed %i", index);
|
||||
|
||||
ui->listWidget->clear();
|
||||
|
||||
if (index >= 0 && index < m_pieceLists.size())
|
||||
{
|
||||
VPPieceList *pieceList = m_pieceLists.at(index);
|
||||
|
||||
if (pieceList)
|
||||
{
|
||||
QList<VPPiece*> pieces = pieceList->GetPieces();
|
||||
|
||||
for (auto piece : pieces)
|
||||
{
|
||||
new QListWidgetItem(piece->PieceIcon(QSize(120, 120)) , piece->GetName(), ui->listWidget);
|
||||
}
|
||||
}
|
||||
ui->listWidget->SetCurrentPieceList(pieceList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<widget class="VPCarrouselPieceList" name="listWidget">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
|
@ -72,6 +72,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>VPCarrouselPieceList</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>vpcarrouselpiecelist.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -28,12 +28,6 @@
|
|||
|
||||
#include "vpcarrouselpiece.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPainter>
|
||||
#include <QDrag>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
|
||||
|
@ -48,103 +42,22 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
|
|||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, VPCarrouselPieceList *carrouselPieceList) :
|
||||
m_piece(piece),
|
||||
m_carrouselPieceList(carrouselPieceList),
|
||||
m_dragStart(QPoint())
|
||||
VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
|
||||
QListWidgetItem(parent,1001),
|
||||
m_piece(piece)
|
||||
{
|
||||
Init();
|
||||
int width = 120 - 8;
|
||||
QFontMetrics metrix = QFontMetrics(QFont());
|
||||
QString clippedText = metrix.elidedText(piece->GetName(), Qt::ElideRight, width);
|
||||
setIcon(m_piece->PieceIcon(QSize(120, 120)));
|
||||
setText(clippedText);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrouselPiece::~VPCarrouselPiece()
|
||||
{
|
||||
delete m_piecePreview;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::Init()
|
||||
{
|
||||
// Define the structure
|
||||
setFixedSize(124,128);
|
||||
QVBoxLayout *pieceLayout = new QVBoxLayout();
|
||||
pieceLayout->setMargin(0);
|
||||
pieceLayout->setSpacing(0);
|
||||
setLayout(pieceLayout);
|
||||
|
||||
setStyleSheet("background-color:white; border: 2px solid transparent;");
|
||||
|
||||
// define the preview of the piece
|
||||
m_piecePreview = new VPCarrouselPiecePreview(this);
|
||||
|
||||
// m_graphicsView = new VMainGraphicsView(this);
|
||||
// --> undefined reference to 'VMainGraphicsView::VMainGraphicView(QWidget*)'
|
||||
QGraphicsScene *graphicsScene = new QGraphicsScene(this);
|
||||
m_piecePreview->setScene(graphicsScene);
|
||||
m_piecePreview->setFixedSize(120,100);
|
||||
m_piecePreview->setStyleSheet("border: 4px solid transparent;");
|
||||
m_piecePreview->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
|
||||
// define the label
|
||||
m_label = new QLabel();
|
||||
m_label->sizePolicy();
|
||||
m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
m_label->setFixedSize(120,24);
|
||||
m_label->setStyleSheet("border: 0px;");
|
||||
m_label->setMouseTracking(false);
|
||||
|
||||
pieceLayout->addWidget(m_piecePreview);
|
||||
pieceLayout->addWidget(m_label);
|
||||
|
||||
|
||||
// connect the signals
|
||||
connect(m_piece, &VPPiece::SelectionChanged, this, &VPCarrouselPiece::on_PieceSelectionChanged);
|
||||
|
||||
// then refresh the data
|
||||
Refresh();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::CleanPreview()
|
||||
{
|
||||
m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::Refresh()
|
||||
{
|
||||
// update the graphic view / the scene
|
||||
|
||||
QVector<QPointF> points = m_piece->GetSeamLine();
|
||||
if(points.isEmpty())
|
||||
{
|
||||
points = m_piece->GetCuttingLine();
|
||||
}
|
||||
|
||||
QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
||||
pen.setCosmetic(true);
|
||||
QBrush noBrush(Qt::NoBrush);
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo(points.first());
|
||||
for (int i = 1; i < points.size(); ++i)
|
||||
path.lineTo(points.at(i));
|
||||
m_piecePreview->scene()->addPath(path, pen, noBrush);
|
||||
|
||||
m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio);
|
||||
|
||||
// update the label of the piece
|
||||
QFontMetrics metrix(m_label->font());
|
||||
int width = m_label->width() - 8;
|
||||
QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width);
|
||||
m_label->setText(clippedText);
|
||||
|
||||
// set the tooltip
|
||||
setToolTip(m_piece->GetName());
|
||||
|
||||
// set the selection state correctly.
|
||||
on_PieceSelectionChanged();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -154,138 +67,62 @@ VPPiece * VPCarrouselPiece::GetPiece()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::on_PieceSelectionChanged()
|
||||
void VPCarrouselPiece::RefreshSelection()
|
||||
{
|
||||
if(m_piece->GetIsSelected())
|
||||
{
|
||||
setStyleSheet("background-color:white; border: 2px solid red;");
|
||||
}
|
||||
else
|
||||
{
|
||||
setStyleSheet("background-color:white; border: 2px solid transparent;");
|
||||
}
|
||||
setSelected(m_piece->GetIsSelected());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
qCDebug(pCarrouselPiece, "mouse pressed");
|
||||
////---------------------------------------------------------------------------------------------------------------------
|
||||
//void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
|
||||
//{
|
||||
// QMenu contextMenu;
|
||||
|
||||
// VPPieceList* unplacedPieces = m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList();
|
||||
// QList<VPSheet*> sheets = m_piece->GetPieceList()->GetLayout()->GetSheets();
|
||||
// QList<VPPieceList*> pieceLists = QList<VPPieceList*>();
|
||||
// for (auto sheet : sheets)
|
||||
// {
|
||||
// pieceLists.append(sheet->GetPieceList());
|
||||
// }
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
if(!(event->modifiers() & Qt::ControlModifier))
|
||||
{
|
||||
m_carrouselPieceList->GetCarrousel()->ClearSelection();
|
||||
m_piece->SetIsSelected(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_piece->SetIsSelected(!m_piece->GetIsSelected());
|
||||
}
|
||||
// // move to piece list actions -- TODO : To be tested properly when we have several piece lists
|
||||
// pieceLists.removeAll(m_piece->GetPieceList());
|
||||
// if(pieceLists.count() > 0)
|
||||
// {
|
||||
// QMenu *moveMenu = contextMenu.addMenu(tr("Move to"));
|
||||
|
||||
m_dragStart = event->pos();
|
||||
}
|
||||
}
|
||||
// // TODO order in alphabetical order
|
||||
|
||||
// for (auto pieceList : pieceLists)
|
||||
// {
|
||||
// QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
|
||||
// QVariant data = QVariant::fromValue(pieceList);
|
||||
// moveToPieceList->setData(data);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!(event->buttons() & Qt::LeftButton))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// connect(moveToPieceList, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
|
||||
// }
|
||||
// }
|
||||
|
||||
if(m_piece->GetPieceList() != m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// // remove from piece list action
|
||||
// if(m_piece->GetPieceList() != unplacedPieces)
|
||||
// {
|
||||
// QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet"));
|
||||
// QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
|
||||
// removeAction->setData(data);
|
||||
// connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
|
||||
// }
|
||||
|
||||
if((event->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// contextMenu.exec(event->globalPos());
|
||||
//}
|
||||
|
||||
// make sure the multiple selection is removed
|
||||
m_carrouselPieceList->GetCarrousel()->ClearSelection();
|
||||
m_piece->SetIsSelected(true);
|
||||
|
||||
// starts the dragging
|
||||
QDrag *drag = new QDrag(this);
|
||||
VPMimeDataPiece *mimeData = new VPMimeDataPiece();
|
||||
mimeData->SetPiecePtr(m_piece);
|
||||
mimeData->setObjectName("piecePointer");
|
||||
|
||||
// in case we would want to have the pieces original size:
|
||||
//drag->setHotSpot(QPoint(0,0));
|
||||
//QPixmap pixmap(m_piecePreview->sceneRect().size().toSize());
|
||||
|
||||
QPixmap pixmap(112,92);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
m_piecePreview->scene()->render(&painter);
|
||||
|
||||
drag->setPixmap(pixmap);
|
||||
drag->setMimeData(mimeData);
|
||||
drag->exec();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu contextMenu;
|
||||
|
||||
VPPieceList* unplacedPieces = m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList();
|
||||
QList<VPSheet*> sheets = m_piece->GetPieceList()->GetLayout()->GetSheets();
|
||||
QList<VPPieceList*> pieceLists = QList<VPPieceList*>();
|
||||
for (auto sheet : sheets)
|
||||
{
|
||||
pieceLists.append(sheet->GetPieceList());
|
||||
}
|
||||
|
||||
// move to piece list actions -- TODO : To be tested properly when we have several piece lists
|
||||
pieceLists.removeAll(m_piece->GetPieceList());
|
||||
if(pieceLists.count() > 0)
|
||||
{
|
||||
QMenu *moveMenu = contextMenu.addMenu(tr("Move to"));
|
||||
|
||||
// TODO order in alphabetical order
|
||||
|
||||
for (auto pieceList : pieceLists)
|
||||
{
|
||||
QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
|
||||
QVariant data = QVariant::fromValue(pieceList);
|
||||
moveToPieceList->setData(data);
|
||||
|
||||
connect(moveToPieceList, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
|
||||
}
|
||||
}
|
||||
|
||||
// remove from piece list action
|
||||
if(m_piece->GetPieceList() != unplacedPieces)
|
||||
{
|
||||
QAction *removeAction = contextMenu.addAction(tr("Remove from Layout"));
|
||||
QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
|
||||
removeAction->setData(data);
|
||||
connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
|
||||
}
|
||||
|
||||
contextMenu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiece::on_ActionPieceMovedToPieceList()
|
||||
{
|
||||
QAction *act = qobject_cast<QAction *>(sender());
|
||||
QVariant v = act->data();
|
||||
VPPieceList *pieceList = v.value<VPPieceList *>();
|
||||
if(pieceList != nullptr)
|
||||
{
|
||||
pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList);
|
||||
}
|
||||
}
|
||||
////---------------------------------------------------------------------------------------------------------------------
|
||||
//void VPCarrouselPiece::on_ActionPieceMovedToPieceList()
|
||||
//{
|
||||
// QAction *act = qobject_cast<QAction *>(sender());
|
||||
// QVariant v = act->data();
|
||||
// VPPieceList *pieceList = v.value<VPPieceList *>();
|
||||
// if(pieceList != nullptr)
|
||||
// {
|
||||
// pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList);
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -28,48 +28,28 @@
|
|||
#ifndef VPCARROUSELPIECE_H
|
||||
#define VPCARROUSELPIECE_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QGraphicsView>
|
||||
#include <QMouseEvent>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
#include "vppiece.h"
|
||||
#include "vpcarrouselpiecepreview.h"
|
||||
|
||||
|
||||
class VPCarrouselPieceList;
|
||||
|
||||
class VPCarrouselPiece : public QFrame
|
||||
class VPCarrouselPiece : public QListWidgetItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VPCarrouselPiece(VPPiece *piece, VPCarrouselPieceList *carrouselPieceList);
|
||||
explicit VPCarrouselPiece(VPPiece *piece, QListWidget* parent);
|
||||
~VPCarrouselPiece();
|
||||
|
||||
void Init();
|
||||
void Refresh();
|
||||
|
||||
/**
|
||||
* @brief CleanPiecesPreview fitInView of the qGraphicsView of the pieces works properly
|
||||
* only when the piece is in place in the piece list and we call it from the piece list.
|
||||
*/
|
||||
void CleanPreview();
|
||||
|
||||
/**
|
||||
* @brief GetPiece Returns the corresponding layout piece
|
||||
* @return the corresponding layout piece
|
||||
*/
|
||||
VPPiece * GetPiece();
|
||||
|
||||
public slots:
|
||||
void on_PieceSelectionChanged();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
/**
|
||||
* @brief RefreshSelection refreshes the selection of the piece according to the selection information of m_piece
|
||||
*/
|
||||
void RefreshSelection();
|
||||
|
||||
private slots:
|
||||
/**
|
||||
|
@ -79,17 +59,8 @@ private slots:
|
|||
void on_ActionPieceMovedToPieceList();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPCarrouselPiece)
|
||||
|
||||
VPPiece *m_piece;
|
||||
|
||||
VPCarrouselPieceList *m_carrouselPieceList;
|
||||
|
||||
QLabel *m_label{nullptr};
|
||||
VPCarrouselPiecePreview *m_piecePreview{nullptr};
|
||||
|
||||
QPoint m_dragStart;
|
||||
|
||||
private slots:
|
||||
|
||||
};
|
||||
|
|
|
@ -25,53 +25,57 @@
|
|||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "vpcarrouselpiecelist.h"
|
||||
#include "vpcarrousel.h"
|
||||
#include "../vmisc/backport/qoverload.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QDrag>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
#include "vpcarrousel.h"
|
||||
#include "vpcarrouselpiece.h"
|
||||
#include "../vmisc/backport/qoverload.h"
|
||||
#include "vpmimedatapiece.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrouselPieceList::VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel) :
|
||||
m_pieceList(pieceList),
|
||||
m_carrousel(carrousel),
|
||||
m_carrouselPieces(QList<VPCarrouselPiece*>())
|
||||
VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
|
||||
QListWidget(parent)
|
||||
{
|
||||
Init();
|
||||
// Init();
|
||||
|
||||
setStyleSheet("QListWidget::item{background-color:transparent; border: 2px solid transparent; color: black;} QListWidget::item:selected {background-color:transparent; border: 2px solid red; color: black; selection-background-color: white;}");
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
setSelectionMode(QAbstractItemView::MultiSelection);
|
||||
setViewMode(QListView::IconMode);
|
||||
|
||||
connect(this, &VPCarrouselPieceList::itemSelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedInternal);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrouselPieceList::~VPCarrouselPieceList()
|
||||
{
|
||||
Clear();
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::Init()
|
||||
{
|
||||
// initiales the structure
|
||||
QVBoxLayout *layoutPiecesLayout = new QVBoxLayout();
|
||||
layoutPiecesLayout->setMargin(0);
|
||||
setLayout(layoutPiecesLayout);
|
||||
|
||||
// then refresh the content
|
||||
Refresh();
|
||||
|
||||
// add the connections
|
||||
connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
|
||||
connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
|
||||
// // add the connections
|
||||
// connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
|
||||
// connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::Refresh()
|
||||
{
|
||||
Clear();
|
||||
clear();
|
||||
|
||||
if(m_pieceList != nullptr)
|
||||
{
|
||||
// Updates the carrousel pieces from the pieces list
|
||||
QList<VPPiece*> pieces = m_pieceList->GetPieces();
|
||||
|
||||
|
@ -80,54 +84,109 @@ void VPCarrouselPieceList::Refresh()
|
|||
[](const VPPiece* a, const VPPiece* b) -> bool { return a->GetName() < b->GetName();});
|
||||
|
||||
// create the corresponding carrousel pieces
|
||||
|
||||
bool _isVisible = isVisible();
|
||||
setVisible(true);
|
||||
for (auto piece : pieces)
|
||||
{
|
||||
VPCarrouselPiece *carrouselPiece = new VPCarrouselPiece(piece, this);
|
||||
m_carrouselPieces.append(carrouselPiece);
|
||||
layout()->addWidget(carrouselPiece);
|
||||
carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed.
|
||||
}
|
||||
setVisible(_isVisible);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::Clear()
|
||||
{
|
||||
// Removes and deletes the carrousel pieces from the piece list
|
||||
while (!m_carrouselPieces.isEmpty())
|
||||
{
|
||||
VPCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast();
|
||||
|
||||
if(carrouselPiece != nullptr)
|
||||
{
|
||||
layout()->removeWidget(carrouselPiece);
|
||||
delete carrouselPiece;
|
||||
// update the label of the piece
|
||||
VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this);
|
||||
carrouselpiece->setSelected(piece->GetIsSelected());
|
||||
connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<VPCarrouselPiece*> VPCarrouselPieceList::GetCarrouselPieces()
|
||||
{
|
||||
return m_carrouselPieces;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrousel* VPCarrouselPieceList::GetCarrousel()
|
||||
{
|
||||
return m_carrousel;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPPieceList* VPCarrouselPieceList::GetPieceList()
|
||||
VPPieceList* VPCarrouselPieceList::GetCurrentPieceList()
|
||||
{
|
||||
return m_pieceList;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::SetCurrentPieceList(VPPieceList* pieceList)
|
||||
{
|
||||
m_pieceList = pieceList;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
qCDebug(pCarrouselPieceList, "mouse pressed");
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
m_dragStart = event->pos();
|
||||
}
|
||||
|
||||
if (!(event->modifiers() & Qt::ControlModifier))
|
||||
{
|
||||
// clearSelection doesn't work properly here so we go through the elements.
|
||||
for(auto item: selectedItems())
|
||||
{
|
||||
item->setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
QListWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
qCDebug(pCarrouselPieceList, "mouse moved");
|
||||
|
||||
if ((event->buttons() & Qt::LeftButton) &&
|
||||
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
|
||||
(m_pieceList->GetSheet() == nullptr)) // only if it's from unplaced pieces
|
||||
{
|
||||
startDrag(Qt::MoveAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
QListWidget::mouseMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
|
||||
{
|
||||
|
||||
qCDebug(pCarrouselPieceList, "start drag");
|
||||
|
||||
QListWidgetItem* item = currentItem();
|
||||
if(item->type() == 1001)
|
||||
{
|
||||
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (item);
|
||||
|
||||
// starts the dragging
|
||||
QDrag *drag = new QDrag(this);
|
||||
VPMimeDataPiece *mimeData = new VPMimeDataPiece();
|
||||
mimeData->SetPiecePtr(pieceItem->GetPiece()); //TODO
|
||||
mimeData->setObjectName("piecePointer");
|
||||
|
||||
QPixmap pixmap = pieceItem->GetPiece()->PieceIcon(QSize(120,120)).pixmap(QSize(120,120));
|
||||
|
||||
drag->setPixmap(pixmap);
|
||||
drag->setMimeData(mimeData);
|
||||
if(drag->exec() == Qt::MoveAction)
|
||||
{
|
||||
delete takeItem(row(item));
|
||||
clearSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e)
|
||||
{
|
||||
qCDebug(pCarrouselPieceList, "drag move");
|
||||
|
||||
|
||||
e->acceptProposedAction();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece)
|
||||
{
|
||||
|
@ -141,15 +200,38 @@ void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece)
|
||||
{
|
||||
for (auto carrouselPiece : m_carrouselPieces)
|
||||
{
|
||||
if(carrouselPiece->GetPiece() == piece)
|
||||
{
|
||||
m_carrouselPieces.removeAll(carrouselPiece);
|
||||
layout()->removeWidget(carrouselPiece);
|
||||
delete carrouselPiece;
|
||||
// TODO
|
||||
Q_UNUSED(piece)
|
||||
}
|
||||
|
||||
return;
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::on_SelectionChangedInternal()
|
||||
{
|
||||
for(int i = 0; i < count(); ++i)
|
||||
{
|
||||
QListWidgetItem* _item = item(i);
|
||||
if(_item->type() == 1001)
|
||||
{
|
||||
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
|
||||
blockSignals(true);
|
||||
itemPiece->GetPiece()->SetIsSelected(itemPiece->isSelected());
|
||||
blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPieceList::on_SelectionChangedExternal()
|
||||
{
|
||||
for(int i = 0; i < count(); ++i)
|
||||
{
|
||||
QListWidgetItem* _item = item(i);
|
||||
if(_item->type() == 1001)
|
||||
{
|
||||
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
|
||||
blockSignals(true);
|
||||
itemPiece->RefreshSelection();
|
||||
blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,43 +29,47 @@
|
|||
#ifndef VPCARROUSELPIECELIST_H
|
||||
#define VPCARROUSELPIECELIST_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QListWidget>
|
||||
#include "vppiecelist.h"
|
||||
#include "vpcarrouselpiece.h"
|
||||
|
||||
class VPCarrousel;
|
||||
|
||||
class VPCarrouselPieceList : public QWidget
|
||||
class VPCarrouselPieceList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel);
|
||||
VPCarrouselPieceList(QWidget* parent);
|
||||
~VPCarrouselPieceList();
|
||||
|
||||
void Init();
|
||||
void Refresh();
|
||||
|
||||
/**
|
||||
* @brief Clear it clears the carrousel pieceList from its pieces
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
QList<VPCarrouselPiece*> GetCarrouselPieces();
|
||||
|
||||
VPCarrousel* GetCarrousel();
|
||||
|
||||
/**
|
||||
* @brief GetPieceList Returns the corresponding VPPieceList
|
||||
* @return the VPPieceList
|
||||
*/
|
||||
VPPieceList* GetPieceList();
|
||||
VPPieceList* GetCurrentPieceList();
|
||||
|
||||
/**
|
||||
* @brief SetCurrentPieceList Sets the current piece list to the given piece list and redraw
|
||||
* the carrousel.
|
||||
*/
|
||||
void SetCurrentPieceList(VPPieceList* pieceList);
|
||||
|
||||
public slots:
|
||||
void on_SelectionChangedExternal();
|
||||
|
||||
protected:
|
||||
void startDrag(Qt::DropActions supportedActions) override;
|
||||
void dragMoveEvent(QDragMoveEvent* e) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPCarrouselPieceList)
|
||||
|
||||
VPPieceList *m_pieceList;
|
||||
VPCarrousel *m_carrousel;
|
||||
QList<VPCarrouselPiece*> m_carrouselPieces;
|
||||
VPPieceList *m_pieceList{nullptr};
|
||||
QPoint m_dragStart;
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -79,6 +83,8 @@ private slots:
|
|||
*/
|
||||
void on_PieceRemoved(VPPiece* piece);
|
||||
|
||||
void on_SelectionChangedInternal();
|
||||
|
||||
};
|
||||
|
||||
#endif // VPCARROUSELPIECELIST_H
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vpcarrouselpiecepreview.cpp
|
||||
** @author Ronan Le Tiec
|
||||
** @date 3 5, 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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "vpcarrouselpiecepreview.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrouselPiecePreview::VPCarrouselPiecePreview(QWidget *parent):
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPCarrouselPiecePreview::~VPCarrouselPiecePreview()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiecePreview::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPCarrouselPiecePreview::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vpcarrouselpiecepreview.h
|
||||
** @author Ronan Le Tiec
|
||||
** @date 3 5, 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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef VPCARROUSELPIECEPREVIEW_H
|
||||
#define VPCARROUSELPIECEPREVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
class VPCarrouselPiecePreview: public QGraphicsView
|
||||
{
|
||||
public:
|
||||
VPCarrouselPiecePreview(QWidget *parent = nullptr);
|
||||
~VPCarrouselPiecePreview();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // VPCARROUSELPIECEPREVIEW_H
|
|
@ -327,7 +327,7 @@ void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|||
}
|
||||
|
||||
// remove from layout action
|
||||
QAction *removeAction = contextMenu.addAction(tr("Remove from Layout"));
|
||||
QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet"));
|
||||
QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
|
||||
removeAction->setData(data);
|
||||
connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPLayout::VPLayout() :
|
||||
m_unplacedPieceList(new VPPieceList(this))
|
||||
m_unplacedPieceList(new VPPieceList(this)),
|
||||
m_sheets(QList<VPSheet*>())
|
||||
{
|
||||
m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces"));
|
||||
}
|
||||
|
|
|
@ -296,5 +296,10 @@ QIcon VPPiece::PieceIcon(const QSize &size) const
|
|||
painter.drawPolygon(shape);
|
||||
painter.end();
|
||||
|
||||
return QIcon(pixmap);
|
||||
QIcon icon;
|
||||
|
||||
icon.addPixmap(pixmap,QIcon::Normal);
|
||||
icon.addPixmap(pixmap,QIcon::Selected);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
Q_LOGGING_CATEGORY(pPieceList, "p.pieceList")
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPPieceList::VPPieceList(VPLayout *layout):
|
||||
VPPieceList::VPPieceList(VPLayout *layout, VPSheet *sheet):
|
||||
m_sheet(sheet),
|
||||
m_layout(layout)
|
||||
{
|
||||
|
||||
|
@ -52,6 +53,12 @@ VPLayout* VPPieceList::GetLayout()
|
|||
return m_layout;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPSheet* VPPieceList::GetSheet()
|
||||
{
|
||||
return m_sheet;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<VPPiece *> VPPieceList::GetPieces()
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <QList>
|
||||
#include "vppiece.h"
|
||||
#include "vpsheet.h"
|
||||
|
||||
class VPLayout;
|
||||
|
||||
|
@ -37,7 +38,7 @@ class VPPieceList : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VPPieceList(VPLayout *layout);
|
||||
VPPieceList(VPLayout *layout, VPSheet *sheet = nullptr);
|
||||
~VPPieceList();
|
||||
|
||||
QList<VPPiece *> GetPieces();
|
||||
|
@ -59,6 +60,14 @@ public:
|
|||
*/
|
||||
VPLayout* GetLayout();
|
||||
|
||||
|
||||
/**
|
||||
* @brief GetSheet returns the sheet corresponding to this piece list, or nullptr
|
||||
* if no sheet associated
|
||||
* @return the sheet
|
||||
*/
|
||||
VPSheet* GetSheet();
|
||||
|
||||
/**
|
||||
* @brief ClearSelection Clears the selection of the pieces in this piece list
|
||||
*/
|
||||
|
@ -81,6 +90,8 @@ private:
|
|||
QString m_name{};
|
||||
QList<VPPiece *> m_pieces{};
|
||||
|
||||
VPSheet *m_sheet{nullptr};
|
||||
|
||||
VPLayout *m_layout{nullptr};
|
||||
|
||||
// control
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
VPSheet::VPSheet(VPLayout* layout) :
|
||||
m_layout(layout)
|
||||
{
|
||||
m_pieceList = new VPPieceList(layout);
|
||||
m_pieceList = new VPPieceList(layout, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user