Refactoring Piece carrousel

This commit is contained in:
Ronan Le Tiec 2020-05-24 14:55:03 +02:00
parent b4b77c4cdf
commit f00168e59b
15 changed files with 273 additions and 459 deletions

View File

@ -8,7 +8,6 @@ SOURCES += \
$$PWD/vpcarrousel.cpp \ $$PWD/vpcarrousel.cpp \
$$PWD/vpcarrouselpiece.cpp \ $$PWD/vpcarrouselpiece.cpp \
$$PWD/vpcarrouselpiecelist.cpp \ $$PWD/vpcarrouselpiecelist.cpp \
$$PWD/vpcarrouselpiecepreview.cpp \
$$PWD/vpcommandline.cpp \ $$PWD/vpcommandline.cpp \
$$PWD/vpcommands.cpp \ $$PWD/vpcommands.cpp \
$$PWD/vpgraphicspiece.cpp \ $$PWD/vpgraphicspiece.cpp \
@ -33,7 +32,6 @@ HEADERS += \
$$PWD/vpcarrousel.h \ $$PWD/vpcarrousel.h \
$$PWD/vpcarrouselpiece.h \ $$PWD/vpcarrouselpiece.h \
$$PWD/vpcarrouselpiecelist.h \ $$PWD/vpcarrouselpiecelist.h \
$$PWD/vpcarrouselpiecepreview.h \
$$PWD/vpcommandline.h \ $$PWD/vpcommandline.h \
$$PWD/vpcommands.h \ $$PWD/vpcommands.h \
$$PWD/vpgraphicspiece.h \ $$PWD/vpgraphicspiece.h \

View File

@ -30,6 +30,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QMessageBox> #include <QMessageBox>
#include <QScrollBar> #include <QScrollBar>
#include <QFontMetrics>
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#include "vppiecelist.h" #include "vppiecelist.h"
@ -53,8 +54,6 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&VPCarrousel::on_ActivePieceListChanged); &VPCarrousel::on_ActivePieceListChanged);
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
// ------ then we fill the carrousel with the layout content // ------ then we fill the carrousel with the layout content
Refresh(); Refresh();
} }
@ -103,21 +102,11 @@ void VPCarrousel::on_ActivePieceListChanged(int index)
{ {
qCDebug(pCarrousel, "index changed %i", index); qCDebug(pCarrousel, "index changed %i", index);
ui->listWidget->clear();
if (index >= 0 && index < m_pieceLists.size()) if (index >= 0 && index < m_pieceLists.size())
{ {
VPPieceList *pieceList = m_pieceLists.at(index); VPPieceList *pieceList = m_pieceLists.at(index);
if (pieceList) ui->listWidget->SetCurrentPieceList(pieceList);
{
QList<VPPiece*> pieces = pieceList->GetPieces();
for (auto piece : pieces)
{
new QListWidgetItem(piece->PieceIcon(QSize(120, 120)) , piece->GetName(), ui->listWidget);
}
}
} }
} }

View File

@ -37,7 +37,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QListWidget" name="listWidget"> <widget class="VPCarrouselPieceList" name="listWidget">
<property name="verticalScrollBarPolicy"> <property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum> <enum>Qt::ScrollBarAlwaysOn</enum>
</property> </property>
@ -72,6 +72,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>VPCarrouselPieceList</class>
<extends>QListWidget</extends>
<header>vpcarrouselpiecelist.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -28,12 +28,6 @@
#include "vpcarrouselpiece.h" #include "vpcarrouselpiece.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QGraphicsScene>
#include <QPainter>
#include <QDrag>
#include <QPainter>
#include <QApplication> #include <QApplication>
#include <QMenu> #include <QMenu>
@ -48,103 +42,22 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, VPCarrouselPieceList *carrouselPieceList) : VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
m_piece(piece), QListWidgetItem(parent,1001),
m_carrouselPieceList(carrouselPieceList), m_piece(piece)
m_dragStart(QPoint())
{ {
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() 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()) setSelected(m_piece->GetIsSelected());
{
setStyleSheet("background-color:white; border: 2px solid red;");
}
else
{
setStyleSheet("background-color:white; border: 2px solid transparent;");
}
} }
//--------------------------------------------------------------------------------------------------------------------- ////---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPiece::mousePressEvent(QMouseEvent *event) //void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
{ //{
qCDebug(pCarrouselPiece, "mouse pressed"); // 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) // // move to piece list actions -- TODO : To be tested properly when we have several piece lists
{ // pieceLists.removeAll(m_piece->GetPieceList());
if(!(event->modifiers() & Qt::ControlModifier)) // if(pieceLists.count() > 0)
{ // {
m_carrouselPieceList->GetCarrousel()->ClearSelection(); // QMenu *moveMenu = contextMenu.addMenu(tr("Move to"));
m_piece->SetIsSelected(true);
}
else
{
m_piece->SetIsSelected(!m_piece->GetIsSelected());
}
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);
//--------------------------------------------------------------------------------------------------------------------- // connect(moveToPieceList, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
void VPCarrouselPiece::mouseMoveEvent(QMouseEvent *event) // }
{ // }
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
if(m_piece->GetPieceList() != m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList()) // // remove from piece list action
{ // if(m_piece->GetPieceList() != unplacedPieces)
return; // {
} // 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()) // contextMenu.exec(event->globalPos());
{ //}
return;
}
// make sure the multiple selection is removed ////---------------------------------------------------------------------------------------------------------------------
m_carrouselPieceList->GetCarrousel()->ClearSelection(); //void VPCarrouselPiece::on_ActionPieceMovedToPieceList()
m_piece->SetIsSelected(true); //{
// QAction *act = qobject_cast<QAction *>(sender());
// starts the dragging // QVariant v = act->data();
QDrag *drag = new QDrag(this); // VPPieceList *pieceList = v.value<VPPieceList *>();
VPMimeDataPiece *mimeData = new VPMimeDataPiece(); // if(pieceList != nullptr)
mimeData->SetPiecePtr(m_piece); // {
mimeData->setObjectName("piecePointer"); // pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList);
// }
// 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);
}
}

