Enable a context menu to remove dive handlers.

This commit enables a context menu to remove dive handlers,
because it was hard to find that ctrl+click selected it,
then a delete button press removed it. it's better now. :)

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2013-11-14 23:29:36 -02:00 committed by Dirk Hohndel
parent 3302ee11c1
commit cec30c27d9
2 changed files with 31 additions and 7 deletions

View file

@ -673,6 +673,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
} }
QPointF mappedPos = mapToScene(event->pos()); QPointF mappedPos = mapToScene(event->pos());
if (event->button() == Qt::LeftButton){
Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) { Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) { if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
activeDraggedHandler = h; activeDraggedHandler = h;
@ -680,6 +681,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
originalHandlerPos = activeDraggedHandler->pos(); originalHandlerPos = activeDraggedHandler->pos();
} }
} }
}
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);
} }
@ -703,8 +705,25 @@ DiveHandler::DiveHandler(): QGraphicsEllipseItem()
setZValue(2); setZValue(2);
} }
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{
QMenu m;
m.addAction(QObject::tr("Remove this Point"), this, SLOT(selfRemove()));
m.exec(event->screenPos());
}
void DiveHandler::selfRemove()
{
setSelected(true);
DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics*>(scene()->views().first());
view->keyDeleteAction();
}
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent* event) void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent* event)
{ {
if (event->button() != Qt::LeftButton)
return;
if (event->modifiers().testFlag(Qt::ControlModifier)) { if (event->modifiers().testFlag(Qt::ControlModifier)) {
setSelected(true); setSelected(true);
} }

View file

@ -95,11 +95,15 @@ private:
QGraphicsSimpleTextItem *text; QGraphicsSimpleTextItem *text;
}; };
class DiveHandler : public QGraphicsEllipseItem{ class DiveHandler : public QObject, public QGraphicsEllipseItem{
Q_OBJECT
public: public:
DiveHandler(); DiveHandler();
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event); void mousePressEvent(QGraphicsSceneMouseEvent* event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
public slots:
void selfRemove();
}; };
class Ruler : public QGraphicsLineItem{ class Ruler : public QGraphicsLineItem{
@ -118,7 +122,6 @@ public:
qreal posAtValue(qreal value); qreal posAtValue(qreal value);
void setColor(const QColor& color); void setColor(const QColor& color);
void setTextColor(const QColor& color); void setTextColor(const QColor& color);
private: private:
Qt::Orientation orientation; Qt::Orientation orientation;
QList<QGraphicsLineItem*> ticks; QList<QGraphicsLineItem*> ticks;
@ -210,6 +213,8 @@ private:
int minMinutes; // this holds the minimum duration of the dive. int minMinutes; // this holds the minimum duration of the dive.
int dpMaxTime; // this is the time of the dive calculated by the deco. int dpMaxTime; // this is the time of the dive calculated by the deco.
friend class DiveHandler;
}; };
#include "ui_diveplanner.h" #include "ui_diveplanner.h"