SVN commit 765006 by aseigo: context menus are nice M +20 -3 piece.cpp M +3 -0 piece.h --- trunk/extragear/plasma/applets/fifteenPuzzle/src/piece.cpp #765005:765006 @@ -24,10 +24,13 @@ #include #include -#include #include #include +#include + +#include + Piece::Piece(int size, int id, QGraphicsItem *parent) : QGraphicsPixmapItem(parent) { @@ -85,9 +88,23 @@ void Piece::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); - if (m_id == 0) { - return; + if (m_id == 0 || event->button() != Qt::LeftButton) { + event->ignore(); + return; } + event->accept(); emit pressed(this); } + +void Piece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + // HACK: QGraphicsItem's documentation says that the event will be passed + // to the parent if it's not handled, but it isn't passed. This can be + // removed when Qt4.4 becomes a requirement. See Qt bug #176902. + Plasma::Widget *parentWidget = Plasma::Widget::parent(this); + if (parentWidget) { + parentWidget->contextMenuEvent(event); + } +} + --- trunk/extragear/plasma/applets/fifteenPuzzle/src/piece.h #765005:765006 @@ -23,6 +23,8 @@ #include #include +class QGraphicsSceneContextMenuEvent; + class Piece : public QObject, public QGraphicsPixmapItem { Q_OBJECT @@ -40,6 +42,7 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); signals: void pressed(QGraphicsItem *item);