aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-11-19 23:37:45 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-19 17:58:18 -0800
commite8d1f14c90701077d6edc645ad575632fcf29a78 (patch)
tree28518cf9a8f0e38bfd55c8d12156329c08f09f23
parent4c2e6c4658df4d52cf097a3d426a01aaae2b71db (diff)
downloadsubsurface-e8d1f14c90701077d6edc645ad575632fcf29a78.tar.gz
Enable the 'Remove Event' callback.
Based on the code in the Gtk branch. [Dirk Hohndel: whitespace cleanup and changed the message text] Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/profilegraphics.cpp32
-rw-r--r--qt-ui/profilegraphics.h3
2 files changed, 26 insertions, 9 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 231d9f057..a1852a6ab 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -17,6 +17,7 @@
#include <QMouseEvent>
#include <QToolBar>
#include <qtextdocument.h>
+#include <QMessageBox>
#include <limits>
#include "../color.h"
@@ -137,7 +138,7 @@ void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
continue;
QAction *action = new QAction(&m);
action->setText("Remove Event");
- action->setData(event->globalPos()); // so we know what to remove.
+ action->setData(QVariant::fromValue<void*>(item)); // so we know what to remove.
connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent()));
m.addAction(action);
action = new QAction(&m);
@@ -181,12 +182,28 @@ void ProfileGraphicsView::hideEvents()
void ProfileGraphicsView::removeEvent()
{
QAction *action = qobject_cast<QAction*>(sender());
- QPoint globalPos = action->data().toPoint();
- QPoint viewPos = mapFromGlobal(globalPos);
- QPointF scenePos = mapToScene(viewPos);
- qDebug() << "Remove Event";
+ EventItem *item = static_cast<EventItem*>(action->data().value<void*>());
+ struct event *event = item->ev;
+
+ if (QMessageBox::question(mainWindow(),
+ tr("Remove the selected event?"),
+ tr("%1 @ %2:%3").arg(event->name)
+ .arg(event->time.seconds / 60)
+ .arg(event->time.seconds % 60, 2, 10, QChar('0')),
+ QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok){
+ struct event **ep = &current_dc->events;
+ while (ep && *ep != event)
+ ep = &(*ep)->next;
+ if (ep) {
+ *ep = event->next;
+ free(event);
+ }
+ mark_divelist_changed(TRUE);
+ }
+ plot(current_dive, TRUE);
}
+
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
{
if (!toolTip)
@@ -903,7 +920,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
int x = SCALEXGC(ev->time.seconds);
int y = SCALEYGC(entry->depth);
- EventItem *item = new EventItem(0, isGrayscale);
+ EventItem *item = new EventItem(ev, 0, isGrayscale);
item->setPos(x, y);
scene()->addItem(item);
@@ -1536,9 +1553,8 @@ QColor EventItem::getColor(const color_indice_t i)
return profile_color[i].at((isGrayscale) ? 1 : 0);
}
-EventItem::EventItem(QGraphicsItem* parent, bool grayscale): QGraphicsPolygonItem(parent)
+EventItem::EventItem(struct event *ev, QGraphicsItem* parent, bool grayscale): QGraphicsPolygonItem(parent), isGrayscale(grayscale), ev(ev)
{
- isGrayscale = grayscale;
setFlag(ItemIgnoresTransformations);
setFlag(ItemIsFocusable);
setAcceptHoverEvents(true);
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index 5970ca829..059b66785 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -100,7 +100,8 @@ private:
class EventItem : public QGraphicsPolygonItem
{
public:
- explicit EventItem(QGraphicsItem* parent = 0, bool grayscale = FALSE);
+ explicit EventItem(struct event *ev, QGraphicsItem* parent = 0, bool grayscale = FALSE);
+ struct event* ev;
private:
ToolTipItem *controller;