bar.cpp
76 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
|
r247 | : ChartItem(parent) | ||
sauimone
|
r56 | { | ||
} | ||||
sauimone
|
r247 | void Bar::setSize(const QSizeF& size) | ||
{ | ||||
mWidth = size.width(); | ||||
mHeight = size.height(); | ||||
} | ||||
sauimone
|
r113 | void Bar::resize( qreal w, qreal h ) | ||
sauimone
|
r56 | { | ||
sauimone
|
r97 | // qDebug() << "bar::resize" << w << h; | ||
sauimone
|
r56 | mWidth = w; | ||
mHeight = h; | ||||
} | ||||
sauimone
|
r247 | void Bar::setColor( QColor col ) | ||
{ | ||||
mColor = col; | ||||
} | ||||
sauimone
|
r56 | 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
|
r247 | // TODO: accept brush instead of color | ||
sauimone
|
r183 | painter->setBrush(mBrush); | ||
sauimone
|
r247 | // QBrush brush(mColor); | ||
// painter->setBrush(brush); | ||||
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
|
r247 | //#include "moc_bar_p.cpp" | ||
sauimone
|
r239 | |||
sauimone
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||