summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-11-25 18:30:49 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-12-12 15:52:40 -0800
commit3b2ae46eb81281b1e145fe58121b542ce30e3925 (patch)
treecc1c967901726edc017285824329884f09b32faa /profile-widget
parentcd33d88768a14f1ce9651fbd80a40c89aaaec91f (diff)
downloadsubsurface-3b2ae46eb81281b1e145fe58121b542ce30e3925.tar.gz
profile: move DiveHandler to profile-widget folder
These are the small dots that describe dragable points on the profile when in the planner. It makes no sense to have them in desktop's planner-widget code. They belong to the profile. Therefore, move the code there and compile on mobile. Not everything can be compiled on mobile for now, but it is a start. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/CMakeLists.txt2
-rw-r--r--profile-widget/divehandler.cpp95
-rw-r--r--profile-widget/divehandler.h32
-rw-r--r--profile-widget/profilewidget2.cpp22
-rw-r--r--profile-widget/profilewidget2.h4
5 files changed, 143 insertions, 12 deletions
diff --git a/profile-widget/CMakeLists.txt b/profile-widget/CMakeLists.txt
index 2f5ea0378..ef8267d92 100644
--- a/profile-widget/CMakeLists.txt
+++ b/profile-widget/CMakeLists.txt
@@ -6,6 +6,8 @@ set(SUBSURFACE_PROFILE_LIB_SRCS
divecartesianaxis.h
diveeventitem.cpp
diveeventitem.h
+ divehandler.cpp
+ divehandler.h
divelineitem.cpp
divelineitem.h
divepixmapitem.cpp
diff --git a/profile-widget/divehandler.cpp b/profile-widget/divehandler.cpp
new file mode 100644
index 000000000..ab56feb6f
--- /dev/null
+++ b/profile-widget/divehandler.cpp
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "divehandler.h"
+#include "profilewidget2.h"
+#include "core/gettextfromc.h"
+#include "qt-models/diveplannermodel.h"
+#include "qt-models/models.h"
+
+#include <QMenu>
+#include <QGraphicsSceneMouseEvent>
+#include <QSettings>
+
+DiveHandler::DiveHandler() : QGraphicsEllipseItem()
+{
+ setRect(-5, -5, 10, 10);
+ setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
+ setBrush(Qt::white);
+ setZValue(2);
+ t.start();
+}
+
+int DiveHandler::parentIndex()
+{
+ ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
+ return view->handles.indexOf(this);
+}
+
+void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+{
+ QMenu m;
+ // Don't have a gas selection for the last point
+ emit released();
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
+ if (index.sibling(index.row() + 1, index.column()).isValid()) {
+ 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());
+ action->setData(i);
+ connect(action, &QAction::triggered, this, &DiveHandler::changeGas);
+ m.addAction(action);
+ }
+ }
+ // don't allow removing the last point
+ if (plannerModel->rowCount() > 1) {
+ m.addSeparator();
+ m.addAction(gettextFromC::tr("Remove this point"), this, &DiveHandler::selfRemove);
+ m.exec(event->screenPos());
+ }
+}
+
+void DiveHandler::selfRemove()
+{
+#ifndef SUBSURFACE_MOBILE
+ setSelected(true);
+ ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
+ view->keyDeleteAction();
+#endif
+}
+
+void DiveHandler::changeGas()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
+ plannerModel->gasChange(index.sibling(index.row() + 1, index.column()), action->data().toInt());
+}
+
+void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (t.elapsed() < 40)
+ return;
+ t.start();
+
+ ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
+ if(view->isPointOutOfBoundaries(event->scenePos()))
+ return;
+
+ QGraphicsEllipseItem::mouseMoveEvent(event);
+ emit moved();
+}
+
+void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsItem::mousePressEvent(event);
+ emit clicked();
+}
+
+void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsItem::mouseReleaseEvent(event);
+ emit released();
+}
diff --git a/profile-widget/divehandler.h b/profile-widget/divehandler.h
new file mode 100644
index 000000000..ecd0248c8
--- /dev/null
+++ b/profile-widget/divehandler.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef DIVEHANDLER_HPP
+#define DIVEHANDLER_HPP
+
+#include <QGraphicsPathItem>
+#include <QElapsedTimer>
+
+class DiveHandler : public QObject, public QGraphicsEllipseItem {
+ Q_OBJECT
+public:
+ DiveHandler();
+
+protected:
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+signals:
+ void moved();
+ void clicked();
+ void released();
+private:
+ int parentIndex();
+public
+slots:
+ void selfRemove();
+ void changeGas();
+private:
+ QElapsedTimer t;
+};
+
+#endif
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 342c60e90..61764fb6f 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -12,6 +12,7 @@
#include "profile-widget/diveeventitem.h"
#include "profile-widget/divetextitem.h"
#include "profile-widget/divetooltipitem.h"
+#include "profile-widget/divehandler.h"
#include "core/planner.h"
#include "core/device.h"
#include "profile-widget/ruleritem.h"
@@ -23,7 +24,6 @@
#include "core/divelist.h"
#include "core/errorhelper.h"
#ifndef SUBSURFACE_MOBILE
-#include "desktop-widgets/diveplanner.h"
#include "desktop-widgets/simplewidgets.h"
#include "desktop-widgets/divepicturewidget.h"
#include "desktop-widgets/mainwindow.h"
@@ -1003,6 +1003,16 @@ void ProfileWidget2::scale(qreal sx, qreal sy)
#endif
}
+bool ProfileWidget2::isPointOutOfBoundaries(const QPointF &point) const
+{
+ double xpos = timeAxis->valueAt(point);
+ double ypos = profileYAxis->valueAt(point);
+ return xpos > timeAxis->maximum() ||
+ xpos < timeAxis->minimum() ||
+ ypos > profileYAxis->maximum() ||
+ ypos < profileYAxis->minimum();
+}
+
#ifndef SUBSURFACE_MOBILE
void ProfileWidget2::wheelEvent(QWheelEvent *event)
{
@@ -1041,16 +1051,6 @@ void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event)
}
}
-bool ProfileWidget2::isPointOutOfBoundaries(const QPointF &point) const
-{
- double xpos = timeAxis->valueAt(point);
- double ypos = profileYAxis->valueAt(point);
- return xpos > timeAxis->maximum() ||
- xpos < timeAxis->minimum() ||
- ypos > profileYAxis->maximum() ||
- ypos < profileYAxis->minimum();
-}
-
void ProfileWidget2::scrollViewTo(const QPoint &pos)
{
/* since we cannot use translate() directly on the scene we hack on
diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h
index 26552e578..8895fe2ba 100644
--- a/profile-widget/profilewidget2.h
+++ b/profile-widget/profilewidget2.h
@@ -252,12 +252,14 @@ private:
void calculatePictureYPositions();
void updateDurationLine(PictureEntry &e);
void updateThumbnailPaintOrder();
+#endif
QList<DiveHandler *> handles;
+#ifndef SUBSURFACE_MOBILE
void repositionDiveHandlers();
int fixHandlerIndex(DiveHandler *activeHandler);
- friend class DiveHandler;
#endif
+ friend class DiveHandler;
QHash<Qt::Key, QAction *> actionsForKeys;
bool shouldCalculateMaxTime;
bool shouldCalculateMaxDepth;