aboutsummaryrefslogtreecommitdiffstats
path: root/profile-widget/divetooltipitem.h
blob: 9a1cdb8bf3a811ee4fc1606b6892dd4ab47ac9a7 (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
// SPDX-License-Identifier: GPL-2.0
#ifndef DIVETOOLTIPITEM_H
#define DIVETOOLTIPITEM_H

#include <QVector>
#include <QPair>
#include <QRectF>
#include <QIcon>
#include <QElapsedTimer>
#include "backend-shared/roundrectitem.h"
#include "core/display.h"

class DiveCartesianAxis;
class QGraphicsLineItem;
class QGraphicsSimpleTextItem;
class QGraphicsPixmapItem;

/* 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.
 */
class ToolTipItem : public QObject, public RoundRectItem {
	Q_OBJECT
	Q_PROPERTY(QRectF rect READ rect WRITE setRect)

public:
	enum Status {
		COLLAPSED,
		EXPANDED
	};

	explicit ToolTipItem(QGraphicsItem *parent = 0);
	~ToolTipItem();

	void refresh(const dive *d, const QPointF &pos, bool inPlanner);
	void readPos();
	void mousePressEvent(QGraphicsSceneMouseEvent *event);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
	void setTimeAxis(DiveCartesianAxis *axis);
	void setPlotInfo(const plot_info &plot);
	void clearPlotInfo();
public
slots:
	void setRect(const QRectF &rect);

private:
	typedef QPair<QGraphicsPixmapItem *, QGraphicsSimpleTextItem *> ToolTip;
	QVector<ToolTip> toolTips;
	ToolTip entryToolTip;
	QGraphicsSimpleTextItem *title;
	Status status;
	QRectF rectangle;
	QRectF nextRectangle;
	DiveCartesianAxis *timeAxis;
	plot_info pInfo;
	int lastTime;
	QElapsedTimer refreshTime;
	QList<QGraphicsItem*> oldSelection;

	void addToolTip(const QString &toolTip, const QPixmap &pixmap);
	void collapse();
	void expand();
	void clear();
	bool isExpanded() const;
	void persistPos() const;
	void updateTitlePosition();
};

#endif // DIVETOOLTIPITEM_H