diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2014-02-17 19:15:40 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-17 14:50:14 -0800 |
commit | 31ee4dac65bd6e8b0c3583fc0245cc83a90542d5 (patch) | |
tree | 06f1574051bce9fc533a5d2c47d66b5c0d89e5e6 /qt-ui/profile/profilewidget2.cpp | |
parent | d81223b3f4031ec2f33db164351fb369aeed6b8c (diff) | |
download | subsurface-31ee4dac65bd6e8b0c3583fc0245cc83a90542d5.tar.gz |
Make part of the context menu work (gas change event)
The code of the context menu and the gas change event callback is mostly
the same as the old profile, with minimum modifications, as this changes
the order of the code on the callback to make it a bit saner (declare
variables first, call code later).
This also fixes a bug on the model that was not cleaning itself in the
correct way after a call to clear.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/profilewidget2.cpp')
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 659ac1cb4..bba1a96a8 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -10,6 +10,7 @@ #include "divetextitem.h" #include "divetooltipitem.h" #include "animationfunctions.h" +#include "planner.h" #include <QSignalTransition> #include <QPropertyAnimation> #include <QMenu> @@ -543,3 +544,80 @@ void ProfileWidget2::setProfileState() event->setVisible(true); } } + +extern struct ev_select *ev_namelist; +extern int evn_allocated; +extern int evn_used; + +void ProfileWidget2::contextMenuEvent(QContextMenuEvent* event) +{ + if (selected_dive == -1) + return; + QMenu m; + QMenu *gasChange = m.addMenu(tr("Add Gas Change")); + GasSelectionModel *model = GasSelectionModel::instance(); + model->repopulate(); + int rowCount = model->rowCount(); + for (int i = 0; i < rowCount; i++) { + QAction *action = new QAction(&m); + action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString()); + connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); + action->setData(event->globalPos()); + gasChange->addAction(action); + } + QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); + action->setData(event->globalPos()); + QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos()))); + Q_FOREACH(QGraphicsItem *i, itemsAtPos) { + EventItem *item = dynamic_cast<EventItem*>(i); + if (!item) + continue; + action = new QAction(&m); + action->setText(tr("Remove Event")); + 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); + action->setText(tr("Hide similar events")); + action->setData(QVariant::fromValue<void*>(item)); + connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents())); + m.addAction(action); + break; + } + bool some_hidden = false; + for (int i = 0; i < evn_used; i++) { + if (ev_namelist[i].plot_ev == false) { + some_hidden = true; + break; + } + } + if (some_hidden) { + action = m.addAction(tr("Unhide all events"), this, SLOT(unhideEvents())); + action->setData(event->globalPos()); + } + m.exec(event->globalPos()); +} + +void ProfileWidget2::changeGas() +{ + QAction *action = qobject_cast<QAction*>(sender()); + QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); + QString gas = action->text(); + // backup the things on the dataModel, since we will clear that out. + int diveComputer = dataModel->dcShown(); + int diveId = dataModel->id(); + int o2, he; + int seconds = timeAxis->valueAt(scenePos); + struct dive *d = getDiveById(diveId); + + validate_gas(gas.toUtf8().constData(), &o2, &he); + add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, o2, he)); + // this means we potentially have a new tank that is being used and needs to be shown + fixup_dive(d); + MainWindow::instance()->information()->updateDiveInfo(selected_dive); + mark_divelist_changed(true); + // force the redraw of the dive. + //TODO: find a way to make this do not need a full redraw + dataModel->clear(); + plotDives(QList<dive*>() << getDiveById(diveId)); +}
\ No newline at end of file |