bar.cpp
74 lines
| 1.3 KiB
| text/x-c
|
CppLexer
|
r118 | #include "bar_p.h" | ||
|
r56 | #include <QDebug> | ||
|
r59 | #include <QPainter> | ||
|
r56 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r103 | Bar::Bar(QGraphicsItem *parent) | ||
|
r104 | : ChartItem(parent) | ||
|
r56 | { | ||
} | ||||
|
r115 | void Bar::setSize(const QSizeF& size) | ||
|
r74 | { | ||
mWidth = size.width(); | ||||
mHeight = size.height(); | ||||
} | ||||
|
r113 | void Bar::resize( qreal w, qreal h ) | ||
|
r56 | { | ||
|
r97 | // qDebug() << "bar::resize" << w << h; | ||
|
r56 | mWidth = w; | ||
mHeight = h; | ||||
} | ||||
void Bar::setColor( QColor col ) | ||||
{ | ||||
mColor = col; | ||||
} | ||||
|
r183 | |||
|
r56 | void Bar::setPos(qreal x, qreal y) | ||
{ | ||||
|
r97 | // qDebug() << "Bar::setpos" << x << y; | ||
|
r56 | mXpos = x; | ||
mYpos = y; | ||||
} | ||||
|
r183 | void Bar::setPen(QPen pen) | ||
{ | ||||
mPen = pen; | ||||
} | ||||
void Bar::setBrush(QBrush brush) | ||||
{ | ||||
mBrush = brush; | ||||
} | ||||
|
r56 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||||
|
r82 | if (0 == mHeight) { | ||
return; | ||||
} | ||||
|
r97 | // TODO: accept brush instead of color | ||
|
r183 | painter->setBrush(mBrush); | ||
// QBrush brush(mColor); | ||||
// painter->setBrush(brush); | ||||
|
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); | ||||
|
r56 | } | ||
QRectF Bar::boundingRect() const | ||||
{ | ||||
QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); | ||||
return r; | ||||
} | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||