diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2014-01-22 15:08:19 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-22 12:29:41 -0800 |
commit | 2e2a87e6196428280647085527720564c8e3c563 (patch) | |
tree | 4506ed9801e4af7a7f4ceaf3effcab0234f3bb97 | |
parent | f22428b345524a75527320bc9664ca2257ebe590 (diff) | |
download | subsurface-2e2a87e6196428280647085527720564c8e3c563.tar.gz |
Add a MeanDepthItem that has 2 strings.
Dirk's implementation of the MeanDepth item was correct, but in order to
add the 2 strings to it ( one at the begin, one at the end ) I had to put
more stuff inside the ProfileWidget that's already packed with graphics
items.
So I created a new class MeanDepthItem that contains these 2 strings and
will get updated whenever the value changes.
I also fixed a math inconsistency where I changed RIGHT to LEFT.
(wich fixed a few text-placements, and broke others.)
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 27 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.h | 16 | ||||
-rw-r--r-- | qt-ui/profile/divetextitem.cpp | 4 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 3 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 3 |
5 files changed, 47 insertions, 6 deletions
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 9fda21485..5ddef1e90 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -7,6 +7,7 @@ #include "dive.h" #include "profilegraphics.h" #include "preferences.h" +#include "helpers.h" #include <QPen> #include <QPainter> @@ -384,7 +385,6 @@ void DiveCalculatedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsI QGraphicsPolygonItem::paint(painter, option, widget); } - void DiveReportedCeiling::modelDataChanged() { if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1) @@ -425,3 +425,28 @@ void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsIte { QGraphicsPolygonItem::paint(painter, option, widget); } + +MeanDepthLine::MeanDepthLine() +{ + leftText = new DiveTextItem(this); + leftText->setAlignment(Qt::AlignRight | Qt::AlignBottom); + leftText->setBrush(getColor(MEAN_DEPTH)); + rightText = new DiveTextItem(this); + rightText->setAlignment(Qt::AlignLeft | Qt::AlignBottom); + rightText->setBrush(getColor(MEAN_DEPTH)); + leftText->setPos(0, 0); + rightText->setPos(line().length(), 0); +} + +void MeanDepthLine::setLine(qreal x1, qreal y1, qreal x2, qreal y2) +{ + QGraphicsLineItem::setLine(x1, y1, x2, y2); + leftText->setPos(x1, 0); + rightText->setPos(x2, 0); +} + +void MeanDepthLine::setMeanDepth(int value) +{ + leftText->setText(get_depth_string(value, false, false)); + rightText->setText(get_depth_string(value, false, false)); +} diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index 57b1e70e8..272ee0821 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -4,6 +4,8 @@ #include <QObject> #include <QGraphicsPolygonItem> #include "graphicsview-common.h" +#include "divelineitem.h" + /* This is the Profile Item, it should be used for quite a lot of things on the profile view. The usage should be pretty simple: @@ -100,4 +102,16 @@ public: virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); virtual void preferencesChanged(); }; -#endif
\ No newline at end of file + +class MeanDepthLine : public DiveLineItem { + Q_OBJECT +public: + MeanDepthLine(); + void setMeanDepth(int value); + void setLine(qreal x1, qreal y1, qreal x2, qreal y2); +private: + int meanDepth; + DiveTextItem *leftText; + DiveTextItem *rightText; +}; +#endif diff --git a/qt-ui/profile/divetextitem.cpp b/qt-ui/profile/divetextitem.cpp index 0bf071069..163bb64f4 100644 --- a/qt-ui/profile/divetextitem.cpp +++ b/qt-ui/profile/divetextitem.cpp @@ -59,9 +59,9 @@ void DiveTextItem::updateText() (internalAlignFlags & Qt::AlignBottom) ? +rect.height() : /*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4; - xPos = (internalAlignFlags & Qt::AlignLeft ) ? +rect.width() : + xPos = (internalAlignFlags & Qt::AlignLeft ) ? -rect.width() : (internalAlignFlags & Qt::AlignHCenter) ? -rect.width()/2 : - /* (internalAlignFlags & Qt::AlignRight) */ -rect.width(); + /* (internalAlignFlags & Qt::AlignRight) */ 0; textPath.addText( xPos, yPos, fnt, internalText); QPainterPathStroker stroker; diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index b5610e4cf..4b19af1ba 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -37,7 +37,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : temperatureItem(NULL), gasPressureItem(NULL), cartesianPlane(new DiveCartesianPlane()), - meanDepth(new DiveLineItem()), + meanDepth(new MeanDepthLine()), diveComputerText(new DiveTextItem()), diveCeiling(NULL), reportedCeiling(NULL) @@ -304,6 +304,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives) timeAxis->updateTicks(); cylinderPressureAxis->setMinimum(pInfo.minpressure); cylinderPressureAxis->setMaximum(pInfo.maxpressure); + meanDepth->setMeanDepth(pInfo.meandepth); meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth)); dataModel->setDive(current_dive, pInfo); diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index 369941930..780a9b2a7 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -16,6 +16,7 @@ #include "graphicsview-common.h" #include "divelineitem.h" +class MeanDepthLine; class DiveReportedCeiling; class DiveTextItem; class TemperatureAxis; @@ -83,7 +84,7 @@ private: DiveTemperatureItem *temperatureItem; DiveCartesianAxis *cylinderPressureAxis; DiveGasPressureItem *gasPressureItem; - DiveLineItem *meanDepth; + MeanDepthLine *meanDepth; QList<DiveEventItem*> eventItems; DiveTextItem *diveComputerText; DiveCalculatedCeiling *diveCeiling; |