Cleaning carousel.
This commit is contained in:
parent
91a69b83b6
commit
ec6c1cad23
|
@ -47,6 +47,7 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
|
||||||
ui(new Ui::VPCarrousel),
|
ui(new Ui::VPCarrousel),
|
||||||
m_layout(layout)
|
m_layout(layout)
|
||||||
{
|
{
|
||||||
|
SCASSERT(m_layout != nullptr)
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->listWidget->SetCarrousel(this);
|
ui->listWidget->SetCarrousel(this);
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ private:
|
||||||
|
|
||||||
Qt::Orientation m_orientation{Qt::Vertical};
|
Qt::Orientation m_orientation{Qt::Vertical};
|
||||||
|
|
||||||
static QString GetSheetName(const VPCarrouselSheet &sheet);
|
static auto GetSheetName(const VPCarrouselSheet &sheet) -> QString;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VPCARROUSEL_H
|
#endif // VPCARROUSEL_H
|
||||||
|
|
|
@ -44,9 +44,10 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
|
VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
|
||||||
QListWidgetItem(parent,1001),
|
QListWidgetItem(parent, Type),
|
||||||
m_piece(piece)
|
m_piece(piece)
|
||||||
{
|
{
|
||||||
|
SCASSERT(m_piece != nullptr)
|
||||||
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);
|
||||||
|
@ -54,15 +55,8 @@ VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) :
|
||||||
setText(clippedText);
|
setText(clippedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPCarrouselPiece::~VPCarrouselPiece()
|
auto VPCarrouselPiece::GetPiece() -> VPPiece *
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
VPPiece * VPCarrouselPiece::GetPiece()
|
|
||||||
{
|
{
|
||||||
return m_piece;
|
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();
|
QRectF boundingRect = m_piece->DetailBoundingRect();
|
||||||
qreal canvasSize = qMax(boundingRect.height(), boundingRect.width());
|
qreal canvasSize = qMax(boundingRect.height(), boundingRect.width());
|
||||||
|
|
|
@ -37,14 +37,16 @@
|
||||||
class VPCarrouselPiece : public QListWidgetItem
|
class VPCarrouselPiece : public QListWidgetItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum { Type = UserType + 1};
|
||||||
|
|
||||||
explicit VPCarrouselPiece(VPPiece *piece, QListWidget* parent);
|
explicit VPCarrouselPiece(VPPiece *piece, QListWidget* parent);
|
||||||
~VPCarrouselPiece();
|
virtual ~VPCarrouselPiece() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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();
|
auto GetPiece() -> VPPiece *;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief RefreshSelection refreshes the selection of the piece according to the selection information of m_piece
|
* @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
|
* @param size of the icon
|
||||||
* @return the created 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:
|
private:
|
||||||
Q_DISABLE_COPY(VPCarrouselPiece)
|
Q_DISABLE_COPY(VPCarrouselPiece)
|
||||||
VPPiece *m_piece;
|
VPPiece *m_piece;
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VPCARROUSELPIECE_H
|
#endif // VPCARROUSELPIECE_H
|
||||||
|
|
|
@ -45,21 +45,15 @@ Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
|
VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
|
||||||
QListWidget(parent),
|
QListWidget(parent)
|
||||||
m_dragStart(QPoint())
|
|
||||||
{
|
{
|
||||||
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);
|
setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||||
setSelectionMode(QAbstractItemView::MultiSelection);
|
setSelectionMode(QAbstractItemView::MultiSelection);
|
||||||
setViewMode(QListView::IconMode);
|
setViewMode(QListView::IconMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
VPCarrouselPieceList::~VPCarrouselPieceList()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPCarrouselPieceList::SetCarrousel(VPCarrousel *carrousel)
|
void VPCarrouselPieceList::SetCarrousel(VPCarrousel *carrousel)
|
||||||
{
|
{
|
||||||
|
@ -116,7 +110,7 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPCarrouselPieceList::mouseMoveEvent(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()) &&
|
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
|
||||||
(selectedItems().count() > 0) &&
|
(selectedItems().count() > 0) &&
|
||||||
(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)) // only if it's from unplaced pieces
|
(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)
|
Q_UNUSED(supportedActions)
|
||||||
|
|
||||||
QListWidgetItem* _item = currentItem();
|
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
|
// starts the dragging
|
||||||
auto *drag = new QDrag(this);
|
auto *drag = new QDrag(this);
|
||||||
|
@ -171,9 +165,9 @@ void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e)
|
||||||
void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
|
void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QListWidgetItem* _item = currentItem();
|
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;
|
QMenu menu;
|
||||||
|
|
||||||
|
@ -223,9 +217,9 @@ void VPCarrouselPieceList::on_SelectionChangedExternal()
|
||||||
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() == VPCarrouselPiece::Type)
|
||||||
{
|
{
|
||||||
VPCarrouselPiece *itemPiece = static_cast<VPCarrouselPiece *> (_item);
|
auto *itemPiece = static_cast<VPCarrouselPiece *> (_item);
|
||||||
itemPiece->RefreshSelection();
|
itemPiece->RefreshSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class VPCarrouselPieceList : public QListWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VPCarrouselPieceList(QWidget* parent);
|
explicit VPCarrouselPieceList(QWidget* parent);
|
||||||
~VPCarrouselPieceList();
|
virtual ~VPCarrouselPieceList() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Refresh refreshes the items of the carrousel piece list
|
* @brief Refresh refreshes the items of the carrousel piece list
|
||||||
|
@ -58,7 +58,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetCarrousel(VPCarrousel *carrousel);
|
void SetCarrousel(VPCarrousel *carrousel);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief on_SelectionChangedExternal when the selection was changed outside of the carrousel
|
* @brief on_SelectionChangedExternal when the selection was changed outside of the carrousel
|
||||||
|
@ -78,7 +77,7 @@ private:
|
||||||
Q_DISABLE_COPY(VPCarrouselPieceList)
|
Q_DISABLE_COPY(VPCarrouselPieceList)
|
||||||
|
|
||||||
QList<VPPiece *> m_pieceList{};
|
QList<VPPiece *> m_pieceList{};
|
||||||
QPoint m_dragStart;
|
QPoint m_dragStart{};
|
||||||
VPCarrousel *m_carrousel{nullptr};
|
VPCarrousel *m_carrousel{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user