Commit a035284f authored by Stefan Majewsky's avatar Stefan Majewsky

Massive performance optimization of cursor management for big puzzles.

Call QGraphicsItem::setCursor for the Part as a whole rather than for
the single pieces. This means that the cursor is now also set for shadow
items. I have consequently enabled mouse interaction for shadow items,
too, in order to have consistent behavior.

This in turn "fixes" feature request 212842, but it introduces an
interesting bug: When one clicks on a piece that is covered by another
piece's shadow, the other piece will be selected instead. I consider
this bug less important than the above-named performance problems of
QGraphicsItem::setCursor.

CCBUG: 212842

svn path=/trunk/KDE/kdegames/palapeli/; revision=1062639
parent a7b79da4
......@@ -32,7 +32,7 @@ Palapeli::Part::Part(Palapeli::Piece* piece)
{
m_pieces << piece;
piece->setParentItem(this);
piece->setCursor(Qt::OpenHandCursor);
setCursor(Qt::OpenHandCursor);
setFlag(QGraphicsItem::ItemIsMovable);
setHandlesChildEvents(true);
//add shadow to piece
......@@ -57,8 +57,7 @@ void Palapeli::Part::mousePressEvent(QGraphicsSceneMouseEvent* event)
//move item to top
static int zValue = 0;
setZValue(++zValue);
foreach (Palapeli::Piece* piece, m_pieces)
piece->setCursor(Qt::ClosedHandCursor);
setCursor(Qt::ClosedHandCursor);
}
}
......@@ -79,8 +78,7 @@ void Palapeli::Part::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
searchConnections();
emit partMoved();
foreach (Palapeli::Piece* piece, m_pieces)
piece->setCursor(Qt::OpenHandCursor);
setCursor(Qt::OpenHandCursor);
}
}
......
......@@ -23,6 +23,7 @@ Palapeli::Piece::Piece(const QPixmap& pixmap, const QPointF& offset)
: m_pixmapItem(new QGraphicsPixmapItem(pixmap, this))
{
m_pixmapItem->setOffset(offset);
setAcceptedMouseButtons(Qt::LeftButton);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
......
......@@ -101,6 +101,6 @@ QPixmap Palapeli::createShadow(const QPixmap& source, int radius)
Palapeli::ShadowItem::ShadowItem(const QPixmap& pixmap, int radius, const QPointF& offset)
{
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(Palapeli::createShadow(pixmap, radius), this);
item->setAcceptedMouseButtons(0);
item->setAcceptedMouseButtons(Qt::LeftButton);
item->setOffset(offset + QPointF(-radius, -radius));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment