summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/profilewidget2.cpp44
-rw-r--r--qt-ui/profile/profilewidget2.h4
2 files changed, 48 insertions, 0 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 6b44dff18..f0b7bc380 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -540,6 +540,30 @@ void ProfileWidget2::wheelEvent(QWheelEvent *event)
toolTipItem->setPos(mapToScene(toolTipPos));
}
+void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ if (currentState == PLAN || currentState == ADD) {
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ QPointF mappedPos = mapToScene(event->pos());
+ if (isPointOutOfBoundaries(mappedPos))
+ return;
+
+ int minutes = rint(timeAxis->valueAt(mappedPos) / 60);
+ int milimeters = rint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
+ plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0, true);
+ }
+}
+
+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
@@ -672,6 +696,26 @@ void ProfileWidget2::setProfileState()
rulerItem->setVisible(prefs.rulergraph);
}
+void ProfileWidget2::setAddState()
+{
+ if (currentState == ADD)
+ return;
+
+ /* show the same stuff that the profile shows. */
+ currentState = ADD; /* enable the add state. */
+ setBackgroundBrush(QColor(Qt::blue).light());
+}
+
+void ProfileWidget2::setPlanState()
+{
+ if (currentState == PLAN)
+ return;
+
+ /* show the same stuff that the profile shows. */
+ currentState = PLAN; /* enable the add state. */
+ setBackgroundBrush(QColor(Qt::green).light());
+}
+
extern struct ev_select *ev_namelist;
extern int evn_allocated;
extern int evn_used;
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index a5d9eed27..1ba6e5723 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -68,6 +68,7 @@ public:
virtual bool eventFilter(QObject *, QEvent *);
void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue);
void setPrintMode(bool mode, bool grayscale = false);
+ bool isPointOutOfBoundaries(const QPointF& point) const;
State currentState;
public
@@ -75,6 +76,8 @@ slots: // Necessary to call from QAction's signals.
void settingsChanged();
void setEmptyState();
void setProfileState();
+ void setPlanState();
+ void setAddState();
void changeGas();
void addBookmark();
void hideEvents();
@@ -88,6 +91,7 @@ protected:
virtual void wheelEvent(QWheelEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *event);
+ virtual void mouseDoubleClickEvent(QMouseEvent *event);
private: /*methods*/
void fixBackgroundPos();