mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
4c2e6c4658
commit
e8d1f14c90
2 changed files with 26 additions and 9 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <qtextdocument.h>
|
#include <qtextdocument.h>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "../color.h"
|
#include "../color.h"
|
||||||
|
@ -137,7 +138,7 @@ void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
||||||
continue;
|
continue;
|
||||||
QAction *action = new QAction(&m);
|
QAction *action = new QAction(&m);
|
||||||
action->setText("Remove Event");
|
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()));
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent()));
|
||||||
m.addAction(action);
|
m.addAction(action);
|
||||||
action = new QAction(&m);
|
action = new QAction(&m);
|
||||||
|
@ -181,12 +182,28 @@ void ProfileGraphicsView::hideEvents()
|
||||||
void ProfileGraphicsView::removeEvent()
|
void ProfileGraphicsView::removeEvent()
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction*>(sender());
|
QAction *action = qobject_cast<QAction*>(sender());
|
||||||
QPoint globalPos = action->data().toPoint();
|
EventItem *item = static_cast<EventItem*>(action->data().value<void*>());
|
||||||
QPoint viewPos = mapFromGlobal(globalPos);
|
struct event *event = item->ev;
|
||||||
QPointF scenePos = mapToScene(viewPos);
|
|
||||||
qDebug() << "Remove Event";
|
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 = ¤t_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)
|
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (!toolTip)
|
if (!toolTip)
|
||||||
|
@ -903,7 +920,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
|
||||||
int x = SCALEXGC(ev->time.seconds);
|
int x = SCALEXGC(ev->time.seconds);
|
||||||
int y = SCALEYGC(entry->depth);
|
int y = SCALEYGC(entry->depth);
|
||||||
|
|
||||||
EventItem *item = new EventItem(0, isGrayscale);
|
EventItem *item = new EventItem(ev, 0, isGrayscale);
|
||||||
item->setPos(x, y);
|
item->setPos(x, y);
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
|
|
||||||
|
@ -1536,9 +1553,8 @@ QColor EventItem::getColor(const color_indice_t i)
|
||||||
return profile_color[i].at((isGrayscale) ? 1 : 0);
|
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(ItemIgnoresTransformations);
|
||||||
setFlag(ItemIsFocusable);
|
setFlag(ItemIsFocusable);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
|
|
@ -100,7 +100,8 @@ private:
|
||||||
class EventItem : public QGraphicsPolygonItem
|
class EventItem : public QGraphicsPolygonItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit EventItem(QGraphicsItem* parent = 0, bool grayscale = FALSE);
|
explicit EventItem(struct event *ev, QGraphicsItem* parent = 0, bool grayscale = FALSE);
|
||||||
|
struct event* ev;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ToolTipItem *controller;
|
ToolTipItem *controller;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue