blob: 15783ea2aef5e162fbabb2f7205163c9c86f9342 (
plain)
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
|
#include "ChartToolTip.h"
const QFont ChartToolTip::Font("Sans Serif", 11);
ChartToolTip::ChartToolTip(const QPointF& pos, const QString& text):
text(text)
{
setPos(pos);
document.setDefaultFont(Font);
document.setHtml(text);
QSizeF docSize = document.size();
setRect(QRectF(QPointF(-docSize.width() / 2, -docSize.height() / 2), docSize));
}
void ChartToolTip::paint(QPainter* painter, const QStyleOptionGraphicsItem*,
QWidget*)
{
drawFrame(painter);
drawText(painter);
}
void ChartToolTip::drawFrame(QPainter* painter)
{
painter->setPen(QPen(Qt::black));
painter->setBrush(QBrush(Qt::white));
painter->drawRect(rect());
}
void ChartToolTip::drawText(QPainter* painter)
{
painter->translate(rect().topLeft());
document.drawContents(painter);
}
void ChartToolTip::adjustPos()
{
QRectF toolTipRect = mapRectToScene(boundingRect());
QRectF sceneRect = scene()->sceneRect();
if(toolTipRect.right() >= sceneRect.right())
moveBy(-(toolTipRect.right() - sceneRect.right()) - 1, 0);
if(toolTipRect.top() <= sceneRect.top())
moveBy(0, sceneRect.top() - toolTipRect.top() + 1);
}
|