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-01-16 17:02:32 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
DiveEventItem::DiveEventItem(QObject* parent): DivePixmapItem(parent),
|
2014-01-16 23:30:47 +00:00
|
|
|
vAxis(NULL), hAxis(NULL), dataModel(NULL), internalEvent(NULL)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
setFlag(ItemIgnoresTransformations);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
|
|
|
|
{
|
|
|
|
hAxis = axis;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::setModel(DivePlotDataModel* model)
|
|
|
|
{
|
|
|
|
dataModel = model;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::setEvent(struct event* ev)
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
#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"));
|
|
|
|
} else if ((strcmp(internalEvent->name, "bookmark") == 0)) {
|
|
|
|
setPixmap(EVENT_PIXMAP(":flag"));
|
2014-01-16 23:30:47 +00:00
|
|
|
} else if(strcmp(internalEvent->name, "heading") == 0) {
|
2014-01-16 17:02:32 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":flag"));
|
|
|
|
} else {
|
|
|
|
setPixmap(EVENT_PIXMAP(":warning"));
|
|
|
|
}
|
|
|
|
#undef EVENT_PIXMAP
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::setupToolTipString()
|
|
|
|
{
|
|
|
|
//TODO Fix this. :)
|
|
|
|
#if 0
|
|
|
|
This needs to be redone, but right now the events are being plotted and I liked pretty much the code.
|
|
|
|
|
|
|
|
struct dive *dive = getDiveById(diveId);
|
|
|
|
Q_ASSERT(dive != NULL);
|
|
|
|
EventItem *item = new EventItem(ev, 0, isGrayscale);
|
|
|
|
item->setPos(x, y);
|
|
|
|
scene()->addItem(item);
|
|
|
|
|
|
|
|
/* we display the event on screen - so translate (with the correct context for events) */
|
|
|
|
QString name = gettextFromC::instance()->tr(ev->name);
|
|
|
|
if (ev->value) {
|
|
|
|
if (ev->name && strcmp(ev->name, "gaschange") == 0) {
|
|
|
|
int he = get_he(&dive->cylinder[entry->cylinderindex].gasmix);
|
|
|
|
int o2 = get_o2(&dive->cylinder[entry->cylinderindex].gasmix);
|
|
|
|
|
|
|
|
name += ": ";
|
|
|
|
if (he)
|
|
|
|
name += QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10);
|
|
|
|
else if (is_air(o2, he))
|
|
|
|
name += tr("air");
|
|
|
|
else
|
|
|
|
name += QString(tr("EAN%1")).arg((o2 + 5) / 10);
|
|
|
|
|
|
|
|
} else if (ev->name && !strcmp(ev->name, "SP change")) {
|
|
|
|
name += QString(":%1").arg((double) ev->value / 1000);
|
|
|
|
} else {
|
|
|
|
name += QString(":%1").arg(ev->value);
|
|
|
|
}
|
|
|
|
} else if (ev->name && name == "SP change") {
|
|
|
|
name += "\n" + tr("Bailing out to OC");
|
|
|
|
} else {
|
|
|
|
name += ev->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
|
|
|
|
ev->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//item->setToolTipController(toolTip);
|
|
|
|
//item->addToolTip(name);
|
|
|
|
item->setToolTip(name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveEventItem::eventVisibilityChanged(const QString& eventName, bool visible)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-15 23:05:47 +00:00
|
|
|
void DiveEventItem::recalculatePos(bool instant)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-01-16 23:30:47 +00:00
|
|
|
if (!vAxis || !hAxis || !internalEvent || !dataModel) {
|
2014-01-16 17:02:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
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-01-16 17:02:32 +00:00
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
2014-01-16 23:30:47 +00:00
|
|
|
if (!isVisible()) {
|
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-15 23:05:47 +00:00
|
|
|
if (!instant){
|
|
|
|
Animations::moveTo(this, x, y, 500);
|
|
|
|
}else{
|
|
|
|
setPos(x,y);
|
|
|
|
}
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|