summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2018-04-08 22:09:26 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-05-14 23:47:00 +0300
commit6b0ecb012dcfe1945bedf38fe25f67a1d2c3c400 (patch)
treef074faf8ddbdeac480c70628e7003b343609c8e4 /profile-widget
parent9c24d6bef816c05992c59b45d32fcb4fe256d5a3 (diff)
downloadsubsurface-6b0ecb012dcfe1945bedf38fe25f67a1d2c3c400.tar.gz
Place divemode changes in submenu of context menu
Also unify the repeated code in slots. Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/profilewidget2.cpp63
-rw-r--r--profile-widget/profilewidget2.h4
2 files changed, 35 insertions, 32 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 4c141b5bb..e5502a3f6 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1413,13 +1413,35 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
setpointAction->setData(event->globalPos());
QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark()));
action->setData(event->globalPos());
- if(current_dc->divemode) {
- QAction *OCAction = m.addAction(tr("Add OC switch"), this, SLOT(addOCSwitch()));
- OCAction->setData(event->globalPos());
- QAction *CCRAction = m.addAction(tr("Add CCR switch"), this, SLOT(addCCRSwitch()));
- CCRAction->setData(event->globalPos());
- QAction *PSCRAction = m.addAction(tr("Add PSCR switch"), this, SLOT(addPSCRSwitch()));
- PSCRAction->setData(event->globalPos());
+ struct event *ev = NULL;
+ enum dive_comp_type divemode = UNDEF_COMP_TYPE;
+ QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos()));
+ QString gas = action->text();
+ qreal sec_val = timeAxis->valueAt(scenePos);
+ int seconds = (sec_val < 0.0) ? 0 : (int)sec_val;
+
+ get_current_divemode(current_dc, seconds, &ev, &divemode);
+ QMenu *changeMode = m.addMenu(tr("Change divemode"));
+ if (divemode != OC) {
+ QAction *action = new QAction(&m);
+ action->setText("OC");
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwith()));
+ action->setData(event->globalPos());
+ changeMode->addAction(action);
+ }
+ if (divemode != CCR) {
+ QAction *action = new QAction(&m);
+ action->setText("CCR");
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwith()));
+ action->setData(event->globalPos());
+ changeMode->addAction(action);
+ }
+ if (divemode != PSCR) {
+ QAction *action = new QAction(&m);
+ action->setText("PSCR");
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwith()));
+ action->setData(event->globalPos());
+ changeMode->addAction(action);
}
if (same_string(current_dc->model, "manually added dive"))
@@ -1582,31 +1604,14 @@ void ProfileWidget2::addBookmark()
replot();
}
-void ProfileWidget2::addOCSwitch()
-{
- QAction *action = qobject_cast<QAction *>(sender());
- QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
- add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), 8, 0, 0, "modechange");
- invalidate_dive_cache(current_dive);
- mark_divelist_changed(true);
- replot();
-}
-
-void ProfileWidget2::addCCRSwitch()
-{
- QAction *action = qobject_cast<QAction *>(sender());
- QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
- add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), 8, 0, 1, "modechange");
- invalidate_dive_cache(current_dive);
- mark_divelist_changed(true);
- replot();
-}
-
-void ProfileWidget2::addPSCRSwitch()
+void ProfileWidget2::addDivemodeSwith()
{
+ int i;
QAction *action = qobject_cast<QAction *>(sender());
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
- add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), 8, 0, 2, "modechange");
+ for (i = 0; i < UNDEF_COMP_TYPE; i++)
+ if (QString(divemode_text[i]) == action->text())
+ add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), 8, 0, i, "modechange");
invalidate_dive_cache(current_dive);
mark_divelist_changed(true);
replot();
diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h
index 65a7d99c5..d13ff194b 100644
--- a/profile-widget/profilewidget2.h
+++ b/profile-widget/profilewidget2.h
@@ -115,9 +115,7 @@ slots: // Necessary to call from QAction's signals.
void changeGas();
void addSetpointChange();
void addBookmark();
- void addOCSwitch();
- void addCCRSwitch();
- void addPSCRSwitch();
+ void addDivemodeSwith();
void hideEvents();
void unhideEvents();
void removeEvent();