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-03-16 04:12:34 +00:00
|
|
|
#include "profile.h"
|
2014-01-16 17:02:32 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
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-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-02-21 21:29:35 +00:00
|
|
|
} else if (internalEvent->type == 123) {
|
|
|
|
QPixmap picture;
|
|
|
|
picture.load(internalEvent->name);
|
|
|
|
setPixmap(picture.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
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
|
|
|
|
QString name = tr(internalEvent->name);
|
|
|
|
int value = internalEvent->value;
|
|
|
|
if (value) {
|
|
|
|
if (name == "gaschange") {
|
|
|
|
int he = value >> 16;
|
|
|
|
int o2 = value & 0xffff;
|
2014-01-16 17:02:32 +00:00
|
|
|
|
|
|
|
name += ": ";
|
|
|
|
if (he)
|
2014-02-25 20:27:12 +00:00
|
|
|
name += QString("%1/%2").arg(o2).arg(he);
|
2014-01-16 17:02:32 +00:00
|
|
|
else if (is_air(o2, he))
|
|
|
|
name += tr("air");
|
|
|
|
else
|
2014-02-25 20:27:12 +00:00
|
|
|
name += QString(tr("EAN%1")).arg(o2);
|
|
|
|
} else if (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-02-25 20:27:12 +00:00
|
|
|
} else if (name == "SP change") {
|
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()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < evn_used; i++) {
|
|
|
|
if (!strcmp(internalEvent->name, ev_namelist[i].ev_name) && ev_namelist[i].plot_ev == false)
|
|
|
|
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
|
|
|
}
|