summaryrefslogtreecommitdiffstats
path: root/qt-ui/profilegraphics.h
blob: 9ad04674bf8f4d496280dc9cfefc0b5e2c53c6f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef PROFILEGRAPHICS_H
#define PROFILEGRAPHICS_H

#include <QGraphicsView>
#include <QGraphicsItem>
#include <QIcon>

struct text_render_options;
struct graphics_context;
struct plot_info;
typedef struct text_render_options text_render_options_t;


class ToolTipItem;
class ToolTipStatusHandler;

class ToolTipStatusHandler :public QObject, public QGraphicsEllipseItem {
public:
    explicit ToolTipStatusHandler(QObject* parent = 0);
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent* event);
};

class ToolTipItem :public QObject, public QGraphicsPathItem {
	Q_OBJECT
	Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)

public:
	enum Status {COLLAPSED, EXPANDED};
	enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32};

    explicit ToolTipItem(QGraphicsItem* parent = 0);

	void collapse();
	void expand();
	void clear();
	void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
	void removeToolTip(const QString& toolTip);

public Q_SLOTS:
	void setRect(const QRectF& rect);

private:
	typedef QPair<QGraphicsPixmapItem*, QGraphicsSimpleTextItem*> ToolTip;
	enum Status status;
	QMap<QString, ToolTip > toolTips;
	QGraphicsRectItem *background;
	QRectF rectangle;
};

class ProfileGraphicsView : public QGraphicsView {
Q_OBJECT
public:
	ProfileGraphicsView(QWidget* parent = 0);
	void plot(struct dive *d);
	void addToolTip(const QString& text, const QIcon& icon = QIcon());
	void removeToolTip(const QString& text);

protected:
	void resizeEvent(QResizeEvent *event);

private:
	void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi);
	void plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString &text);
	void plot_events(struct graphics_context *gc, struct plot_info *pi, struct divecomputer *dc);
	void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event);

	QPen defaultPen;
	QBrush defaultBrush;
	ToolTipItem *toolTip;
};


#endif