profile: port context menu to QtQuick
This is for desktop only. We will have to think about what to do on mobile. Either a "hamburger menu" or a "long click" seem to be the most reasonable options. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0bf1d35a4b
commit
fade8ca95d
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
|
#include "desktop-widgets/simplewidgets.h"
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -106,7 +107,7 @@ ProfileView::ProfileView(QQuickItem *parent) :
|
|||||||
setFlag(ItemHasContents, true);
|
setFlag(ItemHasContents, true);
|
||||||
|
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setAcceptedMouseButtons(Qt::LeftButton);
|
setAcceptedMouseButtons(Qt::RightButton | Qt::LeftButton);
|
||||||
|
|
||||||
auto tec = qPrefTechnicalDetails::instance();
|
auto tec = qPrefTechnicalDetails::instance();
|
||||||
connect(tec, &qPrefTechnicalDetails::calcalltissuesChanged , this, &ProfileView::replot);
|
connect(tec, &qPrefTechnicalDetails::calcalltissuesChanged , this, &ProfileView::replot);
|
||||||
@ -462,6 +463,15 @@ void ProfileView::editEventName(struct event *event)
|
|||||||
#endif
|
#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.
|
// Formats cylinder information for display.
|
||||||
// eg : "Cyl 1 (AL80 EAN32)"
|
// eg : "Cyl 1 (AL80 EAN32)"
|
||||||
static QString formatCylinderDescription(int i, const cylinder_t *cylinder)
|
static QString formatCylinderDescription(int i, const cylinder_t *cylinder)
|
||||||
@ -484,6 +494,63 @@ void ProfileView::unhideEvents()
|
|||||||
replot();
|
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<MenuEntry> 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<MenuEntry> 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<MenuEntry> 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)
|
void ProfileView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
// Handle dragging of items
|
// Handle dragging of items
|
||||||
@ -491,6 +558,12 @@ void ProfileView::mousePressEvent(QMouseEvent *event)
|
|||||||
if (event->isAccepted())
|
if (event->isAccepted())
|
||||||
return;
|
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
|
// Open context menu if computer name is clicked
|
||||||
if (d && profileScene->pointOnDiveComputerText(event->pos())) {
|
if (d && profileScene->pointOnDiveComputerText(event->pos())) {
|
||||||
std::vector<MenuEntry> m;
|
std::vector<MenuEntry> m;
|
||||||
|
|||||||
@ -108,6 +108,8 @@ private:
|
|||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
void contextMenu(const QPointF pos, const QPoint globalPos);
|
||||||
|
void addSetpointChange(int seconds);
|
||||||
|
|
||||||
ChartItemPtr<ToolTipItem> tooltip;
|
ChartItemPtr<ToolTipItem> tooltip;
|
||||||
void updateTooltip(QPointF pos, bool plannerMode, int animSpeed);
|
void updateTooltip(QPointF pos, bool plannerMode, int animSpeed);
|
||||||
|
|||||||
@ -294,109 +294,6 @@ bool ProfileWidget2::isPlanner() const
|
|||||||
return currentState == PLAN;
|
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<DiveEventItem *>(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
|
#ifndef SUBSURFACE_MOBILE
|
||||||
|
|
||||||
void ProfileWidget2::profileChanged(dive *dive)
|
void ProfileWidget2::profileChanged(dive *dive)
|
||||||
|
|||||||
@ -307,6 +307,10 @@ void ChartView::setLayerVisibility(size_t z, bool visible)
|
|||||||
|
|
||||||
void ChartView::mousePressEvent(QMouseEvent *event)
|
void ChartView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
// Only left-button for drag events.
|
||||||
|
if (event->button() != Qt::LeftButton)
|
||||||
|
return event->ignore();
|
||||||
|
|
||||||
QPointF pos = event->localPos();
|
QPointF pos = event->localPos();
|
||||||
|
|
||||||
for (auto item: dragableItems) {
|
for (auto item: dragableItems) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user