aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/profile/divecartesianaxis.cpp160
-rw-r--r--qt-ui/profile/divecartesianaxis.h46
-rw-r--r--subsurface.pro6
3 files changed, 210 insertions, 2 deletions
diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
new file mode 100644
index 000000000..78ef38e68
--- /dev/null
+++ b/qt-ui/profile/divecartesianaxis.cpp
@@ -0,0 +1,160 @@
+#include "divecartesianaxis.h"
+#include "divelineitem.h"
+#include "divetextitem.h"
+#include "helpers.h"
+
+#include <QPen>
+#include <QGraphicsScene>
+#include <QDebug>
+#include <QPropertyAnimation>
+#include <QGraphicsView>
+#include <QStyleOption>
+
+void DiveCartesianAxis::setMaximum(double maximum)
+{
+ max = maximum;
+}
+
+void DiveCartesianAxis::setMinimum(double minimum)
+{
+ min = minimum;
+}
+
+void DiveCartesianAxis::setTextColor(const QColor& color)
+{
+ textColor = color;
+}
+
+DiveCartesianAxis::DiveCartesianAxis() : orientation(Qt::Horizontal)
+{
+}
+
+DiveCartesianAxis::~DiveCartesianAxis()
+{
+
+}
+
+void DiveCartesianAxis::setOrientation(Qt::Orientation o)
+{
+ orientation = o;
+ // position the elements on the screen.
+ setMinimum(minimum());
+ setMaximum(maximum());
+}
+
+void DiveCartesianAxis::updateTicks()
+{
+ qDeleteAll(ticks);
+ ticks.clear();
+ qDeleteAll(labels);
+ labels.clear();
+
+ QLineF m = line();
+ DiveLineItem *item = NULL;
+ DiveTextItem *label = NULL;
+
+ double steps = (max - min) / interval;
+ qreal pos;
+ double currValue = min;
+
+ if (orientation == Qt::Horizontal) {
+ double stepSize = (m.x2() - m.x1()) / steps;
+ for (pos = m.x1(); pos <= m.x2(); pos += stepSize, currValue += interval) {
+ item = new DiveLineItem(this);
+ item->setLine(pos, m.y1(), pos, m.y1() + tickSize);
+ item->setPen(pen());
+ ticks.push_back(item);
+
+ label = new DiveTextItem(this);
+ label->setText(QString::number(currValue));
+ label->setBrush(QBrush(textColor));
+ label->setFlag(ItemIgnoresTransformations);
+ label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
+ labels.push_back(label);
+ }
+ } else {
+ double stepSize = (m.y2() - m.y1()) / steps;
+ for (pos = m.y1(); pos <= m.y2(); pos += stepSize, currValue += interval) {
+ item = new DiveLineItem(this);
+ item->setLine(m.x1(), pos, m.x1() - tickSize, pos);
+ item->setPen(pen());
+ ticks.push_back(item);
+
+ label = new DiveTextItem(this);
+ label->setText(get_depth_string(currValue, false, false));
+ label->setBrush(QBrush(textColor));
+ label->setFlag(ItemIgnoresTransformations);
+ label->setPos(m.x2() - 80, pos);
+ labels.push_back(label);
+ }
+ }
+}
+
+QString DiveCartesianAxis::textForValue(double value)
+{
+ return QString::number(value);
+}
+
+void DiveCartesianAxis::setTickSize(qreal size)
+{
+ tickSize = size;
+}
+
+void DiveCartesianAxis::setTickInterval(double i)
+{
+ interval = i;
+}
+
+qreal DiveCartesianAxis::valueAt(const QPointF& p)
+{
+ QLineF m = line();
+ double retValue = orientation == Qt::Horizontal ?
+ max * (p.x() - m.x1()) / (m.x2() - m.x1()) :
+ max * (p.y() - m.y1()) / (m.y2() - m.y1());
+ return retValue;
+}
+
+qreal DiveCartesianAxis::posAtValue(qreal value)
+{
+ QLineF m = line();
+ QPointF p = pos();
+
+ double size = max - min;
+ double percent = value / size;
+ double realSize = orientation == Qt::Horizontal ?
+ m.x2() - m.x1() :
+ m.y2() - m.y1();
+ double retValue = realSize * percent;
+ retValue = (orientation == Qt::Horizontal) ?
+ retValue + m.x1() + p.x():
+ retValue + m.y1() + p.y();
+ return retValue;
+}
+
+qreal DiveCartesianAxis::percentAt(const QPointF& p)
+{
+ qreal value = valueAt(p);
+ double size = max - min;
+ double percent = value / size;
+ return percent;
+}
+
+double DiveCartesianAxis::maximum() const
+{
+ return max;
+}
+
+double DiveCartesianAxis::minimum() const
+{
+ return min;
+}
+
+void DiveCartesianAxis::setColor(const QColor& color)
+{
+ QPen defaultPen(color);
+ defaultPen.setJoinStyle(Qt::RoundJoin);
+ defaultPen.setCapStyle(Qt::RoundCap);
+ defaultPen.setWidth(2);
+ defaultPen.setCosmetic(true);
+ setPen(defaultPen);
+}
diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h
new file mode 100644
index 000000000..1c8170ef4
--- /dev/null
+++ b/qt-ui/profile/divecartesianaxis.h
@@ -0,0 +1,46 @@
+#ifndef DIVECARTESIANAXIS_H
+#define DIVECARTESIANAXIS_H
+
+#include <QObject>
+#include <QGraphicsLineItem>
+class DiveTextItem;
+class DiveLineItem;
+
+class DiveCartesianAxis : public QObject, public QGraphicsLineItem{
+ Q_OBJECT
+ Q_PROPERTY(QLineF line WRITE setLine READ line)
+ Q_PROPERTY(QPointF pos WRITE setPos READ pos)
+ Q_PROPERTY(qreal x WRITE setX READ x)
+ Q_PROPERTY(qreal y WRITE setY READ y)
+public:
+ DiveCartesianAxis();
+ virtual ~DiveCartesianAxis();
+ void setMinimum(double minimum);
+ void setMaximum(double maximum);
+ void setTickInterval(double interval);
+ void setOrientation(Qt::Orientation orientation);
+ void setTickSize(qreal size);
+ void updateTicks();
+ double minimum() const;
+ double maximum() const;
+ qreal valueAt(const QPointF& p);
+ qreal percentAt(const QPointF& p);
+ qreal posAtValue(qreal value);
+ void setColor(const QColor& color);
+ void setTextColor(const QColor& color);
+ int unitSystem;
+
+protected:
+ virtual QString textForValue(double value);
+
+ Qt::Orientation orientation;
+ QList<DiveLineItem*> ticks;
+ QList<DiveTextItem*> labels;
+ double min;
+ double max;
+ double interval;
+ double tickSize;
+ QColor textColor;
+};
+
+#endif \ No newline at end of file
diff --git a/subsurface.pro b/subsurface.pro
index 2753e3374..ead81818d 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -68,7 +68,8 @@ HEADERS = \
qt-ui/profile/divepixmapitem.h \
qt-ui/profile/divelineitem.h \
qt-ui/profile/divetextitem.h \
- qt-ui/profile/animationfunctions.h
+ qt-ui/profile/animationfunctions.h \
+ qt-ui/profile/divecartesianaxis.h
SOURCES = \
deco.c \
@@ -124,7 +125,8 @@ SOURCES = \
qt-ui/profile/divepixmapitem.cpp \
qt-ui/profile/divelineitem.cpp \
qt-ui/profile/divetextitem.cpp \
- qt-ui/profile/animationfunctions.cpp
+ qt-ui/profile/animationfunctions.cpp \
+ qt-ui/profile/divecartesianaxis.cpp
linux*: SOURCES += linux.c
mac: SOURCES += macos.c