aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Subsurface-mobile.pro2
-rw-r--r--desktop-widgets/diveplanner.cpp85
-rw-r--r--desktop-widgets/diveplanner.h27
-rw-r--r--packaging/ios/Subsurface-mobile.pro2
-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
9 files changed, 147 insertions, 124 deletions
diff --git a/Subsurface-mobile.pro b/Subsurface-mobile.pro
index fe8ee6ee4..bbb2d561e 100644
--- a/Subsurface-mobile.pro
+++ b/Subsurface-mobile.pro
@@ -157,6 +157,7 @@ SOURCES += subsurface-mobile-main.cpp \
profile-widget/divepixmapitem.cpp \
profile-widget/divetooltipitem.cpp \
profile-widget/tankitem.cpp \
+ profile-widget/divehandler.cpp \
profile-widget/divelineitem.cpp \
profile-widget/diverectitem.cpp \
profile-widget/divetextitem.cpp
@@ -292,6 +293,7 @@ HEADERS += \
profile-widget/tankitem.h \
profile-widget/animationfunctions.h \
profile-widget/divecartesianaxis.h \
+ profile-widget/divehandler.h \
profile-widget/divelineitem.h \
profile-widget/divepixmapitem.h \
profile-widget/diverectitem.h \
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index 166783453..f1efa3f27 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -15,8 +15,6 @@
#include "profile-widget/profilewidget2.h"
#include "qt-models/diveplannermodel.h"
-#include <QGraphicsSceneMouseEvent>
-#include <QSettings>
#include <QShortcut>
#ifndef NO_PRINTING
#include <QPrintDialog>
@@ -24,89 +22,6 @@
#include <QBuffer>
#endif
-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()
-{
- setSelected(true);
- ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
- view->keyDeleteAction();
-}
-
-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();
-}
-
DivePlannerWidget::DivePlannerWidget(QWidget *parent) : QWidget(parent, QFlag(0))
{
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
diff --git a/desktop-widgets/diveplanner.h b/desktop-widgets/diveplanner.h
index e0e2dc026..7f1857f6a 100644
--- a/desktop-widgets/diveplanner.h
+++ b/desktop-widgets/diveplanner.h
@@ -2,41 +2,14 @@
#ifndef DIVEPLANNER_H
#define DIVEPLANNER_H
-#include <QGraphicsPathItem>
#include <QAbstractTableModel>
#include <QAbstractButton>
#include <QDateTime>
-#include <QSignalMapper>
-#include <QElapsedTimer>
class QListView;
class QModelIndex;
class DivePlannerPointsModel;
-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;
-};
-
#include "ui_diveplanner.h"
class DivePlannerWidget : public QWidget {
diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro
index 2bcbd698e..23e99b1e8 100644
--- a/packaging/ios/Subsurface-mobile.pro
+++ b/packaging/ios/Subsurface-mobile.pro
@@ -163,6 +163,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \
../../profile-widget/divepixmapitem.cpp \
../../profile-widget/divetooltipitem.cpp \
../../profile-widget/tankitem.cpp \
+ ../../profile-widget/divehandler.cpp \
../../profile-widget/divelineitem.cpp \
../../profile-widget/diverectitem.cpp \
../../profile-widget/divetextitem.cpp
@@ -322,6 +323,7 @@ HEADERS += \
../../profile-widget/tankitem.h \
../../profile-widget/animationfunctions.h \
../../profile-widget/divecartesianaxis.h \
+ ../../profile-widget/divehandler.h \
../../profile-widget/divelineitem.h \
../../profile-widget/divepixmapitem.h \
../../profile-widget/diverectitem.h \
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;