View File

@ -28,48 +28,28 @@
#ifndef VPCARROUSELPIECE_H #ifndef VPCARROUSELPIECE_H
#define VPCARROUSELPIECE_H #define VPCARROUSELPIECE_H
#include <QFrame>
#include <QLabel>
#include <QGraphicsView>
#include <QMouseEvent> #include <QMouseEvent>
#include <QListWidgetItem>
#include "vppiece.h" #include "vppiece.h"
#include "vpcarrouselpiecepreview.h"
class VPCarrouselPieceList; class VPCarrouselPiece : public QListWidgetItem
class VPCarrouselPiece : public QFrame
{ {
Q_OBJECT
public: public:
explicit VPCarrouselPiece(VPPiece *piece, VPCarrouselPieceList *carrouselPieceList); explicit VPCarrouselPiece(VPPiece *piece, QListWidget* parent);
~VPCarrouselPiece(); ~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 * @brief GetPiece Returns the corresponding layout piece
* @return the corresponding layout piece * @return the corresponding layout piece
*/ */
VPPiece * GetPiece(); VPPiece * GetPiece();
public slots: /**
void on_PieceSelectionChanged(); * @brief RefreshSelection refreshes the selection of the piece according to the selection information of m_piece
*/
protected: void RefreshSelection();
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
private slots: private slots:
/** /**
@ -79,17 +59,8 @@ private slots:
void on_ActionPieceMovedToPieceList(); void on_ActionPieceMovedToPieceList();
private: private:
Q_DISABLE_COPY(VPCarrouselPiece)
VPPiece *m_piece; VPPiece *m_piece;
VPCarrouselPieceList *m_carrouselPieceList;
QLabel *m_label{nullptr};
VPCarrouselPiecePreview *m_piecePreview{nullptr};
QPoint m_dragStart;
private slots: private slots:
}; };

View File

@ -25,53 +25,57 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>. ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
** **
*************************************************************************/ *************************************************************************/
#include "vpcarrouselpiecelist.h" #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> #include <QLoggingCategory>
Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList") Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPCarrouselPieceList::VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel) : VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
m_pieceList(pieceList), QListWidget(parent)
m_carrousel(carrousel),
m_carrouselPieces(QList<VPCarrouselPiece*>())
{ {
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() VPCarrouselPieceList::~VPCarrouselPieceList()
{ {
Clear();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::Init() void VPCarrouselPieceList::Init()
{ {
// initiales the structure // // add the connections
QVBoxLayout *layoutPiecesLayout = new QVBoxLayout(); // connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
layoutPiecesLayout->setMargin(0); // connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::Refresh() void VPCarrouselPieceList::Refresh()
{ {
Clear(); clear();
if(m_pieceList != nullptr)
{
// Updates the carrousel pieces from the pieces list // Updates the carrousel pieces from the pieces list
QList<VPPiece*> pieces = m_pieceList->GetPieces(); 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();}); [](const VPPiece* a, const VPPiece* b) -> bool { return a->GetName() < b->GetName();});
// create the corresponding carrousel pieces // create the corresponding carrousel pieces
bool _isVisible = isVisible();
setVisible(true);
for (auto piece : pieces) for (auto piece : pieces)
{ {
VPCarrouselPiece *carrouselPiece = new VPCarrouselPiece(piece, this); // update the label of the piece
m_carrouselPieces.append(carrouselPiece); VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this);
layout()->addWidget(carrouselPiece); carrouselpiece->setSelected(piece->GetIsSelected());
carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed. connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal);
}
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;
} }
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QList<VPCarrouselPiece*> VPCarrouselPieceList::GetCarrouselPieces()
{
return m_carrouselPieces;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPCarrousel* VPCarrouselPieceList::GetCarrousel() VPPieceList* VPCarrouselPieceList::GetCurrentPieceList()
{
return m_carrousel;
}
//---------------------------------------------------------------------------------------------------------------------
VPPieceList* VPCarrouselPieceList::GetPieceList()
{ {
return m_pieceList; 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) void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece)
{ {
@ -141,15 +200,38 @@ void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece) void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece)
{ {
for (auto carrouselPiece : m_carrouselPieces) // TODO
{ Q_UNUSED(piece)
if(carrouselPiece->GetPiece() == piece) }
{
m_carrouselPieces.removeAll(carrouselPiece);
layout()->removeWidget(carrouselPiece);
delete carrouselPiece;
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);
} }
} }
} }

View File

@ -29,43 +29,47 @@
#ifndef VPCARROUSELPIECELIST_H #ifndef VPCARROUSELPIECELIST_H
#define VPCARROUSELPIECELIST_H #define VPCARROUSELPIECELIST_H
#include <QWidget> #include <QListWidget>
#include "vppiecelist.h" #include "vppiecelist.h"
#include "vpcarrouselpiece.h"
class VPCarrousel;
class VPCarrouselPieceList : public QWidget class VPCarrouselPieceList : public QListWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel); VPCarrouselPieceList(QWidget* parent);
~VPCarrouselPieceList(); ~VPCarrouselPieceList();
void Init(); void Init();
void Refresh(); 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 * @brief GetPieceList Returns the corresponding VPPieceList
* @return the 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: private:
Q_DISABLE_COPY(VPCarrouselPieceList) Q_DISABLE_COPY(VPCarrouselPieceList)
VPPieceList *m_pieceList; VPPieceList *m_pieceList{nullptr};
VPCarrousel *m_carrousel; QPoint m_dragStart;
QList<VPCarrouselPiece*> m_carrouselPieces;
private slots: private slots:
@ -79,6 +83,8 @@ private slots:
*/ */
void on_PieceRemoved(VPPiece* piece); void on_PieceRemoved(VPPiece* piece);
void on_SelectionChangedInternal();
}; };
#endif // VPCARROUSELPIECELIST_H #endif // VPCARROUSELPIECELIST_H

