From af40b52988262e8332f1a19da609032fe28371b9 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 24 May 2020 19:53:51 +0200 Subject: [PATCH] Refactoring Piece carrousel part 2 --- src/app/puzzle/vpcarrousel.cpp | 31 ++--- src/app/puzzle/vpcarrousel.h | 9 +- src/app/puzzle/vpcarrouselpiece.cpp | 88 +++++++------- src/app/puzzle/vpcarrouselpiece.h | 9 +- src/app/puzzle/vpcarrouselpiecelist.cpp | 146 ++++++++++++++++++------ src/app/puzzle/vpcarrouselpiecelist.h | 28 ++++- src/app/puzzle/vplayout.cpp | 24 ++++ src/app/puzzle/vplayout.h | 8 ++ src/app/puzzle/vpmainwindow.cpp | 3 + src/app/puzzle/vpmainwindow.ui | 63 +++++++++- src/app/puzzle/vppiece.cpp | 46 -------- 11 files changed, 302 insertions(+), 153 deletions(-) diff --git a/src/app/puzzle/vpcarrousel.cpp b/src/app/puzzle/vpcarrousel.cpp index cf419a913..072b3a528 100644 --- a/src/app/puzzle/vpcarrousel.cpp +++ b/src/app/puzzle/vpcarrousel.cpp @@ -49,6 +49,7 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) : m_layout(layout) { ui->setupUi(this); + ui->listWidget->SetCarrousel(this); // init the combo box connect(ui->comboBoxPieceList, QOverload::of(&QComboBox::currentIndexChanged), this, @@ -61,8 +62,6 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) : //--------------------------------------------------------------------------------------------------------------------- void VPCarrousel::Refresh() { - // NOTE: alternative to clearing the carrousel and adding things again, we could make comparision - // --- clears the content of the carrousel Clear(); @@ -70,18 +69,14 @@ void VPCarrousel::Refresh() // Do not rely on m_layout because we do not control it. m_pieceLists = QList(); m_pieceLists.append(m_layout->GetUnplacedPieceList()); - for(auto sheet : m_layout->GetSheets()) - { - m_pieceLists.append(sheet->GetPieceList()); - } + m_pieceLists.append(m_layout->GetFocusedSheet()->GetPieceList()); - for (auto pieceList : m_pieceLists) - { - // add piece list name to combo - ui->comboBoxPieceList->blockSignals(true); - ui->comboBoxPieceList->addItem(pieceList->GetName()); - ui->comboBoxPieceList->blockSignals(false); - } + ui->comboBoxPieceList->blockSignals(true); + + ui->comboBoxPieceList->addItem(m_layout->GetUnplacedPieceList()->GetName()); + ui->comboBoxPieceList->addItem(tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName()); + + ui->comboBoxPieceList->blockSignals(false); on_ActivePieceListChanged(0); @@ -148,3 +143,13 @@ void VPCarrousel::ClearSelection() { m_layout->ClearSelection(); } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrousel::ClearSelectionExceptForCurrentPieceList() +{ + if (m_layout != nullptr) + { + m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList()); + } +} diff --git a/src/app/puzzle/vpcarrousel.h b/src/app/puzzle/vpcarrousel.h index f4aed9aff..4a3119a0e 100644 --- a/src/app/puzzle/vpcarrousel.h +++ b/src/app/puzzle/vpcarrousel.h @@ -75,11 +75,18 @@ public: */ 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: Q_DISABLE_COPY(VPCarrousel) Ui::VPCarrousel *ui; - VPLayout *m_layout; + VPLayout *m_layout{nullptr}; + QList m_pieceLists{}; Qt::Orientation m_orientation{Qt::Vertical}; diff --git a/src/app/puzzle/vpcarrouselpiece.cpp b/src/app/puzzle/vpcarrouselpiece.cpp index a2ac6382a..93b737238 100644 --- a/src/app/puzzle/vpcarrouselpiece.cpp +++ b/src/app/puzzle/vpcarrouselpiece.cpp @@ -30,6 +30,7 @@ #include #include +#include #include "vpmimedatapiece.h" #include "vpcarrouselpiecelist.h" @@ -49,7 +50,7 @@ VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) : int width = 120 - 8; QFontMetrics metrix = QFontMetrics(QFont()); QString clippedText = metrix.elidedText(piece->GetName(), Qt::ElideRight, width); - setIcon(m_piece->PieceIcon(QSize(120, 120))); + setIcon(CreatePieceIcon(QSize(120, 120))); setText(clippedText); } @@ -72,57 +73,50 @@ void VPCarrouselPiece::RefreshSelection() setSelected(m_piece->GetIsSelected()); } -////--------------------------------------------------------------------------------------------------------------------- -//void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event) -//{ -// QMenu contextMenu; +//--------------------------------------------------------------------------------------------------------------------- +QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const +{ + QVector points = m_piece->GetSeamLine(); + if(points.isEmpty()) + { + points = m_piece->GetCuttingLine(); + } -// VPPieceList* unplacedPieces = m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList(); -// QList sheets = m_piece->GetPieceList()->GetLayout()->GetSheets(); -// QList pieceLists = QList(); -// for (auto sheet : sheets) -// { -// pieceLists.append(sheet->GetPieceList()); -// } + QPolygonF shape(points); + shape << shape.first(); -// // 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")); + QRectF boundingRect = shape.boundingRect(); + qreal canvasSize = qMax(boundingRect.height(), boundingRect.width()); + QRectF canvas = QRectF(0, 0, canvasSize, canvasSize); -// // 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) -// { -// QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName()); -// QVariant data = QVariant::fromValue(pieceList); -// moveToPieceList->setData(data); + QPixmap pixmap(size); + pixmap.fill(QColor("white")); -// 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 -// 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); -// } + int spacing = 2; + painter.translate(spacing, spacing); -// 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))); -////--------------------------------------------------------------------------------------------------------------------- -//void VPCarrouselPiece::on_ActionPieceMovedToPieceList() -//{ -// QAction *act = qobject_cast(sender()); -// QVariant v = act->data(); -// VPPieceList *pieceList = v.value(); -// if(pieceList != nullptr) -// { -// pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList); -// } -//} + painter.translate(dx, dy); + + painter.drawPolygon(shape); + painter.end(); + + QIcon icon; + + icon.addPixmap(pixmap,QIcon::Normal); + icon.addPixmap(pixmap,QIcon::Selected); + + return icon; +} diff --git a/src/app/puzzle/vpcarrouselpiece.h b/src/app/puzzle/vpcarrouselpiece.h index 46f0afe2c..7a2008a7d 100644 --- a/src/app/puzzle/vpcarrouselpiece.h +++ b/src/app/puzzle/vpcarrouselpiece.h @@ -51,12 +51,13 @@ public: */ void RefreshSelection(); -private slots: /** - * @brief on_ActionPieceMovedToPieceList Slot called when the piece is moved via the - * context menu to anoter piece list + * @brief CreatePieceIcon Creates an icon of the piece of given size + * @param size of the icon + * @return the created icon */ - void on_ActionPieceMovedToPieceList(); + QIcon CreatePieceIcon(const QSize &size) const; + private: VPPiece *m_piece; diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index 63cfced52..c782bfeb7 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "vpcarrousel.h" #include "vpcarrouselpiece.h" @@ -43,12 +44,11 @@ Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList") //--------------------------------------------------------------------------------------------------------------------- VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) : - QListWidget(parent) + QListWidget(parent), + m_dragStart(QPoint()) { -// 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); + setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid red;}"); + setContextMenuPolicy(Qt::DefaultContextMenu); setSelectionMode(QAbstractItemView::MultiSelection); setViewMode(QListView::IconMode); @@ -62,11 +62,9 @@ VPCarrouselPieceList::~VPCarrouselPieceList() } //--------------------------------------------------------------------------------------------------------------------- -void VPCarrouselPieceList::Init() +void VPCarrouselPieceList::SetCarrousel(VPCarrousel *carrousel) { -// // add the connections -// connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded); -// connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved); + m_carrousel = carrousel; } //--------------------------------------------------------------------------------------------------------------------- @@ -76,13 +74,11 @@ void VPCarrouselPieceList::Refresh() if(m_pieceList != nullptr) { + m_pieceList->disconnect(this); + // Updates the carrousel pieces from the pieces list QList 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 for (auto piece : pieces) { @@ -91,6 +87,10 @@ void VPCarrouselPieceList::Refresh() carrouselpiece->setSelected(piece->GetIsSelected()); 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) { - qCDebug(pCarrouselPieceList, "mouse pressed"); - if (event->button() == Qt::LeftButton) { m_dragStart = event->pos(); @@ -134,10 +132,9 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event) { - qCDebug(pCarrouselPieceList, "mouse moved"); - if ((event->buttons() & Qt::LeftButton) && ((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) && + (selectedItems().count() > 0) && (m_pieceList->GetSheet() == nullptr)) // only if it's from unplaced pieces { startDrag(Qt::MoveAction); @@ -152,28 +149,29 @@ void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- 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 (item); + VPCarrouselPiece *pieceItem = static_cast (_item); // starts the dragging QDrag *drag = new QDrag(this); VPMimeDataPiece *mimeData = new VPMimeDataPiece(); - mimeData->SetPiecePtr(pieceItem->GetPiece()); //TODO + VPPiece* piece = pieceItem->GetPiece(); + mimeData->SetPiecePtr(piece); 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->setMimeData(mimeData); if(drag->exec() == Qt::MoveAction) { - delete takeItem(row(item)); + delete takeItem(row(_item)); clearSelection(); + piece->SetIsSelected(true); } } } @@ -182,56 +180,128 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions) void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) { qCDebug(pCarrouselPieceList, "drag move"); - - e->acceptProposedAction(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) +{ + QListWidgetItem* _item = currentItem(); + if(_item->type() == 1001) + { + VPCarrouselPiece *pieceItem = static_cast (_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 (_item); + QAction *act = qobject_cast(sender()); + QVariant v = act->data(); + VPPieceList *pieceList = v.value(); + if(pieceList != nullptr) + { + pieceList->GetLayout()->MovePieceToPieceList(pieceItem->GetPiece(), pieceList); + } + } +} + + + //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece) { - Q_UNUSED(piece) - - // TODO/ FIXME: see if we find a solution more efficient refreshing the complete layout everytime. - - Refresh(); + if(piece->GetPieceList() == m_pieceList) + { + // update the label of the piece + VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this); + carrouselpiece->setSelected(piece->GetIsSelected()); + connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); + } } //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece) { - // TODO - Q_UNUSED(piece) + for(int i = 0; i < count(); ++i) + { + QListWidgetItem* _item = item(i); + if(_item->type() == 1001) + { + VPCarrouselPiece *itemPiece = static_cast (_item); + + if(piece == itemPiece->GetPiece()) + { + delete takeItem(row(_item)); + + return; + } + } + } } //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_SelectionChangedInternal() { + blockSignals(true); + for(int i = 0; i < count(); ++i) { QListWidgetItem* _item = item(i); if(_item->type() == 1001) { VPCarrouselPiece *itemPiece = static_cast (_item); - blockSignals(true); 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() { + blockSignals(true); for(int i = 0; i < count(); ++i) { QListWidgetItem* _item = item(i); if(_item->type() == 1001) { VPCarrouselPiece *itemPiece = static_cast (_item); - blockSignals(true); itemPiece->RefreshSelection(); - blockSignals(false); } } + blockSignals(false); } diff --git a/src/app/puzzle/vpcarrouselpiecelist.h b/src/app/puzzle/vpcarrouselpiecelist.h index 0af1870e8..8dd2ee55d 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.h +++ b/src/app/puzzle/vpcarrouselpiecelist.h @@ -31,6 +31,7 @@ #include #include "vppiecelist.h" +#include "vpcarrousel.h" class VPCarrouselPieceList : public QListWidget @@ -40,7 +41,9 @@ public: VPCarrouselPieceList(QWidget* parent); ~VPCarrouselPieceList(); - void Init(); + /** + * @brief Refresh refreshes the items of the carrousel piece list + */ void Refresh(); /** @@ -53,9 +56,19 @@ public: * @brief SetCurrentPieceList Sets the current piece list to the given piece list and redraw * 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: + /** + * @brief on_SelectionChangedExternal when the selection was changed outside of the carrousel + */ void on_SelectionChangedExternal(); protected: @@ -65,11 +78,14 @@ protected: void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override; + private: Q_DISABLE_COPY(VPCarrouselPieceList) VPPieceList *m_pieceList{nullptr}; QPoint m_dragStart; + VPCarrousel *m_carrousel{nullptr}; private slots: @@ -83,8 +99,16 @@ private slots: */ void on_PieceRemoved(VPPiece* piece); + /** + * @brief on_SelectionChangedInternal when the selection was changed inside of the carrousel + */ 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 diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index 3b06f0020..fe77d2959 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -30,6 +30,11 @@ #include "vppiece.h" #include "vpsheet.h" + +#include + +Q_LOGGING_CATEGORY(pLayout, "p.layout") + //--------------------------------------------------------------------------------------------------------------------- VPLayout::VPLayout() : 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) { diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index 5d36fad93..a81017bb8 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -84,6 +84,14 @@ public: */ 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 * @param piece the piece to move diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 16d6437a5..a2bd21750 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -395,6 +395,9 @@ void VPMainWindow::SetPropertyTabCurrentPieceData() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabSheetData() { + // set name // TODO FIXME make it better + ui->lineEditSheetName->setText(m_layout->GetFocusedSheet()->GetName()); + // set Width / Length QSizeF size = m_layout->GetFocusedSheet()->GetSheetSizeConverted(); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, size.width()); diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 927c80787..461e49af9 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -172,7 +172,7 @@ QTabWidget::Rounded - 1 + 0 @@ -230,7 +230,7 @@ 0 0 342 - 1318 + 1264 @@ -253,6 +253,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -398,6 +410,18 @@ 0 + + 0 + + + 0 + + + 0 + + + 0 + @@ -420,6 +444,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -519,6 +555,29 @@ + + + + Infos + + + + + + + + Name + + + + + + + + + + + diff --git a/src/app/puzzle/vppiece.cpp b/src/app/puzzle/vppiece.cpp index b1a3903e4..ed3df5899 100644 --- a/src/app/puzzle/vppiece.cpp +++ b/src/app/puzzle/vppiece.cpp @@ -256,50 +256,4 @@ void VPPiece::SetPieceList(VPPieceList* pieceList) } } -//--------------------------------------------------------------------------------------------------------------------- -QIcon VPPiece::PieceIcon(const QSize &size) const -{ - QVector 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; -}