summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/animationfunctions.cpp10
-rw-r--r--qt-ui/profile/animationfunctions.h3
-rw-r--r--qt-ui/profile/divecartesianaxis.cpp40
-rw-r--r--qt-ui/profile/divecartesianaxis.h2
-rw-r--r--qt-ui/profile/diveplotdatamodel.cpp2
-rw-r--r--qt-ui/profile/diveprofileitem.cpp39
-rw-r--r--qt-ui/profile/diveprofileitem.h14
-rw-r--r--qt-ui/profile/divetooltipitem.cpp19
-rw-r--r--qt-ui/profile/divetooltipitem.h3
-rw-r--r--qt-ui/profile/profilewidget2.cpp479
-rw-r--r--qt-ui/profile/profilewidget2.h34
-rw-r--r--qt-ui/profile/ruleritem.cpp20
-rw-r--r--qt-ui/profile/ruleritem.h10
13 files changed, 555 insertions, 120 deletions
diff --git a/qt-ui/profile/animationfunctions.cpp b/qt-ui/profile/animationfunctions.cpp
index 05e437cf0..bd08a22ee 100644
--- a/qt-ui/profile/animationfunctions.cpp
+++ b/qt-ui/profile/animationfunctions.cpp
@@ -4,8 +4,7 @@
#include <QPropertyAnimation>
#include <QPointF>
-namespace Animations
-{
+namespace Animations {
void hide(QObject *obj)
{
@@ -26,15 +25,14 @@ namespace Animations
void moveTo(QObject *obj, qreal x, qreal y)
{
- if (prefs.animation != 0){
+ if (prefs.animation != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
animation->setDuration(prefs.animation);
animation->setStartValue(obj->property("pos").toPointF());
animation->setEndValue(QPointF(x, y));
animation->start(QAbstractAnimation::DeleteWhenStopped);
- }
- else{
- obj->setProperty("pos", QPointF(x,y));
+ } else {
+ obj->setProperty("pos", QPointF(x, y));
}
}
diff --git a/qt-ui/profile/animationfunctions.h b/qt-ui/profile/animationfunctions.h
index e0338393e..9269e6dd3 100644
--- a/qt-ui/profile/animationfunctions.h
+++ b/qt-ui/profile/animationfunctions.h
@@ -6,8 +6,7 @@
class QObject;
-namespace Animations
-{
+namespace Animations {
void hide(QObject *obj);
void moveTo(QObject *obj, qreal x, qreal y);
void moveTo(QObject *obj, const QPointF &pos);
diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
index c1e93faa7..353f9880c 100644
--- a/qt-ui/profile/divecartesianaxis.cpp
+++ b/qt-ui/profile/divecartesianaxis.cpp
@@ -97,7 +97,7 @@ void DiveCartesianAxis::setTextVisible(bool arg1)
return;
}
textVisibility = arg1;
- Q_FOREACH(DiveTextItem * item, labels) {
+ Q_FOREACH (DiveTextItem *item, labels) {
item->setVisible(textVisibility);
}
}
@@ -108,7 +108,7 @@ void DiveCartesianAxis::setLinesVisible(bool arg1)
return;
}
lineVisibility = arg1;
- Q_FOREACH(DiveLineItem * item, lines) {
+ Q_FOREACH (DiveLineItem *item, lines) {
item->setVisible(lineVisibility);
}
}
@@ -161,8 +161,8 @@ void DiveCartesianAxis::updateTicks(color_indice_t color)
for (int i = 0, count = labels.size(); i < count; i++, currValueText += interval) {
qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ?
- begin + i * stepSize :
- begin - i * stepSize;
+ begin + i * stepSize :
+ begin - i * stepSize;
labels[i]->setText(textForValue(currValueText));
if (orientation == LeftToRight || orientation == RightToLeft) {
@@ -174,8 +174,8 @@ void DiveCartesianAxis::updateTicks(color_indice_t color)
for (int i = 0, count = lines.size(); i < count; i++, currValueLine += interval) {
qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ?
- begin + i * stepSize :
- begin - i * stepSize;
+ begin + i * stepSize :
+ begin - i * stepSize;
if (orientation == LeftToRight || orientation == RightToLeft) {
lines[i]->animateMoveTo(childPos, m.y1());
@@ -237,9 +237,9 @@ void DiveCartesianAxis::updateTicks(color_indice_t color)
}
}
- Q_FOREACH(DiveTextItem * item, labels)
+ Q_FOREACH (DiveTextItem *item, labels)
item->setVisible(textVisibility);
- Q_FOREACH(DiveLineItem * item, lines)
+ Q_FOREACH (DiveLineItem *item, lines)
item->setVisible(lineVisibility);
}
@@ -272,8 +272,8 @@ qreal DiveCartesianAxis::valueAt(const QPointF &p) const
relativePosition -= pos(); // normalize p based on the axis' offset on screen
double retValue = (orientation == LeftToRight || orientation == RightToLeft) ?
- max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) :
- max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1());
+ max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) :
+ max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1());
return retValue;
}
@@ -289,8 +289,8 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
double realSize = orientation == LeftToRight || orientation == RightToLeft ?
- m.x2() - m.x1() :
- m.y2() - m.y1();
+ m.x2() - m.x1() :
+ m.y2() - m.y1();
// Inverted axis, just invert the percentage.
if (orientation == RightToLeft || orientation == BottomToTop)
@@ -298,10 +298,10 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
double retValue = realSize * percent;
double adjusted =
- orientation == LeftToRight ? retValue + m.x1() + p.x() :
- orientation == RightToLeft ? retValue + m.x1() + p.x() :
- orientation == TopToBottom ? retValue + m.y1() + p.y() :
- /* entation == BottomToTop */ retValue + m.y1() + p.y();
+ orientation == LeftToRight ? retValue + m.x1() + p.x() :
+ orientation == RightToLeft ? retValue + m.x1() + p.x() :
+ orientation == TopToBottom ? retValue + m.y1() + p.y() :
+ /* entation == BottomToTop */ retValue + m.y1() + p.y();
return adjusted;
}
@@ -411,17 +411,17 @@ QString TemperatureAxis::textForValue(double value)
PartialGasPressureAxis::PartialGasPressureAxis()
{
- connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(preferencesChanged()));
+ connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
}
void PartialGasPressureAxis::setModel(DivePlotDataModel *m)
{
model = m;
- connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(preferencesChanged()));
- preferencesChanged();
+ connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(settingsChanged()));
+ settingsChanged();
}
-void PartialGasPressureAxis::preferencesChanged()
+void PartialGasPressureAxis::settingsChanged()
{
bool showPhe = prefs.pp_graphs.phe;
bool showPn2 = prefs.pp_graphs.pn2;
diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h
index e5b9b7b0e..34089e614 100644
--- a/qt-ui/profile/divecartesianaxis.h
+++ b/qt-ui/profile/divecartesianaxis.h
@@ -110,7 +110,7 @@ public:
void setModel(DivePlotDataModel *model);
public
slots:
- void preferencesChanged();
+ void settingsChanged();
private:
DivePlotDataModel *model;
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp
index 990564fbb..2fe636a4b 100644
--- a/qt-ui/profile/diveplotdatamodel.cpp
+++ b/qt-ui/profile/diveplotdatamodel.cpp
@@ -178,7 +178,7 @@ void DivePlotDataModel::emitDataChanged()
void DivePlotDataModel::calculateDecompression()
{
- struct dive *d = get_dive_by_diveid(id());
+ struct dive *d = get_dive_by_uniq_id(id());
struct divecomputer *dc = select_dc(d);
init_decompression(d);
calculate_deco_information(d, dc, &pInfo, false);
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index 1615be87f..2a6d5ac2f 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -18,10 +18,10 @@
AbstractProfilePolygonItem::AbstractProfilePolygonItem() : QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
{
- connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(preferencesChanged()));
+ connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
}
-void AbstractProfilePolygonItem::preferencesChanged()
+void AbstractProfilePolygonItem::settingsChanged()
{
}
@@ -156,10 +156,8 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI
if (!entry->in_deco) {
/* not in deco implies this is a safety stop, no ceiling */
p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
- } else if (entry->stopdepth < entry->depth) {
- p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->stopdepth)));
} else {
- p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)));
+ p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth))));
}
}
setPolygon(p);
@@ -194,7 +192,7 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI
}
}
-void DiveProfileItem::preferencesChanged()
+void DiveProfileItem::settingsChanged()
{
//TODO: Only modelDataChanged() here if we need to rebuild the graph ( for instance,
// if the prefs.dcceiling are enabled, but prefs.redceiling is disabled
@@ -298,7 +296,7 @@ void DiveHeartrateItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
painter->drawPolyline(polygon());
}
-void DiveHeartrateItem::preferencesChanged()
+void DiveHeartrateItem::settingsChanged()
{
QSettings s;
s.beginGroup("TecDetails");
@@ -427,7 +425,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
int last_pressure[MAX_CYLINDERS] = { 0, };
int last_time[MAX_CYLINDERS] = { 0, };
struct plot_data *entry;
- struct dive *dive = get_dive_by_diveid(dataModel->id());
+ struct dive *dive = get_dive_by_uniq_id(dataModel->id());
cyl = -1;
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
@@ -489,9 +487,9 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
QPen pen;
pen.setCosmetic(true);
pen.setWidth(2);
- struct dive *d = get_dive_by_diveid(dataModel->id());
+ struct dive *d = get_dive_by_uniq_id(dataModel->id());
struct plot_data *entry = dataModel->data().entry;
- Q_FOREACH(const QPolygonF & poly, polygons) {
+ Q_FOREACH (const QPolygonF &poly, polygons) {
for (int i = 1, count = poly.count(); i < count; i++, entry++) {
pen.setBrush(getSacColor(entry->sac, d->sac));
painter->setPen(pen);
@@ -505,7 +503,7 @@ DiveCalculatedCeiling::DiveCalculatedCeiling() : is3mIncrement(false), gradientF
gradientFactor->setY(0);
gradientFactor->setBrush(getColor(PRESSURE_TEXT));
gradientFactor->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
- preferencesChanged();
+ settingsChanged();
}
void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
@@ -544,10 +542,10 @@ void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsI
DiveCalculatedTissue::DiveCalculatedTissue()
{
- preferencesChanged();
+ settingsChanged();
}
-void DiveCalculatedTissue::preferencesChanged()
+void DiveCalculatedTissue::settingsChanged()
{
setVisible(prefs.calcalltissues && prefs.calcceiling);
}
@@ -562,11 +560,7 @@ void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QMo
plot_data *entry = dataModel->data().entry;
for (int i = 0, count = dataModel->rowCount(); i < count; i++, entry++) {
if (entry->in_deco && entry->stopdepth) {
- if (entry->stopdepth < entry->depth) {
- p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->stopdepth)));
- } else {
- p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)));
- }
+ p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth))));
} else {
p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
}
@@ -585,7 +579,7 @@ void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QMo
setBrush(pat);
}
-void DiveCalculatedCeiling::preferencesChanged()
+void DiveCalculatedCeiling::settingsChanged()
{
if (dataModel && is3mIncrement != prefs.calcceiling3m) {
// recalculate that part.
@@ -595,7 +589,7 @@ void DiveCalculatedCeiling::preferencesChanged()
setVisible(prefs.calcceiling);
}
-void DiveReportedCeiling::preferencesChanged()
+void DiveReportedCeiling::settingsChanged()
{
setVisible(prefs.dcceiling);
}
@@ -688,9 +682,8 @@ void PartialPressureGasItem::paint(QPainter *painter, const QStyleOptionGraphics
QPolygonF poly;
painter->setPen(QPen(alertColor, pWidth));
- Q_FOREACH(const QPolygonF & poly, alertPolygons)
+ Q_FOREACH (const QPolygonF &poly, alertPolygons)
painter->drawPolyline(poly);
-
}
void PartialPressureGasItem::setThreshouldSettingsKey(const QString &threshouldSettingsKey)
@@ -702,7 +695,7 @@ PartialPressureGasItem::PartialPressureGasItem()
{
}
-void PartialPressureGasItem::preferencesChanged()
+void PartialPressureGasItem::settingsChanged()
{
QSettings s;
s.beginGroup("TecDetails");
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index c7fa59841..de0c6f0c9 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -46,7 +46,7 @@ public:
}
public
slots:
- virtual void preferencesChanged();
+ virtual void settingsChanged();
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
virtual void modelDataRemoved(const QModelIndex &parent, int from, int to);
@@ -75,7 +75,7 @@ public:
DiveProfileItem();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
- virtual void preferencesChanged();
+ virtual void settingsChanged();
void plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color);
private:
@@ -100,7 +100,7 @@ public:
DiveHeartrateItem();
virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
- virtual void preferencesChanged();
+ virtual void settingsChanged();
void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey);
bool isVisible();
@@ -130,7 +130,7 @@ public:
DiveCalculatedCeiling();
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- virtual void preferencesChanged();
+ virtual void settingsChanged();
private:
bool is3mIncrement;
@@ -143,14 +143,14 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem {
public:
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- virtual void preferencesChanged();
+ virtual void settingsChanged();
};
class DiveCalculatedTissue : public DiveCalculatedCeiling {
Q_OBJECT
public:
DiveCalculatedTissue();
- virtual void preferencesChanged();
+ virtual void settingsChanged();
};
class MeanDepthLine : public DiveLineItem {
@@ -176,7 +176,7 @@ public:
PartialPressureGasItem();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
- virtual void preferencesChanged();
+ virtual void settingsChanged();
void setThreshouldSettingsKey(const QString &threshouldSettingsKey);
void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey);
void setColors(const QColor &normalColor, const QColor &alertColor);
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index 0e68685b9..032daf6ee 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -1,5 +1,6 @@
#include "divetooltipitem.h"
#include "divecartesianaxis.h"
+#include "profilewidget2.h"
#include "profile.h"
#include "dive.h"
#include "membuffer.h"
@@ -21,7 +22,7 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon)
{
QGraphicsPixmapItem *iconItem = 0;
double yValue = title->boundingRect().height() + SPACING;
- Q_FOREACH(ToolTip t, toolTips) {
+ Q_FOREACH (ToolTip t, toolTips) {
yValue += t.second->boundingRect().height();
}
if (!icon.isNull()) {
@@ -39,7 +40,7 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon)
void ToolTipItem::clear()
{
- Q_FOREACH(ToolTip t, toolTips) {
+ Q_FOREACH (ToolTip t, toolTips) {
delete t.first;
delete t.second;
}
@@ -96,7 +97,7 @@ void ToolTipItem::expand()
return;
double width = 0, height = title->boundingRect().height() + SPACING;
- Q_FOREACH(ToolTip t, toolTips) {
+ Q_FOREACH (ToolTip t, toolTips) {
if (t.second->boundingRect().width() > width)
width = t.second->boundingRect().width();
height += t.second->boundingRect().height();
@@ -180,6 +181,9 @@ void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
persistPos();
QGraphicsPathItem::mouseReleaseEvent(event);
+ Q_FOREACH (QGraphicsItem *item, oldSelection) {
+ item->setSelected(true);
+ }
}
void ToolTipItem::persistPos()
@@ -226,8 +230,15 @@ void ToolTipItem::refresh(const QPointF &pos)
free_buffer(&mb);
QList<QGraphicsItem *> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, scene()->views().first()->transform());
- Q_FOREACH(QGraphicsItem * item, items) {
+ Q_FOREACH (QGraphicsItem *item, items) {
if (!item->toolTip().isEmpty())
addToolTip(item->toolTip());
}
}
+
+void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ oldSelection = scene()->selectedItems();
+ scene()->clearSelection();
+ QGraphicsItem::mousePressEvent(event);
+}
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
index 1f84d0664..c22287b06 100644
--- a/qt-ui/profile/divetooltipitem.h
+++ b/qt-ui/profile/divetooltipitem.h
@@ -45,6 +45,7 @@ public:
bool isExpanded() const;
void persistPos();
void readPos();
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void setTimeAxis(DiveCartesianAxis *axis);
void setPlotInfo(const plot_info &plot);
@@ -64,6 +65,8 @@ private:
DiveCartesianAxis *timeAxis;
plot_info pInfo;
int lastTime;
+
+ QList<QGraphicsItem*> oldSelection;
};
#endif // DIVETOOLTIPITEM_H
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index d2d01a384..2de64e71f 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -21,7 +21,6 @@
#include <QMenu>
#include <QContextMenuEvent>
#include <QDebug>
-#include <QSettings>
#include <QScrollBar>
#include <QtCore/qmath.h>
#include <QMessageBox>
@@ -100,6 +99,23 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
setEmptyState();
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
+ QAction *action = NULL;
+#define ADD_ACTION(SHORTCUT, Slot) \
+ action = new QAction(this); \
+ action->setShortcut(SHORTCUT); \
+ action->setShortcutContext(Qt::WindowShortcut); \
+ addAction(action); \
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(Slot)); \
+ actionsForKeys[SHORTCUT] = action;
+
+ ADD_ACTION(Qt::Key_Escape, keyEscAction());
+ ADD_ACTION(Qt::Key_Delete, keyDeleteAction());
+ ADD_ACTION(Qt::Key_Up, keyUpAction());
+ ADD_ACTION(Qt::Key_Down, keyDownAction());
+ ADD_ACTION(Qt::Key_Left, keyLeftAction());
+ ADD_ACTION(Qt::Key_Right, keyRightAction());
+#undef ADD_ACTION
+
#ifndef QT_NO_DEBUG
QTableView *diveDepthTableView = new QTableView();
diveDepthTableView->setModel(dataModel);
@@ -107,6 +123,9 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
#endif
}
+#define SUBSURFACE_OBJ_DATA 1
+#define SUBSURFACE_OBJ_DC_TEXT 0x42
+
void ProfileWidget2::addItemsToScene()
{
scene()->addItem(background);
@@ -120,6 +139,11 @@ void ProfileWidget2::addItemsToScene()
scene()->addItem(temperatureItem);
scene()->addItem(gasPressureItem);
scene()->addItem(meanDepth);
+ // I cannot seem to figure out if an object that I find with itemAt() on the scene
+ // is the object I am looking for - my guess is there's a simple way in Qt to do that
+ // but nothing I tried worked.
+ // so instead this adds a special magic key/value pair to the object to mark it
+ diveComputerText->setData(SUBSURFACE_OBJ_DATA, SUBSURFACE_OBJ_DC_TEXT);
scene()->addItem(diveComputerText);
scene()->addItem(diveCeiling);
scene()->addItem(reportedCeiling);
@@ -131,7 +155,7 @@ void ProfileWidget2::addItemsToScene()
scene()->addItem(rulerItem);
scene()->addItem(rulerItem->sourceNode());
scene()->addItem(rulerItem->destNode());
- Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) {
+ Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) {
scene()->addItem(tissue);
}
}
@@ -196,7 +220,7 @@ void ProfileWidget2::setupItemOnScene()
setupItem(temperatureItem, timeAxis, temperatureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1);
setupItem(heartBeatItem, timeAxis, heartBeatAxis, dataModel, DivePlotDataModel::HEARTBEAT, DivePlotDataModel::TIME, 1);
heartBeatItem->setVisibilitySettingsKey("hrgraph");
- heartBeatItem->preferencesChanged();
+ heartBeatItem->settingsChanged();
setupItem(diveProfileItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::DEPTH, DivePlotDataModel::TIME, 0);
#define CREATE_PP_GAS(ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS) \
@@ -204,7 +228,7 @@ void ProfileWidget2::setupItemOnScene()
ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \
ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \
ITEM->setColors(getColor(COLOR, isGrayscale), getColor(COLOR_ALERT, isGrayscale)); \
- ITEM->preferencesChanged(); \
+ ITEM->settingsChanged(); \
ITEM->setZValue(99);
CREATE_PP_GAS(pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph");
@@ -227,7 +251,7 @@ void ProfileWidget2::replot()
{
int diveId = dataModel->id();
dataModel->clear();
- plotDives(QList<dive *>() << get_dive_by_diveid(diveId));
+ plotDives(QList<dive *>() << get_dive_by_uniq_id(diveId));
}
void ProfileWidget2::setupItemSizes()
@@ -336,6 +360,19 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
if (!d)
return;
+ //TODO: This is a temporary hack to help me understand the Planner.
+ // It seems that each time the 'createTemporaryPlan' runs, a new
+ // dive is created, and thus, we can plot that. hm...
+ if (currentState == ADD) {
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ plannerModel->createTemporaryPlan();
+ if (!plannerModel->getDiveplan().dp) {
+ plannerModel->deleteTemporaryPlan();
+ return;
+ }
+ }
+ //END
+
int animSpeedBackup = -1;
if (firstCall && MainWindow::instance()->filesFromCommandLine()) {
animSpeedBackup = prefs.animation;
@@ -352,12 +389,7 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
// reset some item visibility on printMode changes
toolTipItem->setVisible(!printMode);
- QSettings s;
- s.beginGroup("TecDetails");
- const bool rulerVisible = s.value("rulergraph", false).toBool() && !printMode;
- rulerItem->setVisible(rulerVisible);
- rulerItem->sourceNode()->setVisible(rulerVisible);
- rulerItem->destNode()->setVisible(rulerVisible);
+ rulerItem->setVisible(prefs.rulergraph && !printMode);
// No need to do this again if we are already showing the same dive
// computer of the same dive, so we check the unique id of the dive
@@ -368,7 +400,8 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
if (d->id == dataModel->id() && dc_number == dataModel->dcShown())
return;
- setProfileState();
+ if (currentState == EMPTY)
+ setProfileState();
// next get the dive computer structure - if there are no samples
// let's create a fake profile that's somewhat reasonable for the
@@ -463,14 +496,24 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
event = event->next;
}
// Only set visible the events that should be visible
- Q_FOREACH(DiveEventItem * event, eventItems) {
+ Q_FOREACH (DiveEventItem *event, eventItems) {
event->setVisible(!event->shouldBeHidden());
// qDebug() << event->getEvent()->name << "@" << event->getEvent()->time.seconds << "is hidden:" << event->isHidden();
}
- diveComputerText->setText(currentdc->model);
+ QString dcText = currentdc->model;
+ int nr;
+ if ((nr = number_of_computers(current_dive)) > 1)
+ dcText += tr(" (#%1 of %2)").arg(dc_number + 1).arg(nr);
+ diveComputerText->setText(dcText);
if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1) {
prefs.animation = animSpeedBackup;
}
+
+ if (currentState == ADD) { // TODO: figure a way to move this from here.
+ repositionDiveHandlers();
+ DivePlannerPointsModel *model = DivePlannerPointsModel::instance();
+ model->deleteTemporaryPlan();
+ }
}
void ProfileWidget2::settingsChanged()
@@ -492,16 +535,6 @@ void ProfileWidget2::settingsChanged()
needReplot = true;
}
- if (currentState == PROFILE) {
- rulerItem->setVisible(prefs.rulergraph);
- rulerItem->destNode()->setVisible(prefs.rulergraph);
- rulerItem->sourceNode()->setVisible(prefs.rulergraph);
- needReplot = true;
- } else {
- rulerItem->setVisible(false);
- rulerItem->destNode()->setVisible(false);
- rulerItem->sourceNode()->setVisible(false);
- }
if (needReplot)
replot();
}
@@ -543,6 +576,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
@@ -585,6 +642,8 @@ void ProfileWidget2::setEmptyState()
if (currentState == EMPTY)
return;
+ disconnectTemporaryConnections();
+ setBackgroundBrush(getColor(::BACKGROUND, isGrayscale));
dataModel->clear();
currentState = EMPTY;
MainWindow::instance()->setToolButtonsEnabled(false);
@@ -604,15 +663,13 @@ void ProfileWidget2::setEmptyState()
diveCeiling->setVisible(false);
reportedCeiling->setVisible(false);
rulerItem->setVisible(false);
- rulerItem->destNode()->setVisible(false);
- rulerItem->sourceNode()->setVisible(false);
pn2GasItem->setVisible(false);
po2GasItem->setVisible(false);
pheGasItem->setVisible(false);
- Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) {
+ Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) {
tissue->setVisible(false);
}
- Q_FOREACH(DiveEventItem * event, eventItems) {
+ Q_FOREACH (DiveEventItem *event, eventItems) {
event->setVisible(false);
}
}
@@ -623,6 +680,10 @@ void ProfileWidget2::setProfileState()
if (currentState == PROFILE)
return;
+ disconnectTemporaryConnections();
+ //TODO: Move the DC handling to another method.
+ MainWindow::instance()->enableDcShortcuts();
+
currentState = PROFILE;
MainWindow::instance()->setToolButtonsEnabled(true);
toolTipItem->readPos();
@@ -670,16 +731,50 @@ void ProfileWidget2::setProfileState()
reportedCeiling->setVisible(prefs.dcceiling);
if (prefs.calcalltissues) {
- Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) {
+ Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) {
tissue->setVisible(true);
}
}
- QSettings s;
- s.beginGroup("TecDetails");
- bool rulerVisible = s.value("rulergraph", false).toBool();
- rulerItem->setVisible(rulerVisible);
- rulerItem->destNode()->setVisible(rulerVisible);
- rulerItem->sourceNode()->setVisible(rulerVisible);
+ rulerItem->setVisible(prefs.rulergraph);
+}
+
+void ProfileWidget2::setAddState()
+{
+ if (currentState == ADD)
+ return;
+
+ setProfileState();
+ disconnectTemporaryConnections();
+ //TODO: Move this method to another place, shouldn't be on mainwindow.
+ MainWindow::instance()->disableDcShortcuts();
+ actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left);
+ actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right);
+ actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up);
+ actionsForKeys[Qt::Key_Down]->setShortcut(Qt::Key_Down);
+ actionsForKeys[Qt::Key_Escape]->setShortcut(Qt::Key_Escape);
+ actionsForKeys[Qt::Key_Delete]->setShortcut(Qt::Key_Delete);
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot()));
+ connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot()));
+ connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ this, SLOT(pointInserted(const QModelIndex &, int, int)));
+ connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+ this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
+ /* 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;
+ setProfileState();
+ disconnectTemporaryConnections();
+ /* 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;
@@ -688,9 +783,36 @@ extern int evn_used;
void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
{
- if (selected_dive == -1)
+ if (currentState == ADD || currentState == PLAN) {
+ QGraphicsView::contextMenuEvent(event);
return;
+ }
QMenu m;
+ bool isDCName = false;
+ if (selected_dive == -1)
+ return;
+ // figure out if we are ontop of the dive computer name in the profile
+ QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
+ if (sceneItem) {
+ QGraphicsItem *parentItem = sceneItem;
+ while (parentItem) {
+ if (parentItem->data(SUBSURFACE_OBJ_DATA) == SUBSURFACE_OBJ_DC_TEXT) {
+ isDCName = true;
+ break;
+ }
+ parentItem = parentItem->parentItem();
+ }
+ if (isDCName) {
+ if (dc_number == 0)
+ return;
+ // create menu to show when right clicking on dive computer name
+ m.addAction(tr("Make first divecomputer"), this, SLOT(makeFirstDC()));
+ m.exec(event->globalPos());
+ // don't show the regular profile context menu
+ return;
+ }
+ }
+ // create the profile context menu
QMenu *gasChange = m.addMenu(tr("Add Gas Change"));
GasSelectionModel *model = GasSelectionModel::instance();
model->repopulate();
@@ -704,7 +826,6 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
}
QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark()));
action->setData(event->globalPos());
- QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
action = new QAction(&m);
action->setText(tr("Remove Event"));
@@ -738,6 +859,18 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
m.exec(event->globalPos());
}
+void ProfileWidget2::makeFirstDC()
+{
+ make_first_dc();
+ mark_divelist_changed(true);
+ // this is now the first DC, so we need to redraw the profile and refresh the dive list
+ // (and no, it's not just enough to rewrite the text - the first DC is special so values in the
+ // dive list may change).
+ // As a side benefit, this returns focus to the dive list.
+ dc_number = 0;
+ MainWindow::instance()->refreshDisplay();
+}
+
void ProfileWidget2::hideEvents()
{
QAction *action = qobject_cast<QAction *>(sender());
@@ -749,14 +882,18 @@ void ProfileWidget2::hideEvents()
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
if (event->name) {
for (int i = 0; i < evn_used; i++) {
- if (!strcmp(event->name, ev_namelist[i].ev_name)) {
+ if (same_string(event->name, ev_namelist[i].ev_name)) {
ev_namelist[i].plot_ev = false;
break;
}
}
+ Q_FOREACH (DiveEventItem *evItem, eventItems) {
+ if (same_string(evItem->getEvent()->name, event->name))
+ evItem->hide();
+ }
+ } else {
+ item->hide();
}
- item->hide();
- replot();
}
}
@@ -765,7 +902,8 @@ void ProfileWidget2::unhideEvents()
for (int i = 0; i < evn_used; i++) {
ev_namelist[i].plot_ev = true;
}
- replot();
+ Q_FOREACH (DiveEventItem *item, eventItems)
+ item->show();
}
void ProfileWidget2::removeEvent()
@@ -775,16 +913,10 @@ void ProfileWidget2::removeEvent()
struct event *event = item->getEvent();
if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT(
- tr("Remove the selected event?"),
- tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))),
+ tr("Remove the selected event?"),
+ tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
- struct event **ep = &current_dc->events;
- while (ep && *ep != event)
- ep = &(*ep)->next;
- if (ep) {
- *ep = event->next;
- free(event);
- }
+ remove_event(event);
mark_divelist_changed(true);
replot();
}
@@ -808,7 +940,7 @@ void ProfileWidget2::changeGas()
int diveId = dataModel->id();
int o2, he;
int seconds = timeAxis->valueAt(scenePos);
- struct dive *d = get_dive_by_diveid(diveId);
+ struct dive *d = get_dive_by_uniq_id(diveId);
validate_gas(gas.toUtf8().constData(), &o2, &he);
add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, o2, he));
@@ -846,3 +978,248 @@ void ProfileWidget2::editName()
}
replot();
}
+
+void ProfileWidget2::disconnectTemporaryConnections()
+{
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ disconnect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot()));
+ disconnect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot()));
+
+ disconnect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ this, SLOT(pointInserted(const QModelIndex &, int, int)));
+ disconnect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+ this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
+
+
+ Q_FOREACH (QAction *action, actionsForKeys.values()) {
+ action->setShortcut(QKeySequence());
+ }
+}
+
+void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end)
+{
+ DiveHandler *item = new DiveHandler();
+ scene()->addItem(item);
+ handles << item;
+
+ connect(item, SIGNAL(moved()), this, SLOT(recreatePlannedDive()));
+ QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
+ scene()->addItem(gasChooseBtn);
+ gasChooseBtn->setZValue(10);
+ gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations);
+ gases << gasChooseBtn;
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ if (plannerModel->recalcQ())
+ replot();
+}
+
+void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end)
+{ // start and end are inclusive.
+ int num = (end - start) + 1;
+ for (int i = num; i != 0; i--) {
+ delete handles.back();
+ handles.pop_back();
+ delete gases.back();
+ gases.pop_back();
+ }
+ scene()->clearSelection();
+ replot();
+}
+
+void ProfileWidget2::repositionDiveHandlers()
+{
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ // Re-position the user generated dive handlers
+ int last = 0;
+ for (int i = 0; i < plannerModel->rowCount(); i++) {
+ struct divedatapoint datapoint = plannerModel->at(i);
+ if (datapoint.time == 0) // those are the magic entries for tanks
+ continue;
+ DiveHandler *h = handles.at(i);
+ h->setPos(timeAxis->posAtValue(datapoint.time), profileYAxis->posAtValue(datapoint.depth));
+ QPointF p1 = (last == i) ? QPointF(timeAxis->posAtValue(0), profileYAxis->posAtValue(0)) : handles[last]->pos();
+ QPointF p2 = handles[i]->pos();
+ QLineF line(p1, p2);
+ QPointF pos = line.pointAt(0.5);
+ gases[i]->setPos(pos);
+ gases[i]->setText(dpGasToStr(plannerModel->at(i)));
+ last = i;
+ }
+}
+
+int ProfileWidget2::fixHandlerIndex(DiveHandler *activeHandler)
+{
+ int index = handles.indexOf(activeHandler);
+ if (index > 0 && index < handles.count() - 1) {
+ DiveHandler *before = handles[index - 1];
+ if (before->pos().x() > activeHandler->pos().x()) {
+ handles.swap(index, index - 1);
+ return index - 1;
+ }
+ DiveHandler *after = handles[index + 1];
+ if (after->pos().x() < activeHandler->pos().x()) {
+ handles.swap(index, index + 1);
+ return index + 1;
+ }
+ }
+ return index;
+}
+
+void ProfileWidget2::recreatePlannedDive()
+{
+ DiveHandler *activeHandler = qobject_cast<DiveHandler *>(sender());
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ int index = fixHandlerIndex(activeHandler);
+ int mintime = 0, maxtime = (timeAxis->maximum() + 10) * 60;
+ if (index > 0)
+ mintime = plannerModel->at(index - 1).time;
+ if (index < plannerModel->size() - 1)
+ maxtime = plannerModel->at(index + 1).time;
+
+ int minutes = rint(timeAxis->valueAt(activeHandler->pos()) / 60);
+ if (minutes * 60 <= mintime || minutes * 60 >= maxtime)
+ return;
+
+ divedatapoint data = plannerModel->at(index);
+ data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
+ data.time = rint(timeAxis->valueAt(activeHandler->pos()));
+
+ plannerModel->editStop(index, data);
+}
+
+void ProfileWidget2::keyDownAction()
+{
+ if (currentState != ADD && currentState != PLAN)
+ return;
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) {
+ if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
+ int row = handles.indexOf(handler);
+ divedatapoint dp = plannerModel->at(row);
+ if (dp.depth >= profileYAxis->maximum())
+ continue;
+
+ dp.depth += M_OR_FT(1, 5);
+ plannerModel->editStop(row, dp);
+ }
+ }
+}
+
+void ProfileWidget2::keyUpAction()
+{
+ if (currentState != ADD && currentState != PLAN)
+ return;
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) {
+ if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
+ int row = handles.indexOf(handler);
+ divedatapoint dp = plannerModel->at(row);
+
+ if (dp.depth <= 0)
+ continue;
+
+ dp.depth -= M_OR_FT(1, 5);
+ plannerModel->editStop(row, dp);
+ }
+ }
+}
+
+void ProfileWidget2::keyLeftAction()
+{
+ if (currentState != ADD && currentState != PLAN)
+ return;
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) {
+ if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
+ int row = handles.indexOf(handler);
+ divedatapoint dp = plannerModel->at(row);
+
+ if (dp.time / 60 <= 0)
+ continue;
+
+ // don't overlap positions.
+ // maybe this is a good place for a 'goto'?
+ double xpos = timeAxis->posAtValue((dp.time - 60) / 60);
+ bool nextStep = false;
+ Q_FOREACH (DiveHandler *h, handles) {
+ if (IS_FP_SAME(h->pos().x(), xpos)) {
+ nextStep = true;
+ break;
+ }
+ }
+ if (nextStep)
+ continue;
+
+ dp.time -= 60;
+ plannerModel->editStop(row, dp);
+ }
+ }
+}
+
+void ProfileWidget2::keyRightAction()
+{
+ if (currentState != ADD && currentState != PLAN)
+ return;
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) {
+ if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
+ int row = handles.indexOf(handler);
+ divedatapoint dp = plannerModel->at(row);
+ if (dp.time / 60 >= timeAxis->maximum())
+ continue;
+
+ // don't overlap positions.
+ // maybe this is a good place for a 'goto'?
+ double xpos = timeAxis->posAtValue((dp.time + 60) / 60);
+ bool nextStep = false;
+ Q_FOREACH (DiveHandler *h, handles) {
+ if (IS_FP_SAME(h->pos().x(), xpos)) {
+ nextStep = true;
+ break;
+ }
+ }
+ if (nextStep)
+ continue;
+
+ dp.time += 60;
+ plannerModel->editStop(row, dp);
+ }
+ }
+}
+
+void ProfileWidget2::keyDeleteAction()
+{
+ if (currentState != ADD && currentState != PLAN)
+ return;
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ int selCount = scene()->selectedItems().count();
+ if (selCount) {
+ QVector<int> selectedIndexes;
+ Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) {
+ if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
+ selectedIndexes.push_back(handles.indexOf(handler));
+ }
+ }
+ plannerModel->removeSelectedPoints(selectedIndexes);
+ }
+}
+
+void ProfileWidget2::keyEscAction()
+{
+ if (currentState != ADD && currentState != PLAN)
+ return;
+
+ if (scene()->selectedItems().count()) {
+ scene()->clearSelection();
+ return;
+ }
+
+ DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ if (plannerModel->isPlanner())
+ plannerModel->cancelPlan();
+}
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index d00cb26c1..3c3d86d01 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -40,6 +40,9 @@ class DiveCalculatedTissue;
class PartialPressureGasItem;
class PartialGasPressureAxis;
class AbstractProfilePolygonItem;
+class DiveHandler;
+class QGraphicsSimpleTextItem;
+class QModelIndex;
class ProfileWidget2 : public QGraphicsView {
Q_OBJECT
@@ -64,28 +67,47 @@ public:
ProfileWidget2(QWidget *parent = 0);
void plotDives(QList<dive *> dives);
- void replot();
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
slots: // Necessary to call from QAction's signals.
void settingsChanged();
void setEmptyState();
void setProfileState();
+ void setPlanState();
+ void setAddState();
void changeGas();
void addBookmark();
void hideEvents();
void unhideEvents();
void removeEvent();
void editName();
+ void makeFirstDC();
+ void pointInserted(const QModelIndex &parent, int start, int end);
+ void pointsRemoved(const QModelIndex &, int start, int end);
+ void replot();
+
+ /* this is called for every move on the handlers. maybe we can speed up this a bit? */
+ void recreatePlannedDive();
+
+ /* key press handlers */
+ void keyEscAction();
+ void keyDeleteAction();
+ void keyUpAction();
+ void keyDownAction();
+ void keyLeftAction();
+ void keyRightAction();
protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *event);
+ virtual void mouseDoubleClickEvent(QMouseEvent *event);
private: /*methods*/
void fixBackgroundPos();
@@ -94,10 +116,10 @@ private: /*methods*/
void setupItemSizes();
void addItemsToScene();
void setupItemOnScene();
+ void disconnectTemporaryConnections();
private:
DivePlotDataModel *dataModel;
- State currentState;
int zoomLevel;
qreal zoomFactor;
DivePixmapItem *background;
@@ -130,6 +152,14 @@ private:
RulerItem2 *rulerItem;
bool isGrayscale;
bool printMode;
+
+ //specifics for ADD and PLAN
+ QList<DiveHandler *> handles;
+ QList<QGraphicsSimpleTextItem *> gases;
+ void repositionDiveHandlers();
+ int fixHandlerIndex(DiveHandler *activeHandler);
+ friend class DiveHandler;
+ QHash<Qt::Key, QAction *> actionsForKeys;
};
#endif // PROFILEWIDGET2_H
diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp
index 768d912e9..0f2a24a80 100644
--- a/qt-ui/profile/ruleritem.cpp
+++ b/qt-ui/profile/ruleritem.cpp
@@ -1,5 +1,7 @@
#include "ruleritem.h"
#include "divetextitem.h"
+#include "profilewidget2.h"
+#include "../preferences.h"
#include <QFont>
#include <QFontMetrics>
@@ -24,7 +26,7 @@ RulerNodeItem2::RulerNodeItem2() : entry(NULL), ruler(NULL)
setFlag(ItemIgnoresTransformations);
}
-void RulerNodeItem2::setPlotInfo(plot_info& info)
+void RulerNodeItem2::setPlotInfo(plot_info &info)
{
pInfo = info;
entry = pInfo.entry;
@@ -79,6 +81,15 @@ RulerItem2::RulerItem2() : source(new RulerNodeItem2()),
textItemBack->setPen(QColor(Qt::white));
textItemBack->setFlag(QGraphicsItem::ItemIgnoresTransformations);
setPen(QPen(QColor(Qt::black), 0.0));
+ connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
+}
+
+void RulerItem2::settingsChanged()
+{
+ ProfileWidget2 *profWidget = NULL;
+ if (scene() && scene()->views().count())
+ profWidget = qobject_cast<ProfileWidget2 *>(scene()->views().first());
+ setVisible(profWidget->currentState == ProfileWidget2::PROFILE ? prefs.rulergraph : false);
}
void RulerItem2::recalculate()
@@ -157,3 +168,10 @@ void RulerItem2::setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth)
source->timeAxis = time;
recalculate();
}
+
+void RulerItem2::setVisible(bool visible)
+{
+ QGraphicsLineItem::setVisible(visible);
+ source->setVisible(visible);
+ dest->setVisible(visible);
+}
diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h
index 7bfc63eee..3eda33225 100644
--- a/qt-ui/profile/ruleritem.h
+++ b/qt-ui/profile/ruleritem.h
@@ -17,7 +17,7 @@ class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem {
public:
explicit RulerNodeItem2();
void setRuler(RulerItem2 *r);
- void setPlotInfo(struct plot_info& info);
+ void setPlotInfo(struct plot_info &info);
void recalculate();
protected:
@@ -31,7 +31,8 @@ private:
DiveCartesianAxis *depthAxis;
};
-class RulerItem2 : public QGraphicsLineItem {
+class RulerItem2 : public QObject, public QGraphicsLineItem {
+ Q_OBJECT
public:
explicit RulerItem2();
void recalculate();
@@ -40,6 +41,11 @@ public:
RulerNodeItem2 *sourceNode() const;
RulerNodeItem2 *destNode() const;
void setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth);
+ void setVisible(bool visible);
+
+public
+slots:
+ void settingsChanged();
private:
struct plot_info pInfo;