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,31 +92,66 @@ 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();
|
||||||
|
|
||||||
QPixmap pixmap(size);
|
QVector<QIcon::Mode> iconModes;
|
||||||
pixmap.fill(QColor("white"));
|
iconModes.append(QIcon::Normal);
|
||||||
|
|
||||||
QPainter painter;
|
if(not isDragIcon)
|
||||||
painter.begin(&pixmap);
|
{
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
iconModes.append(QIcon::Selected);
|
||||||
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;
|
QIcon icon;
|
||||||
|
|
||||||
icon.addPixmap(pixmap,QIcon::Normal);
|
for(auto iconMode : iconModes)
|
||||||
icon.addPixmap(pixmap,QIcon::Selected);
|
{
|
||||||
|
QPixmap pixmap(size);
|
||||||
|
|
||||||
|
if(not isDragIcon)
|
||||||
|
{
|
||||||
|
pixmap.fill(QColor(Qt::white));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pixmap.fill(QColor(Qt::transparent));
|
||||||
|
}
|
||||||
|
|
||||||
|
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)));
|
||||||
|
|
||||||
|
if(not isDragIcon)
|
||||||
|
{
|
||||||
|
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.end();
|
||||||
|
|
||||||
|
icon.addPixmap(pixmap,iconMode);
|
||||||
|
}
|
||||||
|
|
||||||
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