aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/diveeventitem.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-16 15:02:32 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-17 06:17:09 +0700
commit1f8078828663f6bfff768cbc2fb36e6643eb3d0e (patch)
tree93437eb965759cb6b08ce2b92b6568c81d4559e7 /qt-ui/profile/diveeventitem.cpp
parent9cb5ea45d886c15b26b196bc292b7a4bbf359b20 (diff)
downloadsubsurface-1f8078828663f6bfff768cbc2fb36e6643eb3d0e.tar.gz
Added a DiveEventItem that knows how to handle itself.
Simply pass a event to the item and it will know what to do. The sad part is that this isn't true yet - there's quite a bit of boilerplate that a lot of the items are needing, but the good part is that the boolerplate is the same in all of the items, which means that I can create a tiny bit of abstraction to encapsulate it and the code will be way smaller to setup the items on the canvas. Right now the items are being correctly placed on the right places. It doesn't supports hidding / showing yet. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/diveeventitem.cpp')
-rw-r--r--qt-ui/profile/diveeventitem.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp
new file mode 100644
index 000000000..a6153f96f
--- /dev/null
+++ b/qt-ui/profile/diveeventitem.cpp
@@ -0,0 +1,123 @@
+#include "diveeventitem.h"
+#include "diveplotdatamodel.h"
+#include "divecartesianaxis.h"
+#include "dive.h"
+#include <QDebug>
+
+DiveEventItem::DiveEventItem(QObject* parent): DivePixmapItem(parent),
+ vAxis(NULL), hAxis(NULL), internalEvent(NULL), dataModel(NULL)
+{
+ setFlag(ItemIgnoresTransformations);
+}
+
+
+void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
+{
+ hAxis = axis;
+ recalculate();
+}
+
+void DiveEventItem::setModel(DivePlotDataModel* model)
+{
+ dataModel = model;
+ recalculate();
+}
+
+void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
+{
+ vAxis = axis;
+ recalculate();
+}
+
+void DiveEventItem::setEvent(struct event* ev)
+{
+ internalEvent = ev;
+ setupPixmap();
+ setupToolTipString();
+ recalculate();
+}
+
+void DiveEventItem::setupPixmap()
+{
+#define EVENT_PIXMAP( PIX ) QPixmap(QString(PIX)).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)
+ if(!internalEvent->name){
+ setPixmap(EVENT_PIXMAP(":warning"));
+ } else if ((strcmp(internalEvent->name, "bookmark") == 0)) {
+ setPixmap(EVENT_PIXMAP(":flag"));
+ } else if(strcmp(internalEvent->name, "heading") == 0){
+ 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)
+{
+
+}
+
+void DiveEventItem::recalculate()
+{
+ if (!vAxis || !hAxis || !internalEvent || !dataModel){
+ return;
+ }
+ qDebug() << "Calculating.";
+ QModelIndexList result = dataModel->match(dataModel->index(0,DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds );
+ if(result.isEmpty()){
+ hide();
+ return;
+ }
+ if(!isVisible()){
+ 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);
+ setPos(x, y);
+}