diff --git a/profile-widget/profileview.cpp b/profile-widget/profileview.cpp index e395ec187..ab0eb0e83 100644 --- a/profile-widget/profileview.cpp +++ b/profile-widget/profileview.cpp @@ -31,6 +31,7 @@ #ifndef SUBSURFACE_MOBILE #include "core/device.h" +#include "desktop-widgets/simplewidgets.h" #include #include #include @@ -106,7 +107,7 @@ ProfileView::ProfileView(QQuickItem *parent) : setFlag(ItemHasContents, true); setAcceptHoverEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); + setAcceptedMouseButtons(Qt::RightButton | Qt::LeftButton); auto tec = qPrefTechnicalDetails::instance(); connect(tec, &qPrefTechnicalDetails::calcalltissuesChanged , this, &ProfileView::replot); @@ -462,6 +463,15 @@ void ProfileView::editEventName(struct event *event) #endif } +// TODO: How should that work on mobile? +void ProfileView::addSetpointChange(int seconds) +{ +#ifndef SUBSURFACE_MOBILE + SetpointDialog dialog(mutable_dive(), dc, seconds); + dialog.exec(); +#endif +} + // Formats cylinder information for display. // eg : "Cyl 1 (AL80 EAN32)" static QString formatCylinderDescription(int i, const cylinder_t *cylinder) @@ -484,6 +494,63 @@ void ProfileView::unhideEvents() replot(); } +void ProfileView::contextMenu(const QPointF pos, const QPoint globalPos) +{ + // No context menu in Plan mode + if (mode == Mode::Plan) + return; + + // Only open the contextmenu on the profile + if (!d || !profileScene->pointOnProfile(pos)) + return; + + std::vector m; + int seconds = profileScene->timeAt(pos); + + // if we have more than one gas, offer to switch to another one + if (d->cylinders.nr > 1) { + std::vector gasChangeMenu; + for (int i = 0; i < d->cylinders.nr; i++) { + const cylinder_t *cylinder = get_cylinder(d, i); + QString label = formatCylinderDescription(i, cylinder); + gasChangeMenu.emplace_back(label, [this, i, seconds] { + Command::addGasSwitch(mutable_dive(), dc, seconds, i); + }); + } + m.emplace_back(tr("Add gas change"), std::move(gasChangeMenu)); + } + + m.emplace_back(tr("Add setpoint change"), [this, seconds]() { addSetpointChange(seconds); }); + m.emplace_back(tr("Add bookmark"), [this, seconds]() { + Command::addEventBookmark(mutable_dive(), dc, seconds); + }); + m.emplace_back(tr("Split dive into two"), [this, seconds]() { + Command::splitDives(mutable_dive(), duration_t{ seconds }); + }); + + + const struct event *ev = NULL; + enum divemode_t divemode = UNDEF_COMP_TYPE; + + std::vector changeModeMenu; + get_current_divemode(get_dive_dc_const(d, dc), seconds, &ev, &divemode); + if (divemode != OC) + changeModeMenu.emplace_back(gettextFromC::tr(divemode_text_ui[OC]), [this, seconds]() { + Command::addEventDivemodeSwitch(mutable_dive(), dc, seconds, OC); + }); + if (divemode != CCR) + changeModeMenu.emplace_back(gettextFromC::tr(divemode_text_ui[CCR]), [this, seconds]() { + Command::addEventDivemodeSwitch(mutable_dive(), dc, seconds, CCR); + }); + if (divemode != PSCR) + changeModeMenu.emplace_back(gettextFromC::tr(divemode_text_ui[PSCR]), [this, seconds]() { + Command::addEventDivemodeSwitch(mutable_dive(), dc, seconds, PSCR); + }); + m.emplace_back(tr("Change divemode"), changeModeMenu); + + execMenu(m, globalPos); +} + void ProfileView::mousePressEvent(QMouseEvent *event) { // Handle dragging of items @@ -491,6 +558,12 @@ void ProfileView::mousePressEvent(QMouseEvent *event) if (event->isAccepted()) return; + // On Desktop, the right botton opens the menu. + // For Mobile, we will have to think about something. + // Perhaps a "hamburger menu"? + if (event->button() == Qt::RightButton) + return contextMenu(event->pos(), event->globalPos()); + // Open context menu if computer name is clicked if (d && profileScene->pointOnDiveComputerText(event->pos())) { std::vector m; diff --git a/profile-widget/profileview.h b/profile-widget/profileview.h index 76d4b8f75..7bc76da2d 100644 --- a/profile-widget/profileview.h +++ b/profile-widget/profileview.h @@ -108,6 +108,8 @@ private: void mouseReleaseEvent(QMouseEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override; void keyPressEvent(QKeyEvent *e) override; + void contextMenu(const QPointF pos, const QPoint globalPos); + void addSetpointChange(int seconds); ChartItemPtr tooltip; void updateTooltip(QPointF pos, bool plannerMode, int animSpeed); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 1d44a8c3f..4b5e60329 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -294,109 +294,6 @@ bool ProfileWidget2::isPlanner() const return currentState == PLAN; } -#if 0 // TODO::: FINISH OR DISABLE -struct int ProfileWidget2::getEntryFromPos(QPointF pos) -{ - // find the time stamp corresponding to the mouse position - int seconds = lrint(timeAxis->valueAt(pos)); - - for (int i = 0; i < plotInfo.nr; i++) { - if (plotInfo.entry[i].sec >= seconds) - return i; - } - return plotInfo.nr - 1; -} -#endif - -#ifndef SUBSURFACE_MOBILE - -static bool isDiveTextItem(const QGraphicsItem *item, const DiveTextItem *textItem) -{ - while (item) { - if (item == textItem) - return true; - item = item->parentItem(); - } - return false; -} - -void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) -{ - if (currentState == EDIT || currentState == PLAN) { - QGraphicsView::contextMenuEvent(event); - return; - } - QMenu m; - if (!d) - return; - - // create the profile context menu - QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos())); - qreal sec_val = profileScene->timeAxis->valueAt(scenePos); - int seconds = (sec_val < 0.0) ? 0 : (int)sec_val; - DiveEventItem *item = dynamic_cast(sceneItem); - - // Add or edit Gas Change - if (d && item && event_is_gaschange(item->getEvent())) { - } else if (d && d->cylinders.nr > 1) { - // if we have more than one gas, offer to switch to another one - QMenu *gasChange = m.addMenu(tr("Add gas change")); - for (int i = 0; i < d->cylinders.nr; i++) { - const cylinder_t *cylinder = get_cylinder(d, i); - QString label = printCylinderDescription(i, cylinder); - gasChange->addAction(label, [this, i, seconds] { changeGas(i, seconds); }); - } - } - m.addAction(tr("Add setpoint change"), [this, seconds]() { ProfileWidget2::addSetpointChange(seconds); }); - m.addAction(tr("Add bookmark"), [this, seconds]() { addBookmark(seconds); }); - m.addAction(tr("Split dive into two"), [this, seconds]() { splitDive(seconds); }); - const struct event *ev = NULL; - enum divemode_t divemode = UNDEF_COMP_TYPE; - - get_current_divemode(get_dive_dc_const(d, dc), seconds, &ev, &divemode); - QMenu *changeMode = m.addMenu(tr("Change divemode")); - if (divemode != OC) - changeMode->addAction(gettextFromC::tr(divemode_text_ui[OC]), - [this, seconds](){ addDivemodeSwitch(seconds, OC); }); - if (divemode != CCR) - changeMode->addAction(gettextFromC::tr(divemode_text_ui[CCR]), - [this, seconds](){ addDivemodeSwitch(seconds, CCR); }); - if (divemode != PSCR) - changeMode->addAction(gettextFromC::tr(divemode_text_ui[PSCR]), - [this, seconds](){ addDivemodeSwitch(seconds, PSCR); }); - - m.exec(event->globalPos()); -} - -void ProfileWidget2::addBookmark(int seconds) -{ - if (d) - Command::addEventBookmark(mutable_dive(), dc, seconds); -} - -void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode) -{ - if (d) - Command::addEventDivemodeSwitch(mutable_dive(), dc, seconds, divemode); -} - -void ProfileWidget2::addSetpointChange(int seconds) -{ - if (!d) - return; - SetpointDialog dialog(mutable_dive(), dc, seconds); - dialog.exec(); -} - -void ProfileWidget2::splitDive(int seconds) -{ - if (!d) - return; - Command::splitDives(mutable_dive(), duration_t{ seconds }); -} - -#endif - #ifndef SUBSURFACE_MOBILE void ProfileWidget2::profileChanged(dive *dive) diff --git a/qt-quick/chartview.cpp b/qt-quick/chartview.cpp index aada86f96..03c72dd4d 100644 --- a/qt-quick/chartview.cpp +++ b/qt-quick/chartview.cpp @@ -307,6 +307,10 @@ void ChartView::setLayerVisibility(size_t z, bool visible) void ChartView::mousePressEvent(QMouseEvent *event) { + // Only left-button for drag events. + if (event->button() != Qt::LeftButton) + return event->ignore(); + QPointF pos = event->localPos(); for (auto item: dragableItems) {