mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Place divemode changes in submenu of context menu
Also unify the repeated code in slots. Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
9c24d6bef8
commit
6b0ecb012d
2 changed files with 35 additions and 32 deletions
|
@ -1413,13 +1413,35 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
||||||
setpointAction->setData(event->globalPos());
|
setpointAction->setData(event->globalPos());
|
||||||
QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark()));
|
QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark()));
|
||||||
action->setData(event->globalPos());
|
action->setData(event->globalPos());
|
||||||
if(current_dc->divemode) {
|
struct event *ev = NULL;
|
||||||
QAction *OCAction = m.addAction(tr("Add OC switch"), this, SLOT(addOCSwitch()));
|
enum dive_comp_type divemode = UNDEF_COMP_TYPE;
|
||||||
OCAction->setData(event->globalPos());
|
QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos()));
|
||||||
QAction *CCRAction = m.addAction(tr("Add CCR switch"), this, SLOT(addCCRSwitch()));
|
QString gas = action->text();
|
||||||
CCRAction->setData(event->globalPos());
|
qreal sec_val = timeAxis->valueAt(scenePos);
|
||||||
QAction *PSCRAction = m.addAction(tr("Add PSCR switch"), this, SLOT(addPSCRSwitch()));
|
int seconds = (sec_val < 0.0) ? 0 : (int)sec_val;
|
||||||
PSCRAction->setData(event->globalPos());
|
|
||||||
|
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"))
|
if (same_string(current_dc->model, "manually added dive"))
|
||||||
|
@ -1582,31 +1604,14 @@ void ProfileWidget2::addBookmark()
|
||||||
replot();
|
replot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileWidget2::addOCSwitch()
|
void ProfileWidget2::addDivemodeSwith()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
|
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
|
||||||
add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), 8, 0, 0, "modechange");
|
for (i = 0; i < UNDEF_COMP_TYPE; i++)
|
||||||
invalidate_dive_cache(current_dive);
|
if (QString(divemode_text[i]) == action->text())
|
||||||
mark_divelist_changed(true);
|
add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), 8, 0, i, "modechange");
|
||||||
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()
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
invalidate_dive_cache(current_dive);
|
invalidate_dive_cache(current_dive);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
replot();
|
replot();
|
||||||
|
|
|
@ -115,9 +115,7 @@ slots: // Necessary to call from QAction's signals.
|
||||||
void changeGas();
|
void changeGas();
|
||||||
void addSetpointChange();
|
void addSetpointChange();
|
||||||
void addBookmark();
|
void addBookmark();
|
||||||
void addOCSwitch();
|
void addDivemodeSwith();
|
||||||
void addCCRSwitch();
|
|
||||||
void addPSCRSwitch();
|
|
||||||
void hideEvents();
|
void hideEvents();
|
||||||
void unhideEvents();
|
void unhideEvents();
|
||||||
void removeEvent();
|
void removeEvent();
|
||||||
|
|
Loading…
Add table
Reference in a new issue