diff options
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/diveeventitem.cpp | 18 | ||||
-rw-r--r-- | qt-ui/profile/diveeventitem.h | 1 | ||||
-rw-r--r-- | qt-ui/profile/diveplotdatamodel.cpp | 6 | ||||
-rw-r--r-- | qt-ui/profile/diveplotdatamodel.h | 4 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 29 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.h | 2 | ||||
-rw-r--r-- | qt-ui/profile/divetooltipitem.cpp | 6 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 122 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 7 | ||||
-rw-r--r-- | qt-ui/profile/ruleritem.cpp | 12 |
10 files changed, 165 insertions, 42 deletions
diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp index 1fd4ef07a..3f75ab10a 100644 --- a/qt-ui/profile/diveeventitem.cpp +++ b/qt-ui/profile/diveeventitem.cpp @@ -4,8 +4,12 @@ #include "animationfunctions.h" #include "libdivecomputer.h" #include "dive.h" +#include "profile.h" #include <QDebug> +extern struct ev_select *ev_namelist; +extern int evn_used; + DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent), vAxis(NULL), hAxis(NULL), @@ -105,6 +109,15 @@ void DiveEventItem::eventVisibilityChanged(const QString &eventName, bool visibl { } +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; +} + void DiveEventItem::recalculatePos(bool instant) { if (!vAxis || !hAxis || !internalEvent || !dataModel) @@ -116,9 +129,8 @@ void DiveEventItem::recalculatePos(bool instant) hide(); return; } - if (!isVisible()) + if (!isVisible() && !shouldBeHidden()) 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); @@ -126,4 +138,6 @@ void DiveEventItem::recalculatePos(bool instant) Animations::moveTo(this, x, y); else setPos(x, y); + if (isVisible() && shouldBeHidden()) + hide(); } diff --git a/qt-ui/profile/diveeventitem.h b/qt-ui/profile/diveeventitem.h index 1b138163c..f358fee6d 100644 --- a/qt-ui/profile/diveeventitem.h +++ b/qt-ui/profile/diveeventitem.h @@ -17,6 +17,7 @@ public: void setVerticalAxis(DiveCartesianAxis *axis); void setHorizontalAxis(DiveCartesianAxis *axis); void setModel(DivePlotDataModel *model); + bool shouldBeHidden(); public slots: void recalculatePos(bool instant = false); diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp index 7412a7764..ad2859b9e 100644 --- a/qt-ui/profile/diveplotdatamodel.cpp +++ b/qt-ui/profile/diveplotdatamodel.cpp @@ -3,8 +3,6 @@ #include "display.h" #include "profile.h" #include "graphicsview-common.h" -#include "dive.h" -#include "display.h" #include "divelist.h" #include <QDebug> @@ -153,7 +151,7 @@ int DivePlotDataModel::id() const return diveId; } -int DivePlotDataModel::dcShown() const +unsigned int DivePlotDataModel::dcShown() const { return dcNr; } @@ -183,7 +181,7 @@ void DivePlotDataModel::calculateDecompression() struct dive *d = getDiveById(id()); if (!d) return; - struct divecomputer *dc = select_dc(&d->dc); + struct divecomputer *dc = select_dc(d); init_decompression(d); calculate_deco_information(d, dc, &pInfo, false); dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16)); diff --git a/qt-ui/profile/diveplotdatamodel.h b/qt-ui/profile/diveplotdatamodel.h index 272c0d1c3..35805256d 100644 --- a/qt-ui/profile/diveplotdatamodel.h +++ b/qt-ui/profile/diveplotdatamodel.h @@ -55,7 +55,7 @@ public: void setDive(struct dive *d, const plot_info &pInfo); const plot_info &data() const; int id() const; - int dcShown() const; + unsigned int dcShown() const; double pheMax(); double pn2Max(); double po2Max(); @@ -65,7 +65,7 @@ public: private: plot_info pInfo; int diveId; - int dcNr; + unsigned int dcNr; }; #endif // DIVEPLOTDATAMODEL_H diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index b84f2928d..2ffc7ec02 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -636,17 +636,29 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const plot_data *entry = dataModel->data().entry; QPolygonF poly; - alertPoly.clear(); + QPolygonF alertpoly; + alertPolygons.clear(); QSettings s; s.beginGroup("TecDetails"); double threshould = s.value(threshouldKey).toDouble(); + bool inAlertFragment = false; for (int i = 0; i < dataModel->rowCount(); i++, entry++) { double value = dataModel->index(i, vDataColumn).data().toDouble(); int time = dataModel->index(i, hDataColumn).data().toInt(); QPointF point(hAxis->posAtValue(time), vAxis->posAtValue(value)); poly.push_back(point); - if (value >= threshould) - alertPoly.push_back(point); + if (value >= threshould) { + if (inAlertFragment) { + alertPolygons.back().push_back(point); + } else { + alertpoly.clear(); + alertpoly.push_back(point); + alertPolygons.append(alertpoly); + inAlertFragment = true; + } + } else { + inAlertFragment = false; + } } setPolygon(poly); /* @@ -656,10 +668,15 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const void PartialPressureGasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - painter->setPen(normalColor); + const qreal pWidth = 0.0; + painter->setPen(QPen(normalColor, pWidth)); painter->drawPolyline(polygon()); - painter->setPen(alertColor); - painter->drawPolyline(alertPoly); + + QPolygonF poly; + painter->setPen(QPen(alertColor, pWidth)); + Q_FOREACH(const QPolygonF & poly, alertPolygons) + painter->drawPolyline(poly); + } void PartialPressureGasItem::setThreshouldSettingsKey(const QString &threshouldSettingsKey) diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index ee7132c40..480776546 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -177,7 +177,7 @@ public: void setColors(const QColor &normalColor, const QColor &alertColor); private: - QPolygonF alertPoly; + QVector<QPolygonF> alertPolygons; QString threshouldKey; QString visibilityKey; QColor normalColor; diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index c11266a5a..0e68685b9 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -184,10 +184,9 @@ void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void ToolTipItem::persistPos() { - QPoint currentPos = scene()->views().at(0)->mapFromScene(pos()); QSettings s; s.beginGroup("ProfileMap"); - s.setValue("tooltip_position", currentPos); + s.setValue("tooltip_position", pos()); s.endGroup(); } @@ -195,8 +194,7 @@ void ToolTipItem::readPos() { QSettings s; s.beginGroup("ProfileMap"); - QPointF value = scene()->views().at(0)->mapToScene( - s.value("tooltip_position").toPoint()); + QPointF value = s.value("tooltip_position").toPoint(); if (!scene()->sceneRect().contains(value)) { value = QPointF(0, 0); } diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 2cdff1cff..a58244689 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -13,6 +13,7 @@ #include "planner.h" #include "device.h" #include "ruleritem.h" +#include <libdivecomputer/parser.h> #include <QSignalTransition> #include <QPropertyAnimation> #include <QMenu> @@ -21,6 +22,7 @@ #include <QSettings> #include <QScrollBar> #include <QtCore/qmath.h> +#include <QMessageBox> #ifndef QT_NO_DEBUG #include <QTableView> @@ -81,7 +83,9 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), po2GasItem(new PartialPressureGasItem()), heartBeatAxis(new DiveCartesianAxis()), heartBeatItem(new DiveHeartrateItem()), - rulerItem(new RulerItem2()) + rulerItem(new RulerItem2()), + isGrayscale(false), + printMode(false) { memset(&plotInfo, 0, sizeof(plotInfo)); @@ -139,10 +143,11 @@ void ProfileWidget2::setupItemOnScene() profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom); profileYAxis->setMinimum(0); profileYAxis->setTickInterval(M_OR_FT(10, 30)); - profileYAxis->setTickSize(1); + profileYAxis->setTickSize(0.5); profileYAxis->setLineSize(96); timeAxis->setLineSize(92); + timeAxis->setTickSize(-0.5); gasYAxis->setOrientation(DiveCartesianAxis::BottomToTop); gasYAxis->setTickInterval(1); @@ -173,7 +178,7 @@ void ProfileWidget2::setupItemOnScene() meanDepth->setAxis(profileYAxis); diveComputerText->setAlignment(Qt::AlignRight | Qt::AlignTop); - diveComputerText->setBrush(getColor(TIME_TEXT)); + diveComputerText->setBrush(getColor(TIME_TEXT, isGrayscale)); rulerItem->setAxis(timeAxis, profileYAxis); @@ -193,7 +198,7 @@ void ProfileWidget2::setupItemOnScene() setupItem(ITEM, timeAxis, gasYAxis, dataModel, DivePlotDataModel::VERTICAL_COLUMN, DivePlotDataModel::TIME, 0); \ ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \ ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \ - ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \ + ITEM->setColors(getColor(COLOR, isGrayscale), getColor(COLOR_ALERT, isGrayscale)); \ ITEM->preferencesChanged(); \ ITEM->setZValue(99); @@ -335,13 +340,21 @@ void ProfileWidget2::plotDives(QList<dive *> dives) firstCall = false; } - // restore default zoom level and tooltip position + // restore default zoom level if (zoomLevel) { const qreal defScale = 1.0 / qPow(zoomFactor, (qreal)zoomLevel); scale(defScale, defScale); zoomLevel = 0; } - toolTipItem->setPos(0, 0); + + // 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); // 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 @@ -357,7 +370,7 @@ void ProfileWidget2::plotDives(QList<dive *> dives) // next get the dive computer structure - if there are no samples // let's create a fake profile that's somewhat reasonable for the // data that we have - struct divecomputer *currentdc = select_dc(&d->dc); + struct divecomputer *currentdc = select_dc(d); Q_ASSERT(currentdc); if (!currentdc || !currentdc->samples) { currentdc = fake_dc(currentdc); @@ -416,6 +429,10 @@ void ProfileWidget2::plotDives(QList<dive *> dives) cylinderPressureAxis->setMaximum(pInfo.maxpressure); rulerItem->setPlotInfo(pInfo); + if (prefs.show_average_depth) + meanDepth->setVisible(true); + else + meanDepth->setVisible(false); meanDepth->setMeanDepth(pInfo.meandepth); meanDepth->setLine(0, 0, timeAxis->posAtValue(d->duration.seconds), 0); meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth)); @@ -438,10 +455,10 @@ void ProfileWidget2::plotDives(QList<dive *> dives) eventItems.push_back(item); event = event->next; } - // Only set visible the ones that should be visible, but how? + // Only set visible the events that should be visible Q_FOREACH(DiveEventItem * event, eventItems) { - event->setVisible(true); - // qDebug() << event->getEvent()->name << "@" << event->getEvent()->time.seconds; + event->setVisible(!event->shouldBeHidden()); + // qDebug() << event->getEvent()->name << "@" << event->getEvent()->time.seconds << "is hidden:" << event->isHidden(); } diveComputerText->setText(currentdc->model); if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1){ @@ -474,6 +491,7 @@ void ProfileWidget2::settingsChanged() rulerItem->setVisible(rulerVisible); rulerItem->destNode()->setVisible(rulerVisible); rulerItem->sourceNode()->setVisible(rulerVisible); + replot(); } else { rulerItem->setVisible(false); rulerItem->destNode()->setVisible(false); @@ -581,6 +599,9 @@ void ProfileWidget2::setEmptyState() 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) { tissue->setVisible(false); } @@ -598,7 +619,7 @@ void ProfileWidget2::setProfileState() currentState = PROFILE; MainWindow::instance()->setToolButtonsEnabled(true); toolTipItem->readPos(); - setBackgroundBrush(getColor(::BACKGROUND)); + setBackgroundBrush(getColor(::BACKGROUND, isGrayscale)); background->setVisible(false); toolTipItem->setVisible(true); @@ -620,6 +641,9 @@ void ProfileWidget2::setProfileState() temperatureAxis->setLine(itemPos.temperature.expanded); cylinderPressureAxis->setLine(itemPos.cylinder.expanded); } + pn2GasItem->setVisible(s.value("pn2graph").toBool()); + po2GasItem->setVisible(s.value("po2graph").toBool()); + pheGasItem->setVisible(s.value("phegraph").toBool()); gasYAxis->setPos(itemPos.partialPressure.pos.on); gasYAxis->setLine(itemPos.partialPressure.expanded); @@ -673,11 +697,8 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) } QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); action->setData(event->globalPos()); - QList<QGraphicsItem *> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos()))); - Q_FOREACH(QGraphicsItem * i, itemsAtPos) { - DiveEventItem *item = dynamic_cast<DiveEventItem *>(i); - if (!item) - continue; + QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos())); + if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) { action = new QAction(&m); action->setText(tr("Remove Event")); action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove. @@ -688,7 +709,6 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) action->setData(QVariant::fromValue<void *>(item)); connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents())); m.addAction(action); - break; } bool some_hidden = false; for (int i = 0; i < evn_used; i++) { @@ -704,13 +724,73 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) m.exec(event->globalPos()); } +void ProfileWidget2::hideEvents() +{ + QAction *action = qobject_cast<QAction *>(sender()); + DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>()); + struct event *event = item->getEvent(); + + if (QMessageBox::question(MainWindow::instance(), + TITLE_OR_TEXT(tr("Hide events"), tr("Hide all %1 events?").arg(event->name)), + 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)) { + ev_namelist[i].plot_ev = false; + break; + } + } + } + item->hide(); + replot(); + } +} + +void ProfileWidget2::unhideEvents() +{ + for (int i = 0; i < evn_used; i++) { + ev_namelist[i].plot_ev = true; + } + replot(); +} + +void ProfileWidget2::removeEvent() +{ + QAction *action = qobject_cast<QAction *>(sender()); + DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>()); + 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'))), + QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { + struct event **ep = ¤t_dc->events; + while (ep && *ep != event) + ep = &(*ep)->next; + if (ep) { + *ep = event->next; + free(event); + } + mark_divelist_changed(true); + replot(); + } +} + +void ProfileWidget2::addBookmark() +{ + QAction *action = qobject_cast<QAction *>(sender()); + QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); + add_event(current_dc, timeAxis->valueAt(scenePos), SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"); + replot(); +} + void ProfileWidget2::changeGas() { QAction *action = qobject_cast<QAction *>(sender()); QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); QString gas = action->text(); // backup the things on the dataModel, since we will clear that out. - int diveComputer = dataModel->dcShown(); + unsigned int diveComputer = dataModel->dcShown(); int diveId = dataModel->id(); int o2, he; int seconds = timeAxis->valueAt(scenePos); @@ -724,3 +804,9 @@ void ProfileWidget2::changeGas() mark_divelist_changed(true); replot(); } + +void ProfileWidget2::setPrintMode(bool mode, bool grayscale) +{ + printMode = mode; + isGrayscale = mode ? grayscale : false; +} diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index b5339edef..eb7486e8d 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -67,6 +67,7 @@ public: 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); public slots: // Necessary to call from QAction's signals. @@ -74,6 +75,10 @@ slots: // Necessary to call from QAction's signals. void setEmptyState(); void setProfileState(); void changeGas(); + void addBookmark(); + void hideEvents(); + void unhideEvents(); + void removeEvent(); protected: virtual void resizeEvent(QResizeEvent *event); @@ -122,6 +127,8 @@ private: DiveCartesianAxis *heartBeatAxis; DiveHeartrateItem *heartBeatItem; RulerItem2 *rulerItem; + bool isGrayscale; + bool printMode; }; #endif // PROFILEWIDGET2_H diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp index 627958e37..768d912e9 100644 --- a/qt-ui/profile/ruleritem.cpp +++ b/qt-ui/profile/ruleritem.cpp @@ -42,7 +42,7 @@ void RulerNodeItem2::recalculate() if (x() < 0) { setPos(0, y()); } else if (x() > timeAxis->posAtValue(data->sec)) { - setPos(timeAxis->posAtValue(data->sec), y()); + setPos(timeAxis->posAtValue(data->sec), depthAxis->posAtValue(data->depth)); } else { data = pInfo.entry; count = 0; @@ -77,6 +77,8 @@ RulerItem2::RulerItem2() : source(new RulerNodeItem2()), textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations); textItemBack->setBrush(QColor(0xff, 0xff, 0xff, 190)); textItemBack->setPen(QColor(Qt::white)); + textItemBack->setFlag(QGraphicsItem::ItemIgnoresTransformations); + setPen(QPen(QColor(Qt::black), 0.0)); } void RulerItem2::recalculate() @@ -116,13 +118,13 @@ void RulerItem2::recalculate() } // always show the text bellow the lowest of the start and end points qreal tgtY = (startPoint.y() >= endPoint.y()) ? startPoint.y() : endPoint.y(); - textItem->setPos(tgtX - 1, tgtY + 4); + // this isn't exactly optimal, since we want to scale the 1.0, 4.0 distances as well + textItem->setPos(tgtX - 1.0, tgtY + 4.0); // setup the text background textItemBack->setVisible(startPoint.x() != endPoint.x()); - QPointF wh = mapFromScene(view->mapToScene(QPoint(textItem->boundingRect().width(), - textItem->boundingRect().height()))); - textItemBack->setRect(tgtX - 2, tgtY + 3, wh.x() + 2, wh.y() + 3); + textItemBack->setPos(textItem->x(), textItem->y()); + textItemBack->setRect(0, 0, textItem->boundingRect().width(), textItem->boundingRect().height()); } RulerNodeItem2 *RulerItem2::sourceNode() const |