Refactoring Piece carrousel part 2

This commit is contained in:
Ronan Le Tiec 2020-05-24 19:53:51 +02:00
parent f00168e59b
commit af40b52988
11 changed files with 302 additions and 153 deletions

View File

@ -49,6 +49,7 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
m_layout(layout) m_layout(layout)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->listWidget->SetCarrousel(this);
// init the combo box // init the combo box
connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
@ -61,8 +62,6 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::Refresh() void VPCarrousel::Refresh()
{ {
// NOTE: alternative to clearing the carrousel and adding things again, we could make comparision
// --- clears the content of the carrousel // --- clears the content of the carrousel
Clear(); Clear();
@ -70,18 +69,14 @@ void VPCarrousel::Refresh()
// Do not rely on m_layout because we do not control it. // Do not rely on m_layout because we do not control it.
m_pieceLists = QList<VPPieceList*>(); m_pieceLists = QList<VPPieceList*>();
m_pieceLists.append(m_layout->GetUnplacedPieceList()); m_pieceLists.append(m_layout->GetUnplacedPieceList());
for(auto sheet : m_layout->GetSheets()) m_pieceLists.append(m_layout->GetFocusedSheet()->GetPieceList());
{
m_pieceLists.append(sheet->GetPieceList());
}
for (auto pieceList : m_pieceLists) ui->comboBoxPieceList->blockSignals(true);
{
// add piece list name to combo ui->comboBoxPieceList->addItem(m_layout->GetUnplacedPieceList()->GetName());
ui->comboBoxPieceList->blockSignals(true); ui->comboBoxPieceList->addItem(tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName());
ui->comboBoxPieceList->addItem(pieceList->GetName());
ui->comboBoxPieceList->blockSignals(false); ui->comboBoxPieceList->blockSignals(false);
}
on_ActivePieceListChanged(0); on_ActivePieceListChanged(0);
@ -148,3 +143,13 @@ void VPCarrousel::ClearSelection()
{ {
m_layout->ClearSelection(); m_layout->ClearSelection();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::ClearSelectionExceptForCurrentPieceList()
{
if (m_layout != nullptr)
{
m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList());
}
}

View File

@ -75,11 +75,18 @@ public:
*/ */
void ClearSelection(); void ClearSelection();
/**
* @brief ClearSelectionExceptForCurrentPieceList Clears the selection of all pieces of
* the layout except for the one in the current piece list
*/
void ClearSelectionExceptForCurrentPieceList();
private: private:
Q_DISABLE_COPY(VPCarrousel) Q_DISABLE_COPY(VPCarrousel)
Ui::VPCarrousel *ui; Ui::VPCarrousel *ui;
VPLayout *m_layout; VPLayout *m_layout{nullptr};
QList<VPPieceList*> m_pieceLists{}; QList<VPPieceList*> m_pieceLists{};
Qt::Orientation m_orientation{Qt::Vertical}; Qt::Orientation m_orientation{Qt::Vertical};

View File

@ -30,6 +30,7 @@
#include <QApplication> #include <QApplication>
#include <QMenu> #include <QMenu>
#include <QPainter>
#include "vpmimedatapiece.h" #include "vpmimedatapiece.h"
#include "vpcarrouselpiecelist.h" #include "vpcarrouselpiecelist.h"
@ -49,7 +50,7 @@ VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
int width = 120 - 8; int width = 120 - 8;
QFontMetrics metrix = QFontMetrics(QFont()); QFontMetrics metrix = QFontMetrics(QFont());
QString clippedText = metrix.elidedText(piece->GetName(), Qt::ElideRight, width); QString clippedText = metrix.elidedText(piece->GetName(), Qt::ElideRight, width);
setIcon(m_piece->PieceIcon(QSize(120, 120))); setIcon(CreatePieceIcon(QSize(120, 120)));
setText(clippedText); setText(clippedText);
} }
@ -72,57 +73,50 @@ void VPCarrouselPiece::RefreshSelection()
setSelected(m_piece->GetIsSelected()); setSelected(m_piece->GetIsSelected());
} }
////--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
//void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event) QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const
//{ {
// QMenu contextMenu; QVector<QPointF> points = m_piece->GetSeamLine();
if(points.isEmpty())
{
points = m_piece->GetCuttingLine();
}
// VPPieceList* unplacedPieces = m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList(); QPolygonF shape(points);
// QList<VPSheet*> sheets = m_piece->GetPieceList()->GetLayout()->GetSheets(); shape << shape.first();
// 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 QRectF boundingRect = shape.boundingRect();
// pieceLists.removeAll(m_piece->GetPieceList()); qreal canvasSize = qMax(boundingRect.height(), boundingRect.width());
// if(pieceLists.count() > 0) QRectF canvas = QRectF(0, 0, canvasSize, canvasSize);
// {
// QMenu *moveMenu = contextMenu.addMenu(tr("Move to"));
// // TODO order in alphabetical order qreal dx = canvas.center().x() - boundingRect.center().x();
qreal dy = canvas.center().y() - boundingRect.center().y();
// for (auto pieceList : pieceLists) QPixmap pixmap(size);
// { pixmap.fill(QColor("white"));
// QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
// QVariant data = QVariant::fromValue(pieceList);
// moveToPieceList->setData(data);
// connect(moveToPieceList, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList); QPainter painter;
// } painter.begin(&pixmap);
// } painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// // remove from piece list action int spacing = 2;
// if(m_piece->GetPieceList() != unplacedPieces) painter.translate(spacing, spacing);
// {
// 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);
// }
// contextMenu.exec(event->globalPos()); qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100;
//} qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100;
painter.scale(1./scaleFactorX, 1./scaleFactorY);
painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY)));
////--------------------------------------------------------------------------------------------------------------------- painter.translate(dx, dy);
//void VPCarrouselPiece::on_ActionPieceMovedToPieceList()
//{ painter.drawPolygon(shape);
// QAction *act = qobject_cast<QAction *>(sender()); painter.end();
// QVariant v = act->data();
// VPPieceList *pieceList = v.value<VPPieceList *>(); QIcon icon;
// if(pieceList != nullptr)
// { icon.addPixmap(pixmap,QIcon::Normal);
// pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList); icon.addPixmap(pixmap,QIcon::Selected);
// }
//} return icon;
}

