Cleaning carousel.

This commit is contained in:
Roman Telezhynskyi 2021-07-29 18:05:25 +03:00
parent 91a69b83b6
commit ec6c1cad23
6 changed files with 23 additions and 36 deletions

View File

@ -47,6 +47,7 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
ui(new Ui::VPCarrousel),
m_layout(layout)
{
SCASSERT(m_layout != nullptr)
ui->setupUi(this);
ui->listWidget->SetCarrousel(this);

View File

@ -100,7 +100,7 @@ private:
Qt::Orientation m_orientation{Qt::Vertical};
static QString GetSheetName(const VPCarrouselSheet &sheet);
static auto GetSheetName(const VPCarrouselSheet &sheet) -> QString;
};
#endif // VPCARROUSEL_H

View File

@ -44,9 +44,10 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//---------------------------------------------------------------------------------------------------------------------
VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
QListWidgetItem(parent,1001),
QListWidgetItem(parent, Type),
m_piece(piece)
{
SCASSERT(m_piece != nullptr)
int width = 120 - 8;
QFontMetrics metrix = QFontMetrics(QFont());
QString clippedText = metrix.elidedText(piece->GetName(), Qt::ElideRight, width);
@ -54,15 +55,8 @@ VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
setText(clippedText);
}
//---------------------------------------------------------------------------------------------------------------------
VPCarrouselPiece::~VPCarrouselPiece()
{
}
//---------------------------------------------------------------------------------------------------------------------
VPPiece * VPCarrouselPiece::GetPiece()
auto VPCarrouselPiece::GetPiece() -> VPPiece *
{
return m_piece;
}
@ -74,7 +68,7 @@ void VPCarrouselPiece::RefreshSelection()
}
//---------------------------------------------------------------------------------------------------------------------
QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size, bool isDragIcon) const
auto VPCarrouselPiece::CreatePieceIcon(const QSize &size, bool isDragIcon) const -> QIcon
{
QRectF boundingRect = m_piece->DetailBoundingRect();
qreal canvasSize = qMax(boundingRect.height(), boundingRect.width());

View File

@ -37,14 +37,16 @@
class VPCarrouselPiece : public QListWidgetItem
{
public:
enum { Type = UserType + 1};
explicit VPCarrouselPiece(VPPiece *piece, QListWidget* parent);
~VPCarrouselPiece();
virtual ~VPCarrouselPiece() = default;
/**
* @brief GetPiece Returns the corresponding layout piece
* @return the corresponding layout piece
*/
VPPiece * GetPiece();
auto GetPiece() -> VPPiece *;
/**
* @brief RefreshSelection refreshes the selection of the piece according to the selection information of m_piece
@ -56,15 +58,12 @@ public:
* @param size of the icon
* @return the created icon
*/
QIcon CreatePieceIcon(const QSize &size, bool isDragIcon = false) const;
auto CreatePieceIcon(const QSize &size, bool isDragIcon = false) const -> QIcon;
private:
Q_DISABLE_COPY(VPCarrouselPiece)
VPPiece *m_piece;
private slots:
};
#endif // VPCARROUSELPIECE_H

View File

@ -45,21 +45,15 @@ Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
//---------------------------------------------------------------------------------------------------------------------
VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
QListWidget(parent),
m_dragStart(QPoint())
QListWidget(parent)
{
setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid rgb(255,160,160);}");
setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} "
"QListWidget::item:selected {border: 2px solid rgb(255,160,160);}");
setContextMenuPolicy(Qt::DefaultContextMenu);
setSelectionMode(QAbstractItemView::MultiSelection);
setViewMode(QListView::IconMode);
}
//---------------------------------------------------------------------------------------------------------------------
VPCarrouselPieceList::~VPCarrouselPieceList()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::SetCarrousel(VPCarrousel *carrousel)
{
@ -116,7 +110,7 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) &&
if (((event->buttons() & Qt::LeftButton) != 0u) &&
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
(selectedItems().count() > 0) &&
(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)) // only if it's from unplaced pieces
@ -136,9 +130,9 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
Q_UNUSED(supportedActions)
QListWidgetItem* _item = currentItem();
if(_item->type() == 1001)
if(_item->type() == VPCarrouselPiece::Type)
{
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item);
auto *pieceItem = static_cast<VPCarrouselPiece *> (_item);
// starts the dragging
auto *drag = new QDrag(this);
@ -171,9 +165,9 @@ void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e)
void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
{
QListWidgetItem* _item = currentItem();
if(_item != nullptr && _item->type() == 1001)
if(_item != nullptr && _item->type() == VPCarrouselPiece::Type)
{
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item);
auto *pieceItem = static_cast<VPCarrouselPiece *> (_item);
QMenu menu;
@ -223,9 +217,9 @@ void VPCarrouselPieceList::on_SelectionChangedExternal()
for(int i = 0; i < count(); ++i)
{
QListWidgetItem* _item = item(i);
if(_item->type() == 1001)
if(_item->type() == VPCarrouselPiece::Type)
{
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
auto *itemPiece = static_cast<VPCarrouselPiece *> (_item);
itemPiece->RefreshSelection();
}
}

View File

@ -39,7 +39,7 @@ class VPCarrouselPieceList : public QListWidget
Q_OBJECT
public:
explicit VPCarrouselPieceList(QWidget* parent);
~VPCarrouselPieceList();
virtual ~VPCarrouselPieceList() = default;
/**
* @brief Refresh refreshes the items of the carrousel piece list
@ -58,7 +58,6 @@ public:
*/
void SetCarrousel(VPCarrousel *carrousel);
public slots:
/**
* @brief on_SelectionChangedExternal when the selection was changed outside of the carrousel
@ -78,7 +77,7 @@ private:
Q_DISABLE_COPY(VPCarrouselPieceList)
QList<VPPiece *> m_pieceList{};
QPoint m_dragStart;
QPoint m_dragStart{};
VPCarrousel *m_carrousel{nullptr};
};