Improve Piece carrousel icon and drag icon
This commit is contained in:
parent
728b2c83c3
commit
dd5970f8ba
|
@ -74,7 +74,7 @@ void VPCarrouselPiece::RefreshSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const
|
QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size, bool isDragIcon) const
|
||||||
{
|
{
|
||||||
QVector<QPointF> points = m_piece->GetMappedContourPoints(); // seamline
|
QVector<QPointF> points = m_piece->GetMappedContourPoints(); // seamline
|
||||||
if(points.isEmpty())
|
if(points.isEmpty())
|
||||||
|
@ -92,8 +92,28 @@ QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const
|
||||||
qreal dx = canvas.center().x() - boundingRect.center().x();
|
qreal dx = canvas.center().x() - boundingRect.center().x();
|
||||||
qreal dy = canvas.center().y() - boundingRect.center().y();
|
qreal dy = canvas.center().y() - boundingRect.center().y();
|
||||||
|
|
||||||
|
QVector<QIcon::Mode> iconModes;
|
||||||
|
iconModes.append(QIcon::Normal);
|
||||||
|
|
||||||
|
if(not isDragIcon)
|
||||||
|
{
|
||||||
|
iconModes.append(QIcon::Selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon icon;
|
||||||
|
|
||||||
|
for(auto iconMode : iconModes)
|
||||||
|
{
|
||||||
QPixmap pixmap(size);
|
QPixmap pixmap(size);
|
||||||
pixmap.fill(QColor("white"));
|
|
||||||
|
if(not isDragIcon)
|
||||||
|
{
|
||||||
|
pixmap.fill(QColor(Qt::white));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pixmap.fill(QColor(Qt::transparent));
|
||||||
|
}
|
||||||
|
|
||||||
QPainter painter;
|
QPainter painter;
|
||||||
painter.begin(&pixmap);
|
painter.begin(&pixmap);
|
||||||
|
@ -101,6 +121,7 @@ QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
int spacing = 2;
|
int spacing = 2;
|
||||||
|
|
||||||
painter.translate(spacing, spacing);
|
painter.translate(spacing, spacing);
|
||||||
|
|
||||||
qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100;
|
qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100;
|
||||||
|
@ -108,15 +129,29 @@ QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const
|
||||||
painter.scale(1./scaleFactorX, 1./scaleFactorY);
|
painter.scale(1./scaleFactorX, 1./scaleFactorY);
|
||||||
painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY)));
|
painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY)));
|
||||||
|
|
||||||
|
if(not isDragIcon)
|
||||||
|
{
|
||||||
painter.translate(dx, dy);
|
painter.translate(dx, dy);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
painter.translate(-boundingRect.topLeft().x()+spacing, -boundingRect.topLeft().y()+spacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(iconMode == QIcon::Selected)
|
||||||
|
{
|
||||||
|
painter.setBrush(QBrush(QColor(255,160,160,60)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
painter.setBrush(QBrush(Qt::white));
|
||||||
|
}
|
||||||
|
|
||||||
painter.drawPolygon(shape);
|
painter.drawPolygon(shape);
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
QIcon icon;
|
icon.addPixmap(pixmap,iconMode);
|
||||||
|
}
|
||||||
icon.addPixmap(pixmap,QIcon::Normal);
|
|
||||||
icon.addPixmap(pixmap,QIcon::Selected);
|
|
||||||
|
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
* @param size of the icon
|
* @param size of the icon
|
||||||
* @return the created icon
|
* @return the created icon
|
||||||
*/
|
*/
|
||||||
QIcon CreatePieceIcon(const QSize &size) const;
|
QIcon CreatePieceIcon(const QSize &size, bool isDragIcon = false) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -47,7 +47,7 @@ VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) :
|
||||||
QListWidget(parent),
|
QListWidget(parent),
|
||||||
m_dragStart(QPoint())
|
m_dragStart(QPoint())
|
||||||
{
|
{
|
||||||
setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid red;}");
|
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);
|
||||||
|
@ -163,7 +163,7 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
|
||||||
mimeData->SetPiecePtr(piece);
|
mimeData->SetPiecePtr(piece);
|
||||||
mimeData->setObjectName("piecePointer");
|
mimeData->setObjectName("piecePointer");
|
||||||
|
|
||||||
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120)).pixmap(QSize(120,120));
|
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120), true).pixmap(QSize(120,120));
|
||||||
|
|
||||||
drag->setPixmap(pixmap);
|
drag->setPixmap(pixmap);
|
||||||
drag->setMimeData(mimeData);
|
drag->setMimeData(mimeData);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user