diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-02-27 13:28:58 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-27 10:48:47 -0800 |
commit | 52fe9101c8c69fee522385abf5d5e1037f60e59c (patch) | |
tree | f38730c8129872097cd7a032a19a0e7896fe2c37 | |
parent | 169589413056c8c76f52de5db662fe2269ff8c65 (diff) | |
download | subsurface-52fe9101c8c69fee522385abf5d5e1037f60e59c.tar.gz |
New profile: add placeholder code for the RulerItem
This patch just creates two files for the rulerItem, a .h and a .cpp.
nothing was done to make it visible on the new profile yet - will do that
on the next commits
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/mainwindow.ui | 5 | ||||
-rw-r--r-- | qt-ui/profile/ruleritem.cpp | 161 | ||||
-rw-r--r-- | qt-ui/profile/ruleritem.h | 50 | ||||
-rw-r--r-- | subsurface.pro | 6 |
4 files changed, 215 insertions, 7 deletions
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index e6adb5ba2..accfe4758 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -807,11 +807,6 @@ <string>Auto Group</string> </property> </action> - <action name="actionToggleZoom"> - <property name="text"> - <string>Toggle &Zoom</string> - </property> - </action> <action name="actionYearlyStatistics"> <property name="text"> <string>&Yearly Statistics</string> diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp new file mode 100644 index 000000000..b7b3a8229 --- /dev/null +++ b/qt-ui/profile/ruleritem.cpp @@ -0,0 +1,161 @@ +#include "ruleritem.h" +#include <QFont> +#include <QFontMetrics> +#include <QPainter> +#include <QGraphicsScene> + +#include "profile.h" +#include "display.h" + +RulerNodeItem2::RulerNodeItem2(QGraphicsItem *parent) : QGraphicsEllipseItem(parent), entry(NULL) , ruler(NULL) +{ + setRect(QRect(QPoint(-8,8),QPoint(8,-8))); + setBrush(QColor(0xff, 0, 0, 127)); + setPen(QColor("#FF0000")); + setFlag(QGraphicsItem::ItemIsMovable); + setFlag(ItemSendsGeometryChanges); + setFlag(ItemIgnoresTransformations); +} + +void RulerNodeItem2::setRuler(RulerItem2 *r) +{ + ruler = r; +} + +void RulerNodeItem2::recalculate() +{ + // Port that away from the SCALEGC + //struct plot_info *pi = &gc.pi; + //struct plot_data *data = pi->entry+(pi->nr-1); + //uint16_t count = 0; +// if (x() < 0) { +// setPos(0, y()); +// } else if (x() > SCALEXGC(data->sec)) { +// setPos(SCALEXGC(data->sec), y()); +// } else { +// data = pi->entry; +// count=0; +// while (SCALEXGC(data->sec) < x() && count < pi->nr) { +// data = pi->entry+count; +// count++; +// } +// setPos(SCALEGC(data->sec, data->depth)); +// entry=data; +} + +QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionHasChanged) { + recalculate(); + if (ruler != NULL) + ruler->recalculate(); + if (scene()) { + scene()->update(); + } + } + return QGraphicsEllipseItem::itemChange(change, value); +} + +RulerItem2::RulerItem2(QGraphicsItem *parent, RulerNodeItem2 *sourceNode, RulerNodeItem2 *destNode) : QGraphicsObject(parent), source(sourceNode), dest(destNode) +{ + recalculate(); +} + +void RulerItem2::recalculate() +{ + char buffer[500]; + QPointF tmp; + QFont font; + QFontMetrics fm(font); + + if (source == NULL || dest == NULL) + return; + + prepareGeometryChange(); + startPoint = mapFromItem(source, 0, 0); + endPoint = mapFromItem(dest, 0, 0); + if (startPoint.x() > endPoint.x()) { + tmp = endPoint; + endPoint = startPoint; + startPoint = tmp; + } + QLineF line(startPoint, endPoint); + + compare_samples(source->entry, dest->entry, buffer, 500, 1); + text = QString(buffer); + + QRect r = fm.boundingRect(QRect(QPoint(10,-1*INT_MAX), QPoint(line.length()-10, 0)), Qt::TextWordWrap, text); + if (r.height() < 10) + height = 10; + else + height = r.height(); + + QLineF line_n = line.normalVector(); + line_n.setLength(height); + if (scene()) { + /* Determine whether we draw down or upwards */ + if (scene()->sceneRect().contains(line_n.p2()) && + scene()->sceneRect().contains(endPoint+QPointF(line_n.dx(),line_n.dy()))) + paint_direction = -1; + else + paint_direction = 1; + } +} + +RulerNodeItem2 *RulerItem2::sourceNode() const +{ + return source; +} + +RulerNodeItem2 *RulerItem2::destNode() const +{ + return dest; +} + +void RulerItem2::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + QLineF line(startPoint, endPoint); + QLineF line_n = line.normalVector(); + painter->setPen(QColor(Qt::black)); + painter->setBrush(Qt::NoBrush); + line_n.setLength(height); + + if (paint_direction == 1) + line_n.setAngle(line_n.angle()+180); + painter->drawLine(line); + painter->drawLine(line_n); + painter->drawLine(line_n.p1() + QPointF(line.dx(), line.dy()), line_n.p2() + QPointF(line.dx(), line.dy())); + + //Draw Text + painter->save(); + painter->translate(startPoint.x(), startPoint.y()); + painter->rotate(line.angle()*-1); + if (paint_direction == 1) + painter->translate(0, height); + painter->setPen(Qt::black); + painter->drawText(QRectF(QPointF(10,-1*height), QPointF(line.length()-10, 0)), Qt::TextWordWrap, text); + painter->restore(); +} + +QRectF RulerItem2::boundingRect() const +{ + return shape().controlPointRect(); +} + +QPainterPath RulerItem2::shape() const +{ + QPainterPath path; + QLineF line(startPoint, endPoint); + QLineF line_n = line.normalVector(); + line_n.setLength(height); + if (paint_direction == 1) + line_n.setAngle(line_n.angle()+180); + path.moveTo(startPoint); + path.lineTo(line_n.p2()); + path.lineTo(line_n.p2() + QPointF(line.dx(), line.dy())); + path.lineTo(endPoint); + path.lineTo(startPoint); + return path; +} diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h new file mode 100644 index 000000000..68d6c3180 --- /dev/null +++ b/qt-ui/profile/ruleritem.h @@ -0,0 +1,50 @@ +#ifndef RULERITEM_H +#define RULERITEM_H + +#include <QObject> +#include <QGraphicsEllipseItem> +#include <QGraphicsObject> + +struct plot_data; +class RulerItem2; + +class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem +{ + Q_OBJECT + friend class RulerItem2; +public: + explicit RulerNodeItem2(QGraphicsItem* parent); + void setRuler(RulerItem2 *r); + void recalculate(); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant & value ); + +private: + struct plot_data *entry; + RulerItem2* ruler; +}; + +class RulerItem2 : public QGraphicsObject +{ + Q_OBJECT +public: + explicit RulerItem2(QGraphicsItem* parent, + RulerNodeItem2 *sourceMarker, + RulerNodeItem2 *destMarker); + void recalculate(); + + RulerNodeItem2* sourceNode() const; + RulerNodeItem2* destNode() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0); + QRectF boundingRect() const; + QPainterPath shape() const; + +private: + QPointF startPoint, endPoint; + RulerNodeItem2 *source, *dest; + QString text; + int height; + int paint_direction; +}; +#endif
\ No newline at end of file diff --git a/subsurface.pro b/subsurface.pro index 7ba8e51f1..3a73a0c78 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -75,7 +75,8 @@ HEADERS = \ qt-ui/profile/diveplotdatamodel.h \ qt-ui/profile/diveprofileitem.h \ qt-ui/profile/diveeventitem.h \ - qt-ui/profile/divetooltipitem.h + qt-ui/profile/divetooltipitem.h \ + qt-ui/profile/ruleritem.h SOURCES = \ deco.c \ @@ -138,7 +139,8 @@ SOURCES = \ qt-ui/profile/diveplotdatamodel.cpp \ qt-ui/profile/diveprofileitem.cpp \ qt-ui/profile/diveeventitem.cpp \ - qt-ui/profile/divetooltipitem.cpp + qt-ui/profile/divetooltipitem.cpp \ + qt-ui/profile/ruleritem.cpp linux*: SOURCES += linux.c mac: SOURCES += macos.c |