2013-05-04 19:12:43 +00:00
|
|
|
#ifndef PROFILEGRAPHICS_H
|
|
|
|
#define PROFILEGRAPHICS_H
|
|
|
|
|
|
|
|
#include <QGraphicsView>
|
2013-05-07 18:44:54 +00:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QIcon>
|
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-07 23:12:01 +00:00
|
|
|
/**!
|
|
|
|
*
|
|
|
|
* Hookay, so, if you wanna extend the ToolTips that are displayed
|
|
|
|
* in the Profile Graph, there's one 'toolTip' widget already on it,
|
|
|
|
* you can just pass it to your Reimplementation of QGraphiscItem
|
|
|
|
* and do the following:
|
|
|
|
*
|
|
|
|
* EventItem::setController(ToolTipItem *c)
|
|
|
|
* {
|
|
|
|
* controller = c;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* void EventItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
|
|
|
|
* {
|
|
|
|
* controller->addToolTip(text, icon);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* void EventItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
|
|
|
|
* {
|
|
|
|
* controller->removeToolTip(text);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Remember to removeToolTip when you don't want it to be displayed.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
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-05-07 18:44:54 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
QMap<QString, ToolTip > toolTips;
|
|
|
|
QGraphicsRectItem *background;
|
2013-05-07 23:09:51 +00:00
|
|
|
QGraphicsLineItem *separator;
|
|
|
|
QGraphicsSimpleTextItem *title;
|
|
|
|
|
2013-05-07 18:44:54 +00:00
|
|
|
QRectF rectangle;
|
|
|
|
};
|
|
|
|
|
2013-05-07 23:12:01 +00:00
|
|
|
class EventItem : public QGraphicsPolygonItem
|
|
|
|
{
|
2013-05-07 23:09:51 +00:00
|
|
|
public:
|
|
|
|
explicit EventItem(QGraphicsItem* parent = 0);
|
|
|
|
void addToolTip(const QString& text,const QIcon& icon = QIcon());
|
|
|
|
void setToolTipController(ToolTipItem *controller);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ToolTipItem *controller;
|
|
|
|
QString text;
|
|
|
|
QIcon icon;
|
|
|
|
};
|
|
|
|
|
2013-05-07 23:12:01 +00:00
|
|
|
class ProfileGraphicsView : public QGraphicsView
|
|
|
|
{
|
2013-05-04 19:12:43 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ProfileGraphicsView(QWidget* parent = 0);
|
|
|
|
void plot(struct dive *d);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *event);
|
|
|
|
|
2013-05-04 22:20:49 +00:00
|
|
|
private:
|
|
|
|
void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi);
|
2013-05-06 18:35:17 +00:00
|
|
|
void plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString &text);
|
2013-05-06 21:58:18 +00:00
|
|
|
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);
|
2013-05-04 23:18:16 +00:00
|
|
|
|
|
|
|
QPen defaultPen;
|
|
|
|
QBrush defaultBrush;
|
2013-05-07 18:44:54 +00:00
|
|
|
ToolTipItem *toolTip;
|
2013-05-04 19:12:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|