aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-11-14 23:29:36 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-15 13:15:35 +0900
commitcec30c27d936a45d87e707363f824653949a5c02 (patch)
tree68fdfdce95f9a9f5914d4e6b61cf73f2ae936c70 /qt-ui
parent3302ee11c1fc215b979da7a403dc5468da68e84c (diff)
downloadsubsurface-cec30c27d936a45d87e707363f824653949a5c02.tar.gz
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>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/diveplanner.cpp29
-rw-r--r--qt-ui/diveplanner.h9
2 files changed, 31 insertions, 7 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 34c729944..0b5b3301e 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -673,11 +673,13 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
}
QPointF mappedPos = mapToScene(event->pos());
- Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
- if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
- activeDraggedHandler = h;
- activeDraggedHandler->setBrush(Qt::red);
- originalHandlerPos = activeDraggedHandler->pos();
+ if (event->button() == Qt::LeftButton){
+ Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
+ if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
+ activeDraggedHandler = h;
+ activeDraggedHandler->setBrush(Qt::red);
+ originalHandlerPos = activeDraggedHandler->pos();
+ }
}
}
QGraphicsView::mousePressEvent(event);
@@ -703,8 +705,25 @@ DiveHandler::DiveHandler(): QGraphicsEllipseItem()
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)
{
+ if (event->button() != Qt::LeftButton)
+ return;
+
if (event->modifiers().testFlag(Qt::ControlModifier)) {
setSelected(true);
}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 232b8f0fe..bd9b254d1 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -95,11 +95,15 @@ private:
QGraphicsSimpleTextItem *text;
};
-class DiveHandler : public QGraphicsEllipseItem{
+class DiveHandler : public QObject, public QGraphicsEllipseItem{
+Q_OBJECT
public:
DiveHandler();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event);
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
+public slots:
+ void selfRemove();
};
class Ruler : public QGraphicsLineItem{
@@ -118,7 +122,6 @@ public:
qreal posAtValue(qreal value);
void setColor(const QColor& color);
void setTextColor(const QColor& color);
-
private:
Qt::Orientation orientation;
QList<QGraphicsLineItem*> ticks;
@@ -210,6 +213,8 @@ private:
int minMinutes; // this holds the minimum duration of the dive.
int dpMaxTime; // this is the time of the dive calculated by the deco.
+
+ friend class DiveHandler;
};
#include "ui_diveplanner.h"