bar.cpp
77 lines
| 1.4 KiB
| text/x-c
|
CppLexer
sauimone
|
r118 | #include "bar_p.h" | ||
sauimone
|
r56 | #include <QDebug> | ||
Michal Klocek
|
r59 | #include <QPainter> | ||
sauimone
|
r56 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Tero Ahola
|
r103 | Bar::Bar(QGraphicsItem *parent) | ||
sauimone
|
r239 | : QGraphicsObject(parent) | ||
sauimone
|
r56 | { | ||
} | ||||
sauimone
|
r113 | void Bar::resize( qreal w, qreal h ) | ||
sauimone
|
r56 | { | ||
sauimone
|
r97 | // qDebug() << "bar::resize" << w << h; | ||
sauimone
|
r56 | mWidth = w; | ||
mHeight = h; | ||||
} | ||||
void Bar::setPos(qreal x, qreal y) | ||||
{ | ||||
sauimone
|
r97 | // qDebug() << "Bar::setpos" << x << y; | ||
sauimone
|
r56 | mXpos = x; | ||
mYpos = y; | ||||
} | ||||
sauimone
|
r183 | void Bar::setPen(QPen pen) | ||
{ | ||||
mPen = pen; | ||||
} | ||||
void Bar::setBrush(QBrush brush) | ||||
{ | ||||
mBrush = brush; | ||||
} | ||||
sauimone
|
r56 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||||
sauimone
|
r82 | if (0 == mHeight) { | ||
return; | ||||
} | ||||
sauimone
|
r239 | |||
sauimone
|
r183 | painter->setBrush(mBrush); | ||
sauimone
|
r113 | |||
// This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. | ||||
int x0 = mXpos; | ||||
int x1 = (mXpos + mWidth); | ||||
int w = x1-x0; | ||||
int y0 = mYpos; | ||||
int y1 = (mYpos + mHeight); | ||||
int h = y1-y0; | ||||
painter->drawRect(x0, y0 ,w ,h); | ||||
sauimone
|
r56 | } | ||
QRectF Bar::boundingRect() const | ||||
{ | ||||
QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); | ||||
return r; | ||||
} | ||||
sauimone
|
r239 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) | ||
{ | ||||
emit hoverEnter(); | ||||
} | ||||
void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | ||||
{ | ||||
emit hoverLeave(); | ||||
} | ||||
void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) | ||||
{ | ||||
emit clicked(); | ||||
} | ||||
#include "moc_bar_p.cpp" | ||||
sauimone
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||