2013-05-04 19:12:43 +00:00
|
|
|
#ifndef PROFILEGRAPHICS_H
|
|
|
|
#define PROFILEGRAPHICS_H
|
|
|
|
|
2013-07-13 15:18:26 +00:00
|
|
|
#include "graphicsview-common.h"
|
2013-05-08 21:56:06 +00:00
|
|
|
#include "../display.h"
|
2013-05-04 19:12:43 +00:00
|
|
|
#include <QGraphicsView>
|
2013-05-07 18:44:54 +00:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QIcon>
|
2013-06-10 22:02:06 +00:00
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QGraphicsProxyWidget>
|
2013-05-04 19:12:43 +00:00
|
|
|
|
2013-05-06 18:35:17 +00:00
|
|
|
struct text_render_options;
|
|
|
|
struct graphics_context;
|
|
|
|
struct plot_info;
|
|
|
|
typedef struct text_render_options text_render_options_t;
|
|
|
|
|
2013-05-09 21:45:58 +00:00
|
|
|
/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
|
|
|
|
* or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
|
|
|
|
*/
|
2013-05-07 23:12:01 +00:00
|
|
|
class ToolTipItem :public QObject, public QGraphicsPathItem
|
|
|
|
{
|
2013-05-07 18:44:54 +00:00
|
|
|
Q_OBJECT
|
2013-05-07 23:09:51 +00:00
|
|
|
void updateTitlePosition();
|
2013-05-07 18:44:54 +00:00
|
|
|
Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)
|
|
|
|
|
|
|
|
public:
|
2013-05-07 23:09:51 +00:00
|
|
|
enum Status{COLLAPSED, EXPANDED};
|
|
|
|
enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
|
2013-05-07 18:44:54 +00:00
|
|
|
|
2013-05-07 23:09:51 +00:00
|
|
|
explicit ToolTipItem(QGraphicsItem* parent = 0);
|
2013-06-10 16:54:17 +00:00
|
|
|
virtual ~ToolTipItem();
|
2013-05-07 18:44:54 +00:00
|
|
|
|
|
|
|
void collapse();
|
|
|
|
void expand();
|
|
|
|
void clear();
|
|
|
|
void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
|
2013-05-10 14:07:44 +00:00
|
|
|
void refresh(struct graphics_context* gc, QPointF pos);
|
2013-06-08 01:49:57 +00:00
|
|
|
bool isExpanded();
|
2013-06-10 17:28:44 +00:00
|
|
|
void persistPos();
|
|
|
|
void readPos();
|
2013-06-10 17:48:31 +00:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
|
|
|
bool eventFilter(QObject* , QEvent* );
|
2013-06-19 17:20:16 +00:00
|
|
|
public slots:
|
2013-05-07 18:44:54 +00:00
|
|
|
void setRect(const QRectF& rect);
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef QPair<QGraphicsPixmapItem*, QGraphicsSimpleTextItem*> ToolTip;
|
2013-07-30 21:36:20 +00:00
|
|
|
QList<ToolTip> toolTips;
|
2013-05-08 02:00:05 +00:00
|
|
|
QGraphicsPathItem *background;
|
2013-05-07 23:09:51 +00:00
|
|
|
QGraphicsLineItem *separator;
|
|
|
|
QGraphicsSimpleTextItem *title;
|
2013-06-08 01:49:57 +00:00
|
|
|
Status status;
|
2013-05-07 18:44:54 +00:00
|
|
|
QRectF rectangle;
|
2013-06-10 17:48:31 +00:00
|
|
|
bool dragging;
|
2013-07-05 12:33:50 +00:00
|
|
|
QRectF nextRectangle;
|
2013-05-07 18:44:54 +00:00
|
|
|
};
|
|
|
|
|
2013-09-25 00:07:07 +00:00
|
|
|
class RulerItem;
|
|
|
|
|
|
|
|
class RulerNodeItem : public QObject, public QGraphicsEllipseItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
friend class RulerItem;
|
|
|
|
public:
|
|
|
|
explicit RulerNodeItem(QGraphicsItem* parent, graphics_context gc);
|
|
|
|
void setRuler(RulerItem *r);
|
|
|
|
void recalculate();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QVariant itemChange(GraphicsItemChange change, const QVariant & value );
|
|
|
|
|
|
|
|
private:
|
|
|
|
graphics_context gc;
|
|
|
|
struct plot_data *entry;
|
|
|
|
RulerItem* ruler;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RulerItem : public QGraphicsObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit RulerItem(QGraphicsItem* parent,
|
|
|
|
RulerNodeItem *sourceMarker,
|
|
|
|
RulerNodeItem *destMarker);
|
|
|
|
void recalculate();
|
|
|
|
|
|
|
|
RulerNodeItem* sourceNode() const;
|
|
|
|
RulerNodeItem* destNode() const;
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
QPainterPath shape() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QPointF startPoint, endPoint;
|
|
|
|
RulerNodeItem *source, *dest;
|
|
|
|
QString text;
|
|
|
|
int height;
|
|
|
|
int paint_direction;
|
|
|
|
};
|
|
|
|
|
2013-05-07 23:12:01 +00:00
|
|
|
class EventItem : public QGraphicsPolygonItem
|
|
|
|
{
|
2013-05-07 23:09:51 +00:00
|
|
|
public:
|
2013-07-13 15:18:26 +00:00
|
|
|
explicit EventItem(QGraphicsItem* parent = 0, bool grayscale = FALSE);
|
2013-05-07 23:09:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ToolTipItem *controller;
|
|
|
|
QString text;
|
|
|
|
QIcon icon;
|
2013-07-13 15:18:26 +00:00
|
|
|
bool isGrayscale;
|
|
|
|
|
|
|
|
QColor getColor(const color_indice_t i);
|
2013-05-07 23:09:51 +00:00
|
|
|
};
|
|
|
|
|
2013-06-10 22:02:06 +00:00
|
|
|
class GraphicsTextEditor : public QGraphicsTextItem{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
GraphicsTextEditor(QGraphicsItem* parent = 0);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
|
|
|
|
virtual void keyReleaseEvent(QKeyEvent* event);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void textChanged(const QString& text);
|
|
|
|
void editingFinished(const QString& text);
|
|
|
|
};
|
|
|
|
|
2013-05-07 23:12:01 +00:00
|
|
|
class ProfileGraphicsView : public QGraphicsView
|
|
|
|
{
|
2013-05-04 19:12:43 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-06-10 20:33:46 +00:00
|
|
|
enum Mode{DIVE, PLAN};
|
|
|
|
|
2013-05-04 19:12:43 +00:00
|
|
|
ProfileGraphicsView(QWidget* parent = 0);
|
2013-05-26 18:33:45 +00:00
|
|
|
void plot(struct dive *d, bool forceRedraw = FALSE);
|
2013-05-08 10:22:23 +00:00
|
|
|
bool eventFilter(QObject* obj, QEvent* event);
|
2013-05-16 19:00:33 +00:00
|
|
|
void clear();
|
2013-07-13 14:02:06 +00:00
|
|
|
void setPrintMode(bool mode, bool grayscale = FALSE);
|
2013-05-04 19:12:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *event);
|
2013-05-23 04:25:05 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
|
|
|
void wheelEvent(QWheelEvent* event);
|
|
|
|
void showEvent(QShowEvent* event);
|
2013-05-04 19:12:43 +00:00
|
|
|
|
2013-06-19 17:20:16 +00:00
|
|
|
public slots:
|
2013-05-26 18:33:45 +00:00
|
|
|
void refresh();
|
2013-06-10 22:35:22 +00:00
|
|
|
void edit_dive_time(const QString& time);
|
2013-09-25 00:39:21 +00:00
|
|
|
void on_rulerAction();
|
|
|
|
void on_scaleAction();
|
2013-05-26 18:33:45 +00:00
|
|
|
|
2013-05-04 22:20:49 +00:00
|
|
|
private:
|
2013-05-08 21:56:06 +00:00
|
|
|
void plot_depth_profile();
|
2013-07-01 12:21:01 +00:00
|
|
|
QGraphicsItemGroup *plot_text(text_render_options_t *tro, const QPointF& pos, const QString &text, QGraphicsItem *parent = 0);
|
2013-05-08 21:56:06 +00:00
|
|
|
void plot_events(struct divecomputer *dc);
|
|
|
|
void plot_one_event(struct event *event);
|
|
|
|
void plot_temperature_profile();
|
2013-06-10 16:54:17 +00:00
|
|
|
void plot_cylinder_pressure(struct divecomputer *dc);
|
2013-05-09 18:28:50 +00:00
|
|
|
void plot_temperature_text();
|
|
|
|
void plot_single_temp_text(int sec, int mkelvin);
|
2013-05-09 18:37:43 +00:00
|
|
|
void plot_depth_text();
|
|
|
|
void plot_text_samples();
|
|
|
|
void plot_depth_sample(struct plot_data *entry, text_render_options_t *tro);
|
2013-05-09 18:42:38 +00:00
|
|
|
void plot_cylinder_pressure_text();
|
2013-05-10 15:56:56 +00:00
|
|
|
void plot_pressure_value(int mbar, int sec, double xalign, double yalign);
|
2013-05-31 06:21:39 +00:00
|
|
|
void plot_gas_value(int mbar, int sec, double xalign, double yalign, int o2, int he);
|
2013-05-09 18:47:39 +00:00
|
|
|
void plot_deco_text();
|
2013-06-13 17:52:30 +00:00
|
|
|
void plot_add_line(int sec, double val, QColor c, QPointF &from);
|
2013-05-09 18:47:39 +00:00
|
|
|
void plot_pp_gas_profile();
|
2013-05-09 20:30:16 +00:00
|
|
|
void plot_pp_text();
|
2013-05-09 21:02:52 +00:00
|
|
|
void plot_depth_scale();
|
|
|
|
|
2013-09-25 00:39:21 +00:00
|
|
|
|
|
|
|
void addControlItems();
|
|
|
|
|
2013-09-25 00:07:07 +00:00
|
|
|
void create_ruler();
|
|
|
|
void add_ruler();
|
|
|
|
void remove_ruler();
|
|
|
|
|
2013-07-13 15:18:26 +00:00
|
|
|
QColor getColor(const color_indice_t i);
|
2013-05-09 03:24:03 +00:00
|
|
|
QColor get_sac_color(int sac, int avg_sac);
|
2013-07-04 20:55:27 +00:00
|
|
|
void scrollViewTo(const QPoint pos);
|
2013-05-04 23:18:16 +00:00
|
|
|
|
|
|
|
QPen defaultPen;
|
|
|
|
QBrush defaultBrush;
|
2013-05-07 18:44:54 +00:00
|
|
|
ToolTipItem *toolTip;
|
2013-05-08 21:56:06 +00:00
|
|
|
graphics_context gc;
|
2013-05-09 22:59:55 +00:00
|
|
|
struct dive *dive;
|
2013-05-23 03:31:27 +00:00
|
|
|
struct divecomputer *diveDC;
|
2013-05-10 14:45:07 +00:00
|
|
|
int zoomLevel;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
bool rulerEnabled;
|
2013-07-12 14:20:59 +00:00
|
|
|
bool printMode;
|
2013-07-13 14:02:06 +00:00
|
|
|
bool isGrayscale;
|
2013-05-10 16:57:36 +00:00
|
|
|
|
|
|
|
// Top Level Items.
|
|
|
|
QGraphicsItem* profileGrid;
|
|
|
|
QGraphicsItem* timeMarkers;
|
|
|
|
QGraphicsItem* depthMarkers;
|
|
|
|
QGraphicsItem* diveComputer;
|
2013-09-25 00:07:07 +00:00
|
|
|
RulerItem *rulerItem;
|
2013-09-25 00:39:21 +00:00
|
|
|
QGraphicsProxyWidget *toolBarProxy;
|
2013-06-10 20:33:46 +00:00
|
|
|
|
2013-06-10 22:02:06 +00:00
|
|
|
// For 'Plan' mode.:
|
|
|
|
GraphicsTextEditor *depthEditor;
|
|
|
|
GraphicsTextEditor *timeEditor;
|
|
|
|
|
2013-06-10 20:33:46 +00:00
|
|
|
enum Mode mode;
|
2013-05-04 19:12:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|