View File

@ -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();
}

View File

@ -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

View File

@ -327,7 +327,7 @@ void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
} }
// remove from layout action // 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()); QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
removeAction->setData(data); removeAction->setData(data);
connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);

View File

@ -32,7 +32,8 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPLayout::VPLayout() : VPLayout::VPLayout() :
m_unplacedPieceList(new VPPieceList(this)) m_unplacedPieceList(new VPPieceList(this)),
m_sheets(QList<VPSheet*>())
{ {
m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces"));
} }

View File

@ -296,5 +296,10 @@ QIcon VPPiece::PieceIcon(const QSize &size) const
painter.drawPolygon(shape); painter.drawPolygon(shape);
painter.end(); painter.end();
return QIcon(pixmap); QIcon icon;
icon.addPixmap(pixmap,QIcon::Normal);
icon.addPixmap(pixmap,QIcon::Selected);
return icon;
} }

View File

@ -34,7 +34,8 @@
Q_LOGGING_CATEGORY(pPieceList, "p.pieceList") Q_LOGGING_CATEGORY(pPieceList, "p.pieceList")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPPieceList::VPPieceList(VPLayout *layout): VPPieceList::VPPieceList(VPLayout *layout, VPSheet *sheet):
m_sheet(sheet),
m_layout(layout) m_layout(layout)
{ {
@ -52,6 +53,12 @@ VPLayout* VPPieceList::GetLayout()
return m_layout; return m_layout;
} }
//---------------------------------------------------------------------------------------------------------------------
VPSheet* VPPieceList::GetSheet()
{
return m_sheet;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<VPPiece *> VPPieceList::GetPieces() QList<VPPiece *> VPPieceList::GetPieces()
{ {

View File

@ -30,6 +30,7 @@
#include <QList> #include <QList>
#include "vppiece.h" #include "vppiece.h"
#include "vpsheet.h"
class VPLayout; class VPLayout;
@ -37,7 +38,7 @@ class VPPieceList : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
VPPieceList(VPLayout *layout); VPPieceList(VPLayout *layout, VPSheet *sheet = nullptr);
~VPPieceList(); ~VPPieceList();
QList<VPPiece *> GetPieces(); QList<VPPiece *> GetPieces();
@ -59,6 +60,14 @@ public:
*/ */
VPLayout* GetLayout(); 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 * @brief ClearSelection Clears the selection of the pieces in this piece list
*/ */
@ -81,6 +90,8 @@ private:
QString m_name{}; QString m_name{};
QList<VPPiece *> m_pieces{}; QList<VPPiece *> m_pieces{};
VPSheet *m_sheet{nullptr};
VPLayout *m_layout{nullptr}; VPLayout *m_layout{nullptr};
// control // control

View File

@ -34,7 +34,7 @@
VPSheet::VPSheet(VPLayout* layout) : VPSheet::VPSheet(VPLayout* layout) :
m_layout(layout) m_layout(layout)
{ {
m_pieceList = new VPPieceList(layout); m_pieceList = new VPPieceList(layout, this);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------