2014-01-16 17:02:32 +00:00
|
|
|
#include "diveeventitem.h"
|
|
|
|
#include "diveplotdatamodel.h"
|
|
|
|
#include "divecartesianaxis.h"
|
2014-02-15 23:05:47 +00:00
|
|
|
#include "animationfunctions.h"
|
2014-02-25 20:27:12 +00:00
|
|
|
#include "libdivecomputer.h"
|
2014-01-16 17:02:32 +00:00
|
|
|
#include "dive.h"
|
2014-07-01 19:07:38 +00:00
|
|
|
#include "planner.h"
|
2014-03-16 04:12:34 +00:00
|
|
|
#include "profile.h"
|
2014-01-16 17:02:32 +00:00
|
|
|
#include <QDebug>
|
2014-04-30 05:37:19 +00:00
|
|
|
#include "gettextfromc.h"
|
2014-01-16 17:02:32 +00:00
|
|
|
|
2014-03-16 04:12:34 +00:00
|
|
|
extern struct ev_select *ev_namelist;
|
|
|
|
extern int evn_used;
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent),
|
|
|
|
vAxis(NULL),
|
|
|
|
hAxis(NULL),
|
|
|
|
dataModel(NULL),
|
|
|
|
internalEvent(NULL)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
setFlag(ItemIgnoresTransformations);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis *axis)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
hAxis = axis;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setModel(DivePlotDataModel *model)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
dataModel = model;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setVerticalAxis(DiveCartesianAxis *axis)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
vAxis = axis;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
|
|
|
connect(vAxis, SIGNAL(sizeChanged()), this, SLOT(recalculatePos()));
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 20:27:12 +00:00
|
|
|
struct event *DiveEventItem::getEvent()
|
|
|
|
{
|
|
|
|
return internalEvent;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setEvent(struct event *ev)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-02-23 16:35:06 +00:00
|
|
|
if (!ev)
|
|
|
|
return;
|
2014-01-16 17:02:32 +00:00
|
|
|
internalEvent = ev;
|
|
|
|
setupPixmap();
|
|
|
|
setupToolTipString();
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::setupPixmap()
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
#define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)
|
2014-07-10 17:54:05 +00:00
|
|
|
#define EVENT_PIXMAP_BIGGER(PIX) QPixmap(QString(PIX)).scaled(40, 38, Qt::KeepAspectRatio, Qt::SmoothTransformation)
|
2014-01-16 23:30:47 +00:00
|
|
|
if (!internalEvent->name) {
|
2014-01-16 17:02:32 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":warning"));
|
2014-04-03 19:16:15 +00:00
|
|
|
} else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) {
|
2014-01-16 17:02:32 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":flag"));
|
2014-02-21 21:29:35 +00:00
|
|
|
} else if (strcmp(internalEvent->name, "heading") == 0) {
|
2014-01-16 17:02:32 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":flag"));
|
2014-08-17 18:26:21 +00:00
|
|
|
} else if (event_is_gaschange(internalEvent)) {
|
|
|
|
if (internalEvent->gas.mix.he.permille)
|
2014-07-10 17:54:05 +00:00
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeTrimix"));
|
2014-08-17 18:26:21 +00:00
|
|
|
else if (gasmix_is_air(&internalEvent->gas.mix))
|
2014-07-10 17:54:05 +00:00
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeAir"));
|
|
|
|
else
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeNitrox"));
|
2014-01-16 17:02:32 +00:00
|
|
|
} else {
|
|
|
|
setPixmap(EVENT_PIXMAP(":warning"));
|
|
|
|
}
|
|
|
|
#undef EVENT_PIXMAP
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::setupToolTipString()
|
|
|
|
{
|
2014-02-25 20:27:12 +00:00
|
|
|
// we display the event on screen - so translate
|
2014-04-30 05:37:19 +00:00
|
|
|
QString name = gettextFromC::instance()->tr(internalEvent->name);
|
2014-02-25 20:27:12 +00:00
|
|
|
int value = internalEvent->value;
|
2014-04-30 05:37:19 +00:00
|
|
|
int type = internalEvent->type;
|
2014-02-25 20:27:12 +00:00
|
|
|
if (value) {
|
2014-08-17 18:26:21 +00:00
|
|
|
if (event_is_gaschange(internalEvent)) {
|
2014-07-16 22:26:46 +00:00
|
|
|
QModelIndexList result = dataModel->match(dataModel->index(0, DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds);
|
|
|
|
if (result.isEmpty()) {
|
|
|
|
Q_ASSERT("can't find a spot in the dataModel");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We need to look at row + 1, where the new gas is active to find what we are switching to.
|
|
|
|
int cylinder_idx = dataModel->data(dataModel->index(result.first().row() + 1, DivePlotDataModel::CYLINDERINDEX)).toInt();
|
2014-01-16 17:02:32 +00:00
|
|
|
name += ": ";
|
2014-07-17 17:58:55 +00:00
|
|
|
name += gasname(&displayed_dive.cylinder[cylinder_idx].gasmix);
|
2014-05-05 16:28:58 +00:00
|
|
|
} else if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
|
2014-02-28 04:09:57 +00:00
|
|
|
name += QString(":%1").arg((double)value / 1000);
|
2014-01-16 17:02:32 +00:00
|
|
|
} else {
|
2014-02-25 20:27:12 +00:00
|
|
|
name += QString(":%1").arg(value);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
2014-05-05 16:28:58 +00:00
|
|
|
} else if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
|
|
|
|
// this is a bad idea - we are abusing an existing event type that is supposed to
|
2014-06-22 14:41:44 +00:00
|
|
|
// warn of high or low pO₂ and are turning it into a set point change event
|
2014-01-16 17:02:32 +00:00
|
|
|
name += "\n" + tr("Bailing out to OC");
|
|
|
|
} else {
|
2014-02-25 20:27:12 +00:00
|
|
|
name += internalEvent->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
|
|
|
|
internalEvent->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
2014-02-25 20:27:12 +00:00
|
|
|
// qDebug() << name;
|
|
|
|
setToolTip(name);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::eventVisibilityChanged(const QString &eventName, bool visible)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-16 22:10:03 +00:00
|
|
|
bool DiveEventItem::shouldBeHidden()
|
|
|
|
{
|
2014-07-01 19:07:38 +00:00
|
|
|
struct event *event = internalEvent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gas change events - particularly at the beginning of a dive - are
|
|
|
|
* special. It's just the dive computer specifying the initial gas.
|
|
|
|
*
|
|
|
|
* Don't bother showing them if they match the first gas already
|
|
|
|
*/
|
2014-07-17 06:55:03 +00:00
|
|
|
if (!strcmp(event->name, "gaschange") && event->time.seconds <= 30) {
|
2014-07-17 17:58:55 +00:00
|
|
|
struct dive *dive = &displayed_dive;
|
2014-07-17 06:55:02 +00:00
|
|
|
if (dive && get_cylinder_index(dive, event) == 0)
|
2014-07-01 19:07:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-16 22:10:03 +00:00
|
|
|
for (int i = 0; i < evn_used; i++) {
|
2014-07-01 19:07:38 +00:00
|
|
|
if (!strcmp(event->name, ev_namelist[i].ev_name) && ev_namelist[i].plot_ev == false)
|
2014-03-16 22:10:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-15 23:05:47 +00:00
|
|
|
void DiveEventItem::recalculatePos(bool instant)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-02-23 16:35:06 +00:00
|
|
|
if (!vAxis || !hAxis || !internalEvent || !dataModel)
|
2014-01-16 17:02:32 +00:00
|
|
|
return;
|
2014-02-23 16:35:06 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QModelIndexList result = dataModel->match(dataModel->index(0, DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds);
|
2014-01-16 23:30:47 +00:00
|
|
|
if (result.isEmpty()) {
|
2014-02-23 16:35:06 +00:00
|
|
|
Q_ASSERT("can't find a spot in the dataModel");
|
2014-01-16 17:02:32 +00:00
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-16 22:10:03 +00:00
|
|
|
if (!isVisible() && !shouldBeHidden())
|
2014-01-16 17:02:32 +00:00
|
|
|
show();
|
|
|
|
int depth = dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
|
|
|
|
qreal x = hAxis->posAtValue(internalEvent->time.seconds);
|
|
|
|
qreal y = vAxis->posAtValue(depth);
|
2014-02-23 16:35:06 +00:00
|
|
|
if (!instant)
|
2014-03-11 20:27:05 +00:00
|
|
|
Animations::moveTo(this, x, y);
|
2014-02-23 16:35:06 +00:00
|
|
|
else
|
2014-02-28 04:09:57 +00:00
|
|
|
setPos(x, y);
|
2014-03-16 22:10:03 +00:00
|
|
|
if (isVisible() && shouldBeHidden())
|
2014-03-16 04:12:34 +00:00
|
|
|
hide();
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|