View File

@ -51,12 +51,13 @@ public:
*/ */
void RefreshSelection(); void RefreshSelection();
private slots:
/** /**
* @brief on_ActionPieceMovedToPieceList Slot called when the piece is moved via the * @brief CreatePieceIcon Creates an icon of the piece of given size
* context menu to anoter piece list * @param size of the icon
* @return the created icon
*/ */
void on_ActionPieceMovedToPieceList(); QIcon CreatePieceIcon(const QSize &size) const;
private: private:
VPPiece *m_piece; VPPiece *m_piece;

View File

@ -31,6 +31,7 @@
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QPainter> #include <QPainter>
#include <QApplication> #include <QApplication>
#include <QMenu>
#include "vpcarrousel.h" #include "vpcarrousel.h"
#include "vpcarrouselpiece.h" #include "vpcarrouselpiece.h"
@ -43,12 +44,11 @@ Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) : VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
QListWidget(parent) QListWidget(parent),
m_dragStart(QPoint())
{ {
// Init(); setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid red;}");
setContextMenuPolicy(Qt::DefaultContextMenu);
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); setSelectionMode(QAbstractItemView::MultiSelection);
setViewMode(QListView::IconMode); setViewMode(QListView::IconMode);
@ -62,11 +62,9 @@ VPCarrouselPieceList::~VPCarrouselPieceList()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::Init() void VPCarrouselPieceList::SetCarrousel(VPCarrousel *carrousel)
{ {
// // add the connections m_carrousel = carrousel;
// connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
// connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -76,13 +74,11 @@ void VPCarrouselPieceList::Refresh()
if(m_pieceList != nullptr) if(m_pieceList != nullptr)
{ {
m_pieceList->disconnect(this);
// 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();
// sort the pieces in alphabetical order
std::sort(pieces.begin(), pieces.end(),
[](const VPPiece* a, const VPPiece* b) -> bool { return a->GetName() < b->GetName();});
// create the corresponding carrousel pieces // create the corresponding carrousel pieces
for (auto piece : pieces) for (auto piece : pieces)
{ {
@ -91,6 +87,10 @@ void VPCarrouselPieceList::Refresh()
carrouselpiece->setSelected(piece->GetIsSelected()); carrouselpiece->setSelected(piece->GetIsSelected());
connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal);
} }
sortItems();
connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
} }
} }
@ -112,8 +112,6 @@ void VPCarrouselPieceList::SetCurrentPieceList(VPPieceList* pieceList)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event) void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
{ {
qCDebug(pCarrouselPieceList, "mouse pressed");
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
{ {
m_dragStart = event->pos(); m_dragStart = event->pos();
@ -134,10 +132,9 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event) void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
{ {
qCDebug(pCarrouselPieceList, "mouse moved");
if ((event->buttons() & Qt::LeftButton) && if ((event->buttons() & Qt::LeftButton) &&
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) && ((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
(selectedItems().count() > 0) &&
(m_pieceList->GetSheet() == nullptr)) // only if it's from unplaced pieces (m_pieceList->GetSheet() == nullptr)) // only if it's from unplaced pieces
{ {
startDrag(Qt::MoveAction); startDrag(Qt::MoveAction);
@ -152,28 +149,29 @@ void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions) void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
{ {
Q_UNUSED(supportedActions)
qCDebug(pCarrouselPieceList, "start drag"); QListWidgetItem* _item = currentItem();
if(_item->type() == 1001)
QListWidgetItem* item = currentItem();
if(item->type() == 1001)
{ {
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (item); VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item);
// starts the dragging // starts the dragging
QDrag *drag = new QDrag(this); QDrag *drag = new QDrag(this);
VPMimeDataPiece *mimeData = new VPMimeDataPiece(); VPMimeDataPiece *mimeData = new VPMimeDataPiece();
mimeData->SetPiecePtr(pieceItem->GetPiece()); //TODO VPPiece* piece = pieceItem->GetPiece();
mimeData->SetPiecePtr(piece);
mimeData->setObjectName("piecePointer"); mimeData->setObjectName("piecePointer");
QPixmap pixmap = pieceItem->GetPiece()->PieceIcon(QSize(120,120)).pixmap(QSize(120,120)); QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120)).pixmap(QSize(120,120));
drag->setPixmap(pixmap); drag->setPixmap(pixmap);
drag->setMimeData(mimeData); drag->setMimeData(mimeData);
if(drag->exec() == Qt::MoveAction) if(drag->exec() == Qt::MoveAction)
{ {
delete takeItem(row(item)); delete takeItem(row(_item));
clearSelection(); clearSelection();
piece->SetIsSelected(true);
} }
} }
} }
@ -182,56 +180,128 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e)
{ {
qCDebug(pCarrouselPieceList, "drag move"); qCDebug(pCarrouselPieceList, "drag move");
e->acceptProposedAction(); e->acceptProposedAction();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
{
QListWidgetItem* _item = currentItem();
if(_item->type() == 1001)
{
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item);
QMenu contextMenu;
if(m_pieceList->GetSheet() == nullptr)
{
VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList();
QAction *moveAction = contextMenu.addAction(tr("Move to Sheet"));
QVariant data = QVariant::fromValue(sheetPieces);
moveAction->setData(data);
connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList);
}
// remove from piece list action
if(m_pieceList->GetSheet() != nullptr)
{
VPPieceList* unplacedPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetUnplacedPieceList();
QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet"));
QVariant data = QVariant::fromValue(unplacedPieces);
removeAction->setData(data);
connect(removeAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList);
}
contextMenu.exec(event->globalPos());
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_ActionPieceMovedToPieceList()
{
QListWidgetItem* _item = currentItem();
if(_item->type() == 1001)
{
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item);
QAction *act = qobject_cast<QAction *>(sender());
QVariant v = act->data();
VPPieceList *pieceList = v.value<VPPieceList *>();
if(pieceList != nullptr)
{
pieceList->GetLayout()->MovePieceToPieceList(pieceItem->GetPiece(), pieceList);
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece) void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece)
{ {
Q_UNUSED(piece) if(piece->GetPieceList() == m_pieceList)
{
// TODO/ FIXME: see if we find a solution more efficient refreshing the complete layout everytime. // update the label of the piece
VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this);
Refresh(); carrouselpiece->setSelected(piece->GetIsSelected());
connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece) void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece)
{ {
// TODO for(int i = 0; i < count(); ++i)
Q_UNUSED(piece) {
QListWidgetItem* _item = item(i);
if(_item->type() == 1001)
{
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
if(piece == itemPiece->GetPiece())
{
delete takeItem(row(_item));
return;
}
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_SelectionChangedInternal() void VPCarrouselPieceList::on_SelectionChangedInternal()
{ {
blockSignals(true);
for(int i = 0; i < count(); ++i) for(int i = 0; i < count(); ++i)
{ {
QListWidgetItem* _item = item(i); QListWidgetItem* _item = item(i);
if(_item->type() == 1001) if(_item->type() == 1001)
{ {
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item); VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
blockSignals(true);
itemPiece->GetPiece()->SetIsSelected(itemPiece->isSelected()); itemPiece->GetPiece()->SetIsSelected(itemPiece->isSelected());
blockSignals(false);
} }
} }
m_carrousel->ClearSelectionExceptForCurrentPieceList();
// TODO FIXME: when selecting pieces on the sheet, and then selecting a unplaced piece in the piece carrousel
// the selection is cleared in the sheet (good !) but the cliked item in unplaced pieces in not selected (bad!)
blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_SelectionChangedExternal() void VPCarrouselPieceList::on_SelectionChangedExternal()
{ {
blockSignals(true);
for(int i = 0; i < count(); ++i) for(int i = 0; i < count(); ++i)
{ {
QListWidgetItem* _item = item(i); QListWidgetItem* _item = item(i);
if(_item->type() == 1001) if(_item->type() == 1001)
{ {
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item); VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
blockSignals(true);
itemPiece->RefreshSelection(); itemPiece->RefreshSelection();
blockSignals(false);
} }
} }
blockSignals(false);
} }

View File

@ -31,6 +31,7 @@
#include <QListWidget> #include <QListWidget>
#include "vppiecelist.h" #include "vppiecelist.h"
#include "vpcarrousel.h"
class VPCarrouselPieceList : public QListWidget class VPCarrouselPieceList : public QListWidget
@ -40,7 +41,9 @@ public:
VPCarrouselPieceList(QWidget* parent); VPCarrouselPieceList(QWidget* parent);
~VPCarrouselPieceList(); ~VPCarrouselPieceList();
void Init(); /**
* @brief Refresh refreshes the items of the carrousel piece list
*/
void Refresh(); void Refresh();
/** /**
@ -53,9 +56,19 @@ public:
* @brief SetCurrentPieceList Sets the current piece list to the given piece list and redraw * @brief SetCurrentPieceList Sets the current piece list to the given piece list and redraw
* the carrousel. * the carrousel.
*/ */
void SetCurrentPieceList(VPPieceList* pieceList); void SetCurrentPieceList(VPPieceList *pieceList);
/**
* @brief SetCarrousel Sets the carrousel corresponding to the list
* @param carrousel
*/
void SetCarrousel(VPCarrousel *carrousel);
public slots: public slots:
/**
* @brief on_SelectionChangedExternal when the selection was changed outside of the carrousel
*/
void on_SelectionChangedExternal(); void on_SelectionChangedExternal();
protected: protected:
@ -65,11 +78,14 @@ protected:
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
private: private:
Q_DISABLE_COPY(VPCarrouselPieceList) Q_DISABLE_COPY(VPCarrouselPieceList)
VPPieceList *m_pieceList{nullptr}; VPPieceList *m_pieceList{nullptr};
QPoint m_dragStart; QPoint m_dragStart;
VPCarrousel *m_carrousel{nullptr};
private slots: private slots:
@ -83,8 +99,16 @@ private slots:
*/ */
void on_PieceRemoved(VPPiece* piece); void on_PieceRemoved(VPPiece* piece);
/**
* @brief on_SelectionChangedInternal when the selection was changed inside of the carrousel
*/
void on_SelectionChangedInternal(); void on_SelectionChangedInternal();
/**
* @brief on_ActionPieceMovedToPieceList when a piece is moved to another piece list via a context menu
*/
void on_ActionPieceMovedToPieceList();
}; };
#endif // VPCARROUSELPIECELIST_H #endif // VPCARROUSELPIECELIST_H

View File

@ -30,6 +30,11 @@
#include "vppiece.h" #include "vppiece.h"
#include "vpsheet.h" #include "vpsheet.h"
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(pLayout, "p.layout")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPLayout::VPLayout() : VPLayout::VPLayout() :
m_unplacedPieceList(new VPPieceList(this)), m_unplacedPieceList(new VPPieceList(this)),
@ -147,6 +152,25 @@ void VPLayout::ClearSelection()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList)
{
if(m_unplacedPieceList != pieceList)
{
m_unplacedPieceList->ClearSelection();
}
for (auto sheet : m_sheets)
{
if(sheet->GetPieceList() != pieceList)
{
sheet->ClearSelection();
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList)
{ {

View File

@ -84,6 +84,14 @@ public:
*/ */
void ClearSelection(); void ClearSelection();
/**
* @brief ClearSelectionExceptForPieceList same as clearSelection but it leaves the selection
* for the given piece list like it ist.
*
* @param pieceList the piece list to let be the way it is.
*/
void ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList);
/** /**
* @brief MovePieceToPieceList Moves the given piece to the given piece list * @brief MovePieceToPieceList Moves the given piece to the given piece list
* @param piece the piece to move * @param piece the piece to move

View File

@ -395,6 +395,9 @@ void VPMainWindow::SetPropertyTabCurrentPieceData()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::SetPropertyTabSheetData() void VPMainWindow::SetPropertyTabSheetData()
{ {
// set name // TODO FIXME make it better
ui->lineEditSheetName->setText(m_layout->GetFocusedSheet()->GetName());
// set Width / Length // set Width / Length
QSizeF size = m_layout->GetFocusedSheet()->GetSheetSizeConverted(); QSizeF size = m_layout->GetFocusedSheet()->GetSheetSizeConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, size.width()); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, size.width());

View File

@ -172,7 +172,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -230,7 +230,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>342</width> <width>342</width>
<height>1318</height> <height>1264</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -253,6 +253,18 @@
<item> <item>
<widget class="QWidget" name="containerCurrentPieceData" native="true"> <widget class="QWidget" name="containerCurrentPieceData" native="true">
<layout class="QVBoxLayout" name="containerCurrentPieceDataLayout"> <layout class="QVBoxLayout" name="containerCurrentPieceDataLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBoxCurrentPieceInfo"> <widget class="QGroupBox" name="groupBoxCurrentPieceInfo">
<property name="title"> <property name="title">
@ -398,6 +410,18 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="labelCurrentPieceNoPieceSelected"> <widget class="QLabel" name="labelCurrentPieceNoPieceSelected">
<property name="minimumSize"> <property name="minimumSize">
@ -420,6 +444,18 @@
<item> <item>
<widget class="QWidget" name="containerCurrentPieceMultipleData" native="true"> <widget class="QWidget" name="containerCurrentPieceMultipleData" native="true">
<layout class="QVBoxLayout" name="verticalLayout_11"> <layout class="QVBoxLayout" name="verticalLayout_11">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="labelCurrentPieceMultiplePieceSelected"> <widget class="QLabel" name="labelCurrentPieceMultiplePieceSelected">
<property name="minimumSize"> <property name="minimumSize">
@ -519,6 +555,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBoxSheetInfos">
<property name="title">
<string>Infos</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<layout class="QFormLayout" name="formLayout_8">
<item row="0" column="0">
<widget class="QLabel" name="labelSheetName">
<property name="text">
<string>Name </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditSheetName"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBoxSheetFormat"> <widget class="QGroupBox" name="groupBoxSheetFormat">
<property name="title"> <property name="title">

View File

@ -256,50 +256,4 @@ void VPPiece::SetPieceList(VPPieceList* pieceList)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QIcon VPPiece::PieceIcon(const QSize &size) const
{
QVector<QPointF> points = GetSeamLine();
if(points.isEmpty())
{
points = GetCuttingLine();
}
QPolygonF shape(points);
shape << shape.first();
QRectF boundingRect = shape.boundingRect();
qreal canvasSize = qMax(boundingRect.height(), boundingRect.width());
QRectF canvas = QRectF(0, 0, canvasSize, canvasSize);
qreal dx = canvas.center().x() - boundingRect.center().x();
qreal dy = canvas.center().y() - boundingRect.center().y();
QPixmap pixmap(size);
pixmap.fill(QColor("white"));
QPainter painter;
painter.begin(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
int spacing = 2;
painter.translate(spacing, spacing);
qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100;
qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100;
painter.scale(1./scaleFactorX, 1./scaleFactorY);
painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY)));
painter.translate(dx, dy);
painter.drawPolygon(shape);
painter.end();
QIcon icon;
icon.addPixmap(pixmap,QIcon::Normal);
icon.addPixmap(pixmap,QIcon::Selected);
return icon;
}