subsurface/qt-ui/profilegraphics.h
Dirk Hohndel d590cb9519 Adds real support for ToolTips.
This patch changes the Event drawing so it can display tooltips. It is now
the responsibility of the item to show / hide a tooltip.

A bit of code-refactoring got on here too because I was using only
QGraphicsItem calls and I wanted to use a hover in / hover out event
to show / hide the tooltip.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-07 16:14:15 -07:00

81 lines
2.2 KiB
C++

#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 :public QObject, public QGraphicsPathItem {
Q_OBJECT
void updateTitlePosition();
Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)
public:
enum Status{COLLAPSED, EXPANDED};
enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
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;
QMap<QString, ToolTip > toolTips;
QGraphicsRectItem *background;
QGraphicsLineItem *separator;
QGraphicsSimpleTextItem *title;
QRectF rectangle;
};
class EventItem : public QGraphicsPolygonItem{
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;
};
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